4 * Run a command on each of a bunch of files
6 * © 1998 Straylight/Edgeware
9 /*----- Licensing note ----------------------------------------------------*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, write to the Free Software Foundation,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /*----- Header files ------------------------------------------------------*/
39 /*----- Run commands ------------------------------------------------------*/
41 typedef struct each_ctx {
49 * Arguments: @const char *f@ = pointer to a filename
50 * @void *ctx@ = pointer to a context block
57 static void run(const char *f, void *ctx)
63 _swi(OS_SubstituteArgs, _inr(0, 4),
64 f, buf, sizeof(buf), ex->skel, ex->sksz);
71 fprintf(stderr, "each: couldn't run `%s': %s\n",
72 buf, _kernel_last_oserror()->errmess);
81 * Arguments: @int argc@ = number of arguments
82 * @char *argv[]@ = list of arguments
84 * Returns: Zero if all went well
86 * Use: Installs files in the right places. This is a bit of a
87 * rip-off of unix `cp'.
90 int main(int argc, char *argv[])
95 /* --- Make sure we have some arguments --- */
98 fprintf(stderr, "Usage: each COMMAND FILE...\n");
102 /* --- Go to work --- */
105 ex.sksz = strlen(ex.skel);
108 for (i = 2; i < argc; i++) {
109 if (glob(argv[i], run, &ex) == 0)
118 /*----- That's all, folks -------------------------------------------------*/