OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_config.c versions 1.13 and 1.14
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_config.c 1.13 -> 1.14

--- rc_config.c  2002/04/23 12:30:29     1.13
+++ rc_config.c  2002/04/24 16:47:07     1.14
@@ -27,12 +27,11 @@
 **  rc_config.c: Run-command processor ISO C source file
 */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "rc.h"
-#include "str.h"
+#include "rc_config.h"
 #include "rc_const.h"               /* String constants                     */
 
 static int m_nLocks = 0;            /* Server locks, not thread-safe FIXME  */
@@ -40,16 +39,46 @@
 
 
 /***************************************
-* configConstruct(void)                *
+* configDebug(void)                    *
+* Debug a configuration                *
+* Warning: There is no error checking  *
+*          or debugging of this        *
+*          debugger block              *
+***************************************/
+void configDebug(void)
+{
+    int i = 0;
+    ex_t Except;
+    char *szTemp = NULL;
+
+    fprintf(stderr, "Run command file: %s\n", configGetrcfile());
+
+    szTemp = (char *)configGetsec(i);
+    fprintf(stderr, "Sections:");
+    while (szTemp) {
+        fprintf(stderr, " %s", szTemp);
+        ex_try {
+            szTemp = (char *)configGetsec(++i);
+        }
+        ex_catch(Except) {
+            break;
+        }
+    }
+
+    fprintf(stderr, "\n%s", configSummarize());
+}
+
+/***************************************
+* configNew(void)                      *
 * Construct a configuration            *
 ***************************************/
-rc_return_t configConstruct(void)
+rc_return_t configNew(void)
 {
     ex_t Except;
 
     if (m_nLocks == 0) {                    /* If we don't have one yet */
         ex_try {                            /* then construct a new one */
-            clioptConstruct();              /* Member cliopt instance   */
+            clioptNew();                    /* Member cliopt instance   */
         }
         ex_catch(Except) {
             rethrow;
@@ -112,6 +141,52 @@
     return(NULL);   /* Not reached  */
 }
 
+const char *configGetrcfile(void)
+{
+    ex_t Except;
+
+    if (m_nLocks) {                     /* Make sure config exists   */
+        ex_try {
+            /* Because (1) only one rc file can be specified and     */
+            /*         (2) it must be specified on the command line, */
+            /* we don't bother checking the environment or conf file */
+            /* contrary to the behaviour of Getval earlier           */
+            return (clioptGetrcfile());
+        }
+        ex_catch(Except) {
+            rethrow;
+        }
+    }
+    else {
+        RC_THROW(RC_ERR_USE);
+    }
+    return(NULL);   /* Not reached  */
+}
+
+const char *configGetsec(int nIndex)
+{
+    ex_t Except;
+    char **pszSectemp = NULL;
+
+    if (m_nLocks && nIndex < clioptGetseclen()) {/* Make sure config exists   */
+        ex_try {                                 /* FIXME Might need to check */
+            pszSectemp = (char **)clioptGetsec();/* FIXME env, conf, configs  */
+            if (pszSectemp[nIndex])
+                return(pszSectemp[nIndex]);
+            else {
+                RC_THROW(RC_ERR_USE);
+            }
+        }
+        ex_catch(Except) {
+            rethrow;
+        }
+    }
+    else {
+        RC_THROW(RC_ERR_USE);
+    }
+    return(NULL);   /* Not reached  */
+}
+
 /***************************************
 * configSummarize(void)                *
 * Configuration summary                *
@@ -120,24 +195,39 @@
 {
     ex_t Except;
     int i = 0;
-    int bCaught = FALSE;
+    char *szTemp = NULL;
 
-    while (!bCaught) {
+    m_szSummary = malloc(NULL);
+    for (i = 0; i < RC_NUMOPTS; i++)
+    {
         ex_try {    /* FIXME Not threadsafe, wrap with crit section */
-            if (configGetval(i)) { /* FIXME Is realloc portable here? */
-                /* FIXME Unportable kludge to ensure storage FIXME */
-                m_szSummary = realloc(m_szSummary, sizeof("OptionXXis") + \
-                    sizeof(configGetname(i)) + sizeof(configGetval(i) + 8));
-                if (!(strcmp(configGetval(i), "1")))
-                    str_concat(m_szSummary, "Option ", configGetname(i), " is on.\n");
-                else
-                    str_concat(m_szSummary, "Option ", configGetname(i), " is ", configGetval(i), ".\n");
+            if (configGetval(i) == NULL); /* NOP */
+            else if (!(strcmp(configGetval(i), "1"))) {
+                szTemp = malloc(strlen(m_szSummary) + strlen(configGetval(i)));
+                strcpy(szTemp, m_szSummary);
+                strcat(szTemp, "Option ");
+                strcat(szTemp, configGetname(i));
+                strcat(szTemp, " is on.\n");
+                if (m_szSummary)
+                    free(m_szSummary);
+                m_szSummary = szTemp;
+            }
+            else {
+                szTemp = malloc(strlen(m_szSummary) + strlen(configGetval(i)));
+                strcpy(szTemp, m_szSummary);
+                strcat(szTemp, "Option ");
+                strcat(szTemp, configGetname(i));
+                strcat(szTemp, " is ");
+                strcat(szTemp, configGetval(i));
+                strcat(szTemp, ".\n");
+                if (m_szSummary)
+                    free(m_szSummary);
+                m_szSummary = szTemp;
             }
-        }           /* FIXME Not threadsafe, wrap with crit section */
-        ex_catch(Except) {  /* Breaks the otherwise endless loop above */
-            bCaught = TRUE;
+        }               /* FIXME Not threadsafe, wrap with crit section */
+        ex_catch(Except) {  /* Breaks the otherwise endless loop above  */
+            rethrow;
         }
-        i++;
     }
 
     return ((const char *)m_szSummary);
@@ -151,16 +241,12 @@
 {
     ex_t Except;
 
-    ex_try {    /* Parse option groups in order of priority     */
-        clioptParse(argc, argv);        /* Command line options */
-/*        envoptParse(m_nLocks->pOpt);*/    /* Environment options  */
-/*        cnfoptParse(m_nLocks->pOpt);*/    /* Configfile options   */
-    }
-    ex_catch(Except) {
-        rethrow;
-    }
-
-    ex_try {
+    ex_try {    /* Parse option groups in order of priority      */
+        clioptParseopt(argc, argv);     /* Command line options  */
+        clioptParserc();                /* Command line rc file  */
+        clioptParsesec();               /* Command line sections */
+/*        envoptParse(m_nLocks->pOpt);*/    /* Environment options   */
+/*        cnfoptParse(m_nLocks->pOpt);*/    /* Configfile options    */
     }
     ex_catch(Except) {
         rethrow;
@@ -170,16 +256,16 @@
 }
 
 /***************************************
-* configDestruct(void)                 *
+* configDelete(void)                   *
 * Destruct a configuration             *
 ***************************************/
-rc_return_t configDestruct(void)
+rc_return_t configDelete(void)
 {
     ex_t Except;
 
     if (--m_nLocks == 0) {          /* If m_nLocks is 0, deallocate */
         ex_try {                    /* FIXME, not thread-safe       */
-            clioptDestruct();
+            clioptDelete();
             if (m_szSummary)
                 free(m_szSummary);
         }

CVSTrac 2.0.1