Check-in Number:
|
3338 | |
Date: |
2003-May-15 14:49:11 (local)
2003-May-15 12:49:11 (UTC) |
User: | ms |
Branch: | |
Comment: |
Add sectionCopy(), sectionDump(), and vectorCount(), and change the processor
object's script vector to a section vector. |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/rc/rc.h 1.40 -> 1.41
--- rc.h 2003/05/14 16:36:28 1.40
+++ rc.h 2003/05/15 12:49:11 1.41
@@ -119,6 +119,7 @@
/* Section function prototypes */
rc_section_t *sectionNew(void);
+rc_section_t *sectionCopy(rc_section_t *);
const int sectionGetpri(rc_section_t *);
const int sectionGetuid(rc_section_t *);
const char *sectionGetdata(rc_section_t *);
@@ -127,6 +128,7 @@
rc_return_t sectionSetuid(rc_section_t *, long);
rc_return_t sectionSetdata(rc_section_t *, const char *);
rc_return_t sectionSetndata(rc_section_t *, const char *, size_t);
+rc_return_t sectionDump(rc_section_t *);
rc_return_t sectionDelete(rc_section_t *);
/* Processor function prototypes */
@@ -143,6 +145,7 @@
/* Utility (nonbounded) function prototypes */
char *strErr(rc_return_t);
char **vectorCopy(const char **);
+short vectorCount(const char **);
rc_return_t vectorDel(char **);
/* Other function prototypes */
|
|
ossp-pkg/rc/rc_anal.c 1.12 -> 1.13
--- rc_anal.c 2003/05/12 15:43:32 1.12
+++ rc_anal.c 2003/05/15 12:49:11 1.13
@@ -156,6 +156,7 @@
ex_try { /* Sections are a vector, so we must copy accordingly */
(*ppInst)->m_pszSecs = vectorCopy(pkszVector);
+ (*ppInst)->m_nSecs = vectorCount(pkszVector);
}
ex_catch(Except) {
TRACE("VectorCopy broke");
|
|
ossp-pkg/rc/rc_private.h 1.22 -> 1.23
--- rc_private.h 2003/05/14 16:36:28 1.22
+++ rc_private.h 2003/05/15 12:49:11 1.23
@@ -75,6 +75,7 @@
/* Analyser type */
typedef struct {
short m_nRcs; /* How many rc files */
+ short m_nSecs; /* How many sections */
char **m_szRcs; /* Rc file names */
char *m_szTmp; /* Temp file name */
char *m_szFuncs; /* Function file names */
@@ -97,7 +98,7 @@
typedef struct {
rc_anal_t *m_pAnal;
rc_script_t *m_pScriptcom;
- rc_script_t **m_ppScriptvec;
+ rc_section_t **m_ppSectvec;
} rc_proc_t;
#endif /* __OSSPRC_PRIVATE_H__ */
|
|
ossp-pkg/rc/rc_proc.c 1.21 -> 1.22
--- rc_proc.c 2003/05/14 16:36:28 1.21
+++ rc_proc.c 2003/05/15 12:49:11 1.22
@@ -45,7 +45,7 @@
************************************************/
rc_proc_t *procNew(void)
{
- int nIter = 0;
+/* int nIter = 0;*/
rc_proc_t *pNewrc = NULL;
pNewrc = malloc(sizeof(rc_proc_t));
@@ -54,9 +54,10 @@
pNewrc->m_pScriptcom = scriptNew(); /* Construct a run-command script */
/* Logic needed for multiple run-command section combination with priorities */
- pNewrc->m_ppScriptvec = malloc(sizeof(rc_script_t *) * pNewrc->m_pAnal->m_nRcs);
- for (nIter = 0; nIter < pNewrc->m_pAnal->m_nRcs; nIter++)
- pNewrc->m_ppScriptvec[nIter] = scriptNew();
+ pNewrc->m_ppSectvec = calloc(pNewrc->m_pAnal->m_nRcs *\
+ pNewrc->m_pAnal->m_nSecs, sizeof(rc_section_t *));
+/* for (nIter = 0; nIter < pNewrc->m_pAnal->m_nRcs; nIter++)
+ pNewrc->m_ppSectvec[nIter] = sectionNew();*/
return(pNewrc);
}
@@ -153,11 +154,8 @@
/* Extract a section from the temp script, and append it */
pSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]);
- if (pSec) { /* Only call if the section lookup succeeds */
- scriptAppend(pRc->m_ppScriptvec[nIter], sectionGetdata(pSec),
- sectionGetlen(pSec) - 1);
- scriptAppend(pRc->m_ppScriptvec[nIter], "\n", sizeof(char));
- }
+ if (pSec) /* Only copy if the section lookup succeeds */
+ pRc->m_ppSectvec[pRc->m_pAnal->m_nSecs * nIter + i] = sectionCopy(pSec);
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],\
@@ -216,10 +214,9 @@
}
else if (configGetval(RC_PRN_VAL)) { /* Print */
scriptDump(pRc->m_pScriptcom);
- for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs; nIter++) {
- if (*pRc->m_ppScriptvec[nIter])
- scriptDump(pRc->m_ppScriptvec[nIter]);
- }
+ for (nIter = 0; nIter < pRc->m_pAnal->m_nRcs * pRc->m_pAnal->m_nSecs; nIter++)
+ if (pRc->m_ppSectvec[nIter])
+ sectionDump(pRc->m_ppSectvec[nIter]);
}
else /* Something is wrong here */
return(RC_THROW(RC_ERR_INT));
@@ -233,17 +230,17 @@
************************************************/
rc_return_t procDelete(rc_proc_t *pRc)
{
- int nIter = 0;
+ int nSecvec = pRc->m_pAnal->m_nRcs * pRc->m_pAnal->m_nSecs;
- /* Destroy the script vector */
- for (nIter = pRc->m_pAnal->m_nRcs - 1; nIter >= 0 ; nIter--) {
- if (pRc->m_ppScriptvec[nIter]) {
- scriptDelete(pRc->m_ppScriptvec[nIter]);
- pRc->m_ppScriptvec[nIter] = NULL;
+ /* Destroy the section vector */
+ while (nSecvec-- > 0) {
+ if (pRc->m_ppSectvec[nSecvec]) {
+ sectionDelete(pRc->m_ppSectvec[nSecvec]);
+ pRc->m_ppSectvec[nSecvec] = NULL;
}
}
- free(pRc->m_ppScriptvec);
- pRc->m_ppScriptvec = NULL;
+ free(pRc->m_ppSectvec);
+ pRc->m_ppSectvec = NULL;
scriptDelete(pRc->m_pScriptcom); /* Destroy the script */
analDelete(pRc->m_pAnal); /* Destroy the analyser */
free(pRc); /* Free the processor itself */
|
|
ossp-pkg/rc/rc_sect.c 1.3 -> 1.4
--- rc_sect.c 2003/05/14 16:36:28 1.3
+++ rc_sect.c 2003/05/15 12:49:11 1.4
@@ -52,6 +52,28 @@
}
/************************************************
+* sectionCopy(rc_section_t *) *
+* Opaque copy constructor *
+************************************************/
+rc_section_t *sectionCopy(rc_section_t *pOrigsec)
+{
+ rc_section_t *pSec = NULL;
+
+ /* Today is a rain and no coffee day */
+ pSec = (rc_section_t *)malloc(sizeof(rc_section_t));
+ pSec->nPri = pOrigsec->nPri;
+ pSec->nUid = pOrigsec->nUid;
+ pSec->szData = malloc(strlen(pOrigsec->szData) * sizeof(char) + 1);
+ strcpy(pSec->szData, pOrigsec->szData);
+ pSec->Bytes = pOrigsec->Bytes;
+
+ if (!pSec)
+ RC_THROW(RC_ERR_MEM);
+
+ return(pSec);
+}
+
+/************************************************
* sectionGetXXX(rc_section_t *) *
* Accessor methods *
************************************************/
@@ -160,6 +182,22 @@
}
/************************************************
+* sectionDump(rc_section_t *) *
+* Print a section to standard out *
+************************************************/
+rc_return_t sectionDump(rc_section_t *pSec)
+{
+ /* Don't remove this! It encapsulates the script object, */
+ /* which might not be a simple string */
+ if (pSec) {
+ fprintf(stdout, "%s", sectionGetdata(pSec));
+ return(RC_THROW(RC_OK));
+ }
+ else
+ return(RC_THROW(RC_ERR_USE));
+}
+
+/************************************************
* sectionDelete(rc_section_t *) *
* Destruct a section *
************************************************/
|
|
ossp-pkg/rc/rc_util.c 1.5 -> 1.6
--- rc_util.c 2002/07/29 15:07:01 1.5
+++ rc_util.c 2003/05/15 12:49:11 1.6
@@ -77,6 +77,18 @@
return(NULL); /* Failure */
}
+/* Vector counter */
+short vectorCount(const char **pszVec)
+{
+ int i = 0;
+ assert(pszVec); /* Check for unallocated incoming */
+
+ while (pszVec[i]) /* Loop through elements, */
+ i++; /* and count them here */
+
+ return(i);
+}
+
/* Vector destructor */
rc_return_t vectorDel(char **pszVec)
{
|
|