blob: a890c390347e34b197a530087b78adc2a61fe7f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* Token.C
*
* The text to be parsed is broken into fundamental units called tokens.
* To parse the LaTeX files, the program interprets and handles these tokens.
*
* Copyright 1992 Jonathan Monsarrat. Permission given to freely distribute,
* edit and use as long as this copyright statement remains intact.
*
*/
#include <string.h>
#include <stdio.h>
#include "Operator.h"
#include "Global.h"
#include "Document.h"
/* Gets a new token from the last line read from a file. If no such line
* exists, it gets a new line from the open file. If no file is open, it
* opens a new file. If no more files are left to open, returns failure. */
Token::Token()
{
_valid = FALSE;
Global::files->get_token(*this); // Reads a new token from a file
}
/* Deal correctly with this new token. */
void Token::handle()
{
// cerr << "Token: " << _text << endl;
// Look up the appropriate operator from an array of operators.
Operator *op = Operator::get_operator(_text);
if(op)
do
op->execute(); // Execute the operator.
while((++op)->isvalid() && op->match(_text));
else {
if(_text[0] == '\\' && // Found unknown command and not in a comment
!Stack::get(Environment::PDocument, Document::Comment, "")) {
char message[MAXSTRING]; // It's a LaTeX command I don't understand!
sprintf(message,"Skipping unknown LaTeX command %s", _text);
Global::files->warning(message);
return;
}
Operator::plaintext(_text); // If no operator, it must be plain text.
}
}
int Token::isvalid()
{
return(_valid);
}
void Token::make_text(char *token_text)
{
strcpy(_text,token_text);
_valid = TRUE;
}
int Token::match(char *str)
{
return !strcmp(str,_text);
}
char *Token::get_text()
{
return _text;
}
|