Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): format code in arch.c



details:   https://anonhg.NetBSD.org/src/rev/0e948269b7d9
branches:  trunk
changeset: 1014783:0e948269b7d9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 03 10:04:34 2020 +0000

description:
make(1): format code in arch.c

diffstat:

 usr.bin/make/arch.c |  141 ++++++++++++++++++++++++++-------------------------
 1 files changed, 71 insertions(+), 70 deletions(-)

diffs (truncated from 343 to 300 lines):

diff -r 61ba99b7f80a -r 0e948269b7d9 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Oct 03 09:56:00 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Oct 03 10:04:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.127 2020/10/01 22:42:00 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.128 2020/10/03 10:04:34 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -134,7 +134,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.127 2020/10/01 22:42:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.128 2020/10/03 10:04:34 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -151,11 +151,11 @@
 static ArchList *archives;     /* The archives we've already examined */
 
 typedef struct Arch {
-    char         *name;      /* Name of archive */
-    Hash_Table   members;    /* All the members of the archive described
-                              * by <name, struct ar_hdr *> key/value pairs */
-    char         *fnametab;  /* Extended name table strings */
-    size_t       fnamesize;  /* Size of the string table */
+    char *name;                        /* Name of archive */
+    Hash_Table members;                /* All the members of the archive described
+                                * by <name, struct ar_hdr *> key/value pairs */
+    char *fnametab;            /* Extended name table strings */
+    size_t fnamesize;          /* Size of the string table */
 } Arch;
 
 static FILE *ArchFindMember(const char *, const char *,
@@ -170,8 +170,8 @@
 ArchFree(void *ap)
 {
     Arch *a = (Arch *)ap;
-    Hash_Search          search;
-    Hash_Entry   *entry;
+    Hash_Search search;
+    Hash_Entry *entry;
 
     /* Free memory from hash entries */
     for (entry = Hash_EnumFirst(&a->members, &search);
@@ -258,7 +258,7 @@
         * place and skip to the end of it (either white-space or
         * a close paren).
         */
-       Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */
+       Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */
 
        while (*cp != '\0' && *cp != ')' && ch_isspace(*cp)) {
            cp++;
@@ -270,7 +270,7 @@
                 * Variable spec, so call the Var module to parse the puppy
                 * so we can safely advance beyond it...
                 */
-               void    *freeIt;
+               void *freeIt;
                const char *result;
                Boolean isError;
                const char *nested_p = cp;
@@ -324,11 +324,11 @@
         * later.
         */
        if (doSubst) {
-           char    *buf;
-           char    *sacrifice;
-           char    *oldMemName = memName;
+           char *buf;
+           char *sacrifice;
+           char *oldMemName = memName;
 
-           (void)Var_Subst(memName, ctxt, VARE_UNDEFERR | VARE_WANTRES,
+           (void)Var_Subst(memName, ctxt, VARE_UNDEFERR|VARE_WANTRES,
                            &memName);
            /* TODO: handle errors */
 
@@ -449,15 +449,15 @@
 static struct ar_hdr *
 ArchStatMember(const char *archive, const char *member, Boolean hash)
 {
-#define AR_MAX_NAME_LEN            (sizeof(arh.ar_name)-1)
-    FILE *       arch;       /* Stream to archive */
-    size_t       size;       /* Size of archive member */
-    char         magic[SARMAG];
+#define AR_MAX_NAME_LEN (sizeof(arh.ar_name) - 1)
+    FILE *arch;                        /* Stream to archive */
+    size_t size;               /* Size of archive member */
+    char magic[SARMAG];
     ArchListNode *ln;
-    Arch         *ar;        /* Archive descriptor */
-    struct ar_hdr arh;        /* archive-member header for reading archive */
-    char         memName[MAXPATHLEN+1];
-                           /* Current member name while hashing. */
+    Arch *ar;                  /* Archive descriptor */
+    struct ar_hdr arh;         /* archive-member header for reading archive */
+    char memName[MAXPATHLEN + 1];
+                               /* Current member name while hashing. */
 
     /*
      * Because of space constraints and similar things, files are archived
@@ -486,7 +486,7 @@
 
        {
            /* Try truncated name */
-           char copy[AR_MAX_NAME_LEN+1];
+           char copy[AR_MAX_NAME_LEN + 1];
            size_t len = strlen(member);
 
            if (len > AR_MAX_NAME_LEN) {
@@ -506,11 +506,11 @@
         * no need to allocate extra room for the header we're returning,
         * so just declare it static.
         */
-        static struct ar_hdr   sarh;
+       static struct ar_hdr sarh;
 
-        arch = ArchFindMember(archive, member, &sarh, "r");
+       arch = ArchFindMember(archive, member, &sarh, "r");
 
-        if (arch == NULL) {
+       if (arch == NULL) {
            return NULL;
        } else {
            fclose(arch);
@@ -533,8 +533,8 @@
      */
     if ((fread(magic, SARMAG, 1, arch) != 1) ||
        (strncmp(magic, ARMAG, SARMAG) != 0)) {
-           fclose(arch);
-           return NULL;
+       fclose(arch);
+       return NULL;
     }
 
     ar = bmake_malloc(sizeof(Arch));
@@ -545,7 +545,7 @@
     memName[AR_MAX_NAME_LEN] = '\0';
 
     while (fread((char *)&arh, sizeof(struct ar_hdr), 1, arch) == 1) {
-       if (strncmp( arh.ar_fmag, ARFMAG, sizeof(arh.ar_fmag)) != 0) {
+       if (strncmp(arh.ar_fmag, ARFMAG, sizeof(arh.ar_fmag)) != 0) {
            /*
             * The header is bogus, so the archive is bad
             * and there's no way we can recover...
@@ -560,7 +560,7 @@
             * boundary, so we need to extract the size of the file from the
             * 'size' field of the header and round it up during the seek.
             */
-           arh.ar_size[sizeof(arh.ar_size)-1] = '\0';
+           arh.ar_size[sizeof(arh.ar_size) - 1] = '\0';
            size = (size_t)strtol(arh.ar_size, NULL, 10);
 
            memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
@@ -579,15 +579,14 @@
                 * svr4 magic mode; handle it
                 */
                switch (ArchSVR4Entry(ar, memName, size, arch)) {
-               case -1:  /* Invalid data */
+               case -1:        /* Invalid data */
                    goto badarch;
-               case 0:   /* List of files entry */
+               case 0:         /* List of files entry */
                    continue;
-               default:  /* Got the entry */
+               default:        /* Got the entry */
                    break;
                }
-           }
-           else {
+           } else {
                if (nameend[0] == '/')
                    nameend[0] = '\0';
            }
@@ -601,23 +600,24 @@
            if (strncmp(memName, AR_EFMT1, sizeof(AR_EFMT1) - 1) == 0 &&
                ch_isdigit(memName[sizeof(AR_EFMT1) - 1])) {
 
-               int elen = atoi(&memName[sizeof(AR_EFMT1)-1]);
+               int elen = atoi(&memName[sizeof(AR_EFMT1) - 1]);
 
                if ((unsigned int)elen > MAXPATHLEN)
-                       goto badarch;
+                   goto badarch;
                if (fread(memName, (size_t)elen, 1, arch) != 1)
-                       goto badarch;
+                   goto badarch;
                memName[elen] = '\0';
                if (fseek(arch, -elen, SEEK_CUR) != 0)
-                       goto badarch;
+                   goto badarch;
                if (DEBUG(ARCH) || DEBUG(MAKE)) {
-                   debug_printf("ArchStat: Extended format entry for %s\n", memName);
+                   debug_printf("ArchStat: Extended format entry for %s\n",
+                                memName);
                }
            }
 #endif
 
            {
-               Hash_Entry *he;
+               Hash_Entry *he;
                he = Hash_CreateEntry(&ar->members, memName, NULL);
                Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
                memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
@@ -706,12 +706,12 @@
 
     entry = (size_t)strtol(&name[1], &eptr, 0);
     if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
-        DEBUG1(ARCH, "Could not parse SVR4 name %s\n", name);
+       DEBUG1(ARCH, "Could not parse SVR4 name %s\n", name);
        return 2;
     }
     if (entry >= ar->fnamesize) {
        DEBUG2(ARCH, "SVR4 entry offset %s is greater than %lu\n",
-                  name, (unsigned long)ar->fnamesize);
+              name, (unsigned long)ar->fnamesize);
        return 2;
     }
 
@@ -746,13 +746,13 @@
  */
 static FILE *
 ArchFindMember(const char *archive, const char *member, struct ar_hdr *arhPtr,
-    const char *mode)
+              const char *mode)
 {
-    FILE *       arch;       /* Stream to archive */
-    int                  size;       /* Size of archive member */
-    char         magic[SARMAG];
-    size_t       len, tlen;
-    const char *  base;
+    FILE *arch;                        /* Stream to archive */
+    int size;                  /* Size of archive member */
+    char magic[SARMAG];
+    size_t len, tlen;
+    const char *base;
 
     arch = fopen(archive, mode);
     if (arch == NULL) {
@@ -765,8 +765,8 @@
      */
     if ((fread(magic, SARMAG, 1, arch) != 1) ||
        (strncmp(magic, ARMAG, SARMAG) != 0)) {
-           fclose(arch);
-           return NULL;
+       fclose(arch);
+       return NULL;
     }
 
     /*
@@ -785,13 +785,13 @@
     }
 
     while (fread((char *)arhPtr, sizeof(struct ar_hdr), 1, arch) == 1) {
-       if (strncmp(arhPtr->ar_fmag, ARFMAG, sizeof(arhPtr->ar_fmag) ) != 0) {
-            /*
-             * The header is bogus, so the archive is bad
-             * and there's no way we can recover...
-             */
-            fclose(arch);
-            return NULL;
+       if (strncmp(arhPtr->ar_fmag, ARFMAG, sizeof(arhPtr->ar_fmag)) != 0) {
+           /*
+            * The header is bogus, so the archive is bad
+            * and there's no way we can recover...
+            */
+           fclose(arch);
+           return NULL;
        } else if (strncmp(member, arhPtr->ar_name, tlen) == 0) {
            /*
             * If the member's name doesn't take up the entire 'name' field,
@@ -800,7 +800,8 @@
             * of the matched string is anything but a space, this isn't the
             * member we sought.
             */
-           if (tlen != sizeof(arhPtr->ar_name) && arhPtr->ar_name[tlen] != ' '){
+           if (tlen != sizeof(arhPtr->ar_name) &&
+               arhPtr->ar_name[tlen] != ' ') {
                goto skip;
            } else {
                /*
@@ -866,7 +867,7 @@
             * extract the size of the file from the 'size' field of the
             * header and round it up during the seek.
             */
-           arhPtr->ar_size[sizeof(arhPtr->ar_size)-1] = '\0';
+           arhPtr->ar_size[sizeof(arhPtr->ar_size) - 1] = '\0';
            size = (int)strtol(arhPtr->ar_size, NULL, 10);
            if (fseek(arch, (size + 1) & ~1, SEEK_CUR) != 0) {
                fclose(arch);
@@ -901,8 +902,8 @@
 void
 Arch_Touch(GNode *gn)
 {
-    FILE *       arch;   /* Stream open to archive, positioned properly */
-    struct ar_hdr arh;   /* Current header describing member */



Home | Main Index | Thread Index | Old Index