Index: ossp-pkg/rc/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/rc/Makefile.in,v rcsdiff -q -kk '-r1.10' '-r1.11' -u '/v/ossp/cvs/ossp-pkg/rc/Makefile.in,v' 2>/dev/null --- Makefile.in 2002/02/06 16:56:33 1.10 +++ Makefile.in 2002/02/07 12:38:32 1.11 @@ -57,8 +57,8 @@ TARGET_PROGS = rc TARGET_MANS = rc.1 rc-sample.5 -SRCS = rc.c rc_version.c rc_pcre.c -OBJS = rc.o rc_version.o rc_pcre.o +SRCS = rc.c rc_option.c rc_version.c rc_pcre.c +OBJS = rc.o rc_option.o rc_version.o rc_pcre.o SUBDIRS = @SUBDIR_EX@ @SUBDIR_VAR@ @SUBDIR_STR@ @SUBDIR_POPT@ @@ -133,10 +133,10 @@ distclean: clean $(RM) config.log config.status config.cache # Generated by ./configure - $(RM) Makefile rc_config.h # Generated by ./configure + $(RM) Makefile rc_config.h # Generated by ./configure realclean: distclean - $(RM) configure rc_config.h.in # Generated by Autoconf + $(RM) configure rc_config.h.in # Generated by Autoconf $(RM) shtool check: test Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.9' '-r1.10' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/02/06 18:16:40 1.9 +++ rc.c 2002/02/07 12:38:32 1.10 @@ -30,164 +30,37 @@ #include #include "rc.h" -#include "rc_p.h" /* FIXME, remove when options moves */ -#include "rc_strings.h" /* FIXME, remove when options moves */ #ifdef HAVE_CONFIG_H #include "rc_config.h" #endif -/* Third party headers for libraries linked in */ +/* Third party headers for libraries linked in */ #include "ex.h" /* OSSP ex exception library */ -#include "str.h" /* OSSP str string library */ -#include "var.h" /* OSSP var variable library */ -#include "popt.h" /* OSSP popt options library */ -/* FIXME if we only catch exceptions we might not need the following */ -/* Catch OSSP ex based exceptions */ -#define RC_THROW(rv) \ - ( (rv) != RC_OK && (ex_catching && !ex_shielding) \ - ? (ex_throw(ossprc_id, NULL, (rv)), (rv)) : (rv)) - -/* Unique identifier to use with OSSP ex library */ -const char ossprc_id[] = "OSSP rc"; - - -static void die(rc_return_t rv) -{ - fprintf(stderr, "OSSP rc: Error, dying.\n"); - exit((int)rv); -} int main(int argc, char *argv[]) { - char cOpt = 0; /* For argument parsing */ - int iBufpos = 0; /* For tracking options */ - char *szCLIBuf = NULL; - char *szFuncfile = NULL; /* Rc.func file name and location */ - int nIter = 0; - char pcBuf[BUFSIZ+1]; - popt_context optCon; /* Context for parsing options */ - - struct popt_option optionsTable[] = { - /* Long options with short keys but no arguments */ - { "usage", '?', POPT_ARG_NONE, 0, RC_USE_VAL, RC_USE_DESC, NULL }, - { "debug", 'd', POPT_ARG_NONE, 0, RC_DBG_VAL, RC_DBG_DESC, NULL }, - { "version", 'V', POPT_ARG_NONE, 0, RC_VER_VAL, RC_VER_DESC, NULL }, - { "eval", 'e', POPT_ARG_NONE, 0, RC_EVL_VAL, RC_EVL_DESC, NULL }, - { "help", 'h', POPT_ARG_NONE, 0, RC_HLP_VAL, RC_HLP_DESC, NULL }, - { "info", 'i', POPT_ARG_NONE, 0, RC_INF_VAL, RC_INF_DESC, NULL }, - { "labels", 'l', POPT_ARG_NONE, 0, RC_LBL_VAL, RC_LBL_DESC, NULL }, - { "print", 'p', POPT_ARG_NONE, 0, RC_PRN_VAL, RC_PRN_DESC, NULL }, - { "silent", 's', POPT_ARG_NONE, 0, RC_SIL_VAL, RC_SIL_DESC, NULL }, - { "raw", 'r', POPT_ARG_NONE, 0, RC_RAW_VAL, RC_RAW_DESC, NULL }, - { "verbose", 'v', POPT_ARG_NONE, 0, RC_VRB_VAL, RC_VRB_DESC, NULL }, - { "exec", 'x', POPT_ARG_NONE, 0, RC_EXC_VAL, RC_EXC_DESC, NULL }, - - /* Single argument long options with short keys */ - { "locate", 'L', POPT_ARG_STRING, 0, RC_LOC_VAL, RC_LOC_DESC, "regx" }, - { "conf", 'c', POPT_ARG_STRING, 0, RC_CNF_VAL, RC_CNF_DESC, "path" }, - { "func", 'f', POPT_ARG_STRING, &szFuncfile,\ - RC_FNC_VAL, RC_FNC_DESC, "path" }, - { "query", 'q', POPT_ARG_STRING, 0, RC_QRY_VAL, RC_QRY_DESC, "varx" }, - { "tmp", 't', POPT_ARG_STRING, 0, RC_TMP_VAL, RC_TMP_DESC, "path" }, - - /* Single argument long options without short keys */ - { "RequireOwner", 0, POPT_ARG_STRING, 0,\ - RC_OWN_VAL, RC_OWN_DESC, "user" }, - { "RequireGroup", 0, POPT_ARG_STRING, 0,\ - RC_GRP_VAL, RC_GRP_DESC, "group" }, - { "RequireUmask", 0, POPT_ARG_INT, 0,\ - RC_MSK_VAL, RC_MSK_DESC, "umask" }, - { "ParseEnvAss", 0, POPT_ARG_STRING, 0,\ - RC_ASS_VAL, RC_ASS_DESC, "regx" }, - { "ParseSectionDef", 0, POPT_ARG_STRING, 0,\ - RC_DEF_VAL, RC_DEF_DESC, "regx" }, - { "ParseSectionRef", 0, POPT_ARG_STRING, 0,\ - RC_REF_VAL, RC_REF_DESC, "regx" }, - { "ParseSectionParam", 0, POPT_ARG_STRING, 0,\ - RC_PRM_VAL, RC_PRM_DESC, "regx" }, - { "ParseTerminal", 0, POPT_ARG_STRING, 0,\ - RC_TRM_VAL, RC_TRM_DESC, "regx" }, - { "NameConfig", 0, POPT_ARG_STRING, 0,\ - RC_NCF_VAL, RC_NCF_DESC, "name" }, - { "NameCommon", 0, POPT_ARG_STRING, 0,\ - RC_CMN_VAL, RC_CMN_DESC, "name" }, - { "NameDefault", 0, POPT_ARG_STRING, 0,\ - RC_DFL_VAL, RC_DFL_DESC, "name" }, - { "NameError", 0, POPT_ARG_STRING, 0,\ - RC_ERR_VAL, RC_ERR_DESC, "name" }, - - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - optCon = popt_getcontext(NULL, argc, (const char **)argv, optionsTable, 0); - popt_setotheroptionhelp(optCon, - "[OPTIONS]* [rcfile] [[section [args]] ...]"); - - if (argc < 2) { - popt_printusage(optCon, stderr, 0); - exit(1); - } + ex_t Except; + int bCaught = 0; - /* Now do options processing */ - while ((cOpt = popt_getnextopt(optCon)) >= 0) { - switch (cOpt) { - case 'h': - pcBuf[iBufpos++] = 'h'; - break; - case 'V': - pcBuf[iBufpos++] = 'V'; - break; - case 'i': - pcBuf[iBufpos++] = 'i'; - break; - case 'q': - pcBuf[iBufpos++] = 'q'; - break; - } + ex_try { + parseopts(argc, argv); } - - { /* FIXME Code snippet to use with throwable library calls FIXME */ - ex_t Except; - int bCaught = 0; - - ex_try { /* OSSP exception-enabled library calls go here */ - } - ex_catch(Except) { - if ((rc_return_t)Except.ex_value != RC_ERR_USE) - fprintf(stderr, "Nonusage exception: %d\n",\ - (rc_return_t)Except.ex_value); - bCaught = 1; - } - if (!bCaught) - fprintf(stderr, "Great, we can keep executing exceptionless.\n"); - } /* FIXME Code snippet to use with throwable library calls FIXME */ - - szCLIBuf = (char *)popt_getarg(optCon); - if ((szCLIBuf == NULL)) { - fprintf(stderr, "Please specify at least one rcfile and section.\n"); - popt_printusage(optCon, stderr, 0); - die(RC_THROW(RC_ERR_USE)); /* FIXME Vielleicht muss local = */ - } /* (int)RC_THROW(RC_ERR_USE));die(local); oder etwas so FIXME */ - - if (cOpt < -1) { - /* An error occurred during option processing */ - fprintf(stderr, "%s: %s\n", - popt_badoption(optCon, POPT_BADOPTION_NOALIAS), - popt_strerror(cOpt)); - die(RC_THROW(RC_ERR_INT)); /* FIXME Ebenso als vorherige Merkung */ + ex_catch(Except) { + if ((rc_return_t)Except.ex_value != RC_ERR_USE) + fprintf(stderr, "Nonusage exception: %d\n",\ + (rc_return_t)Except.ex_value); + bCaught = 1; } + if (!bCaught) { + fprintf(stderr, "No exceptions caught.\n"); + exit(0); /* Success */ + } + else + 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); - /* Print out options, szCLIBuf chosen */ - fprintf(stderr, "Options chosen: "); - for (nIter = 0; nIter < iBufpos ; nIter++) - fprintf(stderr, "-%c ", pcBuf[nIter]); - if (szFuncfile) - fprintf(stderr, "-f %s ", szFuncfile); - fprintf(stderr, "\nRun these commands: %s\n", szCLIBuf); - - popt_freecontext(optCon); - exit(0); + exit(1); /* Failure */ } Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/02/06 18:16:40 1.8 +++ rc.h 2002/02/07 12:38:32 1.9 @@ -50,7 +50,6 @@ /* RC return codes */ typedef enum { RC_OK, /* Success */ - RC_ERR_ARG, /* Argument error */ RC_ERR_USE, /* Usage error */ RC_ERR_MEM, /* Memory error */ RC_ERR_SYS, /* System error (see errno) */ @@ -60,7 +59,7 @@ } rc_return_t; /* Function prototypes */ -static void die(rc_return_t); +rc_return_t parseopts(int, char **); /*rc_result_t rc_Err (void); rc_result_t rc_Warn (void); Index: ossp-pkg/rc/rc_option.c RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_option.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_option.c,v' | diff -u /dev/null - -L'ossp-pkg/rc/rc_option.c' 2>/dev/null --- ossp-pkg/rc/rc_option.c +++ - 2024-05-04 13:46:26.979676420 +0200 @@ -0,0 +1,167 @@ +/* rc - OSSP Run-command processor +** Copyright (c) 2002 Cable & Wireless Deutschland GmbH +** Copyright (c) 2002 The OSSP Project +** Copyright (c) 2002 Ralf S. Engelschall +** +** This file is part of OSSP rc, a portable Run-command processor +** which can be found at http://www.ossp.org/pkg/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_option.c: Run-command processor ISO C source file +*/ + +#include + +#include "rc.h" +#include "rc_option.h" /* Values and other for popt */ +#include "rc_const.h" /* Strings and other constants */ + +#ifdef HAVE_CONFIG_H +#include "rc_config.h" +#endif + +/* Third party headers for libraries linked in */ +#include "ex.h" /* OSSP ex exception library */ +#include "popt.h" /* OSSP popt options library */ + +/* Define the ability to throw OSSP ex exceptions */ +#define RC_THROW(rv) \ + ( (rv) != RC_OK && (ex_catching && !ex_shielding) \ + ? (ex_throw(ossprc_id, NULL, (rv)), (rv)) : (rv)) + +/* Unique identifier to use with OSSP ex library */ +const char ossprc_id[] = "OSSP rc"; + + +rc_return_t parseopts(int argc, char *argv[]) +{ + char cOpt = 0; /* For argument parsing */ + int iBufpos = 0; /* For tracking options */ + char *szCLIBuf = NULL; + char *szFuncfile = NULL; /* Rc.func file name and location */ + int nIter = 0; + char pcBuf[BUFSIZ+1]; + popt_context optCon; /* Context for parsing options */ + + struct popt_option optionsTable[] = { + /* Long options with short keys but no arguments */ + { "usage", '?', POPT_ARG_NONE, 0, RC_USE_VAL, RC_USE_DESC, NULL }, + { "debug", 'd', POPT_ARG_NONE, 0, RC_DBG_VAL, RC_DBG_DESC, NULL }, + { "version", 'V', POPT_ARG_NONE, 0, RC_VER_VAL, RC_VER_DESC, NULL }, + { "eval", 'e', POPT_ARG_NONE, 0, RC_EVL_VAL, RC_EVL_DESC, NULL }, + { "help", 'h', POPT_ARG_NONE, 0, RC_HLP_VAL, RC_HLP_DESC, NULL }, + { "info", 'i', POPT_ARG_NONE, 0, RC_INF_VAL, RC_INF_DESC, NULL }, + { "labels", 'l', POPT_ARG_NONE, 0, RC_LBL_VAL, RC_LBL_DESC, NULL }, + { "print", 'p', POPT_ARG_NONE, 0, RC_PRN_VAL, RC_PRN_DESC, NULL }, + { "silent", 's', POPT_ARG_NONE, 0, RC_SIL_VAL, RC_SIL_DESC, NULL }, + { "raw", 'r', POPT_ARG_NONE, 0, RC_RAW_VAL, RC_RAW_DESC, NULL }, + { "verbose", 'v', POPT_ARG_NONE, 0, RC_VRB_VAL, RC_VRB_DESC, NULL }, + { "exec", 'x', POPT_ARG_NONE, 0, RC_EXC_VAL, RC_EXC_DESC, NULL }, + + /* Single argument long options with short keys */ + { "locate", 'L', POPT_ARG_STRING, 0, RC_LOC_VAL, RC_LOC_DESC, "regx" }, + { "conf", 'c', POPT_ARG_STRING, 0, RC_CNF_VAL, RC_CNF_DESC, "path" }, + { "func", 'f', POPT_ARG_STRING, &szFuncfile,\ + RC_FNC_VAL, RC_FNC_DESC, "path" }, + { "query", 'q', POPT_ARG_STRING, 0, RC_QRY_VAL, RC_QRY_DESC, "varx" }, + { "tmp", 't', POPT_ARG_STRING, 0, RC_TMP_VAL, RC_TMP_DESC, "path" }, + + /* Single argument long options without short keys */ + { "RequireOwner", 0, POPT_ARG_STRING, 0,\ + RC_OWN_VAL, RC_OWN_DESC, "user" }, + { "RequireGroup", 0, POPT_ARG_STRING, 0,\ + RC_GRP_VAL, RC_GRP_DESC, "group" }, + { "RequireUmask", 0, POPT_ARG_INT, 0,\ + RC_MSK_VAL, RC_MSK_DESC, "umask" }, + { "ParseEnvAss", 0, POPT_ARG_STRING, 0,\ + RC_ASS_VAL, RC_ASS_DESC, "regx" }, + { "ParseSectionDef", 0, POPT_ARG_STRING, 0,\ + RC_DEF_VAL, RC_DEF_DESC, "regx" }, + { "ParseSectionRef", 0, POPT_ARG_STRING, 0,\ + RC_REF_VAL, RC_REF_DESC, "regx" }, + { "ParseSectionParam", 0, POPT_ARG_STRING, 0,\ + RC_PRM_VAL, RC_PRM_DESC, "regx" }, + { "ParseTerminal", 0, POPT_ARG_STRING, 0,\ + RC_TRM_VAL, RC_TRM_DESC, "regx" }, + { "NameConfig", 0, POPT_ARG_STRING, 0,\ + RC_NCF_VAL, RC_NCF_DESC, "name" }, + { "NameCommon", 0, POPT_ARG_STRING, 0,\ + RC_CMN_VAL, RC_CMN_DESC, "name" }, + { "NameDefault", 0, POPT_ARG_STRING, 0,\ + RC_DFL_VAL, RC_DFL_DESC, "name" }, + { "NameError", 0, POPT_ARG_STRING, 0,\ + RC_ERR_VAL, RC_ERR_DESC, "name" }, + + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } + }; + + optCon = popt_getcontext(NULL, argc, (const char **)argv, optionsTable, 0); + popt_setotheroptionhelp(optCon, "[options] "); + + if (argc < 2) { + popt_printusage(optCon, stderr, 0); + return(RC_THROW(RC_ERR_USE)); + } + + /* Now do options processing */ + while ((cOpt = popt_getnextopt(optCon)) >= 0) { + switch (cOpt) { + case 'h': + pcBuf[iBufpos++] = 'h'; + break; + case 'V': + pcBuf[iBufpos++] = 'V'; + break; + case 'i': + pcBuf[iBufpos++] = 'i'; + break; + case 'q': + pcBuf[iBufpos++] = 'q'; + break; + } + } + + szCLIBuf = (char *)popt_getarg(optCon); + if ((szCLIBuf == NULL)) { + fprintf(stderr, "Please specify at least one rcfile and section.\n"); + popt_printusage(optCon, stderr, 0); + return(RC_THROW(RC_ERR_USE)); + } + + if (cOpt < -1) { + /* An error occurred during option processing */ + fprintf(stderr, "%s: %s\n", + popt_badoption(optCon, POPT_BADOPTION_NOALIAS), + popt_strerror(cOpt)); + return(RC_THROW(RC_ERR_INT)); + } + + /* Print out options, szCLIBuf chosen */ + fprintf(stderr, "Options chosen: "); + for (nIter = 0; nIter < iBufpos ; nIter++) + fprintf(stderr, "-%c ", pcBuf[nIter]); + if (szFuncfile) + fprintf(stderr, "-f %s ", szFuncfile); + fprintf(stderr, "\nRun these commands: %s\n", szCLIBuf); + + popt_freecontext(optCon); + return(RC_THROW(RC_OK)); +} Index: ossp-pkg/rc/rc_option.h RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_option.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_option.h,v' | diff -u /dev/null - -L'ossp-pkg/rc/rc_option.h' 2>/dev/null --- ossp-pkg/rc/rc_option.h +++ - 2024-05-04 13:46:26.982432559 +0200 @@ -0,0 +1,30 @@ +/* Option values used with popt */ +#define RC_USE_VAL 32 +#define RC_DBG_VAL 33 +#define RC_VER_VAL 34 +#define RC_EVL_VAL 35 +#define RC_HLP_VAL 36 +#define RC_INF_VAL 37 +#define RC_LBL_VAL 38 +#define RC_PRN_VAL 39 +#define RC_SIL_VAL 40 +#define RC_RAW_VAL 41 +#define RC_VRB_VAL 42 +#define RC_EXC_VAL 43 +#define RC_LOC_VAL 44 +#define RC_CNF_VAL 45 +#define RC_FNC_VAL 46 +#define RC_QRY_VAL 47 +#define RC_TMP_VAL 48 +#define RC_OWN_VAL 49 +#define RC_GRP_VAL 50 +#define RC_MSK_VAL 51 +#define RC_ASS_VAL 52 +#define RC_DEF_VAL 53 +#define RC_REF_VAL 54 +#define RC_PRM_VAL 55 +#define RC_TRM_VAL 56 +#define RC_NCF_VAL 57 +#define RC_CMN_VAL 58 +#define RC_DFL_VAL 59 +#define RC_ERR_VAL 60