OSSP CVS Repository

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

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