1Description: Patches as of mmv 1.01b-15
2 This patch contains the functional patches as of mmv 1.01b-15 when it
3 has been converted to the source format "3.0 (quilt)"
4Author: Multiple Authors. See changelog for details.
5Reviewed-By: Axel Beckert <abe@debian.org>
6Last-Update: 2012-12-29
7
8--- mmv-1.01b.orig/mmv.c
9+++ mmv-1.01b/mmv.c
10@@ -62,7 +62,8 @@ static char USAGE[] =
11 %s [-m|x%s|c|o|a|z] [-h] [-d|p] [-g|t] [-v|n] [from to]\n\
12 \n\
13 Use #N in the ``to'' pattern to get the string matched\n\
14-by the N'th ``from'' pattern wildcard.\n";
15+by the N'th ``from'' pattern wildcard.\n\
16+Use -- as the end of options.\n";
17
18 #define OTHEROPT (_osmajor < 3 ? "" : "|r")
19
20@@ -75,7 +76,9 @@ Use #[l|u]N in the ``to'' pattern to get
21 string matched by the N'th ``from'' pattern wildcard.\n\
22 \n\
23 A ``from'' pattern containing wildcards should be quoted when given\n\
24-on the command line.\n";
25+on the command line. Also you may need to quote ``to'' pattern.\n\
26+\n\
27+Use -- as the end of options.\n";
28
29 #ifdef IS_SYSV
30 #define OTHEROPT ""
31@@ -85,6 +88,7 @@ on the command line.\n";
32
33 #endif
34
35+#include <unistd.h>
36 #include <stdio.h>
37 #include <ctype.h>
38
39@@ -120,14 +124,12 @@ extern unsigned _stklen = 10000;
40 #else
41 /* for various flavors of UN*X */
42
43+#include <libgen.h>
44+#include <stdlib.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <sys/file.h>
48
49-extern char *getenv();
50-extern long lseek();
51-extern char *malloc();
52-
53 #ifdef HAS_DIRENT
54 #include <dirent.h>
55 typedef struct dirent DIRENTRY;
56@@ -390,7 +392,7 @@ static int movealias(/* REP *first, REP
57 static int snap(/* REP *first, REP *p */);
58 static void showdone(/* REP *fin */);
59 static void breakout(/*  */);
60-static int breakrep(/* */);
61+static void breakrep(int);
62 static void breakstat(/* */);
63 static void quit(/*  */);
64 static int copymove(/* REP *p */);
65@@ -436,9 +438,11 @@ static CHUNK *freechunks = NULL;
66 static SLICER slicer[2] = {{NULL, NULL, 0}, {NULL, NULL, 0}};
67
68 static int badreps = 0, paterr = 0, direrr, failed = 0, gotsig = 0, repbad;
69-static FILE *outfile = stdout;
70+static FILE *outfile;
71
72+#ifdef IS_MSDOS
73 static char IDF[] = "$$mmvdid.";
74+#endif
75 static char TEMP[] = "$$mmvtmp.";
76 static char TOOLONG[] = "(too long)";
77 static char EMPTY[] = "(empty)";
78@@ -456,12 +460,12 @@ char pathbuf[MAXPATH];
79 char fullrep[MAXPATH + 1];
80 static char *(start[MAXWILD]);
81 static int len[MAXWILD];
82-static char hasdot[MAXWILD];
83 static REP mistake;
84 #define MISTAKE (&mistake)
85
86 #ifdef IS_MSDOS
87
88+static char hasdot[MAXWILD];
89 static int olddevflag, curdisk, maxdisk;
90 static struct {
91 	char ph_banner[30];
92@@ -497,6 +501,8 @@ int main(argc, argv)
93 {
94 	char *frompat, *topat;
95
96+	outfile = stdout;
97+
98 	init();
99 	procargs(argc, argv, &frompat, &topat);
100 	domatch(frompat, topat);
101@@ -560,7 +566,7 @@ static void procargs(argc, argv, pfrompa
102 	char **pfrompat, **ptopat;
103 {
104 	char *p, c;
105-	char *cmdname = argv[0];
106+	char *cmdname = basename(argv[0]);
107
108 #ifdef IS_MSDOS
109 #define CMDNAME (patch.ph_name)
110@@ -575,6 +581,11 @@ static void procargs(argc, argv, pfrompa
111 	for (argc--, argv++; argc > 0 && **argv == '-'; argc--, argv++)
112 		for (p = *argv + 1; *p != '\0'; p++) {
113 			c = mylower(*p);
114+			if (c == '-') {
115+				argc--;
116+				argv++;
117+				goto endargs;
118+			}
119 			if (c == 'v' && !noex)
120 				verbose = 1;
121 			else if (c == 'n' && !verbose)
122@@ -618,7 +629,8 @@ static void procargs(argc, argv, pfrompa
123 			}
124 		}
125
126-	if (op == DFLT)
127+endargs:
128+	if (op == DFLT) {
129 		if (strcmp(cmdname, MOVENAME) == 0)
130 			op = XMOVE;
131 		else if (strcmp(cmdname, COPYNAME) == 0)
132@@ -629,6 +641,8 @@ static void procargs(argc, argv, pfrompa
133 			op = HARDLINK;
134 		else
135 			op = DFLTOP;
136+	}
137+
138 	if (
139 		op & DIRMOVE &&
140 #ifdef IS_MSDOS
141@@ -775,7 +789,7 @@ static void matchpat()
142 static int parsepat()
143 {
144 	char *p, *lastname, c;
145-	int totwilds, instage, x, havedot;
146+	int totwilds, instage, x;
147 	static char TRAILESC[] = "%s -> %s : trailing %c is superfluous.\n";
148
149 	lastname = from;
150@@ -999,20 +1013,16 @@ static int parsepat()
151 				printf(TRAILESC, from, to, ESC);
152 				return(-1);
153 			}
154+#ifdef IS_MSDOS
155 		default:
156 			if (
157-#ifdef IS_MSDOS
158 				c <= ' ' || c >= 127 ||
159 				strchr(":/\\*?[]=+;,\"|<>", c) != NULL
160-#else
161-				c & 0x80
162-#endif
163 			) {
164 				printf("%s -> %s : illegal character '%c' (0x%02X).\n",
165 					from, to, c, c);
166 				return(-1);
167 			}
168-#ifdef IS_MSDOS
169 			if (isupper(c))
170 				*p = c + ('a' - 'A');
171 #endif
172@@ -1042,7 +1052,7 @@ static int dostage(lastend, pathend, sta
173 	DIRINFO *di;
174 	HANDLE *h, *hto;
175 	int prelen, litlen, nfils, i, k, flags, try;
176-	FILEINFO **pf, *fdel;
177+	FILEINFO **pf, *fdel = NULL;
178 	char *nto, *firstesc;
179 	REP *p;
180 	int wantdirs, ret = 1, laststage = (stage + 1 == nstages);
181@@ -1172,11 +1182,12 @@ static int trymatch(ffrom, pat)
182 	if (*p == '.' || (!matchall && ffrom->fi_attrib & (FA_HIDDEN | FA_SYSTEM)))
183 		return(strcmp(pat, p) == 0);
184 #else
185-	if (*p == '.')
186+	if (*p == '.') {
187 		if (p[1] == '\0' || (p[1] == '.' && p[2] == '\0'))
188 			return(strcmp(pat, p) == 0);
189 		else if (!matchall && *pat != '.')
190 			return(0);
191+	}
192 #endif
193 	return(-1);
194 }
195@@ -1312,7 +1323,7 @@ static int checkto(hfrom, f, phto, pnto,
196 {
197 	char tpath[MAXPATH + 1];
198 	char *pathend;
199-	FILEINFO *fdel;
200+	FILEINFO *fdel = NULL;
201 	int hlen, tlen;
202
203 	if (op & DIRMOVE) {
204@@ -1405,7 +1416,9 @@ static char *getpath(tpath)
205 static int badname(s)
206 	char *s;
207 {
208+#ifdef IS_MSDOS
209 	char *ext;
210+#endif
211
212 	return (
213 #ifdef IS_MSDOS
214@@ -1715,20 +1728,19 @@ static HANDLE *checkdir(p, pathend, whic
215 	struct stat dstat;
216 	DIRID d;
217 	DEVID v;
218-	DIRINFO **newdirs, *di;
219-	int nfils;
220-	FILEINFO **fils;
221+	DIRINFO *di = NULL;
222 	char *myp, *lastslash = NULL;
223 	int sticky;
224 	HANDLE *h;
225
226-	if (hsearch(p, which, &h))
227+	if (hsearch(p, which, &h)) {
228 		if (h->h_di == NULL) {
229 			direrr = h->h_err;
230 			return(NULL);
231 		}
232 		else
233 			return(h);
234+	}
235
236 	if (*p == '\0')
237 		myp = ".";
238@@ -1899,7 +1911,10 @@ static int match(pat, s, start1, len1)
239 	char *pat, *s, **start1;
240 	int *len1;
241 {
242-	char c, *olds;
243+	char c;
244+#ifdef IS_MSDOS
245+	char *olds;
246+#endif
247
248 	*start1 = 0;
249 	for(;;)
250@@ -2376,9 +2391,9 @@ static void goonordie()
251 static void doreps()
252 {
253 	char *fstart;
254-	int k, printaliased = 0, alias;
255+	int k, printaliased = 0, alias = 0;
256 	REP *first, *p;
257-	long aliaslen;
258+	long aliaslen = 0l;
259
260 #ifdef IS_MSDOS
261 	ctrlbrk(breakrep);
262@@ -2396,11 +2411,12 @@ static void doreps()
263 			}
264 			strcpy(fullrep, p->r_hto->h_name);
265 			strcat(fullrep, p->r_nto);
266-			if (!noex && (p->r_flags & R_ISCYCLE))
267+			if (!noex && (p->r_flags & R_ISCYCLE)) {
268 				if (op & APPEND)
269 					aliaslen = appendalias(first, p, &printaliased);
270 				else
271 					alias = movealias(first, p, &printaliased);
272+			}
273 			strcpy(pathbuf, p->r_hfrom->h_name);
274 			fstart = pathbuf + strlen(pathbuf);
275 			if ((p->r_flags & R_ISALIASED) && !(op & APPEND))
276@@ -2459,7 +2475,7 @@ static long appendalias(first, p, pprint
277 	REP *first, *p;
278 	int *pprintaliased;
279 {
280-	long ret;
281+	long ret = 0l;
282
283 #ifdef IS_MSDOS
284 	int fd;
285@@ -2578,10 +2594,10 @@ static void breakout()
286 }
287
288
289-static int breakrep()
290+static void breakrep(int signum)
291 {
292 	gotsig = 1;
293-	return(1);
294+	return;
295 }
296
297
298@@ -2624,11 +2640,12 @@ static int copymove(p)
299
300 static int copy(ff, len)
301 	FILEINFO *ff;
302-	long len;
303+	off_t len;
304 {
305-	char buf[BUFSIZE], c;
306+	char buf[BUFSIZE];
307 	int f, t, k, mode, perm;
308 #ifdef IS_MSDOS
309+        char c;
310 	struct ftime tim;
311 #else
312 #ifdef IS_SYSV
313@@ -2672,7 +2689,7 @@ static int copy(ff, len)
314 		return(-1);
315 	}
316 	if (op & APPEND)
317-		lseek(t, 0L, 2);
318+		lseek(t, (off_t)0, SEEK_END);
319 #ifdef IS_MSDOS
320 	if (op & ZAPPEND && filelength(t) != 0) {
321 		if (lseek(t, -1L, 1) == -1L || read(t, &c, 1) != 1) {
322@@ -2684,10 +2701,10 @@ static int copy(ff, len)
323 			lseek(t, -1L, 1);
324 	}
325 #endif
326-	if ((op & APPEND) && len != -1L) {
327+	if ((op & APPEND) && len != (off_t)-1) {
328 		while (
329 			len != 0 &&
330-			(k = read(f, buf, len > BUFSIZE ? BUFSIZE : (unsigned)len)) > 0 &&
331+			(k = read(f, buf, (len > BUFSIZE) ? BUFSIZE : (size_t)len)) > 0 &&
332 			write(t, buf, k) == k
333 		)
334 			len -= k;
335@@ -2711,7 +2728,9 @@ static int copy(ff, len)
336 				tim.modtime = fstat.st_mtime,
337 #else
338 				tim[0].tv_sec = fstat.st_atime,
339+				tim[0].tv_usec = 0,
340 				tim[1].tv_sec = fstat.st_mtime,
341+				tim[1].tv_usec = 0,
342 #endif
343 				utimes(fullrep, tim)
344 			)
345Index: mmv/Makefile
346===================================================================
347--- mmv.orig/Makefile	2012-09-16 18:24:31.375886230 +0200
348+++ mmv/Makefile	2012-09-16 18:24:46.260122528 +0200
349@@ -1,16 +1,16 @@
350 # Possible defines in CONF:
351 #	IS_MSDOS IS_SYSV IS_V7 IS_BSD HAS_DIRENT HAS_RENAME MV_DIR
352
353-CC		=gcc -traditional
354+CC		=gcc
355 LD		=$(CC)
356 CONF		=-DIS_SYSV -DHAS_DIRENT -DHAS_RENAME
357-CFLAGS		=-O2 -m486 $(CONF)
358+CFLAGS		=-O2 $(CONF)
359 LDFLAGS		=-s -N
360
361 #IBIN		=$(LOCAL)$(ARCH)/bin
362 #IMAN		=$(LOCAL)$(ANY)/man
363 IBIN=$(DESTDIR)/usr/bin/
364-IMAN=$(DESTDIR)/usr/man/
365+IMAN=$(DESTDIR)/usr/share/man/
366
367 mmv:		mmv.o
368
369