[Midnightbsd-cvs] src [7310] trunk/lib/libmport: whitespace & formatting

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Sep 26 11:44:49 EDT 2015


Revision: 7310
          http://svnweb.midnightbsd.org/src/?rev=7310
Author:   laffer1
Date:     2015-09-26 11:44:48 -0400 (Sat, 26 Sep 2015)
Log Message:
-----------
whitespace & formatting

Modified Paths:
--------------
    trunk/lib/libmport/error.c
    trunk/lib/libmport/plist.c

Modified: trunk/lib/libmport/error.c
===================================================================
--- trunk/lib/libmport/error.c	2015-09-26 15:44:35 UTC (rev 7309)
+++ trunk/lib/libmport/error.c	2015-09-26 15:44:48 UTC (rev 7310)
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/lib/libmport/error.c,v 1.11 2011/07/24 15:59:08 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include "mport.h"
 #include "mport_private.h"
@@ -33,21 +33,20 @@
 #include <string.h>
 #include <stdarg.h>
 
-
 static int mport_err;
 static char err_msg[256];
 
 /* This goes with the error codes in mport.h */
 static char default_error_msg[] = "An error occured.";
-  
 
+
 /* mport_err_code()
  *
  * Return the current numeric error code. 
  */
-MPORT_PUBLIC_API int mport_err_code(void) 
-{
-  return mport_err;
+MPORT_PUBLIC_API int
+mport_err_code(void) {
+    return mport_err;
 }
 
 /* mport_err_string()
@@ -54,9 +53,9 @@
  *
  * Return the current error string (if any).  Do not free this memory, it is static. 
  */
-MPORT_PUBLIC_API const char * mport_err_string(void)
-{
-  return err_msg;
+MPORT_PUBLIC_API const char *
+mport_err_string(void) {
+    return err_msg;
 }
 
 
@@ -67,20 +66,20 @@
  * Set an error condition, with the given code and message.  A default message will
  * be used if msg is NULL
  */
-int mport_set_err(int code, const char *msg) 
-{
-  mport_err = code;
-  
-  if (code == MPORT_OK) {
-    bzero(err_msg, sizeof(err_msg));
-  } else {  
-    if (msg != NULL) {
-      strlcpy(err_msg, msg, sizeof(err_msg));
+int
+mport_set_err(int code, const char *msg) {
+    mport_err = code;
+
+    if (code == MPORT_OK) {
+        bzero(err_msg, sizeof(err_msg));
     } else {
-      strlcpy(err_msg, default_error_msg, sizeof(err_msg));
+        if (msg != NULL) {
+            strlcpy(err_msg, msg, sizeof(err_msg));
+        } else {
+            strlcpy(err_msg, default_error_msg, sizeof(err_msg));
+        }
     }
-  }
-  return code;
+    return code;
 }
 
 
@@ -90,8 +89,8 @@
  * There is no way to access the default error messages with this function,
  * use mport_set_err() for that.
  */
-int mport_set_errx(int code, const char *fmt, ...) 
-{
+int
+mport_set_errx(int code, const char *fmt, ...) {
     va_list args;
     char *err;
     int ret;
@@ -98,14 +97,13 @@
 
     va_start(args, fmt);
     if (vasprintf(&err, fmt, args) == -1) {
-	fprintf(stderr, "fatal error: mport_set_errx can't format the string.\n");
-	exit(255);
+        fprintf(stderr, "fatal error: mport_set_errx can't format the string.\n");
+        exit(255);
     }
     ret = mport_set_err(code, err);
-    
     free(err);
-    
+
     va_end(args);
-    
+
     return ret;
-}
+}
\ No newline at end of file

Modified: trunk/lib/libmport/plist.c
===================================================================
--- trunk/lib/libmport/plist.c	2015-09-26 15:44:35 UTC (rev 7309)
+++ trunk/lib/libmport/plist.c	2015-09-26 15:44:48 UTC (rev 7310)
@@ -38,35 +38,36 @@
 
 
 #define CMND_MAGIC_COOKIE '@'
-#define STRING_EQ(r,l) (strcmp((r),(l)) == 0)
+#define STRING_EQ(r, l) (strcmp((r),(l)) == 0)
 
-static mportAssetListEntryType parse_command(const char*);
+static mportAssetListEntryType parse_command(const char *);
 
 /* Do everything needed to set up a new plist.  Always use this to create a plist,
  * don't go off and do it yourself.
  */
-MPORT_PUBLIC_API mportAssetList* mport_assetlist_new(void) 
-{
-  mportAssetList *list = (mportAssetList*)calloc(1, sizeof(mportAssetList));
-  assert(list != NULL);
-  STAILQ_INIT(list);
-  return list;
+MPORT_PUBLIC_API mportAssetList *
+mport_assetlist_new(void) {
+
+    mportAssetList *list = (mportAssetList *) calloc(1, sizeof(mportAssetList));
+    assert(list != NULL);
+    STAILQ_INIT(list);
+    return list;
 }
 
 
 /* free all the entries in the list, and then the list itself. */
-MPORT_PUBLIC_API void mport_assetlist_free(mportAssetList *list) 
-{
-  mportAssetListEntry *n = NULL;
+MPORT_PUBLIC_API void
+mport_assetlist_free(mportAssetList *list) {
+    mportAssetListEntry *n = NULL;
 
-  while (!STAILQ_EMPTY(list)) {
-     n = STAILQ_FIRST(list);
-     STAILQ_REMOVE_HEAD(list, next);
-     free(n->data);
-     free(n);
-  }
-  
-  free(list);
+    while (!STAILQ_EMPTY(list)) {
+        n = STAILQ_FIRST(list);
+        STAILQ_REMOVE_HEAD(list, next);
+        free(n->data);
+        free(n);
+    }
+
+    free(list);
 }
 
 
@@ -74,138 +75,138 @@
  * an error code on failure.
  *
  */
-MPORT_PUBLIC_API int mport_parse_plistfile(FILE *fp, mportAssetList *list)
-{
-  size_t length;
-  size_t entrylen;
-  char *line;
+MPORT_PUBLIC_API int
+mport_parse_plistfile(FILE *fp, mportAssetList *list) {
+    size_t length;
+    size_t entrylen;
+    char *line;
 
-  assert(fp != NULL);
-  
-  while ((line = fgetln(fp, &length)) != NULL) {
-    if (feof(fp)) {
-      /* File didn't end in \n, get an exta byte so that the next step doesn't
-         wack the last char in the string. */
-      length++;
-      if ((line = realloc(line, length)) == NULL) {
-        RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-      }
-    }
-    
-    if (length == 1)
-      /* This is almost certainly a blank line. skip it */
-      continue;
-    
-    
-    /* change the last \n to \0 */
-    *(line + length - 1) = '\0';
+    assert(fp != NULL);
 
-    mportAssetListEntry *entry = (mportAssetListEntry *)calloc(1, sizeof(mportAssetListEntry));
-    
-    if (entry == NULL) {
-      RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-    }
-       
-    if (*line == CMND_MAGIC_COOKIE) {
-      line++;
-      char *cmnd = strsep(&line, " \t");
-      
-      if (cmnd == NULL) 
-        RETURN_ERROR(MPORT_ERR_FATAL, "Malformed plist file.");
+    while ((line = fgetln(fp, &length)) != NULL) {
+        if (feof(fp)) {
+            /* File didn't end in \n, get an exta byte so that the next step doesn't
+               wack the last char in the string. */
+            length++;
+            if ((line = realloc(line, length)) == NULL) {
+                RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+            }
+        }
 
-      entry->type = parse_command(cmnd);      
-    } else {
-      entry->type = ASSET_FILE;
-    }
-  
-    
-    if (line == NULL) {
-      /* line was just a directive, no data */
-      entry->data = NULL;
-    } else {    
-      if (entry->type == ASSET_COMMENT) {
-        if (!strncmp(line, "ORIGIN:", 7)) {
-          line += 7;
-          entry->type = ASSET_ORIGIN;
-        } else if (!strncmp(line, "DEPORIGIN:", 10)) {
-          line += 10;
-          entry->type = ASSET_DEPORIGIN;
+        if (length == 1)
+            /* This is almost certainly a blank line. skip it */
+            continue;
+
+
+        /* change the last \n to \0 */
+        *(line + length - 1) = '\0';
+
+        mportAssetListEntry *entry = (mportAssetListEntry *) calloc(1, sizeof(mportAssetListEntry));
+
+        if (entry == NULL) {
+            RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
         }
-      }     
-     
-      entrylen = strlen(line) + 1; 
-      entry->data = (char *)calloc(entrylen, sizeof(char));
-      if (entry->data == NULL) {
-        RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-      }
 
-      char *pos = line + strlen(line) - 1;
-      
-      while (isspace(*pos)) {
-        *pos = 0;
-        pos--;
-      }
-      
-      strlcpy(entry->data, line, entrylen);
+        if (*line == CMND_MAGIC_COOKIE) {
+            line++;
+            char *cmnd = strsep(&line, " \t");
+
+            if (cmnd == NULL)
+                RETURN_ERROR(MPORT_ERR_FATAL, "Malformed plist file.");
+
+            entry->type = parse_command(cmnd);
+        } else {
+            entry->type = ASSET_FILE;
+        }
+
+
+        if (line == NULL) {
+            /* line was just a directive, no data */
+            entry->data = NULL;
+        } else {
+            if (entry->type == ASSET_COMMENT) {
+                if (!strncmp(line, "ORIGIN:", 7)) {
+                    line += 7;
+                    entry->type = ASSET_ORIGIN;
+                } else if (!strncmp(line, "DEPORIGIN:", 10)) {
+                    line += 10;
+                    entry->type = ASSET_DEPORIGIN;
+                }
+            }
+
+            entrylen = strlen(line) + 1;
+            entry->data = (char *) calloc(entrylen, sizeof(char));
+            if (entry->data == NULL) {
+                RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+            }
+
+            char *pos = line + strlen(line) - 1;
+
+            while (isspace(*pos)) {
+                *pos = 0;
+                pos--;
+            }
+
+            strlcpy(entry->data, line, entrylen);
+        }
+
+        STAILQ_INSERT_TAIL(list, entry, next);
     }
-    
-    STAILQ_INSERT_TAIL(list, entry, next);
-  }
 
-  return MPORT_OK;  
+    return MPORT_OK;
 }
 
 
-    
-static mportAssetListEntryType parse_command(const char *s) 
-{
-  /* This is in a rough frequency order */
-  if (STRING_EQ(s, "comment"))
-    return ASSET_COMMENT;
-  if (STRING_EQ(s, "exec"))
-    return ASSET_EXEC;
-  if (STRING_EQ(s, "unexec"))
-    return ASSET_UNEXEC;
-  if (STRING_EQ(s, "dirrm"))
-    return ASSET_DIRRM;
-  if (STRING_EQ(s, "dirrmtry"))
-    return ASSET_DIRRMTRY;
-  if (STRING_EQ(s, "dir"))
-    return ASSET_DIR;
-  if (STRING_EQ(s, "cwd") || STRING_EQ(s, "cd"))
-    return ASSET_CWD;
-  if (STRING_EQ(s, "srcdir"))
-    return ASSET_SRC;
-  if (STRING_EQ(s, "mode"))
-    return ASSET_CHMOD;
-  if (STRING_EQ(s, "owner"))
-    return ASSET_CHOWN;
-  if (STRING_EQ(s, "group"))
-    return ASSET_CHGRP;
-  if (STRING_EQ(s, "noinst"))
-    return ASSET_NOINST;
-  if (STRING_EQ(s, "ignore"))
-    return ASSET_IGNORE;
-  if (STRING_EQ(s, "ignore_inst"))
-    return ASSET_IGNORE_INST;
-  if (STRING_EQ(s, "name"))
-    return ASSET_NAME;
-  if (STRING_EQ(s, "display"))
-    return ASSET_DISPLAY;
-  if (STRING_EQ(s, "pkgdep"))
-    return ASSET_PKGDEP;
-  if (STRING_EQ(s, "conflicts"))
-    return ASSET_CONFLICTS;
-  if (STRING_EQ(s, "mtree"))
-    return ASSET_MTREE;
-  if (STRING_EQ(s, "option"))
-    return ASSET_OPTION;
-  if (STRING_EQ(s, "sample"))
-    return ASSET_SAMPLE;
-  if (STRING_EQ(s, "shell"))
-    return ASSET_SHELL;
-  
-  return ASSET_INVALID;
+static mportAssetListEntryType
+parse_command(const char *s) {
+
+    /* This is in a rough frequency order */
+    if (STRING_EQ(s, "comment"))
+        return ASSET_COMMENT;
+    if (STRING_EQ(s, "exec"))
+        return ASSET_EXEC;
+    if (STRING_EQ(s, "unexec"))
+        return ASSET_UNEXEC;
+    if (STRING_EQ(s, "dirrm"))
+        return ASSET_DIRRM;
+    if (STRING_EQ(s, "dirrmtry"))
+        return ASSET_DIRRMTRY;
+    if (STRING_EQ(s, "dir"))
+        return ASSET_DIR;
+    if (STRING_EQ(s, "cwd") || STRING_EQ(s, "cd"))
+        return ASSET_CWD;
+    if (STRING_EQ(s, "srcdir"))
+        return ASSET_SRC;
+    if (STRING_EQ(s, "mode"))
+        return ASSET_CHMOD;
+    if (STRING_EQ(s, "owner"))
+        return ASSET_CHOWN;
+    if (STRING_EQ(s, "group"))
+        return ASSET_CHGRP;
+    if (STRING_EQ(s, "noinst"))
+        return ASSET_NOINST;
+    if (STRING_EQ(s, "ignore"))
+        return ASSET_IGNORE;
+    if (STRING_EQ(s, "ignore_inst"))
+        return ASSET_IGNORE_INST;
+    if (STRING_EQ(s, "name"))
+        return ASSET_NAME;
+    if (STRING_EQ(s, "display"))
+        return ASSET_DISPLAY;
+    if (STRING_EQ(s, "pkgdep"))
+        return ASSET_PKGDEP;
+    if (STRING_EQ(s, "conflicts"))
+        return ASSET_CONFLICTS;
+    if (STRING_EQ(s, "mtree"))
+        return ASSET_MTREE;
+    if (STRING_EQ(s, "option"))
+        return ASSET_OPTION;
+    if (STRING_EQ(s, "sample"))
+        return ASSET_SAMPLE;
+    if (STRING_EQ(s, "shell"))
+        return ASSET_SHELL;
+
+    return ASSET_INVALID;
 }
 
 



More information about the Midnightbsd-cvs mailing list