////////////////////////////////////////////////////////////////////////// // // // // ////////////////////////////////////////////////////////////////////////// void CPreprocessor::AddIncludeDirectories(CArrayHeaderNameMap* pcHeaderNames) { CHeaderNameMap* pcHeaderNameMap; int i; for (i = 0; i < pcHeaderNames->NumElements(); i++) { pcHeaderNameMap = pcHeaderNames->Get(i); AddIncludeDirectory(pcHeaderNameMap); } }
int main( int argc, char** argv ){ int i = 1; char *pStr; static int iRecursion = 0; // Track levels of recursion. static CString outputFileName; // Entering. iRecursion++; while( i < argc ){ if( argv[i][0] == '-' || argv[i][0] == '/' ){ switch( argv[i][1] ){ case 'i': case 'I': if( argv[i][2] != 0 ){ pStr = &(argv[i][2]); } else { i++; pStr = argv[i]; } if( pStr == 0 || *pStr == '-' || *pStr == '/' ){ goto usage; } else { AddIncludeDirectory( pStr ); } break; case 'f': case 'F': if( argv[i][2] != 0 ){ pStr = &(argv[i][2]); } else { i++; pStr = argv[i]; } if( pStr == 0 || *pStr == '-' || *pStr == '/'){ goto usage; } else { CStdioFile f; CString s; if( f.Open( pStr, CFile::modeRead ) ){ while(f.ReadString(s)){ s.TrimLeft(); s.TrimRight(); if( s.GetLength() ){ CFileRecord::AddFile( s, NULL, FALSE, TRUE ); } } f.Close(); } else { fprintf(stderr,"makedep: file not found: %s", pStr ); exit(-1); } } break; case 'o': case 'O': if( argv[i][2] != 0 ){ pStr = &(argv[i][2]); } else { i++; pStr = argv[i]; } if( pStr == 0 || *pStr == '-' || *pStr == '/'){ goto usage; } else { CStdioFile f; CString s; outputFileName = pStr; if(!(pAltFile = fopen(pStr, "w+"))) { fprintf(stderr, "makedep: file not found: %s", pStr ); exit(-1); } } break; case '1': if( argv[i][2] == '6') { b16 = TRUE; } break; case 's': case 'S': bSimple = TRUE; break; case 'h': case 'H': case '?': usage: fprintf(stderr, "usage: makedep -I <dirname> -F <filelist> <filename>\n" " -I <dirname> Directory name, can be repeated\n" " -F <filelist> List of files to scan, one per line\n" " -O <outputFile> File to write output, default stdout\n"); exit(-1); } } else if( argv[i][0] == '@' ){ // file contains our commands. CStdioFile f; CString s; int iNewArgc = 0; char **apNewArgv = new char*[5000]; memset(apNewArgv, 0, sizeof(apNewArgv)); // First one is always the name of the exe. apNewArgv[0] = argv[0]; iNewArgc++; const char *pTraverse; const char *pBeginArg; if( f.Open( &argv[i][1], CFile::modeRead ) ){ while( iNewArgc < 5000 && f.ReadString(s) ) { // Scan the string for args, and do the right thing. pTraverse = (const char *)s; while(iNewArgc < 5000 && *pTraverse) { if(isspace(*pTraverse)) { pTraverse++; continue; } // Extract to next space. pBeginArg = pTraverse; do { pTraverse++; } while(*pTraverse && !isspace(*pTraverse)); apNewArgv[iNewArgc] = new char[pTraverse - pBeginArg + 1]; memset(apNewArgv[iNewArgc], 0, pTraverse - pBeginArg + 1); strncpy(apNewArgv[iNewArgc], pBeginArg, pTraverse - pBeginArg); iNewArgc++; } } f.Close(); } // Recurse if needed. if(iNewArgc > 1) { main(iNewArgc, apNewArgv); } // Free off the argvs (but not the very first one which we didn't allocate). while(iNewArgc > 1) { iNewArgc--; delete [] apNewArgv[iNewArgc]; } delete [] apNewArgv; } else { CFileRecord::AddFile( argv[i], NULL, FALSE, TRUE ); } i++; } // Only of the very bottom level of recursion do we do this. if(iRecursion == 1) { // only write the results out if no errors encountered if (mainReturn == 0) { CFileRecord::ProcessFiles(); if( !bSimple ){ CFileRecord::PrintTargets("OBJ_FILES", "\\"); if(b16) { CFileRecord::PrintTargets("LINK_OBJS", "+\\"); } else { CFileRecord::PrintTargets("LINK_OBJS", "^"); } CFileRecord::PrintSources(); CFileRecord::PrintBuildRules(); } CFileRecord::PrintDependancies(); } if(pAltFile != stdout) { fclose(pAltFile); if (mainReturn != 0) { remove(outputFileName); // kill output file if returning an error } } } iRecursion--; if (iRecursion == 0 ) { // last time through -- clean up allocated CFileRecords! CFileRecord *pFRec; CString name; POSITION next; next = CFileRecord::fileMap.GetStartPosition(); while( next ){ CFileRecord::fileMap.GetNextAssoc( next, name, *(void**)&pFRec ); delete pFRec; } } return mainReturn; }