OSSP CVS Repository

ossp - Check-in [3462]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3462
Date: 2003-Jun-27 16:26:13 (local)
2003-Jun-27 14:26:13 (UTC)
User:ms
Branch:
Comment: Implement common section parsing and running on execution mode.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.51 -> 1.52     1 inserted, 0 deleted
ossp-pkg/rc/rc_const.h      1.29 -> 1.30     0 inserted, 3 deleted
ossp-pkg/rc/rc_file.c      1.2 -> 1.3     3 inserted, 1 deleted
ossp-pkg/rc/rc_list.c      1.1 -> 1.2     20 inserted, 0 deleted
ossp-pkg/rc/rc_proc.c      1.49 -> 1.50     54 inserted, 14 deleted
ossp-pkg/rc/rc_sect.c      1.15 -> 1.16     7 inserted, 2 deleted

ossp-pkg/rc/rc.h 1.51 -> 1.52

--- rc.h 2003/06/26 18:45:14     1.51
+++ rc.h 2003/06/27 14:26:13     1.52
@@ -102,6 +102,7 @@
 /* List function prototypes */
 rc_list_t *listNew(void);
 rc_return_t listDelete(rc_list_t *);
+rc_file_t *listGetrcfile(rc_list_t *, const char *);
 rc_return_t listPopulate(rc_list_t *, const char *);
 
 /* Script function prototypes */


ossp-pkg/rc/rc_const.h 1.29 -> 1.30

--- rc_const.h   2003/06/26 18:45:14     1.29
+++ rc_const.h   2003/06/27 14:26:13     1.30
@@ -47,9 +47,6 @@
 #define RC_PNF_TEXT "# Printing code from functions file."
 #define RC_PRN_TEXT "# Printing section %s of rcfile %s."
 
-/* Single word user text, should not include termination */
-#define RC_CFG_TEXT "config"
-
 /* Option descriptions used with popt, should not include termination */
 #define RC_USE_DESC "Print a short usage summary, then exit."
 #define RC_DBG_DESC "Don't remove temporary files, and write debug messages to stderr."


ossp-pkg/rc/rc_file.c 1.2 -> 1.3

--- rc_file.c    2003/06/26 18:45:14     1.2
+++ rc_file.c    2003/06/27 14:26:13     1.3
@@ -316,6 +316,8 @@
 {
     int nIter = 0;
 
+    assert(pRcf && szSec);
+
     /* Return the section if it is found */
     for (nIter = 0; nIter < pRcf->m_nSecs; nIter++) {
         if (!strcmp(pRcf->m_ppSecvec[nIter]->m_szName, szSec))
@@ -362,7 +364,7 @@
 
     /* Deep copy of section text */
     if (scriptGetdata(pInsec->m_pData))
-        scriptSetdata(pRcfile->m_ppSecvec[pRcfile->m_nSecs]->m_pData, pInsec->m_pData);
+        scriptSetdata(pRcfile->m_ppSecvec[pRcfile->m_nSecs]->m_pData, scriptGetdata(pInsec->m_pData));
 
     return(RC_THROW(RC_OK));
 }


ossp-pkg/rc/rc_list.c 1.1 -> 1.2

--- rc_list.c    2003/06/18 14:35:29     1.1
+++ rc_list.c    2003/06/27 14:26:13     1.2
@@ -138,6 +138,26 @@
 }
 
 /************************************************
+* listGetrcfile(rc_list_t *, const char *)      *
+* Searches the rcfile list and returns the file *
+* matching the given name                       *
+************************************************/
+rc_file_t *listGetrcfile(rc_list_t *pInst, const char *kszName)
+{
+    int nIter = 0;
+
+    assert(pInst && kszName); /* Dummy check */
+
+    /* Iterate through list, searching for a rcfile matching the given name */
+    for (nIter = 0; nIter < pInst->m_nFiles && \
+        strcmp(pInst->m_ppFilevec[nIter]->m_szName, kszName); nIter++);
+    if (nIter < pInst->m_nFiles)
+        return(pInst->m_ppFilevec[nIter]);  /* Name of rcfile in list matched */
+    else
+        return(NULL);                       /* Name did not match any rcfile  */
+}
+
+/************************************************
 * listDelete(rc_list_t *)                       *
 * Destruct a rcfile list                        *
 ************************************************/


ossp-pkg/rc/rc_proc.c 1.49 -> 1.50

--- rc_proc.c    2003/06/27 10:15:19     1.49
+++ rc_proc.c    2003/06/27 14:26:13     1.50
@@ -205,9 +205,9 @@
         scriptAdd(pFatscript, pRc->m_pScriptfunc);
         /* Conditionally print config section notice in verbal mode */
         if (configGetval(RC_VRB_VAL)) {
-            nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CFG_TEXT) * 2 + 2) * sizeof (char);
+            nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_DEF_NCF) * 2 + 2) * sizeof (char);
             szVerbose = malloc(nBytes);
-            sprintf(szVerbose, RC_EVN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
+            sprintf(szVerbose, RC_EVN_TEXT, RC_DEF_NCF, RC_DEF_NCF);
             strcat(szVerbose, "\n");
             scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
             free(szVerbose);
@@ -232,7 +232,7 @@
                     szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
                     nBytes = (strlen(RC_EVN_TEXT) + strlen(szTmp) + 2) * sizeof (char);
                     szVerbose = malloc(nBytes);
-                    sprintf(szVerbose, RC_EVN_TEXT, szTmp, szTmp);
+                    sprintf(szVerbose, RC_EVN_TEXT, szTmp, sectionGetparent(ppSectmp[nTmp]));
                     strcat(szVerbose, "\n");
                     scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
                     free(szVerbose);
@@ -322,10 +322,10 @@
                     size_t nSection = 0;
 
                     /* Allocate space just for string to prepare for verbose */
-                    nSizverb = (strlen(RC_EXN_TEXT) + strlen(RC_CFG_TEXT) * 2 \
+                    nSizverb = (strlen(RC_EXN_TEXT) + strlen(RC_DEF_NCF) * 2 \
                         + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
                     szVerbose = malloc(nSizverb);
-                    sprintf(szVerbose, RC_EXN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
+                    sprintf(szVerbose, RC_EXN_TEXT, RC_DEF_NCF, sectionGetparent(ppSectmp[nTmp]));
 
                     /* Allocate space for entire string to execvp(3) */
                     nPrescr = (strlen(RC_VST_TEXT) + strlen(RC_EXF_TEXT) + \
@@ -337,8 +337,12 @@
                     strcat(szExec, RC_ECHO_STR);    /* Continue with the echo string */
                     strcat(szExec, "\"");           /* Append a quote next to the echo */
                     strcat(szExec, RC_VST_TEXT);    /* Continue with the start text */
-                    strcat(szExec, "\n");           /* Stick a newline inbetween */
-                    strcat(szExec, RC_EXF_TEXT);    /* Continue with the func text */
+
+                    if (strlen(szFunc) > 0) {
+                        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 funcs script code */
                     strcat(szExec, RC_ECHO_STR);    /* Continue with the echo string */
@@ -346,14 +350,39 @@
                     strcat(szExec, szVerbose);      /* Continue with the config text */
                     strcat(szExec, "\";");          /* Finalize the verbosity notice */
                     strcat(szExec, szCnf);          /* Then with the config script code  */
+
+                    /* Examine our list, and try to take the corresponding */
+                    /* common section data from it to add to your script   */
+                    {
+                        rc_section_t *pComsec = NULL;
+                        pComsec = rcfileGetsec(listGetrcfile(pRc->m_pList, \
+                            ppSectmp[nTmp]->m_szParent), configGetval(RC_CMN_VAL));
+                        if (pComsec) { /* If we have a common section to load,  */
+                            szTmp = (char *)sectionGetname(pComsec);
+                            nSecverb = (strlen(RC_EXN_TEXT) + strlen(szTmp) * 2 \
+                                + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
+                            realloc(szVerbose, nSecverb);
+                            sprintf(szVerbose, RC_EXN_TEXT, szTmp, sectionGetparent(pComsec));
+                            nSection = (strlen(szTmp) + 1) * sizeof (char);
+                            realloc(szExec, nSizverb + nPrescr + nSecverb + nSection);
+                            strcat(szExec, RC_ECHO_STR);    /* Start out 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, sectionGetdata(pComsec)); /* load it */
+                        }
+                    }
+
+                    /* Build last set of verbose data for the actual script */
                     szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
                     nSecverb = (strlen(RC_EXN_TEXT) + strlen(szTmp) * 2 \
                         + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
                     realloc(szVerbose, nSecverb);
-                    sprintf(szVerbose, RC_EXN_TEXT, szTmp, szTmp);
-                    szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
-                    nSection = (strlen(szTmp) + 1) * sizeof (char);
+                    sprintf(szVerbose, RC_EXN_TEXT, szTmp, sectionGetparent(ppSectmp[nTmp]));
+                    nSection = (strlen(szTmp) + strlen(sectionGetdata(ppSectmp[nTmp])) + 1) * sizeof (char);
                     realloc(szExec, nSizverb + nPrescr + nSecverb + nSection);
+
+                    szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
                     strcat(szExec, RC_ECHO_STR);    /* Start out with the echo string */
                     strcat(szExec, "\"");           /* Append a quote next to the echo */
                     strcat(szExec, szVerbose);      /* Continue with the verboseity text */
@@ -392,6 +421,17 @@
                     strcpy(szExec, RC_BANG_STR);     /* Start out with the shebang string */
                     strcat(szExec, szFunc); /* Continue with just the funcs script code   */
                     strcat(szExec, szCnf);  /* Continue with just the config script code  */
+
+                    /* Examine our list, and try to take the corresponding */
+                    /* common section data from it to add to your script   */
+                    {
+                        rc_section_t *pComsec = NULL;
+                        pComsec = rcfileGetsec(listGetrcfile(pRc->m_pList, \
+                            ppSectmp[nTmp]->m_szParent), configGetval(RC_CMN_VAL));
+                        if (pComsec)   /* If we have a common section to load,  */
+                            strcat(szExec, sectionGetdata(pComsec)); /* load it */
+                    }
+
                     strcat(szExec, szTmp);  /* And build a section onto the command chain */
                     pszVec[2] = szExec;     /* Actually launch the new process image now  */
 
@@ -438,9 +478,9 @@
         scriptDump(pRc->m_pScriptfunc); /* Dump the funcs script */
         /* Conditionally print config section notice in verbal mode */
         if (configGetval(RC_VRB_VAL)) {
-            nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_CFG_TEXT) * 2 + 2) * sizeof (char);
+            nBytes = (strlen(RC_EVN_TEXT) + strlen(RC_DEF_NCF) * 2 + 2) * sizeof (char);
             szVerbose = malloc(nBytes);
-            sprintf(szVerbose, RC_EVN_TEXT, RC_CFG_TEXT, RC_CFG_TEXT);
+            sprintf(szVerbose, RC_EVN_TEXT, RC_DEF_NCF, RC_DEF_NCF);
             strcat(szVerbose, "\n");
             fprintf(stderr, szVerbose);
             free(szVerbose);
@@ -465,7 +505,7 @@
                     szTmp = (char *)sectionGetname(ppSectmp[nTmp]);
                     nBytes = (strlen(RC_PRN_TEXT) + strlen(szTmp) + 1) * sizeof (char);
                     szVerbose = malloc(nBytes);
-                    sprintf(szVerbose, RC_PRN_TEXT, szTmp, szTmp);
+                    sprintf(szVerbose, RC_PRN_TEXT, szTmp, sectionGetparent(ppSectmp[nTmp]));
                     fprintf(stderr, "%s", szVerbose);
                     free(szVerbose);
                     szVerbose = NULL;
@@ -479,7 +519,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_CFG_TEXT);
+        fprintf(stderr, "file %s, section %s\n", pRc->m_pList->m_ppFilevec[nRcs]->m_szName, RC_DEF_NCF);
         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 && \


ossp-pkg/rc/rc_sect.c 1.15 -> 1.16

--- rc_sect.c    2003/06/26 18:45:14     1.15
+++ rc_sect.c    2003/06/27 14:26:13     1.16
@@ -161,8 +161,13 @@
 
 const char *sectionGetdata(rc_section_t *pSec)
 { /* Data of section, this is the script body of the particular section */
-    if (pSec && scriptGetdata(pSec->m_pData))
-        return(scriptGetdata(pSec->m_pData));
+    char *szScriptdata = NULL;
+
+    if (pSec && (szScriptdata = scriptGetdata(pSec->m_pData)))
+        if (strlen(szScriptdata) > 0)
+            return(szScriptdata);
+        else
+            return NULL;
     else
         RC_THROW(RC_ERR_USE);
 

CVSTrac 2.0.1