4 * Perform expansions on the command line arguments
6 * © 1998 Straylight/Edgeware
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's core utilities (coreutils).
13 * Coreutils is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Coreutils is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with coreutils. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /*----- Header files ------------------------------------------------------*/
42 /*----- Type definitions --------------------------------------------------*/
44 typedef struct cmdr_ctx {
45 char **av; /* Pointer to @argv@ array */
46 size_t sz; /* Size currently allocated */
47 size_t i; /* Next available @argv@ index */
50 /*----- Main code ---------------------------------------------------------*/
52 /* --- @cmdr_add@ --- *
54 * Arguments: @const char *p@ = pointer to an expanded item
55 * @void *ctx@ = pointer to my context
59 * Use: Adds a globbed filename to the output buffer.
62 static void cmdr_add(const char *p, void *ctx)
66 if (cx->i == cx->sz) {
68 cx->av = xrealloc(cx->av, cx->sz * sizeof(cx->av[0]));
70 cx->av[cx->i++] = xstrdup(p);
73 /* --- @cmdreplace@ --- *
75 * Arguments: @int *argc@ = pointer to argument count
76 * @char ***argv@ = address of pointer to arg list
80 * Use: Mangles the argument list until it's nice.
83 void cmdreplace(int *argc, char ***argv)
89 /* --- Initialise the context --- */
92 cx.av = xmalloc(cx.sz * sizeof(cx.av[0]));
95 /* --- Copy over @argv[0]@ because it's special --- */
97 cx.av[cx.i++] = iav[iac++];
99 /* --- Copy over everything else --- */
102 if (glob(iav[iac], cmdr_add, &cx) == 0) {
105 cx.av = xrealloc(cx.av, cx.sz * sizeof(cx.av[0]));
107 cx.av[cx.i++] = iav[iac];
112 /* --- Copy over the terminator --- */
116 cx.av = xrealloc(cx.av, cx.sz * sizeof(cx.av[0]));
120 /* --- Return appropriate values to the caller --- */
126 /*----- That's all, folks -------------------------------------------------*/