Commit Diff


commit - 428771da62734f9dce6974d0cb76e74b0274714c
commit + becabb0c45306570037c36547eaa2225cb24e4a7
blob - 75e89b826ca181e45b48677924d0db052b18c062
blob + e12159414ad54aaf01b881b27f0f3e44631f6cc2
--- Makefile
+++ Makefile
@@ -34,7 +34,7 @@ dist: clean
 	rm -rf rene-$(VERSION)
 
 clean:
-	-rm -f $(BIN) $(OBJ) *.tar.gz *.core
+	-rm -f $(BIN) $(OBJ) *.tar.gz *.core t/*.out t/*.err
 
 test: all
 	sh ./t/t.sh
blob - /dev/null
blob + 353d7b582c9ebffb98ed668bd2de672294be4e07 (mode 644)
--- /dev/null
+++ COPYING
@@ -0,0 +1,12 @@
+Copyright (c) 2022-2023 by Alexander Arkhipov <aa_src@manpager.net>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
blob - 9e4493647aac5f594b374a9e6bad12654eee5b4c
blob + 5db2384deb7abf9ef698cfcbd3e966d4a7b6dd31
--- README
+++ README
@@ -2,23 +2,6 @@ rene is a batch-renaming tool similar to rename from u
 Unix-likes. To install, edit config.mk if necessary, and then run make and
 make install:
 
- $ $EDITOR config.mk
- $ make
- # make install
-
-
-COPYING
-
-Copyright (c) 2022 Alexander Arkhipov <scm@mineeyes.cyou>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+	$ $EDITOR config.mk
+	$ make
+	# make install
blob - 600a65df3c46936110b851538688167a1e4aa638
blob + 27dcd1a8046fb24f5bf95aa71dcf9ca4aa92d728
--- rene.1
+++ rene.1
@@ -1,12 +1,12 @@
-.Dd July 07, 2022
+.Dd March 5, 2023
 .Dt RENE 1
 .Os
 .Sh NAME
 .Nm rene
-.Op Fl ailnov
 .Nd rename files
 .Sh SYNOPSIS
 .Nm
+.Op Fl ailnov
 .Ar from to file ...
 .Sh DESCRIPTION
 The utility
@@ -23,21 +23,25 @@ The options are as follows:
 .It Fl a
 Replace all occurences of
 .Ar from
-instead of only the first one. Overrides
+instead of only the first one.
+Overrides
 .Fl l .
 .It Fl i
-Prompt to stderr before overriding existing files. A renaming operation is only
-attempted if the response form stdin begins with the character
+Prompt to stderr before overriding existing files.
+A renaming operation is only attempted if the response form stdin begins with
+the character
 .Dq y .
 .It Fl l
 Replace the last occurence of
 .Ar from
 instead of the first one.
 .It Fl n
-Don't actually rename any files. Useful with
+Don't actually rename any files.
+Useful with
 .Fl v .
 .It Fl o
-Don't override existing files. Disables
+Don't override existing files.
+Disables
 .Fl i .
 .It Fl v
 Display the old and new names of each renamed file.
@@ -48,4 +52,4 @@ Display the old and new names of each renamed file.
 .Xr mv 1 ,
 .Xr rename 2
 .Sh AUTHORS
-.An Alexander Arkhipov Aq Mt src@mineeyes.cyou .
+.An Alexander Arkhipov Aq Mt aa_src@manpager.net .
blob - f4edf16fa222e6c9f6d106f9e6e91cea6666c48d
blob + e77b1be1d3eef8a1bac11b62c1828cb47391902e
--- rene.c
+++ rene.c
@@ -6,16 +6,14 @@
 #include <string.h>
 #include <unistd.h>
 
-#define O_INTERACTIVE 1
-#define O_NOACT (1<<1)
-#define O_NOOVERRIDE (1<<2)
-#define O_REPLACEALL (1<<3)
-#define O_REPLACELAST (1<<4)
-#define O_VERBOSE (1<<5)
-
 #define MAX_FILENAME 4096
 
-uint8_t opts;
+int aflag = 0;
+int iflag = 0;
+int lflag = 0;
+int nflag = 0;
+int oflag = 0;
+int vflag = 0;
 char new[MAX_FILENAME], *newe = new + MAX_FILENAME-1;
 
 void
@@ -64,7 +62,7 @@ errx(int eval, const char *fmt, ...)
 int
 ren(char *from, char *to, char *f)
 {
-	int y = !(opts & O_NOOVERRIDE);
+	int y = !oflag;
 
 	char *p = strrchr(f, '/');
 	if (p) {
@@ -75,7 +73,7 @@ ren(char *from, char *to, char *f)
 	if (!(p = strstr(p, from)))
 		return 1;
 	int fromlen = strlen(from);
-	if (opts & O_REPLACELAST)
+	if (lflag)
 		for(char *x; (x = strstr(p+fromlen, from)); p = x)
 			;
 
@@ -93,20 +91,20 @@ toolong:
 			if (newp == newe)
 				goto toolong;
 		fp += fromlen;
-		if (!(opts & O_REPLACEALL) || !(p = strstr(fp, from)))
+		if (!aflag || !(p = strstr(fp, from)))
 			p = strchr(fp, '\0');
 	}
 	*newp = '\0';
 
-	if (opts & O_INTERACTIVE && access(new, F_OK) == 0) {
+	if (iflag && access(new, F_OK) == 0) {
 		fprintf(stderr, "replace %s with %s? ", from, to);
 		y = getchar() == 'y';
 	}
-	if (y && !(opts & O_NOACT) && !(y += rename(f, new))) {
+	if (y && !nflag && !(y += rename(f, new))) {
 		warn("rename");
 		return 0;
 	}
-	if (opts & O_VERBOSE && y)
+	if (vflag && y)
 		printf("%s -> %s\n", f, new);
 	return 1;
 }
@@ -129,22 +127,22 @@ main(int argc, char *argv[])
 	while ((c = getopt(argc, argv, "ailnov")) != -1) {
 		switch (c) {
 		case 'a':
-			opts |= O_REPLACEALL;
+			aflag = 1;
 			break;
 		case 'i':
-			opts |= O_INTERACTIVE;
+			iflag = 1;
 			break;
 		case 'l':
-			opts |= O_REPLACELAST;
+			lflag = 1;
 			break;
 		case 'n':
-			opts |= O_NOACT;
+			nflag = 1;
 			break;
 		case 'o':
-			opts |= O_NOOVERRIDE;
+			oflag = 1;
 			break;
 		case 'v':
-			opts |= O_VERBOSE;
+			vflag = 1;
 			break;
 		default:
 			usage();