]> andersk Git - moira.git/blobdiff - clients/moira/menu.c
Enlarge magic constant. Fix this a better way at some point.
[moira.git] / clients / moira / menu.c
index ef5e5c1aea246fac0dd644b7090cb8904f0f168b..4c15bb0167701f3ad3cbf427140e38c874c0d9c3 100644 (file)
 #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$");
 
@@ -63,7 +76,8 @@ char **parsed_argv;           /*   comand line input */
 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);
@@ -72,29 +86,33 @@ int toggle_logging(int argc, char *argv[]);
 
 /*
  * 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);
 }
 
@@ -108,7 +126,7 @@ void menu_com_err_hook(const char *who, long code, const char *fmt, ...)
 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
@@ -123,6 +141,8 @@ void Start_menu(Menu *m)
     {
 #ifdef CURSES_HAS_NEWTERM
       set_term(scrn);
+      endwin();
+      initscr();
 #endif
       raw();           /* We parse & print everything ourselves */
       noecho();
@@ -245,7 +265,7 @@ int Do_menu(Menu *m, int margc, char *margv[])
       /* 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);
@@ -450,11 +470,11 @@ void refresh_screen(void)
 /* 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;
@@ -634,9 +654,6 @@ void Put_message(char *msg)
 /* Will be truncated to COLS characters.  */
 void Put_line(char *msg)
 {
-  int y, x, i;
-  char *msg1, chr;
-
   if (!more_flg)
     return;
 
@@ -648,6 +665,9 @@ void Put_line(char *msg)
 #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);
@@ -677,6 +697,9 @@ void Put_line(char *msg)
 #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++)
@@ -759,13 +782,30 @@ struct menu_line *Find_command(Menu *m, char *command)
     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");
This page took 0.118243 seconds and 4 git commands to generate.