--- rc_script.c 2002/07/05 12:54:56 1.6
+++ rc_script.c 2002/07/10 19:03:58 1.7
@@ -104,7 +104,8 @@
{
char *szTempout = NULL;
char *piLabstart = NULL;
- char *piLabend = NULL;
+ int nLabsize = NULL;
+ char *piBlocend = NULL; /* Misnomer used to control section looping */
char *piStart = NULL;
char *piEnd = NULL;
int nOffset = 0;
@@ -112,8 +113,9 @@
int nVecsize = 0;
int nSubstrings = 0;
int *pnVec = NULL;
- const int kiRegopt = 0;
const char *kszErr = NULL;
+ const int kiRegopt = PCRE_DOTALL | PCRE_MULTILINE;
+/* const int kiRegopt = PCRE_DOTALL | PCRE_MULTILINE | PCRE_UNGREEDY;*/
pcre *pRegex = NULL; /* Perl Compatible Regular Expression */
pcre_extra *pExtra = NULL; /* Used for studying an expression */
@@ -121,8 +123,8 @@
assert(pScript); /* Check for a valid incoming script */
assert(configGetval(RC_DEF_VAL));
- if (!kszSecname) /* If we get a NULL section label, give a NULL result */
- return (NULL); /* This might be useful in some loop constructs */
+ if (!kszSecname) /* If we get a NULL section label, then throw up */
+ RC_THROW(RC_ERR_USE);
if ((pRegex = pcre_compile(configGetval(RC_DEF_VAL), kiRegopt, &kszErr, &nOffset, NULL)) == NULL) {
RC_THROW(RC_ERR_SYS);
@@ -140,36 +142,32 @@
/* Use multiples of six, because PCRE needs 2x multiples of three */
nVecsize = 6 * (nSubstrings > 0 ? nSubstrings : 1);
nVecsize *= RC_GOOD_MEASURE; /* Add redundancy factor for error margin */
+/* pAwesome += RC_GOOD_VIBRATIONS;*/ /* Add good vibes for super action */
/* Filter the rc file for the section label, do it here the first time */
pnVec = calloc(nVecsize, sizeof(int)); /* 2/3 vec 1/3 scrapinfo */
nFound = pcre_exec(pRegex, pExtra, *pScript,\
strlen(*pScript), 0, 0, pnVec, nVecsize);
- piLabend = *pScript; /* Start piLabstart pointing to the script object */
+ piBlocend = *pScript; /* Start piBlocend pointing to the script object */
while (nFound > 1) { /* Loop as long as we have more sections */
- piLabstart = piLabend + *(pnVec + 2 * RC_SEC_SUB); /* Seclabel start */
- piLabend += *(pnVec + 1); /* Find end of section label */
+ piLabstart = piBlocend + *(pnVec + 2);
+ nLabsize = *(pnVec + 3) - *(pnVec + 2);
/* Test the substring. If it matches our label, generate a subscript */
- if (!strncmp(piLabstart , kszSecname, sizeof(kszSecname))) {
- piStart = strstr(piLabend, "\n") + sizeof(char); /* Wrap to start */
-
- /* See if more sections follow or if this is the last one */
- if (pcre_exec(pRegex, pExtra, piLabend, strlen(*pScript), 0, 0, pnVec, nVecsize) > 0)
- piEnd = piLabend + *pnVec;
- else /* Doch, last section in file */
- piEnd = piLabend + strlen(*pScript);
-
+ if (!strncmp(piLabstart, kszSecname, nLabsize)) {
+ piStart = piBlocend + *(pnVec + 4);
+ piEnd = piBlocend + *(pnVec + 5);
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 */
}
+ piBlocend += *(pnVec + 1); /* Find end of section block */
/* Get ready for the next round of matching */
- nFound = pcre_exec(pRegex, pExtra, piLabend,\
- strlen(piLabend), 0, 0, pnVec, nVecsize);
+ nFound = pcre_exec(pRegex, pExtra, piBlocend,\
+ strlen(piBlocend), 0, 0, pnVec, nVecsize);
}
/* Under correct conditions, the section subscript was returned in loop */
|