Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.12' '-r1.13' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- rc_proc.c 2002/07/05 12:54:56 1.12 +++ rc_proc.c 2002/07/10 19:03:58 1.13 @@ -94,6 +94,9 @@ } } + /* Stick on the starting shell id line */ + scriptAppend(pRc->m_pScript, "#! /bin/sh\n", strlen("#! /bin/sh\n")); + /* Read the func file if it was opened successfully */ /* We unfortunately make the assumption that 0 is an invalid filedesc */ if (nFdfunc) { @@ -101,6 +104,7 @@ while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) { scriptAppend(pRc->m_pScript, sBuf, nRet); } + scriptAppend(pRc->m_pScript, "\n", sizeof(char)); if (nRet == -1) /* Handle read errors */ RC_THROW(RC_ERR_IO); } @@ -129,18 +133,29 @@ RC_THROW(RC_ERR_IO); 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 */ + } + 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 append if the section lookup succeeds */ + 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 */ fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\ pRc->m_pAnal->m_pszSecs[i],\ pRc->m_pAnal->m_szRcs[nIter]); - if (szSec) { /* Cleanup section string */ + if (szSec) { /* Cleanup iterative section string */ free(szSec); szSec = NULL; } Index: ossp-pkg/rc/rc_script.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_script.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/rc/rc_script.c,v' 2>/dev/null --- 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 */