static bool openSrc( // ATTEMPT TO OPEN FILE char *name, // - file name enum file_type typ ) // - type of file being opened { pch_absorb pch_OK; // - pre-compiled header load status FILE *fp; // - file pointer #ifdef OPT_BR bool might_browse; // - true ==> might browse, if right file type #endif if( SrcFileProcessOnce( name ) ) { SrcFileOpen( NULL, name ); return( TRUE ); } fp = SrcFileFOpen( name, SFO_SOURCE_FILE ); if( fp == NULL ) { return( FALSE ); } #ifdef OPT_BR might_browse = FALSE; #endif if( CompFlags.watch_for_pcheader ) { CompFlags.watch_for_pcheader = FALSE; pch_OK = PCHeaderAbsorb( name ); if( pch_OK != PCHA_OK ) { SrcFileSetCreatePCHeader(); SrcFileOpen( fp, name ); #ifdef OPT_BR might_browse = TRUE; #endif } else { SrcFileOpen( NULL, name ); fclose( fp ); } } else { SrcFileOpen( fp, name ); if( typ == FT_SRC ) { SetSrcFilePrimary(); } #ifdef OPT_BR might_browse = TRUE; #endif } #ifdef OPT_BR if( might_browse ) switch( typ ) { case FT_SRC : case FT_LIBRARY : case FT_HEADER : BrinfOpenSource( SrcFileCurrent() ); break; } #endif return( TRUE ); }
static boolean doIoSuppOpenSrc( // OPEN A SOURCE FILE (PRIMARY,HEADER) struct path_descr *fd, // - descriptor for file name enum file_type typ ) // - type of search path to use { char **paths; // - optional paths to prepend char **exts; // - optional extensions to append boolean retn; // - return: TRUE ==> opened char *path; // - next path char bufpth[ _MAX_PATH ]; // - buffer for next path SRCFILE curr; // - current included file SRCFILE stdin_srcfile; // - srcfile for stdin struct path_descr idescr; // - descriptor for included file LINE_NO dummy; // - dummy line number holder char prevpth[ _MAX_PATH ]; // - buffer for previous path switch( typ ) { case FT_SRC: if( fd->fnm[0] == '\0' && fd->ext[0] == '.' && fd->ext[1] == '\0' ) { if( ErrCount != 0 ) { // command line errors may result in "." as the input name // so the user thinks that the compiler is hung! return( FALSE ); } WholeFName = FNameAdd( "stdin" ); stdin_srcfile = SrcFileOpen( stdin, WholeFName ); SrcFileNotAFile( stdin_srcfile ); goto file_was_found; } paths = pathSrc; exts = extsSrc; break; case FT_HEADER: case FT_LIBRARY: if( !CompFlags.ignore_current_dir ) { paths = pathHdr; } else { paths = NULL; } exts = extsHdr; break; case FT_CMD: paths = pathCmd; exts = extsCmd; break; } switch( typ ) { case FT_LIBRARY: if( fd->drv[0] != '\0' || IS_DIR_SEP( fd->dir[0] ) ) { retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; } break; case FT_HEADER: // even if ignoreing current dir, have to look for absolute paths if( !CompFlags.ignore_current_dir || fd->drv[0] != '\0' ) { // look in current directory retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; } /* check directories of currently included files */ if( !IS_PATH_SEP( fd->dir[0] ) ) { prevpth[0] = '\xff'; /* to make it not compare with anything else */ prevpth[1] = '\0'; curr = SrcFileCurrent(); for( ;; ) { if( curr == NULL ) break; splitFileName( SrcFileName( curr ), &idescr ); _makepath( bufpth, idescr.drv, idescr.dir, NULL, NULL ); /*optimization: don't try and open if in previously checked dir*/ if( strcmp( bufpth, prevpth ) != 0 ) { retn = openSrcPath( bufpth, exts, fd, FT_HEADER ); if( retn ) goto file_was_found; } curr = SrcFileIncluded( curr, &dummy ); strcpy( prevpth, bufpth ); } } break; case FT_SRC: case FT_CMD: retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; break; } switch( typ ) { case FT_HEADER: case FT_LIBRARY: HFileListStart(); for( ; ; ) { HFileListNext( bufpth ); if( *bufpth == '\0' ) break; retn = openSrcPath( bufpth, exts, fd, typ ); if( retn ) goto file_was_found; } break; } switch( typ ) { case FT_HEADER: case FT_CMD: case FT_SRC: if( IS_PATH_SEP( fd->dir[0] ) ) { // absolute path break; } if( paths != NULL ) { for( ; ; ) { path = *paths++; if( path == NULL ) break; retn = openSrcPath( path, exts, fd, typ ); if( retn ) goto file_was_found; } } break; } return FALSE; file_was_found: switch( typ ) { case FT_CMD: SrcFileCommand(); break; case FT_LIBRARY: SrcFileLibrary(); break; } return TRUE; }