Index: ossp-pkg/rc/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/rc/Makefile.in,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/rc/Makefile.in,v' 2>/dev/null --- Makefile.in 2002/04/25 16:17:57 1.26 +++ Makefile.in 2002/05/22 13:29:40 1.27 @@ -59,11 +59,11 @@ TARGET_PROGS = rc TARGET_MANS = rc.1 rc-sample.5 -SRCS = rc.c rc_config.c rc_cliopt.c rc_proc.c \ - rc_version.c rc_pcre.c rc_util.c +SRCS = rc.c rc_anal.c rc_config.c rc_cliopt.c \ + rc_proc.c rc_version.c rc_pcre.c rc_util.c -OBJS = rc.o rc_config.o rc_cliopt.o rc_proc.o \ - rc_version.o rc_pcre.o rc_util.o +OBJS = rc.o rc_anal.o rc_config.o rc_cliopt.o \ + rc_proc.o rc_version.o rc_pcre.o rc_util.o SUBDIRS = @SUBDIR_EX@ @SUBDIR_POPT@ #SUBDIRS = @SUBDIR_EX@ @SUBDIR_VAR@ @SUBDIR_VAL@ @SUBDIR_STR@ @SUBDIR_POPT@ Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/05/22 09:47:27 1.26 +++ rc.c 2002/05/22 13:29:40 1.27 @@ -45,18 +45,18 @@ ex_try { /* Configuration and abstract analysis block */ configNew(); /* Construct a new configuration */ - configLoad(argc, argv); /* Read configuration from cli, env, and conf */ + configLoad(argc, (const char **)argv); /* Load cli, env, and conf */ configDebug(); /* FIXME Remove FIXME */ configVerify(); /* Test for usage, help, and version options */ - pAnal = analNew(); /* Construct a new analyzer */ - analParse(pAnal); /* Preprocess the analyzed configuration */ +/* pAnal = analNew();*/ /* Construct a new analyzer */ +/* analParse(pAnal);*/ /* Preprocess the analyzed configuration */ } ex_catch(Except) { /* Exceptions thrown during configuration and analysis */ if ((rc_return_t)Except.ex_value == RC_ERR_USE) { clioptPrintusage(); } - else + else if (FAILED((rc_return_t)Except.ex_value)) 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); @@ -64,33 +64,37 @@ } ex_try { /* Main script building and processing block */ - rc_script_t *pScript = NULL; +/* rc_script_t *pScript = NULL;*/ rc_proc_t *pProc = NULL; - pScript = scriptNew(pAnal); /* Construct a new script */ - scriptBuild(pScript); +/* pScript = scriptNew(pAnal);*/ /* Construct a new script */ +/* scriptBuild(pScript);*/ - pProc = procNew(pScript); /* Construct a new processor */ - procRun(pProc); /* [Execute|Evaluate|Print] script */ - procDelete(pProc); /* Destroy the processor */ - scriptDelete(pScript); /* Destroy the script */ - } - ex_catch(Except) { /* Exceptions thrown during script processing */ - 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); - exit(1); /* Return failure */ +/* pProc = procNew(pScript);*/ /* Construct a new processor */ +/* procRun(pProc);*/ /* [Execute|Evaluate|Print] script */ +/* procDelete(pProc);*/ /* Destroy the processor */ +/* scriptDelete(pScript);*/ /* Destroy the script */ + } + ex_catch(Except) { /* Error exceptions thrown during script processing */ + if (FAILED((rc_return_t)Except.ex_value)) { + 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); + exit(1); /* Return failure */ + } } ex_try { /* Start shutdown of main program */ - analDelete(pAnal); /* Destroy the analyzer */ +/* analDelete(pAnal);*/ /* Destroy the analyzer */ configDelete(); /* Destroy the configuration */ } - ex_catch(Except) { /* Exceptions thrown during program shutdown */ - 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); - exit(1); /* Return failure */ + ex_catch(Except) { /* Error exceptions thrown during program shutdown */ + if (FAILED((rc_return_t)Except.ex_value)) { + 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); + exit(1); /* Return failure */ + } } exit(0); /* Return success */ Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/05/13 16:57:00 1.25 +++ rc.h 2002/05/22 13:29:40 1.26 @@ -43,65 +43,55 @@ #define TRUE (!FALSE) #endif +/* Return and error code macro helpers */ +#define WARNING(scode) (scode >= RC_WRN_0) +#define FAILED(scode) ((scode >= RC_ERR_0) && !WARNING(scode)) +#define SUCCEEDED(scode) ((scode == RC_OK) || WARNING(scode)) + #include "rc_private.h" /* Rc return codes */ typedef enum { - RC_OK, /* Success */ - RC_ERR_USE, /* Usage error */ - RC_ERR_MEM, /* Memory error */ - RC_ERR_SYS, /* System error (see errno) */ - RC_ERR_IO, /* Input/output error */ - RC_ERR_INT /* Internal error */ + RC_OK = 1, /* Success */ + RC_ERR_0 = 2, /* Error base */ + RC_ERR_USE = 3, /* Usage error */ + RC_ERR_MEM = 4, /* Memory error */ + RC_ERR_SYS = 5, /* System error (see errno) */ + RC_ERR_IO = 6, /* Input/output error */ + RC_ERR_INT = 7, /* Internal error */ + RC_WRN_0 = 8, /* Warning base */ + RC_WRN_OWR = 9 /* Overwrite warning */ } rc_return_t; -/* Processor class */ -typedef struct { - int nTmpfile; /* Temp file descriptor */ -} rc_proc_t; - -/* Rc script type */ -typedef char *rc_script_t; - -/* Option function prototypes */ -/*rc_return_t optionProcess(void); -rc_return_t optionProcess(void);*/ - /* Config function prototypes */ rc_return_t configNew(void); -rc_return_t configLoad(int, char **); +rc_return_t configLoad(int, const char **); rc_return_t configVerify(void); rc_return_t configDelete(void); const char *configSummarize(void); -void configDebug(void); /* FIXME Remove */ +void configDebug(void); /* FIXME Remove */ /* Config accessor prototypes */ const char *configGetval(rc_opt_t); const char *configGetname(rc_opt_t); const char *configGetrcfile(void); -const char *configGetsec(int); +const char **configGetsecs(void); /* Command line function prototypes */ rc_return_t clioptNew(void); rc_return_t clioptPrintusage(void); -/*FIXME rc_return_t clioptRemnode(rc_bintup_t **); - rc_return_t clioptRemallimp(rc_bintup_t **); - rc_return_t clioptRemall(void); - rc_return_t clioptAppnode(const char *, const char *);*/ rc_return_t clioptProcess(int, const char *); -rc_return_t clioptParseopt(int, char **); -rc_return_t clioptParserc(void); -rc_return_t clioptParsesec(void); +rc_return_t clioptParseopts(int, const char **); +rc_return_t clioptParseargs(void); rc_return_t clioptDelete(void); /* Command line accessor prototypes */ const char *clioptGetval(rc_opt_t); const char *clioptGetrcfile(void); -const char **clioptGetsec(void); -int clioptGetseclen(void); +const char **clioptGetsecs(void); rc_return_t clioptSetval(rc_opt_t, const char *); rc_return_t clioptSetrcfile(const char *); -rc_return_t clioptSetsec(const char **); +rc_return_t clioptSetsecs(const char **); /* Processor function prototypes */ rc_proc_t *procNew(void); @@ -113,16 +103,6 @@ rc_return_t procParse(rc_proc_t *); rc_return_t procRun(rc_proc_t *); - /* Option function prototypes */ - /*FIXME rc_return_t optNew(rc_opt_t **); - rc_return_t optDelete(rc_opt_t **);*/ - - /* Option accessor prototypes */ - /*FIXME rc_return_t optGetname(rc_opt_t *, char **); - rc_return_t optGetval(rc_opt_t *, char **); - rc_return_t optSetname(rc_opt_t *, const char *); - rc_return_t optSetval(rc_opt_t *, const char *);*/ - /* Utility (nonbounded) function prototypes */ char *strErr(rc_return_t); Index: ossp-pkg/rc/rc_cliopt.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v' 2>/dev/null --- 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, " "); - 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 */ Index: ossp-pkg/rc/rc_config.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.c,v rcsdiff -q -kk '-r1.15' '-r1.16' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.c,v' 2>/dev/null --- rc_config.c 2002/04/25 09:51:29 1.15 +++ rc_config.c 2002/05/22 13:29:40 1.16 @@ -48,22 +48,14 @@ void configDebug(void) { int i = 0; - ex_t Except; - char *szTemp = NULL; + char **szTemp = NULL; fprintf(stderr, "Run command file: %s\n", configGetrcfile()); - szTemp = (char *)configGetsec(i); + szTemp = (char **)configGetsecs(); fprintf(stderr, "Sections:"); - while (szTemp) { - fprintf(stderr, " %s", szTemp); - ex_try { - szTemp = (char *)configGetsec(++i); - } - ex_catch(Except) { - break; - } - } + while (szTemp[i]) + fprintf(stderr, " %s", szTemp[i++]); fprintf(stderr, "\n%s", configSummarize()); } @@ -151,7 +143,7 @@ /* (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()); + return(clioptGetrcfile()); } ex_catch(Except) { rethrow; @@ -160,22 +152,17 @@ else { RC_THROW(RC_ERR_USE); } + return(NULL); /* Not reached */ } -const char *configGetsec(int nIndex) +const char **configGetsecs(void) { 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); - } + if (m_nLocks) { /* Make sure config exists */ + ex_try { /* FIXME Might need to check */ + return(clioptGetsecs()); /* FIXME env, conf, configs */ } ex_catch(Except) { rethrow; @@ -184,6 +171,7 @@ else { RC_THROW(RC_ERR_USE); } + return(NULL); /* Not reached */ } @@ -234,17 +222,16 @@ } /************************************************ -* configLoad(int, char **) * +* configLoad(int, const char **) * * Load a configuration * ************************************************/ -rc_return_t configLoad(int argc, char *argv[]) +rc_return_t configLoad(int nTotal, const char *szArgvec[]) { ex_t Except; - ex_try { /* Parse option groups in order of priority */ - clioptParseopt(argc, argv); /* Command line options */ - clioptParserc(); /* Command line rc file */ - clioptParsesec(); /* Command line sections */ + ex_try { /* Parse option groups in order of priority */ + clioptParseopts(nTotal, szArgvec); /* Command line options */ + clioptParseargs(); /* Command line args */ /* envoptParse(m_nLocks->pOpt);*/ /* Environment options */ /* cnfoptParse(m_nLocks->pOpt);*/ /* Configfile options */ } Index: ossp-pkg/rc/rc_config.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.h,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.h,v' 2>/dev/null --- rc_config.h 2002/04/22 12:49:26 1.4 +++ rc_config.h 2002/05/22 13:29:40 1.5 @@ -47,7 +47,7 @@ #define RC_LOC_VAL 13 /* Locations */ #define RC_CNF_VAL 14 /* Conf file */ #define RC_FNC_VAL 15 /* Func file */ -#define RC_QRY_VAL 16 /* Format */ +#define RC_QRY_VAL 16 /* Query */ #define RC_TMP_VAL 17 /* Temp dir */ #define RC_OWN_VAL 18 /* User name */ #define RC_GRP_VAL 19 /* Group name */ Index: ossp-pkg/rc/rc_const.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_const.h,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/rc/rc_const.h,v' 2>/dev/null --- rc_const.h 2002/04/24 16:47:07 1.5 +++ rc_const.h 2002/05/22 13:29:40 1.6 @@ -108,6 +108,8 @@ #define RC_ERRSTR_INT "Internal" #define RC_ERRSTR_UNK "Unrecognized" +#define RC_CONF_WILD "all" + /* FIXME Tie to shtool generation */ #define RC_VERSION "77.77" Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- rc_private.h 2002/04/12 19:15:12 1.11 +++ rc_private.h 2002/05/22 13:29:40 1.12 @@ -64,4 +64,24 @@ typedef int rc_opt_t; /* For use with RC_XXX_VAL definitions */ +/* Analyser type */ +typedef struct { + char *m_szRcs; /* Rc file names */ + char *m_szTmp; /* Temp file name */ + char *m_szFuncs; /* Function file names */ + char *m_szLocs; /* Location path names */ + char *m_szSecs; /* Section names */ +} rc_anal_t; + +/* Script type */ +typedef struct { + rc_anal_t *m_pAnal; + char *m_szText; +} rc_script_t; + +/* Processor class */ +typedef struct { + rc_script_t *m_pScript; +} rc_proc_t; + #endif /* __OSSPRC_PRIVATE_H__ */ Index: ossp-pkg/rc/rc_test.sh RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v' 2>/dev/null --- rc_test.sh 2002/04/22 12:49:26 1.9 +++ rc_test.sh 2002/05/22 13:29:40 1.10 @@ -38,8 +38,8 @@ # Test some long options, should fail for false combination usage echo; echo "./rc --verbose --silent uucp stop sleep=6 start" ./rc --verbose --silent uucp stop sleep=6 start -echo; echo "./rc --query --silent zebra bing bang" -./rc --query --silent zebra bing bang +echo; echo "./rc --query myvar --silent zebra bing bang" +./rc --query myvar --silent zebra bing bang echo; echo "./rc --conf /sfw/rc.conf --locate /etc/rc3.d:/sfw/etc/rc.d --query what to enter here" ./rc --conf /sfw/rc.conf --locate /etc/rc3.d:/sfw/etc/rc.d --query what to enter here