/* Include search order is intended to be compatible with C/C++ compilers * and is as follows: * * 1) For absolute pathnames, try only that pathname and nothing else * * 2) For includes in double quotes only, search current directory * * 3) For includes in double quotes only, search the directory * of including file * * 4) Search include directories specified by IncludePath1 (usually command * line -I argument(s) * * 5) Search include directories specified by IncludePath2 (usualy INCLUDE path) * * 6) Directory 'h' adjacent to current directory (../h) * * Note that some of these steps will be skipped if PPFLAG_IGNORE_CWD and/or * PPFLAG_IGNORE_INCLUDE is set. */ int PP_FindInclude( const char *filename, size_t len, char *fullfilename, int incl_type ) { int rc = -1; char drivebuf[_MAX_DRIVE]; char dirbuf[_MAX_DIR]; memcpy( fullfilename, filename, len ); fullfilename[len] = '\0'; if( HAS_PATH( fullfilename ) ) { rc = access( fullfilename, R_OK ); } else { if( rc == -1 && incl_type != PPINCLUDE_SYS && (PPFlags & PPFLAG_IGNORE_CWD) == 0 ) { rc = access( fullfilename, R_OK ); } if( rc == -1 && incl_type == PPINCLUDE_USR && PP_File != NULL ) { size_t len1; _splitpath( PP_File->filename, drivebuf, dirbuf, NULL, NULL ); _makepath( fullfilename, drivebuf, dirbuf, NULL, NULL ); len1 = strlen( fullfilename ); if( len1 > 0 ) { char c = fullfilename[len1 - 1]; if( !IS_PATH_SEP( c ) ) { fullfilename[len1++] = DIR_SEP; } } memcpy( fullfilename + len1, filename, len ); fullfilename[len1 + len] = '\0'; rc = access( fullfilename, R_OK ); } if( rc == -1 && IncludePath1 != NULL ) { rc = findInclude( IncludePath1, filename, len, fullfilename ); } if( rc == -1 && IncludePath2 != NULL ) { rc = findInclude( IncludePath2, filename, len, fullfilename ); } if( rc == -1 && incl_type == PPINCLUDE_USR && (PPFlags & PPFLAG_IGNORE_DEFDIRS) == 0 ) { memcpy( fullfilename, H_DIR, sizeof( H_DIR ) - 1 ); memcpy( fullfilename + sizeof( H_DIR ) - 1, filename, len ); fullfilename[sizeof( H_DIR ) - 1 + len] = '\0'; rc = access( fullfilename, R_OK ); } } return( rc ); }
/* Include search order is intended to be compatible with C/C++ compilers * and is as follows: * * 1) For absolute pathnames, try only that pathname and nothing else * * 2) For includes in double quotes only, search current directory * * 3) For includes in double quotes only, search the directory * of including file * * 4) Search include directories specified by IncludePath1 (usually command * line -I argument(s) * * 5) Search include directories specified by IncludePath2 (usualy INCLUDE path) * * 6) Directory 'h' adjacent to current directory (../h) * * Note that some of these steps will be skipped if PPFLAG_IGNORE_CWD and/or * PPFLAG_IGNORE_INCLUDE is set. */ int PP_FindInclude( const char *filename, char *fullfilename, int incl_type ) { int rc = -1; char drivebuf[ _MAX_DRIVE ]; char dirbuf[ _MAX_DIR ]; if( HAS_PATH( filename ) ) { if( (rc = access( filename, R_OK )) == 0 ) { strcpy( fullfilename, filename ); } } else { if( rc == -1 && incl_type != PPINCLUDE_SYS && (PPFlags & PPFLAG_IGNORE_CWD) == 0 ) { if( (rc = access( filename, R_OK )) == 0 ) { strcpy( fullfilename, filename ); } } if( rc == -1 && incl_type == PPINCLUDE_USR && PP_File != NULL ) { size_t len; _splitpath( PP_File->filename, drivebuf, dirbuf, NULL, NULL ); _makepath( fullfilename, drivebuf, dirbuf, NULL, NULL ); len = strlen( fullfilename ); if( len > 0 ) { char c = fullfilename[len - 1]; if( !IS_PATH_SEP( c ) ) { fullfilename[len++] = c; } } strcpy( fullfilename + len, filename ); rc = access( fullfilename, R_OK ); } if( rc == -1 && IncludePath1 != NULL ) { rc = findInclude( IncludePath1, filename, fullfilename ); } if( rc == -1 && IncludePath2 != NULL ) { rc = findInclude( IncludePath2, filename, fullfilename ); } if( rc == -1 && incl_type == PPINCLUDE_USR && (PPFlags & PPFLAG_IGNORE_DEFDIRS) == 0 ) { sprintf( fullfilename, H_DIR "%s", filename ); rc = access( fullfilename, R_OK ); } } return( rc ); }