--- rc_proc.c 2003/06/23 11:27:53 1.47
+++ rc_proc.c 2003/06/26 18:45:14 1.48
@@ -68,16 +68,15 @@
rc_return_t procPopulate(rc_proc_t *pRc)
{
int nSect = 0;
- int nFdrc = -1;
int nFdfunc = -1;
int nRet = 0;
int nRcs = 0;
ex_t Except;
char *sBuf = NULL;
- char *szLocex = NULL;
- rc_script_t *pTempscript = NULL;
+ rc_file_t *pRcfile = NULL;
rc_section_t *pSec = NULL;
+ rc_section_t *pCom = NULL;
short nTotalsecs = vectorCount(configGetsecs());
assert(pRc->m_pList->m_ppFilevec);
@@ -93,6 +92,7 @@
if (nRet == -1) /* Handle read errors */
RC_THROW(RC_ERR_IO);
scriptAppend(pRc->m_pScriptfunc, "\n", sizeof("\n"));
+ close(nFdfunc); /* Close Func file handle */
}
else
RC_THROW(RC_ERR_FNC);
@@ -104,86 +104,40 @@
if (!pRc->m_pList->m_ppFilevec[nRcs])
RC_THROW(RC_ERR_INT); /* Rcfile vector is missing its tail */
- /* Build the location path name */
- if (!configGetval(RC_LOC_VAL)) {
- szLocex = NULL;
- szLocex = strdup("./"); /* FIXME: Relocate default val */
- RC_THROW(RC_ERR_INT); /* Config should have given a locs default */
- }
- else { /* Only enter block with valid string, strdup can't handle NULL */
- if (*(configGetval(RC_LOC_VAL) + strlen(configGetval(RC_LOC_VAL)) - sizeof (char)) != '/') {
- szLocex = malloc(strlen(configGetval(RC_LOC_VAL)) + \
- sizeof (char) + \
- strlen("rc.") + \
- strlen(pRc->m_pList->m_ppFilevec[nRcs]->m_szName) + \
- sizeof (char));
- strcpy(szLocex, configGetval(RC_LOC_VAL));
- strcat(szLocex, "/");
- strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
- strcat(szLocex, pRc->m_pList->m_ppFilevec[nRcs]->m_szName);
- }
- else {
- szLocex = malloc(strlen(configGetval(RC_LOC_VAL)) + \
- strlen("rc.") + \
- strlen(pRc->m_pList->m_ppFilevec[nRcs]->m_szName) + \
- sizeof (char));
- strcpy(szLocex, configGetval(RC_LOC_VAL));
- strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
- strcat(szLocex, pRc->m_pList->m_ppFilevec[nRcs]->m_szName);
- }
- }
+ pRcfile = rcfileNew(pRc->m_pList->m_ppFilevec[nRcs]->m_szName);
+ rcfileParse(pRcfile);
- /* Open the rc file unconditionally */
- if ((nFdrc = open(szLocex, O_RDONLY)) == -1)
- RC_THROW(RC_ERR_RCF);
-
- /* Read data from the rc file into a temporary script */
- pTempscript = scriptNew();
- while ((nRet = read(nFdrc, sBuf, RC_READ_BUFSIZE)) > 0)
- scriptAppend(pTempscript, sBuf, nRet);
-
- if (nRet == -1) /* Handle read errors */
- RC_THROW(RC_ERR_IO);
-
- try {
- /* Append common section if it exists */
- pSec = scriptSection(pTempscript, configGetval(RC_NCF_VAL));
+ try { /* If it exists, append config section unconditionally */
+ pSec = rcfileGetsec(pRcfile, configGetval(RC_NCF_VAL));
if (pSec) { /* Only operate if the section lookup succeeds */
scriptAppend(pRc->m_pScriptcom, sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
scriptAppend(pRc->m_pScriptcom, "\n", strlen ("\n"));
- sectionDelete(pSec); /* Cleanup */
- pSec = NULL; /* Cleanup */
}
for (nSect = 0; nSect < nTotalsecs; nSect++) { /* Iterate over */
/* Extract a section from the temp script, and append it */
- pSec = scriptSection(pTempscript, configGetsecs()[nSect]);
-
- if (pSec) /* Only copy if the section lookup succeeds */
+ pSec = rcfileGetsec(pRcfile, configGetsecs()[nSect]);
+ if (pSec) {
+ /* Append common section only if the target section matches */
+ pCom = rcfileGetsec(pRcfile, configGetval(RC_CMN_VAL));
+ if (pCom) /* Only append if the common lookup succeeds */
+ rcfileAppendsec(pRc->m_pList->m_ppFilevec[nRcs], pCom);
+ /* Only copy if the section lookup succeeds */
rcfileAppendsec(pRc->m_pList->m_ppFilevec[nRcs], pSec);
+ }
else if (configGetval(RC_DBG_VAL)) /* Only show if debug set */
fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\
configGetsecs()[nSect], pRc->m_pList->m_ppFilevec[nRcs]->m_szName);
-
- if (pSec) { /* Cleanup iterative section string */
- sectionDelete(pSec);
- pSec = NULL;
- }
}
}
catch(Except)
rethrow;
- /* Clean up our crap */
- scriptDelete(pTempscript); /* Temp script */
- pTempscript = NULL;
- free(szLocex); /* Temp Location + Rcfile */
- szLocex = NULL;
- close(nFdrc); /* Close Rc file handle */
+ /* Attach our rcfile in the list */
+ pRc->m_pList->m_ppFilevec[nRcs] = pRcfile;
+ pRcfile = NULL;
}
- close(nFdfunc); /* Close Func file handle */
-
/* Memory cleanups */
if (sBuf) {
free(sBuf);
@@ -248,20 +202,18 @@
free(szVerbose);
szVerbose = NULL;
}
- scriptAppend(pFatscript, scriptTostring(pRc->m_pScriptfunc), \
- strlen(scriptTostring(pRc->m_pScriptfunc)));
+ scriptAdd(pFatscript, pRc->m_pScriptfunc);
/* Conditionally print common section notice in verbal mode */
if (configGetval(RC_VRB_VAL)) {
- nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 2) * sizeof (char);
+ nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CFG_TEXT) * 2 + 2) * sizeof (char);
szVerbose = malloc(nBytes);
- sprintf(szVerbose, RC_EVN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ sprintf(szVerbose, RC_EVN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
strcat(szVerbose, "\n");
scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
free(szVerbose);
szVerbose = NULL;
}
- scriptAppend(pFatscript, scriptTostring(pRc->m_pScriptcom), \
- strlen(scriptTostring(pRc->m_pScriptcom)));
+ scriptAdd(pFatscript, pRc->m_pScriptcom);
for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
for (nRcs = 0; nRcs < pRc->m_pList->m_nFiles; nRcs++) {
for (nTmp = 0; nTmp < pRc->m_pList->m_ppFilevec[nRcs]->m_nSecs && \
@@ -344,8 +296,8 @@
}
/* Allocate a block of section pointers to use temporarily */
ppSectmp = calloc(pRc->m_pList->m_nFiles, sizeof(rc_section_t *));
- szFunc = (char *)scriptTostring(pRc->m_pScriptfunc);
- szCom = (char *)scriptTostring(pRc->m_pScriptcom);
+ szFunc = (char *)scriptGetdata(pRc->m_pScriptfunc);
+ szCom = (char *)scriptGetdata(pRc->m_pScriptcom);
for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
for (nRcs = 0; nRcs < pRc->m_pList->m_nFiles; nRcs++) {
for (nTmp = 0; nTmp < pRc->m_pList->m_ppFilevec[nRcs]->m_nSecs && \
@@ -363,17 +315,17 @@
nTmp = 0; /* Count from zero until however many sections we have */
while (nTmp < pRc->m_pList->m_nFiles && ppSectmp[nTmp]) {
/* Conditionally print common and other section notices in verbal mode */
- if (configGetval(RC_VRB_VAL)) {
+ if (configGetval(RC_VRB_VAL)) { /* Verbose mode is active */
size_t nSizverb = 0;
size_t nPrescr = 0;
size_t nSecverb = 0;
size_t nSection = 0;
/* Allocate space just for string to prepare for verbose */
- nSizverb = (strlen(RC_EXN_TEXT) + strlen(RC_CMN_TEXT) * 2 \
+ nSizverb = (strlen(RC_EXN_TEXT) + strlen(RC_CFG_TEXT) * 2 \
+ strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
szVerbose = malloc(nSizverb);
- sprintf(szVerbose, RC_EXN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ sprintf(szVerbose, RC_EXN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
/* Allocate space for entire string to execvp(3) */
nPrescr = (strlen(RC_VST_TEXT) + strlen(RC_EXF_TEXT) + \
@@ -388,12 +340,12 @@
strcat(szExec, "\n"); /* Stick a newline inbetween */
strcat(szExec, RC_EXF_TEXT); /* Continue with the func text */
strcat(szExec, "\";"); /* Finalize the verbosity notice */
- strcat(szExec, szFunc); /* Continue with the common script code */
+ strcat(szExec, szFunc); /* Continue with the funcs script code */
strcat(szExec, RC_ECHO_STR); /* Continue with the echo string */
strcat(szExec, "\""); /* Append a quote next to the echo */
strcat(szExec, szVerbose); /* Continue with the common text */
strcat(szExec, "\";"); /* Finalize the verbosity notice */
- strcat(szExec, szCom); /* Then with the funcs script code */
+ strcat(szExec, szCom); /* Then with the common script code */
szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
nSecverb = (strlen(RC_EXN_TEXT) + strlen(szTmp) * 2 \
+ strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
@@ -433,7 +385,7 @@
szExec = NULL;
}
}
- else {
+ else { /* Verbose mode is off */
szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
szExec = malloc((strlen(szFunc) + strlen(szCom) + \
strlen(szTmp) + 1) * sizeof(char));
@@ -486,9 +438,9 @@
scriptDump(pRc->m_pScriptfunc); /* Dump the funcs script */
/* Conditionally print common section notice in verbal mode */
if (configGetval(RC_VRB_VAL)) {
- nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 2) * sizeof (char);
+ nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CFG_TEXT) * 2 + 2) * sizeof (char);
szVerbose = malloc(nBytes);
- sprintf(szVerbose, RC_EVN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
+ sprintf(szVerbose, RC_EVN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
strcat(szVerbose, "\n");
fprintf(stderr, szVerbose);
free(szVerbose);
@@ -527,7 +479,7 @@
else if (configGetval(RC_PAR_VAL)) { /* Parse names */
/* Allocate a block of section pointers to use as a temporary */
ppSectmp = calloc(pRc->m_pList->m_nFiles, sizeof(rc_section_t *));
- fprintf(stderr, "file %s, section %s\n", pRc->m_pList->m_ppFilevec[nRcs]->m_szName, RC_CMN_TEXT);
+ fprintf(stderr, "file %s, section %s\n", pRc->m_pList->m_ppFilevec[nRcs]->m_szName, RC_CFG_TEXT);
for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
for (nRcs = 0; nRcs < pRc->m_pList->m_nFiles; nRcs++) {
for (nTmp = 0; nTmp < pRc->m_pList->m_ppFilevec[nRcs]->m_nSecs && \
|