141 |
# include "regex.h" |
# include "regex.h" |
142 |
#endif |
#endif |
143 |
|
|
144 |
static void check_use_macro_escape M4_PARAMS((void)); |
static void check_use_macro_escape (void); |
145 |
static int file_peek M4_PARAMS((void)); |
static int file_peek (void); |
146 |
static int file_read M4_PARAMS((void)); |
static int file_read (void); |
147 |
static void file_unget M4_PARAMS((int ch)); |
static void file_unget (int ch); |
148 |
static void file_clean M4_PARAMS((void)); |
static void file_clean (void); |
149 |
static void init_macro_token M4_PARAMS((m4_token_data *td)); |
static void init_macro_token (m4_token_data *td); |
150 |
static int macro_peek M4_PARAMS((void)); |
static int macro_peek (void); |
151 |
static int macro_read M4_PARAMS((void)); |
static int macro_read (void); |
152 |
static int match_input M4_PARAMS((const unsigned char *s)); |
static int match_input (const unsigned char *s); |
153 |
static int next_char M4_PARAMS((void)); |
static int next_char (void); |
154 |
static void pop_input M4_PARAMS((void)); |
static void pop_input (void); |
155 |
static void set_syntax_internal M4_PARAMS((int code, int ch)); |
static void set_syntax_internal (int code, int ch); |
156 |
static int single_peek M4_PARAMS((void)); |
static int single_peek (void); |
157 |
static int single_read M4_PARAMS((void)); |
static int single_read (void); |
158 |
static int string_peek M4_PARAMS((void)); |
static int string_peek (void); |
159 |
static int string_read M4_PARAMS((void)); |
static int string_read (void); |
160 |
static void string_unget M4_PARAMS((int ch)); |
static void string_unget (int ch); |
161 |
static void unget_input M4_PARAMS((int ch)); |
static void unget_input (int ch); |
162 |
static void unset_syntax_attribute M4_PARAMS((int code, int ch)); |
static void unset_syntax_attribute (int code, int ch); |
163 |
|
|
164 |
struct input_funcs |
struct input_funcs |
165 |
{ |
{ |
166 |
int (*peek_func) M4_PARAMS((void)); /* function to peek input */ |
int (*peek_func) (void); /* function to peek input */ |
167 |
int (*read_func) M4_PARAMS((void)); /* function to read input */ |
int (*read_func) (void); /* function to read input */ |
168 |
void (*unget_func) M4_PARAMS((int)); /* function to unread input */ |
void (*unget_func) (int); /* function to unread input */ |
169 |
void (*clean_func) M4_PARAMS((void)); /* function to clean up */ |
void (*clean_func) (void); /* function to clean up */ |
170 |
}; |
}; |
171 |
|
|
172 |
struct input_block |
struct input_block |
284 |
alone is taken as belonging to the line it ends, and the current |
alone is taken as belonging to the line it ends, and the current |
285 |
line number is not incremented until the next character is read. */ |
line number is not incremented until the next character is read. */ |
286 |
static int |
static int |
287 |
file_peek () |
file_peek (void) |
288 |
{ |
{ |
289 |
int ch; |
int ch; |
290 |
|
|
297 |
} |
} |
298 |
|
|
299 |
static int |
static int |
300 |
file_read () |
file_read (void) |
301 |
{ |
{ |
302 |
int ch; |
int ch; |
303 |
|
|
326 |
} |
} |
327 |
|
|
328 |
static void |
static void |
329 |
file_clean () |
file_clean (void) |
330 |
{ |
{ |
331 |
if (debug_level & M4_DEBUG_TRACE_INPUT) |
if (debug_level & M4_DEBUG_TRACE_INPUT) |
332 |
M4_DEBUG_MESSAGE2 (_("Input reverted to %s, line %d"), |
M4_DEBUG_MESSAGE2 (_("Input reverted to %s, line %d"), |
346 |
}; |
}; |
347 |
|
|
348 |
void |
void |
349 |
m4_push_file (fp, title) |
m4_push_file (FILE *fp, const char *title) |
|
FILE *fp; |
|
|
const char *title; |
|
350 |
{ |
{ |
351 |
input_block *i; |
input_block *i; |
352 |
|
|
381 |
next is non-NULL, this push invalidates a call to push_string_init (), |
next is non-NULL, this push invalidates a call to push_string_init (), |
382 |
whose storage are consequentely released. */ |
whose storage are consequentely released. */ |
383 |
static int |
static int |
384 |
macro_peek () |
macro_peek (void) |
385 |
{ |
{ |
386 |
if (isp->u.u_m.read == TRUE) |
if (isp->u.u_m.read == TRUE) |
387 |
return CHAR_RETRY; |
return CHAR_RETRY; |
390 |
} |
} |
391 |
|
|
392 |
static int |
static int |
393 |
macro_read () |
macro_read (void) |
394 |
{ |
{ |
395 |
if (isp->u.u_m.read == TRUE) |
if (isp->u.u_m.read == TRUE) |
396 |
return CHAR_RETRY; |
return CHAR_RETRY; |
404 |
}; |
}; |
405 |
|
|
406 |
void |
void |
407 |
m4_push_macro (func, handle, traced) |
m4_push_macro (m4_builtin_func *func, lt_dlhandle handle, |
408 |
m4_builtin_func *func; |
boolean traced) |
|
lt_dlhandle handle; |
|
|
boolean traced; |
|
409 |
{ |
{ |
410 |
input_block *i; |
input_block *i; |
411 |
|
|
430 |
|
|
431 |
/* Push a single character on to the input stack. */ |
/* Push a single character on to the input stack. */ |
432 |
static int |
static int |
433 |
single_peek () |
single_peek (void) |
434 |
{ |
{ |
435 |
return isp->u.u_c.ch; |
return isp->u.u_c.ch; |
436 |
} |
} |
437 |
|
|
438 |
static int |
static int |
439 |
single_read () |
single_read (void) |
440 |
{ |
{ |
441 |
int ch = isp->u.u_c.ch; |
int ch = isp->u.u_c.ch; |
442 |
|
|
451 |
}; |
}; |
452 |
|
|
453 |
void |
void |
454 |
m4_push_single (ch) |
m4_push_single (int ch) |
|
int ch; |
|
455 |
{ |
{ |
456 |
input_block *i; |
input_block *i; |
457 |
|
|
475 |
/* First half of push_string (). The pointer next points to the new |
/* First half of push_string (). The pointer next points to the new |
476 |
input_block. */ |
input_block. */ |
477 |
static int |
static int |
478 |
string_peek () |
string_peek (void) |
479 |
{ |
{ |
480 |
int ch = *isp->u.u_s.current; |
int ch = *isp->u.u_s.current; |
481 |
|
|
483 |
} |
} |
484 |
|
|
485 |
static int |
static int |
486 |
string_read () |
string_read (void) |
487 |
{ |
{ |
488 |
int ch = *isp->u.u_s.current++; |
int ch = *isp->u.u_s.current++; |
489 |
|
|
492 |
} |
} |
493 |
|
|
494 |
static void |
static void |
495 |
string_unget (ch) |
string_unget (int ch) |
|
int ch; |
|
496 |
{ |
{ |
497 |
if (isp->u.u_s.current > isp->u.u_s.start) |
if (isp->u.u_s.current > isp->u.u_s.start) |
498 |
*--isp->u.u_s.current = ch; |
*--isp->u.u_s.current = ch; |
505 |
}; |
}; |
506 |
|
|
507 |
struct obstack * |
struct obstack * |
508 |
m4_push_string_init () |
m4_push_string_init (void) |
509 |
{ |
{ |
510 |
if (next != NULL) |
if (next != NULL) |
511 |
{ |
{ |
529 |
release the memory used for the object. */ |
release the memory used for the object. */ |
530 |
|
|
531 |
const char * |
const char * |
532 |
m4_push_string_finish () |
m4_push_string_finish (void) |
533 |
{ |
{ |
534 |
const char *ret = NULL; |
const char *ret = NULL; |
535 |
|
|
557 |
Push_wrapup should be done as push_string (), but this will suffice, as |
Push_wrapup should be done as push_string (), but this will suffice, as |
558 |
long as arguments to m4_m4wrap () are moderate in size. */ |
long as arguments to m4_m4wrap () are moderate in size. */ |
559 |
void |
void |
560 |
m4_push_wrapup (s) |
m4_push_wrapup (const char *s) |
|
const char *s; |
|
561 |
{ |
{ |
562 |
input_block *i = (input_block *) obstack_alloc (&wrapup_stack, |
input_block *i = (input_block *) obstack_alloc (&wrapup_stack, |
563 |
sizeof (struct input_block)); |
sizeof (struct input_block)); |
577 |
reset to the saved values before the memory for the input_block are |
reset to the saved values before the memory for the input_block are |
578 |
released. */ |
released. */ |
579 |
static void |
static void |
580 |
pop_input () |
pop_input (void) |
581 |
{ |
{ |
582 |
input_block *tmp = isp->prev; |
input_block *tmp = isp->prev; |
583 |
|
|
609 |
/* When a MACRO token is seen, next_token () uses init_macro_token |
/* When a MACRO token is seen, next_token () uses init_macro_token |
610 |
to retrieve the value of the function pointer. */ |
to retrieve the value of the function pointer. */ |
611 |
static void |
static void |
612 |
init_macro_token (td) |
init_macro_token (m4_token_data *td) |
|
m4_token_data *td; |
|
613 |
{ |
{ |
614 |
if (isp->funcs->read_func != macro_read) |
if (isp->funcs->read_func != macro_read) |
615 |
{ |
{ |
629 |
next_char () is used to read and advance the input to the next |
next_char () is used to read and advance the input to the next |
630 |
character. */ |
character. */ |
631 |
static int |
static int |
632 |
next_char () |
next_char (void) |
633 |
{ |
{ |
634 |
int ch; |
int ch; |
635 |
int (*f) M4_PARAMS((void)); |
int (*f) (void); |
636 |
|
|
637 |
while (1) |
while (1) |
638 |
{ |
{ |
664 |
the input stream. At any given time, it reads from the input_block |
the input stream. At any given time, it reads from the input_block |
665 |
on the top of the current input stack. */ |
on the top of the current input stack. */ |
666 |
int |
int |
667 |
m4_peek_input () |
m4_peek_input (void) |
668 |
{ |
{ |
669 |
int ch; |
int ch; |
670 |
int (*f) M4_PARAMS((void)); |
int (*f) (void); |
671 |
|
|
672 |
while (1) |
while (1) |
673 |
{ |
{ |
697 |
/* The function unget_input () puts back a character on the input |
/* The function unget_input () puts back a character on the input |
698 |
stack, using an existing input_block if possible. */ |
stack, using an existing input_block if possible. */ |
699 |
static void |
static void |
700 |
unget_input (ch) |
unget_input (int ch) |
|
int ch; |
|
701 |
{ |
{ |
702 |
if (isp != NULL && isp->funcs->unget_func != NULL) |
if (isp != NULL && isp->funcs->unget_func != NULL) |
703 |
(*isp->funcs->unget_func)(ch); |
(*isp->funcs->unget_func)(ch); |
708 |
/* skip_line () simply discards all immediately following characters, upto |
/* skip_line () simply discards all immediately following characters, upto |
709 |
the first newline. It is only used from m4_dnl (). */ |
the first newline. It is only used from m4_dnl (). */ |
710 |
void |
void |
711 |
m4_skip_line () |
m4_skip_line (void) |
712 |
{ |
{ |
713 |
int ch; |
int ch; |
714 |
|
|
727 |
All strings herein should be unsigned. Otherwise sign-extension |
All strings herein should be unsigned. Otherwise sign-extension |
728 |
of individual chars might break quotes with 8-bit chars in it. */ |
of individual chars might break quotes with 8-bit chars in it. */ |
729 |
static int |
static int |
730 |
match_input (s) |
match_input (const unsigned char *s) |
|
const unsigned char *s; |
|
731 |
{ |
{ |
732 |
int n; /* number of characters matched */ |
int n; /* number of characters matched */ |
733 |
int ch; /* input character */ |
int ch; /* input character */ |
769 |
|
|
770 |
|
|
771 |
/* Inititialise input stacks, and quote/comment characters. */ |
/* Inititialise input stacks, and quote/comment characters. */ |
772 |
static void set_syntax_internal M4_PARAMS((int code, int ch)); |
static void set_syntax_internal (int code, int ch); |
773 |
static void unset_syntax_attribute M4_PARAMS((int code, int ch)); |
static void unset_syntax_attribute (int code, int ch); |
774 |
|
|
775 |
void |
void |
776 |
m4_input_init () |
m4_input_init (void) |
777 |
{ |
{ |
778 |
m4_current_file = _("NONE"); |
m4_current_file = _("NONE"); |
779 |
m4_current_line = 0; |
m4_current_line = 0; |
816 |
} |
} |
817 |
|
|
818 |
void |
void |
819 |
m4_syntax_init () |
m4_syntax_init (void) |
820 |
{ |
{ |
821 |
int ch; |
int ch; |
822 |
|
|
847 |
} |
} |
848 |
|
|
849 |
int |
int |
850 |
m4_syntax_code (ch) |
m4_syntax_code (char ch) |
|
char ch; |
|
851 |
{ |
{ |
852 |
int code; |
int code; |
853 |
|
|
880 |
} |
} |
881 |
|
|
882 |
static void |
static void |
883 |
check_use_macro_escape () |
check_use_macro_escape (void) |
884 |
{ |
{ |
885 |
int ch; |
int ch; |
886 |
|
|
896 |
m4_changecom () and m4_changequote (). Both functions overrides the |
m4_changecom () and m4_changequote (). Both functions overrides the |
897 |
syntax_table to maintain compatibility. */ |
syntax_table to maintain compatibility. */ |
898 |
void |
void |
899 |
m4_set_quotes (lq, rq) |
m4_set_quotes (const char *lq, const char *rq) |
|
const char *lq; |
|
|
const char *rq; |
|
900 |
{ |
{ |
901 |
int ch; |
int ch; |
902 |
for (ch = 256; --ch >= 0; ) /* changequote overrides syntax_table */ |
for (ch = 256; --ch >= 0; ) /* changequote overrides syntax_table */ |
924 |
} |
} |
925 |
|
|
926 |
void |
void |
927 |
m4_set_comment (bc, ec) |
m4_set_comment (const char *bc, const char *ec) |
|
const char *bc; |
|
|
const char *ec; |
|
928 |
{ |
{ |
929 |
int ch; |
int ch; |
930 |
for (ch = 256; --ch >= 0; ) /* changecom overrides syntax_table */ |
for (ch = 256; --ch >= 0; ) /* changecom overrides syntax_table */ |
953 |
|
|
954 |
/* Functions to manipulate the syntax table. */ |
/* Functions to manipulate the syntax table. */ |
955 |
static void |
static void |
956 |
set_syntax_internal (code, ch) |
set_syntax_internal (int code, int ch) |
|
int code; |
|
|
int ch; |
|
957 |
{ |
{ |
958 |
if (code & M4_SYNTAX_MASKS) |
if (code & M4_SYNTAX_MASKS) |
959 |
m4_syntax_table[ch] |= code; |
m4_syntax_table[ch] |= code; |
968 |
} |
} |
969 |
|
|
970 |
static void |
static void |
971 |
unset_syntax_attribute (code, ch) |
unset_syntax_attribute (int code, int ch) |
|
int code; |
|
|
int ch; |
|
972 |
{ |
{ |
973 |
if (code & M4_SYNTAX_MASKS) |
if (code & M4_SYNTAX_MASKS) |
974 |
m4_syntax_table[ch] &= ~code; |
m4_syntax_table[ch] &= ~code; |
981 |
} |
} |
982 |
|
|
983 |
void |
void |
984 |
m4_set_syntax (key, chars) |
m4_set_syntax (char key, const unsigned char *chars) |
|
char key; |
|
|
const unsigned char *chars; |
|
985 |
{ |
{ |
986 |
int ch, code; |
int ch, code; |
987 |
|
|
1008 |
#ifdef ENABLE_CHANGEWORD |
#ifdef ENABLE_CHANGEWORD |
1009 |
|
|
1010 |
void |
void |
1011 |
m4_set_word_regexp (regexp) |
m4_set_word_regexp (const char *regexp) |
|
const char *regexp; |
|
1012 |
{ |
{ |
1013 |
int i; |
int i; |
1014 |
char test[2]; |
char test[2]; |
1062 |
The storage pointed to by the fields in TD is therefore subject to |
The storage pointed to by the fields in TD is therefore subject to |
1063 |
change the next time next_token () is called. */ |
change the next time next_token () is called. */ |
1064 |
m4_token_t |
m4_token_t |
1065 |
m4_next_token (td) |
m4_next_token (m4_token_data *td) |
|
m4_token_data *td; |
|
1066 |
{ |
{ |
1067 |
int ch; |
int ch; |
1068 |
int quote_level; |
int quote_level; |
1320 |
|
|
1321 |
#ifdef DEBUG_INPUT |
#ifdef DEBUG_INPUT |
1322 |
|
|
1323 |
static void lex_debug M4_PARAMS((void)); |
static void lex_debug (void); |
1324 |
|
|
1325 |
int |
int |
1326 |
m4_print_token (s, t, td) |
m4_print_token (const char *s, m4_token_t t, m4_token_data *td) |
|
const char *s; |
|
|
m4_token_t t; |
|
|
m4_token_data *td; |
|
1327 |
{ |
{ |
1328 |
fprintf (stderr, "%s: ", s); |
fprintf (stderr, "%s: ", s); |
1329 |
switch (t) |
switch (t) |
1360 |
} |
} |
1361 |
|
|
1362 |
static void |
static void |
1363 |
lex_debug () |
lex_debug (void) |
1364 |
{ |
{ |
1365 |
m4_token_t t; |
m4_token_t t; |
1366 |
m4_token_data td; |
m4_token_data td; |