--- rc.c 2002/02/05 20:37:34 1.8
+++ rc.c 2002/02/06 18:16:40 1.9
@@ -33,12 +33,25 @@
#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 */
#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)
{
@@ -46,28 +59,11 @@
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<package>\
- <command> [<command> ...]", szProgname);
-}*/
-
int main(int argc, char *argv[])
{
char cOpt = 0; /* For argument parsing */
int iBufpos = 0; /* For tracking options */
- char *szCLIBuf = NULL;
+ char *szCLIBuf = NULL;
char *szFuncfile = NULL; /* Rc.func file name and location */
int nIter = 0;
char pcBuf[BUFSIZ+1];
@@ -138,31 +134,50 @@
/* 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;
+ case 'h':
+ pcBuf[iBufpos++] = 'h';
+ break;
+ case 'V':
+ pcBuf[iBufpos++] = 'V';
+ break;
+ case 'i':
+ pcBuf[iBufpos++] = 'i';
+ break;
+ case 'q':
+ pcBuf[iBufpos++] = 'q';
+ break;
}
}
+ { /* 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))
- usage(optCon, RC_ERR_ARG, "Specify at least one rcfile and section.");
+ 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_ERR_ARG);
+ popt_badoption(optCon, POPT_BADOPTION_NOALIAS),
+ popt_strerror(cOpt));
+ die(RC_THROW(RC_ERR_INT)); /* FIXME Ebenso als vorherige Merkung */
}
/* Print out options, szCLIBuf chosen */
|