Changeset 41630 in vbox
- Timestamp:
- Jun 8, 2012 5:54:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/filesplitter.cpp
r41624 r41630 30 30 31 31 32 /******************************************************************************* 33 * Defined Constants And Macros * 34 *******************************************************************************/ 35 #ifndef S_ISDIR 36 # define S_ISDIR(a_fMode) ( (S_IFMT & (a_fMode)) == S_IFDIR ) 37 #endif 38 39 32 40 /** 33 41 * Calculates the line number for a file position. … … 71 79 72 80 return RTEXITCODE_FAILURE; 81 } 82 83 84 /** 85 * Opens the makefile list for writing. 86 * 87 * @returns Exit code. 88 * @param pcszPath The path to the file. 89 * @param pcszVariableName The make variable name. 90 * @param ppFile Where to return the file stream. 91 */ 92 static int openMakefileList(const char *pcszPath, const char *pcszVariableName, FILE **ppFile) 93 { 94 *ppFile = NULL; 95 96 FILE *pFile= fopen(pcszPath, "w"); 97 if (!pFile) 98 return printErr("Failed to open \"%s\" for writing the file list"); 99 100 if (fprintf(pFile, "%s := \\\n", pcszVariableName) <= 0) 101 { 102 fclose(pFile); 103 return printErr("Error writing to the makefile list.\n"); 104 } 105 106 *ppFile = pFile; 107 return 0; 108 } 109 110 111 /** 112 * Adds the given file to the makefile list. 113 * 114 * @returns Exit code. 115 * @param pFile The file stream of the makefile list. 116 * @param pszFilename The file name to add. 117 */ 118 static int addFileToMakefileList(FILE *pFile, char *pszFilename) 119 { 120 if (pFile) 121 { 122 char *pszSlash = pszFilename; 123 while ((pszSlash = strchr(pszSlash, '\\')) != NULL) 124 *pszSlash++ = '/'; 125 126 if (fprintf(pFile, "\t%s \\\n", pszFilename) <= 0) 127 return printErr("Error adding file to makefile list.\n"); 128 } 129 return 0; 130 } 131 132 133 /** 134 * Closes the makefile list. 135 * 136 * @returns Exit code derived from @a rc. 137 * @param pFile The file stream of the makefile list. 138 * @param rc The current exit code. 139 */ 140 static int closeMakefileList(FILE *pFile, int rc) 141 { 142 fprintf(pFile, "\n\n"); 143 if (fclose(pFile)) 144 return printErr("Error closing the file list file: %s\n", strerror(errno)); 145 return rc; 73 146 } 74 147 … … 189 262 * @returns exit code. 190 263 * @param pcszOutDir Path to the output directory. 191 * @param pcszContent The content to split up. 192 */ 193 static int splitFile(const char *pcszOutDir, const char *pcszContent) 264 * @param pcszContent The content to split up. 265 * @param pFileList The file stream of the makefile list. Can be NULL. 266 */ 267 static int splitFile(const char *pcszOutDir, const char *pcszContent, FILE *pFileList) 194 268 { 195 269 static char const s_szBeginMarker[] = "\n// ##### BEGINFILE \""; … … 248 322 } 249 323 324 if (!rc) 325 rc = addFileToMakefileList(pFileList, pszFilename); 326 250 327 free(pszFilename); 251 328 … … 263 340 int rc = 0; 264 341 265 if (argc == 3 )342 if (argc == 3 || argc == 5) 266 343 { 267 344 struct stat DirStat; 268 if ( stat(argv[2], &DirStat) == 0345 if ( stat(argv[2], &DirStat) == 0 269 346 && S_ISDIR(DirStat.st_mode)) 270 347 { … … 273 350 if (!rc) 274 351 { 275 rc = splitFile(argv[2], pszContent); 352 FILE *pFileList = NULL; 353 if (argc == 5) 354 rc = openMakefileList(argv[3], argv[4], &pFileList); 355 356 if (argc < 4 || pFileList) 357 rc = splitFile(argv[2], pszContent, pFileList); 358 359 if (pFileList) 360 rc = closeMakefileList(pFileList, rc); 276 361 free(pszContent); 277 362 } … … 281 366 } 282 367 else 283 rc = printErr("Must be started with exactly two arguments,\n" 284 "1) the input file and 2) the directory where to put the output files\n"); 285 return rc; 286 } 368 rc = printErr("Syntax error: usage: filesplitter <infile> <outdir> [<list.kmk> <kmkvar>]\n"); 369 return rc; 370 }
Note:
See TracChangeset
for help on using the changeset viewer.