#include "menu.h"
#include <ctype.h>
+#ifdef HAVE_CURSES
#include <curses.h>
+#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
/* Structure for holding current displayed menu */
struct menu_screen {
+#ifdef HAVE_CURSES
WINDOW *ms_screen; /* Window for this menu */
WINDOW *ms_title; /* Title subwindow */
WINDOW *ms_menu; /* Menu subwindow */
WINDOW *ms_input; /* Input subwindow */
+#endif /* HAVE_CURSES */
int ms_input_y; /* Input subwindow reference coordinate */
} *cur_ms;
+#ifndef HAVE_CURSES
+int COLS;
+#endif
+
#define NULLMS ((struct menu_screen *) 0)
Menu *top_menu; /* Root for command search */
Put_message(buf);
}
+#ifdef HAVE_CURSES
/*
* Start_menu takes a menu as an argument. It initializes curses u.s.w.,
* and a quit in any submenu should unwind back to here. (it might not,
endwin();
}
-
-/* Like Start_menu, except it doesn't print menus and doesn't use curses */
-void Start_no_menu(Menu *m)
-{
- cur_ms = NULLMS;
- COLS = 80;
- /* Run the menu */
- Do_menu(m, -1, NULL);
-}
-
/*
* Create a new menu screen template with the specified menu length
* and return it.
delwin(ms->ms_screen);
free(ms);
}
+#endif /* HAVE_CURSES */
+
+/* Like Start_menu, except it doesn't print menus and doesn't use curses */
+void Start_no_menu(Menu *m)
+{
+ cur_ms = NULLMS;
+ COLS = 80;
+ /* Run the menu */
+ Do_menu(m, -1, NULL);
+}
/*
* This guy actually puts up the menu
parsed_argc = 0;
+#ifdef HAVE_CURSES
/* The following get run only in curses mode */
if (cur_ms != NULLMS)
{
waddstr(my_ms->ms_menu, " q. (quit) Quit.");
}
else
+#endif /* HAVE_CURSES */
{
Put_message(m->m_title);
for (line = 0; line < m->m_length; line++)
{
/* This will be set by a return val from func or submenu */
quitflag = DM_NORMAL;
+#ifdef HAVE_CURSES
/* This is here because we may be coming from another menu */
if (cur_ms != NULL)
{
touchwin(my_ms->ms_screen);
wrefresh(my_ms->ms_screen);
}
+#endif /* HAVE_CURSES */
if (margc > 1)
{
/* Initialize argv */
!strcmp(argv[0], "q") || !strcmp(argv[0], "quit"))
{
/* here if it's either return or quit */
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
cur_ms = old_cur_ms;
destroy_ms(my_ms);
}
+#endif /* HAVE_CURSES */
if (m->m_exit != NULLFUNC)
m->m_exit(m);
return *argv[0] == 'r' ? DM_NORMAL : DM_QUIT;
}
if (quitflag == DM_QUIT)
{
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
cur_ms = old_cur_ms;
destroy_ms(my_ms);
}
+#endif /* HAVE_CURSES */
if (m->m_exit != NULLFUNC)
m->m_exit(m);
parsed_argc = 0;
void refresh_screen(void)
{
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
touchwin(cur_ms->ms_screen);
refresh_ms(cur_ms);
}
+#endif /* HAVE_CURSES */
}
char *p;
int y, x, oldx, oldy;
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
more_flg = 1;
wmove(cur_ms->ms_input, y, 0);
wclrtoeol(cur_ms->ms_input);
y--;
-#ifdef __NetBSD__
- x = cur_ms->ms_input->maxx - 1;
-#else
- x = cur_ms->ms_input->_maxx - 1;
-#endif
+ x = getmaxx(cur_ms->ms_input) - 1;
}
}
break;
waddch(cur_ms->ms_input, c);
*p++ = c;
x++;
-#ifdef __NetBSD__
- if (x >= cur_ms->ms_input->maxx)
-#else
- if (x >= cur_ms->ms_input->_maxx)
-#endif
+ if (x >= getmaxx(cur_ms->ms_input))
{
x = 0;
y++;
return 1;
}
else
+#endif /* HAVE_CURSES */
{
char bigbuf[BUFSIZ];
one at the top of the screen when a ---More--- prompt is displayed */
void Start_paging(void)
{
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
lines_left = LINES - cur_ms->ms_input_y - 1;
else
+#endif /* HAVE_CURSES */
lines_left = 23;
}
if (--lines_left == 0)
{
/* Give the user a more prompt */
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
wstandout(cur_ms->ms_input);
wclrtoeol(cur_ms->ms_input);
}
else
+#endif /* HAVE_CURSES */
{
printf("---More (hit return)---");
getchar();
}
}
+#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
msg1 = calloc(COLS, 1);
wprintw(cur_ms->ms_input, "%s\n", msg1);
}
else
+#endif /* HAVE_CURSES */
puts(msg);
}
+#ifdef HAVE_CURSES
/* Refresh a menu_screen onto the real screen */
void refresh_ms(struct menu_screen *ms)
{
wrefresh(ms->ms_menu);
wrefresh(ms->ms_input);
}
+#endif /* HAVE_CURSES */
/* Parse buf into a list of words, which will be placed in strings specified by
argv. Space for these strings must have already been allocated.