Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jul 2007 11:01:55 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 123369 for review
Message-ID:  <200707121101.l6CB1s4x012064@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123369

Change 123369 by gcooper@optimus-revised_pkgtools on 2007/07/12 11:01:40

	create/perform.c:
		Move revision info to head of +CONTENTS file, where (IMO) it should belong.
	lib/plist.c:
		-Almost done with revised parser algorithm. Just a few kinks to work out in adding packages.
		-Also, cut down on command parsing time in plist_cmd by using improved search heuristics
		(if first char is 'd', search for 'isplay', 'irrm', etc). I'm trying to cut down on
		unnecessary looping which no doubt occurs in strcmp by unrolling the logic a bit.

Affected files ...

.. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/create/perform.c#2 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#5 edit

Differences ...

==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/create/perform.c#2 (text+ko) ====

@@ -206,6 +206,13 @@
     /* Slurp in the packing list */
     read_plist(&plist, pkg_in);
 
+    if (asprintf(&cp, "PKG_FORMAT_REVISION:%d.%d", PLIST_FMT_VER_MAJOR,
+		 PLIST_FMT_VER_MINOR) == -1) {
+	errx(2, "%s: asprintf() failed", __func__);
+    }
+    add_plist_top(&plist, PLIST_COMMENT, cp);
+    free(cp);
+
     /* Prefix should add an @cwd to the packing list */
     if (Prefix)
 	add_plist_top(&plist, PLIST_CWD, Prefix);
@@ -221,13 +228,6 @@
     if (find_plist(&plist, PLIST_NAME) == NULL)
 	add_plist_top(&plist, PLIST_NAME, basename(pkg));
 
-    if (asprintf(&cp, "PKG_FORMAT_REVISION:%d.%d", PLIST_FMT_VER_MAJOR,
-		 PLIST_FMT_VER_MINOR) == -1) {
-	errx(2, "%s: asprintf() failed", __func__);
-    }
-    add_plist_top(&plist, PLIST_COMMENT, cp);
-    free(cp);
-
     /*
      * We're just here for to dump out a revised plist for the FreeBSD ports
      * hack.  It's not a real create in progress.

==== //depot/projects/soc2007/revised_fbsd_pkgtools/usr/src/usr.sbin/pkg_install/lib/plist.c#5 (text+ko) ====

@@ -309,55 +309,100 @@
 	}
 	++cp, ++sp;
     }
+    printf("COMMAND STRING: %s\nCMD: %s\nCP: %s\nSP: %s\n", s, cmd, cp, sp);
+
+    if(!*(cmd+1))
+	return FAIL;
+
     if (arg)
 	*arg = (char *)sp;
-    if (!strcmp(cmd, "cwd"))
-	return PLIST_CWD;
-    else if (!strcmp(cmd, "srcdir"))
-	return PLIST_SRC;
-    else if (!strcmp(cmd, "cd"))
-	return PLIST_CWD;
+
+    if(*cmd == 'c') {
+
+	if(!strcmp(cmd+1, "wd") || *(cmd+1) == 'd') {
+	    printf("CWD IS: %s\n", sp);
+	    return PLIST_CWD;
+	}
+
+	else if(*(cmd+1) == 'o') {
+
+	    if(!strcmp(cmd+2, "mment")) {
+	    	if (!strncmp(*arg, "ORIGIN:", 7)) {
+		    *arg += 7;
+		    return PLIST_ORIGIN;
+		} else if (!strncmp(*arg, "DEPORIGIN:", 10)) {
+		    *arg += 10;
+		    return PLIST_DEPORIGIN;
+	        }
+		return PLIST_COMMENT;
+
+	    } else if(!strcmp(cmd+2, "nflicts")) {
+		return PLIST_CONFLICTS;
+	    }
+
+	}
+
+    }
+
     else if (!strcmp(cmd, "exec"))
 	return PLIST_CMD;
     else if (!strcmp(cmd, "unexec"))
 	return PLIST_UNEXEC;
-    else if (!strcmp(cmd, "mode"))
-	return PLIST_CHMOD;
-    else if (!strcmp(cmd, "owner"))
-	return PLIST_CHOWN;
+    else if(*cmd == 'i') {
+
+	if (!strcmp(cmd+1, "gnore"))
+	    return PLIST_IGNORE;
+	else if(!strcmp(cmd+1, "gnore_inst"))
+	    return PLIST_IGNORE_INST;
+
+    }
+
+    else if (*cmd == 'd') {
+
+	if (!strcmp(cmd+1, "irrm"))
+	    return PLIST_DIR_RM;
+	else if(!strcmp(cmd+1, "isplay"))
+	    return PLIST_DISPLAY;
+
+    }
+
+    else if (*cmd == 'n') {
+
+	if (!strcmp(cmd+1, "oinst"))
+	    return PLIST_NOINST;
+	else if(!strcmp(cmd+1, "ame"))
+	    return PLIST_NAME;
+
+    }
+
+    else if (!strcmp(cmd, "srcdir"))
+	return PLIST_SRC;
+
+    else if (*cmd == 'm') {
+
+	if(!strcmp(cmd+1, "ode"))
+	    return PLIST_CHMOD;
+	else if(!strcmp(cmd+1, "tree"))
+	    return PLIST_MTREE;
+
+    }
+
+    else if (*cmd == 'o') {
+
+	if(!strcmp(cmd+1, "wner"))
+	    return PLIST_CHOWN;
+	else if (!strcmp(cmd+1, "ption"))
+	    return PLIST_OPTION;
+
+    }
+
     else if (!strcmp(cmd, "group"))
 	return PLIST_CHGRP;
-    else if (!strcmp(cmd, "noinst"))
-	return PLIST_NOINST;
-    else if (!strcmp(cmd, "comment")) {
-	if (!strncmp(*arg, "ORIGIN:", 7)) {
-	    *arg += 7;
-	    return PLIST_ORIGIN;
-	} else if (!strncmp(*arg, "DEPORIGIN:", 10)) {
-	    *arg += 10;
-	    return PLIST_DEPORIGIN;
-	}
-	return PLIST_COMMENT;
-    } else if (!strcmp(cmd, "ignore"))
-	return PLIST_IGNORE;
-    else if (!strcmp(cmd, "ignore_inst"))
-	return PLIST_IGNORE_INST;
-    else if (!strcmp(cmd, "name"))
-	return PLIST_NAME;
-    else if (!strcmp(cmd, "display"))
-	return PLIST_DISPLAY;
     else if (!strcmp(cmd, "pkgdep"))
 	return PLIST_PKGDEP;
-    else if (!strcmp(cmd, "conflicts"))
-	return PLIST_CONFLICTS;
-    else if (!strcmp(cmd, "mtree"))
-	return PLIST_MTREE;
-    else if (!strcmp(cmd, "dirrm"))
-	return PLIST_DIR_RM;
-    else if (!strcmp(cmd, "option"))
-	return PLIST_OPTION;
-    else
-	return FAIL;
+
+    return FAIL;
+
 }
 
 void
@@ -367,7 +412,7 @@
 }
 
 void
-read_plist_np_revised(Package *pkg, FILE *fp)
+read_plist_np(Package *pkg, FILE *fp)
 {
 
     struct stat contents_stat;
@@ -390,11 +435,13 @@
 
     assert(contents_stat.st_size != 0);
 
-    plines = (char*) malloc(contents_stat.st_size);
+    plines = (char*) calloc(1, contents_stat.st_size);
 
     for(i = 0; !feof(fp) && i <= contents_stat.st_size; i++)
 	*(plines+i) = fgetc(fp);
 
+//    printf("+CONTENTS DUMP: %s\n", plines);
+
     /* Avoid strangely crafted files with zero-length, but non-zero size */
     assert(i != 0);
 
@@ -404,75 +451,83 @@
 
     if(trim_end_whitespace(pline)) {
 
-	int major, minor;
+	if(*pline != CMD_CHAR) {
+	    cmd = PLIST_FILE;
+	}
+
+	else {
+
+	    int major, minor;
+
+	    pline++;
+
+	    cp = pline;
 
-	cp = pline;
+	    cmd = plist_cmd(pline, &cp);
 
-	cmd = plist_cmd(pline, &cp);
+	    if (cmd != PLIST_COMMENT) {
+		errx(-1, "First line of +CONTENTS file was invalid (should be a "
+		    "package version signature)!\nLine was: %s", pline);
+	    }
 
-	if (cmd == FAIL) {
-	    warnx("%s: unknown command '%s' (package tools out of date?)",
-		__func__, cp);
-	}
+	    if (cmd == PLIST_COMMENT &&
+		sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", &major, &minor) == 2) {
 
-	else if (*cp == '\0') {
-	    cp = NULL;
-	}
+		pkg->fmtver_maj = major;
+	        pkg->fmtver_mnr = minor;
 
-	else if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n",
-					   &major, &minor) == 2) {
-	    pkg->fmtver_maj = major;
-	    pkg->fmtver_mnr = minor;
+		/* 
+		 * If the version is greater than the version major.minor, we
+		 * have a compatibility problem..
+		 */
+	    	if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) {
+		    warnx("plist format revision (%d.%d) is higher than supported"
+			    "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr,
+			    PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR);
 
-	    /* 
-	     * If the version is greater than the version major.minor, we
-	     * have a compatibility problem..
-	     */
-	    if (0 < verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR)) {
-		warnx("plist format revision (%d.%d) is higher than supported"
-		    "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr,
-		    PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR);
+		    if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) {
+			cleanup(0);
+			exit(2);
+	            }
 
-		if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) {
-		    cleanup(0);
-		    exit(2);
-	        }
+		}
 
 	    }
+	
+	}
 
-	}
+    } else
+	errx(-1, "Length of first line was 0. This shouldn't happen");
 
-    }
+    add_plist(pkg, cmd, cp);
 
     /* Now let's iterate through the lines and parse the commands */
     while( NULL != (pline = strtok(NULL, "\n")) ) {
 
 	if(trim_end_whitespace(pline)) {
-	    
-	    if (*pline != CMD_CHAR)
-		cmd = PLIST_FILE;
 
-	    else {
+	    cp = pline;
 
-	        cp = pline;
+	    if(*pline == CMD_CHAR) {
 
-	        cmd = plist_cmd(pline, &cp);
+		cmd = plist_cmd(pline+1, &cp);
 
 		if (cmd == FAIL) {
 		    warnx("%s: unknown command '%s' (package tools out of date?)",
 			__func__, cp);
-	    	} else if (*cp == '\0') {
+		} else if (*cp == '\0')
 	            cp = NULL;
-	        }
 
-		add_plist(pkg, cmd, cp);
+	    } else
+		cmd = PLIST_FILE;
 
-	    }
+	    add_plist(pkg, cmd, cp);
 
 	}
 
     }
 
+    free(plines);
 
 }
 
@@ -489,7 +544,7 @@
 
 /* Read a packing list from a file */
 void
-read_plist_np(Package *pkg, FILE *fp)
+read_plist_old_np(Package *pkg, FILE *fp)
 {
 
 #if BUFFER_TRY



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707121101.l6CB1s4x012064>