📄 lex.zconf.c_shipped
字号:
* @return the allocated buffer state. */ YY_BUFFER_STATE zconf_create_buffer (FILE * file, int size ){ YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) zconfalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in zconf_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) zconfalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in zconf_create_buffer()" ); b->yy_is_our_buffer = 1; zconf_init_buffer(b,file ); return b;}/** Destroy the buffer. * @param b a buffer created with zconf_create_buffer() * */ void zconf_delete_buffer (YY_BUFFER_STATE b ){ if ( ! b ) return; if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) zconffree((void *) b->yy_ch_buf ); zconffree((void *) b );}/* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a zconfrestart() or at EOF. */ static void zconf_init_buffer (YY_BUFFER_STATE b, FILE * file ){ int oerrno = errno; zconf_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then zconf_init_buffer was _probably_ * called from zconfrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = 0; errno = oerrno;}/** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * */ void zconf_flush_buffer (YY_BUFFER_STATE b ){ if ( ! b ) return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) zconf_load_buffer_state( );}/** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. * */void zconfpush_buffer_state (YY_BUFFER_STATE new_buffer ){ if (new_buffer == NULL) return; zconfensure_buffer_stack(); /* This block is copied from zconf_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from zconf_switch_to_buffer. */ zconf_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1;}/** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */void zconfpop_buffer_state (void){ if (!YY_CURRENT_BUFFER) return; zconf_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { zconf_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; }}/* Allocates the stack if it does not exist. * Guarantees space for at least one push. */static void zconfensure_buffer_stack (void){ int num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)zconfalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)zconfrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; }}/** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */YY_BUFFER_STATE zconf_scan_buffer (char * base, yy_size_t size ){ YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) zconfalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in zconf_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; zconf_switch_to_buffer(b ); return b;}/** Setup the input buffer state to scan a string. The next call to zconflex() will * scan from a @e copy of @a str. * @param yy_str a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * zconf_scan_bytes() instead. */YY_BUFFER_STATE zconf_scan_string (yyconst char * yy_str ){ return zconf_scan_bytes(yy_str,strlen(yy_str) );}/** Setup the input buffer state to scan the given bytes. The next call to zconflex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */YY_BUFFER_STATE zconf_scan_bytes (yyconst char * bytes, int len ){ YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = len + 2; buf = (char *) zconfalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in zconf_scan_bytes()" ); for ( i = 0; i < len; ++i ) buf[i] = bytes[i]; buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; b = zconf_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in zconf_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b;}#ifndef YY_EXIT_FAILURE#define YY_EXIT_FAILURE 2#endifstatic void yy_fatal_error (yyconst char* msg ){ (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE );}/* Redefine yyless() so it works in section 3 code. */#undef yyless#define yyless(n) \ do \ { \ /* Undo effects of setting up zconftext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ zconftext[zconfleng] = (yy_hold_char); \ (yy_c_buf_p) = zconftext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ zconfleng = yyless_macro_arg; \ } \ while ( 0 )/* Accessor methods (get/set functions) to struct members. *//** Get the current line number. * */int zconfget_lineno (void){ return zconflineno;}/** Get the input stream. * */FILE *zconfget_in (void){ return zconfin;}/** Get the output stream. * */FILE *zconfget_out (void){ return zconfout;}/** Get the length of the current token. * */int zconfget_leng (void){ return zconfleng;}/** Get the current token. * */char *zconfget_text (void){ return zconftext;}/** Set the current line number. * @param line_number * */void zconfset_lineno (int line_number ){ zconflineno = line_number;}/** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see zconf_switch_to_buffer */void zconfset_in (FILE * in_str ){ zconfin = in_str ;}void zconfset_out (FILE * out_str ){ zconfout = out_str ;}int zconfget_debug (void){ return zconf_flex_debug;}void zconfset_debug (int bdebug ){ zconf_flex_debug = bdebug ;}/* zconflex_destroy is for both reentrant and non-reentrant scanners. */int zconflex_destroy (void){ /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ zconf_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; zconfpop_buffer_state(); } /* Destroy the stack itself. */ zconffree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; return 0;}/* * Internal utility routines. */#ifndef yytext_ptrstatic void yy_flex_strncpy (char* s1, yyconst char * s2, int n ){ register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i];}#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen (yyconst char * s ){ register int n; for ( n = 0; s[n]; ++n ) ; return n;}#endifvoid *zconfalloc (yy_size_t size ){ return (void *) malloc( size );}void *zconfrealloc (void * ptr, yy_size_t size ){ /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size );}void zconffree (void * ptr ){ free( (char *) ptr ); /* see zconfrealloc() for (char *) cast */}#define YYTABLES_NAME "yytables"#undef YY_NEW_FILE#undef YY_FLUSH_BUFFER#undef yy_set_bol#undef yy_new_buffer#undef yy_set_interactive#undef yytext_ptr#undef YY_DO_BEFORE_ACTION#ifdef YY_DECL_IS_OURS#undef YY_DECL_IS_OURS#undef YY_DECL#endifvoid zconf_starthelp(void){ new_string(); last_ts = first_ts = 0; BEGIN(HELP);}static void zconf_endhelp(void){ zconflval.string = text; BEGIN(INITIAL);}/* * Try to open specified file with following names: * ./name * $(srctree)/name * The latter is used when srctree is separate from objtree * when compiling the kernel. * Return NULL if file is not found. */FILE *zconf_fopen(const char *name){ char *env, fullname[PATH_MAX+1]; FILE *f; f = fopen(name, "r"); if (!f && name[0] != '/') { env = getenv(SRCTREE); if (env) { sprintf(fullname, "%s/%s", env, name); f = fopen(fullname, "r"); } } return f;}void zconf_initscan(const char *name){ zconfin = zconf_fopen(name); if (!zconfin) { printf("can't find file %s\n", name); exit(1); } current_buf = malloc(sizeof(*current_buf)); memset(current_buf, 0, sizeof(*current_buf)); current_file = file_lookup(name); current_file->lineno = 1; current_file->flags = FILE_BUSY;}void zconf_nextfile(const char *name){ struct file *file = file_lookup(name); struct buffer *buf = malloc(sizeof(*buf)); memset(buf, 0, sizeof(*buf)); current_buf->state = YY_CURRENT_BUFFER; zconfin = zconf_fopen(name); if (!zconfin) { printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); exit(1); } zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE)); buf->parent = current_buf; current_buf = buf; if (file->flags & FILE_BUSY) { printf("recursive scan (%s)?\n", name); exit(1); } if (file->flags & FILE_SCANNED) { printf("file %s already scanned?\n", name); exit(1); } file->flags |= FILE_BUSY; file->lineno = 1; file->parent = current_file; current_file = file;}static void zconf_endfile(void){ struct buffer *parent; current_file->flags |= FILE_SCANNED; current_file->flags &= ~FILE_BUSY; current_file = current_file->parent; parent = current_buf->parent; if (parent) { fclose(zconfin); zconf_delete_buffer(YY_CURRENT_BUFFER); zconf_switch_to_buffer(parent->state); } free(current_buf); current_buf = parent;}int zconf_lineno(void){ return current_pos.lineno;}char *zconf_curname(void){ return current_pos.file ? current_pos.file->name : "<none>";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -