summaryrefslogtreecommitdiff
path: root/console-client
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2004-03-21 19:57:00 +0000
committerMarcus Brinkmann <marcus@gnu.org>2004-03-21 19:57:00 +0000
commit132c62de3caad3a9c7de679854f8eb214ad0ce8e (patch)
tree476ea75710fcba20a624e2ce3b5bb1aace60f29b /console-client
parentf34ee975ad64f836b3e6af7303f79c6e8ff76a3d (diff)
2004-03-21 Marco Gerards <metgerards@student.han.nl>
* console.c (main): Make sure the arguments are parsed in order. * driver.c (driver_add): Set up argc and argv so they can be used by argp. * generic-speaker.c: Include <string.h> and <argp.h>. (struct melody): New member `name'. Every melody was given a name. (BELL_CLASSIC, BELL_LINUX, BELL_ALARM, BELL_CMAJOR): New macros. (doc, options, argp): New variables. (parse_opt): New function. (generic_speaker_init): Parse the arguments using argp. * vga.c (doc, options, argp): New variables. (parse_opt): New function. (parse_startup_args): Function removed. (vga_display_init): Use argp_parse instead of parse_startup_args.
Diffstat (limited to 'console-client')
-rw-r--r--console-client/ChangeLog17
-rw-r--r--console-client/console.c4
-rw-r--r--console-client/driver.c10
-rw-r--r--console-client/generic-speaker.c86
-rw-r--r--console-client/vga.c124
5 files changed, 175 insertions, 66 deletions
diff --git a/console-client/ChangeLog b/console-client/ChangeLog
index b4393a9f..d7f97be9 100644
--- a/console-client/ChangeLog
+++ b/console-client/ChangeLog
@@ -1,3 +1,20 @@
+2004-03-21 Marco Gerards <metgerards@student.han.nl>
+
+ * console.c (main): Make sure the arguments are parsed in order.
+ * driver.c (driver_add): Set up argc and argv so they can be used
+ by argp.
+ * generic-speaker.c: Include <string.h> and <argp.h>.
+ (struct melody): New member `name'. Every melody was given a
+ name.
+ (BELL_CLASSIC, BELL_LINUX, BELL_ALARM, BELL_CMAJOR): New macros.
+ (doc, options, argp): New variables.
+ (parse_opt): New function.
+ (generic_speaker_init): Parse the arguments using argp.
+ * vga.c (doc, options, argp): New variables.
+ (parse_opt): New function.
+ (parse_startup_args): Function removed.
+ (vga_display_init): Use argp_parse instead of parse_startup_args.
+
2004-03-07 Marco Gerards <metgerards@student.han.nl>
* bdf.c (bdf_read): Change the types of has_size, has_fbbx,
diff --git a/console-client/console.c b/console-client/console.c
index 0fb3aa97..4bc9d6f4 100644
--- a/console-client/console.c
+++ b/console-client/console.c
@@ -1,5 +1,5 @@
/* console.c -- A pluggable console client.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This program is free software; you can redistribute it and/or
@@ -455,7 +455,7 @@ main (int argc, char *argv[])
driver_init ();
/* Parse our command line. This shouldn't ever return an error. */
- argp_parse (&startup_argp, argc, argv, 0, 0, 0);
+ argp_parse (&startup_argp, argc, argv, ARGP_IN_ORDER, 0, 0);
err = driver_start (&errname);
if (err)
diff --git a/console-client/driver.c b/console-client/driver.c
index 5c4630a0..15b6f185 100644
--- a/console-client/driver.c
+++ b/console-client/driver.c
@@ -1,5 +1,5 @@
/* driver.c - The console client driver code.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -99,6 +99,7 @@ error_t driver_add (const char *const name, const char *const driver,
unsigned int i;
char *dir = driver_path;
int defpath = 0;
+ char *opt_backup;
mutex_lock (&driver_list_lock);
for (i = 0; i < driver_list_len; i++)
@@ -213,8 +214,13 @@ error_t driver_add (const char *const name, const char *const driver,
return ENOMEM;
}
+ opt_backup = argv[*next - 1];
+ argv[*next - 1] = (char *) name;
/* If we will start the driver, the init function must not exit. */
- err = (*drv->ops->init) (&drv->handle, start, argc, argv, next);
+ err = (*drv->ops->init) (&drv->handle, start, argc - (*next - 1),
+ argv + *next - 1, next);
+ argv[*next - 1] = opt_backup;
+
if (!err && start && drv->ops->start)
err = (*drv->ops->start) (drv->handle);
if (err)
diff --git a/console-client/generic-speaker.c b/console-client/generic-speaker.c
index 5eaf3c5c..a28f5e12 100644
--- a/console-client/generic-speaker.c
+++ b/console-client/generic-speaker.c
@@ -1,5 +1,5 @@
/* generic-speaker.c - The simple speaker bell driver.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -20,6 +20,8 @@
#include <errno.h>
#include <sys/io.h>
+#include <string.h>
+#include <argp.h>
#include <cthreads.h>
@@ -202,31 +204,37 @@ struct note
struct melody
{
+ char *name;
int measure;
struct note *next;
struct note note[];
};
+#define BELL_CLASSIC "classic"
+#define BELL_LINUX "linux"
+#define BELL_ALARM "alarm"
+#define BELL_CMAJOR "cmajor"
+
static struct melody beep1 =
- { 160, NULL, {
+ { BELL_CLASSIC, 160, NULL, {
/* The classical bell. */
{ T_a_1, 4 }, { T_FINE, 0 }
} };
static struct melody beep2 =
- { 60, NULL, {
+ { BELL_LINUX, 60, NULL, {
/* The Linux bell. */
{ 750, 1 }, { T_FINE, 0 }
} };
static struct melody beep3 =
- { 160, NULL, {
+ { BELL_ALARM, 160, NULL, {
/* The tritonus. Quite alarming. */
{ T_f_2, 2 }, { T_b_1, 4 }, { T_FINE, 0 }
} };
static struct melody beep4 =
- { 160, NULL, {
+ { BELL_CMAJOR, 160, NULL, {
/* C-Major chord. A bit playful. */
{ T_c_2, 2 }, { T_e_2, 2 }, { T_g_2, 2 },
{ T_FINE, 0 }
@@ -237,7 +245,7 @@ static int active_beep;
#if QUAERENDO_INVENIETIS
struct melody tune1 =
- { 160, NULL, {
+ { "FSF Song", 160, NULL, {
/* The Free Software Song. Measure: 7/4. */
{ T_d_2, 16 }, { T_c_2, 8 }, { T_b_1, 16 }, { T_a_1, 16 },
{ T_b_1, 16 }, { T_c_2, 8 }, { T_b_1, 8 }, { T_a_1, 8 }, { T_g_1, 16 },
@@ -254,7 +262,7 @@ struct melody tune1 =
} };
struct melody tune2 =
- { 160, NULL, {
+ { "I Feel Pretty", 160, NULL, {
/* I feel pretty. Measure: 3/4. By Leonard Bernstein. */
{ T_c_1, 8 }, { T_e_1, 8 },
{ T_f_1, 4 }, { T_a_1, 20 },
@@ -273,7 +281,7 @@ struct melody tune2 =
} };
struct melody tune3 =
- { 120, NULL, {
+ { "Summertime", 120, NULL, {
/* Summertime. Measure: 4/4. By George & Ira Gershwin. */
{ T_b_1, 8 }, { T_g_1, 8 },
{ T_b_1, 36 }, { T_REST, 4 }, { T_a_1, 6 }, { T_g_1, 2 },
@@ -299,7 +307,7 @@ struct melody tune3 =
} };
struct melody tune4 =
- { 250, NULL, {
+ { "Indiana Jones Theme", 250, NULL, {
/* Indiana Jones Theme. Measure: 4/4. By John Williams. */
{ T_e_1, 4 }, { T_REST, 8 }, { T_f_1, 4 },
{ T_g_1, 4 }, { T_REST, 4 }, { T_c_2, 24 },
@@ -386,11 +394,71 @@ next_note (void *handle)
}
+static const char doc[] = "Generic speaker driver";
+
+static const struct argp_option options[] =
+ {
+ {"bell-style", 'b', "BELL", 0, "Use one of the bells: "
+ BELL_CLASSIC ", " BELL_LINUX ", " BELL_ALARM
+ " or " BELL_CMAJOR},
+ { 0 }
+ };
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ int *pos = (int *) state->input;
+
+ switch (key)
+ {
+ case 'b':
+ {
+ unsigned int i;
+ int found = 0;
+
+ for (i = 0; i < sizeof (*beep); i++)
+ {
+ if (! strcasecmp (beep[i]->name, arg))
+ {
+ found = 1;
+ break;
+ }
+ }
+
+ if (! found)
+ argp_usage (state);
+
+ active_beep = i;
+ break;
+ }
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ /* Save which option comes after the last accepted option. */
+ *pos = state->next;
+ return 0;
+}
+
+static struct argp argp = {options, parse_opt, 0, doc};
+
/* Initialization of the generic speaker driver. */
static error_t
generic_speaker_init (void **handle, int no_exit,
int argc, char *argv[], int *next)
{
+ error_t err;
+ int pos = 1;
+
+ /* Parse the arguments. */
+ err = argp_parse (&argp, argc, argv, ARGP_IN_ORDER | ARGP_NO_EXIT
+ | ARGP_SILENT, 0 , &pos);
+ *next += pos - 1;
+
+ if (err && err != EINVAL)
+ return err;
+
timer_clear (&generic_speaker_timer);
generic_speaker_timer.fnc = &next_note;
diff --git a/console-client/vga.c b/console-client/vga.c
index ae32049f..aecdfcdc 100644
--- a/console-client/vga.c
+++ b/console-client/vga.c
@@ -1,5 +1,5 @@
/* vga.c - The VGA device display driver.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -152,80 +152,97 @@ vga_display_flash (void *handle)
}
-/* Parse arguments at startup. */
+
+static const char doc[] = "VGA Driver";
+
+static const struct argp_option options[] =
+ {
+ {"font", 'f', "FONT", 0, "Use FONT for normal text"},
+ {"font-italic", 'i', "FONT", 0, "Use FONT for italic text"},
+ {"font-bold", 'b', "FONT", 0, "Use FONT for bold text"},
+ {"font-bold-italic",'a', "FONT", 0,
+ "Use FONT for text that is both bold and italic"},
+ {"max-colors", 'm', 0 , 0,
+ "Prefer a lot of colors above a lot of glyphs"},
+ {"max-glyphs", 'g', 0 , 0,
+ "Prefer a lot of glyphs above a lot of colors"},
+ { 0 }
+ };
+
static error_t
-parse_startup_args (int no_exit, int argc, char *argv[], int *next)
+parse_opt (int key, char *arg, struct argp_state *state)
{
-#define PARSE_FONT_OPT(x,y) \
- do { \
- if (!strcmp (argv[*next], x)) \
- { \
- (*next)++; \
- if (*next == argc) \
- { \
- if (no_exit) \
- return EINVAL; \
- else \
- error (1, 0, "option " x \
- " requires an argument"); \
- } \
- if (vga_display_##y) \
- free (vga_display_##y); \
- vga_display_##y = strdup (argv[*next]); \
- if (!vga_display_##y) \
- { \
- if (no_exit) \
- return errno; \
- else \
- error (1, errno, "malloc failed"); \
- } \
- (*next)++; \
- continue; \
- } \
- } while (0)
-
-#define PARSE_FONT_OPT_NOARGS(x,y,z) \
- { \
- if (!strcmp (argv[*next], x)) \
- { \
- (*next)++; \
- vga_display_##y = z; \
- } \
- }
-
- while (*next < argc)
+ int *pos = (int *) state->input;
+
+ switch (key)
{
- PARSE_FONT_OPT ("--font", font);
- PARSE_FONT_OPT ("--font-italic", font_italic);
- PARSE_FONT_OPT ("--font-bold", font_bold);
- PARSE_FONT_OPT ("--font-bold-italic", font_bold_italic);
- PARSE_FONT_OPT_NOARGS ("--max-colors", max_glyphs, 1);
- PARSE_FONT_OPT_NOARGS ("--max-glyphs", max_glyphs, 0);
+ case 'f':
+ vga_display_font = strdup (arg);
+ if (! vga_display_font)
+ return 0;
+ break;
+ case 'i':
+ vga_display_font_italic = strdup (arg);
+ if (! vga_display_font_italic)
+ return 0;
+ break;
+
+ case 'b':
+ vga_display_font_bold = strdup (arg);
+ if (! vga_display_font_bold)
+ return 0;
+ break;
+ case 'a':
+ vga_display_font_bold_italic = strdup (arg);
+ if (! vga_display_font_bold_italic)
+ return 0;
break;
+
+ case 'm':
+ vga_display_max_glyphs = 1;
+ break;
+
+ case 'g':
+ vga_display_max_glyphs = 0;
+ break;
+
+ case ARGP_KEY_END:
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
}
+
+ *pos = state->next;
return 0;
}
+static struct argp argp = {options, parse_opt, 0, doc};
+
/* Initialize the subsystem. */
static error_t
-vga_display_init (void **handle, int no_exit, int argc, char *argv[], int *next)
+vga_display_init (void **handle, int no_exit, int argc, char *argv[],
+ int *next)
{
error_t err;
struct vga_display *disp;
+ int pos = 1;
/* XXX Assert that we are called only once. */
mutex_init (&vga_display_lock);
timer_clear (&vga_display_timer);
vga_display_timer.fnc = &vga_display_flash_off;
-
+
/* Parse the arguments. */
- err = parse_startup_args (no_exit, argc, argv, next);
- if (err)
+ err = argp_parse (&argp, argc, argv, ARGP_IN_ORDER | ARGP_NO_EXIT
+ | ARGP_SILENT, 0, &pos);
+ *next += pos - 1;
+ if (err && err != EINVAL)
return err;
- /* Create and initialize the display srtucture as much as
+ /* Create and initialize the display structure as much as
possible. */
disp = calloc (1, sizeof *disp);
if (!disp)
@@ -339,7 +356,8 @@ vga_display_set_cursor_status (void *handle, uint32_t state)
if (!cursor_hidden)
{
if (state != CONS_CURSOR_INVISIBLE)
- dynafont_set_cursor (disp->df, state == CONS_CURSOR_VERY_VISIBLE ? 1 : 0);
+ dynafont_set_cursor (disp->df,
+ state == CONS_CURSOR_VERY_VISIBLE ? 1 : 0);
vga_display_cursor (state == CONS_CURSOR_INVISIBLE ? 0 : 1);
}