#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+
+#ifdef _WIN32
+#include <windows.h>
+#include <conio.h>
+#include <process.h>
+#ifdef getchar
+#undef getchar
+#endif
+#define getchar() _getch()
+#define getpid _getpid
+#endif /* _WIN32 */
RCSID("$Header$");
int Parse_words(char *buf, char *argv[], int n);
void refresh_ms(struct menu_screen *ms);
void Put_line(char *msg);
-void menu_com_err_hook(const char *who, long code, const char *fmt, ...);
+void menu_com_err_hook(const char *who, long code,
+ const char *fmt, va_list ap);
struct menu_screen *make_ms(int length);
void destroy_ms(struct menu_screen *ms);
struct menu_line *find_command_from(char *c, struct menu *m, int d);
/*
* Hook function to cause error messages to be printed through
- * curses instead of around it. Takes at most 5 args to the
- * printf string (crock...)
+ * curses instead of around it.
*/
-void menu_com_err_hook(const char *who, long code, const char *fmt, ...)
+void menu_com_err_hook(const char *who, long code, const char *fmt, va_list ap)
{
char buf[BUFSIZ], *cp;
- va_list ap;
- strcpy(buf, who);
- for (cp = buf; *cp; cp++)
- ;
- *cp++ = ':';
- *cp++ = ' ';
+ if (who)
+ {
+ strcpy(buf, who);
+ for (cp = buf; *cp; cp++)
+ ;
+ *cp++ = ':';
+ *cp++ = ' ';
+ }
+ else
+ {
+ cp = buf;
+ *cp = '\0';
+ }
if (code)
{
strcpy(cp, error_message(code));
while (*cp)
cp++;
}
- va_start(ap, fmt);
vsprintf(cp, fmt, ap);
- va_end(ap);
Put_message(buf);
}
void Start_menu(Menu *m)
{
void (*old_hook)(const char *, long, const char *, va_list) =
- set_com_err_hook((void (*) (const char *, long, const char *, va_list))menu_com_err_hook);
+ set_com_err_hook(menu_com_err_hook);
#ifdef CURSES_HAS_NEWTERM
SCREEN *scrn = newterm(NULL, stdout, stdin);
#else
{
#ifdef CURSES_HAS_NEWTERM
set_term(scrn);
+ endwin();
+ initscr();
#endif
raw(); /* We parse & print everything ourselves */
noecho();
/* Now print the title and the menu */
wclear(my_ms->ms_screen);
wrefresh(my_ms->ms_screen);
- wmove(my_ms->ms_title, 0, MAX(0, (COLS - strlen(m->m_title)) >> 1));
+ wmove(my_ms->ms_title, 0, MAX(0, (COLS - (int)strlen(m->m_title)) >> 1));
wstandout(my_ms->ms_title);
waddstr(my_ms->ms_title, m->m_title);
wstandend(my_ms->ms_title);
/* Prompt the user for input in the input window of cur_ms */
int Prompt_input(char *prompt, char *buf, int buflen)
{
+#ifdef HAVE_CURSES
int c;
char *p;
int y, x, oldx, oldy;
-#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
more_flg = 1;
/* Will be truncated to COLS characters. */
void Put_line(char *msg)
{
- int y, x, i;
- char *msg1, chr;
-
if (!more_flg)
return;
#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
+ int x, y;
+ char chr;
+
wstandout(cur_ms->ms_input);
wprintw(cur_ms->ms_input, "---More---");
wstandend(cur_ms->ms_input);
#ifdef HAVE_CURSES
if (cur_ms != NULLMS)
{
+ int i;
+ char *msg1;
+
msg1 = calloc(COLS, 1);
strncpy(msg1, msg, COLS - 1);
for (i = strlen(msg1); i < COLS - 1; i++)
return find_command_from(command, m, MAX_MENU_DEPTH);
}
+static char *get_tmp_dir(void)
+{
+#ifdef _WIN32
+ static char tmp[BUFSIZ];
+ DWORD len;
+ if (!tmp[0])
+ {
+ len = GetTempPath(sizeof(tmp), tmp);
+ if (!len || (len > sizeof(tmp)))
+ strcpy(tmp, ".");
+ }
+ return tmp;
+#else
+ return "/var/tmp";
+#endif
+}
+
int toggle_logging(int argc, char *argv[])
{
char buf[BUFSIZ];
if (!log_file)
{
- sprintf(buf, "/var/tmp/%s-log.%ld", whoami, (long)getpid());
+ sprintf(buf, "%s/%s-log.%ld", get_tmp_dir(), whoami, (long)getpid());
/* open the file */
log_file = fopen(buf, "a");