]> git.deb.at Git - pkg/mmv.git/blobdiff - mmv.c
Imported Debian patch 1.01b-12.2
[pkg/mmv.git] / mmv.c
diff --git a/mmv.c b/mmv.c
index 8dc9ccbec172d2990119adcd7695f20e2d7d5796..f95772e42f1e28e19cf53e1955afbddb9a8302b2 100644 (file)
--- a/mmv.c
+++ b/mmv.c
@@ -62,7 +62,8 @@ static char USAGE[] =
 %s [-m|x%s|c|o|a|z] [-h] [-d|p] [-g|t] [-v|n] [from to]\n\
 \n\
 Use #N in the ``to'' pattern to get the string matched\n\
 %s [-m|x%s|c|o|a|z] [-h] [-d|p] [-g|t] [-v|n] [from to]\n\
 \n\
 Use #N in the ``to'' pattern to get the string matched\n\
-by the N'th ``from'' pattern wildcard.\n";
+by the N'th ``from'' pattern wildcard.\n\
+Use -- as the end of options.\n";
 
 #define OTHEROPT (_osmajor < 3 ? "" : "|r")
 
 
 #define OTHEROPT (_osmajor < 3 ? "" : "|r")
 
@@ -75,7 +76,9 @@ Use #[l|u]N in the ``to'' pattern to get the [lowercase|uppercase of the]\n\
 string matched by the N'th ``from'' pattern wildcard.\n\
 \n\
 A ``from'' pattern containing wildcards should be quoted when given\n\
 string matched by the N'th ``from'' pattern wildcard.\n\
 \n\
 A ``from'' pattern containing wildcards should be quoted when given\n\
-on the command line.\n";
+on the command line. Also you may need to quote ``to'' pattern.\n\
+\n\
+Use -- as the end of options.\n";
 
 #ifdef IS_SYSV
 #define OTHEROPT ""
 
 #ifdef IS_SYSV
 #define OTHEROPT ""
@@ -85,6 +88,7 @@ on the command line.\n";
 
 #endif
 
 
 #endif
 
+#include <unistd.h>
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
 
@@ -120,14 +124,11 @@ extern unsigned _stklen = 10000;
 #else
 /* for various flavors of UN*X */
 
 #else
 /* for various flavors of UN*X */
 
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 
-extern char *getenv();
-extern long lseek();
-extern char *malloc();
-
 #ifdef HAS_DIRENT
 #include <dirent.h>
 typedef struct dirent DIRENTRY;
 #ifdef HAS_DIRENT
 #include <dirent.h>
 typedef struct dirent DIRENTRY;
@@ -390,7 +391,7 @@ static int movealias(/* REP *first, REP *p, int *pprintaliased */);
 static int snap(/* REP *first, REP *p */);
 static void showdone(/* REP *fin */);
 static void breakout(/*  */);
 static int snap(/* REP *first, REP *p */);
 static void showdone(/* REP *fin */);
 static void breakout(/*  */);
-static int breakrep(/* */);
+static void breakrep(int);
 static void breakstat(/* */);
 static void quit(/*  */);
 static int copymove(/* REP *p */);
 static void breakstat(/* */);
 static void quit(/*  */);
 static int copymove(/* REP *p */);
@@ -577,6 +578,11 @@ static void procargs(argc, argv, pfrompat, ptopat)
        for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++)
                for (p = *argv + 1; *p != '\0'; p++) {
                        c = mylower(*p);
        for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++)
                for (p = *argv + 1; *p != '\0'; p++) {
                        c = mylower(*p);
+                       if (c == '-') {
+                               argc--;
+                               argv++;
+                               goto endargs;
+                       }
                        if (c == 'v' && !noex)
                                verbose = 1;
                        else if (c == 'n' && !verbose)
                        if (c == 'v' && !noex)
                                verbose = 1;
                        else if (c == 'n' && !verbose)
@@ -620,6 +626,7 @@ static void procargs(argc, argv, pfrompat, ptopat)
                        }
                }
 
                        }
                }
 
+endargs:
        if (op == DFLT)
                if (strcmp(cmdname, MOVENAME) == 0)
                        op = XMOVE;
        if (op == DFLT)
                if (strcmp(cmdname, MOVENAME) == 0)
                        op = XMOVE;
@@ -1001,20 +1008,16 @@ static int parsepat()
                                printf(TRAILESC, from, to, ESC);
                                return(-1);
                        }
                                printf(TRAILESC, from, to, ESC);
                                return(-1);
                        }
+#ifdef IS_MSDOS
                default:
                        if (
                default:
                        if (
-#ifdef IS_MSDOS
                                c <= ' ' || c >= 127 ||
                                strchr(":/\\*?[]=+;,\"|<>", c) != NULL
                                c <= ' ' || c >= 127 ||
                                strchr(":/\\*?[]=+;,\"|<>", c) != NULL
-#else
-                               c & 0x80
-#endif
                        ) {
                                printf("%s -> %s : illegal character '%c' (0x%02X).\n",
                                        from, to, c, c);
                                return(-1);
                        }
                        ) {
                                printf("%s -> %s : illegal character '%c' (0x%02X).\n",
                                        from, to, c, c);
                                return(-1);
                        }
-#ifdef IS_MSDOS
                        if (isupper(c))
                                *p = c + ('a' - 'A');
 #endif
                        if (isupper(c))
                                *p = c + ('a' - 'A');
 #endif
@@ -2580,10 +2583,10 @@ static void breakout()
 }
 
 
 }
 
 
-static int breakrep()
+static void breakrep(int signum)
 {
        gotsig = 1;
 {
        gotsig = 1;
-       return(1);
+       return;
 }
 
 
 }
 
 
@@ -2626,7 +2629,7 @@ static int copymove(p)
 
 static int copy(ff, len)
        FILEINFO *ff;
 
 static int copy(ff, len)
        FILEINFO *ff;
-       long len;
+       off_t len;
 {
        char buf[BUFSIZE], c;
        int f, t, k, mode, perm;
 {
        char buf[BUFSIZE], c;
        int f, t, k, mode, perm;
@@ -2674,7 +2677,7 @@ static int copy(ff, len)
                return(-1);
        }
        if (op & APPEND)
                return(-1);
        }
        if (op & APPEND)
-               lseek(t, 0L, 2);
+               lseek(t, (off_t)0, SEEK_END);
 #ifdef IS_MSDOS
        if (op & ZAPPEND && filelength(t) != 0) {
                if (lseek(t, -1L, 1) == -1L || read(t, &c, 1) != 1) {
 #ifdef IS_MSDOS
        if (op & ZAPPEND && filelength(t) != 0) {
                if (lseek(t, -1L, 1) == -1L || read(t, &c, 1) != 1) {
@@ -2686,10 +2689,10 @@ static int copy(ff, len)
                        lseek(t, -1L, 1);
        }
 #endif
                        lseek(t, -1L, 1);
        }
 #endif
-       if ((op & APPEND) && len != -1L) {
+       if ((op & APPEND) && len != (off_t)-1) {
                while (
                        len != 0 &&
                while (
                        len != 0 &&
-                       (k = read(f, buf, len > BUFSIZE ? BUFSIZE : (unsigned)len)) > 0 &&
+                       (k = read(f, buf, (len > BUFSIZE) ? BUFSIZE : (size_t)len)) > 0 &&
                        write(t, buf, k) == k
                )
                        len -= k;
                        write(t, buf, k) == k
                )
                        len -= k;