Merged the fix for the trailing % in "find -printf".
[findutils.git] / lib / buildcmd.h
blob81c1a1a5603d931227ca7e9b56adf454b26171b8
1 /* buildcmd.[ch] -- build command lines from a stream of arguments
2 Copyright (C) 2005 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 2, or (at your option)
7 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA.
20 * Written by James Youngman.
22 #ifndef INC_BUILDCMD_H
23 #define INC_BUILDCMD_H 1
25 struct buildcmd_state
27 /* Number of valid elements in `cmd_argv'. */
28 int cmd_argc; /* 0 */
30 /* The list of args being built. */
31 char **cmd_argv; /* NULL */
33 /* Number of elements allocated for `cmd_argv'. */
34 int cmd_argv_alloc;
36 /* Storage for elements of `cmd_argv'. */
37 char *argbuf;
39 /* Number of chars being used in `cmd_argv'. */
40 size_t cmd_argv_chars;
42 /* Number of chars being used in `cmd_argv' for the initial args.. */
43 size_t cmd_initial_argv_chars;
45 /* User context information. */
46 void *usercontext;
48 /* to-do flag. */
49 int todo;
52 struct buildcmd_control
54 /* If true, exit if lines_per_exec or args_per_exec is exceeded. */
55 int exit_if_size_exceeded; /* false */
57 /* POSIX limits on the argument length. */
58 size_t posix_arg_size_max;
59 size_t posix_arg_size_min;
61 /* The maximum number of characters that can be used per command line. */
62 size_t arg_max;
64 /* max_arg_count: the maximum number of arguments that can be used.
66 * Many systems include the size of the pointers in ARG_MAX.
67 * Linux on PPC fails if we just subtract 1 here.
69 * However, not all systems define ARG_MAX. Our bc_get_arg_max()
70 * function returns a useful value even if ARG_MAX is not defined.
71 * However, sometimes, max_arg_count is LONG_MAX!
73 long max_arg_count;
76 /* The length of `replace_pat'. */
77 size_t rplen;
79 /* If nonzero, then instead of putting the args from stdin at
80 the end of the command argument list, they are each stuck into the
81 initial args, replacing each occurrence of the `replace_pat' in the
82 initial args. */
83 char *replace_pat;
85 /* Number of initial arguments given on the command line. */
86 int initial_argc; /* 0 */
88 /* exec callback. */
89 int (*exec_callback)(const struct buildcmd_control *, struct buildcmd_state *);
91 /* If nonzero, the maximum number of nonblank lines from stdin to use
92 per command line. */
93 long lines_per_exec; /* 0 */
95 /* The maximum number of arguments to use per command line. */
96 long args_per_exec;
99 enum BC_INIT_STATUS
101 BC_INIT_OK = 0,
102 BC_INIT_ENV_TOO_BIG
105 extern size_t bc_size_of_environment (void);
108 extern void bc_do_insert (const struct buildcmd_control *ctl,
109 struct buildcmd_state *state,
110 char *arg, size_t arglen,
111 const char *prefix, size_t pfxlen,
112 const char *linebuf, size_t lblen,
113 int initial_args);
115 extern void bc_push_arg (const struct buildcmd_control *ctl,
116 struct buildcmd_state *state,
117 const char *arg, size_t len,
118 const char *prefix, size_t pfxlen,
119 int initial_args);
121 extern void bc_init_state(const struct buildcmd_control *ctl,
122 struct buildcmd_state *state,
123 void *usercontext);
124 extern enum BC_INIT_STATUS bc_init_controlinfo(struct buildcmd_control *ctl);
125 extern size_t bc_get_arg_max(void);
126 extern void bc_use_sensible_arg_max(struct buildcmd_control *ctl);
127 extern void bc_clear_args(const struct buildcmd_control *ctl,
128 struct buildcmd_state *state);
131 #endif