Index: ossp-pkg/rc/00TODO RCS File: /v/ossp/cvs/ossp-pkg/rc/00TODO,v rcsdiff -q -kk '-r1.53' '-r1.54' -u '/v/ossp/cvs/ossp-pkg/rc/00TODO,v' 2>/dev/null --- 00TODO 2003/07/07 15:27:59 1.53 +++ 00TODO 2003/07/11 14:13:16 1.54 @@ -15,6 +15,7 @@ Give example semantics of a common scenario. No error semantics in pseudocode. Remove all character strings from code to rc_const.h + rc_script.c:254 isspace nimmt nicht char sondern unsigned char her Known bugs Not multithreaded (too many potentials for race conditions or overwrite) Index: ossp-pkg/rc/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/rc/Makefile.in,v rcsdiff -q -kk '-r1.36' '-r1.37' -u '/v/ossp/cvs/ossp-pkg/rc/Makefile.in,v' 2>/dev/null --- Makefile.in 2003/07/08 11:41:54 1.36 +++ Makefile.in 2003/07/11 14:13:16 1.37 @@ -60,10 +60,10 @@ TARGET_MANS = rc.1 rc-sample.5 SRCS = rc.c rc_error.c rc_list.c rc_script.c rc_file.c rc_sect.c rc_config.c \ - rc_cliopt.c rc_proc.c rc_version.c rc_pcre.c rc_util.c + rc_filopt.c rc_cliopt.c rc_proc.c rc_version.c rc_pcre.c rc_util.c OBJS = rc.o rc_error.o rc_list.o rc_script.o rc_file.o rc_sect.o rc_config.o \ - rc_cliopt.o rc_proc.o rc_version.o rc_pcre.o rc_util.o + rc_filopt.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@ @@ -126,7 +126,7 @@ $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir) $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man1 $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man5 - $(SHTOOL) install -c -m 755 rc $(DESTDIR)$(bindir)/rc + $(SHTOOL) install -s -c -m 755 rc $(DESTDIR)$(bindir)/rc $(SHTOOL) install -c -m 644 rc.1 $(DESTDIR)$(mandir)/man1/rc.1 $(SHTOOL) install -c -m 644 rc-sample.5 $(DESTDIR)$(mandir)/man5/rc-sample.5 Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.44' '-r1.45' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2003/07/07 13:30:51 1.44 +++ rc.c 2003/07/11 14:13:16 1.45 @@ -38,22 +38,23 @@ int main(int argc, char *argv[]) { ex_t Except; + rc_config_t *pConf = NULL; + rc_proc_t *pProc = NULL; try { /* Configuration block, config is built here */ - configNew(); /* Construct a new config, add default values */ - configLoad(argc, (const char **)argv); /* Load cli, env, and conf */ - configDefaults(); /* Add default values to empty config members */ + pConf = configNew(); /* Construct a new config, add default values */ + configLoad(pConf, argc, (const char **)argv); /* Load cli, env, conf */ + configDefaults(pConf); /* Add default values to empty config members */ } catch(Except) /* Exceptions of the configuration block */ rcError(Except); try { /* Main processing block, script built */ - rc_proc_t *pProc = NULL; pProc = procNew(); /* Construct a new processor */ procPopulate(pProc); /* Populate with run commands */ procRun(pProc); /* [Execute|Evaluate|Print] script */ procDelete(pProc); /* Destroy the processor */ - configDelete(); /* Destroy the configuration */ + configDelete(pConf); /* Destroy the configuration */ } catch(Except) /* Exceptions while script processing */ rcError(Except); Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.59' '-r1.60' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2003/07/07 13:30:51 1.59 +++ rc.h 2003/07/11 14:13:16 1.60 @@ -86,20 +86,20 @@ const char **configGetsecs(void); /* Command line function prototypes */ -rc_return_t clioptNew(void); -rc_return_t clioptPrintusage(void); -rc_return_t clioptProcess(int, const char *); -rc_return_t clioptParseopts(int, const char **); -rc_return_t clioptParseargs(void); -rc_return_t clioptDelete(void); +rc_cliopt_t *clioptNew(void); +rc_return_t clioptPrintusage(rc_cliopt_t *); +rc_return_t clioptProcess(rc_cliopt_t *, int, const char *); +rc_return_t clioptParseopts(rc_cliopt_t *, int, const char **); +rc_return_t clioptParseargs(rc_cliopt_t *); +rc_return_t clioptDelete(rc_cliopt_t *); /* Command line accessor prototypes */ -const char *clioptGetval(rc_opt_t); -const char *clioptGetrcfile(void); -const char **clioptGetsecs(void); -rc_return_t clioptSetval(rc_opt_t, const char *); -rc_return_t clioptSetrcfile(const char *); -rc_return_t clioptSetsecs(const char **); +const char *clioptGetval(rc_cliopt_t *, rc_opt_t); +const char *clioptGetrcfile(rc_cliopt_t *); +const char **clioptGetsecs(rc_cliopt_t *); +rc_return_t clioptSetval(rc_cliopt_t *, rc_opt_t, const char *); +rc_return_t clioptSetrcfile(rc_cliopt_t *, const char *); +rc_return_t clioptSetsecs(rc_cliopt_t *, const char **); /* List function prototypes */ rc_list_t *listNew(void); Index: ossp-pkg/rc/rc_cliopt.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v rcsdiff -q -kk '-r1.20' '-r1.21' -u '/v/ossp/cvs/ossp-pkg/rc/rc_cliopt.c,v' 2>/dev/null --- rc_cliopt.c 2003/07/07 13:30:51 1.20 +++ rc_cliopt.c 2003/07/11 14:13:16 1.21 @@ -31,64 +31,29 @@ #include #include "rc.h" +#include "rc_cliopt.h" #include "rc_const.h" #include "rc_config.h" #include "popt.h" /* OSSP popt options library */ -static char *m_pszOptuples[RC_NUMOPTS]; /* Option name value tuples */ -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[] = { - /* Long options are defined as 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_PAR_NAME, 'a', POPT_ARG_NONE, 0, RC_PAR_VAL, RC_PAR_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"}, - - /* Special stuff */ - POPT_AUTOHELP - {NULL, 0, 0, NULL, 0} -}; - /*************************************** * clioptNew(void) * * Construct a command line option * ***************************************/ -rc_return_t clioptNew(void) +rc_cliopt_t *clioptNew(void) { + rc_cliopt_t *pRetobj = calloc(1, sizeof (rc_cliopt_t)); + if (pRetobj) { + pRetobj->m_pszOptuples = calloc(RC_NUMOPTS, sizeof (char *)); + if (!pRetobj->m_pszOptuples) + RC_THROW(RC_ERR_MEM); + } + else + RC_THROW(RC_ERR_MEM); + + return(pRetobj); + /* assert(s_pBintab == NULL); */ /* Error if constructed already */ /* s_pBintab = malloc(sizeof(*s_pBintab));*/ /* Allocate a cliopt instance */ /* if (!s_pBintab) @@ -98,17 +63,13 @@ /*FIXME optNew((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/ /* s_pBintab->pOptlist->pvData = NULL; s_pBintab->pOptlist->pvNext = NULL;*/ - - memset(m_pszOptuples, 0L, sizeof(m_pszOptuples)); - - return(RC_THROW(RC_OK)); } /*************************************** -* clioptPrintusage() * +* clioptPrintusage(rc_cliopt_t *) * * Print usage to command line stderr * ***************************************/ -rc_return_t clioptPrintusage(void) +rc_return_t clioptPrintusage(rc_cliopt_t *this) { popt_printusage(m_Optcon, stderr, 0); @@ -116,35 +77,35 @@ } /*************************************** -* clioptGetXXX() * -* clioptSetXXX() * +* clioptGetXXX(rc_cliopt_t *) * +* clioptSetXXX(rc_cliopt_t *) * * Command line option accessors * ***************************************/ -const char *clioptGetval(rc_opt_t Optname) +const char *clioptGetval(rc_cliopt_t *this, rc_opt_t Optname) { if (!(Optname < RC_NUMOPTS)) /* Validate option range */ RC_THROW(RC_ERR_USE); - return((const char *)m_pszOptuples[Optname]); + return((const char *)this->m_pszOptuples[Optname]); } -const char *clioptGetrcfile(void) +const char *clioptGetrcfile(rc_cliopt_t *this) { - if (!m_szRcfile) + if (!this->m_szRcfile) RC_THROW(RC_ERR_USE); - return((const char *)m_szRcfile); + return((const char *)this->m_szRcfile); } -const char **clioptGetsecs(void) +const char **clioptGetsecs(rc_cliopt_t *this) { - if (!m_pszSecs) + if (!this->m_pszSecs) RC_THROW(RC_ERR_USE); - return((const char **)m_pszSecs); + return((const char **)this->m_pszSecs); } -rc_return_t clioptSetval(rc_opt_t Optname, const char *kszOptval) +rc_return_t clioptSetval(rc_cliopt_t *this, rc_opt_t Optname, const char *kszOptval) { if (!(Optname < RC_NUMOPTS)) /* Validate option range */ return(RC_THROW(RC_ERR_USE)); @@ -156,28 +117,28 @@ return(RC_THROW(RC_OK)); } -rc_return_t clioptSetrcfile(const char *kszRc) +rc_return_t clioptSetrcfile(rc_cliopt_t *this, const char *kszRc) { - if (m_szRcfile) /* Warn on overwrites */ + if (this->m_szRcfile) /* Warn on overwrites */ RC_THROW(RC_WRN_OWR); if (kszRc) - m_szRcfile = strdup(kszRc); + this->m_szRcfile = strdup(kszRc); else return(RC_THROW(RC_ERR_USE)); /* Incoming string is NULL? */ return(RC_THROW(RC_OK)); } -rc_return_t clioptSetsecs(const char **pkszSecs) +rc_return_t clioptSetsecs(rc_cliopt_t *this, const char **pkszSecs) { ex_t Except; assert (pkszSecs); /* IF NULL, its broken */ - if (m_pszSecs) /* Warn on overwrites */ + if (this->m_pszSecs) /* Warn on overwrites */ RC_THROW(RC_WRN_OWR); try { - m_pszSecs = vectorCopy(pkszSecs); + this->m_pszSecs = vectorCopy(pkszSecs); } catch(Except) rethrow; @@ -185,91 +146,91 @@ return(RC_THROW(RC_OK)); } -/*************************************** -* clioptProcess(int) * -* Switch through available options * -* processing the corresponding option * -* and update option table accordingly * -***************************************/ -rc_return_t clioptProcess(int cliOption, const char *kszArg) +/**************************************************** +* clioptProcess(rc_cliopt_t *, int, const char *) * +* Switch through available options * +* processing the corresponding option * +* and update option table accordingly * +****************************************************/ +rc_return_t clioptProcess(rc_cliopt_t *this, int cliOption, const char *kszArg) { switch (cliOption) { /* Begin concrete (digital) options */ case RC_USE_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Usage */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Usage */ case RC_DBG_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Debug */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Debug */ case RC_VER_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Version */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Version */ case RC_EVL_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Eval */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Eval */ case RC_HLP_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Help */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Help */ case RC_INF_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Info */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Info */ case RC_LBL_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Label */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Label */ case RC_PRN_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Print */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Print */ case RC_PAR_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Print */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Print */ case RC_SIL_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Silent */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Silent */ case RC_RAW_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Raw */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Raw */ case RC_VRB_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Verbose */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Verbose */ case RC_EXC_VAL: - clioptSetval(cliOption, RC_DEF_ON); break; /* Exec */ + clioptSetval(this, cliOption, RC_DEF_ON); break; /* Exec */ /* Begin abstract (nondigital) options */ case RC_LOC_VAL: - clioptSetval(cliOption, kszArg); break; /* Locations */ + clioptSetval(this, cliOption, kszArg); break; /* Locations */ case RC_CNF_VAL: - clioptSetval(cliOption, kszArg); break; /* Conf file */ + clioptSetval(this, cliOption, kszArg); break; /* Conf file */ case RC_FNC_VAL: - clioptSetval(cliOption, kszArg); break; /* Func file */ + clioptSetval(this, cliOption, kszArg); break; /* Func file */ case RC_QRY_VAL: - clioptSetval(cliOption, kszArg); break; /* Format */ + clioptSetval(this, cliOption, kszArg); break; /* Format */ case RC_TMP_VAL: - clioptSetval(cliOption, kszArg); break; /* Temp dir */ + clioptSetval(this, cliOption, kszArg); break; /* Temp dir */ case RC_OWN_VAL: - clioptSetval(cliOption, kszArg); break; /* User name */ + clioptSetval(this, cliOption, kszArg); break; /* User name */ case RC_GRP_VAL: - clioptSetval(cliOption, kszArg); break; /* Group name */ + clioptSetval(this, cliOption, kszArg); break; /* Group name */ case RC_MSK_VAL: - clioptSetval(cliOption, kszArg); break; /* Umask */ + clioptSetval(this, cliOption, kszArg); break; /* Umask */ case RC_ASS_VAL: - clioptSetval(cliOption, kszArg); break; /* Assignregex */ + clioptSetval(this, cliOption, kszArg); break; /* Assignregex */ case RC_DEF_VAL: - clioptSetval(cliOption, kszArg); break; /* Labelregex */ + clioptSetval(this, cliOption, kszArg); break; /* Labelregex */ case RC_REF_VAL: - clioptSetval(cliOption, kszArg); break; /* Refregex */ + clioptSetval(this, cliOption, kszArg); break; /* Refregex */ case RC_PRM_VAL: - clioptSetval(cliOption, kszArg); break; /* Paramregex */ + clioptSetval(this, cliOption, kszArg); break; /* Paramregex */ case RC_TRM_VAL: - clioptSetval(cliOption, kszArg); break; /* Termregex */ + clioptSetval(this, cliOption, kszArg); break; /* Termregex */ case RC_NCF_VAL: - clioptSetval(cliOption, kszArg); break; /* Configname */ + clioptSetval(this, cliOption, kszArg); break; /* Configname */ case RC_CMN_VAL: - clioptSetval(cliOption, kszArg); break; /* Commonname */ + clioptSetval(this, cliOption, kszArg); break; /* Commonname */ case RC_DFL_VAL: - clioptSetval(cliOption, kszArg); break; /* Defaultname */ + clioptSetval(this, cliOption, kszArg); break; /* Defaultname */ case RC_ERR_VAL: - clioptSetval(cliOption, kszArg); break; /* Errorname */ + clioptSetval(this, cliOption, kszArg); break; /* Errorname */ default : break; } return(RC_THROW(RC_OK)); } -/*************************************** -* clioptParseopts(int, const char **) * -* Parse command line options * -***************************************/ -rc_return_t clioptParseopts(int nArgs, const char *szVector[]) +/******************************************************** +* clioptParseopts(rc_cliopt_t *, int, const char **) * +* Parse command line options * +********************************************************/ +rc_return_t clioptParseopts(rc_cliopt_t *this, int nArgs, const char *szVector[]) { ex_t Except; char cliOpt = 0; /* For argument parsing */ @@ -286,7 +247,7 @@ /* Now do options processing */ while ((cliOpt = popt_getnextopt(m_Optcon)) >= 0) {/* Loop, each time */ try { /* eating a new option */ - clioptProcess(cliOpt, popt_getoptarg(m_Optcon)); + clioptProcess(this, cliOpt, popt_getoptarg(m_Optcon)); } catch(Except) /* Error condition probably deserves attention */ rethrow; @@ -303,17 +264,17 @@ } /****************************************** -* clioptParseargs(void) * +* clioptParseargs(rc_cliopt_t *) * * Parse command line rc file and sections * ******************************************/ -rc_return_t clioptParseargs(void) +rc_return_t clioptParseargs(rc_cliopt_t *this) { ex_t Except; /* Use popt as a transport to read the user specified rcfile and sections */ try { - clioptSetrcfile(popt_getarg(m_Optcon)); - clioptSetsecs(popt_getargs(m_Optcon)); + clioptSetrcfile(this, popt_getarg(m_Optcon)); + clioptSetsecs(this, popt_getargs(m_Optcon)); } catch(Except) rethrow; /* Our generic response */ @@ -322,10 +283,10 @@ } /*************************************** -* clioptDelete(void) * +* clioptDelete(rc_cliopt_t *) * * Destruct a command line option * ***************************************/ -rc_return_t clioptDelete(void) +rc_return_t clioptDelete(rc_cliopt_t *this) { int i = 0; /* ex_t Except; @@ -343,24 +304,25 @@ */ popt_freecontext(m_Optcon); /* Free the popt context */ - for (i = 0; i < RC_NUMOPTS; i++) { /* Free the tuples themselves */ - if (m_pszOptuples[i]) { - free(m_pszOptuples[i]); - m_pszOptuples[i] = NULL; + if (m_pszOptuples) { + for (i = 0; i < RC_NUMOPTS; i++) { /* Free the tuples themselves */ + if (m_pszOptuples[i]) { + free(m_pszOptuples[i]); + m_pszOptuples[i] = NULL; + } } + free(this->m_pszOptuples); + this->m_pszOptuples = NULL; + } + if (this->m_szRcfile) { /* Free the rc file arg */ + free(this->m_szRcfile); + this->m_szRcfile = NULL; + } + if (this->m_pszSecs) { /* Free the section name arg */ + vectorDel(this->m_pszSecs); + this->m_pszSecs = NULL; } - if (m_szRcfile) /* Free the rc file arg */ - free(m_szRcfile); - - if (m_pszSecs) /* Free the section name arg */ - vectorDel(m_pszSecs); - -/* FIXME BEGIN DEBUG */ -for (i = 0; i < RC_NUMOPTS; i++) - if (m_pszOptuples[i]) - TRACE("Problem! Destructor failed!\n"); -/* FIXME END DEBUG */ - + free(this); return(RC_THROW(RC_OK)); } Index: ossp-pkg/rc/rc_config.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_config.c,v rcsdiff -q -kk '-r1.41' '-r1.42' -u '/v/ossp/cvs/ossp-pkg/rc/rc_config.c,v' 2>/dev/null --- rc_config.c 2003/07/11 09:38:29 1.41 +++ rc_config.c 2003/07/11 14:13:16 1.42 @@ -40,31 +40,36 @@ #include "rc_version.c" #undef _RC_VERSION_C_AS_HEADER_ -static int m_nLocks = 0; /* Server locks, not thread-safe FIXME */ +static int m_nLocks = 0; /* Server locks, not thread-safe FIXME */ /*************************************** * configNew(void) * * Construct a configuration * ***************************************/ -rc_return_t configNew(void) +rc_config_t configNew(void) { ex_t Except; + rc_config_t *pRetobj = NULL; - if (m_nLocks == 0) { /* If we don't have one yet */ - try { /* then construct a new one */ - clioptNew(); /* Member cliopt instance */ + if (m_nLocks == 0) { /* If we don't have one yet */ + pRetobj = malloc(sizeof (rc_config_t)); /* then construct a new one */ + if (pRetobj) { + try { + pRetobj->m_pCliopts = clioptNew(); /* Member cliopt instance */ + } + catch(Except) + rethrow; } - catch(Except) - rethrow; + else + RC_THROW(RC_ERR_MEM); } m_nLocks++; /* FIXME not threadsafe */ + return(pRetobj); /* Warn: Experimental design pattern code abstracts operations from config */ /* configVisit(pfnSetdefaults); configVisit(pfnGetoptinfo);*/ - - return(RC_THROW(RC_OK)); } /* FIXME: Make into configVisit, using callbacks to get and set option info */ @@ -375,16 +380,16 @@ } /*************************************** -* configDelete(void) * +* configDelete(rc_config_t *) * * Destruct a configuration * ***************************************/ -rc_return_t configDelete(void) +rc_return_t configDelete(rc_config_t *this) { ex_t Except; if (--m_nLocks == 0) { /* If m_nLocks is 0, deallocate */ try { /* FIXME, not thread-safe */ - clioptDelete(); + clioptDelete(this->m_pCliopts); } catch(Except) rethrow; Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.38' '-r1.39' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- rc_private.h 2003/07/11 09:38:29 1.38 +++ rc_private.h 2003/07/11 14:13:16 1.39 @@ -70,6 +70,18 @@ typedef int rc_opt_t; /* For use with RC_XXX_VAL definitions */ +/* Cliopt class */ +typedef struct { + char **m_pszOptuples; + char *m_szRcfile; + char **m_pszSecs; +} rc_cliopt_t; + +/* Configuration class */ +typedef struct { + rc_cliopt_t *pCliopts; +} rc_config_t; + /* Script type */ typedef char * rc_script_t;