head 1.21;
access;
symbols
OSSP_RC_0_7_3:1.20
OSSP_RC_0_7_2:1.20
OSSP_RC_0_7_1:1.20
OSSP_RC_ALPHA_06:1.16
OSSP_RC_EXBROKEN:1.14;
locks; strict;
comment @ * @;
1.21
date 2003.07.11.14.13.16; author ms; state Exp;
branches;
next 1.20;
1.20
date 2003.07.07.13.30.51; author ms; state Exp;
branches;
next 1.19;
1.19
date 2003.07.07.12.55.42; author ms; state Exp;
branches;
next 1.18;
1.18
date 2003.06.13.18.33.07; author ms; state Exp;
branches;
next 1.17;
1.17
date 2003.06.03.15.27.13; author ms; state Exp;
branches;
next 1.16;
1.16
date 2003.05.27.13.14.08; author ms; state Exp;
branches;
next 1.15;
1.15
date 2003.05.26.16.03.57; author ms; state Exp;
branches;
next 1.14;
1.14
date 2002.08.01.15.22.58; author ms; state Exp;
branches;
next 1.13;
1.13
date 2002.07.05.12.54.56; author ms; state Exp;
branches;
next 1.12;
1.12
date 2002.06.26.14.42.53; author ms; state Exp;
branches;
next 1.11;
1.11
date 2002.06.26.14.11.16; author ms; state Exp;
branches;
next 1.10;
1.10
date 2002.05.23.18.03.20; author ms; state Exp;
branches;
next 1.9;
1.9
date 2002.05.22.13.29.40; author ms; state Exp;
branches;
next 1.8;
1.8
date 2002.04.25.16.17.57; author ms; state Exp;
branches;
next 1.7;
1.7
date 2002.04.24.16.47.07; author ms; state Exp;
branches;
next 1.6;
1.6
date 2002.04.23.12.30.29; author ms; state Exp;
branches;
next 1.5;
1.5
date 2002.04.22.15.22.39; author ms; state Exp;
branches;
next 1.4;
1.4
date 2002.04.22.12.16.39; author ms; state Exp;
branches;
next 1.3;
1.3
date 2002.04.12.19.15.12; author ms; state Exp;
branches;
next 1.2;
1.2
date 2002.04.11.16.52.45; author ms; state Exp;
branches;
next 1.1;
1.1
date 2002.04.09.17.01.28; author ms; state Exp;
branches;
next ;
desc
@@
1.21
log
@Flush of configuration changes before upcoming configuration structure is
completed.
@
text
@/* OSSP rc - Run-Command Processor
** Copyright (c) 2002-2003 Ralf S. Engelschall
** Copyright (c) 2002-2003 Cable & Wireless Deutschland GmbH
** Copyright (c) 2002-2003 The OSSP Project
**
** This file is part of OSSP rc, a portable run-command processor
** which can be found at http://www.ossp.org/pkg/lib/rc/
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
** the above copyright notice and this permission notice appear in all
** copies.
**
** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** rc_cliopt.c: Run-Command Processor ISO C source file
*/
#include
#include
#include "rc.h"
#include "rc_cliopt.h"
#include "rc_const.h"
#include "rc_config.h"
#include "popt.h" /* OSSP popt options library */
/***************************************
* clioptNew(void) *
* Construct a command line option *
***************************************/
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)
return(RC_THROW(RC_ERR_MEM));
s_pBintab->pOptlist = malloc(sizeof(*s_pBintab->pOptlist));*/
/*FIXME optNew((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/
/* s_pBintab->pOptlist->pvData = NULL;
s_pBintab->pOptlist->pvNext = NULL;*/
}
/***************************************
* clioptPrintusage(rc_cliopt_t *) *
* Print usage to command line stderr *
***************************************/
rc_return_t clioptPrintusage(rc_cliopt_t *this)
{
popt_printusage(m_Optcon, stderr, 0);
return(RC_THROW(RC_OK));
}
/***************************************
* clioptGetXXX(rc_cliopt_t *) *
* clioptSetXXX(rc_cliopt_t *) *
* Command line option accessors *
***************************************/
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 *)this->m_pszOptuples[Optname]);
}
const char *clioptGetrcfile(rc_cliopt_t *this)
{
if (!this->m_szRcfile)
RC_THROW(RC_ERR_USE);
return((const char *)this->m_szRcfile);
}
const char **clioptGetsecs(rc_cliopt_t *this)
{
if (!this->m_pszSecs)
RC_THROW(RC_ERR_USE);
return((const char **)this->m_pszSecs);
}
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));
if (!(kszOptval)) /* Validate string value */
return(RC_THROW(RC_ERR_USE));
if (!(m_pszOptuples[Optname] = strdup(kszOptval)))
return(RC_THROW(RC_ERR_MEM));
return(RC_THROW(RC_OK));
}
rc_return_t clioptSetrcfile(rc_cliopt_t *this, const char *kszRc)
{
if (this->m_szRcfile) /* Warn on overwrites */
RC_THROW(RC_WRN_OWR);
if (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(rc_cliopt_t *this, const char **pkszSecs)
{
ex_t Except;
assert (pkszSecs); /* IF NULL, its broken */
if (this->m_pszSecs) /* Warn on overwrites */
RC_THROW(RC_WRN_OWR);
try {
this->m_pszSecs = vectorCopy(pkszSecs);
}
catch(Except)
rethrow;
return(RC_THROW(RC_OK));
}
/****************************************************
* 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(this, cliOption, RC_DEF_ON); break; /* Usage */
case RC_DBG_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Debug */
case RC_VER_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Version */
case RC_EVL_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Eval */
case RC_HLP_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Help */
case RC_INF_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Info */
case RC_LBL_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Label */
case RC_PRN_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Print */
case RC_PAR_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Print */
case RC_SIL_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Silent */
case RC_RAW_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Raw */
case RC_VRB_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Verbose */
case RC_EXC_VAL:
clioptSetval(this, cliOption, RC_DEF_ON); break; /* Exec */
/* Begin abstract (nondigital) options */
case RC_LOC_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Locations */
case RC_CNF_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Conf file */
case RC_FNC_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Func file */
case RC_QRY_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Format */
case RC_TMP_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Temp dir */
case RC_OWN_VAL:
clioptSetval(this, cliOption, kszArg); break; /* User name */
case RC_GRP_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Group name */
case RC_MSK_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Umask */
case RC_ASS_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Assignregex */
case RC_DEF_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Labelregex */
case RC_REF_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Refregex */
case RC_PRM_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Paramregex */
case RC_TRM_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Termregex */
case RC_NCF_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Configname */
case RC_CMN_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Commonname */
case RC_DFL_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Defaultname */
case RC_ERR_VAL:
clioptSetval(this, cliOption, kszArg); break; /* Errorname */
default : break;
}
return(RC_THROW(RC_OK));
}
/********************************************************
* 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 */
m_Optcon = popt_getcontext(NULL, nArgs, szVector, m_pOptable, 0);
popt_setotheroptionhelp(m_Optcon, " ");
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));
}
/* Now do options processing */
while ((cliOpt = popt_getnextopt(m_Optcon)) >= 0) {/* Loop, each time */
try { /* eating a new option */
clioptProcess(this, cliOpt, popt_getoptarg(m_Optcon));
}
catch(Except) /* Error condition probably deserves attention */
rethrow;
}
if (cliOpt < -1) { /* The option given was not found in the index */
fprintf(stderr, "%s: %s\n",
popt_badoption(m_Optcon, POPT_BADOPTION_NOALIAS),
popt_strerror(cliOpt));
return(RC_THROW(RC_ERR_USE));
}
return(RC_THROW(RC_OK));
}
/******************************************
* clioptParseargs(rc_cliopt_t *) *
* Parse command line rc file and sections *
******************************************/
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(this, popt_getarg(m_Optcon));
clioptSetsecs(this, popt_getargs(m_Optcon));
}
catch(Except)
rethrow; /* Our generic response */
return(RC_THROW(RC_OK));
}
/***************************************
* clioptDelete(rc_cliopt_t *) *
* Destruct a command line option *
***************************************/
rc_return_t clioptDelete(rc_cliopt_t *this)
{
int i = 0;
/* ex_t Except;
assert(s_pBintab);*/ /* Error if not constructed */
/* try {
clioptRemall();*/ /* Removes ALL list nodes */
/*FIXME optDelete((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/
/* free(s_pBintab->pOptlist);*/ /* Deallocate option list */
/* free(s_pBintab);*/ /* Deallocate cliopt and */
/* s_pBintab = NULL;*/ /* clear its reference */
/* }
catch(Except)
rethrow;
*/
popt_freecontext(m_Optcon); /* Free the popt context */
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;
}
free(this);
return(RC_THROW(RC_OK));
}
@
1.20
log
@More header corrections and improvements.
@
text
@d34 1
a38 47
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}
};
d44 1
a44 1
rc_return_t clioptNew(void)
d46 11
a65 4
memset(m_pszOptuples, 0L, sizeof(m_pszOptuples));
return(RC_THROW(RC_OK));
d69 1
a69 1
* clioptPrintusage() *
d72 1
a72 1
rc_return_t clioptPrintusage(void)
d80 2
a81 2
* clioptGetXXX() *
* clioptSetXXX() *
d84 1
a84 1
const char *clioptGetval(rc_opt_t Optname)
d89 1
a89 1
return((const char *)m_pszOptuples[Optname]);
d92 1
a92 1
const char *clioptGetrcfile(void)
d94 1
a94 1
if (!m_szRcfile)
d97 1
a97 1
return((const char *)m_szRcfile);
d100 1
a100 1
const char **clioptGetsecs(void)
d102 1
a102 1
if (!m_pszSecs)
d105 1
a105 1
return((const char **)m_pszSecs);
d108 1
a108 1
rc_return_t clioptSetval(rc_opt_t Optname, const char *kszOptval)
d120 1
a120 1
rc_return_t clioptSetrcfile(const char *kszRc)
d122 1
a122 1
if (m_szRcfile) /* Warn on overwrites */
d125 1
a125 1
m_szRcfile = strdup(kszRc);
d132 1
a132 1
rc_return_t clioptSetsecs(const char **pkszSecs)
d137 1
a137 1
if (m_pszSecs) /* Warn on overwrites */
d141 1
a141 1
m_pszSecs = vectorCopy(pkszSecs);
d149 7
a155 7
/***************************************
* clioptProcess(int) *
* Switch through available options *
* processing the corresponding option *
* and update option table accordingly *
***************************************/
rc_return_t clioptProcess(int cliOption, const char *kszArg)
d160 1
a160 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Usage */
d162 1
a162 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Debug */
d164 1
a164 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Version */
d166 1
a166 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Eval */
d168 1
a168 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Help */
d170 1
a170 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Info */
d172 1
a172 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Label */
d174 1
a174 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Print */
d176 1
a176 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Print */
d178 1
a178 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Silent */
d180 1
a180 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Raw */
d182 1
a182 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Verbose */
d184 1
a184 1
clioptSetval(cliOption, RC_DEF_ON); break; /* Exec */
d188 1
a188 1
clioptSetval(cliOption, kszArg); break; /* Locations */
d190 1
a190 1
clioptSetval(cliOption, kszArg); break; /* Conf file */
d192 1
a192 1
clioptSetval(cliOption, kszArg); break; /* Func file */
d194 1
a194 1
clioptSetval(cliOption, kszArg); break; /* Format */
d196 1
a196 1
clioptSetval(cliOption, kszArg); break; /* Temp dir */
d198 1
a198 1
clioptSetval(cliOption, kszArg); break; /* User name */
d200 1
a200 1
clioptSetval(cliOption, kszArg); break; /* Group name */
d202 1
a202 1
clioptSetval(cliOption, kszArg); break; /* Umask */
d205 1
a205 1
clioptSetval(cliOption, kszArg); break; /* Assignregex */
d207 1
a207 1
clioptSetval(cliOption, kszArg); break; /* Labelregex */
d209 1
a209 1
clioptSetval(cliOption, kszArg); break; /* Refregex */
d211 1
a211 1
clioptSetval(cliOption, kszArg); break; /* Paramregex */
d213 1
a213 1
clioptSetval(cliOption, kszArg); break; /* Termregex */
d216 1
a216 1
clioptSetval(cliOption, kszArg); break; /* Configname */
d218 1
a218 1
clioptSetval(cliOption, kszArg); break; /* Commonname */
d220 1
a220 1
clioptSetval(cliOption, kszArg); break; /* Defaultname */
d222 1
a222 1
clioptSetval(cliOption, kszArg); break; /* Errorname */
d229 5
a233 5
/***************************************
* clioptParseopts(int, const char **) *
* Parse command line options *
***************************************/
rc_return_t clioptParseopts(int nArgs, const char *szVector[])
d250 1
a250 1
clioptProcess(cliOpt, popt_getoptarg(m_Optcon));
d267 1
a267 1
* clioptParseargs(void) *
d270 1
a270 1
rc_return_t clioptParseargs(void)
d276 2
a277 2
clioptSetrcfile(popt_getarg(m_Optcon));
clioptSetsecs(popt_getargs(m_Optcon));
d286 1
a286 1
* clioptDelete(void) *
d289 1
a289 1
rc_return_t clioptDelete(void)
d307 6
a312 4
for (i = 0; i < RC_NUMOPTS; i++) { /* Free the tuples themselves */
if (m_pszOptuples[i]) {
free(m_pszOptuples[i]);
m_pszOptuples[i] = NULL;
d314 10
d326 1
a326 12
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 */
@
1.19
log
@Correct and update copyrights and source headers.
@
text
@d1 1
a1 1
/* OSSP rc - Run-command processor
d6 1
a6 1
** This file is part of OSSP rc, a portable Run-command processor
d27 1
a27 1
** rc_cliopt.c: Run-command processor ISO C source file
@
1.18
log
@Sweeping cleanups. Reduced the analyzer to almost nothing. Removed unused
method prototypes. Added 'parse' mode option that doesn't work yet. Removed
procReadtmp. Change the way we build path names from the locations directory.
@
text
@d2 3
a4 3
** Copyright (c) 2002 Ralf S. Engelschall
** Copyright (c) 2002 Cable & Wireless Deutschland GmbH
** Copyright (c) 2002 The OSSP Project
@
1.17
log
@Fixed wrong debug option token name
@
text
@d53 1
d213 2
@
1.16
log
@Clean up non BSD compiler warnings.
@
text
@d46 1
a46 1
{RC_DBG_NAME, 'd', POPT_ARG_NONE, 0, RC_DBG_VAL, RC_DBG_DESC, NULL},
@
1.15
log
@Preliminary exception handling repairs.
@
text
@d101 1
a101 1
memset(m_pszOptuples, NULL, sizeof(m_pszOptuples));
@
1.14
log
@Swap magic numbers for more friendly definitions.
@
text
@d181 1
a181 1
catch(Except) {
a182 1
}
d288 1
a288 1
catch(Except) { /* Error condition probably deserves attention */
a289 1
}
d315 1
a315 1
catch(Except) {
a316 1
}
d338 1
a338 1
catch(Except) {
d340 1
a340 1
}*/
@
1.13
log
@Resolve some null pointer and ex_ bugs, and clean up --print output.
@
text
@d199 1
a199 1
clioptSetval(cliOption, "1"); break; /* Usage */
d201 1
a201 1
clioptSetval(cliOption, "1"); break; /* Debug */
d203 1
a203 1
clioptSetval(cliOption, "1"); break; /* Version */
d205 1
a205 1
clioptSetval(cliOption, "1"); break; /* Eval */
d207 1
a207 1
clioptSetval(cliOption, "1"); break; /* Help */
d209 1
a209 1
clioptSetval(cliOption, "1"); break; /* Info */
d211 1
a211 1
clioptSetval(cliOption, "1"); break; /* Label */
d213 1
a213 1
clioptSetval(cliOption, "1"); break; /* Print */
d215 1
a215 1
clioptSetval(cliOption, "1"); break; /* Silent */
d217 1
a217 1
clioptSetval(cliOption, "1"); break; /* Raw */
d219 1
a219 1
clioptSetval(cliOption, "1"); break; /* Verbose */
d221 1
a221 1
clioptSetval(cliOption, "1"); break; /* Exec */
@
1.12
log
@Relocate debug config dumping logic and clean up terminal option handling.
@
text
@d174 1
@
1.11
log
@Intermediate committal, lots of additions, compiles and works very limited.
@
text
@d293 1
a293 2
if (cliOpt < -1) {
/* An error occurred during option processing */
d297 1
a297 1
return(RC_THROW(RC_ERR_INT));
@
1.10
log
@More flush work on analyzer.
@
text
@d44 1
a44 1
/* Long options with short keys but no arguments */
d177 1
a177 1
ex_try {
d180 1
a180 1
ex_catch(Except) {
d285 1
a285 1
ex_try { /* eating a new option */
d288 1
a288 1
ex_catch(Except) { /* Error condition probably deserves attention */
d313 1
a313 1
ex_try {
d317 1
a317 1
ex_catch(Except) {
d334 1
a334 1
/* ex_try {
d341 1
a341 1
ex_catch(Except) {
@
1.9
log
@Fix the build, comment missing pieces, and synchronize throughout.
@
text
@d172 1
a172 2
int nSecs = 0;
int nIndex = 0;
d174 1
a174 1
if (m_pszSecs) /* Warn on overwrites */
d176 6
a181 10
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_pszSecs[nIndex] = NULL; /* Used later to find the end of the array */
a182 2
else
return(RC_THROW(RC_ERR_USE)); /* Incoming sections are NULL? */
d355 3
a357 7
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_pszSecs);
}
@
1.8
log
@Begin processor pieces.
@
text
@d39 2
a40 2
static char *m_szRcfile = NULL; /* rc file */
static char **m_pszSec = NULL; /* Section names */
d138 1
a138 1
const char **clioptGetsec(void)
d140 1
a140 1
if (!m_pszSec)
d143 1
a143 12
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);
d160 3
a162 3
if (m_szRcfile) /* Forbid overwriting */
return(RC_THROW(RC_ERR_USE)); /* an existing rcfile */
else if (kszRc)
d170 1
a170 1
rc_return_t clioptSetsec(const char *pkszSec[])
d175 10
a184 9
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]));
d186 1
a186 1
m_pszSec[nIndex] = NULL; /* Used later to find the end of the array */
d273 1
a273 1
* clioptParseopt(int, char **) *
d276 1
a276 1
rc_return_t clioptParseopt(int argc, char *argv[])
d281 1
a281 1
m_Optcon = popt_getcontext(NULL, argc, (const char **)argv, m_pOptable, 0);
d284 1
a284 1
if (argc < 2) { /* Allow the user to enter just one option, -h z.B. */
a295 4
/* 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);
d311 5
a315 24
/***************************************
* 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)
d319 4
a322 3
/* 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));
d362 4
a365 4
if (m_pszSec) { /* Free the section name arg */
for (i = 0; m_pszSec[i]; i++) {
free(m_pszSec[i]);
m_pszSec[i] = NULL;
d367 1
a367 1
free(m_pszSec);
@
1.7
log
@Command line option configuration and some processor operations.
@
text
@d183 2
a184 1
int i = 0;
d189 2
a190 2
for (i = 0; pkszSec[i]; i++); /* Count the sections */
m_pszSec = malloc(sizeof (char **) * i + 1); /* Allocate using i */
d192 3
a194 3
for (i = 0; pkszSec[i]; i++) {
m_pszSec[i] = malloc(strlen(pkszSec[i]));
memcpy(m_pszSec[i], pkszSec[i], strlen(pkszSec[i]));
d196 1
a196 1
m_pszSec[i] = NULL; /* Used later for finding the end of array */
@
1.6
log
@Added OSSP str back to build configuration, and used it for output formatting.
Added pieces of rc file and section command line parsing logic.
@
text
@a29 1
#include
d36 1
a36 1
#include "popt.h" /* OSSP popt options library*/
d38 45
a82 3
static char *m_pszOptuples[RC_NUMOPTS]; /* Option name value tuples */
static char *m_szRcfile = NULL; /* rc file */
static char *m_szSec = NULL; /* Section names */
d86 1
a86 1
* clioptConstruct(void) *
d89 1
a89 1
rc_return_t clioptConstruct(void)
d97 1
a97 1
/*FIXME optConstruct((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/
a102 1
TRACE("cliopt constructed.\n");
d107 14
a120 2
* clioptGetval(rc_opt_t) *
* Command line option accessor *
a129 4
/***************************************
* clioptGetrcfile(void) *
* Command line rc file accessor *
***************************************/
d132 3
d138 32
a169 5
/***************************************
* clioptGetsec(void) *
* Command line section accessor *
***************************************/
const char *clioptGetsec(void)
d171 30
a200 1
return((const char *)m_szSec);
d209 1
a209 1
rc_return_t clioptProcess(int cliOption, const char *szArg)
d214 1
a214 2
m_pszOptuples[cliOption] = strdup("1"); /* Usage */
return(RC_THROW(RC_ERR_USE));
d216 1
a216 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Debug */
d218 1
a218 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Version */
d220 1
a220 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Eval */
d222 1
a222 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Help */
d224 1
a224 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Info */
d226 1
a226 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Label */
d228 1
a228 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Print */
d230 1
a230 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Silent */
d232 1
a232 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Raw */
d234 1
a234 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Verbose */
d236 1
a236 1
m_pszOptuples[cliOption] = strdup("1"); break; /* Exec */
d240 1
a240 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Locations */
d242 1
a242 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Conf file */
d244 1
a244 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Func file */
d246 1
a246 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Format */
d248 1
a248 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Temp dir */
d250 1
a250 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* User name */
d252 1
a252 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Group name */
d254 1
a254 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Umask */
d257 1
a257 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Assignregex */
d259 1
a259 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Labelregex */
d261 1
a261 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Refregex */
d263 1
a263 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Paramregex */
d265 1
a265 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Termregex */
d268 1
a268 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Configname */
d270 1
a270 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Commonname */
d272 1
a272 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Defaultname */
d274 1
a274 1
m_pszOptuples[cliOption] = strdup(szArg); break; /* Errorname */
d282 1
a282 1
* clioptParse(int, char **) *
d285 1
a285 1
rc_return_t clioptParse(int argc, char *argv[])
d287 5
a291 40
static 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"},
/* Special stuff */
POPT_AUTOHELP
{NULL, 0, 0, NULL, 0}
};
d293 3
a295 11
ex_t Except;
char cliOpt = 0; /* For argument parsing */
char *szCLIBuf = NULL;
popt_context optCon; /* Context for parsing options */
optCon = popt_getcontext(NULL, argc, (const char **)argv, optionsTable, 0);
popt_setotheroptionhelp(optCon, "[options] ");
if (argc < 3) {
fprintf(stderr, "Please enter at least one rcfile and section.\n");
popt_printusage(optCon, stderr, 0);
d300 3
a302 3
while ((cliOpt = popt_getnextopt(optCon)) >= 0) { /* Loop, each time */
ex_try { /* eating a new option */
clioptProcess(cliOpt, popt_getoptarg(optCon));
d304 6
a309 11
ex_catch(Except) {
if ((rc_return_t)Except.ex_value == RC_ERR_USE) {
popt_printusage(optCon, stderr, 0);
rethrow;
}
else { /* Some error condition probably deserves attention */
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;
}
a312 9
/* At this point we should be finished parsing options, so now we use */
/* popt as a transport to read the user specified rcfile and sections. */
szCLIBuf = (char *)popt_getarg(optCon);
if ((szCLIBuf == NULL)) {
fprintf(stderr, "Please enter at least one rcfile and section.\n");
popt_printusage(optCon, stderr, 0);
return(RC_THROW(RC_ERR_USE));
}
d316 1
a316 1
popt_badoption(optCon, POPT_BADOPTION_NOALIAS),
a320 2
fprintf(stderr, "Run these commands: %s\n", szCLIBuf);
popt_freecontext(optCon);
d325 39
a363 1
* clioptDestruct(void) *
d366 1
a366 1
rc_return_t clioptDestruct(void)
d374 1
a374 1
/*FIXME optDestruct((rc_opt_t **)&s_pBintab->pOptlist->pvData);FIXME*/
d383 1
d393 7
a399 2
if (m_szSec) /* Free the section name arg */
free(m_szSec);
a404 1
TRACE("cliopt destructed.\n");
@
1.5
log
@Remove obsolete specs and implementations.
@
text
@d37 1
a37 1
#include "popt.h" /* OSSP popt options library */
d39 3
a41 1
static char *m_szOptuples[RC_NUMOPTS]; /* Option name value tuples */
d60 1
a60 1
memset(m_szOptuples, NULL, sizeof(m_szOptuples));
d75 19
a93 1
return((const char *)m_szOptuples[Optname]);
d107 2
a108 1
m_szOptuples[cliOption] = strdup("1"); break; /* Usage */
d110 1
a110 1
m_szOptuples[cliOption] = strdup("1"); break; /* Debug */
d112 1
a112 1
m_szOptuples[cliOption] = strdup("1"); break; /* Version */
d114 1
a114 1
m_szOptuples[cliOption] = strdup("1"); break; /* Eval */
d116 1
a116 1
m_szOptuples[cliOption] = strdup("1"); break; /* Help */
d118 1
a118 1
m_szOptuples[cliOption] = strdup("1"); break; /* Info */
d120 1
a120 1
m_szOptuples[cliOption] = strdup("1"); break; /* Label */
d122 1
a122 1
m_szOptuples[cliOption] = strdup("1"); break; /* Print */
d124 1
a124 1
m_szOptuples[cliOption] = strdup("1"); break; /* Silent */
d126 1
a126 1
m_szOptuples[cliOption] = strdup("1"); break; /* Raw */
d128 1
a128 1
m_szOptuples[cliOption] = strdup("1"); break; /* Verbose */
d130 1
a130 1
m_szOptuples[cliOption] = strdup("1"); break; /* Exec */
d134 1
a134 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Locations */
d136 1
a136 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Conf file */
d138 1
a138 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Func file */
d140 1
a140 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Format */
d142 1
a142 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Temp dir */
d144 1
a144 1
m_szOptuples[cliOption] = strdup(szArg); break; /* User name */
d146 1
a146 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Group name */
d148 1
a148 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Umask */
d151 1
a151 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Assignregex */
d153 1
a153 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Labelregex */
d155 1
a155 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Refregex */
d157 1
a157 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Paramregex */
d159 1
a159 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Termregex */
d162 1
a162 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Configname */
d164 1
a164 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Commonname */
d166 1
a166 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Defaultname */
d168 1
a168 1
m_szOptuples[cliOption] = strdup(szArg); break; /* Errorname */
d298 6
a303 2
for (i = 0; i < RC_NUMOPTS; i++) /* Free the tuple */
m_szOptuples[i] ? free(m_szOptuples[i]) : RC_NOP; /* or do nothing */
d305 4
a308 1
memset(m_szOptuples, NULL, sizeof(m_szOptuples)); /* Clear tuples */
d312 1
a312 1
if (m_szOptuples[i])
@
1.4
log
@Configuration string parsing logic.
@
text
@a76 9
* clioptSummarize(void) *
* Command line option summary *
***************************************/
const char *clioptSummarize(void)
{
return (NULL);
}
/***************************************
d87 1
a87 2
m_szOptuples[cliOption] = strdup("1"); /* Usage */
break;
d89 1
a89 2
m_szOptuples[cliOption] = strdup("1"); /* Debug */
break;
d91 20
a110 29
m_szOptuples[cliOption] = strdup("1"); /* Version */
break;
case RC_EVL_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Eval */
break;
case RC_HLP_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Help */
break;
case RC_INF_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Info */
break;
case RC_LBL_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Label */
break;
case RC_PRN_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Print */
break;
case RC_SIL_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Silent */
break;
case RC_RAW_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Raw */
break;
case RC_VRB_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Verbose */
break;
case RC_EXC_VAL:
m_szOptuples[cliOption] = strdup("1"); /* Exec */
break;
d113 1
a113 2
m_szOptuples[cliOption] = strdup(szArg); /* Locations */
break;
d115 1
a115 2
m_szOptuples[cliOption] = strdup(szArg); /* Conf file */
break;
d117 1
a117 2
m_szOptuples[cliOption] = strdup(szArg); /* Func file */
break;
d119 1
a119 2
m_szOptuples[cliOption] = strdup(szArg); /* Format */
break;
d121 1
a121 2
m_szOptuples[cliOption] = strdup(szArg); /* Temp dir */
break;
d123 1
a123 2
m_szOptuples[cliOption] = strdup(szArg); /* User name */
break;
d125 1
a125 2
m_szOptuples[cliOption] = strdup(szArg); /* Group name */
break;
d127 2
a128 2
m_szOptuples[cliOption] = strdup(szArg); /* Umask */
break;
d130 1
a130 2
m_szOptuples[cliOption] = strdup(szArg); /* Assign regex */
break;
d132 1
a132 2
m_szOptuples[cliOption] = strdup(szArg); /* Label regex */
break;
d134 1
a134 2
m_szOptuples[cliOption] = strdup(szArg); /* Ref regex */
break;
d136 1
a136 2
m_szOptuples[cliOption] = strdup(szArg); /* Params regex */
break;
d138 2
a139 2
m_szOptuples[cliOption] = strdup(szArg); /* Terminal regex */
break;
d141 1
a141 2
m_szOptuples[cliOption] = strdup(szArg); /* Config name */
break;
d143 1
a143 2
m_szOptuples[cliOption] = strdup(szArg); /* Common name */
break;
d145 1
a145 2
m_szOptuples[cliOption] = strdup(szArg); /* Default name */
break;
d147 2
a148 4
m_szOptuples[cliOption] = strdup(szArg); /* Error name */
break;
default :
break;
d210 1
d216 16
a231 12
while ((cliOpt = popt_getnextopt(optCon)) >= 0)
ex_try {
clioptProcess(cliOpt, popt_getoptarg(optCon));
}
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);
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);
d234 2
d238 1
a238 1
fprintf(stderr, "Please specify at least one rcfile and section.\n");
d255 1
@
1.3
log
@Flush configuration and parsing work.
@
text
@d91 1
a91 1
rc_return_t clioptProcess(int cliOption)
d94 1
d96 1
a96 1
m_szOptuples[cliOption] = strdup("1");
d99 1
a99 1
m_szOptuples[cliOption] = strdup("1");
d102 1
a102 1
m_szOptuples[cliOption] = strdup("1");
d105 1
a105 1
m_szOptuples[cliOption] = strdup("1");
d108 1
a108 1
m_szOptuples[cliOption] = strdup("1");
d111 1
a111 1
m_szOptuples[cliOption] = strdup("1");
d114 1
a114 1
m_szOptuples[cliOption] = strdup("1");
d117 1
a117 1
m_szOptuples[cliOption] = strdup("1");
d120 1
a120 1
m_szOptuples[cliOption] = strdup("1");
d123 1
a123 1
m_szOptuples[cliOption] = strdup("1");
d126 1
a126 1
m_szOptuples[cliOption] = strdup("1");
d129 1
a129 1
m_szOptuples[cliOption] = strdup("1");
d131 1
d133 1
a133 1
m_szOptuples[cliOption] = strdup("1");
d136 1
a136 1
m_szOptuples[cliOption] = strdup("1");
d139 1
a139 1
m_szOptuples[cliOption] = strdup("1");
d142 1
a142 1
m_szOptuples[cliOption] = strdup("1");
d145 1
a145 1
m_szOptuples[cliOption] = strdup("1");
d148 1
a148 1
m_szOptuples[cliOption] = strdup("1");
d151 1
a151 1
m_szOptuples[cliOption] = strdup("1");
d154 1
a154 1
m_szOptuples[cliOption] = strdup("1");
d157 1
a157 1
m_szOptuples[cliOption] = strdup("1");
d160 1
a160 1
m_szOptuples[cliOption] = strdup("1");
d163 1
a163 1
m_szOptuples[cliOption] = strdup("1");
d166 1
a166 1
m_szOptuples[cliOption] = strdup("1");
d169 1
a169 1
m_szOptuples[cliOption] = strdup("1");
d172 1
a172 1
m_szOptuples[cliOption] = strdup("1");
d175 1
a175 1
m_szOptuples[cliOption] = strdup("1");
d178 1
a178 1
m_szOptuples[cliOption] = strdup("1");
d181 1
a181 1
m_szOptuples[cliOption] = strdup("1");
d198 12
a209 12
{ 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 },
d219 12
a230 12
{ 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" },
d234 1
a234 1
{ NULL, 0, 0, NULL, 0 }
d253 1
a253 1
clioptProcess(cliOpt);
@
1.2
log
@Flush the toilet.
@
text
@d39 1
a39 40
static char *s_szOptuples[RC_NUMOPTS]; /* Option name value tuples */
static 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 }
};
d58 1
a58 1
memset(s_szOptuples, NULL, sizeof(s_szOptuples));
d60 1
a60 1
TRACE("cliopt constructed.");
d70 2
a71 1
ex_t Except;
d73 1
a73 8
assert(Optname < RC_NUMOPTS); /* Invalidate if nonexistent option */
ex_try {
return((const char *)s_szOptuples[Optname]);
}
ex_catch(Except) {
rethrow;
}
return (NULL); /* Not reached */
d94 89
a182 89
case RC_USE_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_DBG_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_VER_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_EVL_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_HLP_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_INF_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_LBL_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_PRN_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_SIL_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_RAW_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_VRB_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_EXC_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_LOC_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_CNF_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_FNC_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_QRY_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_TMP_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_OWN_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_GRP_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_MSK_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_ASS_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_DEF_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_REF_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_PRM_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_TRM_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_NCF_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_CMN_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_DFL_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
case RC_ERR_VAL:
s_szOptuples[cliOption] = strdup("1");
break;
default :
break;
d194 41
d303 2
a304 6
for (i = 0; i < RC_NUMOPTS; i++)
if (s_szOptuples[i])
TRACEL(i);
for (i = 0; i < RC_NUMOPTS; i++) /* Free the tuple */
s_szOptuples[i] ? free(s_szOptuples[i]) : RC_NOP; /* or do nothing */
d306 1
a306 1
memset(s_szOptuples, NULL, sizeof(s_szOptuples)); /* Clear tuples */
d308 1
d310 4
a313 3
if (s_szOptuples[i])
TRACE("Problem! Destructor failed!");
TRACE("cliopt destructed.");
@
1.1
log
@Add new configuration pieces.
@
text
@d32 1
d35 3
a37 1
#include "rc_cliopt.h"
d39 40
a78 1
static rc_cliopt_t *s_pInst = NULL; /* Singleton cliopt instance */
d87 3
a89 3
assert(s_pInst == NULL);
s_pInst = malloc(sizeof(s_pInst)); /* Allocate a cliopt instance */
if (!s_pInst)
d92 8
d104 2
a105 2
* clioptGetXXXX(void) *
* Command line option accessors *
d107 1
a107 1
short clioptGetvers(void)
a109 1
short nVer = 0;
d111 1
a111 1
assert(s_pInst);
d113 1
a113 1
d118 111
d230 1
a230 1
return(nVer);
d234 53
d292 28
a319 3
assert(s_pInst);
free(s_pInst); /* Deallocate cliopt and */
s_pInst = NULL; /* clear its reference */
@