Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/usr.sbin/pkg_install/lib Pull up 1.27-1.30:



details:   https://anonhg.NetBSD.org/src/rev/d41104eb3f5d
branches:  netbsd-1-4
changeset: 469274:d41104eb3f5d
user:      he <he%NetBSD.org@localhost>
date:      Sun Aug 22 18:12:49 1999 +0000

description:
Pull up 1.27-1.30:
  De-linting and some code cleanup.
  Clean up URL handling.  (hubertf)

diffstat:

 usr.sbin/pkg_install/lib/file.c |  178 +++++++++++++++++----------------------
 1 files changed, 77 insertions(+), 101 deletions(-)

diffs (258 lines):

diff -r 23baf27f0c17 -r d41104eb3f5d usr.sbin/pkg_install/lib/file.c
--- a/usr.sbin/pkg_install/lib/file.c   Sun Aug 22 18:09:19 1999 +0000
+++ b/usr.sbin/pkg_install/lib/file.c   Sun Aug 22 18:12:49 1999 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: file.c,v 1.25.2.2 1999/06/23 15:00:57 perry Exp $      */
+/*     $NetBSD: file.c,v 1.25.2.3 1999/08/22 18:12:49 he Exp $ */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
 #else
-__RCSID("$NetBSD: file.c,v 1.25.2.2 1999/06/23 15:00:57 perry Exp $");
+__RCSID("$NetBSD: file.c,v 1.25.2.3 1999/08/22 18:12:49 he Exp $");
 #endif
 #endif
 
@@ -167,82 +167,91 @@
     return TRUE;
 }
 
-/* Returns TRUE if file is a URL specification */
-Boolean
-isURL(char *fname)
+/* this struct defines the leading part of a valid URL name */
+typedef struct url_t {
+       char    *u_s;           /* the leading part of the URL */
+       int     u_len;          /* its length */
+} url_t;
+
+/* a table of valid leading strings for URLs */
+static url_t   urls[] = {
+       {       "ftp://";,       6       },
+       {       "http://";,      7       },
+       {       NULL    }
+};
+
+/* Returns length of leading part of any URL from urls table, or -1 */
+int
+URLlength(char *fname)
 {
-    /*
-     * I'm sure there are other types of URL specifications that I could
-     * also be looking for here, but for now I'll just be happy to get ftp
-     * working.
-     */
-    if (!fname)
-       return FALSE;
-    while (isspace((unsigned char)*fname))
-       ++fname;
-    if (!strncmp(fname, "ftp://";, 6))
-       return TRUE;
-    if (!strncmp(fname, "http://";, 7))
-       return TRUE;
-    return FALSE;
+       url_t   *up;
+       int      i;
+
+       if (fname != (char *) NULL) {
+               for (i = 0 ; isspace((unsigned char)*fname) ; i++) {
+                       fname++;
+               }
+               for (up = urls ; up->u_s ; up++) {
+                       if (strncmp(fname, up->u_s, up->u_len) == 0) {
+                               return i + up->u_len;
+                       }
+               }
+       }
+       return -1;
 }
 
 /* Returns the host part of a URL */
 char *
 fileURLHost(char *fname, char *where, int max)
 {
-    char *ret;
+       char    *ret;
+       int      i;
 
-    while (isspace((unsigned char)*fname))
-       ++fname;
-    /* Don't ever call this on a bad URL! */
-    if (!strncmp(fname, "ftp://";, 6))
-       fname += strlen("ftp://";);
-    else
-       fname += strlen("http://";);
-    /* Do we have a place to stick our work? */
-    if ((ret = where) != NULL) {
-       while (*fname && *fname != '/' && max--)
-           *where++ = *fname++;
-       *where = '\0';
+       if ((i = URLlength(fname)) < 0) {
+               errx(1, "fileURLhost called with a bad URL: `%s'", fname);
+       }
+       fname += i;
+       /* Do we have a place to stick our work? */
+       if ((ret = where) != NULL) {
+               while (*fname && *fname != '/' && max--)
+                       *where++ = *fname++;
+               *where = '\0';
+               return ret;
+       }
+       /* If not, they must really want us to stomp the original string */
+       ret = fname;
+       while (*fname && *fname != '/')
+               ++fname;
+       *fname = '\0';
        return ret;
-    }
-    /* If not, they must really want us to stomp the original string */
-    ret = fname;
-    while (*fname && *fname != '/')
-       ++fname;
-    *fname = '\0';
-    return ret;
 }
 
 /* Returns the filename part of a URL */
 char *
 fileURLFilename(char *fname, char *where, int max)
 {
-    char *ret;
+       char    *ret;
+       int      i;
 
-    while (isspace((unsigned char)*fname))
-       ++fname;
-    /* Don't ever call this on a bad URL! */
-    if (!strncmp(fname, "ftp://";, 6))
-       fname += strlen("ftp://";);
-    else
-       fname += strlen("http://";);
-    /* Do we have a place to stick our work? */
-    if ((ret = where) != NULL) {
+       if ((i = URLlength(fname)) < 0) {
+               errx(1, "fileURLhost called with a bad URL: `%s'", fname);
+       }
+       fname += i;
+       /* Do we have a place to stick our work? */
+       if ((ret = where) != NULL) {
+               while (*fname && *fname != '/')
+                       ++fname;
+               if (*fname == '/') {
+                       while (*fname && max--)
+                               *where++ = *fname++;
+               }
+               *where = '\0';
+               return ret;
+       }
+       /* If not, they must really want us to stomp the original string */
        while (*fname && *fname != '/')
-           ++fname;
-       if (*fname == '/') {
-           while (*fname && max--)
-               *where++ = *fname++;
-       }
-       *where = '\0';
-       return ret;
-    }
-    /* If not, they must really want us to stomp the original string */
-    while (*fname && *fname != '/')
-       ++fname;
-    return fname;
+               ++fname;
+       return fname;
 }
 
 /*
@@ -264,7 +273,7 @@
     rp = NULL;
     /* Special tip that sysinstall left for us */
     hint = getenv("PKG_ADD_BASE");
-    if (!isURL(spec)) {
+    if (URLlength(spec) < 0) {
        if (!base && !hint)
            return NULL;
        /* We've been given an existing URL (that's known-good) and now we need
@@ -286,8 +295,7 @@
            }
            else
                return NULL;
-       }
-       else {
+       } else {
            /* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
            strcpy(fname, hint);
            strcat(fname, spec);
@@ -401,7 +409,7 @@
     while (cp) {
        char *cp2 = strsep(&cp, ":");
 
-       snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname);
+       (void) snprintf(tmp, sizeof(tmp), "%s/%s.tgz", cp2 ? cp2 : cp, fname);
        if (ispkgpattern(tmp)) {
            char *s;
            s = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
@@ -516,9 +524,9 @@
     char cmd[FILENAME_MAX];
 
     if (fname[0] == '/')
-       snprintf(cmd, FILENAME_MAX, "cp -p -r %s %s", fname, to);
+       (void) snprintf(cmd, sizeof(cmd), "cp -p -r %s %s", fname, to);
     else
-       snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to);
+       (void) snprintf(cmd, sizeof(cmd), "cp -p -r %s/%s %s", dir, fname, to);
     if (vsystem(cmd)) {
        cleanup(0);
        errx(2, "could not perform '%s'", cmd);
@@ -531,47 +539,15 @@
     char cmd[FILENAME_MAX];
 
     if (fname[0] == '/')
-       snprintf(cmd, FILENAME_MAX, "mv %s %s", fname, to);
+       (void) snprintf(cmd, sizeof(cmd), "mv %s %s", fname, to);
     else
-       snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
+       (void) snprintf(cmd, sizeof(cmd), "mv %s/%s %s", dir, fname, to);
     if (vsystem(cmd)) {
        cleanup(0);
        errx(2, "could not perform '%s'", cmd);
     }
 }
 
-/*
- * Copy a hierarchy (possibly from dir) to the current directory, or
- * if "to" is TRUE, from the current directory to a location someplace
- * else.
- *
- * Though slower, using tar to copy preserves symlinks and everything
- * without me having to write some big hairy routine to do it.
- */
-void
-copy_hierarchy(char *dir, char *fname, Boolean to)
-{
-    char cmd[FILENAME_MAX * 3];
-
-    if (!to) {
-       /* If absolute path, use it */
-       if (*fname == '/')
-           dir = "/";
-       snprintf(cmd, sizeof(cmd), "%s cf - -C %s %s | %s xpf -",
-                TAR_CMD, dir, fname, TAR_CMD);
-    }
-    else
-       snprintf(cmd, sizeof(cmd), "%s cf - %s | %s xpf - -C %s",
-                TAR_CMD, fname, dir, TAR_CMD);
-#ifdef DEBUG
-    printf("Using '%s' to copy trees.\n", cmd);
-#endif
-    if (system(cmd)) {
-       cleanup(0);
-       errx(2, "copy_file: could not perform '%s'", cmd);
-    }
-}
-
 /* Unpack a tar file */
 int
 unpack(char *pkg, char *flist)



Home | Main Index | Thread Index | Old Index