OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_anal.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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));

CVSTrac 2.0.1