summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-05-04 22:00:37 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-05-04 22:00:37 +0000
commitc247ac5b69371efb17292aa7a9e8548d99550fab (patch)
tree579f38654c44f4ec321d6c5793334167bf7fe820 /usr.bin/mg
parent0e1548bc6a75666f789b38ea4bbd5fb3ba1a830d (diff)
Cleanups in filename and buffer name handling.
Mostly just using libc instead of rolling our own.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/buffer.c4
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/file.c71
-rw-r--r--usr.bin/mg/sysdef.h13
4 files changed, 10 insertions, 81 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index 9d4324dbdf6..94db5ed4eef 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.6 2001/05/04 21:47:41 art Exp $ */
+/* $OpenBSD: buffer.c,v 1.7 2001/05/04 22:00:35 art Exp $ */
/*
* Buffer handling.
@@ -390,7 +390,7 @@ bfind(bname, cflag)
bp = bheadp;
while (bp != NULL) {
- if (fncmp(bname, bp->b_bname) == 0)
+ if (strcmp(bname, bp->b_bname) == 0)
return bp;
bp = bp->b_bufp;
}
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 3849cebab75..f1394f0a7e2 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.9 2001/05/03 20:40:22 art Exp $ */
+/* $OpenBSD: def.h,v 1.10 2001/05/04 22:00:35 art Exp $ */
/*
* This file is the general header file for all parts
@@ -328,7 +328,6 @@ int poptofile __P((int, int));
BUFFER *findbuffer __P((char *));
int readin __P((char *));
int insertfile __P((char *, char *, int));
-VOID makename __P((char *, char *));
int filewrite __P((int, int));
int filesave __P((int, int));
int buffsave __P((BUFFER *));
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 8534f90e45e..029e5c2e96b 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,13 +1,12 @@
-/* $OpenBSD: file.c,v 1.5 2001/01/29 01:58:07 niklas Exp $ */
+/* $OpenBSD: file.c,v 1.6 2001/05/04 22:00:35 art Exp $ */
/*
* File commands.
*/
+#include <libgen.h>
#include "def.h"
-static char *itos __P((char *, unsigned int));
-
/*
* Insert a file into the current buffer. Real easy - just call the
* insertfile routine with the file name.
@@ -100,38 +99,18 @@ findbuffer(fname)
unsigned int count = 1;
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
- if (fncmp(bp->b_fname, fname) == 0)
+ if (strcmp(bp->b_fname, fname) == 0)
return bp;
}
/* new buffer name */
- makename(bname, fname);
+ strcpy(bname, basename(fname));
cp = bname + strlen(bname);
- while (bfind(bname, FALSE) != NULL) {
- /* add "<count>" to the name */
- *cp = '<';
- (VOID)strcpy(itos(cp, ++count) + 1, ">");
- }
+ for (count = 1; bfind(bname, FALSE) != NULL; count++)
+ sprintf(cp, "<%d>", count);
return bfind(bname, TRUE);
}
/*
- * Put the decimal representation of num into a buffer. Hacked to be
- * faster, smaller, and less general.
- */
-static char *
-itos(bufp, num)
- char *bufp;
- unsigned int num;
-{
- if (num >= 10) {
- bufp = itos(bufp, num / 10);
- num %= 10;
- }
- *++bufp = '0' + num;
- return bufp;
-}
-
-/*
* Read the file "fname" into the current buffer. Make all of the text
* in the buffer go away, after checking for unsaved changes. This is
* called by the "read" command, the "visit" command, and the mainline
@@ -340,44 +319,6 @@ out: lp2 = NULL;
}
/*
- * Fabriacte a buffer name from a given filename. This routing knows
- * about the syntax of file names on the target system.
- * BDC1 left scan delimiter.
- * BDC2 optional second left scan delimiter.
- * BDC3 optional right scan delimiter.
- */
-VOID
-makename(bname, fname)
- char *bname, *fname;
-{
- char *cp1, *cp2;
-
- cp1 = &fname[0];
- while (*cp1 != 0)
- ++cp1;
-
- /* insure at least 1 character */
- --cp1;
-#ifdef BDC2
- while (cp1 != &fname[0] && cp1[-1] != BDC1 && cp1[-1] != BDC2)
- --cp1;
-#else /* BDC2 */
- while (cp1 != &fname[0] && cp1[-1] != BDC1)
- --cp1;
-#endif /* BDC2 */
- cp2 = &bname[0];
-
-#ifdef BDC3
- while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != BDC3)
- *cp2++ = *cp1++;
-#else /* BDC3 */
- while (cp2 != &bname[NBUFN - 1] && *cp1 != 0)
- *cp2++ = *cp1++;
-#endif /* BDC3 */
- *cp2 = 0;
-}
-
-/*
* Ask for a file name and write the contents of the current buffer to that
* file. Update the remembered file name and clear the buffer changed flag.
* This handling of file names is different from the earlier versions and
diff --git a/usr.bin/mg/sysdef.h b/usr.bin/mg/sysdef.h
index dc5d2158f3b..be69c28735b 100644
--- a/usr.bin/mg/sysdef.h
+++ b/usr.bin/mg/sysdef.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysdef.h,v 1.7 2001/01/29 01:58:10 niklas Exp $ */
+/* $OpenBSD: sysdef.h,v 1.8 2001/05/04 22:00:36 art Exp $ */
/*
* POSIX system header file
@@ -16,19 +16,8 @@
typedef int RSIZE; /* Type for file/region sizes */
typedef short KCHAR; /* Type for internal keystrokes */
-/*
- * Macros used by the buffer name making code.
- * Start at the end of the file name, scan to the left
- * until BDC1 (or BDC2, if defined) is reached. The buffer
- * name starts just to the right of that location, and
- * stops at end of string (or at the next BDC3 character,
- * if defined). BDC2 and BDC3 are mainly for VMS.
- */
-#define BDC1 '/' /* Buffer names. */
-
#define MALLOCROUND(m) (m+=7,m&=~7) /* round up to 8 byte boundry */
-#define fncmp strcmp /* file name comparison */
#define gettermtype() getenv("TERM") /* determine terminal type */
struct fileinfo {