void prs_stream( FILE *str, const char *name ) { yyin = str; src_new_file( name ); yydebug = _prs_debug_flag; yyparse(); }
void src_cpp_line( const char *line, int length ) { arg_List args; char *tmp = alloca( length + 1 ); int lineno; strncpy( tmp, line, length ); tmp [ length ] = '\0'; args = arg_argify( tmp, 0 ); if ((lineno = atoi( arg_get( args, 1 ) )) > 0) --lineno; else lineno = 1; src_new_line( lineno ); /* FIXME! This is debugging cruft to be removed. */ if (arg_count( args ) == 2) { PRINTF(MAA_SRC,( "lineno %s\n", arg_get( args, 1 ) )); } else { PRINTF(MAA_SRC,( "lineno %s in %s\n", arg_get( args, 1 ), arg_get( args, 2 ) )); src_new_file( arg_get( args, 2 ) ); } arg_destroy( args ); }
void prs_file_nocpp( const char *filename ) { if (!filename) err_fatal( "%s No filename specified\n", __func__ ); if (!(yyin = fopen( filename, "r" ))) err_fatal_errno( "%s Cannot open \"%s\" for read\n", __func__, filename ); src_new_file( filename ); yydebug = _prs_debug_flag; yyparse(); fclose( yyin ); }
void prs_file( const char *filename ) { char *buffer; const char **pt; static const char *cpp = NULL; static const char *cpps[] = { "/lib/cpp", "/usr/lib/cpp", "/usr/ccs/lib/cpp", /* Solaris */ "/usr/lang/cpp", 0 }; static const char *extra_options = ""; FILE *tmp; if (!filename) err_fatal( __FUNCTION__, "No filename specified\n" ); if (!cpp) { if ((cpp = getenv( "KHEPERA_CPP" ))) { PRINTF(MAA_PARSE,("%s: Using KHEPERA_CPP from %s\n",__func__,cpp)); } /* Always look for gcc's cpp first, since we know it is ANSI C compliant. */ if (!cpp && (tmp = popen( "gcc -print-file-name=cpp", "r" ))) { char buf[1024]; char *t; if (fread( buf, 1, 1023, tmp ) > 0) { if ((t = strchr( buf, '\n' ))) *t = '\0'; PRINTF(MAA_PARSE,("%s: Using GNU cpp from %s\n",__func__,buf)); cpp = str_find( buf ); extra_options = "-nostdinc -nostdinc++"; } pclose( tmp ); } /* Then look for the vendor's cpp, which may or may not be useful (e.g., on SunOS 4.x machines, it isn't ANSI C compatible. Considering ANSI C is C89, and this is 1996, one might think that Sun would have fixed this... */ if (!cpp) { for (pt = cpps; **pt; pt++) { if (!access( *pt, X_OK )) { PRINTF(MAA_PARSE, ("%s: Using system cpp from %s\n",__func__,*pt)); cpp = *pt; break; } } } if (!cpp) err_fatal("%s:Cannot locate cpp -- set KHEPERA_CPP to cpp's path\n", __func__ ); } buffer = alloca( strlen( cpp ) + sizeof( filename ) + (_prs_cpp_options ? strlen( _prs_cpp_options ) : 0) + 100 ); sprintf( buffer, "%s -I. %s %s 2>/dev/null", cpp, _prs_cpp_options ? _prs_cpp_options : "", filename ); PRINTF(MAA_PARSE,("%s: %s\n",__func__,buffer)); if (!(yyin = popen( buffer, "r" ))) err_fatal_errno("%s Cannot open \"%s\" for read\n", __func__, filename ); src_new_file( filename ); yydebug = _prs_debug_flag; yyparse(); pclose( yyin ); }