OSSP CVS Repository

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

Check-in Number: 1924
Date: 2002-Feb-28 16:30:04 (local)
2002-Feb-28 15:30:04 (UTC)
User:ms
Branch:
Comment: Cleanup and structuring.
Tickets:
Inspections:
Files:
ossp-pkg/rc/Makefile.in      1.15 -> 1.16     4 inserted, 4 deleted
ossp-pkg/rc/rc.c      1.13 -> 1.14     5 inserted, 2 deleted
ossp-pkg/rc/rc.h      1.10 -> 1.11     18 inserted, 9 deleted
ossp-pkg/rc/rc.pod      1.27 -> 1.28     4 inserted, 2 deleted
ossp-pkg/rc/rc_config.c      1.2 -> 1.3     19 inserted, 19 deleted
ossp-pkg/rc/rc_option.c      1.3 -> 1.4     4 inserted, 124 deleted
ossp-pkg/rc/rc_private.h      1.3 -> 1.4     4 inserted, 1 deleted

ossp-pkg/rc/Makefile.in 1.15 -> 1.16

--- Makefile.in  2002/02/13 19:19:28     1.15
+++ Makefile.in  2002/02/28 15:30:04     1.16
@@ -59,11 +59,11 @@
 TARGET_PROGS    = rc
 TARGET_MANS     = rc.1 rc-sample.5
 
-SRCS            = rc.c rc_config.c rc_option.c rc_version.c\
-                  rc_pcre.c rc_util.c
+SRCS            = rc.c rc_config.c rc_optimpl.c rc_option.c\
+                  rc_version.c rc_pcre.c rc_util.c
 
-OBJS            = rc.o rc_config.o rc_option.o rc_version.o\
-                  rc_pcre.o rc_util.o
+OBJS            = rc.o rc_config.o rc_optimpl.o rc_option.o\
+                  rc_version.o rc_pcre.o rc_util.o
 
 SUBDIRS         = @SUBDIR_EX@ @SUBDIR_VAR@ @SUBDIR_VAL@ @SUBDIR_STR@ @SUBDIR_POPT@
 


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

--- rc.c 2002/02/13 19:19:28     1.13
+++ rc.c 2002/02/28 15:30:04     1.14
@@ -33,6 +33,9 @@
 #include "rc.h"
 #include "rc_private.h"
 
+/* Initialize our global OSSP ex library identifier */
+const char g_szOSSPrc[] = "OSSP rc";
+
 
 int main(int argc, char *argv[])
 {
@@ -41,8 +44,8 @@
     rc_config_t *pConf = NULL;
 
     ex_try {
-        configInit(&pConf);
-        configFill(pConf, argc, argv);
+        configConstruct(&pConf);
+        configLoad(pConf, argc, argv);
     }
     ex_catch(Except) {
         bCaught = 1;


ossp-pkg/rc/rc.h 1.10 -> 1.11

--- rc.h 2002/02/08 18:36:40     1.10
+++ rc.h 2002/02/28 15:30:04     1.11
@@ -45,9 +45,6 @@
 
 #include "rc_private.h"
 
-/* Unique identifier to use with OSSP ex library */
-extern const char ossprc_id[];
-
 /* RC return codes */
 typedef enum {
     RC_OK,      /* Success                  */
@@ -59,18 +56,30 @@
 } rc_return_t;
 
 /* Option function prototypes */
-rc_return_t parseOpts(int, char **);
-rc_return_t procOpts(char, char *);
+rc_return_t optionProcess(void);
+rc_return_t optionProcess(void);
+
+/* File option function prototypes */
+rc_return_t foptParse(void);
+rc_return_t foptProcess(void);
+
+/* Environment option function prototypes */
+rc_return_t eoptParse(void);
+rc_return_t eoptProcess(void);
+
+/* Command line option function prototypes */
+rc_return_t coptParse(int);
+rc_return_t coptProcess(char, char *);
 
 /* Config function prototypes */
-rc_return_t configInit(rc_config_t **);
-rc_return_t configFill(rc_config_t *, int, char **);
+rc_return_t configConstruct(rc_config_t **);
+rc_return_t configLoad(rc_config_t *, int, char **);
 rc_return_t configDestruct(rc_config_t *);
 
-/* Util function prototypes   */
+/* Utility (nonbounded) function prototypes */
 char *strErr(rc_return_t);
 
-/* Other function prototypes  */
+/* Other function prototypes */
 
 /*rc_result_t rc_Err              (void);
 rc_result_t rc_Warn             (void);


ossp-pkg/rc/rc.pod 1.27 -> 1.28

--- rc.pod       2002/02/04 22:35:20     1.27
+++ rc.pod       2002/02/28 15:30:04     1.28
@@ -49,6 +49,7 @@
 [B<-t>|B<--tmp> I<dir>]
 [B<-v>|B<--verbose>]
 [B<-x>|B<--exec>] 
+
 [B<--RequireUmask umask>]
 [B<--RequireOwner uid|name>]
 [B<--RequireGroup gid|name>]
@@ -61,8 +62,9 @@
 [B<--NameCommon> name]
 [B<--NameDefault> name]
 [B<--NameError> name]
-I<rcfile>
-I<section>
+
+I<<rcfile>>
+I<<section[...]>>
 
 =head1 DESCRIPTION
 


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

--- rc_config.c  2002/02/13 19:19:28     1.2
+++ rc_config.c  2002/02/28 15:30:04     1.3
@@ -38,20 +38,20 @@
 
 
 /***************************************
-* configInit(rc_config_t)              *
-* Initialize a configuration           *
+* configConstruct(rc_config_t)         *
+* Construct a configuration            *
 ***************************************/
-rc_return_t configInit(rc_config_t **ppConfig)
+rc_return_t configConstruct(rc_config_t **ppConfig)
 {
     ex_t Except;
 
-    *ppConfig = malloc(sizeof(rc_config_t));
-    if (!*ppConfig)
-        return(RC_THROW(RC_ERR_MEM));
-
-    ex_try {
-        val_create(&(*ppConfig)->pVal);
-    }
+    *ppConfig = malloc(sizeof(rc_config_t));    /* Allocate the    */
+    if (!*ppConfig)                             /* configuration's */
+        return(RC_THROW(RC_ERR_MEM));           /* identity        */
+
+    ex_try {                                    /* Make a val instance  */
+        val_create(&(*ppConfig)->pVal);         /* to hold individual   */
+    }                                           /* configuration values */
     ex_catch(Except) {
         rethrow;
     }
@@ -60,20 +60,20 @@
 }
 
 /************************************************
-* configFill(rc_config_t, int, char **)         *
-* Fill a configuration                          *
+* configLoad(rc_config_t, int, char **)         *
+* Load a configuration                          *
 ************************************************/
-rc_return_t configFill(rc_config_t *pConfig, int argc, char *argv[])
+rc_return_t configLoad(rc_config_t *pConfig, int argc, char *argv[])
 {
     ex_t Except;
     char *pTestopt = NULL;
     const char *pFuncpath = "/sfw/etc/rc.func";
 
-    ex_try {
+    ex_try {    /* Register and set configuration values */
         val_reg(pConfig->pVal, RC_FNC_NAME, VAL_TYPE_PTR, RC_FNC_DESC, NULL);
         val_set(pConfig->pVal, RC_FNC_NAME, pFuncpath);
         val_get(pConfig->pVal, RC_FNC_NAME, &pTestopt);
-        fprintf(stderr, "%s\n", pTestopt);
+        fprintf(stderr, "Hier!%s!\n", pTestopt);
     }
     ex_catch(Except) {
         rethrow;
@@ -91,14 +91,14 @@
     ex_t Except;
 
     assert(pConfig);
-    free(pConfig);
+    free(pConfig);      /* Deallocate configuration */
+    pConfig = NULL;     /* and clear its reference  */
 
     ex_try {
-        val_destroy(pConfig->pVal);
-    }
+        val_destroy(pConfig->pVal); /* Destroy the val instance and assume */
+    }                               /* that its reference is cleared also  */
     ex_catch(Except) {
         rethrow;
-        return(RC_THROW(RC_ERR_INT));
     }
 
     return(RC_THROW(RC_OK));


ossp-pkg/rc/rc_option.c 1.3 -> 1.4

--- rc_option.c  2002/02/13 19:19:28     1.3
+++ rc_option.c  2002/02/28 15:30:04     1.4
@@ -31,136 +31,16 @@
 
 #include "rc.h"
 #include "rc_private.h"
-#include "rc_option.h"  /* Option operations rely on popt */
-#include "rc_const.h"   /* Strings and other constants    */
 
-/* Third party headers for libraries linked in       */
-#include "popt.h"       /* OSSP popt options library */
 
-/* Unique identifier to use with OSSP ex library     */
-const char ossprc_id[] = "OSSP rc";
-
-
-/* Loops through available options and fills a configuration if encountered */
-rc_return_t procOpts(char cOpt, char *pcCLI)
+/* Loop through available options */
+rc_return_t optionProcess(void)
 {
-    int  nPos = 0;  /* For tracking options */
-
-    switch (cOpt) {
-    case 'h':
-        pcCLI[nPos++] = 'h';
-        break;
-    case 'V':
-        pcCLI[nPos++] = 'V';
-        break;
-    case 'i':
-        pcCLI[nPos++] = 'i';
-        break;
-    case 'q':
-        pcCLI[nPos++] = 'q';
-        break;
-    }
-
     return(RC_THROW(RC_OK));
 }
 
-rc_return_t parseOpts(int argc, char *argv[])
+/* Parse command line options */
+rc_return_t optionParse(void)
 {
-    ex_t Except;
-    int  bCaught = 0;
-    char pcBuf[BUFSIZ+1];
-    int  nBufpos = 0;           /* For tracking options           */
-    char cOpt = 0;              /* For argument parsing           */
-    char *szCLIBuf = NULL;
-    int  nIter = 0;
-    popt_context optCon;        /* Context for parsing options    */
-
-    struct popt_option optionsTable[] = {
-        /* Long options with short keys but no arguments */
-        { RC_USE_NAME, '?', POPT_ARG_NONE,   0, RC_USE_VAL, RC_USE_DESC, NULL },
-        { RC_DBG_NAME, 'd', POPT_ARG_NONE,   0, RC_DBG_VAL, RC_DBG_DESC, NULL },
-        { RC_VER_NAME, 'V', POPT_ARG_NONE,   0, RC_VER_VAL, RC_VER_DESC, NULL },
-        { RC_EVL_NAME, 'e', POPT_ARG_NONE,   0, RC_EVL_VAL, RC_EVL_DESC, NULL },
-        { RC_HLP_NAME, 'h', POPT_ARG_NONE,   0, RC_HLP_VAL, RC_HLP_DESC, NULL },
-        { RC_INF_NAME, 'i', POPT_ARG_NONE,   0, RC_INF_VAL, RC_INF_DESC, NULL },
-        { RC_LBL_NAME, 'l', POPT_ARG_NONE,   0, RC_LBL_VAL, RC_LBL_DESC, NULL },
-        { RC_PRN_NAME, 'p', POPT_ARG_NONE,   0, RC_PRN_VAL, RC_PRN_DESC, NULL },
-        { RC_SIL_NAME, 's', POPT_ARG_NONE,   0, RC_SIL_VAL, RC_SIL_DESC, NULL },
-        { RC_RAW_NAME, 'r', POPT_ARG_NONE,   0, RC_RAW_VAL, RC_RAW_DESC, NULL },
-        { RC_VRB_NAME, 'v', POPT_ARG_NONE,   0, RC_VRB_VAL, RC_VRB_DESC, NULL },
-        { RC_EXC_NAME, 'x', POPT_ARG_NONE,   0, RC_EXC_VAL, RC_EXC_DESC, NULL },
-                                              
-        /* Single argument long options with short keys */
-        {RC_LOC_NAME, 'L', POPT_ARG_STRING, 0, RC_LOC_VAL, RC_LOC_DESC, "regx"},
-        {RC_CNF_NAME, 'c', POPT_ARG_STRING, 0, RC_CNF_VAL, RC_CNF_DESC, "path"},
-        {RC_FNC_NAME, 'f', POPT_ARG_STRING, 0, RC_FNC_VAL, RC_FNC_DESC, "path"},
-        {RC_QRY_NAME, 'q', POPT_ARG_STRING, 0, RC_QRY_VAL, RC_QRY_DESC, "varx"},
-        {RC_TMP_NAME, 't', POPT_ARG_STRING, 0, RC_TMP_VAL, RC_TMP_DESC, "path"},
-
-        /* Single argument long options without short keys */
-        { RC_OWN_NAME, 0, POPT_ARG_STRING, 0, RC_OWN_VAL, RC_OWN_DESC, "user" },
-        { RC_GRP_NAME, 0, POPT_ARG_STRING, 0, RC_GRP_VAL, RC_GRP_DESC, "group"},
-        { RC_MSK_NAME, 0, POPT_ARG_INT,    0, RC_MSK_VAL, RC_MSK_DESC, "umask"},
-        { RC_ASS_NAME, 0, POPT_ARG_STRING, 0, RC_ASS_VAL, RC_ASS_DESC, "regx" },
-        { RC_DEF_NAME, 0, POPT_ARG_STRING, 0, RC_DEF_VAL, RC_DEF_DESC, "regx" },
-        { RC_REF_NAME, 0, POPT_ARG_STRING, 0, RC_REF_VAL, RC_REF_DESC, "regx" },
-        { RC_PRM_NAME, 0, POPT_ARG_STRING, 0, RC_PRM_VAL, RC_PRM_DESC, "regx" },
-        { RC_TRM_NAME, 0, POPT_ARG_STRING, 0, RC_TRM_VAL, RC_TRM_DESC, "regx" },
-        { RC_NCF_NAME, 0, POPT_ARG_STRING, 0, RC_NCF_VAL, RC_NCF_DESC, "name" },
-        { RC_CMN_NAME, 0, POPT_ARG_STRING, 0, RC_CMN_VAL, RC_CMN_DESC, "name" },
-        { RC_DFL_NAME, 0, POPT_ARG_STRING, 0, RC_DFL_VAL, RC_DFL_DESC, "name" },
-        { RC_ERR_NAME, 0, POPT_ARG_STRING, 0, RC_ERR_VAL, RC_ERR_DESC, "name" },
-
-        POPT_AUTOHELP
-        { NULL, 0, 0, NULL, 0 }
-    };
-
-    optCon = popt_getcontext(NULL, argc, (const char **)argv, optionsTable, 0);
-    popt_setotheroptionhelp(optCon, "[options] <rcfile> <sections [args]>");
-
-    if (argc < 2) {
-        popt_printusage(optCon, stderr, 0);
-        return(RC_THROW(RC_ERR_USE));
-    }
-
-    /* Now do options processing */
-    while ((cOpt = popt_getnextopt(optCon)) >= 0)
-    ex_try {
-        procOpts(cOpt, pcBuf);
-    }
-    ex_catch(Except) {
-        if ((rc_return_t)Except.ex_value != RC_ERR_USE)
-            fprintf(stderr, "Nonusage exception: %d\n",\
-                (rc_return_t)Except.ex_value);
-        bCaught = 1;
-        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);
-    }
-    if (!bCaught)
-        fprintf(stderr, "parseOpts: No exceptions caught.\n");
-
-    szCLIBuf = (char *)popt_getarg(optCon);
-    if ((szCLIBuf == NULL)) {
-        fprintf(stderr, "Please specify at least one rcfile and section.\n");
-        popt_printusage(optCon, stderr, 0);
-        return(RC_THROW(RC_ERR_USE));
-    }
-
-    if (cOpt < -1) {
-        /* An error occurred during option processing */
-        fprintf(stderr, "%s: %s\n",
-                popt_badoption(optCon, POPT_BADOPTION_NOALIAS),
-                popt_strerror(cOpt));
-        return(RC_THROW(RC_ERR_INT));
-    }
-
-    /* Print out options, szCLIBuf chosen */
-    fprintf(stderr, "Options chosen: ");
-    for (nIter = 0; nIter < nBufpos ; nIter++)
-        fprintf(stderr, "-%c ", pcBuf[nIter]);
-    fprintf(stderr, "\nRun these commands: %s\n", szCLIBuf);
-
-    popt_freecontext(optCon);
     return(RC_THROW(RC_OK));
 }


ossp-pkg/rc/rc_private.h 1.3 -> 1.4

--- rc_private.h 2002/02/13 19:19:28     1.3
+++ rc_private.h 2002/02/28 15:30:04     1.4
@@ -48,11 +48,14 @@
 #include "dmalloc.h"
 #endif
 
+/* GUID to use with OSSP ex library */
+const char g_szOSSPrc[];
+
 /* Define the ability to throw OSSP ex exceptions       */
 #include "ex.h" /* OSSP ex exception handling library   */
 #define RC_THROW(rv) \
     ((rv) != RC_OK && (ex_catching && !ex_shielding) \
-     ? (ex_throw(ossprc_id, NULL, (rv)), (rv)) : (rv))
+     ? (ex_throw(g_szOSSPrc, NULL, (rv)), (rv)) : (rv))
 
 #include "val.h"
 

CVSTrac 2.0.1