OSSP CVS Repository

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

ossp-pkg/rc/rc_proc.c 1.16 -> 1.17

--- rc_proc.c    2002/08/01 15:54:45     1.16
+++ rc_proc.c    2002/08/02 20:09:59     1.17
@@ -76,13 +76,15 @@
     int nFdrc     = 0;
     int nFdfunc   = 0;
     int nRet      = 0;
+    int nRept     = 0;
     int nIter     = 0;
     ex_t Except;
 
-    char *sBuf    = NULL;
-    char *szSec   = NULL;
-    char *szLocex = NULL;
-    rc_script_t *pTempscript = NULL;
+    char         *sBuf        = NULL;
+    rc_section_t *pSec        = NULL;
+    char         *szLocex     = NULL;
+    rc_script_t  *pTempscript = NULL;
+    rc_script_t  **ppParts    = NULL;
 
     assert(*pRc->m_pAnal->m_szRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
@@ -109,8 +111,13 @@
             RC_THROW(RC_ERR_IO);
     }
 
+    /* Logic needed for multiple section combination with priorities */
+    ppParts = malloc(sizeof(rc_script_t *) * pRc->m_pAnal->m_nRcs);
+    for (nRept = 0; nRept < pRc->m_pAnal->m_nRcs; nRept++)
+        ppParts[nRept] = scriptNew();
+
     /* Iteratively read possibly globbed rc files */
-    for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++)
+    for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs; nIter++)
     {
         assert(*pRc->m_pAnal->m_szRcs); /* If one of these assertions fail, */
         assert(pRc->m_pAnal->m_szLocs); /* you've probably seen the ex_ bug */
@@ -134,26 +141,31 @@
 
         try {
             /* Append config section if it exists */
-            szSec = scriptSection(pTempscript, configGetval(RC_NCF_VAL));
-            if (szSec) { /* Only operate if the section lookup succeeds */
-                scriptAppend(pRc->m_pScript, szSec, strlen(szSec));
-                scriptAppend(pRc->m_pScript, "\n", sizeof(char));
-                free(szSec);    /* Cleanup */
-                szSec = NULL;   /* Cleanup */
+            pSec = scriptSection(pTempscript, configGetval(RC_NCF_VAL));
+            if (pSec) { /* Only operate if the section lookup succeeds */
+                scriptAppend(ppParts[nIter], sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
+                scriptAppend(ppParts[nIter], "\n", sizeof(char));
+                sectionDelete(pSec);    /* Cleanup */
+                pSec = NULL;            /* Cleanup */
             }
 
+/* FIXME: Swap nested rcfile/section logic loops for section/rcfile ordering */
             for (i = 0; pRc->m_pAnal->m_pszSecs[i]; i++) { /* Iterate over */
                 /* Extract a section from the temp script, and append it */
                 szSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]);
 
                 if (szSec) { /* Only call if the section lookup succeeds */
+                    scriptAppend(ppParts[nIter], szSec, strlen(szSec));
+                    scriptAppend(pRc->m_pScript, "\n", sizeof(char));
+                }
+/*                if (szSec) { -* Only call if the section lookup succeeds *-
                     scriptAppend(pRc->m_pScript, szSec, strlen(szSec));
                     scriptAppend(pRc->m_pScript, "\n", sizeof(char));
                 }
-                else if (configGetval(RC_DBG_VAL)) /* Only show if debug set */
+                else if (configGetval(RC_DBG_VAL)) -* Only show if debug set *-
                     fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\
                         pRc->m_pAnal->m_pszSecs[i],\
-                        pRc->m_pAnal->m_szRcs[nIter]);
+                        pRc->m_pAnal->m_szRcs[nIter]);*/
 
                 if (szSec) { /* Cleanup iterative section string */
                     free(szSec);
@@ -175,6 +187,15 @@
     close(nFdfunc);     /* Close Func file handle */
 
     /* Memory cleanups */
+    if (ppParts) {
+        for (nRept = pRc->m_pAnal->m_nRcs - 1; nRept >= 0 ; nRept--) {
+            if (ppParts[nRept]) {
+                free(ppParts[nRept]);
+                ppParts[nRept] = NULL;
+        }
+        free(ppParts);
+        ppParts = NULL;
+    }
     if (sBuf) {
         free(sBuf);
         sBuf = NULL;

CVSTrac 2.0.1