2 * This is a really stupid C tokenizer. It doesn't do any include
3 * files or anything complex at all. That's the preprocessor.
5 * Copyright (C) 2003 Transmeta Corp.
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
42 int input_stream_nr
= 0;
43 struct stream
*input_streams
;
44 static int input_streams_allocated
;
45 unsigned int tabstop
= 8;
48 #define BUFSIZE (8192)
53 int newline
, whitespace
;
54 struct token
**tokenlist
;
56 unsigned char *buffer
;
59 const char *stream_name(int stream
)
61 if (stream
< 0 || stream
> input_stream_nr
)
62 return "<bad stream>";
63 return input_streams
[stream
].name
;
66 static struct position
stream_pos(stream_t
*stream
)
70 pos
.stream
= stream
->nr
;
71 pos
.newline
= stream
->newline
;
72 pos
.whitespace
= stream
->whitespace
;
73 pos
.pos
= stream
->pos
;
75 pos
.line
= stream
->line
;
83 const char *show_special(int val
)
85 static char buffer
[4];
89 if (val
>= SPECIAL_BASE
)
90 strcpy(buffer
, (char *) combinations
[val
- SPECIAL_BASE
]);
94 const char *show_ident(const struct ident
*ident
)
96 static char buffer
[256];
99 sprintf(buffer
, "%.*s", ident
->len
, ident
->name
);
103 static char *charstr(char *ptr
, unsigned char c
, unsigned char escape
, unsigned char next
)
106 if (c
== escape
|| c
== '\\')
121 return ptr
+ sprintf(ptr
, "%o", c
);
123 return ptr
+ sprintf(ptr
, "%03o", c
);
126 const char *show_string(const struct string
*string
)
128 static char buffer
[4 * MAX_STRING
+ 3];
133 return "<bad_string>";
136 for (i
= 0; i
< string
->length
-1; i
++) {
137 const char *p
= string
->data
+ i
;
138 ptr
= charstr(ptr
, p
[0], '"', p
[1]);
145 static const char *show_char(const char *s
, size_t len
, char prefix
, char delim
)
147 static char buffer
[MAX_STRING
+ 4];
159 static const char *quote_char(const char *s
, size_t len
, char prefix
, char delim
)
161 static char buffer
[2*MAX_STRING
+ 6];
169 for (i
= 0; i
< len
; i
++) {
170 if (s
[i
] == '"' || s
[i
] == '\\')
181 const char *show_token(const struct token
*token
)
183 static char buffer
[256];
187 switch (token_type(token
)) {
189 return "syntax error";
192 return "end-of-input";
195 return show_ident(token
->ident
);
198 return token
->number
;
201 return show_special(token
->special
);
204 return show_char(token
->string
->data
,
205 token
->string
->length
- 1, 0, '\'');
206 case TOKEN_CHAR_EMBEDDED_0
... TOKEN_CHAR_EMBEDDED_3
:
207 return show_char(token
->embedded
,
208 token_type(token
) - TOKEN_CHAR
, 0, '\'');
209 case TOKEN_WIDE_CHAR
:
210 return show_char(token
->string
->data
,
211 token
->string
->length
- 1, 'L', '\'');
212 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
213 return show_char(token
->embedded
,
214 token_type(token
) - TOKEN_WIDE_CHAR
, 'L', '\'');
216 return show_char(token
->string
->data
,
217 token
->string
->length
- 1, 0, '"');
218 case TOKEN_WIDE_STRING
:
219 return show_char(token
->string
->data
,
220 token
->string
->length
- 1, 'L', '"');
222 case TOKEN_STREAMBEGIN
:
223 sprintf(buffer
, "<beginning of '%s'>", stream_name(token
->pos
.stream
));
226 case TOKEN_STREAMEND
:
227 sprintf(buffer
, "<end of '%s'>", stream_name(token
->pos
.stream
));
231 sprintf(buffer
, "<untaint>");
234 case TOKEN_ARG_COUNT
:
235 sprintf(buffer
, "<argcnt>");
239 sprintf(buffer
, "unhandled token type '%d' ", token_type(token
));
244 const char *quote_token(const struct token
*token
)
246 static char buffer
[256];
248 switch (token_type(token
)) {
250 return "syntax error";
253 return show_ident(token
->ident
);
256 return token
->number
;
259 return show_special(token
->special
);
262 return quote_char(token
->string
->data
,
263 token
->string
->length
- 1, 0, '\'');
264 case TOKEN_CHAR_EMBEDDED_0
... TOKEN_CHAR_EMBEDDED_3
:
265 return quote_char(token
->embedded
,
266 token_type(token
) - TOKEN_CHAR
, 0, '\'');
267 case TOKEN_WIDE_CHAR
:
268 return quote_char(token
->string
->data
,
269 token
->string
->length
- 1, 'L', '\'');
270 case TOKEN_WIDE_CHAR_EMBEDDED_0
... TOKEN_WIDE_CHAR_EMBEDDED_3
:
271 return quote_char(token
->embedded
,
272 token_type(token
) - TOKEN_WIDE_CHAR
, 'L', '\'');
274 return quote_char(token
->string
->data
,
275 token
->string
->length
- 1, 0, '"');
276 case TOKEN_WIDE_STRING
:
277 return quote_char(token
->string
->data
,
278 token
->string
->length
- 1, 'L', '"');
280 sprintf(buffer
, "unhandled token type '%d' ", token_type(token
));
285 #define HASHED_INPUT_BITS (6)
286 #define HASHED_INPUT (1 << HASHED_INPUT_BITS)
287 #define HASH_PRIME 0x9e370001UL
289 static int input_stream_hashes
[HASHED_INPUT
] = { [0 ... HASHED_INPUT
-1] = -1 };
291 int *hash_stream(const char *name
)
296 while ((c
= *name
++) != 0)
297 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
300 hash
>>= 32 - HASHED_INPUT_BITS
;
301 return input_stream_hashes
+ hash
;
304 int init_stream(const char *name
, int fd
, const char **next_path
)
306 int stream
= input_stream_nr
, *hash
;
307 struct stream
*current
;
309 if (stream
>= input_streams_allocated
) {
310 int newalloc
= stream
* 4 / 3 + 10;
311 input_streams
= realloc(input_streams
, newalloc
* sizeof(struct stream
));
313 die("Unable to allocate more streams space");
314 input_streams_allocated
= newalloc
;
316 current
= input_streams
+ stream
;
317 memset(current
, 0, sizeof(*current
));
318 current
->name
= name
;
320 current
->next_path
= next_path
;
321 current
->path
= NULL
;
322 current
->constant
= CONSTANT_FILE_MAYBE
;
323 input_stream_nr
= stream
+1;
324 hash
= hash_stream(name
);
325 current
->next_stream
= *hash
;
330 static struct token
* alloc_token(stream_t
*stream
)
332 struct token
*token
= __alloc_token(0);
333 token
->pos
= stream_pos(stream
);
338 * Argh... That was surprisingly messy - handling '\r' complicates the
341 static int nextchar_slow(stream_t
*stream
)
343 int offset
= stream
->offset
;
344 int size
= stream
->size
;
346 int spliced
= 0, had_cr
, had_backslash
;
349 had_cr
= had_backslash
= 0;
352 if (offset
>= size
) {
355 size
= read(stream
->fd
, stream
->buffer
, BUFSIZE
);
359 stream
->offset
= offset
= 0;
362 c
= stream
->buffer
[offset
++];
372 if (!had_backslash
) {
375 stream
->pos
+= tabstop
- stream
->pos
% tabstop
;
400 stream
->offset
= offset
;
416 warning(stream_pos(stream
), "no newline at end of file");
418 warning(stream_pos(stream
), "backslash-newline at end of file");
423 * We want that as light as possible while covering all normal cases.
424 * Slow path (including the logics with line-splicing and EOF sanity
425 * checks) is in nextchar_slow().
427 static inline int nextchar(stream_t
*stream
)
429 int offset
= stream
->offset
;
431 if (offset
< stream
->size
) {
432 int c
= stream
->buffer
[offset
++];
433 static const char special
[256] = {
434 ['\t'] = 1, ['\r'] = 1, ['\n'] = 1, ['\\'] = 1
437 stream
->offset
= offset
;
442 return nextchar_slow(stream
);
445 struct token eof_token_entry
;
447 static struct token
*mark_eof(stream_t
*stream
)
451 end
= alloc_token(stream
);
452 token_type(end
) = TOKEN_STREAMEND
;
453 end
->pos
.newline
= 1;
455 eof_token_entry
.next
= &eof_token_entry
;
456 eof_token_entry
.pos
.newline
= 1;
458 end
->next
= &eof_token_entry
;
459 *stream
->tokenlist
= end
;
460 stream
->tokenlist
= NULL
;
464 static void add_token(stream_t
*stream
)
466 struct token
*token
= stream
->token
;
468 stream
->token
= NULL
;
470 *stream
->tokenlist
= token
;
471 stream
->tokenlist
= &token
->next
;
474 static void drop_token(stream_t
*stream
)
476 stream
->newline
|= stream
->token
->pos
.newline
;
477 stream
->whitespace
|= stream
->token
->pos
.whitespace
;
478 stream
->token
= NULL
;
492 static const long cclass
[257] = {
493 ['0' + 1 ... '7' + 1] = Digit
| Hex
| Escape
, /* \<octal> */
494 ['8' + 1 ... '9' + 1] = Digit
| Hex
,
495 ['A' + 1 ... 'D' + 1] = Letter
| Hex
,
496 ['E' + 1] = Letter
| Hex
| Exp
, /* E<exp> */
497 ['F' + 1] = Letter
| Hex
,
498 ['G' + 1 ... 'O' + 1] = Letter
,
499 ['P' + 1] = Letter
| Exp
, /* P<exp> */
500 ['Q' + 1 ... 'Z' + 1] = Letter
,
501 ['a' + 1 ... 'b' + 1] = Letter
| Hex
| Escape
, /* \a, \b */
502 ['c' + 1 ... 'd' + 1] = Letter
| Hex
,
503 ['e' + 1] = Letter
| Hex
| Exp
| Escape
,/* \e, e<exp> */
504 ['f' + 1] = Letter
| Hex
| Escape
, /* \f */
505 ['g' + 1 ... 'm' + 1] = Letter
,
506 ['n' + 1] = Letter
| Escape
, /* \n */
508 ['p' + 1] = Letter
| Exp
, /* p<exp> */
510 ['r' + 1] = Letter
| Escape
, /* \r */
512 ['t' + 1] = Letter
| Escape
, /* \t */
514 ['v' + 1] = Letter
| Escape
, /* \v */
516 ['x' + 1] = Letter
| Escape
, /* \x<hex> */
517 ['y' + 1 ... 'z' + 1] = Letter
,
519 ['.' + 1] = Dot
| ValidSecond
,
520 ['=' + 1] = ValidSecond
,
521 ['+' + 1] = ValidSecond
,
522 ['-' + 1] = ValidSecond
,
523 ['>' + 1] = ValidSecond
,
524 ['<' + 1] = ValidSecond
,
525 ['&' + 1] = ValidSecond
,
526 ['|' + 1] = ValidSecond
,
527 ['#' + 1] = ValidSecond
,
528 ['\'' + 1] = Quote
| Escape
,
529 ['"' + 1] = Quote
| Escape
,
539 * pp-number identifier-nodigit
546 static int get_one_number(int c
, int next
, stream_t
*stream
)
549 static char buffer
[4095];
550 char *p
= buffer
, *buf
, *buffer_end
= buffer
+ sizeof (buffer
);
555 long class = cclass
[next
+ 1];
556 if (!(class & (Dot
| Digit
| Letter
)))
560 next
= nextchar(stream
);
562 if (next
== '-' || next
== '+') {
565 next
= nextchar(stream
);
570 if (p
== buffer_end
) {
571 sparse_error(stream_pos(stream
), "number token exceeds %td characters",
572 buffer_end
- buffer
);
573 // Pretend we saw just "1".
580 buf
= __alloc_bytes(len
);
581 memcpy(buf
, buffer
, len
);
583 token
= stream
->token
;
584 token_type(token
) = TOKEN_NUMBER
;
591 static int eat_string(int next
, stream_t
*stream
, enum token_type type
)
593 static char buffer
[MAX_STRING
];
594 struct string
*string
;
595 struct token
*token
= stream
->token
;
599 char delim
= type
< TOKEN_STRING
? '\'' : '"';
601 for (escape
= 0; escape
|| next
!= delim
; next
= nextchar(stream
)) {
602 if (len
< MAX_STRING
)
606 warning(stream_pos(stream
),
607 "Newline in string or character constant");
608 if (delim
== '\'') /* assume it's lost ' */
612 warning(stream_pos(stream
),
613 "End of file in middle of string");
617 if (want_hex
&& !(cclass
[next
+ 1] & Hex
))
618 warning(stream_pos(stream
),
619 "\\x used with no following hex digits");
621 escape
= next
== '\\';
623 if (!(cclass
[next
+ 1] & Escape
))
624 warning(stream_pos(stream
),
625 "Unknown escape '%c'", next
);
627 want_hex
= next
== 'x';
631 warning(stream_pos(stream
),
632 "\\x used with no following hex digits");
633 if (len
> MAX_STRING
) {
634 warning(stream_pos(stream
), "string too long (%d bytes, %d bytes max)", len
, MAX_STRING
);
637 if (delim
== '\'' && len
<= 4) {
639 sparse_error(stream_pos(stream
),
640 "empty character constant");
641 return nextchar(stream
);
643 token_type(token
) = type
+ len
;
644 memset(buffer
+ len
, '\0', 4 - len
);
645 memcpy(token
->embedded
, buffer
, 4);
647 token_type(token
) = type
;
648 string
= __alloc_string(len
+1);
649 memcpy(string
->data
, buffer
, len
);
650 string
->data
[len
] = '\0';
651 string
->length
= len
+1;
652 token
->string
= string
;
656 token
= stream
->token
;
658 return nextchar(stream
);
661 static int drop_stream_eoln(stream_t
*stream
)
665 switch (nextchar(stream
)) {
669 return nextchar(stream
);
674 static int drop_stream_comment(stream_t
*stream
)
679 newline
= stream
->newline
;
681 next
= nextchar(stream
);
685 warning(stream_pos(stream
), "End of file in the middle of a comment");
688 next
= nextchar(stream
);
689 if (curr
== '*' && next
== '/')
692 stream
->newline
= newline
;
693 return nextchar(stream
);
696 unsigned char combinations
[][4] = COMBINATION_STRINGS
;
698 #define NR_COMBINATIONS (SPECIAL_ARG_SEPARATOR - SPECIAL_BASE)
700 /* hash function for two-character punctuators - all give unique values */
701 #define special_hash(c0, c1) (((c0*8+c1*2)+((c0*8+c1*2)>>5))&31)
704 * note that we won't get false positives - special_hash(0,0) is 0 and
705 * entry 0 is filled (by +=), so all the missing ones are OK.
707 static unsigned char hash_results
[32][2] = {
708 #define RES(c0, c1) [special_hash(c0, c1)] = {c0, c1}
709 RES('+', '='), /* 00 */
710 RES('/', '='), /* 01 */
711 RES('^', '='), /* 05 */
712 RES('&', '&'), /* 07 */
713 RES('#', '#'), /* 08 */
714 RES('<', '<'), /* 0a */
715 RES('<', '='), /* 0c */
716 RES('!', '='), /* 0e */
717 RES('%', '='), /* 0f */
718 RES('-', '-'), /* 10 */
719 RES('-', '='), /* 11 */
720 RES('-', '>'), /* 13 */
721 RES('=', '='), /* 15 */
722 RES('&', '='), /* 17 */
723 RES('*', '='), /* 18 */
724 RES('.', '.'), /* 1a */
725 RES('+', '+'), /* 1b */
726 RES('|', '='), /* 1c */
727 RES('>', '='), /* 1d */
728 RES('|', '|'), /* 1e */
729 RES('>', '>') /* 1f */
732 static int code
[32] = {
733 #define CODE(c0, c1, value) [special_hash(c0, c1)] = value
734 CODE('+', '=', SPECIAL_ADD_ASSIGN
), /* 00 */
735 CODE('/', '=', SPECIAL_DIV_ASSIGN
), /* 01 */
736 CODE('^', '=', SPECIAL_XOR_ASSIGN
), /* 05 */
737 CODE('&', '&', SPECIAL_LOGICAL_AND
), /* 07 */
738 CODE('#', '#', SPECIAL_HASHHASH
), /* 08 */
739 CODE('<', '<', SPECIAL_LEFTSHIFT
), /* 0a */
740 CODE('<', '=', SPECIAL_LTE
), /* 0c */
741 CODE('!', '=', SPECIAL_NOTEQUAL
), /* 0e */
742 CODE('%', '=', SPECIAL_MOD_ASSIGN
), /* 0f */
743 CODE('-', '-', SPECIAL_DECREMENT
), /* 10 */
744 CODE('-', '=', SPECIAL_SUB_ASSIGN
), /* 11 */
745 CODE('-', '>', SPECIAL_DEREFERENCE
), /* 13 */
746 CODE('=', '=', SPECIAL_EQUAL
), /* 15 */
747 CODE('&', '=', SPECIAL_AND_ASSIGN
), /* 17 */
748 CODE('*', '=', SPECIAL_MUL_ASSIGN
), /* 18 */
749 CODE('.', '.', SPECIAL_DOTDOT
), /* 1a */
750 CODE('+', '+', SPECIAL_INCREMENT
), /* 1b */
751 CODE('|', '=', SPECIAL_OR_ASSIGN
), /* 1c */
752 CODE('>', '=', SPECIAL_GTE
), /* 1d */
753 CODE('|', '|', SPECIAL_LOGICAL_OR
), /* 1e */
754 CODE('>', '>', SPECIAL_RIGHTSHIFT
) /* 1f */
758 static int get_one_special(int c
, stream_t
*stream
)
763 next
= nextchar(stream
);
766 * Check for numbers, strings, character constants, and comments
770 if (next
>= '0' && next
<= '9')
771 return get_one_number(c
, next
, stream
);
774 return eat_string(next
, stream
, TOKEN_STRING
);
776 return eat_string(next
, stream
, TOKEN_CHAR
);
779 return drop_stream_eoln(stream
);
781 return drop_stream_comment(stream
);
785 * Check for combinations
788 if (cclass
[next
+ 1] & ValidSecond
) {
789 i
= special_hash(c
, next
);
790 if (hash_results
[i
][0] == c
&& hash_results
[i
][1] == next
) {
792 next
= nextchar(stream
);
793 if (value
>= SPECIAL_LEFTSHIFT
&&
794 next
== "==."[value
- SPECIAL_LEFTSHIFT
]) {
796 next
= nextchar(stream
);
802 token
= stream
->token
;
803 token_type(token
) = TOKEN_SPECIAL
;
804 token
->special
= value
;
809 #define IDENT_HASH_BITS (13)
810 #define IDENT_HASH_SIZE (1<<IDENT_HASH_BITS)
811 #define IDENT_HASH_MASK (IDENT_HASH_SIZE-1)
813 #define ident_hash_init(c) (c)
814 #define ident_hash_add(oldhash,c) ((oldhash)*11 + (c))
815 #define ident_hash_end(hash) ((((hash) >> IDENT_HASH_BITS) + (hash)) & IDENT_HASH_MASK)
817 static struct ident
*hash_table
[IDENT_HASH_SIZE
];
818 static int ident_hit
, ident_miss
, idents
;
820 void show_identifier_stats(void)
823 int distribution
[100];
825 fprintf(stderr
, "identifiers: %d hits, %d misses\n",
826 ident_hit
, ident_miss
);
828 for (i
= 0; i
< 100; i
++)
831 for (i
= 0; i
< IDENT_HASH_SIZE
; i
++) {
832 struct ident
* ident
= hash_table
[i
];
841 distribution
[count
]++;
844 for (i
= 0; i
< 100; i
++) {
846 fprintf(stderr
, "%2d: %d buckets\n", i
, distribution
[i
]);
850 static struct ident
*alloc_ident(const char *name
, int len
)
852 struct ident
*ident
= __alloc_ident(len
);
853 ident
->symbols
= NULL
;
856 memcpy(ident
->name
, name
, len
);
860 static struct ident
* insert_hash(struct ident
*ident
, unsigned long hash
)
862 ident
->next
= hash_table
[hash
];
863 hash_table
[hash
] = ident
;
868 static struct ident
*create_hashed_ident(const char *name
, int len
, unsigned long hash
)
873 p
= &hash_table
[hash
];
874 while ((ident
= *p
) != NULL
) {
875 if (ident
->len
== (unsigned char) len
) {
876 if (strncmp(name
, ident
->name
, len
) != 0)
886 ident
= alloc_ident(name
, len
);
894 static unsigned long hash_name(const char *name
, int len
)
897 const unsigned char *p
= (const unsigned char *)name
;
899 hash
= ident_hash_init(*p
++);
901 unsigned int i
= *p
++;
902 hash
= ident_hash_add(hash
, i
);
904 return ident_hash_end(hash
);
907 struct ident
*hash_ident(struct ident
*ident
)
909 return insert_hash(ident
, hash_name(ident
->name
, ident
->len
));
912 struct ident
*built_in_ident(const char *name
)
914 int len
= strlen(name
);
915 return create_hashed_ident(name
, len
, hash_name(name
, len
));
918 struct token
*built_in_token(int stream
, const char *name
)
922 token
= __alloc_token(0);
923 token
->pos
.stream
= stream
;
924 token_type(token
) = TOKEN_IDENT
;
925 token
->ident
= built_in_ident(name
);
929 static int get_one_identifier(int c
, stream_t
*stream
)
938 hash
= ident_hash_init(c
);
941 next
= nextchar(stream
);
942 if (!(cclass
[next
+ 1] & (Letter
| Digit
)))
944 if (len
>= sizeof(buf
))
946 hash
= ident_hash_add(hash
, next
);
950 if (cclass
[next
+ 1] & Quote
) {
951 if (len
== 1 && buf
[0] == 'L') {
953 return eat_string(nextchar(stream
), stream
,
956 return eat_string(nextchar(stream
), stream
,
960 hash
= ident_hash_end(hash
);
961 ident
= create_hashed_ident(buf
, len
, hash
);
964 token
= stream
->token
;
965 token_type(token
) = TOKEN_IDENT
;
966 token
->ident
= ident
;
971 static int get_one_token(int c
, stream_t
*stream
)
973 long class = cclass
[c
+ 1];
975 return get_one_number(c
, nextchar(stream
), stream
);
977 return get_one_identifier(c
, stream
);
978 return get_one_special(c
, stream
);
981 static struct token
*setup_stream(stream_t
*stream
, int idx
, int fd
,
982 unsigned char *buf
, unsigned int buf_size
)
989 stream
->whitespace
= 0;
992 stream
->token
= NULL
;
995 stream
->size
= buf_size
;
996 stream
->buffer
= buf
;
998 begin
= alloc_token(stream
);
999 token_type(begin
) = TOKEN_STREAMBEGIN
;
1000 stream
->tokenlist
= &begin
->next
;
1004 static struct token
*tokenize_stream(stream_t
*stream
)
1006 int c
= nextchar(stream
);
1009 struct token
*token
= alloc_token(stream
);
1010 stream
->token
= token
;
1011 stream
->newline
= 0;
1012 stream
->whitespace
= 0;
1013 c
= get_one_token(c
, stream
);
1016 stream
->whitespace
= 1;
1017 c
= nextchar(stream
);
1019 return mark_eof(stream
);
1022 struct token
* tokenize_buffer(void *buffer
, unsigned long size
, struct token
**endtoken
)
1025 struct token
*begin
;
1027 begin
= setup_stream(&stream
, 0, -1, buffer
, size
);
1028 *endtoken
= tokenize_stream(&stream
);
1032 struct token
* tokenize(const char *name
, int fd
, struct token
*endtoken
, const char **next_path
)
1034 struct token
*begin
, *end
;
1036 unsigned char buffer
[BUFSIZE
];
1039 idx
= init_stream(name
, fd
, next_path
);
1041 // info(endtoken->pos, "File %s is const", name);
1045 begin
= setup_stream(&stream
, idx
, fd
, buffer
, 0);
1046 end
= tokenize_stream(&stream
);
1048 end
->next
= endtoken
;