head 1.42;
access;
symbols
OSSP_RC_0_7_3:1.41
OSSP_RC_0_7_2:1.41
OSSP_RC_0_7_1:1.39
OSSP_RC_ALPHA_06:1.31
OSSP_RC_EXBROKEN:1.28;
locks; strict;
comment @ * @;
1.42
date 2003.07.11.14.13.16; author ms; state Exp;
branches;
next 1.41;
1.41
date 2003.07.11.09.38.29; author ms; state Exp;
branches;
next 1.40;
1.40
date 2003.07.11.09.18.20; author ms; state Exp;
branches;
next 1.39;
1.39
date 2003.07.07.13.30.51; author ms; state Exp;
branches;
next 1.38;
1.38
date 2003.07.07.12.55.42; author ms; state Exp;
branches;
next 1.37;
1.37
date 2003.07.02.15.30.20; author ms; state Exp;
branches;
next 1.36;
1.36
date 2003.06.26.18.45.14; author ms; state Exp;
branches;
next 1.35;
1.35
date 2003.06.23.17.41.00; author ms; state Exp;
branches;
next 1.34;
1.34
date 2003.06.23.15.46.05; author ms; state Exp;
branches;
next 1.33;
1.33
date 2003.06.18.14.35.29; author ms; state Exp;
branches;
next 1.32;
1.32
date 2003.06.13.18.33.07; author ms; state Exp;
branches;
next 1.31;
1.31
date 2003.05.28.18.58.16; author ms; state Exp;
branches;
next 1.30;
1.30
date 2003.05.27.11.53.12; author ms; state Exp;
branches;
next 1.29;
1.29
date 2003.05.26.16.03.57; author ms; state Exp;
branches;
next 1.28;
1.28
date 2003.05.26.08.36.40; author ms; state Exp;
branches;
next 1.27;
1.27
date 2002.08.01.15.54.45; author ms; state Exp;
branches;
next 1.26;
1.26
date 2002.08.01.11.59.55; author ms; state Exp;
branches;
next 1.25;
1.25
date 2002.08.01.08.09.04; author ms; state Exp;
branches;
next 1.24;
1.24
date 2002.07.30.16.32.40; author ms; state Exp;
branches;
next 1.23;
1.23
date 2002.07.29.16.34.59; author ms; state Exp;
branches;
next 1.22;
1.22
date 2002.07.05.14.10.24; author ms; state Exp;
branches;
next 1.21;
1.21
date 2002.07.05.13.27.22; author ms; state Exp;
branches;
next 1.20;
1.20
date 2002.07.01.15.03.33; author ms; state Exp;
branches;
next 1.19;
1.19
date 2002.06.27.15.35.58; author ms; state Exp;
branches;
next 1.18;
1.18
date 2002.06.26.14.42.53; author ms; state Exp;
branches;
next 1.17;
1.17
date 2002.06.26.14.11.16; author ms; state Exp;
branches;
next 1.16;
1.16
date 2002.05.22.13.29.40; author ms; state Exp;
branches;
next 1.15;
1.15
date 2002.04.25.09.51.29; author ms; state Exp;
branches;
next 1.14;
1.14
date 2002.04.24.16.47.07; author ms; state Exp;
branches;
next 1.13;
1.13
date 2002.04.23.12.30.29; author ms; state Exp;
branches;
next 1.12;
1.12
date 2002.04.22.15.22.39; author ms; state Exp;
branches;
next 1.11;
1.11
date 2002.04.22.12.16.39; author ms; state Exp;
branches;
next 1.10;
1.10
date 2002.04.12.19.15.12; author ms; state Exp;
branches;
next 1.9;
1.9
date 2002.04.11.16.52.45; author ms; state Exp;
branches;
next 1.8;
1.8
date 2002.04.09.17.01.54; author ms; state Exp;
branches;
next 1.7;
1.7
date 2002.04.08.15.37.10; author ms; state Exp;
branches;
next 1.6;
1.6
date 2002.03.26.17.11.06; author ms; state Exp;
branches;
next 1.5;
1.5
date 2002.03.01.22.48.23; author ms; state Exp;
branches;
next 1.4;
1.4
date 2002.02.28.18.24.04; author ms; state Exp;
branches;
next 1.3;
1.3
date 2002.02.28.15.30.04; author ms; state Exp;
branches;
next 1.2;
1.2
date 2002.02.13.19.19.28; author ms; state Exp;
branches;
next 1.1;
1.1
date 2002.02.08.18.36.40; author ms; state Exp;
branches;
next ;
desc
@@
1.42
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_config.c: Run-Command Processor ISO C source file
*/
#include
#include
#include /* For opendir(3) */
#include "rc.h"
#include "rc_config.h"
#include "rc_const.h" /* String constants */
/* Cludge the version id */
#define _RC_VERSION_C_AS_HEADER_
#include "rc_version.c"
#undef _RC_VERSION_C_AS_HEADER_
static int m_nLocks = 0; /* Server locks, not thread-safe FIXME */
/***************************************
* configNew(void) *
* Construct a configuration *
***************************************/
rc_config_t configNew(void)
{
ex_t Except;
rc_config_t *pRetobj = NULL;
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;
}
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);*/
}
/* FIXME: Make into configVisit, using callbacks to get and set option info */
/***************************************
* configInfo(void) *
* Print the configuration information *
***************************************/
rc_return_t configInfo(void)
{
ex_t Except;
int i = 0;
char **pszTemp = NULL; /* For holding the section string vector */
try {
fprintf(stderr, "# Run command file: %s\n", configGetrcfile());
pszTemp = (char **)configGetsecs();
fprintf(stderr, "# Sections:");
for (i = 0; pszTemp[i]; i++)
fprintf(stderr, " %s", pszTemp[i]);
fputc('\n', stderr);
/* FIXME Not threadsafe, wrap with crit section */
for (i = 0; i < RC_NUMOPTS; i++) {
if (configGetval(i) == NULL); /* NOP */
else if (!(strcmp(configGetval(i), "1")))
fprintf(stderr, "# Option %s is on\n", configGetname(i));
else
fprintf(stderr, "# Option %s is %s\n", configGetname(i),\
configGetval(i));
}
fputc('\n', stderr);
}
catch(Except)
rethrow;
return(RC_THROW(RC_OK));
}
/***************************************
* configGetXXX(rc_opt_t) *
* Configuration accessors *
***************************************/
const char *configGetval(rc_opt_t Optname)
{
ex_t Except;
char *szTemp = NULL;
if (m_nLocks) { /* Make sure config exists */
try {
if ((szTemp = (char *)clioptGetval(Optname)));
/* else if (szTemp = envoptGetval(Optname));
else if (szTemp = cnfoptGetval(Optname));*/
}
catch(Except)
rethrow;
return((const char *)szTemp);
}
else {
RC_THROW(RC_ERR_USE);
}
return(NULL); /* Not reached */
}
const char *configGetname(rc_opt_t Optname)
{
static char *s_szOptnametab[] = { /* NULL is for alignment */
NULL, RC_USE_NAME, RC_DBG_NAME, RC_VER_NAME,
RC_EVL_NAME, RC_HLP_NAME, RC_INF_NAME, RC_LBL_NAME,
RC_PRN_NAME, RC_PAR_NAME, RC_SIL_NAME, RC_RAW_NAME,
RC_VRB_NAME, RC_EXC_NAME, RC_LOC_NAME, RC_CNF_NAME,
RC_FNC_NAME, RC_QRY_NAME, RC_TMP_NAME, RC_OWN_NAME,
RC_GRP_NAME, RC_MSK_NAME, RC_ASS_NAME, RC_DEF_NAME,
RC_REF_NAME, RC_PRM_NAME, RC_TRM_NAME, RC_NCF_NAME,
RC_CMN_NAME, RC_DFL_NAME, RC_ERR_NAME
};
if (m_nLocks) { /* Make sure config exists */
return((const char *)s_szOptnametab[Optname]);
}
else {
RC_THROW(RC_ERR_USE);
}
return(NULL); /* Not reached */
}
const char *configGetrcfile(void)
{
ex_t Except;
char *szRcname = NULL;
if (m_nLocks) { /* Make sure config exists */
try {
/* Because (1) only one rc file can be specified and */
/* (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 */
szRcname = (char *)clioptGetrcfile();
}
catch(Except)
rethrow;
return((const char *)szRcname);
}
else
RC_THROW(RC_ERR_USE);
return(NULL); /* Not reached */
}
const char **configGetsecs(void)
{
ex_t Except;
char **pszSecname = NULL;
if (m_nLocks) { /* Make sure config exists */
try { /* FIXME Might need to check */
pszSecname = (char **)clioptGetsecs(); /* FIXME env, conf, configs */
}
catch(Except)
rethrow;
return((const char **)pszSecname);
}
else
RC_THROW(RC_ERR_USE);
return(NULL); /* Not reached */
}
/************************************************
* configLoad(int, const char **) *
* Load a configuration *
************************************************/
rc_return_t configLoad(int nTotal, const char *szArgvec[])
{
ex_t Except;
try { /* Parse option groups in order of priority */
clioptParseopts(nTotal, szArgvec); /* Command line options */
configVerify(); /* Test for usage, help and version options */
clioptParseargs(); /* Command line args */
/* envoptParse(m_nLocks->pOpt);*/ /* Environment options */
/* cnfoptParse(m_nLocks->pOpt);*/ /* Configfile options */
/* Test if information is asked of the operating environment */
if (configGetval(RC_INF_VAL)) { /* These lines must come after */
configInfo(); /* option parsing is finished! */
}
}
catch(Except)
rethrow;
return(RC_THROW(RC_OK));
}
/************************************************
* configVerify(void) *
* Verify config options help, usage, or version *
* and ensure that no uncompatible option *
* combinations were given *
************************************************/
rc_return_t configVerify(void)
{
ex_t Except;
short bStop = FALSE;
try { /* Checks for legal option combination */
/* I'm too braindead to remember digital logic theory from the */
/* Uni, so I'll hack my own XOR gates with plain math instead */
/* Exec XOR Eval XOR Print */
if (!configGetval(RC_EVL_VAL) \
+ !configGetval(RC_EXC_VAL) \
+ !configGetval(RC_PRN_VAL) \
+ !configGetval(RC_PAR_VAL) < 3) { /* Warning! Magic number */
fprintf(stderr, RC_EEP_TEXT);
bStop = TRUE;
}
/* Silent XOR OutputOptions */
if (configGetval(RC_SIL_VAL) && (configGetval(RC_DBG_VAL) \
|| configGetval(RC_VER_VAL) || configGetval(RC_EVL_VAL) \
|| configGetval(RC_HLP_VAL) || configGetval(RC_INF_VAL) \
|| configGetval(RC_LBL_VAL) || configGetval(RC_PRN_VAL) \
|| configGetval(RC_PAR_VAL) || configGetval(RC_RAW_VAL) \
|| configGetval(RC_VRB_VAL) || configGetval(RC_QRY_VAL))) {
fprintf(stderr, RC_SLO_TEXT);
bStop = TRUE;
}
}
catch(Except)
rethrow;
if (bStop) { /* Did user blow an option rule? */
clioptPrintusage(); /* Yes, so announce it as SUE. */
return(RC_THROW(RC_ERR_TRM));
}
try { /* Basic checks of version, usage, and help options */
if (configGetval(RC_USE_VAL)) {
clioptPrintusage();
bStop = TRUE;
}
else if (configGetval(RC_HLP_VAL)) {
clioptPrintusage(); /* FIXME Replace with real help FIXME */
bStop = TRUE;
}
else if (configGetval(RC_VER_VAL)) {
fprintf(stdout, "OSSP rc %s\n", rc_version.v_short);
bStop = TRUE;
}
}
catch(Except)
rethrow;
if (bStop) /* Did user request a non-operation? */
return(RC_THROW(RC_ERR_TRM)); /* Yes, so terminate after handling. */
else
return(RC_THROW(RC_OK)); /* No, we should continue processing. */
}
/************************************************
* configDefaults(void) *
* Write default values to empty config members *
************************************************/
rc_return_t configDefaults(void)
{
ex_t Except;
DIR *pDir = NULL; /* For detecting our temp dir with opendir(3) */
try { /* Test members for empty attributes */
if (!configGetval(RC_EVL_VAL) && !configGetval(RC_EXC_VAL) \
&& !configGetval(RC_PRN_VAL) && !configGetval(RC_PAR_VAL))
clioptSetval(RC_EXC_VAL, RC_DEF_ON);
/* if (!configGetval(RC_LBL_VAL))
if (!configGetval(RC_SIL_VAL))
if (!configGetval(RC_RAW_VAL))
if (!configGetval(RC_VRB_VAL))*/
if (configGetval(RC_LOC_VAL)) {
if ((pDir = opendir(configGetval(RC_LOC_VAL))) == NULL)
return(RC_THROW(RC_ERR_LOC)); /* Failure, dir doesn't exist */
else
closedir(pDir); /* Success, directory exists */
}
else
clioptSetval(RC_LOC_VAL, "./");
/*
if (!configGetval(RC_CNF_VAL)) {
If exists '/etc/rcconf'
clioptSetval(RC_CNF_VAL, "/etc/rcconf");
Else
RC_NOP;
}
if (!configGetval(RC_FNC_VAL)) {
If exists '/etc/rc.func'
clioptSetval(RC_FNC_VAL, "/etc/rc.func");
Else
RC_NOP;
}
*/
/* if (!configGetval(RC_QRY_VAL))*/
if (configGetval(RC_TMP_VAL)) {
if ((pDir = opendir(configGetval(RC_TMP_VAL))) == NULL)
return(RC_THROW(RC_ERR_TMP)); /* Failure, tmp doesn't exist */
else
closedir(pDir); /* Success, tmp dir exists */
}
else { /* User didn't set tmp so */
clioptSetval(RC_TMP_VAL, RC_DEF_TMP); /* set it for them here */
if ((pDir = opendir(RC_DEF_TMP)) == NULL) /* Try using default */
return(RC_THROW(RC_ERR_TMP)); /* Failure, default not there */
else
closedir(pDir);
}
if (!configGetval(RC_TMP_VAL)) {
pDir = opendir(RC_DEF_TMP);
if (pDir)
clioptSetval(RC_TMP_VAL, RC_DEF_TMP);
closedir(pDir);
}
/* if (!configGetval(RC_OWN_VAL))
if (!configGetval(RC_GRP_VAL))
if (!configGetval(RC_MSK_VAL))
if (!configGetval(RC_ASS_VAL))*/
if (!configGetval(RC_DEF_VAL))
clioptSetval(RC_DEF_VAL, RC_DEF_DEF);
/* if (!configGetval(RC_REF_VAL))
if (!configGetval(RC_PRM_VAL))
if (!configGetval(RC_TRM_VAL))*/
if (!configGetval(RC_NCF_VAL))
clioptSetval(RC_NCF_VAL, RC_DEF_NCF);
if (!configGetval(RC_CMN_VAL))
clioptSetval(RC_CMN_VAL, RC_DEF_CMN);
/* if (!configGetval(RC_DFL_VAL))
if (!configGetval(RC_ERR_VAL))*/
}
catch(Except)
rethrow;
return(RC_THROW(RC_OK)); /* Normal response */
}
/***************************************
* configDelete(rc_config_t *) *
* Destruct a configuration *
***************************************/
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(this->m_pCliopts);
}
catch(Except)
rethrow;
}
else
return(RC_THROW(RC_ERR_USE));
return(RC_THROW(RC_OK));
}
@
1.41
log
@Remove hardcoded version, and replace with dynamic shtool generated data.
@
text
@d43 1
a45 1
d50 1
a50 1
rc_return_t configNew(void)
d53 1
d55 8
a62 3
if (m_nLocks == 0) { /* If we don't have one yet */
try { /* then construct a new one */
clioptNew(); /* Member cliopt instance */
d64 2
a65 2
catch(Except)
rethrow;
d68 1
a72 2
return(RC_THROW(RC_OK));
d383 1
a383 1
* configDelete(void) *
d386 1
a386 1
rc_return_t configDelete(void)
d392 1
a392 1
clioptDelete();
@
1.40
log
@Replace embedded text strings from code to constants header. Address two
functional problems identified by Thomas and Ralf, namely missing error
message identifiers and confusing period punctuation with info option.
@
text
@d32 1
a32 1
#include /* For opendir(3) */
d36 6
a41 1
#include "rc_const.h" /* String constants */
d272 1
a272 1
fprintf(stdout, "OSSP rc %s\n", RC_VERSION);
@
1.39
log
@More header corrections and improvements.
@
text
@d89 1
a89 1
fprintf(stderr, "# Option %s is on.\n", configGetname(i));
d91 1
a91 1
fprintf(stderr, "# Option %s is %s.\n", configGetname(i),\
@
1.38
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_config.c: Run-command processor ISO C source file
@
1.37
log
@Implement location and temporary directory checks.
@
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.36
log
@Break off before fully implementing common section run ops, but after
reorganization of class data, and additional member functions for section and
script manipulation.
@
text
@d287 1
a287 1
DIR *pTmpdir = NULL; /* For detecting our temp dir with opendir(3) */
d299 9
a308 7
if (!configGetval(RC_LOC_VAL)) {
If exists '/etc/rc.d'
clioptSetval(RC_LOC_VAL, "/etc/rc.d/rc.");
FIXME: !This 'rc.' reading logic must still be implemented!
Else
RC_NOP;
}
d325 14
d340 2
a341 2
pTmpdir = opendir(RC_DEF_TMP);
if (pTmpdir)
d343 1
a343 1
closedir(pTmpdir);
@
1.35
log
@Remove already implemented features from config default method, indicating
that they are finished.
@
text
@d344 2
d347 1
a347 2
/* if (!configGetval(RC_CMN_VAL))
if (!configGetval(RC_DFL_VAL))
@
1.34
log
@Conform to original OpenPKG rc behaviour by processing in execute run mode by
default, correct and explain return values, and adjust test suite.
@
text
@d294 1
a294 4
/* if (!configGetval(RC_USE_VAL))
if (!configGetval(RC_HLP_VAL))
if (!configGetval(RC_INF_VAL))
if (!configGetval(RC_LBL_VAL))
@
1.33
log
@Removed analyzer class, removed label class, implemented list class,
implemented file class, cleanup and restructure.
@
text
@d292 1
a292 1
clioptSetval(RC_PRN_VAL, RC_DEF_ON);
@
1.32
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
@d77 1
a77 1
fprintf(stderr, "Run command file: %s\n", configGetrcfile());
d80 1
a80 1
fprintf(stderr, "Sections:");
d89 1
a89 1
fprintf(stderr, "Option %s is on.\n", configGetname(i));
d91 1
a91 1
fprintf(stderr, "Option %s is %s.\n", configGetname(i),\
d94 1
@
1.31
log
@Fix info option.
@
text
@d132 6
a137 6
RC_PRN_NAME, RC_SIL_NAME, RC_RAW_NAME, RC_VRB_NAME,
RC_EXC_NAME, RC_LOC_NAME, RC_CNF_NAME, RC_FNC_NAME,
RC_QRY_NAME, RC_TMP_NAME, RC_OWN_NAME, RC_GRP_NAME,
RC_MSK_NAME, RC_ASS_NAME, RC_DEF_NAME, RC_REF_NAME,
RC_PRM_NAME, RC_TRM_NAME, RC_NCF_NAME, RC_CMN_NAME,
RC_DFL_NAME, RC_ERR_NAME
d232 2
a233 1
+ !configGetval(RC_PRN_VAL) < 2) { /* Warning! Magic number */
d242 2
a243 2
|| configGetval(RC_RAW_VAL) || configGetval(RC_VRB_VAL) \
|| configGetval(RC_QRY_VAL))) {
d290 1
a290 1
&& !configGetval(RC_PRN_VAL))
@
1.30
log
@Back out volatile identifier additions after better understanding their role.
@
text
@d203 5
a265 4
bStop = TRUE;
}
else if (configGetval(RC_INF_VAL)) {
configInfo();
@
1.29
log
@Preliminary exception handling repairs.
@
text
@d109 1
a109 1
volatile char *oszTemp = NULL;
d113 3
a115 3
if ((oszTemp = (char *)clioptGetval(Optname)));
/* else if (oszTemp = envoptGetval(Optname));
else if (oszTemp = cnfoptGetval(Optname));*/
d119 1
a119 1
return((const char *)oszTemp);
d152 1
a152 1
volatile char *oszRcname = NULL;
d160 1
a160 1
oszRcname = (char *)clioptGetrcfile();
d164 1
a164 1
return((const char *)oszRcname);
d174 1
a174 1
volatile char **opszSecname = NULL;
d178 1
a178 1
opszSecname = (char **)clioptGetsecs(); /* FIXME env, conf, configs */
d182 1
a182 1
return((const char **)opszSecname);
@
1.28
log
@Fix eval mode by replacing empty tempdir parameters.
@
text
@d53 1
a53 1
catch(Except) {
a54 1
}
d96 1
a96 1
catch(Except) {
a97 1
}
d109 1
a109 1
char *szTemp = NULL;
d113 3
a115 8
if ((szTemp = (char *)clioptGetval(Optname)))
return((const char *)szTemp);
/* else if (szTemp = envoptGetval(Optname))
return((const char *)szTemp);
else if (szTemp = cnfoptGetval(Optname))
return((const char *)szTemp);*/
else
return(NULL); /* Special case when not found */
d117 1
a117 1
catch(Except) {
d119 1
a119 1
}
d152 1
d160 1
a160 1
return(clioptGetrcfile());
d162 1
a162 1
catch(Except) {
d164 1
a164 1
}
d166 1
a166 1
else {
a167 2
}
d174 1
d176 3
a178 3
if (m_nLocks) { /* Make sure config exists */
try { /* FIXME Might need to check */
return(clioptGetsecs()); /* FIXME env, conf, configs */
d180 1
a180 1
catch(Except) {
d182 1
a182 1
}
d184 1
a184 1
else {
a185 2
}
d204 1
a204 1
catch(Except) {
a205 1
}
d242 1
a242 1
catch(Except) {
d244 1
a244 1
}
d264 1
a264 4
/* FIXME: Ralf! If an exception is thrown (or rethrown) into this context, */
/* then the local handler (in five lines) either segfaults or hangs */
fprintf(stderr, "Hello user, OSSP rc is broken if you use --info. Thanks.\n\n - The management\n");
/* configInfo();*/
d268 1
a268 1
catch(Except) {
a269 1
}
d349 1
a349 1
catch(Except) {
a350 1
}
d367 1
a367 1
catch(Except) {
a368 1
}
@
1.27
log
@Found a new rc_ex bug, and couldn't fix it so I put in a hacky workaround.
@
text
@d32 1
d36 1
a36 1
#include "rc_const.h" /* String constants */
d38 1
a38 1
static int m_nLocks = 0; /* Server locks, not thread-safe FIXME */
d298 1
a336 1
/*
d338 4
a341 4
If exists '/tmp'
clioptSetval(RC_TMP_VAL, "/tmp");
Else
RC_NOP;
a342 1
*/
@
1.26
log
@Moved call to configVerify to squash yet another early error bug.
@
text
@d175 1
a175 1
return(NULL); /* Not reached */
d205 1
a205 1
try { /* Parse option groups in order of priority */
d273 4
a276 1
configInfo();
@
1.25
log
@Rooted out magic numbers and made new default value section for strings.
@
text
@d207 1
a228 2
@
1.24
log
@Begin coding inspection of options for combination usage errors.
@
text
@d299 1
a299 1
clioptSetval(RC_PRN_VAL, "1");
d348 1
a348 1
clioptSetval(RC_DEF_VAL, "^%(\\w+).*?\\n(.*?)^$");
d355 1
a355 1
clioptSetval(RC_NCF_VAL, "config");
@
1.23
log
@Implement about half of the necessary default configuration members.
@
text
@d221 2
d228 31
@
1.22
log
@Prepare for config defaults through addition of the config visitor object.
@
text
@d255 80
@
1.21
log
@Move code block.
@
text
@d58 4
d65 1
d74 1
a74 1
char **pszTemp = NULL; /* For holding the section string vector */
@
1.20
log
@Wrote configInfo, removed config debugging, prepared procRun for
eval/exec/print logic, and improved test conditions.
@
text
@d41 21
a93 21
return(RC_THROW(RC_OK));
}
/***************************************
* configNew(void) *
* Construct a configuration *
***************************************/
rc_return_t configNew(void)
{
ex_t Except;
if (m_nLocks == 0) { /* If we don't have one yet */
try { /* then construct a new one */
clioptNew(); /* Member cliopt instance */
}
catch(Except) {
rethrow;
}
}
m_nLocks++; /* FIXME not threadsafe */
@
1.19
log
@Added 'all' wildcard rcfile globbing and removed location hardcoding and
rcfile prefix hardcoding.
@
text
@a37 1
static char *m_szSummary = NULL; /* Configuration summary storage */
d41 2
a42 5
* configDebug(void) *
* Debug a configuration *
* Warning: There is no error checking *
* or debugging of this *
* debugger block *
d44 1
a44 1
void configDebug(void)
d46 1
d48 1
a48 2
ex_t Except;
char **szTemp = NULL;
d53 1
a53 1
szTemp = (char **)configGetsecs();
d55 3
a57 2
while (szTemp[i])
fprintf(stderr, " %s", szTemp[i++]);
d59 9
a67 1
fprintf(stderr, "\n%s", configSummarize());
d69 1
d73 2
a191 52
/***************************************
* configSummarize(void) *
* Configuration summary *
***************************************/
const char *configSummarize(void)
{
ex_t Except;
int i = 0;
char *szTemp = NULL;
/* Make sure we start with a blank slate */
if (m_szSummary) {
free(m_szSummary);
m_szSummary = NULL;
}
for (i = 0; i < RC_NUMOPTS; i++)
{
try { /* FIXME Not threadsafe, wrap with crit section */
if (configGetval(i) == NULL); /* NOP */
else if (!(strcmp(configGetval(i), "1"))) {
szTemp = calloc(1, (m_szSummary ? strlen(m_szSummary) : 0) + strlen(configGetval(i)));
if (m_szSummary)
strcpy(szTemp, m_szSummary);
strcat(szTemp, "Option ");
strcat(szTemp, configGetname(i));
strcat(szTemp, " is on.\n");
if (m_szSummary)
free(m_szSummary);
m_szSummary = szTemp;
}
else {
szTemp = malloc(strlen(m_szSummary) + strlen(configGetval(i)));
strcpy(szTemp, m_szSummary);
strcat(szTemp, "Option ");
strcat(szTemp, configGetname(i));
strcat(szTemp, " is ");
strcat(szTemp, configGetval(i));
strcat(szTemp, ".\n");
if (m_szSummary)
free(m_szSummary);
m_szSummary = szTemp;
}
} /* FIXME Not threadsafe, wrap with crit section */
catch(Except) { /* Breaks the otherwise endless loop above */
rethrow;
}
}
return ((const char *)m_szSummary);
}
a222 4
if (configGetval(RC_VER_VAL)) {
fprintf(stdout, "OSSP rc %s\n", RC_VERSION);
bStop = TRUE;
}
d227 1
a227 1
if (configGetval(RC_HLP_VAL)) {
d231 8
d245 1
a245 1
return(RC_THROW(RC_WRN_TRM)); /* Yes, so terminate after handling. */
a260 2
if (m_szSummary)
free(m_szSummary);
@
1.18
log
@Relocate debug config dumping logic and clean up terminal option handling.
@
text
@d194 6
a199 1
m_szSummary = malloc(NULL);
d205 3
a207 2
szTemp = malloc(strlen(m_szSummary) + strlen(configGetval(i)));
strcpy(szTemp, m_szSummary);
@
1.17
log
@Intermediate committal, lots of additions, compiles and works very limited.
@
text
@d258 1
d261 1
a261 1
if (configGetval(RC_VER_VAL))
d263 3
a265 1
if (configGetval(RC_USE_VAL))
d267 3
a269 1
if (configGetval(RC_HLP_VAL))
d271 2
d278 4
a281 1
return(RC_THROW(RC_OK));
@
1.16
log
@Fix the build, comment missing pieces, and synchronize throughout.
@
text
@d51 1
d54 2
a55 1
fprintf(stderr, "Run command file: %s\n", configGetrcfile());
d57 4
a60 4
szTemp = (char **)configGetsecs();
fprintf(stderr, "Sections:");
while (szTemp[i])
fprintf(stderr, " %s", szTemp[i++]);
d62 5
a66 1
fprintf(stderr, "\n%s", configSummarize());
d78 1
a78 1
ex_try { /* then construct a new one */
d81 1
a81 1
ex_catch(Except) {
d100 1
a100 1
ex_try {
d110 1
a110 1
ex_catch(Except) {
d147 1
a147 1
ex_try {
d154 1
a154 1
ex_catch(Except) {
d170 1
a170 1
ex_try { /* FIXME Might need to check */
d173 1
a173 1
ex_catch(Except) {
d197 1
a197 1
ex_try { /* FIXME Not threadsafe, wrap with crit section */
d222 1
a222 1
ex_catch(Except) { /* Breaks the otherwise endless loop above */
d238 1
a238 1
ex_try { /* Parse option groups in order of priority */
d244 1
a244 1
ex_catch(Except) {
d259 1
a259 1
ex_try { /* Basic checks of version, usage, and help options */
d267 1
a267 1
ex_catch(Except) {
d283 1
a283 1
ex_try { /* FIXME, not thread-safe */
d288 1
a288 1
ex_catch(Except) {
@
1.15
log
@Moved early option verify from main to config.
@
text
@d51 1
a51 2
ex_t Except;
char *szTemp = NULL;
d55 1
a55 1
szTemp = (char *)configGetsec(i);
d57 2
a58 9
while (szTemp) {
fprintf(stderr, " %s", szTemp);
ex_try {
szTemp = (char *)configGetsec(++i);
}
ex_catch(Except) {
break;
}
}
d146 1
a146 1
return (clioptGetrcfile());
d155 1
d159 1
a159 1
const char *configGetsec(int nIndex)
a161 1
char **pszSectemp = NULL;
d163 3
a165 8
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);
}
d174 1
d225 1
a225 1
* configLoad(int, char **) *
d228 1
a228 1
rc_return_t configLoad(int argc, char *argv[])
d232 3
a234 4
ex_try { /* Parse option groups in order of priority */
clioptParseopt(argc, argv); /* Command line options */
clioptParserc(); /* Command line rc file */
clioptParsesec(); /* Command line sections */
@
1.14
log
@Command line option configuration and some processor operations.
@
text
@d258 23
@
1.13
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
d34 1
a34 1
#include "str.h"
d42 31
a72 1
* configConstruct(void) *
d75 1
a75 1
rc_return_t configConstruct(void)
d81 1
a81 1
clioptConstruct(); /* Member cliopt instance */
d144 46
d198 1
a198 1
int bCaught = FALSE;
d200 3
a202 1
while (!bCaught) {
d204 22
a225 8
if (configGetval(i)) { /* FIXME Is realloc portable here? */
/* FIXME Unportable kludge to ensure storage FIXME */
m_szSummary = realloc(m_szSummary, sizeof("OptionXXis") + \
sizeof(configGetname(i)) + sizeof(configGetval(i) + 8));
if (!(strcmp(configGetval(i), "1")))
str_concat(m_szSummary, "Option ", configGetname(i), " is on.\n");
else
str_concat(m_szSummary, "Option ", configGetname(i), " is ", configGetval(i), ".\n");
d227 3
a229 3
} /* FIXME Not threadsafe, wrap with crit section */
ex_catch(Except) { /* Breaks the otherwise endless loop above */
bCaught = TRUE;
a230 1
i++;
d244 6
a249 10
ex_try { /* Parse option groups in order of priority */
clioptParse(argc, argv); /* Command line options */
/* envoptParse(m_nLocks->pOpt);*/ /* Environment options */
/* cnfoptParse(m_nLocks->pOpt);*/ /* Configfile options */
}
ex_catch(Except) {
rethrow;
}
ex_try {
d259 1
a259 1
* configDestruct(void) *
d262 1
a262 1
rc_return_t configDestruct(void)
d268 1
a268 1
clioptDestruct();
@
1.12
log
@Remove obsolete specs and implementations.
@
text
@d35 2
a36 1
#include "rc_const.h" /* String constants */
d131 4
a134 12
if (!(strcmp(configGetval(i), "1"))) {
strcat(m_szSummary, "Option ");
strcat(m_szSummary, configGetname(i));
strcat(m_szSummary, " is on.\n");
}
else {
strcat(m_szSummary, "Option ");
strcat(m_szSummary, configGetname(i));
strcat(m_szSummary, " is ");
strcat(m_szSummary, configGetval(i));
strcat(m_szSummary, ".\n");
}
@
1.11
log
@Configuration string parsing logic.
@
text
@d32 1
d38 1
d114 39
d190 2
@
1.10
log
@Flush configuration and parsing work.
@
text
@d92 9
a100 9
static char *s_szOptnametab[] = {
RC_USE_NAME, RC_DBG_NAME, RC_VER_NAME, RC_EVL_NAME,
RC_HLP_NAME, RC_INF_NAME, RC_LBL_NAME, RC_PRN_NAME,
RC_SIL_NAME, RC_RAW_NAME, RC_VRB_NAME, RC_EXC_NAME,
RC_LOC_NAME, RC_CNF_NAME, RC_FNC_NAME, RC_QRY_NAME,
RC_TMP_NAME, RC_OWN_NAME, RC_GRP_NAME, RC_MSK_NAME,
RC_ASS_NAME, RC_DEF_NAME, RC_REF_NAME, RC_PRM_NAME,
RC_TRM_NAME, RC_NCF_NAME, RC_CMN_NAME, RC_DFL_NAME,
RC_ERR_NAME
@
1.9
log
@Flush the toilet.
@
text
@d36 1
a36 1
static int s_nLocks = 0; /* Server locks, not thread-safe FIXME */
d47 1
a47 1
if (s_nLocks == 0) { /* If we don't have one yet */
d55 1
a55 1
s_nLocks++; /* FIXME not threadsafe */
d61 1
a61 1
* configGetoptval(rc_opt_t) *
d64 1
a64 1
const char *configGetoptval(rc_opt_t Optname)
d69 1
a69 1
if (s_nLocks) { /* Make sure config exists */
d90 22
d122 2
a123 2
/* envoptParse(s_nLocks->pOpt);*/ /* Environment options */
/* cnfoptParse(s_nLocks->pOpt);*/ /* Configfile options */
d146 1
a146 1
if (--s_nLocks == 0) { /* If m_nLocks is 0, deallocate */
@
1.8
log
@Flush configuration changes.
@
text
@a33 1
#include "rc_private.h"
a34 2
#include "rc_config.h" /* Config types and constants */
#include "rc_option.h" /* Option operations rely on popt */
d36 1
a36 1
static rc_config_t *s_pInst = NULL; /* Singleton config instance */
d47 3
a49 8
if (s_pInst == NULL) { /* If we don't have one */
s_pInst = malloc(sizeof(s_pInst)); /* yet, then allocate */
if (!s_pInst) /* a config instance */
return(RC_THROW(RC_ERR_MEM));
s_pInst->m_nLocks = 0;
ex_try {
clioptConstruct(); /* Make a config instance */
d55 1
a55 1
s_pInst->m_nLocks++; /* FIXME not threadsafe */
d61 1
a61 1
* configGetXXXX(void) *
d64 1
a64 1
short configGetvers(void)
d67 1
a67 1
short nVer = 0;
d69 1
a69 1
if (s_pInst != NULL) {
d71 8
a78 1
a85 1
return(NULL);
d87 1
a87 2
return(nVer);
d98 4
a101 7
ex_try { /* Parse through each type of option */
/* FIXME s_pInst->pOpt will hold a copy of the command line */
// coptParse(s_pInst->pOpt); /* First priority options */
// eoptParse(s_pInst->pOpt); /* Medium priority options */
// foptParse(s_pInst->pOpt); /* Low priority options */
coptParse(argc, argv); /* FIXME Patch for now */
/* FIXME s_pInst->pOpt will hold a copy of the command line */
d124 6
a129 11
if (s_pInst) {
if (--s_pInst->m_nLocks == 0) { /* If m_nLocks is 0, dealloc */
ex_try { /* FIXME, not thread-safe */
clioptDestruct();
}
ex_catch(Except) {
rethrow;
}
free(s_pInst); /* Deallocate config and */
s_pInst = NULL; /* clear its reference */
@
1.7
log
@Bring build back to life and remove val code.
@
text
@d36 1
d39 1
a39 1
static rc_config_t *s_pInst = NULL; /* Singleton configuration instance */
d50 5
a54 5
if (s_pInst == NULL) { /* If we don't have one */
s_pInst = malloc(sizeof(s_pInst)); /* yet, then allocate */
if (!s_pInst) /* a configuration */
return(RC_THROW(RC_ERR_MEM)); /* instance */
s_pInst->nLocks = 0;
d57 1
a57 1
/* Make a config instance */
d63 1
a63 1
s_pInst->nLocks++; /* FIXME not threadsafe */
d131 3
a133 3
if (!(--s_pInst->nLocks)) { /* If nLocks is 0, dealloc */
ex_try { /* FIXME, not thread-safe */
d139 2
a140 2
free(s_pInst); /* Deallocate configuration */
s_pInst = NULL; /* and clear its reference */
@
1.6
log
@Vacation flush, mostly build configuration details. Its not building very
clean right now.
@
text
@a36 1
#include "val.h" /* OSSP val library holds config */
d49 4
a52 4
if (s_pInst == NULL) { /* If we don't have one */
s_pInst = malloc(sizeof(s_pInst)); /* yet, then allocate */
if (!s_pInst) /* a configuration */
return(RC_THROW(RC_ERR_MEM)); /* instance */
d55 3
a57 3
ex_try { /* Make a val instance */
val_create(&s_pInst->pOpt); /* to hold individual */
} /* configuration values */
d78 1
a78 1
val_get(s_pInst->pOpt, RC_VER_NAME, &nVer);
d112 1
a112 4
ex_try { /* Register and set configuration values */
/* FIXME This is real bad, replace with our own */
val_reg(s_pInst->pOpt, RC_VER_NAME, VAL_TYPE_SHORT, RC_VER_DESC, NULL);
val_set(s_pInst->pOpt, RC_VER_NAME, 1);
d132 2
a133 2
val_destroy(s_pInst->pOpt); /* Destroy val instance and */
} /* Assume that pOpt is NULL */
@
1.5
log
@Fixed the build, improved the design, improved the configuration and option
processing.
@
text
@d1 2
a2 1
/* rc - OSSP Run-command processor
a4 1
** Copyright (c) 2002 Ralf S. Engelschall
d7 1
a7 1
** which can be found at http://www.ossp.org/pkg/rc/
@
1.4
log
@Configuration improvements.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d57 1
a57 1
val_create(&s_pInst->pVal); /* to hold individual */
d79 1
a79 1
val_get(s_pInst->pVal, RC_VER_NAME, &nVer);
d101 12
d115 2
a116 2
val_reg(s_pInst->pVal, RC_VER_NAME, VAL_TYPE_SHORT, RC_VER_DESC, NULL);
val_set(s_pInst->pVal, RC_VER_NAME, 1);
d136 2
a137 2
val_destroy(s_pInst->pVal); /* Destroy val instance and */
} /* Assume that pVal is NULL */
@
1.3
log
@Cleanup and structuring.
@
text
@d35 5
a39 3
#include "rc_const.h" /* String constants */
#include "rc_option.h" /* Option operations rely on popt */
#include "val.h" /* OSSP val library holds config */
d43 1
a43 1
* configConstruct(rc_config_t) *
d46 1
a46 1
rc_return_t configConstruct(rc_config_t **ppConfig)
d50 12
a61 9
*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;
d63 1
d68 25
d94 1
a94 1
* configLoad(rc_config_t, int, char **) *
d97 1
a97 1
rc_return_t configLoad(rc_config_t *pConfig, int argc, char *argv[])
a99 2
char *pTestopt = NULL;
const char *pFuncpath = "/sfw/etc/rc.func";
d102 3
a104 4
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, "Hier!%s!\n", pTestopt);
d114 1
a114 1
* configDestruct(rc_config_t) *
d117 1
a117 1
rc_return_t configDestruct(rc_config_t *pConfig)
d121 12
a132 9
assert(pConfig);
free(pConfig); /* Deallocate configuration */
pConfig = NULL; /* and clear its reference */
ex_try {
val_destroy(pConfig->pVal); /* Destroy the val instance and assume */
} /* that its reference is cleared also */
ex_catch(Except) {
rethrow;
d134 2
@
1.2
log
@Small corrections in both logic and build configuration.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@d41 2
a42 2
* configInit(rc_config_t) *
* Initialize a configuration *
d44 1
a44 1
rc_return_t configInit(rc_config_t **ppConfig)
d48 7
a54 7
*ppConfig = malloc(sizeof(rc_config_t));
if (!*ppConfig)
return(RC_THROW(RC_ERR_MEM));
ex_try {
val_create(&(*ppConfig)->pVal);
}
d63 2
a64 2
* configFill(rc_config_t, int, char **) *
* Fill a configuration *
d66 1
a66 1
rc_return_t configFill(rc_config_t *pConfig, int argc, char *argv[])
d72 1
a72 1
ex_try {
d76 1
a76 1
fprintf(stderr, "%s\n", pTestopt);
d94 2
a95 1
free(pConfig);
d98 2
a99 2
val_destroy(pConfig->pVal);
}
a101 1
return(RC_THROW(RC_ERR_INT));
@
1.1
log
@Further abstraction and building in of the configuration logic. We now store
configuration variables using OSSP val, also.
PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
@
text
@a31 1
#include
@