summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-09-28 23:10:45 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-09-28 23:10:45 +0000
commit1d0fcf308929bde5749b889373d5c2f338fa8969 (patch)
tree624b053028a1ff9505b9fd297107278c5273e17d
parent08ae1393b7d415355308856618ca96c3ba2cfbd0 (diff)
downloadmdk-1d0fcf308929bde5749b889373d5c2f338fa8969.tar.gz
mdk-1d0fcf308929bde5749b889373d5c2f338fa8969.tar.bz2
uniform command line options handling
-rw-r--r--mixgtk/gmixvm.c73
-rw-r--r--mixguile/mixguile.c8
-rw-r--r--mixguile/mixguile.h4
-rw-r--r--mixguile/mixguile_main.c7
-rw-r--r--mixlib/mix.c10
-rw-r--r--mixlib/mix.h6
-rw-r--r--mixutils/mixasm.c7
-rw-r--r--mixutils/mixvm.c6
8 files changed, 100 insertions, 21 deletions
diff --git a/mixgtk/gmixvm.c b/mixgtk/gmixvm.c
index 59b4b41..91b03f3 100644
--- a/mixgtk/gmixvm.c
+++ b/mixgtk/gmixvm.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- gmixvm.c :
* Main function of the mix gtk front-end
* ------------------------------------------------------------------
- * Last change: Time-stamp: "2001-04-28 22:37:45 jao"
+ * $Id: gmixvm.c,v 1.3 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include "mixgtk.h"
+static gboolean initfile_ = TRUE;
#ifdef MAKE_GUILE
# include <mixguile/mixguile.h>
@@ -33,15 +34,83 @@ inner_main_ (int argc, char *argv[])
{
mixgtk_init (argc, argv);
mixguile_set_cmd_dispatcher (mixgtk_cmd_dispatcher_get_mix_dispatcher ());
- mixguile_load_bootstrap ();
+ mixguile_load_bootstrap (initfile_);
mixgtk_main ();
mixgtk_release ();
}
#endif
+#ifdef HAVE_GETOPT_LONG
+# include <getopt.h>
+#else
+# include <lib/getopt.h>
+#endif /* HAVE_GETOPT_LONG */
+
+enum {
+ VER_OPT = 'v',
+ NOINIT_OPT = 'q',
+ HELP_OPT = 'h',
+ USAGE_OPT = 'u'
+};
+
+static const char *options_ = "vqhu";
+
+static struct option long_options_[] =
+{
+ {"version", no_argument, 0, VER_OPT},
+ {"help", no_argument, 0, HELP_OPT},
+ {"usage", no_argument, 0, USAGE_OPT},
+ {"noinit", no_argument, 0, NOINIT_OPT},
+ {0, 0, 0, 0}
+};
+
+static void print_usage_ (const gchar *prog)
+{
+ static const char *usage_ =
+ "Usage: %s [-vhuq] [--version] [--help] [--usage] [--noinit]\n";
+ fprintf (stderr, usage_, prog);
+}
+
int
main(int argc, char *argv[])
{
+ int c;
+
+ const char *prog_name = argv[0];
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
+ while (1)
+ {
+ c = getopt_long (argc, argv, options_, long_options_, (int*)0);
+
+ /* Detect the end of the options. */
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case VER_OPT:
+ mix_print_license ("gmixvm, GTK MIX virtual machine");
+ return EXIT_SUCCESS;
+ case NOINIT_OPT:
+ initfile_ = FALSE;
+ break;
+ case HELP_OPT:
+ case USAGE_OPT:
+ print_usage_ (prog_name);
+ return EXIT_SUCCESS;
+ case '?':
+ print_usage_ (prog_name);
+ return EXIT_FAILURE;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ }
+
#ifdef MAKE_GUILE
mixguile_enter (argc, argv, inner_main_);
#else
diff --git a/mixguile/mixguile.c b/mixguile/mixguile.c
index 482832a..2f1ae48 100644
--- a/mixguile/mixguile.c
+++ b/mixguile/mixguile.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixguile.c :
* Implementation of the functions declared in mixguile.h
* ------------------------------------------------------------------
- * $Id: mixguile.c,v 1.5 2001/09/24 23:27:42 jao Exp $
+ * $Id: mixguile.c,v 1.6 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -40,7 +40,7 @@ real_main_ (int argc, char *argv[])
if (vm_dispatcher_)
{
mixguile_set_cmd_dispatcher (vm_dispatcher_);
- mixguile_load_bootstrap ();
+ mixguile_load_bootstrap (init_file_);
}
(*main_fun_)(argc, argv);
}
@@ -62,7 +62,7 @@ mixguile_init (int argc, char *argv[], gboolean initfile,
/* load bootstrap file */
void
-mixguile_load_bootstrap (void)
+mixguile_load_bootstrap (gboolean loadlocal)
{
const gchar *scmfile = SCM_FILE;
gchar *lscmfile = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S,
@@ -77,7 +77,7 @@ mixguile_load_bootstrap (void)
else
mixguile_interpret_file (scmfile);
- if (init_file_ && !access (lscmfile, R_OK))
+ if (loadlocal && !access (lscmfile, R_OK))
{
mixguile_interpret_file (lscmfile);
}
diff --git a/mixguile/mixguile.h b/mixguile/mixguile.h
index 469f455..7a29062 100644
--- a/mixguile/mixguile.h
+++ b/mixguile/mixguile.h
@@ -1,7 +1,7 @@
/* -*-c-*- ---------------- mixguile.h :
* Interface to the mixguile interpreter.
* ------------------------------------------------------------------
- * $Id: mixguile.h,v 1.4 2001/09/24 23:27:42 jao Exp $
+ * $Id: mixguile.h,v 1.5 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -38,7 +38,7 @@ typedef void (*main_func_t) (int argc, char *argv[]);
/* load mixguile startup file */
extern void
-mixguile_load_bootstrap ();
+mixguile_load_bootstrap (gboolean localinit);
/*
initialise the guile command dispatcher and enter the provided
diff --git a/mixguile/mixguile_main.c b/mixguile/mixguile_main.c
index fca0664..c230131 100644
--- a/mixguile/mixguile_main.c
+++ b/mixguile/mixguile_main.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixguile_main.c :
* Main function for mixguile, the MIX Guile shell
* ------------------------------------------------------------------
- * $Id: mixguile_main.c,v 1.4 2001/09/24 23:28:03 jao Exp $
+ * $Id: mixguile_main.c,v 1.5 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
@@ -53,7 +53,6 @@ main (int argc, char *argv[])
mix_vm_cmd_dispatcher_t *dis;
int c;
- const char *prog_name = argv[0];
gboolean initfile = TRUE;
setlocale (LC_ALL, "");
@@ -74,9 +73,7 @@ main (int argc, char *argv[])
switch (c)
{
case VER_OPT:
- fprintf (stderr, _("%s %s, Scheme MIX Virtual Machine.\n"),
- prog_name, VERSION);
- fprintf (stderr, MIX_GPL_LICENSE);
+ mix_print_license ("mixguile, Scheme MIX Virtual Machine");
return EXIT_SUCCESS;
case NOINIT_OPT:
initfile = FALSE;
diff --git a/mixlib/mix.c b/mixlib/mix.c
index 8f49303..af1ba40 100644
--- a/mixlib/mix.c
+++ b/mixlib/mix.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mix.c :
* Implementation of the functions declared in mix.h
* ------------------------------------------------------------------
- * $Id: mix.c,v 1.3 2001/09/24 23:26:31 jao Exp $
+ * $Id: mix.c,v 1.4 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
@@ -60,6 +60,14 @@ const char *MIX_GPL_LICENSE =
"under the terms of the GNU General Public License.\n"
"For more information about these matters, see the files named COPYING.\n";
+void
+mix_print_license (const gchar *program)
+{
+ fprintf (stderr, _("%s (GNU MDK %s)\n\n"),
+ program, VERSION);
+ fprintf (stderr, MIX_GPL_LICENSE);
+}
+
/* check dir, and create it if it doesn't exist */
gboolean
mix_stat_dir (const gchar *dirname, const gchar *alias)
diff --git a/mixlib/mix.h b/mixlib/mix.h
index 2d45636..01a57fa 100644
--- a/mixlib/mix.h
+++ b/mixlib/mix.h
@@ -1,6 +1,8 @@
/* -*-c-*- ---------------- mix.h :
* Initialisation of the mix library
* ------------------------------------------------------------------
+ * $Id: mix.h,v 1.4 2001/09/28 23:10:45 jao Exp $
+ * ------------------------------------------------------------------
* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@@ -60,6 +62,10 @@ mix_release_lib (void);
extern const char *MIX_GPL_LICENSE;
+extern void
+mix_print_license (const gchar *program);
+
+
/* check dir, and create it if it doesn't exist */
extern gboolean
mix_stat_dir (const gchar *dirname, const gchar *alias);
diff --git a/mixutils/mixasm.c b/mixutils/mixasm.c
index c8ece5b..3f21b02 100644
--- a/mixutils/mixasm.c
+++ b/mixutils/mixasm.c
@@ -1,7 +1,9 @@
/* -*-c-*- -------------- mixasm.c:
* Main function of mixasm, the mix assembler
* ------------------------------------------------------------------
- * Copyright (C) 2000 Free Software Foundation, Inc.
+ * $Id: mixasm.c,v 1.3 2001/09/28 23:10:45 jao Exp $
+ * ------------------------------------------------------------------
+ * Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -84,8 +86,7 @@ main (int argc, char **argv)
fprintf (stderr, _(USAGE_), prog_name);
return EXIT_SUCCESS;
case VER_OPT:
- fprintf (stderr, _("%s %s, MIX compiler.\n"), prog_name, VERSION);
- fprintf (stderr, MIX_GPL_LICENSE);
+ mix_print_license ("mixasm, MIX assembler");
return EXIT_SUCCESS;
case OUT_OPT:
out = optarg;
diff --git a/mixutils/mixvm.c b/mixutils/mixvm.c
index 4014164..8c02095 100644
--- a/mixutils/mixvm.c
+++ b/mixutils/mixvm.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixvm.c :
* Main function for mixvm, the mix vm simulator
* ------------------------------------------------------------------
- * $Id: mixvm.c,v 1.5 2001/09/24 23:27:02 jao Exp $
+ * $Id: mixvm.c,v 1.6 2001/09/28 23:10:45 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
@@ -100,9 +100,7 @@ main (int argc, char **argv)
fprintf (stderr, _(USAGE_), prog_name);
return EXIT_SUCCESS;
case VER_OPT:
- fprintf (stderr, _("%s %s, MIX Virtual Machine.\n"),
- prog_name, VERSION);
- fprintf (stderr, MIX_GPL_LICENSE);
+ mix_print_license ("mixvm, MIX virtual machine");
return EXIT_SUCCESS;
case RUN_OPT:
in = optarg;