| 1 |
rabbi |
710 |
/* Mixmaster version 3.0 -- (C) 1999 - 2004 Anonymizer Inc. and others.
|
| 2 |
rabbi |
1 |
|
| 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 |
weasel |
647 |
$Id$ */
|
| 10 |
rabbi |
1 |
|
| 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 |
rabbi |
262 |
#endif /* USE_NCURSES */
|
| 27 |
rabbi |
1 |
|
| 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 |
rabbi |
262 |
#endif /* USE_NCURSES */
|
| 39 |
rabbi |
1 |
}
|
| 40 |
|
|
|
| 41 |
|
|
void menu_exit(void)
|
| 42 |
|
|
{
|
| 43 |
|
|
user_delpass();
|
| 44 |
|
|
#ifdef USE_NCURSES
|
| 45 |
|
|
endwin();
|
| 46 |
rabbi |
262 |
#endif /* USE_NCURSES */
|
| 47 |
rabbi |
1 |
}
|
| 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 |
rabbi |
262 |
#endif /* USE_NCURSES */
|
| 85 |
rabbi |
1 |
|
| 86 |
|
|
int menu_getuserpass(BUFFER *b, int mode)
|
| 87 |
|
|
{
|
| 88 |
|
|
#ifdef USE_NCURSES
|
| 89 |
|
|
char p[LINELEN];
|
| 90 |
|
|
|
| 91 |
|
|
if (menu_initialized) {
|
| 92 |
|
|
cl(LINES - 1, 10);
|
| 93 |
|
|
if (mode == 0)
|
| 94 |
|
|
printw("enter passphrase: ");
|
| 95 |
|
|
else
|
| 96 |
|
|
printw("re-enter passphrase: ");
|
| 97 |
|
|
wgetnstr(stdscr, p, LINELEN);
|
| 98 |
|
|
cl(LINES - 1, 10);
|
| 99 |
|
|
refresh();
|
| 100 |
|
|
if (mode == 0)
|
| 101 |
|
|
buf_appends(b, p);
|
| 102 |
|
|
else
|
| 103 |
|
|
return (bufeq(b, p));
|
| 104 |
|
|
return (0);
|
| 105 |
|
|
}
|
| 106 |
rabbi |
262 |
#endif /* USE_NCURSES */
|
| 107 |
rabbi |
1 |
return (-1);
|
| 108 |
|
|
}
|