Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.33' '-r1.34' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/06/26 14:42:53 1.33 +++ rc.c 2002/06/28 14:20:23 1.34 @@ -81,3 +81,4 @@ exit(0); /* Return success */ } + Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.31' '-r1.32' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/06/27 15:35:58 1.31 +++ rc.h 2002/06/28 14:20:23 1.32 @@ -109,6 +109,7 @@ /* Script function prototypes */ rc_script_t *scriptNew(void); rc_return_t scriptAppend(rc_script_t *, char *, size_t); +const char *scriptSection(rc_script_t *, const char *); rc_return_t scriptDump(rc_script_t *); rc_return_t scriptDelete(rc_script_t *); Index: ossp-pkg/rc/rc_anal.c RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_anal.c,v' 2>/dev/null --- rc_anal.c 2002/06/27 15:35:58 1.6 +++ rc_anal.c 2002/06/28 14:20:23 1.7 @@ -55,6 +55,8 @@ ************************************************/ rc_return_t analRcs(rc_anal_t **ppInst, const char *kszName) { + assert(!(*ppInst)->m_szRcs); /* Rcs should be NULL until we set them */ + if (!kszName) { (*ppInst)->m_szRcs = NULL; /* RC_THROW(RC_WRN_NUL);*/ @@ -64,7 +66,6 @@ if (strcmp(kszName, RC_GLOB_WILD)) { *(*ppInst)->m_szRcs = strdup("rc."); strcat(*(*ppInst)->m_szRcs, kszName); - *((*ppInst)->m_szRcs + sizeof(char **)) = NULL; /* Terminate list */ } else /* Wildcard rcfile indicates we must glob the locs directories */ analGloblocs(ppInst); @@ -241,3 +242,4 @@ return(RC_THROW(RC_OK)); } + Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.16' '-r1.17' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- rc_private.h 2002/06/27 15:35:58 1.16 +++ rc_private.h 2002/06/28 14:20:23 1.17 @@ -88,3 +88,4 @@ } rc_proc_t; #endif /* __OSSPRC_PRIVATE_H__ */ + Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- 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)); } + Index: ossp-pkg/rc/rc_script.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_script.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/rc/rc_script.c,v' 2>/dev/null --- rc_script.c 2002/06/26 14:11:16 1.1 +++ rc_script.c 2002/06/28 14:20:23 1.2 @@ -56,6 +56,8 @@ int nResize = 0; void *pvRealloc = NULL; + assert(pScript); /* Script parameter must be valid */ + if (!szInbuf) { TRACE("Problem with appendScript"); /* return(RC_THROW(RC_ERR_USE));*/ @@ -82,7 +84,7 @@ else strncpy(pvRealloc, szInbuf, Size); - /* Coerce strings into one Script again */ + /* Cleanup and deallocate memory */ if (*pScript) { free(*pScript); *pScript = NULL; @@ -93,6 +95,31 @@ } /************************************************ +* scriptSection(rc_script_t *, const char *) * +* Parse a script for a given section * +************************************************/ +const char *scriptSection(rc_script_t *pScript, const char *kszSecname) +{ + char *szTempout = NULL; + char *szTmpsec = NULL; + char *piStart = NULL; + char *piEnd = NULL; + + szTmpsec = malloc(strlen(kszSecname) + sizeof(char)); + strcpy(szTmpsec, "%"); + strcat(szTmpsec, kszSecname); + + piStart = strstr(*pScript, szTmpsec); /* Find start of section */ + piStart = strstr(piStart, "\n") + sizeof(char); /* Wrap to next line */ + piEnd = strstr(piStart + sizeof(char), "%"); /* FIXME: Remove hardcoded */ + szTempout = malloc(piEnd - piStart + sizeof(char)); + strncpy(szTempout, piStart, piEnd - piStart); + *(szTempout + (piEnd - piStart)) = NULL; /* Terminate the outgoing string */ + + return(szTempout); +} + +/************************************************ * scriptDump(rc_script_t *) * * Print a script to standard out * ************************************************/