home *** CD-ROM | disk | FTP | other *** search
- /*+++*
- * title: optutil.c
- * RCS optutil.c,v 1.3 1998/02/03 00:35:16 tom Exp
- * abstract: command-line option handling support stuff.
- * author: Tom Hageman, The Netherlands <tom@basil.icce.rug.nl>
- * created: November 1996
- * modified: 31 May 1997
- *---*/
-
- #import <stdio.h>
- #import <stdlib.h>
- #import <string.h>
-
- #import "compat.h"
- #import "optutil.h"
- #import "version.h"
-
- #if NEXTSTEP
- # define OSVERSION "NEXTSTEP"
- #elif OPENSTEP
- # define OSVERSION "OPENSTEP"
- #elif RHAPSODY
- # define OSVERSION "Rhapsody"
- #else
- # define OSVERSION "unknown"
- #endif
-
- const char *basename(const char *path)
- {
- const char *s = strrchr(path, '/');
-
- return (s ? ++s : path);
- }
-
- const char *_progname = "(unset)";
-
- #ifndef __GNUC__
- void set_progname(const char *name) { _progname = basename(name); }
- const char *progname() { return _progname; }
- #endif
-
- void handle_usage_help_version(int what, const char *usage, const char *help)
- {
- switch (what)
- {
- case EXIT_USAGE:
- fprintf(stderr, usage, progname());
- fprintf(stderr, "try `%s -H' for more information.\n", progname());
- break;
- case EXIT_HELP:
- printf(usage, progname());
- printf(help, progname());
- what = EXIT_SUCCESS;
- break;
- case EXIT_VERSION:
- printf("%s: %s version %s, %s. (%s)\n",
- progname(), PACKAGE, VERSION, VERSION_DATE, OSVERSION);
- what = EXIT_SUCCESS;
- break;
- default:
- return; /* no-op. */
- }
- exit(what);
- }
-