Changeset 3192 for trunk/src/kmk/kmkbuiltin/append.c
- Timestamp:
- Mar 26, 2018, 10:25:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/append.c
r3177 r3192 24 24 */ 25 25 26 /******************************************************************************* 27 * Header Files *28 ******************************************************************************* /29 #ifndef kmk_builtin_append26 /********************************************************************************************************************************* 27 * Header Files * 28 *********************************************************************************************************************************/ 29 #ifndef KMK_BUILTIN_STANDALONE 30 30 # include "makeint.h" 31 31 # include "filedef.h" … … 46 46 # include <alloca.h> 47 47 #endif 48 #if !defined( kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)48 #if !defined(KMK_BUILTIN_STANDALONE) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 49 49 # include "../w32/winchildren.h" 50 50 #endif … … 173 173 * Appends text to a textfile, creating the textfile if necessary. 174 174 */ 175 #ifndef kmk_builtin_append 176 int kmk_builtin_append(int argc, char **argv, char **envp, struct child *pChild, pid_t *pPidSpawned) 177 #else 178 int main(int argc, char **argv, char **envp) 179 #endif 175 int kmk_builtin_append(int argc, char **argv, char **envp, PKMKBUILTINCTX pCtx, struct child *pChild, pid_t *pPidSpawned) 180 176 { 181 177 #if defined(KBUILD_OS_WINDOWS) || defined(KBUILD_OS_OS2) … … 195 191 int fVariables = 0; 196 192 int fCommands = 0; 197 #ifndef kmk_builtin_append193 #ifndef KMK_BUILTIN_STANDALONE 198 194 int fLookForInserts = 0; 199 #e ndif200 201 g_progname = argv[0]; 195 #else 196 (void)pChild; (void)pPidSpawned; 197 #endif 202 198 203 199 /* … … 221 217 if (fVariables) 222 218 { 223 errx( 1, "Option '-c' clashes with '-v'.");219 errx(pCtx, 1, "Option '-c' clashes with '-v'."); 224 220 return kmk_builtin_append_usage(argv[0], stderr); 225 221 } 226 #ifndef kmk_builtin_append222 #ifndef KMK_BUILTIN_STANDALONE 227 223 fCommands = 1; 228 224 break; 229 225 #else 230 errx( 1, "Option '-c' isn't supported in external mode.");226 errx(pCtx, 1, "Option '-c' isn't supported in external mode."); 231 227 return kmk_builtin_append_usage(argv[0], stderr); 232 228 #endif … … 234 230 if (fVariables) 235 231 { 236 errx( 1, "Option '-d' must come before '-v'!");232 errx(pCtx, 1, "Option '-d' must come before '-v'!"); 237 233 return kmk_builtin_append_usage(argv[0], stderr); 238 234 } … … 242 238 if (fVariables || fCommands) 243 239 { 244 errx( 1, fVariables ? "Option '-i' clashes with '-v'." : "Option '-i' clashes with '-c'.");240 errx(pCtx, 1, fVariables ? "Option '-i' clashes with '-v'." : "Option '-i' clashes with '-c'."); 245 241 return kmk_builtin_append_usage(argv[0], stderr); 246 242 } 247 #ifndef kmk_builtin_append243 #ifndef KMK_BUILTIN_STANDALONE 248 244 fLookForInserts = 1; 249 245 break; 250 246 #else 251 errx( 1, "Option '-C' isn't supported in external mode.");247 errx(pCtx, 1, "Option '-C' isn't supported in external mode."); 252 248 return kmk_builtin_append_usage(argv[0], stderr); 253 249 #endif … … 264 260 if (fCommands) 265 261 { 266 errx( 1, "Option '-v' clashes with '-c'.");262 errx(pCtx, 1, "Option '-v' clashes with '-c'."); 267 263 return kmk_builtin_append_usage(argv[0], stderr); 268 264 } 269 #ifndef kmk_builtin_append265 #ifndef KMK_BUILTIN_STANDALONE 270 266 fVariables = 1; 271 267 break; 272 268 #else 273 errx( 1, "Option '-v' isn't supported in external mode.");269 errx(pCtx, 1, "Option '-v' isn't supported in external mode."); 274 270 return kmk_builtin_append_usage(argv[0], stderr); 275 271 #endif 276 272 default: 277 errx( 1, "Invalid option '%c'! (%s)", *psz, argv[i]);273 errx(pCtx, 1, "Invalid option '%c'! (%s)", *psz, argv[i]); 278 274 return kmk_builtin_append_usage(argv[0], stderr); 279 275 } … … 300 296 { 301 297 if (i <= argc) 302 errx( 1, "missing filename!");298 errx(pCtx, 1, "missing filename!"); 303 299 else 304 errx( 1, "missing define name!");300 errx(pCtx, 1, "missing define name!"); 305 301 return kmk_builtin_append_usage(argv[0], stderr); 306 302 } … … 334 330 write_to_buf(&OutBuf, STR_TUPLE(" ")); 335 331 } 336 #ifndef kmk_builtin_append332 #ifndef KMK_BUILTIN_STANDALONE 337 333 if (fCommands) 338 334 { … … 417 413 * Write the buffer (unless we ran out of heap already). 418 414 */ 419 #if !defined( kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)415 #if !defined(KMK_BUILTIN_STANDALONE) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 420 416 if (!OutBuf.fOutOfMemory) 421 417 { 422 418 rc = MkWinChildCreateAppend(pszFilename, &OutBuf.pszBuf, OutBuf.offBuf, fTruncate, pChild, pPidSpawned); 423 419 if (rc != 0) 424 rc = errx( rc, "MkWinChildCreateAppend failed: %u", rc);420 rc = errx(pCtx, rc, "MkWinChildCreateAppend failed: %u", rc); 425 421 if (OutBuf.pszBuf) 426 422 free(OutBuf.pszBuf); … … 440 436 rc = 0; 441 437 else 442 rc = err( 1, "error writing %lu bytes to '%s'", (unsigned long)OutBuf.offBuf, pszFilename);438 rc = err(pCtx, 1, "error writing %lu bytes to '%s'", (unsigned long)OutBuf.offBuf, pszFilename); 443 439 if (close(fd) < 0) 444 rc = err( 1, "error closing '%s'", pszFilename);440 rc = err(pCtx, 1, "error closing '%s'", pszFilename); 445 441 } 446 442 else 447 rc = err( 1, "failed to open '%s'", pszFilename);443 rc = err(pCtx, 1, "failed to open '%s'", pszFilename); 448 444 free(OutBuf.pszBuf); 449 445 } 450 446 else 451 rc = errx( 1, "out of memory for output buffer! (%u needed)", OutBuf.offBuf + 1);447 rc = errx(pCtx, 1, "out of memory for output buffer! (%u needed)", OutBuf.offBuf + 1); 452 448 return rc; 453 449 } 454 450 451 #ifdef KMK_BUILTIN_STANDALONE 452 int main(int argc, char **argv, char **envp) 453 { 454 KMKBUILTINCTX Ctx = { "kmk_append", NULL }; 455 return kmk_builtin_append(argc, argv, envp, &Ctx, NULL, NULL); 456 } 457 #endif 458
Note:
See TracChangeset
for help on using the changeset viewer.