URI: 
       tmenuutil.c - mixmaster - mixmaster 3.0 patched for libressl
  HTML git clone git://parazyd.org/mixmaster.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
       tmenuutil.c (3088B)
       ---
            1 /* Mixmaster version 3.0  --  (C) 1999 - 2006 Anonymizer Inc. and others.
            2 
            3    Mixmaster may be redistributed and modified under certain conditions.
            4    This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
            5    ANY KIND, either express or implied. See the file COPYRIGHT for
            6    details.
            7 
            8    Menu-based user interface - utility functions
            9    $Id: menuutil.c 934 2006-06-24 13:40:39Z rabbi $ */
           10 
           11 
           12 #include "menu.h"
           13 #include <stdarg.h>
           14 #include <stdlib.h>
           15 #include <ctype.h>
           16 #include <string.h>
           17 
           18 int menu_initialized = 0;
           19 
           20 #ifdef USE_NCURSES
           21 void cl(int y, int x)
           22 {
           23   move(y, x);
           24   hline(' ', COLS - x);
           25 }
           26 #endif /* USE_NCURSES */
           27 
           28 void menu_init(void)
           29 {
           30 #ifdef USE_NCURSES
           31   initscr();
           32   cbreak();
           33   noecho();
           34   nonl();
           35   intrflush(stdscr, FALSE);
           36   keypad(stdscr, TRUE);
           37   menu_initialized = 1;
           38 #endif /* USE_NCURSES */
           39 }
           40 
           41 void menu_exit(void)
           42 {
           43   user_delpass();
           44 #ifdef USE_NCURSES
           45   endwin();
           46 #endif /* USE_NCURSES */
           47 }
           48 
           49 #ifdef USE_NCURSES
           50 void askfilename(char *path)
           51 {
           52   char line[PATHMAX];
           53 
           54   printw("\rFile name: ");
           55   echo();
           56   wgetnstr(stdscr, path, PATHMAX);
           57   noecho();
           58   printw("\r");
           59   if (path[0] == '~') {
           60     char *h;
           61 
           62     if ((h = getenv("HOME")) != NULL) {
           63       strncpy(line, h, PATHMAX);
           64       strcatn(line, "/", PATHMAX);
           65       strcatn(line, path + 1, PATHMAX);
           66       strncpy(path, line, PATHMAX);
           67     }
           68   }
           69 }
           70 
           71 void savemsg(BUFFER *message)
           72 {
           73   char savename[PATHMAX];
           74   FILE *f;
           75 
           76   askfilename(savename);
           77   f = fopen(savename, "a");
           78   if (f != NULL) {
           79     buf_write(message, f);
           80     fclose(f);
           81   }
           82 }
           83 
           84 #endif /* USE_NCURSES */
           85 
           86 void menu_spawn_editor(char *path, int lineno) {
           87 #ifdef WIN32
           88   SHELLEXECUTEINFO sei;
           89   ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
           90   sei.cbSize = sizeof(SHELLEXECUTEINFO);
           91   sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
           92   sei.hwnd = NULL;
           93   sei.lpVerb = "open";
           94   sei.lpFile = path;
           95   sei.lpParameters = NULL;
           96   sei.nShow = SW_SHOWNORMAL;
           97 
           98   if (ShellExecuteEx(&sei) == TRUE) {
           99     WaitForSingleObject(sei.hProcess, INFINITE);
          100     CloseHandle(sei.hProcess);
          101   }
          102 #else /* WIN32 */
          103   char *editor;
          104   char s[PATHMAX];
          105 
          106 /* Command line option +nn to position the cursor? */
          107 #define cursorpos (strfind(editor, "emacs") || streq(editor, "vi") || \
          108                    streq(editor, "joe"))
          109 
          110   editor = getenv("EDITOR");
          111   if (editor == NULL)
          112     editor = "vi";
          113 
          114   if (lineno > 1 && cursorpos)
          115     snprintf(s, PATHMAX, "%s +%d %s", editor, lineno, path);
          116   else
          117     snprintf(s, PATHMAX, "%s %s", editor, path);
          118 
          119 #ifdef USE_NCURSES
          120   clear();
          121   refresh();
          122   endwin();
          123 #endif /* USE_NCURSES */
          124   system(s);
          125 #ifdef USE_NCURSES
          126   refresh();
          127 #endif /* USE_NCURSES */
          128 
          129 #endif /* WIN32 */
          130 }
          131 
          132 int menu_getuserpass(BUFFER *b, int mode)
          133 {
          134 #ifdef USE_NCURSES
          135   char p[LINELEN];
          136 
          137   if (menu_initialized) {
          138     cl(LINES - 1, 10);
          139     if (mode == 0)
          140       printw("enter passphrase: ");
          141     else
          142       printw("re-enter passphrase: ");
          143     wgetnstr(stdscr, p, LINELEN);
          144     cl(LINES - 1, 10);
          145     refresh();
          146     if (mode == 0)
          147       buf_appends(b, p);
          148     else
          149       return (bufeq(b, p));
          150     return (0);
          151   }
          152 #endif /* USE_NCURSES */
          153   return (-1);
          154 }