📄 pgc.l
字号:
<C,xskip>{exec_sql}{else}{space}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */ if (stacked_if_value[preproc_tos].else_branch) mmerror(PARSE_ERROR, ET_FATAL, "Duplicated 'EXEC SQL ELSE;'"); else { stacked_if_value[preproc_tos].else_branch = TRUE; stacked_if_value[preproc_tos].condition = (stacked_if_value[preproc_tos-1].condition && !stacked_if_value[preproc_tos].condition); if (stacked_if_value[preproc_tos].condition) BEGIN(C); else BEGIN(xskip); } }<C,xskip>{informix_special}{else}{space}* { /* are we simulating Informix? */ if (INFORMIX_MODE) { if (stacked_if_value[preproc_tos].else_branch) mmerror(PARSE_ERROR, ET_FATAL, "Duplicated 'EXEC SQL ELSE;'"); else { stacked_if_value[preproc_tos].else_branch = TRUE; stacked_if_value[preproc_tos].condition = (stacked_if_value[preproc_tos-1].condition && !stacked_if_value[preproc_tos].condition); if (stacked_if_value[preproc_tos].condition) BEGIN(C); else BEGIN(xskip); } } else { yyless(1); return (S_ANYTHING); } }<C,xskip>{exec_sql}{endif}{space}*";" { if (preproc_tos == 0) mmerror(PARSE_ERROR, ET_FATAL, "Unmatched 'EXEC SQL ENDIF;'"); else preproc_tos--; if (stacked_if_value[preproc_tos].condition) BEGIN(C); else BEGIN(xskip); }<C,xskip>{informix_special}{endif}{space}*";" { /* are we simulating Informix? */ if (INFORMIX_MODE) { if (preproc_tos == 0) mmerror(PARSE_ERROR, ET_FATAL, "Unmatched 'EXEC SQL ENDIF;'"); else preproc_tos--; if (stacked_if_value[preproc_tos].condition) BEGIN(C); else BEGIN(xskip); } else { yyless(1); return (S_ANYTHING); } }<xskip>{other} { /* ignore */ }<xcond>{identifier}{space}*";" { if (preproc_tos >= MAX_NESTED_IF-1) mmerror(PARSE_ERROR, ET_FATAL, "Too many nested 'EXEC SQL IFDEF' conditions"); else { struct _defines *defptr; unsigned int i; /* * Skip the ";" and trailing whitespace. Note that yytext * contains at least one non-space character plus the ";" */ for (i = strlen(yytext)-2; i > 0 && ecpg_isspace(yytext[i]); i-- ) ; yytext[i+1] = '\0'; for (defptr = defines; defptr != NULL && strcmp(yytext, defptr->old) != 0; defptr = defptr->next); preproc_tos++; stacked_if_value[preproc_tos].else_branch = FALSE; stacked_if_value[preproc_tos].condition = (defptr ? ifcond : !ifcond) && stacked_if_value[preproc_tos-1].condition; } if (stacked_if_value[preproc_tos].condition) BEGIN(C); else BEGIN(xskip); }<xcond>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command"); yyterminate(); }<def_ident>{identifier} { old = mm_strdup(yytext); BEGIN(def); startlit(); }<def_ident>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command"); yyterminate(); } <def>{space}*";" { struct _defines *ptr, *this; for (ptr = defines; ptr != NULL; ptr = ptr->next) { if (strcmp(old, ptr->old) == 0) { free(ptr->new); ptr->new = mm_strdup(literalbuf); } } if (ptr == NULL) { this = (struct _defines *) mm_alloc(sizeof(struct _defines)); /* initial definition */ this->old = old; this->new = mm_strdup(literalbuf); this->next = defines; this->used = NULL; defines = this; } BEGIN(C); }<def>[^;] { addlit(yytext, yyleng); }<incl>\<[^\>]+\>{space}*";"? { parse_include(); }<incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); }<incl>[^;\<\>\"]+";" { parse_include(); }<incl>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command"); yyterminate(); }<<EOF>> { if (yy_buffer == NULL) { if ( preproc_tos > 0 ) { preproc_tos = 0; mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'"); } yyterminate(); } else { struct _yy_buffer *yb = yy_buffer; int i; struct _defines *ptr; for (ptr = defines; ptr; ptr = ptr->next) if (ptr->used == yy_buffer) { ptr->used = NULL; break; } if (yyin != NULL) fclose(yyin); yy_delete_buffer( YY_CURRENT_BUFFER ); yy_switch_to_buffer(yy_buffer->buffer); yylineno = yy_buffer->lineno; /* We have to output the filename only if we change files here */ i = strcmp(input_filename, yy_buffer->filename); free(input_filename); input_filename = yy_buffer->filename; yy_buffer = yy_buffer->next; free(yb); if (i != 0) output_line_number(); } }<INITIAL>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "Internal error: unreachable state, please inform pgsql-bugs@postgresql.org"); }%%voidlex_init(void){ braces_open = 0; preproc_tos = 0; yylineno = 1; ifcond = TRUE; stacked_if_value[preproc_tos].condition = ifcond; stacked_if_value[preproc_tos].else_branch = FALSE; /* initialize literal buffer to a reasonable but expansible size */ if (literalbuf == NULL) { literalalloc = 1024; literalbuf = (char *) malloc(literalalloc); } startlit(); BEGIN(C);}static voidaddlit(char *ytext, int yleng){ /* enlarge buffer if needed */ if ((literallen+yleng) >= literalalloc) { do literalalloc *= 2; while ((literallen+yleng) >= literalalloc); literalbuf = (char *) realloc(literalbuf, literalalloc); } /* append new data, add trailing null */ memcpy(literalbuf+literallen, ytext, yleng); literallen += yleng; literalbuf[literallen] = '\0';}static voidaddlitchar(unsigned char ychar){ /* enlarge buffer if needed */ if ((literallen+1) >= literalalloc) { literalalloc *= 2; literalbuf = (char *) realloc(literalbuf, literalalloc); } /* append new data, add trailing null */ literalbuf[literallen] = ychar; literallen += 1; literalbuf[literallen] = '\0';}static voidparse_include(void){ /* got the include file name */ struct _yy_buffer *yb; struct _include_path *ip; char inc_file[MAXPGPATH]; unsigned int i; yb = mm_alloc(sizeof(struct _yy_buffer)); yb->buffer = YY_CURRENT_BUFFER; yb->lineno = yylineno; yb->filename = input_filename; yb->next = yy_buffer; yy_buffer = yb; /* * skip the ";" if there is one and trailing whitespace. Note that * yytext contains at least one non-space character plus the ";" */ for (i = strlen(yytext)-2; i > 0 && ecpg_isspace(yytext[i]); i--) ; if (yytext[i] == ';') i--; yytext[i+1] = '\0'; yyin = NULL; /* If file name is enclosed in '"' remove these and look only in '.' */ /* Informix does look into all include paths though, except filename starts with '/' */ if (yytext[0] == '"' && yytext[i] == '"' && ((compat != ECPG_COMPAT_INFORMIX && compat != ECPG_COMPAT_INFORMIX_SE) || yytext[1] == '/')) { yytext[i] = '\0'; memmove(yytext, yytext+1, strlen(yytext)); strncpy(inc_file, yytext, sizeof(inc_file)); yyin = fopen(inc_file, "r"); if (!yyin) { if (strcmp(inc_file + strlen(inc_file) - 2, ".h")) { strcat(inc_file, ".h"); yyin = fopen(inc_file, "r"); } } } else { if ((yytext[0] == '"' && yytext[i] == '"') || (yytext[0] == '<' && yytext[i] == '>')) { yytext[i] = '\0'; memmove(yytext, yytext+1, strlen(yytext)); } for (ip = include_paths; yyin == NULL && ip != NULL; ip = ip->next) { if (strlen(ip->path) + strlen(yytext) + 3 > MAXPGPATH) { fprintf(stderr, "Error: Path %s/%s is too long in line %d, skipping.\n", ip->path, yytext, yylineno); continue; } snprintf (inc_file, sizeof(inc_file), "%s/%s", ip->path, yytext); yyin = fopen(inc_file, "r"); if (!yyin) { if (strcmp(inc_file + strlen(inc_file) - 2, ".h")) { strcat(inc_file, ".h"); yyin = fopen( inc_file, "r" ); } } } } if (!yyin) mmerror(NO_INCLUDE_FILE, ET_FATAL, "Cannot open include file %s in line %d\n", yytext, yylineno); input_filename = mm_strdup(inc_file); yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE )); yylineno = 1; output_line_number(); BEGIN(C);}/* * ecpg_isspace() --- return TRUE if flex scanner considers char whitespace */static boolecpg_isspace(char ch){ if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\f') return true; return false;}static bool isdefine(void){ struct _defines *ptr; /* is it a define? */ for (ptr = defines; ptr; ptr = ptr->next) { if (strcmp(yytext, ptr->old) == 0 && ptr->used == NULL) { struct _yy_buffer *yb; yb = mm_alloc(sizeof(struct _yy_buffer)); yb->buffer = YY_CURRENT_BUFFER; yb->lineno = yylineno; yb->filename = mm_strdup(input_filename); yb->next = yy_buffer; ptr->used = yy_buffer = yb; yy_scan_string(ptr->new); return true; } } return false;}static bool isinformixdefine(void){ const char *new = NULL; if (strcmp(yytext, "dec_t") == 0) new = "decimal"; else if (strcmp(yytext, "intrvl_t") == 0) new = "interval"; else if (strcmp(yytext, "dtime_t") == 0) new = "timestamp"; if (new) { struct _yy_buffer *yb; yb = mm_alloc(sizeof(struct _yy_buffer)); yb->buffer = YY_CURRENT_BUFFER; yb->lineno = yylineno; yb->filename = mm_strdup(input_filename); yb->next = yy_buffer; yy_buffer = yb; yy_scan_string(new); return true; } return false;}/* * Called before any actual parsing is done */voidscanner_init(const char *str){ Size slen = strlen(str); /* * Might be left over after ereport() */ if (YY_CURRENT_BUFFER) yy_delete_buffer(YY_CURRENT_BUFFER); /* * Make a scan buffer with special termination needed by flex. */ scanbuf = mm_alloc(slen + 2); memcpy(scanbuf, str, slen); scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; scanbufhandle = yy_scan_buffer(scanbuf, slen + 2); /* initialize literal buffer to a reasonable but expansible size */ literalalloc = 128; literalbuf = (char *) mm_alloc(literalalloc); startlit(); BEGIN(INITIAL);}/* * Called after parsing is done to clean up after scanner_init() */voidscanner_finish(void){ yy_delete_buffer(scanbufhandle); free(scanbuf);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -