📄 misc.c
字号:
action_offset = prolog_offset = action_index; action_array[action_index] = '\0'; }/* mark_prolog - mark the current position in the action array as * representing the end of the action prolog */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 * * Generates a data statement initializing the current 2-D array to "value". */void mk2data( value )int value; { if ( datapos >= NUMDATAITEMS ) { outc( ',' ); dataflush(); } if ( datapos == 0 ) /* Indent. */ out( " " ); else outc( ',' ); ++datapos; out_dec( "%5d", value ); }/* mkdata - generate a data statement * * Generates a data statement initializing the current array element to * "value". */void mkdata( value )int value; { 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 )char array[]; { int val = 0; (void) sscanf( array, "%d", &val ); return val; }/* myesc - return character corresponding to escape sequence */Char myesc( array )Char array[]; { Char c, esc_char; switch ( array[1] ) { case 'b': return '\b'; case 'f': return '\f'; case 'n': return '\n'; case 'r': return '\r'; case 't': return '\t';#if __STDC__ case 'a': return '\a'; case 'v': return '\v';#else case 'a': return '\007'; case 'v': return '\013';#endif case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { /* \<octal> */ int sptr = 1; while ( isascii( array[sptr] ) && isdigit( array[sptr] ) ) /* Don't increment inside loop control * because if isdigit() is a macro it might * expand into multiple increments ... */ ++sptr; c = array[sptr]; array[sptr] = '\0'; esc_char = otoi( array + 1 ); array[sptr] = c; return esc_char; } case 'x': { /* \x<hex> */ int sptr = 2; while ( isascii( array[sptr] ) && isxdigit( (char) array[sptr] ) ) /* Don't increment inside loop control * because if isdigit() is a macro it might * expand into multiple increments ... */ ++sptr; c = array[sptr]; array[sptr] = '\0'; esc_char = htoi( array + 2 ); array[sptr] = c; return esc_char; } default: return array[1]; } }/* otoi - convert an octal digit string to an integer value */int otoi( str )Char str[]; { unsigned int result; (void) sscanf( (char *) str, "%o", &result ); return result; }/* out - various flavors of outputing a (possibly formatted) string for the * generated scanner, keeping track of the line count. */void out( str )const char str[]; { fputs( str, stdout ); out_line_count( str ); }void out_dec( fmt, n )const char fmt[];int n; { printf( fmt, n ); out_line_count( fmt ); }void out_dec2( fmt, n1, n2 )const char fmt[];int n1, n2; { printf( fmt, n1, n2 ); out_line_count( fmt ); }void out_hex( fmt, x )const char fmt[];unsigned int x; { printf( fmt, x ); out_line_count( fmt ); }void out_line_count( str )const char str[]; { register int i; for ( i = 0; str[i]; ++i ) if ( str[i] == '\n' ) ++out_linenum; }void out_str( fmt, str )const char fmt[], str[]; { printf( fmt, str ); out_line_count( fmt ); out_line_count( str ); }void out_str3( fmt, s1, s2, s3 )const char fmt[], s1[], s2[], s3[]; { printf( fmt, s1, s2, s3 ); out_line_count( fmt ); out_line_count( s1 ); out_line_count( s2 ); out_line_count( s3 ); }void out_str_dec( fmt, str, n )const char fmt[], str[];int n; { printf( fmt, str, n ); out_line_count( fmt ); out_line_count( str ); }void outc( c )int c; { putc( c, stdout ); if ( c == '\n' ) ++out_linenum; }void outn( str )const char str[]; { puts( str ); out_line_count( str ); ++out_linenum; }/* readable_form - return the the human-readable form of a character * * The returned string is in static storage. */char *readable_form( c )register int c; { static char rform[10]; if ( (c >= 0 && c < 32) || c >= 127 ) { switch ( c ) { case '\b': return "\\b"; case '\f': return "\\f"; case '\n': return "\\n"; case '\r': return "\\r"; case '\t': return "\\t";#if __STDC__ case '\a': return "\\a"; case '\v': return "\\v";#endif default: (void) sprintf( rform, "\\%.3o", (unsigned int) c ); return rform; } } else if ( c == ' ' ) return "' '"; else { rform[0] = c; rform[1] = '\0'; return rform; } }/* reallocate_array - increase the size of a dynamic array */void *reallocate_array( array, size, element_size )void *array;int size;size_t element_size; { register void *new_array; size_t num_bytes = element_size * size; 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 * Copies skelfile or skel array to stdout until a line beginning with * "%%" or EOF is found. */void skelout() { char buf_storage[MAXLINE]; char *buf = buf_storage; int do_copy = 1; /* Loop pulling lines either from the skelfile, if we're using * one, or from the skel[] array. */ while ( skelfile ? (fgets( buf, MAXLINE, skelfile ) != NULL) : ((buf = (char *) skel[skel_ind++]) != 0) ) { /* copy from skel array */ if ( buf[0] == '%' ) { /* control line */ switch ( buf[1] ) { case '%': return; case '+': do_copy = C_plus_plus; break; case '-': do_copy = ! C_plus_plus; break; case '*': do_copy = 1; break; default: flexfatal( _( "bad line in skeleton file" ) ); } } else if ( do_copy ) { if ( skelfile ) /* Skeleton file reads include final * newline, skel[] array does not. */ out( buf ); else outn( buf ); } } }/* transition_struct_out - output a yy_trans_info structure * * outputs the yy_trans_info structure with the two elements, element_v and * element_n. Formats the output with spaces and carriage returns. */void transition_struct_out( element_v, element_n )int element_v, element_n; { 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 * broken versions of bison. */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 * * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero. */void zero_out( region_ptr, size_in_bytes )char *region_ptr;size_t size_in_bytes; { register char *rp, *rp_end; rp = region_ptr; rp_end = region_ptr + size_in_bytes; while ( rp < rp_end ) *rp++ = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -