Changeset 2015 in kBuild
- Timestamp:
- Nov 1, 2008 10:16:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/append.c
r1695 r2015 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kMk Builtin command - append text to file. 5 * 6 * Copyright (c) 2005-2007 knut st. osmundsen <[email protected]> 7 * 4 */ 5 6 /* 7 * Copyright (c) 2005-2008 knut st. osmundsen <[email protected]> 8 8 * 9 9 * This file is part of kBuild. … … 42 42 { 43 43 fprintf(pf, 44 "usage: %s [-dcn tv] file [string ...]\n"44 "usage: %s [-dcnNtv] file [string ...]\n" 45 45 " or: %s --version\n" 46 46 " or: %s --help\n" … … 51 51 " -c Output the command for specified target(s). [builtin only]\n" 52 52 " -n Insert a new line between the strings.\n" 53 " -N Suppress the trailing new line.\n" 53 54 " -t Truncate the file instead of appending\n" 54 55 " -v Output the value(s) for specified variable(s). [builtin only]\n" … … 69 70 FILE *pFile; 70 71 int fNewLine = 0; 72 int fNoTrailingNewLine = 0; 71 73 int fTruncate = 0; 72 74 int fDefine = 0; … … 83 85 && argv[i][0] == '-' 84 86 && argv[i][1] != '\0' /* '-' is a file */ 85 && strchr("-cdn tv", argv[i][1]) /* valid option char */87 && strchr("-cdnNtv", argv[i][1]) /* valid option char */ 86 88 ) 87 89 { … … 116 118 case 'n': 117 119 fNewLine = 1; 120 break; 121 case 'N': 122 fNoTrailingNewLine = 1; 118 123 break; 119 124 case 't': … … 222 227 } 223 228 224 /* 225 * Add the newline, closing the define if needed, and close the file. 226 */ 227 if ( ( fDefine 228 ? fwrite(fFirst ? "endef\n" : "\nendef\n", 229 1, 230 fFirst ? sizeof("endef\n") - 1 : sizeof("\nendef\n") - 1, 231 pFile) < sizeof("endef\n") 232 : fputc('\n', pFile) == EOF) 229 /* 230 * End the define? 231 */ 232 if (fDefine) 233 { 234 if (fFirst) 235 fwrite("\nendef", 1, sizeof("\nendef") - 1, pFile); 236 else 237 fwrite("endef", 1, sizeof("endef") - 1, pFile); 238 } 239 240 /* 241 * Add the final newline (unless supressed) and close the file. 242 */ 243 if ( ( !fNoTrailingNewLine 244 && fputc('\n', pFile) == EOF) 233 245 || ferror(pFile)) 234 246 {
Note:
See TracChangeset
for help on using the changeset viewer.