OSSP CVS Repository

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

Check-in Number: 2494
Date: 2002-Aug-02 22:09:59 (local)
2002-Aug-02 20:09:59 (UTC)
User:ms
Branch:
Comment: Intermediate priority implementation flush. Build is broken.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc_anal.c      1.10 -> 1.11     2 inserted, 1 deleted
ossp-pkg/rc/rc_const.h      1.12 -> 1.13     2 inserted, 0 deleted
ossp-pkg/rc/rc_proc.c      1.16 -> 1.17     34 inserted, 13 deleted
ossp-pkg/rc/rc_script.c      1.10 -> 1.11     37 inserted, 18 deleted

ossp-pkg/rc/rc_anal.c 1.10 -> 1.11

--- rc_anal.c    2002/08/01 09:45:19     1.10
+++ rc_anal.c    2002/08/02 20:09:59     1.11
@@ -203,7 +203,8 @@
     /* Loop through file index setting rc 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;
+    (*ppInst)->m_szRcs[nIter] = NULL; /* Terminate */
+    (*ppInst)->m_nRcs = nCount; /* Store how many globbed files there are */
 
     /* Cleanup our Dirent object */
     if (pppFiles) {


ossp-pkg/rc/rc_const.h 1.12 -> 1.13

--- rc_const.h   2002/08/01 13:25:32     1.12
+++ rc_const.h   2002/08/02 20:09:59     1.13
@@ -125,5 +125,7 @@
 #define RC_DEF_OFF    "0"                       /* Digital switch */
 #define RC_DEF_DEF    "^%(\\w+)[ \t]*(.*?)\\n(.*?)^$" /* Section definition */
 #define RC_DEF_NCF    "config"                  /* Config section name */
+#define RC_DEF_PRG    "-p"                      /* Section priority string */
+#define RC_DEF_PRI    200                       /* Section priority value */
 
 #endif /* __OSSPRC_CONST_H__ */


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;


ossp-pkg/rc/rc_script.c 1.10 -> 1.11

--- rc_script.c  2002/08/01 14:31:38     1.10
+++ rc_script.c  2002/08/02 20:09:59     1.11
@@ -30,9 +30,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "rc.h"         /* Public Rc interface      */
-#include "rc_pcre.h"    /* For section parsing      */
-#include "rc_config.h"  /* For configuration access */
+#include "rc.h"         /* Public Rc interface        */
+#include "rc_pcre.h"    /* For section parsing        */
+#include "rc_config.h"  /* For configuration access   */
+#include "rc_const.h"   /* For configuration defaults */
 
 
 /************************************************
@@ -100,11 +101,12 @@
 * scriptSection(rc_script_t *, const char *)    *
 * Parse a script for a given section            *
 ************************************************/
-char *scriptSection(rc_script_t *pScript, const char *kszSecname)
+rc_section_t *scriptSection(rc_script_t *pScript, const char *kszSecname)
 {
-    char *szTempout    = NULL;
+    rc_section_t *pSec = NULL;
     char *piLabstart   = NULL;
     int   nLabsize     = NULL;
+    char *piSubtemp    = NULL; /* To find priority and userid in substrings */
     char *piBlocend    = NULL; /* Misnomer used to control section looping */
     char *piStart      = NULL;
     char *piEnd        = NULL;
@@ -145,18 +147,18 @@
 /*    pAwesome += RC_GOOD_VIBRATIONS;*/ /* Add good vibes for super action */
 
     /***********************************************************************/
-    /* Reminder: PCRE writes vectors to help identify substrings           */
+    /* Reminder: PCRE writes vectors to help identify substrings.          */
     /*           That means that in the following code we can              */
     /*           execute a compiled PCRE regex (ab)(\s)(.*)$               */
     /*                                                                     */
     /*           piBlocend + pnVec[0] = 'start of whole matched string'    */
     /*           piBlocend + pnVec[1] = 'end of whole matched string'      */
-    /*           piBlocend + pnVec[2] = 'start of first substring ab'      */
-    /*           piBlocend + pnVec[3] = 'end of first substring ab'        */
-    /*           piBlocend + pnVec[4] = 'start of second substring \s'     */
-    /*           piBlocend + pnVec[5] = 'end of second substring \s'       */
-    /*           piBlocend + pnVec[6] = 'start of third substring .*'      */
-    /*           piBlocend + pnVec[7] = 'end of third substring .*'        */
+    /*           piBlocend + pnVec[2] = 'start of first substring (ab)'    */
+    /*           piBlocend + pnVec[3] = 'end of first substring (ab)'      */
+    /*           piBlocend + pnVec[4] = 'start of second substring (\s)'   */
+    /*           piBlocend + pnVec[5] = 'end of second substring (\s)'     */
+    /*           piBlocend + pnVec[6] = 'start of third substring (.*)'    */
+    /*           piBlocend + pnVec[7] = 'end of third substring (.*)'      */
     /***********************************************************************/
 
     /* Filter the rc file for the section label, do it here the first time */
@@ -169,18 +171,35 @@
         piLabstart = piBlocend + *(pnVec + 2);
         nLabsize   = *(pnVec + 3) - *(pnVec + 2);
 
-        /* Test the substring. If it matches our label, generate a subscript */
+        /* Test the substring. If it matches our label, make a new section */
         if (!strncmp(piLabstart, kszSecname, nLabsize)) {
+            /* Handle the section body */
             piStart   = piBlocend + *(pnVec + 6);
             piEnd     = piBlocend + *(pnVec + 7);
-            szTempout = malloc(piEnd - piStart + sizeof(char));
-            strncpy(szTempout, piStart, piEnd - piStart);
-            *(szTempout + (piEnd - piStart)) = NULL;    /* Terminate outgoing */
-            return(szTempout);  /* Section found, so return the text */
+            pSec = sectionNew();
+            pSec->szData = malloc(piEnd - piStart + sizeof(char));
+            strncpy(pSec->szData, piStart, piEnd - piStart);
+            *(pSec->szData + (piEnd - piStart)) = NULL; /* Terminate outgoing */
+
+            /* Handle the section priority */
+            piStart = piBlocend + *(pnVec + 4);
+            piEnd   = piBlocend + *(pnVec + 5);
+            /* FIXME: Implement --ParseSectionParam for extra gravy */
+            piSubtemp = strnstr(piStart, RC_DEF_PRG, piEnd - piStart);
+            if (piSubtemp) { /* Priority pattern found */
+/* FIXME: Remove the 1 in the following line! */
+                pSec->nPri = strtol(piSubtemp + strlen(RC_DEF_PRG) + 1, (char **)NULL, 10);
+            }
+            else /* Fallback to default value */
+                pSec->nPri = RC_DEF_PRI;
+
+fprintf(stderr, "nPri ist %d!\n", pSec->nPri);
+            /* Handle the section userid   */
+            return(pSec);   /* Section found, so return the text */
         }
 
+        /* Looks like we didn't find the section yet, so keep trying */
         piBlocend += *(pnVec + 1);  /* Find end of section block */
-        /* Get ready for the next round of matching */
         nFound = pcre_exec(pRegex, pExtra, piBlocend,\
             strlen(piBlocend), 0, 0, pnVec, nVecsize);
     }

CVSTrac 2.0.1