Index: ossp-pkg/rc/rc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.c,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/rc/rc.c,v' 2>/dev/null --- rc.c 2002/01/30 17:29:15 1.3 +++ rc.c 2002/02/04 21:48:22 1.4 @@ -28,70 +28,150 @@ */ #include -#include -#include #include "rc.h" -#include "ex.h" /* OSSP ex exception library */ -#include "str.h" /* OSSP str string library */ -#include "var.h" /* OSSP var variable library */ +#include "rc_p.h" /* FIXME, remove when options moves */ +#include "rc_strings.h" /* FIXME, remove when options moves */ +/* 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 */ -void usage(char *szProgname) + +static void die(rc_return_t rv) +{ + fprintf(stderr, "OSSP rc: Error, dying.\n"); + exit((int)rv); +} + +void usage(popt_context optCon, rc_return_t rv, char *szError) +{ + popt_printusage(optCon, stderr, 0); + if (szError) + fprintf(stderr, "%s\n", szError); + exit((int)rv); +} + +/*void usage(char *szProgname) { + popt_peekarg(optCon) == NULL; fprintf(stdout, "Usage: %s [-v|--verbose] [-h|--help]\n\ [-p|--print] [-e|--eval] [-c|--config]\ [-q|--query] [-r|--raw]\n\ [ ...]", szProgname); -} - -int main(int argc, char *argv[]) -{ - int nOpt = 0; /* holds getopt(3) return value */ - int nFile = 0; /* for checking file existence */ +}*/ - int bVerbose = 0; /* v */ - int bHelp = 0; /* h */ - int bPrint = 0; /* p */ - int bEval = 0; /* e */ - int bConfig = 0; /* c */ - int bQuery = 0; /* q */ - int bRaw = 0; /* r */ - - while ((nOpt = getopt(argc, argv, "vhpecqr:")) != -1) - switch (nOpt) { - case 'v': - bVerbose = TRUE; - break; +int main(int argc, char *argv[]) { + char cOpt; /* For argument parsing */ + int iBufpos = 0; /* For tracking options */ + char *szCLIBuf; + char szFuncfile; /* Rc.func file name and location */ + int nIter; + char pcBuf[BUFSIZ+1]; + popt_context optCon; /* Context for parsing options */ + rc_return_t nRet; + + 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, 0, 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); + } + + /* Now do options processing */ + while ((cOpt = popt_getnextopt(optCon)) >= 0) { + switch (cOpt) { case 'h': - bHelp = TRUE; + pcBuf[iBufpos++] = 'h'; break; - case 'p': - bPrint = TRUE; + case 'V': + pcBuf[iBufpos++] = 'V'; break; - case 'e': - bEval = TRUE; - break; - case 'c': - bConfig = TRUE; + case 'i': + pcBuf[iBufpos++] = 'i'; break; case 'q': - bQuery = TRUE; - break; - case 'r': - bRaw = TRUE; + pcBuf[iBufpos++] = 'q'; break; - case '?': - default: - usage(*argv); } + } - argc -= optind; - argv += optind; - - /* check existence of file input to the run-command */ - if ((nFile = open(optarg, O_RDONLY, 0)) < 0) - err(1, "%s", optarg); + szCLIBuf = (char *)popt_getarg(optCon); + if ((szCLIBuf == NULL)) + usage(optCon, RC_ERR_ARG, "Specify at least one rcfile and section."); + + if (cOpt < -1) { + /* An error occurred during option processing */ + fprintf(stderr, "%s: %s\n", + popt_badoption(optCon, POPT_BADOPTION_NOALIAS), + popt_strerror(cOpt)); + die(nRet); + } + + /* Print out options, szCLIBuf chosen */ + printf("Options chosen: "); + for (nIter = 0; nIter < iBufpos ; nIter++) + printf("-%c ", pcBuf[nIter]); + if (szFuncfile) + fprintf(stderr, "-f %s ", szFuncfile); + fprintf(stderr, "\nRun these commands: %s\n", szCLIBuf); - return 0; /* success */ + popt_freecontext(optCon); + exit(0); } Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- rc.h 2002/01/22 22:53:47 1.3 +++ rc.h 2002/02/04 21:48:22 1.4 @@ -43,8 +43,19 @@ #define TRUE (!FALSE) #endif +/* 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) */ + RC_ERR_IO, /* Input/output error */ + RC_ERR_FMT, /* Formatting error */ + RC_ERR_INT, /* Internal error */ +} rc_return_t; -rc_result_t rc_Err (void); +/*rc_result_t rc_Err (void); rc_result_t rc_Warn (void); rc_result_t rc_PathAppend (int bExists, char **pszPaths); rc_result_t rc_PathPrepend (int bExists, char **pszPaths); @@ -53,6 +64,6 @@ rc_result_t rc_ServiceState (char *szService, char **pszServState); rc_result_t rc_TmpDirGen (char *szProgram); rc_result_t rc_TmpDirFile (char *szProgram, char *szFilename, *szVar); -rc_result_t rc_TmpDirDel (char *szProgram); +rc_result_t rc_TmpDirDel (char *szProgram);*/ #endif /* __OSSPRC_H__ */ Index: ossp-pkg/rc/rc_p.h RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_p.h,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_p.h,v' 2>/dev/null --- rc_p.h 2002/01/08 15:47:11 1.1 +++ rc_p.h 2002/02/04 21:48:22 1.2 @@ -36,4 +36,35 @@ #include #endif +/* 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 + #endif /* __OSSPRC_P_H__ */ Index: ossp-pkg/rc/rc_strings.h RCS File: /v/ossp/cvs/ossp-pkg/rc/Attic/rc_strings.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/rc/Attic/rc_strings.h,v' | diff -u /dev/null - -L'ossp-pkg/rc/rc_strings.h' 2>/dev/null --- ossp-pkg/rc/rc_strings.h +++ - 2024-04-29 21:00:42.556238503 +0200 @@ -0,0 +1,66 @@ +/* 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_strings.h: Run-command processor ANSI C public header file +*/ + +#ifndef __OSSPRC_STRINGS_H__ +#define __OSSPRC_STRINGS_H__ + +/* Option descriptions used with popt */ +#define RC_USE_DESC "Print a short usage summary, then exit." +#define RC_DBG_DESC "Don't remove temporary files, and write debug messages to stderr." +#define RC_VER_DESC "Print the version and copyright, then exit." +#define RC_EVL_DESC "Output the command(s) in a format suitable for shell evaluation, but do not run them." +#define RC_HLP_DESC "Print this help, then exit." +#define RC_INF_DESC "Print a comprehensive summary of the rc environment." +#define RC_LBL_DESC "Learn what section labels a rcfile has." +#define RC_PRN_DESC "Output the command(s) in a format suitable for human reading, but do not run them." +#define RC_SIL_DESC "Be silent, and disable output to stdout." +#define RC_RAW_DESC "Output text using no terminal control sequences." +#define RC_VRB_DESC "Output text verbosely." +#define RC_EXC_DESC "Execute the commands through an interpreter." + +#define RC_LOC_DESC "Specifiy the location(s) to search for rcfiles, and ignore parts according to the regex." +#define RC_CNF_DESC "Specify the location(s) of the configuration files." +#define RC_FNC_DESC "Specify the single location of the extra functions file." +#define RC_QRY_DESC "Query the effective value of configuration variables." +#define RC_TMP_DESC "Specify the single location for temporary files." + +#define RC_OWN_DESC "Username used to verify run command rights at runtime." +#define RC_GRP_DESC "Group name used to verify run command rights at runtime." +#define RC_MSK_DESC "Umask used to verify run command rights at runtime." +#define RC_ASS_DESC "Regex used to match name value assignments in a rcfile." +#define RC_DEF_DESC "Regex used to match a section label in a rcfile." +#define RC_REF_DESC "Regex used to match a section reference in a rcfile." +#define RC_PRM_DESC "Regex used to match the parameter(s) of a section label." +#define RC_TRM_DESC "Regex used to match the terminal(s) in a rcfile." +#define RC_NCF_DESC "Name of the config section in a rcfile." +#define RC_CMN_DESC "Name of the common section in a rcfile." +#define RC_DFL_DESC "Name of the default section in a rcfile." +#define RC_ERR_DESC "Name of the error section in a rcfile." + +#endif /* __OSSPRC_STRINGS_H__ */