guc-file.c

来自「PostgreSQL7.4.6 for Linux」· C语言 代码 · 共 1,913 行 · 第 1/4 页

C
1,913
字号
	n = len + 2;	buf = (char *) GUC_yy_flex_alloc( n );	if ( ! buf )		YY_FATAL_ERROR( "out of dynamic memory in GUC_yy_scan_bytes()" );	for ( i = 0; i < len; ++i )		buf[i] = bytes[i];	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;	b = GUC_yy_scan_buffer( buf, n );	if ( ! b )		YY_FATAL_ERROR( "bad buffer in GUC_yy_scan_bytes()" );	/* It's okay to grow etc. this buffer, and we should throw it	 * away when we're done.	 */	b->GUC_yy_is_our_buffer = 1;	return b;	}#endif#ifndef YY_NO_PUSH_STATE#ifdef YY_USE_PROTOSstatic void GUC_yy_push_state( int new_state )#elsestatic void GUC_yy_push_state( new_state )int new_state;#endif	{	if ( GUC_yy_start_stack_ptr >= GUC_yy_start_stack_depth )		{		GUC_yy_size_t new_size;		GUC_yy_start_stack_depth += YY_START_STACK_INCR;		new_size = GUC_yy_start_stack_depth * sizeof( int );		if ( ! GUC_yy_start_stack )			GUC_yy_start_stack = (int *) GUC_yy_flex_alloc( new_size );		else			GUC_yy_start_stack = (int *) GUC_yy_flex_realloc(					(void *) GUC_yy_start_stack, new_size );		if ( ! GUC_yy_start_stack )			YY_FATAL_ERROR(			"out of memory expanding start-condition stack" );		}	GUC_yy_start_stack[GUC_yy_start_stack_ptr++] = YY_START;	BEGIN(new_state);	}#endif#ifndef YY_NO_POP_STATEstatic void GUC_yy_pop_state()	{	if ( --GUC_yy_start_stack_ptr < 0 )		YY_FATAL_ERROR( "start-condition stack underflow" );	BEGIN(GUC_yy_start_stack[GUC_yy_start_stack_ptr]);	}#endif#ifndef YY_NO_TOP_STATEstatic int GUC_yy_top_state()	{	return GUC_yy_start_stack[GUC_yy_start_stack_ptr - 1];	}#endif#ifndef YY_EXIT_FAILURE#define YY_EXIT_FAILURE 2#endif#ifdef YY_USE_PROTOSstatic void GUC_yy_fatal_error( GUC_yyconst char msg[] )#elsestatic void GUC_yy_fatal_error( msg )char msg[];#endif	{	(void) fprintf( stderr, "%s\n", msg );	exit( YY_EXIT_FAILURE );	}/* Redefine GUC_yyless() so it works in section 3 code. */#undef GUC_yyless#define GUC_yyless(n) \	do \		{ \		/* Undo effects of setting up GUC_yytext. */ \		GUC_yytext[GUC_yyleng] = GUC_yy_hold_char; \		GUC_yy_c_buf_p = GUC_yytext + n; \		GUC_yy_hold_char = *GUC_yy_c_buf_p; \		*GUC_yy_c_buf_p = '\0'; \		GUC_yyleng = n; \		} \	while ( 0 )/* Internal utility routines. */#ifndef GUC_yytext_ptr#ifdef YY_USE_PROTOSstatic void GUC_yy_flex_strncpy( char *s1, GUC_yyconst char *s2, int n )#elsestatic void GUC_yy_flex_strncpy( s1, s2, n )char *s1;GUC_yyconst char *s2;int n;#endif	{	register int i;	for ( i = 0; i < n; ++i )		s1[i] = s2[i];	}#endif#ifdef YY_NEED_STRLEN#ifdef YY_USE_PROTOSstatic int GUC_yy_flex_strlen( GUC_yyconst char *s )#elsestatic int GUC_yy_flex_strlen( s )GUC_yyconst char *s;#endif	{	register int n;	for ( n = 0; s[n]; ++n )		;	return n;	}#endif#ifdef YY_USE_PROTOSstatic void *GUC_yy_flex_alloc( GUC_yy_size_t size )#elsestatic void *GUC_yy_flex_alloc( size )GUC_yy_size_t size;#endif	{	return (void *) malloc( size );	}#ifdef YY_USE_PROTOSstatic void *GUC_yy_flex_realloc( void *ptr, GUC_yy_size_t size )#elsestatic void *GUC_yy_flex_realloc( ptr, size )void *ptr;GUC_yy_size_t size;#endif	{	/* 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 );	}#ifdef YY_USE_PROTOSstatic void GUC_yy_flex_free( void *ptr )#elsestatic void GUC_yy_flex_free( ptr )void *ptr;#endif	{	free( ptr );	}#if YY_MAINint main()	{	GUC_yylex();	return 0;	}#endif#line 86 "guc-file.l"struct name_value_pair{	char       *name;	char       *value;	struct name_value_pair *next;};/* * Free a list of name/value pairs, including the names and the values */static voidfree_name_value_list(struct name_value_pair * list){	struct name_value_pair *item;	item = list;	while (item)	{		struct name_value_pair *save;		save = item->next;		free(item->name);		free(item->value);		free(item);		item = save;	}}/* * Official function to read and process the configuration file. The * parameter indicates in what context the file is being read * (postmaster startup, backend startup, or SIGHUP). All options * mentioned in the configuration file are set to new values. This * function does not return if an error occurs. If an error occurs, no * values will be changed. */voidProcessConfigFile(GucContext context){	int token, parse_state;	char *opt_name, *opt_value;	char *filename;	struct name_value_pair *item, *head, *tail;	int elevel;	FILE * fp;	Assert(context == PGC_POSTMASTER || context == PGC_BACKEND 		|| context == PGC_SIGHUP);	Assert(DataDir);	elevel = (context == PGC_SIGHUP) ? DEBUG4 : ERROR;	/*	 * Open file	 */	filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);	if (filename == NULL)	{		ereport(elevel,				(errcode(ERRCODE_OUT_OF_MEMORY),				 errmsg("out of memory")));		return;	}	sprintf(filename, "%s/" CONFIG_FILENAME, DataDir);    fp = AllocateFile(filename, "r");    if (!fp)    {		free(filename);        /* File not found is fine */        if (errno != ENOENT)            ereport(elevel,					(errcode_for_file_access(),					 errmsg("could not open configuration file \"%s\": %m", CONFIG_FILENAME)));		return;    }	/*	 * Parse	 */	GUC_yyin = fp;    parse_state = 0;	head = tail = NULL;	opt_name = opt_value = NULL;    while ((token = GUC_yylex()))        switch(parse_state)        {            case 0: /* no previous input */                if (token == GUC_EOL) /* empty line */                    continue;                if (token != GUC_ID)                    goto parse_error;                opt_name = strdup(GUC_yytext);				if (opt_name == NULL)					goto out_of_memory;                parse_state = 1;                break;            case 1: /* found name */                /* ignore equals sign */                if (token == GUC_EQUALS)                    token = GUC_yylex();                if (token != GUC_ID && token != GUC_STRING && 					token != GUC_INTEGER && token != GUC_REAL && 					token != GUC_UNQUOTED_STRING)                    goto parse_error;                opt_value = strdup(GUC_yytext);				if (opt_value == NULL)					goto out_of_memory;				if (token == GUC_STRING)				{					/* remove the beginning and ending quote/apostrophe */					/* first: shift the whole thing down one character */					memmove(opt_value,opt_value+1,strlen(opt_value)-1);					/* second: null out the 2 characters we shifted */					opt_value[strlen(opt_value)-2]='\0';					/* do the escape thing.  free()'s the strdup above */					opt_value=GUC_scanstr(opt_value);				}                parse_state = 2;                break;            case 2: /* now we'd like an end of line */				if (token != GUC_EOL)					goto parse_error;				/* append to list */				item = malloc(sizeof *item);				if (item == NULL)					goto out_of_memory;				item->name = opt_name;				item->value = opt_value;				item->next = NULL;				if (!head)					tail = head = item;				else				{					tail->next = item;					tail = item;				}                parse_state = 0;                break;        }	FreeFile(fp);	free(filename);	/*	 * Check if all options are valid	 */    for(item = head; item; item=item->next)	{		if (!set_config_option(item->name, item->value, context,							   PGC_S_FILE, false, false))			goto cleanup_exit;	}    /* If we got here all the options parsed okay. */	for(item = head; item; item=item->next)		set_config_option(item->name, item->value, context,						  PGC_S_FILE, false, true); cleanup_exit:	free_name_value_list(head);	return; parse_error:	FreeFile(fp);	free(filename);	free_name_value_list(head);	ereport(elevel,			(errcode(ERRCODE_SYNTAX_ERROR),			 errmsg("syntax error in file \"%s\" line %u, near token \"%s\"", 					CONFIG_FILENAME, ConfigFileLineno, GUC_yytext)));	return; out_of_memory:	FreeFile(fp);	free(filename);	free_name_value_list(head);	ereport(elevel,			(errcode(ERRCODE_OUT_OF_MEMORY),			 errmsg("out of memory")));	return;}/* ---------------- *		scanstr * * if the string passed in has escaped codes, map the escape codes to actual * chars * * the string returned is malloc'd and should eventually be free'd by the * caller! * ---------------- */char *GUC_scanstr(char *s){	char	   *newStr;	int			len,				i,				j;	if (s == NULL || s[0] == '\0')	{		if (s != NULL)			free(s);		return strdup("");	}	len = strlen(s);	newStr = malloc(len + 1);	/* string cannot get longer */	if (newStr == NULL)		ereport(FATAL,				(errcode(ERRCODE_OUT_OF_MEMORY),				 errmsg("out of memory")));	for (i = 0, j = 0; i < len; i++)	{		if (s[i] == '\\')		{			i++;			switch (s[i])			{				case 'b':					newStr[j] = '\b';					break;				case 'f':					newStr[j] = '\f';					break;				case 'n':					newStr[j] = '\n';					break;				case 'r':					newStr[j] = '\r';					break;				case 't':					newStr[j] = '\t';					break;				case '0':				case '1':				case '2':				case '3':				case '4':				case '5':				case '6':				case '7':					{						int			k;						long		octVal = 0;						for (k = 0;							 s[i + k] >= '0' && s[i + k] <= '7' && k < 3;							 k++)							octVal = (octVal << 3) + (s[i + k] - '0');						i += k - 1;						newStr[j] = ((char) octVal);					}					break;				default:					newStr[j] = s[i];					break;				}			}					/* switch */		else			newStr[j] = s[i];		j++;	}	newStr[j] = '\0';	free(s);	return newStr;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?