Okay, spiff is completely incapable of handling files of nontrivial size.
[oota-llvm.git] / utils / Spiff / token.h
1 /*                        Copyright (c) 1988 Bellcore
2 **                            All Rights Reserved
3 **       Permission is granted to copy or use this program, EXCEPT that it
4 **       may not be sold for profit, the copyright notice must be reproduced
5 **       on copies, and credit should be given to Bellcore where it is due.
6 **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
7 */
8
9
10 #ifndef K_INCLUDED
11 #include "float.h"
12 #include "tol.h"
13 #include "strings.h"
14
15 #define         K_MAXTOKENS     50000
16 /*
17 **      values for token type
18 */
19 #define K_LIT           1
20 #define K_FLO_NUM       2
21
22
23 typedef struct {
24         int linenum;            /* line that the token started on */
25         int pos;                /* position on the line where token started */
26         int type;               /* token type */
27         char *text;             /* literal token text */
28         /*
29         **      canonical floationg point representation
30         */
31         F_float flo_num;
32         T_tol tolerance;
33 } _K_str, *K_token;
34
35 /*
36 **      this should really be a two dimensional array
37 **      but i'm too lazy to recode it
38 */
39 extern K_token _K_ato[];        /* storage for the tokens */
40 extern K_token _K_bto[];
41 /*
42 **      save token X from file
43 */
44 extern void K_settoken(/*file,X,ptr*/);
45 #define K_gettoken(file, X)     (file?(_K_bto[X]):(_K_ato[X]))
46
47 extern int _K_atm;      /* count of tokens */
48 extern int _K_btm;
49
50 /*
51 **      get token number X from file
52 */
53 #define K_get_token(file, X)    (file?(_K_bto[X]):(_K_ato[X]))
54
55 #define K_gettmax(file)         (file?_K_btm:_K_atm)
56 #define K_settmax(file,value)   (file?(_K_btm=(value)):(_K_atm=(value)))
57 /*
58 **      increment and return true on overflow
59 */
60 #define K_inctmax(file)         ((file?(++_K_btm):(++_K_atm))>=K_MAXTOKENS)
61
62 #define K_setline(x,y)          (x->linenum = y)
63 #define K_setpos(x,y)           (x->pos = y)
64 #define K_settext(x,y)          (x->text = y)
65 #define K_savetext(x,y,z)       S_savestr(&(x->text),y)
66 #define K_saventext(x,y,z)      S_savenstr(&(x->text),y,z)
67 #define K_setfloat(x,y)         (x->flo_num = y)
68 #define K_settol(x,y)           (x->tolerance = y)
69 #define K_settype(x,y)          (x->type = y)
70
71 #define K_getline(x)            (x->linenum)
72 #define K_getpos(x)             (x->pos)
73 #define K_gettext(x)            (x->text)
74 #define K_getfloat(x)           (x->flo_num)
75 #define K_gettol(x)             (x->tolerance)
76 #define K_gettype(x)            (x->type)
77
78 #define K_maketoken()           (Z_ALLOC(1,_K_str))
79
80 #define K_INCLUDED
81 #endif