| 403 | } |
| 404 | |
| 405 | int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) |
| 406 | { |
| 407 | int newNumberOfCommands; |
| 408 | char*** newCommands; |
| 409 | |
| 410 | /* Make sure we have a command to add. */ |
| 411 | if (!cp || !command || !*command) { |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /* Allocate a new array for command pointers. */ |
| 416 | newNumberOfCommands = cp->NumberOfCommands + 1; |
| 417 | if (!(newCommands = |
| 418 | (char***)malloc(sizeof(char**) * (size_t)(newNumberOfCommands)))) { |
| 419 | /* Out of memory. */ |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* Copy any existing commands into the new array. */ |
| 424 | { |
| 425 | int i; |
| 426 | for (i = 0; i < cp->NumberOfCommands; ++i) { |
| 427 | newCommands[i] = cp->Commands[i]; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /* Add the new command. */ |
| 432 | if (cp->Verbatim) { |
| 433 | /* In order to run the given command line verbatim we need to |
| 434 | parse it. */ |
| 435 | newCommands[cp->NumberOfCommands] = |
| 436 | kwsysSystem_Parse_CommandForUnix(*command, 0); |
| 437 | if (!newCommands[cp->NumberOfCommands] || |
| 438 | !newCommands[cp->NumberOfCommands][0]) { |
| 439 | /* Out of memory or no command parsed. */ |
| 440 | free(newCommands); |
| 441 | return 0; |
| 442 | } |
| 443 | } else { |
| 444 | /* Copy each argument string individually. */ |
| 445 | char const* const* c = command; |
| 446 | kwsysProcess_ptrdiff_t n = 0; |
| 447 | kwsysProcess_ptrdiff_t i = 0; |
| 448 | while (*c++) { |
| 449 | } |
| 450 | n = c - command - 1; |
| 451 | newCommands[cp->NumberOfCommands] = |
| 452 | (char**)malloc((size_t)(n + 1) * sizeof(char*)); |
| 453 | if (!newCommands[cp->NumberOfCommands]) { |
| 454 | /* Out of memory. */ |
| 455 | free(newCommands); |
| 456 | return 0; |
| 457 | } |
| 458 | for (i = 0; i < n; ++i) { |
| 459 | assert(command[i]); /* Quiet Clang scan-build. */ |
| 460 | newCommands[cp->NumberOfCommands][i] = strdup(command[i]); |
| 461 | if (!newCommands[cp->NumberOfCommands][i]) { |
| 462 | break; |
no test coverage detected
searching dependent graphs…