]> andersk Git - moira.git/blobdiff - clients/moira/menu.c
Added support for DEBUG_LIBS so that when this is defined
[moira.git] / clients / moira / menu.c
index 9f375fbcb37c88ec59a1a714c172f8a3fad06fa2..89d40ed2c19cd8efe91be00c0147c4d3519747cb 100644 (file)
@@ -22,6 +22,7 @@ static char rcsid_menu_c[] = "$Header$";
 
 #endif lint
 
+#include <mit-copyright.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <signal.h>
@@ -32,6 +33,10 @@ static char rcsid_menu_c[] = "$Header$";
 #include <com_err.h>
 #include "menu.h"
 
+#ifndef __STDC__
+#define const
+#endif
+
 #define MAX(A,B)       ((A) > (B) ? (A) : (B))
 #define MIN(A,B)       ((A) < (B) ? (A) : (B))
 #define CTL(ch)                ((ch) & 037)
@@ -64,11 +69,11 @@ Menu *top_menu;                     /* Root for command search */
  * curses instead of around it.
  */
 
-int
+void
 menu_com_err_hook(who, code, fmt, args)
-    char *who;
-    int code;
-    char *fmt;
+    const char *who;
+    long code;
+    const char *fmt;
     va_list args;
 {
     char buf[BUFSIZ], *cp;
@@ -102,7 +107,11 @@ Start_menu(m)
     Menu *m;
 {
     struct menu_screen *make_ms();
-    register int (*old_hook)() = set_com_err_hook(menu_com_err_hook);
+#ifdef __STDC__
+    register void (*old_hook)(const char *, long, const char *, va_list) = set_com_err_hook(menu_com_err_hook);
+#else
+    register void (*old_hook)() = set_com_err_hook(menu_com_err_hook);
+#endif
     
     if (initscr() == ERR) {
        fputs("Can't initialize curses!\n", stderr);
@@ -111,8 +120,7 @@ Start_menu(m)
        (void) raw();           /* We parse & print everything ourselves */
        (void) noecho();
        cur_ms = make_ms(0);    /* So we always have some current */
-       /* menu_screen */ 
-       top_menu = m;
+                               /* menu_screen */ 
        /* Run the menu */
        (void) Do_menu(m, -1, (char **) NULL);
     }
@@ -136,7 +144,6 @@ Start_no_menu(m)
 {
     cur_ms = NULLMS;
     COLS = 80;
-    top_menu = m;
     /* Run the menu */
     (void) Do_menu(m, -1, (char **) NULL);
 }
@@ -198,7 +205,7 @@ Do_menu(m, margc, margv)
     int margc;
     char *margv[];
 {
-    struct menu_screen *my_ms, *old_cur_ms;
+    struct menu_screen *my_ms = NULLMS, *old_cur_ms = NULLMS;
     char argvals[MAX_ARGC][MAX_ARGLEN];        /* This is where args are stored */
     char buf[MAX_ARGC * MAX_ARGLEN];
     char *argv[MAX_ARGC];
@@ -318,7 +325,7 @@ Do_menu(m, margc, margv)
            continue;
        } 
        /* finally, try to find it using Find_command */
-       else if ((command = Find_command(argvals[0])) ==
+       else if ((command = Find_command(m, argvals[0])) ==
                 (struct menu_line *) 0) {
            Put_message("Command not recognized");
            continue;
@@ -376,7 +383,7 @@ int Prompt_input(prompt, buf, buflen)
 {
     int c;
     char *p;
-    int y, x, oldx;
+    int y, x, oldx, oldy;
 
     if (cur_ms != NULLMS) {
        more_flg = 1;
@@ -389,17 +396,17 @@ int Prompt_input(prompt, buf, buflen)
        getyx(cur_ms->ms_input, y, x);
 
        oldx = x;
+       oldy = y;
        p = buf;
        while(1) {
            (void) wmove(cur_ms->ms_input, y, x);
                (void) touchwin(cur_ms->ms_screen);
-#ifdef notdef
            (void) wclrtoeol(cur_ms->ms_input);
-#endif notdef
            refresh_ms(cur_ms);
            c = getchar() & 0x7f;
            switch (c) {
            case CTL('C'):
+               *p = '\0';
                return 0;
            case CTL('Z'):
                (void) kill(getpid(), SIGTSTP);
@@ -413,6 +420,9 @@ int Prompt_input(prompt, buf, buflen)
                refresh_ms(cur_ms);
 #endif notdef
                getyx(cur_ms->ms_input, y, x);
+               oldy = y;
+               oldx = x;
+               p = buf;
                break;
 
            case '\n':
@@ -424,19 +434,31 @@ int Prompt_input(prompt, buf, buflen)
                if (p > buf) {
                    p--;
                    x--;
+                   if (x < 0) {
+                       (void) wmove(cur_ms->ms_input, y, 0);
+                       (void) wclrtoeol(cur_ms->ms_input);
+                       y--;
+                       x = cur_ms->ms_input->_maxx-1;
+                   }
                }
                break;
            case CTL('U'):
            case CTL('G'):
            case CTL('['):
                x = oldx;
+               y = oldy;
                p = buf;
                break;
            default:
-               if (isprint(c) && (p - buf < buflen)) {
+               /* (buflen - 1) leaves room for the \0 */
+               if (isprint(c) && (p - buf < buflen - 1)) {
                    (void) waddch(cur_ms->ms_input, c);
                    *p++ = c;
                    x++;
+                   if (x >= cur_ms->ms_input->_maxx) {
+                       x = 0;
+                       y++;
+                   }
                } else
                    putchar(CTL('G'));
                break;
@@ -633,7 +655,7 @@ char *msg;
            }
            else {
                printf("---More (hit return)---");
-               getchar() & 0x7f;
+               getchar();
            }
            Start_paging();     /* Reset lines_left */
        }
@@ -708,10 +730,11 @@ find_command_from(c, m, d)
        if (!strcmp(c, m->m_lines[line].ml_command)) {
            return (&m->m_lines[line]);
        }
-       else if (m->m_lines[line].ml_submenu != NULLMENU
-                && (maybe =
-                  find_command_from(c, m->m_lines[line].ml_submenu, d - 1))
-                != (struct menu_line *) 0) {
+    }
+    for (line = 0; line < m->m_length; line++) {
+       if (m->m_lines[line].ml_submenu != NULLMENU  &&
+           (maybe = find_command_from(c, m->m_lines[line].ml_submenu, d - 1))
+               != (struct menu_line *) 0) {
            return (maybe);
        }
     }
@@ -723,14 +746,15 @@ find_command_from(c, m, d)
 /* And returns a pointer to a menu_line with the specified command name */
 /* It returns (struct menu_line *) 0 if none is found */
 struct menu_line *
-Find_command(command)
+Find_command(m, command)
+    Menu *m;
     char *command;
 {
-    if (top_menu == NULLMENU) {
+    if (m == NULLMENU) {
        return ((struct menu_line *) 0);
     }
     else {
-       return (find_command_from(command, top_menu, MAX_MENU_DEPTH));
+       return (find_command_from(command, m, MAX_MENU_DEPTH));
     }
 }
 
@@ -746,7 +770,6 @@ toggle_logging(argc, argv)
     if (log_file == (FILE *) NULL) {
        pid = getpid();
        if (!whoami) {
-           char *whoami;
            Put_message("I've lost my SENSE of DIRECTION!  I have no IDEA who I AM!");
            Put_message("My God... You've turned him into a DEMOCRAT!!");
            Put_message("               -- Doonesbury");
@@ -774,14 +797,3 @@ toggle_logging(argc, argv)
     }
     return(DM_NORMAL);
 } 
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
This page took 0.095964 seconds and 4 git commands to generate.