From owner-svn-src-user@FreeBSD.ORG Fri Apr 2 05:32:45 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D8C3106566B; Fri, 2 Apr 2010 05:32:45 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2C7738FC0C; Fri, 2 Apr 2010 05:32:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o325WjAG061511; Fri, 2 Apr 2010 05:32:45 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o325WjiY061509; Fri, 2 Apr 2010 05:32:45 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201004020532.o325WjiY061509@svn.freebsd.org> From: Warner Losh Date: Fri, 2 Apr 2010 05:32:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r206073 - user/imp/nopriv/usr.sbin/mtree X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Apr 2010 05:32:45 -0000 Author: imp Date: Fri Apr 2 05:32:44 2010 New Revision: 206073 URL: http://svn.freebsd.org/changeset/base/206073 Log: Fix mismerge from my trial tree... $FreeBSD$ really messed me up.. Modified: user/imp/nopriv/usr.sbin/mtree/spec.c Modified: user/imp/nopriv/usr.sbin/mtree/spec.c ============================================================================== --- user/imp/nopriv/usr.sbin/mtree/spec.c Fri Apr 2 05:21:45 2010 (r206072) +++ user/imp/nopriv/usr.sbin/mtree/spec.c Fri Apr 2 05:32:44 2010 (r206073) @@ -29,6 +29,35 @@ * SUCH DAMAGE. */ +/*- + * Copyright (c) 2001-2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn of Wasabi Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + #if 0 #ifndef lint static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93"; @@ -36,97 +65,94 @@ static char sccsid[] = "@(#)spec.c 8.1 ( #endif #include __FBSDID("$FreeBSD$"); +__RCSID("$NetBSD: spec.c,v 1.78 2009/09/22 04:38:21 apb Exp $"); -#include +#include #include + +#include #include -#include #include -#include #include #include +#include +#include #include +#include #include #include +#include + #include "mtree.h" #include "extern.h" -int lineno; /* Current spec line number. */ +size_t mtree_lineno; /* Current spec line number */ +int mtree_Mflag; /* Merge duplicate entries */ +int mtree_Wflag; /* Don't "whack" permissions */ +int mtree_Sflag; /* Sort entries */ -static void set(char *, NODE *); -static void unset(char *, NODE *); +#if 0 +static dev_t parsedev(char *); +#endif +static void replacenode(NODE *, NODE *); +static void set(char *, NODE *); +static void unset(char *, NODE *); +static void addchild(NODE *, NODE *); +static int nodecmp(const NODE *, const NODE *); +static int appendfield(int, const char *, ...); + +#define REPLACEPTR(x,v) do { if ((x)) free((x)); (x) = (v); } while (0) NODE * -mtree_readspec(FILE *fi) +mtree_readspec(FILE *fp) { - NODE *centry, *last; - char *p; + NODE *centry, *last, *pathparent, *cur; + char *p, *e, *next; NODE ginfo, *root; - int c_cur, c_next; - char buf[2048]; - - centry = last = root = NULL; - bzero(&ginfo, sizeof(ginfo)); - c_cur = c_next = 0; - for (lineno = 1; fgets(buf, sizeof(buf), fi); - ++lineno, c_cur = c_next, c_next = 0) { - /* Skip empty lines. */ - if (buf[0] == '\n') - continue; - - /* Find end of line. */ - if ((p = index(buf, '\n')) == NULL) - errx(1, "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'; + char *buf, *tname, *ntname; + size_t tnamelen, plen; + root = NULL; + centry = last = NULL; + tname = NULL; + tnamelen = 0; + memset(&ginfo, 0, sizeof(ginfo)); + for (mtree_lineno = 0; + (buf = fparseln(fp, NULL, &mtree_lineno, NULL, + FPARSELN_UNESCCOMM)); + free(buf)) { /* Skip leading whitespace. */ - for (p = buf; *p && isspace(*p); ++p); + for (p = buf; *p && isspace((unsigned char)*p); ++p) + continue; - /* 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); + fprintf(stderr, "line %lu: {%s}\n", + (u_long)mtree_lineno, p); #endif - if (c_cur) { - set(p, centry); - continue; - } - /* Grab file name, "$", "set", or "unset". */ - if ((p = strtok(p, "\n\t ")) == NULL) - errx(1, "line %d: missing field", lineno); - - if (p[0] == '/') - switch(p[1]) { - case 's': - if (strcmp(p + 1, "set")) - break; - set(NULL, &ginfo); - continue; - case 'u': - if (strcmp(p + 1, "unset")) - break; - unset(NULL, &ginfo); - continue; - } + next = buf; + while ((p = strsep(&next, " \t")) != NULL && *p == '\0') + continue; + if (p == NULL) + mtree_err("missing field"); - if (index(p, '/')) - errx(1, "line %d: slash character in file name", - lineno); + if (p[0] == '/') { + if (strcmp(p + 1, "set") == 0) + set(next, &ginfo); + else if (strcmp(p + 1, "unset") == 0) + unset(next, &ginfo); + else + mtree_err("invalid specification `%s'", p); + continue; + } - if (!strcmp(p, "..")) { + if (strcmp(p, "..") == 0) { /* Don't go up, if haven't gone down. */ - if (!root) + if (root == NULL) goto noparent; if (last->type != F_DIR || last->flags & F_DONE) { if (last == root)