OSSP CVS Repository

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

ossp-pkg/rc/rc_anal.c 1.5 -> 1.6

--- rc_anal.c    2002/06/26 14:11:16     1.5
+++ rc_anal.c    2002/06/27 15:35:58     1.6
@@ -31,7 +31,9 @@
 #include <string.h>
 
 #include "rc.h"         /* Public interfaces        */
+#include "rc_const.h"   /* String constants         */
 #include "rc_config.h"  /* Configuration interface  */
+#include "rc_anal.h"    /* Anal specific headers    */
 
 
 /************************************************
@@ -58,7 +60,14 @@
 /*        RC_THROW(RC_WRN_NUL);*/
     }
     else { /* Only enter block with valid string, strdup can't handle NULL */
-        (*ppInst)->m_szRcs = strdup(kszName);
+        (*ppInst)->m_szRcs = malloc(sizeof(char **));
+        if (strcmp(kszName, RC_GLOB_WILD)) {
+            *(*ppInst)->m_szRcs = strdup("rc.");
+            strcat(*(*ppInst)->m_szRcs, kszName);
+            *((*ppInst)->m_szRcs + sizeof(char **)) = NULL; /* Terminate list */
+        }
+        else /* Wildcard rcfile indicates we must glob the locs directories */
+            analGloblocs(ppInst);
     }
 
     return(RC_THROW(RC_OK));
@@ -106,6 +115,7 @@
 {
     if (!kszPathexpr) {
         (*ppInst)->m_szLocs = NULL;
+        (*ppInst)->m_szLocs = strdup("./"); /* FIXME: Relocate default val */
 /*        RC_THROW(RC_WRN_NUL);*/
     }
     else { /* Only enter block with valid string, strdup can't handle NULL */
@@ -138,6 +148,50 @@
     return(RC_THROW(RC_OK));
 }
 
+/***************************************************************
+* int analFileselect(struct dirent *Direntry)                  *
+* Calculate whether a directory entry belongs to a defined set *
+***************************************************************/
+int analFileselect(struct dirent *Direntry)
+{
+    if ((Direntry->d_name != NULL) && (strncmp(Direntry->d_name, "rc.", 3) == 0))
+        return (TRUE);
+    else if ((strcmp(Direntry->d_name, ".") == 0) || (strcmp(Direntry->d_name, "..") == 0))
+        return (FALSE);
+    else /* Catchall returns false for all not met set conditions */
+        return (FALSE);
+}
+
+/************************************************
+* analGloblocs(rc_anal_t **ppInst)              *
+* Glob all files of the location directories    *
+************************************************/
+rc_return_t analGloblocs(rc_anal_t **ppInst)
+{
+    struct dirent ***pppFiles = NULL;
+    int nIter  = 0;
+    int nCount = 0;
+
+    assert(*ppInst); /* Verify sanity */
+
+    /* Write the globbed filenames to our anal object */
+    pppFiles = malloc(sizeof(struct dirent));
+    nCount = scandir((*ppInst)->m_szLocs, pppFiles, analFileselect, alphasort);
+
+    /* Loop through file index setting Rf file names according to dirent */
+    for (nIter = 0; nIter < nCount; ++nIter)
+        (*ppInst)->m_szRcs[nIter] = strdup((*pppFiles)[nIter]->d_name);
+    (*ppInst)->m_szRcs[nIter] = NULL;
+
+    /* Cleanup our Dirent object */
+    if (pppFiles) {
+        free(pppFiles);
+        pppFiles = NULL;
+    }
+
+    return(RC_THROW(RC_OK));
+}
+
 /************************************************
 * analParse(rc_anal_t *)                        *
 * Parse the analyzed configuration data         *
@@ -148,10 +202,10 @@
 
     assert(pInst); /* Verify sanity */
     ex_try { /* Read in data from the main configuration */
+        analLocs (&pInst, configGetval(RC_LOC_VAL));
         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) {
@@ -168,15 +222,19 @@
 ************************************************/
 rc_return_t analDelete(rc_anal_t *pInst)
 {
-    if (pInst->m_szRcs)         /* Rc file names       */
+    int nIter = 0;
+
+    while (pInst->m_szRcs[nIter])   /* Rc file names       */
+        free(pInst->m_szRcs[nIter++]);
+    if (pInst->m_szRcs)             /* Rc file name index  */
         free(pInst->m_szRcs);
-    if (pInst->m_szTmp)         /* Temp file name      */
+    if (pInst->m_szTmp)             /* Temp file name      */
         free(pInst->m_szTmp);
-    if (pInst->m_szFuncs)       /* Function file names */
+    if (pInst->m_szFuncs)           /* Function file names */
         free(pInst->m_szFuncs);
-    if (pInst->m_szLocs)        /* Location path names */
+    if (pInst->m_szLocs)            /* Location path names */
         free(pInst->m_szLocs);
-    if (pInst->m_pszSecs)       /* Section names       */
+    if (pInst->m_pszSecs)           /* Section names       */
         vectorDel(pInst->m_pszSecs);
 
     free(pInst);

CVSTrac 2.0.1