built-in jambase is packed now
[k8jam.git] / src / command.c
blob7dee451ced5e53cffe8b872ed7af9a81cbb5d572
1 /*
2 * Copyright 1993, 1995 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6 /*
7 * command.c - maintain lists of commands
9 * 01/20/00 (seiwald) - Upgraded from K&R to ANSI C
10 * 09/08/00 (seiwald) - bulletproof PIECEMEAL size computation
13 #include "jam.h"
15 #include "lists.h"
16 #include "parse.h"
17 #include "variable.h"
18 #include "rules.h"
19 #include "kstrings.h"
21 #include "command.h"
25 * cmd_new() - return a new CMD or 0 if too many args
27 CMD *cmd_new (RULE *rule, LIST *targets, LIST *sources, LIST *shell, int maxline) {
28 CMD *cmd = (CMD *)malloc(sizeof(CMD));
30 kStringNew(&cmd->buf);
31 cmd->rule = rule;
32 cmd->shell = shell;
33 cmd->next = 0;
34 lol_init(&cmd->args);
35 lol_add(&cmd->args, targets);
36 lol_add(&cmd->args, sources);
37 /* bail if the result won't fit in maxline */
38 /* we don't free targets/sources/shell if bailing */
39 if (var_string(rule->actions, &cmd->buf, &cmd->args, ' ') < 0) { cmd_free(cmd); return 0; }
40 return cmd;
45 * cmd_free() - free a CMD
47 void cmd_free (CMD *cmd) {
48 kStringFree(&cmd->buf);
49 lol_free(&cmd->args);
50 list_free(cmd->shell);
51 free(cmd);