lexer rules relaxed a little; please, don't use tokens like abc: -- use "abc:" instead
[k8jam.git] / src / command.c
blobb13cdafa852360459515a04a232184a1ae578c19
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"
20 #include "command.h"
24 * cmd_new() - return a new CMD or 0 if too many args
26 CMD *cmd_new (RULE *rule, LIST *targets, LIST *sources, LIST *shell, int maxline) {
27 CMD *cmd = (CMD *)malloc(sizeof(CMD));
29 cmd->rule = rule;
30 cmd->shell = shell;
31 cmd->next = 0;
32 lol_init(&cmd->args);
33 lol_add(&cmd->args, targets);
34 lol_add(&cmd->args, sources);
35 /* bail if the result won't fit in maxline */
36 /* we don't free targets/sources/shell if bailing */
37 if (var_string(rule->actions, cmd->buf, maxline, &cmd->args) < 0) { cmd_free(cmd); return 0; }
38 return cmd;
43 * cmd_free() - free a CMD
45 void cmd_free (CMD *cmd) {
46 lol_free(&cmd->args);
47 list_free(cmd->shell);
48 free((char *)cmd);