2 * rename.c - aeb 2000-01-01
4 --------------------------------------------------------------
6 if [ $# -le 2 ]; then echo call: rename from to files; exit; fi
11 for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done
12 --------------------------------------------------------------
13 * This shell script will do renames of files, but may fail
14 * in cases involving special characters. Here a C version.
22 static char *progname;
25 do_rename(char *from, char *to, char *s) {
26 char *newname, *where, *p, *q;
29 where = strstr(s, from);
36 newname = malloc(tlen+slen+1);
37 if (newname == NULL) {
38 fprintf(stderr, _("%s: out of memory\n"), progname);
54 if (rename(s, newname) != 0) {
56 fprintf(stderr, _("%s: renaming %s to %s failed: %s\n"),
57 progname, s, newname, strerror(errsv));
65 main(int argc, char **argv) {
70 if ((p = strrchr(progname, '/')) != NULL)
73 setlocale(LC_ALL, "");
74 bindtextdomain(PACKAGE, LOCALEDIR);
78 if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
79 printf(_("%s (%s)\n"),
80 progname, PACKAGE_STRING);
86 fprintf(stderr, _("call: %s from to files...\n"), progname);
93 for (i=3; i<argc; i++)
94 do_rename(from, to, argv[i]);