Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sushi Changes to sushi to allow users to bind diffe...



details:   https://anonhg.NetBSD.org/src/rev/b14afdb4b0b1
branches:  trunk
changeset: 502002:b14afdb4b0b1
user:      garbled <garbled%NetBSD.org@localhost>
date:      Wed Jan 10 10:00:29 2001 +0000

description:
Changes to sushi to allow users to bind different keys to the various
built-in functions.  This allows users to change F1 to say, ^X, in the case
where a function key might not be available, or perhaps is bound to a window
manager.

problem noted by Nathan Williams

diffstat:

 usr.sbin/sushi/C.msg      |    3 +-
 usr.sbin/sushi/blabel.c   |   45 ++++++++++++++++---
 usr.sbin/sushi/scanform.c |   12 ++++-
 usr.sbin/sushi/sushi.8    |   40 ++++++++++++++--
 usr.sbin/sushi/sushi.c    |  106 ++++++++++++++++++++++++++++++++++++---------
 5 files changed, 170 insertions(+), 36 deletions(-)

diffs (truncated from 341 to 300 lines):

diff -r aa754cfab367 -r b14afdb4b0b1 usr.sbin/sushi/C.msg
--- a/usr.sbin/sushi/C.msg      Wed Jan 10 08:43:13 2001 +0000
+++ b/usr.sbin/sushi/C.msg      Wed Jan 10 10:00:29 2001 +0000
@@ -18,6 +18,8 @@
 17 select failure
 18 can't stat
 19 No menu hierchy found.
+20 Bad keybinding
+21 Bad keyword in config file
 $set 2 labels
 1 F1=Help
 2 F2=Refresh
@@ -41,7 +43,6 @@
 7 Finished
 8 Press any key to continue
 9 Use HOME,END,PGUP,PDGN,UP/DOWN Arrow keys to scroll ESC, F3 exits, F10 quits.
-10 No help is available for this screen.
 $set 4 menu titles and stuff
 1 Select choice
 2 Generating form data, please wait
diff -r aa754cfab367 -r b14afdb4b0b1 usr.sbin/sushi/blabel.c
--- a/usr.sbin/sushi/blabel.c   Wed Jan 10 08:43:13 2001 +0000
+++ b/usr.sbin/sushi/blabel.c   Wed Jan 10 10:00:29 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: blabel.c,v 1.6 2001/01/10 03:05:48 garbled Exp $       */
+/*      $NetBSD: blabel.c,v 1.7 2001/01/10 10:00:29 garbled Exp $       */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -49,6 +49,8 @@
 extern char *lang_id;
 extern CDKSCREEN *cdkscreen;
 extern char **searchpaths;
+extern char *keylabel[10];
+extern chtype keybinding[10];
 
 WINDOW *labelwin;
 
@@ -72,6 +74,11 @@
        label[8] = catgets(catalog, 2, 9, "F9=Shell");
        label[9] = catgets(catalog, 2, 10, "F10=Exit");
 
+       /* check for key overrides from the config file */
+       for (i=0; i < 10; i++)
+               if (keybinding[i] != 0)
+                       label[i] = strdup(keylabel[i]);
+
        labelwin = subwin(stdscr, 2, ws.ws_col, ws.ws_row-2, 0);
        wattron(labelwin, A_BOLD);
 
@@ -197,10 +204,34 @@
 void
 bind_menu(CDKSCROLL *scroll, char *basedir)
 {
-       bindCDKObject(vSCROLL, scroll, KEY_F1, wrap_help, basedir);
-       bindCDKObject(vSCROLL, scroll, KEY_F2, do_refresh, NULL);
-       bindCDKObject(vSCROLL, scroll, KEY_F3, do_cancel, NULL);
-       bindCDKObject(vSCROLL, scroll, KEY_F8, do_scrdump, NULL);
-       bindCDKObject(vSCROLL, scroll, KEY_F9, do_shell, NULL);
-       bindCDKObject(vSCROLL, scroll, KEY_F10, do_exit, NULL);
+       if (keybinding[0] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[0],
+                   wrap_help, basedir);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F1, wrap_help, basedir);
+
+       if (keybinding[1] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[1], do_refresh, NULL);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F2, do_refresh, NULL);
+
+       if (keybinding[2] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[2], do_cancel, NULL);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F3, do_cancel, NULL);
+
+       if (keybinding[7] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[7], do_scrdump, NULL);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F8, do_scrdump, NULL);
+
+       if (keybinding[8] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[8], do_shell, NULL);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F9, do_shell, NULL);
+
+       if (keybinding[9] != 0)
+               bindCDKObject(vSCROLL, scroll, keybinding[9], do_exit, NULL);
+       else
+               bindCDKObject(vSCROLL, scroll, KEY_F10, do_exit, NULL);
 }
diff -r aa754cfab367 -r b14afdb4b0b1 usr.sbin/sushi/scanform.c
--- a/usr.sbin/sushi/scanform.c Wed Jan 10 08:43:13 2001 +0000
+++ b/usr.sbin/sushi/scanform.c Wed Jan 10 10:00:29 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: scanform.c,v 1.4 2001/01/10 03:05:48 garbled Exp $       */
+/*      $NetBSD: scanform.c,v 1.5 2001/01/10 10:00:29 garbled Exp $       */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -68,6 +68,8 @@
 extern struct winsize ws;
 extern nl_catd catalog;
 extern char *lang_id;
+extern char *keylabel[10];
+extern chtype keybinding[10];
 
 static void scan_formindex(struct cqForm *cqf, char *row);
 
@@ -263,8 +265,16 @@
 {
        static int      mode = REQ_INS_MODE;
        int             c = wgetch(w);  /* read a character */
+       int             i;
 
        /* printf("GOT A THINGIE: 0x%x %d\n", c, c); */
+
+       /* convert to an FKEY for case */
+       if (c != 0)
+       for (i=0; i < 10; i++)
+               if (c == keybinding[i])
+                       c = KEY_F(i+1);
+
        switch (c) {
        case KEY_F(1):
                return SHOWHELP;
diff -r aa754cfab367 -r b14afdb4b0b1 usr.sbin/sushi/sushi.8
--- a/usr.sbin/sushi/sushi.8    Wed Jan 10 08:43:13 2001 +0000
+++ b/usr.sbin/sushi/sushi.8    Wed Jan 10 10:00:29 2001 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sushi.8,v 1.3 2001/01/08 21:19:31 garbled Exp $
+.\" $NetBSD: sushi.8,v 1.4 2001/01/10 10:00:29 garbled Exp $
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
@@ -90,11 +90,17 @@
 .Bl -tag -width "sushi"
 .It Pa /etc/sushi.conf
 This file is used by sushi to override the default locations searched for 
-menu hierarchies.  It consists of directory names, one per line, that 
-will be searched, in order, for menu hierarchies.  It is not an error to 
-have a non-existant directory listed in this file, as they will simply be 
-skipped over.  The default list of directories searched is printed below, 
-in order:
+menu hierarchies.  It consists of a keyword, followed by instructions.
+To override the default searchpaths in
+.Nm
+you would issue the keyword
+.Sq searchpath
+followed by a directory name, one per line, that will be searched, in order,
+for menu hierarchies.  Each directory name must be preceeded by the
+.Sq searchpath
+keyword. It is not an error to have a non-existant directory listed in
+this file, as they will simply be skipped over.  The default list of
+directories searched is printed below, in order: 
 .It Pa /usr/share/sushi
 .It Pa /usr/pkg/share/sushi
 .It Pa /usr/X11R6/share/sushi
@@ -107,6 +113,28 @@
 .Pa /etc/sushi.conf
 file will not be parsed for environment variables such as $HOME, so it 
 would likely be an error to include it there.
+.Pp
+The
+.Pa /etc/sushi.conf
+file may also include key bindings, which will override the default use
+of function keys in
+.Nm .
+These may be desired in situations where function keys are not available, or
+are not desirable because of a window-manager binding.  The format for
+binding a key is:
+.It bind F1 ^T ^T=Help
+In the above example, we have rebound the
+.Sq F1
+key to Control-T.  The final keyword is the message that will appear at the
+bottom of your screen, to remind you which keys are bound to which
+functions.  There can be no whitespace in the key description.
+The syntax of the new key binding must either be an ascii character
+preceeded by a caret
+.Dq ^
+to signify a control modifier, a function key, such as
+.Sq F9
+or a single ascii character.  It is not possible to bind Alt or Meta keys,
+nor is it possible to bind a modified function key, such as control-F1.
 .El
 .Sh EXAMPLES
 .Pp
diff -r aa754cfab367 -r b14afdb4b0b1 usr.sbin/sushi/sushi.c
--- a/usr.sbin/sushi/sushi.c    Wed Jan 10 08:43:13 2001 +0000
+++ b/usr.sbin/sushi/sushi.c    Wed Jan 10 10:00:29 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sushi.c,v 1.5 2001/01/10 03:05:48 garbled Exp $       */
+/*      $NetBSD: sushi.c,v 1.6 2001/01/10 10:00:29 garbled Exp $       */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
 MTREE_ENTRY *navigate_menu __P((struct cqMenu *, char *, char *));
 MTREE_ENTRY *navigate_submenu __P((MTREE_ENTRY *));
 MTREE_ENTRY *display_menu __P((struct cqMenu *, char *, char *));
-void prepare_searchpath __P((void));
+void parse_config __P((void));
 
 extern char *__progname;
 
@@ -71,8 +71,9 @@
 struct winsize ws;
 nl_catd                catalog;
 char           *lang_id;
-
 char           **searchpaths;
+char           *keylabel[10];
+chtype         keybinding[10];
 
 int
 main(int argc, char **argv)
@@ -87,7 +88,7 @@
        else
                lang_id = strdup(getenv("LANG"));
 
-       prepare_searchpath();
+       parse_config();
        tree_init();
        i = 0;
        for (p = searchpaths[i]; p != NULL; i++) {
@@ -129,13 +130,46 @@
        return(EXIT_SUCCESS);
 }
 
+static char *
+next_word(char **line)
+{
+       char *word, *p;
+
+       p = *line;
+       while (*++p && isspace((unsigned char)*p));
+       word = p;
+       for (; *p != '\0' && !isspace((unsigned char)*p); ++p);
+       *p = '\0';
+       *line = p;
+       return(word);
+}
+
+
+static chtype
+parse_keybinding(char *key)
+{
+       if (tolower(key[0]) == 'f' && isdigit(key[1]))
+               /* we have an F key */
+               return(KEY_F(atoi(key + 1)));
+       else if (key[0] == '^')
+               return((chtype)(toupper(key[1]) & ~0x40));
+       else if (isalpha(key[0]))
+               /* we have an insane user */
+               return((chtype)tolower(key[0]));
+
+       bailout("%s: %s", catgets(catalog, 1, 20, "Bad keybinding"), key);
+       /* NOTREACHED */
+       return(0);
+}
+
 void
-prepare_searchpath(void)
+parse_config(void)
 {
        FILE *conf;
        size_t len;
        int i, j;
-       char *p;
+       char *p, *t, *word;
+       char *key;
 
        conf = fopen("/etc/sushi.conf", "r");
        if (conf == NULL) {
@@ -158,21 +192,51 @@
                        bailout("malloc: %s", strerror(errno));
                i = 0;
                while ((p = fgetln(conf, &len))) {
-                       searchpaths = (char **)realloc(searchpaths,
-                           sizeof(char *) * (i + 2));
-                       if (searchpaths == NULL)
-                               bailout("malloc: %s", strerror(errno));
-                       searchpaths[i] = (char *)malloc(sizeof(char)
-                           * len + 1);
-                       if (searchpaths[i] == NULL)
-                               bailout("malloc: %s", strerror(errno));
-                       searchpaths[i] = strdup(p);
-                       for (j = 0; j < len; j++)
-                               if (searchpaths[i][j] == '\n' ||
-                                   searchpaths[i][j] == '\r')
-                                       searchpaths[i][j] = '\0';
-                       i++;
-               }
+                       if (len == 1 || p[len - 1] == '#' || p[len - 1] != '\n')
+                               continue;
+                       p[len - 1] = '\0';
+                       for (; *p != '\0' && isspace((unsigned char)*p); ++p);
+                       if (*p == '\0' || *p == '#')
+                               continue;
+                       for (t = p; *t && !isspace((unsigned char)*t); ++t);



Home | Main Index | Thread Index | Old Index