--- rc_sect.c 2003/06/18 14:35:29 1.14
+++ rc_sect.c 2003/06/26 18:45:14 1.15
@@ -50,6 +50,7 @@
if (pSec) {
pSec->m_szName = malloc((strlen(szName) + 1) * sizeof(char));
strcpy(pSec->m_szName, szName);
+ pSec->m_pData = scriptNew();
}
else
RC_THROW(RC_ERR_MEM);
@@ -66,9 +67,23 @@
rc_section_t *pSec = NULL;
/* Today is a rain and no coffee day */
- pSec = (rc_section_t *)malloc(sizeof(rc_section_t));
- pSec->m_nPri = pOrigsec->m_nPri;
- pSec->m_nUid = pOrigsec->m_nUid;
+ pSec = (rc_section_t *)calloc(1, sizeof(rc_section_t));
+ pSec->m_nPri = pOrigsec->m_nPri;
+ pSec->m_nUid = pOrigsec->m_nUid;
+
+ /* Deep copy of section name */
+ if (pOrigsec->m_szName) {
+ pSec->m_szName = malloc((strlen(pOrigsec->m_szName) + sizeof(char))\
+ * sizeof(char));
+ strcpy(pSec->m_szName, pOrigsec->m_szName);
+ }
+
+ /* Deep copy of parent name */
+ if (pOrigsec->m_szParent) {
+ pSec->m_szParent = malloc((strlen(pOrigsec->m_szParent) + sizeof(char))\
+ * sizeof(char));
+ strcpy(pSec->m_szParent, pOrigsec->m_szParent);
+ }
/* Deep copy of user name */
if (pOrigsec->m_szLogin) {
@@ -78,10 +93,10 @@
}
/* Deep copy of section text */
- if (pOrigsec->m_szData) {
- pSec->m_szData = malloc((strlen(pOrigsec->m_szData) + sizeof(char))\
- * sizeof(char));
- strcpy(pSec->m_szData, pOrigsec->m_szData);
+ if (scriptGetdata(pOrigsec->m_pData)) {
+ if (!pSec->m_pData)
+ pSec->m_pData = scriptNew();
+ scriptSetdata(pSec->m_pData, scriptGetdata(pOrigsec->m_pData));
}
if (!pSec)
@@ -124,6 +139,16 @@
return(0); /* Not reached */
}
+const char *sectionGetparent(rc_section_t *pSec)
+{ /* Parent rcfile name of section, used for display during verbose */
+ if (pSec)
+ return(pSec->m_szParent);
+ else
+ RC_THROW(RC_ERR_USE);
+
+ return(0); /* Not reached */
+}
+
const char *sectionGetlogin(rc_section_t *pSec)
{ /* User name of section, used for display during print */
if (pSec)
@@ -136,8 +161,8 @@
const char *sectionGetdata(rc_section_t *pSec)
{ /* Data of section, this is the script body of the particular section */
- if (pSec && pSec->m_szData)
- return(pSec->m_szData);
+ if (pSec && scriptGetdata(pSec->m_pData))
+ return(scriptGetdata(pSec->m_pData));
else
RC_THROW(RC_ERR_USE);
@@ -179,6 +204,17 @@
return(RC_THROW(RC_ERR_USE));
}
+rc_return_t sectionSetparent(rc_section_t *pSec, const char *szName)
+{ /* Parent rcfile name of section, used for display during verbose */
+ if (pSec) {
+ pSec->m_szParent = malloc((strlen(szName) + 1) * sizeof (char));
+ strcpy(pSec->m_szParent, szName);
+ return(RC_THROW(RC_OK));
+ }
+
+ return(RC_THROW(RC_ERR_USE));
+}
+
rc_return_t sectionSetlogin(rc_section_t *pSec, const char *szLogin)
{ /* User name of section, used for display during print */
if (pSec) {
@@ -190,44 +226,40 @@
return(RC_THROW(RC_ERR_USE));
}
-rc_return_t sectionSetdata(rc_section_t *pSec, const char *kszScript)
+rc_return_t sectionSetdata(rc_section_t *pSec, const char *kszIn)
{ /* Data of section, this is the script body of the particular section */
- if (pSec) {
- size_t nBytes = (strlen(kszScript) + sizeof(char)) * sizeof(char);
- if (pSec->m_szData) { /* The section data is already in use */
- free(pSec->m_szData);
- pSec->m_szData = malloc(nBytes);
- strcpy(pSec->m_szData, kszScript);
- }
- else { /* Set the data the usual way */
- pSec->m_szData = malloc(nBytes);
- strcpy(pSec->m_szData, kszScript);
- }
- return(RC_THROW(RC_OK));
+
+ assert(pSec && kszIn);
+
+ if (scriptGetdata(pSec->m_pData)) { /* The section data is already in use */
+ scriptDelete(pSec->m_pData);
+ pSec->m_pData = NULL;
}
- return(RC_THROW(RC_ERR_USE));
+ scriptSetdata(pSec->m_pData, kszIn);
+ return(RC_THROW(RC_OK));
}
-rc_return_t sectionSetndata(rc_section_t *pSec, const char *kszScript, size_t Len)
+rc_return_t sectionSetndata(rc_section_t *pSec, const char *kszIn, size_t Len)
{ /* Data of section, this is the script body of the particular section */
- if (pSec) {
- size_t nBytes = (Len + 1) * sizeof(char); /* Set size */
- if (pSec->m_szData) { /* The section data is already in use */
- free(pSec->m_szData);
- pSec->m_szData = malloc(nBytes);
- strncpy(pSec->m_szData, kszScript, Len);
- *(pSec->m_szData + Len) = '\0'; /* Terminate outgoing */
- }
- else { /* Set the data the usual way */
- pSec->m_szData = malloc(nBytes);
- strncpy(pSec->m_szData, kszScript, Len);
- *(pSec->m_szData + Len) = '\0'; /* Terminate outgoing */
- }
- return(RC_THROW(RC_OK));
+
+ char *szTemp = NULL;
+ size_t nBytes = (Len + 1) * sizeof(char); /* Set size */
+
+ assert(pSec && kszIn); /* Dummy detector */
+
+ if (pSec->m_pData) { /* The section data is already in use */
+ scriptDelete(pSec->m_pData);
}
- return(RC_THROW(RC_ERR_USE));
+ pSec->m_pData = scriptNew();
+ szTemp = malloc(nBytes);
+ strncpy(szTemp, kszIn, Len);
+ *(szTemp + Len) = '\0'; /* Terminate outgoing */
+ scriptSetdata(pSec->m_pData, szTemp); /* Finish the job */
+ free(szTemp); /* Deallocate */
+ szTemp = NULL;
+ return(RC_THROW(RC_OK));
}
/************************************************
@@ -281,12 +313,18 @@
{
/* Cleanup our junk */
if (pSec) {
- if (pSec->m_szData)
- free(pSec->m_szData);
- if (pSec->m_szName)
+ if (pSec->m_pData) {
+ scriptDelete(pSec->m_pData);
+ pSec->m_pData = NULL;
+ }
+ if (pSec->m_szName) {
free(pSec->m_szName);
- if (pSec->m_szLogin)
+ pSec->m_szName = NULL;
+ }
+ if (pSec->m_szLogin) {
free(pSec->m_szLogin);
+ pSec->m_szLogin = NULL;
+ }
free(pSec);
}
else /* Dumbass passed an empty section object */
|