OSSP CVS Repository

ossp - Check-in [2154]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2154
Date: 2002-May-23 20:03:20 (local)
2002-May-23 18:03:20 (UTC)
User:ms
Branch:
Comment: More flush work on analyzer.
Tickets:
Inspections:
Files:
ossp-pkg/rc/00TODO      1.24 -> 1.25     5 inserted, 0 deleted
ossp-pkg/rc/rc.h      1.27 -> 1.28     9 inserted, 6 deleted
ossp-pkg/rc/rc_anal.c      1.1 -> 1.2     67 inserted, 19 deleted
ossp-pkg/rc/rc_cliopt.c      1.9 -> 1.10     11 inserted, 22 deleted
ossp-pkg/rc/rc_private.h      1.13 -> 1.14     8 inserted, 7 deleted
ossp-pkg/rc/rc_util.c      1.3 -> 1.4     45 inserted, 0 deleted

ossp-pkg/rc/00TODO 1.24 -> 1.25

--- 00TODO       2002/05/13 16:57:00     1.24
+++ 00TODO       2002/05/23 18:03:20     1.25
@@ -34,6 +34,11 @@
   Convert some normal assert() to real runtime checks.
   Use str_hash von ossp str or static RC_XXX_VAL array from rc_option.h.
 
+Implementation
+  Correct assertion, sanity check, and if () checks according to one standard.
+  Make variable naming standard m_pksz?, and correct throughout.
+  Correct according to a method naming standard like <file>Method.
+
 Detailed ;-) project plan
 -------------------------
 Release v0.8


ossp-pkg/rc/rc.h 1.27 -> 1.28

--- rc.h 2002/05/22 16:01:49     1.27
+++ rc.h 2002/05/23 18:03:20     1.28
@@ -60,7 +60,8 @@
     RC_ERR_IO  = 6, /* Input/output error       */
     RC_ERR_INT = 7, /* Internal error           */
     RC_WRN_0   = 8, /* Warning base             */
-    RC_WRN_OWR = 9  /* Overwrite warning        */
+    RC_WRN_OWR = 9, /* Overwrite warning        */
+    RC_WRN_NUL = 10 /* NULL pointer warning     */
 } rc_return_t;
 
 /* Config function prototypes */
@@ -96,11 +97,11 @@
 /* Analyser function prototypes */
 rc_anal_t *analNew(void);
 rc_return_t analDelete(rc_anal_t *);
-rc_return_t analRcs(rc_anal_t *, const char *);
-rc_return_t analTmp(rc_anal_t *, const char *);
-rc_return_t analFuncs(rc_anal_t *, const char *);
-rc_return_t analLocs(rc_anal_t *, const char *);
-rc_return_t analSecs(rc_anal_t *, const char **);
+rc_return_t analRcs(rc_anal_t **, const char *);
+rc_return_t analTmp(rc_anal_t **, const char *);
+rc_return_t analFuncs(rc_anal_t **, const char *);
+rc_return_t analLocs(rc_anal_t **, const char *);
+rc_return_t analSecs(rc_anal_t **, const char **);
 rc_return_t analParse(rc_anal_t *);
 
 /* Processor function prototypes */
@@ -115,6 +116,8 @@
 
 /* Utility (nonbounded) function prototypes */
 char *strErr(rc_return_t);
+char **vectorCopy(const char **);
+rc_return_t vectorDel(char **);
 
 /* Other function prototypes */
 


ossp-pkg/rc/rc_anal.c 1.1 -> 1.2

--- rc_anal.c    2002/05/22 16:01:49     1.1
+++ rc_anal.c    2002/05/23 18:03:20     1.2
@@ -28,6 +28,7 @@
 */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "rc.h"         /* Public interfaces        */
 #include "rc_config.h"  /* Configuration interface  */
@@ -46,51 +47,87 @@
 }
 
 /************************************************
-* private analRcs(rc_anal_t *, const char *)    *
+* private analRcs(rc_anal_t **, const char *)   *
 * Read a rc file identifier to analyse          *
 ************************************************/
-rc_return_t analRcs(rc_anal_t *pInst, const char *kszName)
+rc_return_t analRcs(rc_anal_t **ppInst, const char *kszName)
 {
-    TRACE(kszName);
+    if (!kszName)
+        RC_THROW(RC_WRN_NUL);
+    else { /* Only enter block with valid string, strdup can't handle NULL */
+        (*ppInst)->m_szRcs = strdup(kszName);
+        TRACE((*ppInst)->m_szRcs);
+    }
+
     return(RC_THROW(RC_OK));
 }
 
 /************************************************
-* private analTmp(rc_anal_t *, const char *)    *
+* private analTmp(rc_anal_t **, const char *)   *
 * Read a temp file to use for analysis          *
 ************************************************/
-rc_return_t analTmp(rc_anal_t *pInst, const char *kszName)
+rc_return_t analTmp(rc_anal_t **ppInst, const char *kszName)
 {
-    TRACE(kszName);
+    if (!kszName)
+        RC_THROW(RC_WRN_NUL);
+    else { /* Only enter block with valid string, strdup can't handle NULL */
+        (*ppInst)->m_szTmp = strdup("Hello");
+        TRACE((*ppInst)->m_szTmp);
+    }
+
     return(RC_THROW(RC_OK));
 }
 
 /************************************************
-* private analFuncs(rc_anal_t *, const char *)  *
+* private analFuncs(rc_anal_t **, const char *) *
 * Read a functions file to analyse              *
 ************************************************/
-rc_return_t analFuncs(rc_anal_t *pInst, const char *kszName)
+rc_return_t analFuncs(rc_anal_t **ppInst, const char *kszName)
 {
-    TRACE(kszName);
+    if (!kszName)
+        RC_THROW(RC_WRN_NUL);
+    else { /* Only enter block with valid string, strdup can't handle NULL */
+        (*ppInst)->m_szFuncs = strdup(kszName);
+        TRACE((*ppInst)->m_szFuncs);
+    }
+
     return(RC_THROW(RC_OK));
 }
 
 /************************************************
-* private analLocs(rc_anal_t *, const char *)   *
+* private analLocs(rc_anal_t **, const char *)  *
 * Read a location path expression to analyse    *
 ************************************************/
-rc_return_t analLocs(rc_anal_t *pInst, const char *kszPathexpr)
+rc_return_t analLocs(rc_anal_t **ppInst, const char *kszPathexpr)
 {
-    TRACE(kszPathexpr);
+    if (!kszPathexpr)
+        RC_THROW(RC_WRN_NUL);
+    else { /* Only enter block with valid string, strdup can't handle NULL */
+        (*ppInst)->m_szLocs = strdup(kszPathexpr);
+        TRACE((*ppInst)->m_szLocs);
+    }
+
     return(RC_THROW(RC_OK));
 }
 
 /************************************************
-* private analSecs(rc_anal_t *, const char **)  *
+* private analSecs(rc_anal_t **, const char **) *
 * Read a sections vector to analyse             *
 ************************************************/
-rc_return_t analSecs(rc_anal_t *pInst, const char **pkszVector)
+rc_return_t analSecs(rc_anal_t **ppInst, const char **pkszVector)
 {
+    ex_t Except;
+
+    if ((*ppInst)->m_pszSecs)   /* Warn on overwrites */
+        RC_THROW(RC_WRN_OWR);
+
+    ex_try {    /* Sections are a vector, so we must copy accordingly */
+        (*ppInst)->m_pszSecs = vectorCopy(pkszVector);
+    }
+    ex_catch(Except) {
+        rethrow;
+    }
+
     TRACE("Variable pkszVector is not an ANSI string.");
     return(RC_THROW(RC_OK));
 }
@@ -105,11 +142,11 @@
 
     assert(pInst); /* Verify sanity */
     ex_try { /* Read in data from the main configuration */
-        analRcs  (pInst, configGetrcfile());
-        analTmp  (pInst, configGetval(RC_TMP_VAL));
-        analFuncs(pInst, configGetval(RC_FNC_VAL));
-        analLocs (pInst, configGetval(RC_LOC_VAL));
-        analSecs (pInst, configGetsecs());
+        analRcs  (&pInst, configGetrcfile());
+        analTmp  (&pInst, configGetval(RC_TMP_VAL));
+        analFuncs(&pInst, configGetval(RC_FNC_VAL));
+        analLocs (&pInst, configGetval(RC_LOC_VAL));
+        analSecs (&pInst, configGetsecs());
     }
     ex_catch(Except) {
         rethrow;
@@ -124,6 +161,17 @@
 ************************************************/
 rc_return_t analDelete(rc_anal_t *pInst)
 {
+    if (pInst->m_szRcs)         /* Rc file names       */
+        free(pInst->m_szRcs);
+    if (pInst->m_szTmp)         /* Temp file name      */
+        free(pInst->m_szTmp);
+    if (pInst->m_szFuncs)       /* Function file names */
+        free(pInst->m_szFuncs);
+    if (pInst->m_szLocs)        /* Location path names */
+        free(pInst->m_szLocs);
+    if (pInst->m_pszSecs)       /* Section names       */
+        vectorDel(pInst->m_pszSecs);
+
     free(pInst);
 
     return(RC_THROW(RC_OK));


ossp-pkg/rc/rc_cliopt.c 1.9 -> 1.10

--- rc_cliopt.c  2002/05/22 13:29:40     1.9
+++ rc_cliopt.c  2002/05/23 18:03:20     1.10
@@ -169,24 +169,17 @@
 
 rc_return_t clioptSetsecs(const char **pkszSecs)
 {
-    int nSecs  = 0;
-    int nIndex = 0;
+    ex_t Except;
 
-    if (m_pszSecs)                                  /* Warn on overwrites */
+    if (m_pszSecs)              /* Warn on overwrites */
         RC_THROW(RC_WRN_OWR);
-    if (pkszSecs) {
-        for (nSecs = 0; pkszSecs[nSecs]; nSecs++);  /* Count the sections */
-        m_pszSecs = malloc(sizeof (char **) * nSecs + 1);
-
-        for (nIndex = 0; pkszSecs[nIndex]; nIndex++) {
-            m_pszSecs[nIndex] = malloc(strlen(pkszSecs[nIndex]));
-            memcpy(m_pszSecs[nIndex], pkszSecs[nIndex],\
-                   strlen(pkszSecs[nIndex]));
-        }
-        m_pszSecs[nIndex] = NULL; /* Used later to find the end of the array */
+
+    ex_try {
+        m_pszSecs = vectorCopy(pkszSecs);
+    }
+    ex_catch(Except) {
+        rethrow;
     }
-    else
-        return(RC_THROW(RC_ERR_USE));   /* Incoming sections are NULL? */
 
     return(RC_THROW(RC_OK));
 }
@@ -359,13 +352,9 @@
 
     if (m_szRcfile)                     /* Free the rc file arg       */
         free(m_szRcfile);
-    if (m_pszSecs) {                    /* Free the section name arg  */
-        for (i = 0; m_pszSecs[i]; i++) {
-            free(m_pszSecs[i]);
-            m_pszSecs[i] = NULL;
-        }
-        free(m_pszSecs);
-    }
+
+    if (m_pszSecs)                      /* Free the section name arg  */
+        vectorDel(m_pszSecs);
 
 /* FIXME BEGIN DEBUG */
 for (i = 0; i < RC_NUMOPTS; i++)


ossp-pkg/rc/rc_private.h 1.13 -> 1.14

--- rc_private.h 2002/05/22 16:01:49     1.13
+++ rc_private.h 2002/05/23 18:03:20     1.14
@@ -45,8 +45,9 @@
 #define TRACEL(num) fprintf(stderr, "%s:%d: %ld\n", __FILE__, __LINE__, (long int)num)
 #endif
 
-/* The GUID for OSSP rc */
-#define RC_STR_ID "OSSP rc"
+
+#define RC_STR_ID "OSSP rc"                         /* APPID for OSSP rc */
+#define RC_UID_ID f8a1845c55e6449481176f6e9cea34b   /* UUID for OSSP rc */
 
 /* Intentional no operation */
 #define RC_NOP ((void)0)
@@ -66,11 +67,11 @@
 
 /* Analyser type */
 typedef struct {
-    char *m_szRcs;   /* Rc file names       */
-    char *m_szTmp;   /* Temp file name      */
-    char *m_szFuncs; /* Function file names */
-    char *m_szLocs;  /* Location path names */
-    char *m_szSecs;  /* Section names       */
+    char *m_szRcs;      /* Rc file names       */
+    char *m_szTmp;      /* Temp file name      */
+    char *m_szFuncs;    /* Function file names */
+    char *m_szLocs;     /* Location path names */
+    char **m_pszSecs;   /* Section vector      */
 } rc_anal_t;
 
 /* Script type */


ossp-pkg/rc/rc_util.c 1.3 -> 1.4

--- rc_util.c    2002/03/26 17:11:06     1.3
+++ rc_util.c    2002/05/23 18:03:20     1.4
@@ -27,6 +27,9 @@
 **  rc_util.c: Run-command processor ISO C source file
 */
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "rc.h"         /* Error definitions  */
 #include "rc_const.h"   /* String definitions */
 
@@ -42,3 +45,45 @@
     else if (rv == RC_ERR_INT) return RC_ERRSTR_INT;
     else                       return RC_ERRSTR_UNK;
 }
+
+/* Vector copy constructor */
+char **vectorCopy(const char **kpszVec)
+{
+    int nSecs  = 0;
+    int nIndex = 0;
+    char **pszTemp = NULL;
+
+    if (kpszVec) {
+        for (nSecs = 0; kpszVec[nSecs]; nSecs++);   /* Count the sections */
+        pszTemp = malloc(sizeof (char **) * nSecs + 1);
+
+        for (nIndex = 0; kpszVec[nIndex]; nIndex++) {           /* Copy loop */
+            pszTemp[nIndex] = malloc(strlen(kpszVec[nIndex]));  /* for each  */
+            memcpy(pszTemp[nIndex], kpszVec[nIndex],            /* element   */
+                   strlen(kpszVec[nIndex]));                    /* in vector */
+        }
+        pszTemp[nIndex] = NULL; /* Used later to find the end of the array */
+        return(pszTemp);        /* Success */
+    }
+    else
+        RC_THROW(RC_ERR_USE);   /* Incoming vector is NULL? */
+
+    return(NULL);               /* Failure */
+}
+
+/* Vector destructor */
+rc_return_t vectorDel(char **pszVec)
+{
+    int i;
+    assert(pszVec);                 /* Check for unallocated incoming */
+
+    for (i = 0; pszVec[i]; i++) {   /* Loop through elements   */
+        free(pszVec[i]);            /* of vector, deallocating */
+        pszVec[i] = NULL;           /* along the way           */
+    }
+
+    free(pszVec);                   /* Free the vector itself  */
+    pszVec = NULL;
+
+    return(RC_THROW(RC_OK));
+}

CVSTrac 2.0.1