1 /* buildcmd.[ch] -- build command lines from a stream of arguments
2 Copyright (C) 2005, 2008 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Written by James Youngman.
20 #ifndef INC_BUILDCMD_H
21 #define INC_BUILDCMD_H 1
25 /* Number of valid elements in `cmd_argv'. */
28 /* The list of args being built. */
29 char **cmd_argv
; /* NULL */
31 /* Number of elements allocated for `cmd_argv'. */
34 /* Storage for elements of `cmd_argv'. */
37 /* Number of chars being used in `cmd_argv'. */
38 size_t cmd_argv_chars
;
40 /* Number of chars being used in `cmd_argv' for the initial args.. */
41 size_t cmd_initial_argv_chars
;
43 /* User context information. */
49 /* Directory in which to perform the exec. */
53 struct buildcmd_control
55 /* If true, exit if lines_per_exec or args_per_exec is exceeded. */
56 int exit_if_size_exceeded
; /* false */
58 /* POSIX limits on the argument length. */
59 size_t posix_arg_size_max
;
60 size_t posix_arg_size_min
;
62 /* The maximum number of characters that can be used per command line. */
65 /* max_arg_count: the maximum number of arguments that can be used.
67 * Many systems include the size of the pointers in ARG_MAX.
68 * Linux on PPC fails if we just subtract 1 here.
70 * However, not all systems define ARG_MAX. Our bc_get_arg_max()
71 * function returns a useful value even if ARG_MAX is not defined.
72 * However, sometimes, max_arg_count is LONG_MAX!
77 /* The length of `replace_pat'. */
80 /* If nonzero, then instead of putting the args from stdin at
81 the end of the command argument list, they are each stuck into the
82 initial args, replacing each occurrence of the `replace_pat' in the
86 /* Number of initial arguments given on the command line. */
87 int initial_argc
; /* 0 */
90 int (*exec_callback
)(const struct buildcmd_control
*, struct buildcmd_state
*);
92 /* If nonzero, the maximum number of nonblank lines from stdin to use
94 long lines_per_exec
; /* 0 */
96 /* The maximum number of arguments to use per command line. */
104 BC_INIT_CANNOT_ACCOMODATE_HEADROOM
107 extern size_t bc_size_of_environment (void);
110 extern void bc_do_insert (const struct buildcmd_control
*ctl
,
111 struct buildcmd_state
*state
,
112 char *arg
, size_t arglen
,
113 const char *prefix
, size_t pfxlen
,
114 const char *linebuf
, size_t lblen
,
117 extern void bc_push_arg (const struct buildcmd_control
*ctl
,
118 struct buildcmd_state
*state
,
119 const char *arg
, size_t len
,
120 const char *prefix
, size_t pfxlen
,
123 extern void bc_init_state(const struct buildcmd_control
*ctl
,
124 struct buildcmd_state
*state
,
126 extern enum BC_INIT_STATUS
bc_init_controlinfo(struct buildcmd_control
*ctl
,
127 size_t arglen_headroom
);
128 extern size_t bc_get_arg_max(void);
129 extern void bc_use_sensible_arg_max(struct buildcmd_control
*ctl
);
130 extern void bc_clear_args(const struct buildcmd_control
*ctl
,
131 struct buildcmd_state
*state
);