- Timestamp:
- Mar 1, 2018 6:42:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/append.c
r2771 r3134 57 57 " the first argument following the file name.\n" 58 58 " -c Output the command for specified target(s). [builtin only]\n" 59 " -i look for --insert-command=trg and --insert-variable=var. [builtin only]\n" 59 60 " -n Insert a newline between the strings.\n" 60 61 " -N Suppress the trailing newline.\n" … … 82 83 int fVariables = 0; 83 84 int fCommands = 0; 85 int fLookForInserts = 0; 84 86 85 87 g_progname = argv[0]; … … 92 94 && argv[i][0] == '-' 93 95 && argv[i][1] != '\0' /* '-' is a file */ 94 && strchr("-cd nNtv", argv[i][1]) /* valid option char */96 && strchr("-cdinNtv", argv[i][1]) /* valid option char */ 95 97 ) 96 98 { … … 123 125 fDefine = 1; 124 126 break; 127 case 'i': 128 if (fVariables || fCommands) 129 { 130 errx(1, fVariables ? "Option '-i' clashes with '-v'." : "Option '-i' clashes with '-c'."); 131 return usage(stderr); 132 } 133 #ifndef kmk_builtin_append 134 fLookForInserts = 1; 135 break; 136 #else 137 errx(1, "Option '-C' isn't supported in external mode."); 138 return usage(stderr); 139 #endif 125 140 case 'n': 126 141 fNewline = 1; … … 228 243 } 229 244 } 245 else if (fLookForInserts && strncmp(psz, "--insert-command=", 17) == 0) 246 { 247 char *pszOldBuf; 248 unsigned cchOldBuf; 249 char *pchEnd; 250 251 install_variable_buffer(&pszOldBuf, &cchOldBuf); 252 253 psz += 17; 254 pchEnd = func_commands(variable_buffer, (char **)&psz, "commands"); 255 fwrite(variable_buffer, 1, pchEnd - variable_buffer, pFile); 256 257 restore_variable_buffer(pszOldBuf, cchOldBuf); 258 } 259 else if (fLookForInserts && strncmp(psz, "--insert-variable=", 18) == 0) 260 { 261 struct variable *pVar = lookup_variable(psz + 18, cch); 262 if (!pVar) 263 continue; 264 if ( !pVar->recursive 265 || IS_VARIABLE_RECURSIVE_WITHOUT_DOLLAR(pVar)) 266 fwrite(pVar->value, 1, pVar->value_length, pFile); 267 else 268 { 269 char *pszExpanded = allocated_variable_expand(pVar->value); 270 fwrite(pszExpanded, 1, strlen(pszExpanded), pFile); 271 free(pszExpanded); 272 } 273 } 230 274 else 231 275 #endif
Note:
See TracChangeset
for help on using the changeset viewer.