1/*
2 * Copyright 1993, 1995 Christopher Seiwald.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7/*
8 * command.c - maintain lists of commands
9 *
10 * 01/20/00 (seiwald) - Upgraded from K&R to ANSI C
11 * 09/08/00 (seiwald) - bulletproof PIECEMEAL size computation
12 */
13
14# include "jam.h"
15
16# include "lists.h"
17# include "parse.h"
18# include "variable.h"
19# include "rules.h"
20
21# include "command.h"
22
23/*
24 * cmd_new() - return a new CMD or 0 if too many args
25 */
26
27CMD *
28cmd_new(
29	RULE	*rule,
30	LIST	*targets,
31	LIST	*sources,
32	LIST	*shell,
33	int	maxline )
34{
35	CMD *cmd = (CMD *)malloc( sizeof( CMD ) );
36
37	cmd->rule = rule;
38	cmd->shell = shell;
39	cmd->next = 0;
40
41	lol_init( &cmd->args );
42	lol_add( &cmd->args, targets );
43	lol_add( &cmd->args, sources );
44
45	/* Bail if the result won't fit in maxline */
46	/* We don't free targets/sources/shell if bailing. */
47
48	if( var_string( rule->actions, cmd->buf, maxline, &cmd->args ) < 0 )
49	{
50	    cmd_free( cmd );
51	    return 0;
52	}
53
54	return cmd;
55}
56
57/*
58 * cmd_free() - free a CMD
59 */
60
61void
62cmd_free( CMD *cmd )
63{
64	lol_free( &cmd->args );
65	list_free( cmd->shell );
66	free( (char *)cmd );
67}
68