⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 param.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
字号:
#include "afx.h"


void parse_params( char *env, char *cfgfile, char *argv[], int argc ) {
	int i;

	if ( env ) {
		char *val = getenv( env );
		if ( val )
			parse_param_line( val );
	}
	if ( cfgfile ) {
		char *cfg = xfind( cfgfile, getrundir());
#if DEBUG
		printf( "*** ConfigFile '%s'\n", cfg );
#endif
		parse_param_file( cfg );
	}
	for (i = 1; i < argc; i++)
		parse_param( argv[i] );
}


void parse_param_line( char *s ) {
	static char a[ LINE_MAX ];
	int i;

	assert( s != NULL );
	while(1) {
		while ( *s && isspace(*s) )	/* skip spaces */
			s++;
		if ( !*s )	/* end of line */
			return;
		if ( *s == '\"') {	/* " */
			s++;
			i = 0;
			while ( *s && *s != '\"' )
				a[i++] = *s, s++;
			a[i] = 0;
            parse_param(a);
            if (!*s)
            	return;
			s++;
		} else {
			i = 0;
			while ( *s && !isspace(*s))
				a[i++] = *s, s++;
			a[i] = 0;
			parse_param(a);
		}
	}
}

void scan_env(char *output,char *string)
{
   char name[256],*p ;
   while (*string) {
      if (*string == '%') {
         p = name ;
         string++ ;
         while (*string && *string != '%')
            *p++ = *string++ ;
         if (*string)
            string++ ;
         *p = 0 ;
         p = getenv(name) ;
         if (p) {
            strcpy(output,p) ;
            output += strlen(output) ;
         }

      } else
         *output++ = *string++ ;
   }
   *output = 0 ;
}

void parse_param_file( char *file ) {
   static char line1[ LINE_MAX ];
   static char line[ LINE_MAX ] ;
	FILE *fp;
	assert( file != NULL );
   fp = fopen( file, "rt" );
	if (fp) {
		while( fgets( line, LINE_MAX-1, fp ) ) {
			int len = strlen( line );
			if ( len > 0 && line[len-1] == '\n' )
				line[len-1] = '\0';
         scan_env(line1, line) ;
         parse_param_line( line1 );
		}
		fclose( fp );
	} else {
		perror( file );
	}
}


void parse_param( char *param ) {
	assert( param != NULL );
	if ( param[0] == '@' ) {
		parse_param_file( param+1 );
	} else if ( param[0] == '-' || param[0] == '/' || param[0] == '+' ) {
		option( param );
	} else {
		source( param );
	}
}

⌨️ 快捷键说明

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