From c247ac5b69371efb17292aa7a9e8548d99550fab Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Fri, 4 May 2001 22:00:37 +0000 Subject: Cleanups in filename and buffer name handling. Mostly just using libc instead of rolling our own. --- usr.bin/mg/buffer.c | 4 +-- usr.bin/mg/def.h | 3 +-- usr.bin/mg/file.c | 71 +++++------------------------------------------------ usr.bin/mg/sysdef.h | 13 +--------- 4 files changed, 10 insertions(+), 81 deletions(-) (limited to 'usr.bin/mg') 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 #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,37 +99,17 @@ 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 "" 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 @@ -339,44 +318,6 @@ out: lp2 = NULL; return s != FIOERR; } -/* - * 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. 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 { -- cgit v1.2.3