--- rc_proc.c 2002/06/27 15:35:58 1.6
+++ rc_proc.c 2002/06/28 14:20:23 1.7
@@ -76,11 +76,14 @@
int nFdfunc = 0;
int nRet = 0;
int nIter = 0;
- char *szBuf = NULL;
+ char *sBuf = NULL;
+ char *szSec = NULL;
char *szLocex = NULL;
+ rc_script_t *pTempscript = NULL;
assert(*pRc->m_pAnal->m_szRcs);
- szBuf = (char *)calloc(0, RC_READ_BUFSIZE);
+ sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
+ pTempscript = scriptNew();
/* Open the func file if it exists in the configuration */
if (pRc->m_pAnal->m_szFuncs) {
@@ -90,7 +93,19 @@
}
}
- /* Keep reading possibly globbed rc files until there are none left */
+ /* Read the func file if it was opened successfully */
+ /* We unfortunately make the assumption that 0 is an invalid filedesc */
+ if (nFdfunc) {
+ /* Read data from the func file */
+ while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
+ scriptAppend(pRc->m_pScript, sBuf, nRet);
+ }
+ if (nRet == -1) /* Handle read errors */
+ TRACE("Problem with procPopulate read(2)");
+ /* RC_THROW(RC_ERR_IO);*/
+ }
+
+ /* Iteratively read possibly globbed rc files */
for (nIter = 0; pRc->m_pAnal->m_szRcs[nIter]; nIter++)
{
szLocex = (char *)malloc(strlen(pRc->m_pAnal->m_szLocs) + strlen(pRc->m_pAnal->m_szRcs[nIter]) + 2);
@@ -103,24 +118,17 @@
fprintf(stderr, "Problem with procPopulate open(2) of %s\n", szLocex);
}
- /* Read the func file if it was opened successfully */
- /* We unfortunately make the assumption that 0 is an invalid filedesc */
- if (nFdfunc) {
- /* Read data from the func file */
- while ((nRet = read(nFdfunc, szBuf, RC_READ_BUFSIZE)) > 0)
- scriptAppend(pRc->m_pScript, szBuf, nRet);
- if (nRet == -1) /* Handle read errors */
- TRACE("Problem with procPopulate read(2)");
- /* RC_THROW(RC_ERR_IO);*/
- }
-
- /* Read data from the rc file */
- while ((nRet = read(nFdrc, szBuf, RC_READ_BUFSIZE)) > 0)
- scriptAppend(pRc->m_pScript, szBuf, nRet);
+ /* Read data from the rc file into a temporary script */
+ while ((nRet = read(nFdrc, sBuf, RC_READ_BUFSIZE)) > 0)
+ scriptAppend(pTempscript, sBuf, nRet);
if (nRet == -1) /* Handle read errors */
TRACE("Problem with procPopulate read(2)");
/* RC_THROW(RC_ERR_IO);*/
+ /* Extract a section from the temp script, and append it to other one */
+ szSec = scriptSection(pTempscript, "start"); /* Extract section */
+ scriptAppend(pRc->m_pScript, szSec, strlen(szSec)); /* Append section */
+
free(szLocex); /* Free our temporarily constructed Location + Rcfile */
szLocex = NULL;
close(nFdrc); /* Close Rc file handle */
@@ -129,9 +137,14 @@
close(nFdfunc); /* Close Func file handle */
/* Memory cleanups */
- if (szBuf) {
- free(szBuf);
- szBuf = NULL;
+ scriptDelete(pTempscript);
+ if (sBuf) {
+ free(sBuf);
+ sBuf = NULL;
+ }
+ if (szSec) {
+ free(szSec);
+ szSec = NULL;
}
return(RC_THROW(RC_OK));
@@ -164,3 +177,4 @@
return(RC_THROW(RC_OK));
}
+
|