misc.c (flex-2.6.3) | : | misc.c (flex-2.6.4) | ||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
/* documentation and/or other materials provided with the distribution. */ | /* documentation and/or other materials provided with the distribution. */ | |||
/* Neither the name of the University nor the names of its contributors */ | /* Neither the name of the University nor the names of its contributors */ | |||
/* may be used to endorse or promote products derived from this software */ | /* may be used to endorse or promote products derived from this software */ | |||
/* without specific prior written permission. */ | /* without specific prior written permission. */ | |||
/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ | |||
/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ | |||
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ | |||
/* PURPOSE. */ | /* PURPOSE. */ | |||
#include "flexdef.h" | #include "flexdef.h" | |||
#include "tables.h" | #include "tables.h" | |||
#define CMD_IF_TABLES_SER "%if-tables-serialization" | #define CMD_IF_TABLES_SER "%if-tables-serialization" | |||
#define CMD_TABLES_YYDMAP "%tables-yydmap" | #define CMD_TABLES_YYDMAP "%tables-yydmap" | |||
#define CMD_DEFINE_YYTABLES "%define-yytables" | #define CMD_DEFINE_YYTABLES "%define-yytables" | |||
#define CMD_IF_CPP_ONLY "%if-c++-only" | #define CMD_IF_CPP_ONLY "%if-c++-only" | |||
#define CMD_IF_C_ONLY "%if-c-only" | #define CMD_IF_C_ONLY "%if-c-only" | |||
#define CMD_IF_C_OR_CPP "%if-c-or-c++" | #define CMD_IF_C_OR_CPP "%if-c-or-c++" | |||
#define CMD_NOT_FOR_HEADER "%not-for-header" | #define CMD_NOT_FOR_HEADER "%not-for-header" | |||
skipping to change at line 145 | skipping to change at line 144 | |||
strcpy (&action_array[action_index], new_text); | strcpy (&action_array[action_index], new_text); | |||
action_index += len; | action_index += len; | |||
} | } | |||
/* allocate_array - allocate memory for an integer array of the given size */ | /* allocate_array - allocate memory for an integer array of the given size */ | |||
void *allocate_array (int size, size_t element_size) | void *allocate_array (int size, size_t element_size) | |||
{ | { | |||
void *mem; | void *mem; | |||
size_t num_bytes = element_size * (size_t) size; | #if HAVE_REALLOCARRAY | |||
/* reallocarray has built-in overflow detection */ | ||||
mem = malloc(num_bytes); | mem = reallocarray(NULL, (size_t) size, element_size); | |||
#else | ||||
size_t num_bytes = (size_t) size * element_size; | ||||
mem = (size && SIZE_MAX / (size_t) size < element_size) ? NULL : | ||||
malloc(num_bytes); | ||||
#endif | ||||
if (!mem) | if (!mem) | |||
flexfatal (_ | flexfatal (_ | |||
("memory allocation failed in allocate_array()")); | ("memory allocation failed in allocate_array()")); | |||
return mem; | return mem; | |||
} | } | |||
/* all_lower - true if a string is all lower-case */ | /* all_lower - true if a string is all lower-case */ | |||
int all_lower (char *str) | int all_lower (char *str) | |||
skipping to change at line 291 | skipping to change at line 295 | |||
/* flexfatal - report a fatal error message and terminate */ | /* flexfatal - report a fatal error message and terminate */ | |||
void flexfatal (const char *msg) | void flexfatal (const char *msg) | |||
{ | { | |||
fprintf (stderr, _("%s: fatal internal error, %s\n"), | fprintf (stderr, _("%s: fatal internal error, %s\n"), | |||
program_name, msg); | program_name, msg); | |||
FLEX_EXIT (1); | FLEX_EXIT (1); | |||
} | } | |||
/* htoui - convert a hexadecimal digit string to an unsigned integer value */ | ||||
unsigned int htoui (unsigned char str[]) | ||||
{ | ||||
unsigned int result; | ||||
(void) sscanf ((char *) str, "%x", &result); | ||||
return result; | ||||
} | ||||
/* lerr - report an error message */ | /* lerr - report an error message */ | |||
void lerr (const char *msg, ...) | void lerr (const char *msg, ...) | |||
{ | { | |||
char errmsg[MAXLINE]; | char errmsg[MAXLINE]; | |||
va_list args; | va_list args; | |||
va_start(args, msg); | va_start(args, msg); | |||
vsnprintf (errmsg, sizeof(errmsg), msg, args); | vsnprintf (errmsg, sizeof(errmsg), msg, args); | |||
va_end(args); | va_end(args); | |||
skipping to change at line 334 | skipping to change at line 327 | |||
va_end(args); | va_end(args); | |||
flexfatal (errmsg); | flexfatal (errmsg); | |||
} | } | |||
/* line_directive_out - spit out a "#line" statement */ | /* line_directive_out - spit out a "#line" statement */ | |||
void line_directive_out (FILE *output_file, int do_infile) | void line_directive_out (FILE *output_file, int do_infile) | |||
{ | { | |||
char directive[MAXLINE], filename[MAXLINE]; | char directive[MAXLINE], filename[MAXLINE]; | |||
char *s1, *s2, *s3; | char *s1, *s2, *s3; | |||
static const char *line_fmt = "#line %d \"%s\"\n"; | static const char line_fmt[] = "#line %d \"%s\"\n"; | |||
if (!gen_line_dirs) | if (!gen_line_dirs) | |||
return; | return; | |||
s1 = do_infile ? infilename : "M4_YY_OUTFILE_NAME"; | s1 = do_infile ? infilename : "M4_YY_OUTFILE_NAME"; | |||
if (do_infile && !s1) | if (do_infile && !s1) | |||
s1 = "<stdin>"; | s1 = "<stdin>"; | |||
s2 = filename; | s2 = filename; | |||
skipping to change at line 493 | skipping to change at line 486 | |||
case '2': | case '2': | |||
case '3': | case '3': | |||
case '4': | case '4': | |||
case '5': | case '5': | |||
case '6': | case '6': | |||
case '7': | case '7': | |||
{ /* \<octal> */ | { /* \<octal> */ | |||
int sptr = 1; | int sptr = 1; | |||
while (sptr <= 3 && | while (sptr <= 3 && | |||
isascii (array[sptr]) && | array[sptr] >= '0' && array[sptr] <= '7') { | |||
isdigit (array[sptr])) | ||||
/* Don't increment inside loop control | ||||
* because if isdigit() is a macro it might | ||||
* expand into multiple increments ... | ||||
*/ | ||||
++sptr; | ++sptr; | |||
} | ||||
c = array[sptr]; | c = array[sptr]; | |||
array[sptr] = '\0'; | array[sptr] = '\0'; | |||
esc_char = (unsigned char) otoui (array + 1); | esc_char = (unsigned char) strtoul (array + 1, NULL, 8); | |||
array[sptr] = c; | array[sptr] = c; | |||
return esc_char; | return esc_char; | |||
} | } | |||
case 'x': | case 'x': | |||
{ /* \x<hex> */ | { /* \x<hex> */ | |||
int sptr = 2; | int sptr = 2; | |||
while (isascii (array[sptr]) && | while (sptr <= 3 && isxdigit (array[sptr])) { | |||
isxdigit (array[sptr])) | ||||
/* Don't increment inside loop control | /* Don't increment inside loop control | |||
* because if isdigit() is a macro it might | * because if isxdigit() is a macro it might | |||
* expand into multiple increments ... | * expand into multiple increments ... | |||
*/ | */ | |||
++sptr; | ++sptr; | |||
} | ||||
c = array[sptr]; | c = array[sptr]; | |||
array[sptr] = '\0'; | array[sptr] = '\0'; | |||
esc_char = (unsigned char) htoui (array + 2); | esc_char = (unsigned char) strtoul (array + 2, NULL, 16); | |||
array[sptr] = c; | array[sptr] = c; | |||
return esc_char; | return esc_char; | |||
} | } | |||
default: | default: | |||
return array[1]; | return array[1]; | |||
} | } | |||
} | } | |||
/* otoui - convert an octal digit string to an unsigned integer value */ | ||||
unsigned int otoui (unsigned char str[]) | ||||
{ | ||||
unsigned int result; | ||||
(void) sscanf ((char *) str, "%o", &result); | ||||
return result; | ||||
} | ||||
/* out - various flavors of outputing a (possibly formatted) string for the | /* out - various flavors of outputing a (possibly formatted) string for the | |||
* generated scanner, keeping track of the line count. | * generated scanner, keeping track of the line count. | |||
*/ | */ | |||
void out (const char *str) | void out (const char *str) | |||
{ | { | |||
fputs (str, stdout); | fputs (str, stdout); | |||
} | } | |||
void out_dec (const char *fmt, int n) | void out_dec (const char *fmt, int n) | |||
skipping to change at line 658 | skipping to change at line 637 | |||
return rform; | return rform; | |||
} | } | |||
} | } | |||
/* reallocate_array - increase the size of a dynamic array */ | /* reallocate_array - increase the size of a dynamic array */ | |||
void *reallocate_array (void *array, int size, size_t element_size) | void *reallocate_array (void *array, int size, size_t element_size) | |||
{ | { | |||
void *new_array; | void *new_array; | |||
size_t num_bytes = element_size * (size_t) size; | #if HAVE_REALLOCARRAY | |||
/* reallocarray has built-in overflow detection */ | ||||
new_array = realloc(array, num_bytes); | new_array = reallocarray(array, (size_t) size, element_size); | |||
#else | ||||
size_t num_bytes = (size_t) size * element_size; | ||||
new_array = (size && SIZE_MAX / (size_t) size < element_size) ? NULL : | ||||
realloc(array, num_bytes); | ||||
#endif | ||||
if (!new_array) | if (!new_array) | |||
flexfatal (_("attempt to increase array size failed")); | flexfatal (_("attempt to increase array size failed")); | |||
return new_array; | return new_array; | |||
} | } | |||
/* skelout - write out one section of the skeleton file | /* skelout - write out one section of the skeleton file | |||
* | * | |||
* Description | * Description | |||
* Copies skelfile or skel array to stdout until a line beginning with | * Copies skelfile or skel array to stdout until a line beginning with | |||
skipping to change at line 783 | skipping to change at line 767 | |||
do_copy = true; | do_copy = true; | |||
} | } | |||
else if (cmd_match (CMD_NOT_FOR_HEADER)) { | else if (cmd_match (CMD_NOT_FOR_HEADER)) { | |||
/* %c begin linkage-only (non-header) code. */ | /* %c begin linkage-only (non-header) code. */ | |||
OUT_BEGIN_CODE (); | OUT_BEGIN_CODE (); | |||
} | } | |||
else if (cmd_match (CMD_OK_FOR_HEADER)) { | else if (cmd_match (CMD_OK_FOR_HEADER)) { | |||
/* %e end linkage-only code. */ | /* %e end linkage-only code. */ | |||
OUT_END_CODE (); | OUT_END_CODE (); | |||
} | } | |||
else if (buf[1] == '#') { | ||||
/* %# a comment in the skel. ignore. */ | ||||
} | ||||
else { | else { | |||
flexfatal (_("bad line in skeleton file")); | flexfatal (_("bad line in skeleton file")); | |||
} | } | |||
} | } | |||
else if (do_copy) | else if (do_copy) | |||
outn (buf); | outn (buf); | |||
} /* end while */ | } /* end while */ | |||
} | } | |||
End of changes. 14 change blocks. | ||||
43 lines changed or deleted | 24 lines changed or added |