/* Copyright (c) 1990 The Regents of the University of California. */ /* All rights reserved. */
/* This code is derived from software contributed to Berkeley by */ /* Vern Paxson. */
/* The United States Government has rights in this work pursuant */ /* to contract no. DE-AC03-76SF00098 between the United States */ /* Department of Energy and the University of California. */
/* This file is part of flex. */
/* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */
/* 1. Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* 2. Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in the */ /* documentation and/or other materials provided with the distribution. */
/* Neither the name of the University nor the names of its contributors */ /* may be used to endorse or promote products derived from this software */ /* without specific prior written permission. */
/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ /* PURPOSE. */
/* Append "new_text" to the running buffer. */ void add_action (new_text) constchar *new_text;
{ int len = strlen (new_text);
while (len + action_index >= action_size - 10/* slop */ ) { int new_size = action_size * 2;
if (new_size <= 0) /* Increase just a little, to try to avoid overflow *on16-bitmachines.
*/
action_size += action_size / 8; else
action_size = new_size;
/* cclcmp - compares two characters for use by qsort with '\0' sorting last. */
int cclcmp (constvoid *a, constvoid *b)
{ if (!*(constChar *) a) return1; else if (!*(constChar *) b) return - 1; else return *(constChar *) a - *(constChar *) b;
}
/* dataend - finish up a block of data declarations */
void dataend ()
{ /* short circuit any output */ if (gentables) {
if (datapos > 0)
dataflush ();
/* add terminator for initialization; { for vi */
outn (" } ;\n");
}
dataline = 0;
datapos = 0;
}
/* dataflush - flush generated data statements */
void dataflush ()
{ /* short circuit any output */ if (!gentables) return;
outc ('\n');
if (++dataline >= NUMDATALINES) { /* Put out a blank line so that the table is grouped into *largeblocksthatenabletheusertofindelementseasily.
*/
outc ('\n');
dataline = 0;
}
/* Reset the number of characters written on the current line. */
datapos = 0;
}
/* flexerror - report an error message and terminate */
/* If output_file is nil then we should put the directive in *theaccumulatedactions.
*/ if (output_file) {
fputs (directive, output_file);
} else
add_action (directive);
}
/* mark_defs1 - mark the current position in the action array as *representingwheretheuser'ssection1definitionsend *andtheprologbegins
*/ void mark_defs1 ()
{
defs1_offset = 0;
action_array[action_index++] = '\0';
action_offset = prolog_offset = action_index;
action_array[action_index] = '\0';
}
/* mark_prolog - mark the current position in the action array as *representingtheendoftheactionprolog
*/ void mark_prolog ()
{
action_array[action_index++] = '\0';
action_offset = action_index;
action_array[action_index] = '\0';
}
/* mk2data - generate a data statement for a two-dimensional array * *Generatesadatastatementinitializingthecurrent2-Darrayto"value".
*/ void mk2data (value) int value;
{ /* short circuit any output */ if (!gentables) return;
if (datapos >= NUMDATAITEMS) {
outc (',');
dataflush ();
}
if (datapos == 0) /* Indent. */
out (" ");
else
outc (',');
++datapos;
out_dec ("%5d", value);
}
/* mkdata - generate a data statement * *Generatesadatastatementinitializingthecurrentarrayelementto *"value".
*/ void mkdata (value) int value;
{ /* short circuit any output */ if (!gentables) return;
if (datapos >= NUMDATAITEMS) {
outc (',');
dataflush ();
}
if (datapos == 0) /* Indent. */
out (" "); else
outc (',');
++datapos;
out_dec ("%5d", value);
}
/* myctoi - return the integer represented by a string of digits */
int myctoi (array) constchar *array;
{ int val = 0;
(void) sscanf (array, "%d", &val);
return val;
}
/* myesc - return character corresponding to escape sequence */
new_array = flex_realloc (array, num_bytes); if (!new_array)
flexfatal (_("attempt to increase array size failed"));
return new_array;
}
/* skelout - write out one section of the skeleton file * *Description *Copiesskelfileorskelarraytostdoutuntilalinebeginningwith *"%%"orEOFisfound.
*/ void skelout ()
{ char buf_storage[MAXLINE]; char *buf = buf_storage; bool do_copy = true;
/* "reset" the state by clearing the buffer and pushing a '1' */ if(sko_len > 0)
sko_peek(&do_copy);
sko_len = 0;
sko_push(do_copy=true);
/* Loop pulling lines either from the skelfile, if we're using *one,orfromtheskel[]array.
*/ while (skelfile ?
(fgets (buf, MAXLINE, skelfile) != NULL) :
((buf = (char *) skel[skel_ind++]) != 0)) {
if (skelfile)
chomp (buf);
/* copy from skel array */ if (buf[0] == '%') { /* control line */ /* print the control line as a comment. */ if (ddebug && buf[1] != '#') { if (buf[strlen (buf) - 1] == '\\')
out_str ("/* %s */\\\n", buf); else
out_str ("/* %s */\n", buf);
}
/* We've been accused of using cryptic markers in the skel. *Sowe'lluseemacs-style-hyphenated-commands. *Wemightconsiderahashifthisif-else-if-else *chaingetstoolarge.
*/ #define cmd_match(s) (strncmp(buf,(s),strlen(s))==0)
if (buf[1] == '%') { /* %% is a break point for skelout() */ return;
} elseif (cmd_match (CMD_PUSH)){
sko_push(do_copy); if(ddebug){
out_str("/*(state = (%s) */",do_copy?"true":"false");
}
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
} elseif (cmd_match (CMD_POP)){
sko_pop(&do_copy); if(ddebug){
out_str("/*(state = (%s) */",do_copy?"true":"false");
}
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
} elseif (cmd_match (CMD_IF_REENTRANT)){
sko_push(do_copy);
do_copy = reentrant && do_copy;
} elseif (cmd_match (CMD_IF_NOT_REENTRANT)){
sko_push(do_copy);
do_copy = !reentrant && do_copy;
} elseif (cmd_match(CMD_IF_BISON_BRIDGE)){
sko_push(do_copy);
do_copy = bison_bridge_lval && do_copy;
} elseif (cmd_match(CMD_IF_NOT_BISON_BRIDGE)){
sko_push(do_copy);
do_copy = !bison_bridge_lval && do_copy;
} elseif (cmd_match (CMD_ENDIF)){
sko_pop(&do_copy);
} elseif (cmd_match (CMD_IF_TABLES_SER)) {
do_copy = do_copy && tablesext;
} elseif (cmd_match (CMD_TABLES_YYDMAP)) { if (tablesext && yydmap_buf.elts)
outn ((char *) (yydmap_buf.elts));
} elseif (cmd_match (CMD_DEFINE_YYTABLES)) {
out_str("#define YYTABLES_NAME \"%s\"\n",
tablesname?tablesname:"yytables");
} elseif (cmd_match (CMD_IF_CPP_ONLY)) { /* only for C++ */
sko_push(do_copy);
do_copy = C_plus_plus;
} elseif (cmd_match (CMD_IF_C_ONLY)) { /* %- only for C */
sko_push(do_copy);
do_copy = !C_plus_plus;
} elseif (cmd_match (CMD_IF_C_OR_CPP)) { /* %* for C and C++ */
sko_push(do_copy);
do_copy = true;
} elseif (cmd_match (CMD_NOT_FOR_HEADER)) { /* %c begin linkage-only (non-header) code. */
OUT_BEGIN_CODE ();
} elseif (cmd_match (CMD_OK_FOR_HEADER)) { /* %e end linkage-only code. */
OUT_END_CODE ();
} elseif (buf[1] == '#') { /* %# a comment in the skel. ignore. */
} else {
flexfatal (_("bad line in skeleton file"));
}
}
void transition_struct_out (element_v, element_n) int element_v, element_n;
{
/* short circuit any output */ if (!gentables) return;
out_dec2 (" {%4d,%4d },", element_v, element_n);
datapos += TRANS_STRUCT_PRINT_LENGTH;
if (datapos >= 79 - TRANS_STRUCT_PRINT_LENGTH) {
outc ('\n');
if (++dataline % 10 == 0)
outc ('\n');
datapos = 0;
}
}
/* The following is only needed when building flex's parser using certain *brokenversionsofbison.
*/ void *yy_flex_xmalloc (size) int size;
{ void *result = flex_alloc ((size_t) size);
if (!result)
flexfatal (_
("memory allocation failed in yy_flex_xmalloc()"));
return result;
}
/* zero_out - set a region of memory to 0 * *Setsregion_ptr[0]throughregion_ptr[size_in_bytes-1]tozero.
*/
rp = region_ptr;
rp_end = region_ptr + size_in_bytes;
while (rp < rp_end)
*rp++ = 0;
}
/* Remove all '\n' and '\r' characters, if any, from the end of str. *strcanbeanynull-terminatedstring,orNULL.
* returns str. */ char *chomp (str) char *str;
{ char *p = str;
if (!str || !*str) /* s is null or empty string */ return str;
/* find end of string minus one */ while (*p)
++p;
--p;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.