OSSP CVS Repository

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

ossp-pkg/rc/rc_cliopt.c 1.8 -> 1.9

--- rc_cliopt.c  2002/04/25 16:17:57     1.8
+++ rc_cliopt.c  2002/05/22 13:29:40     1.9
@@ -36,8 +36,8 @@
 #include "popt.h"                              /* OSSP popt options library   */
 
 static char        *m_pszOptuples[RC_NUMOPTS]; /* Option name value tuples    */
-static char        *m_szRcfile = NULL;         /* rc file                     */
-static char       **m_pszSec   = NULL;         /* Section names               */
+static char        *m_szRcfile  = NULL;        /* rc file name                */
+static char        **m_pszSecs  = NULL;        /* Section names               */
 static popt_context m_Optcon;                  /* Context for parsing options */
 
 static struct popt_option m_pOptable[] = {
@@ -135,23 +135,12 @@
     return((const char *)m_szRcfile);
 }
 
-const char **clioptGetsec(void)
+const char **clioptGetsecs(void)
 {
-    if (!m_pszSec)
+    if (!m_pszSecs)
         RC_THROW(RC_ERR_USE);
 
-    return((const char **)m_pszSec);
-}
-
-int clioptGetseclen(void)
-{
-    int i = 0;
-
-    if (!m_pszSec)
-        RC_THROW(RC_ERR_USE);
-
-    for (i = 0; m_pszSec[i]; i++);
-    return(i);
+    return((const char **)m_pszSecs);
 }
 
 rc_return_t clioptSetval(rc_opt_t Optname, const char *kszOptval)
@@ -168,9 +157,9 @@
 
 rc_return_t clioptSetrcfile(const char *kszRc)
 {
-    if (m_szRcfile)                     /* Forbid overwriting */
-        return(RC_THROW(RC_ERR_USE));   /* an existing rcfile */
-    else if (kszRc)
+    if (m_szRcfile)                     /* Warn on overwrites */
+        RC_THROW(RC_WRN_OWR);
+    if (kszRc)
         m_szRcfile = strdup(kszRc);
     else
         return(RC_THROW(RC_ERR_USE));   /* Incoming string is NULL? */
@@ -178,22 +167,23 @@
     return(RC_THROW(RC_OK));
 }
 
-rc_return_t clioptSetsec(const char *pkszSec[])
+rc_return_t clioptSetsecs(const char **pkszSecs)
 {
     int nSecs  = 0;
     int nIndex = 0;
 
-    if (m_pszSec)                                    /* Forbid overwriting */
-        return(RC_THROW(RC_ERR_USE));                /* an existing rcfile */
-    else if (pkszSec) {
-        for (nSecs = 0; pkszSec[nSecs]; nSecs++);    /* Count the sections */
-        m_pszSec = malloc(sizeof (char **) * nSecs + 1);
-
-        for (nIndex = 0; pkszSec[nIndex]; nIndex++) {
-            m_pszSec[nIndex] = malloc(strlen(pkszSec[nIndex]));
-            memcpy(m_pszSec[nIndex], pkszSec[nIndex], strlen(pkszSec[nIndex]));
+    if (m_pszSecs)                                  /* Warn on overwrites */
+        RC_THROW(RC_WRN_OWR);
+    if (pkszSecs) {
+        for (nSecs = 0; pkszSecs[nSecs]; nSecs++);  /* Count the sections */
+        m_pszSecs = malloc(sizeof (char **) * nSecs + 1);
+
+        for (nIndex = 0; pkszSecs[nIndex]; nIndex++) {
+            m_pszSecs[nIndex] = malloc(strlen(pkszSecs[nIndex]));
+            memcpy(m_pszSecs[nIndex], pkszSecs[nIndex],\
+                   strlen(pkszSecs[nIndex]));
         }
-        m_pszSec[nIndex] = NULL; /* Used later to find the end of the array */
+        m_pszSecs[nIndex] = NULL; /* Used later to find the end of the array */
     }
     else
         return(RC_THROW(RC_ERR_USE));   /* Incoming sections are NULL? */
@@ -280,18 +270,18 @@
 }
 
 /***************************************
-* clioptParseopt(int, char **)         *
+* clioptParseopts(int, const char **)  *
 * Parse command line options           *
 ***************************************/
-rc_return_t clioptParseopt(int argc, char *argv[])
+rc_return_t clioptParseopts(int nArgs, const char *szVector[])
 {
     ex_t Except;
     char cliOpt = 0;    /* For argument parsing */
 
-    m_Optcon = popt_getcontext(NULL, argc, (const char **)argv, m_pOptable, 0);
+    m_Optcon = popt_getcontext(NULL, nArgs, szVector, m_pOptable, 0);
     popt_setotheroptionhelp(m_Optcon, "<rcfile> <sections [args]>");
 
-    if (argc < 2) { /* Allow the user to enter just one option, -h z.B. */
+    if (nArgs < 2) { /* Allow the user to enter just one option, -h z.B. */
         fprintf(stderr, RC_LST_TEXT);
         popt_printusage(m_Optcon, stderr, 0);
         return(RC_THROW(RC_ERR_USE));
@@ -303,10 +293,6 @@
             clioptProcess(cliOpt, popt_getoptarg(m_Optcon));
         }
         ex_catch(Except) { /* Error condition probably deserves attention */
-/* FIXME Examine the following line *(int *) for a potential segfault prob */
-            fprintf(stderr, "Class '%s' threw exception %d in %s:%s():\
-                %d.\n", (char *)Except.ex_class, *(int *)Except.ex_value,\
-                Except.ex_file, Except.ex_func, Except.ex_line);
             rethrow;
         }
     }
@@ -322,36 +308,18 @@
     return(RC_THROW(RC_OK));
 }
 
-/***************************************
-* clioptParserc(void)                  *
-* Parse command line rc file           *
-***************************************/
-rc_return_t clioptParserc(void)
-{
-    ex_t Except;
-
-    /* Use popt as a transport to read the user specified rcfile           */
-    ex_try { /* Retrieve exactly one rc file name from the command line    */
-        clioptSetrcfile(popt_getarg(m_Optcon));     /* No file check here  */
-    }
-    ex_catch(Except) {
-        rethrow; /* Our generic response */
-    }
-
-    return(RC_THROW(RC_OK));
-}
-
-/***************************************
-* clioptParsesec(void)                 *
-* Parse command line sections          *
-***************************************/
-rc_return_t clioptParsesec(void)
+/******************************************
+* clioptParseargs(void)                   *
+* Parse command line rc file and sections *
+******************************************/
+rc_return_t clioptParseargs(void)
 {
     ex_t Except;
 
-    /* Use popt as a transport to read the user specified sections  */
-    ex_try { /* Retrieve one or more sections from the command line */
-        clioptSetsec(popt_getargs(m_Optcon));
+    /* Use popt as a transport to read the user specified rcfile and sections */
+    ex_try {
+        clioptSetrcfile(popt_getarg(m_Optcon));
+        clioptSetsecs(popt_getargs(m_Optcon));
     }
     ex_catch(Except) {
         rethrow; /* Our generic response */
@@ -391,12 +359,12 @@
 
     if (m_szRcfile)                     /* Free the rc file arg       */
         free(m_szRcfile);
-    if (m_pszSec) {                     /* Free the section name arg  */
-        for (i = 0; m_pszSec[i]; i++) {
-            free(m_pszSec[i]);
-            m_pszSec[i] = NULL;
+    if (m_pszSecs) {                    /* Free the section name arg  */
+        for (i = 0; m_pszSecs[i]; i++) {
+            free(m_pszSecs[i]);
+            m_pszSecs[i] = NULL;
         }
-        free(m_pszSec);
+        free(m_pszSecs);
     }
 
 /* FIXME BEGIN DEBUG */

CVSTrac 2.0.1