Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/mtree replace home-grown parser with fparseln()
details: https://anonhg.NetBSD.org/src/rev/d9764c8c8736
branches: trunk
changeset: 514744:d9764c8c8736
user: lukem <lukem%NetBSD.org@localhost>
date: Mon Sep 10 03:22:24 2001 +0000
description:
replace home-grown parser with fparseln()
diffstat:
usr.sbin/mtree/Makefile | 5 ++++-
usr.sbin/mtree/misc.c | 6 +++---
usr.sbin/mtree/spec.c | 47 ++++++++++++++---------------------------------
3 files changed, 21 insertions(+), 37 deletions(-)
diffs (137 lines):
diff -r d84596d6b6b8 -r d9764c8c8736 usr.sbin/mtree/Makefile
--- a/usr.sbin/mtree/Makefile Mon Sep 10 03:08:18 2001 +0000
+++ b/usr.sbin/mtree/Makefile Mon Sep 10 03:22:24 2001 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 1999/12/07 18:42:06 wennmach Exp $
+# $NetBSD: Makefile,v 1.16 2001/09/10 03:22:24 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/27/95
PROG= mtree
@@ -7,6 +7,9 @@
SRCS= compare.c crc.c create.c misc.c mtree.c spec.c verify.c \
stat_flags.c
+LDADD+= -lutil
+DPADD+= ${LIBUTIL}
+
CPPFLAGS+= -I${.CURDIR}/../../bin/ls
.PATH: ${.CURDIR}/../../usr.bin/cksum ${.CURDIR}/../../bin/ls
diff -r d84596d6b6b8 -r d9764c8c8736 usr.sbin/mtree/misc.c
--- a/usr.sbin/mtree/misc.c Mon Sep 10 03:08:18 2001 +0000
+++ b/usr.sbin/mtree/misc.c Mon Sep 10 03:22:24 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: misc.c,v 1.10 2001/07/18 04:51:54 lukem Exp $ */
+/* $NetBSD: misc.c,v 1.11 2001/09/10 03:22:24 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: misc.c,v 1.10 2001/07/18 04:51:54 lukem Exp $");
+__RCSID("$NetBSD: misc.c,v 1.11 2001/09/10 03:22:24 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -50,7 +50,7 @@
#include "mtree.h"
#include "extern.h"
-extern int lineno;
+extern size_t lineno;
typedef struct _key {
const char *name; /* key name */
diff -r d84596d6b6b8 -r d9764c8c8736 usr.sbin/mtree/spec.c
--- a/usr.sbin/mtree/spec.c Mon Sep 10 03:08:18 2001 +0000
+++ b/usr.sbin/mtree/spec.c Mon Sep 10 03:22:24 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spec.c,v 1.23 2001/07/18 04:51:54 lukem Exp $ */
+/* $NetBSD: spec.c,v 1.24 2001/09/10 03:22:24 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: spec.c,v 1.23 2001/07/18 04:51:54 lukem Exp $");
+__RCSID("$NetBSD: spec.c,v 1.24 2001/09/10 03:22:24 lukem Exp $");
#endif
#endif /* not lint */
@@ -53,12 +53,13 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <util.h>
#include <vis.h>
#include "mtree.h"
#include "extern.h"
-int lineno; /* Current spec line number. */
+size_t lineno; /* Current spec line number. */
static void set(char *, NODE *);
static void unset(char *, NODE *);
@@ -69,47 +70,27 @@
NODE *centry, *last;
char *p;
NODE ginfo, *root;
- int c_cur, c_next;
- char buf[2048];
+ char *buf;
root = NULL;
centry = last = NULL;
memset(&ginfo, 0, sizeof(ginfo));
- c_cur = c_next = 0;
- for (lineno = 1; fgets(buf, sizeof(buf), stdin);
- ++lineno, c_cur = c_next, c_next = 0) {
- /* Skip empty lines. */
- if (buf[0] == '\n')
+ for (lineno = 0;
+ (buf = fparseln(stdin, NULL, &lineno, NULL,
+ FPARSELN_UNESCCOMM | FPARSELN_UNESCCONT | FPARSELN_UNESCESC));
+ free(buf)) {
+ /* Skip leading whitespace. */
+ for (p = buf; *p && isspace((unsigned char)*p); ++p)
continue;
- /* Find end of line. */
- if ((p = strchr(buf, '\n')) == NULL)
- mtree_err("line %d too long", lineno);
-
- /* See if next line is continuation line. */
- if (p[-1] == '\\') {
- --p;
- c_next = 1;
- }
-
- /* Null-terminate the line. */
- *p = '\0';
-
- /* Skip leading whitespace. */
- for (p = buf; *p && isspace((unsigned char)*p); ++p);
-
- /* If nothing but whitespace or comment char, continue. */
- if (!*p || *p == '#')
+ /* If nothing but whitespace, continue. */
+ if (!*p)
continue;
#ifdef DEBUG
(void)fprintf(stderr, "line %d: {%s}\n", lineno, p);
#endif
- if (c_cur) {
- set(p, centry);
- continue;
- }
-
+
/* Grab file name, "$", "set", or "unset". */
if ((p = strtok(p, "\n\t ")) == NULL)
mtree_err("missing field");
Home |
Main Index |
Thread Index |
Old Index