/[pkg-mixmaster]/trunk/Mix/Src/menuutil.c
ViewVC logotype

Contents of /trunk/Mix/Src/menuutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 262 - (show annotations) (download)
Wed Sep 18 23:26:17 2002 UTC (10 years, 8 months ago) by rabbi
File MIME type: text/plain
File size: 1993 byte(s)
Added closing comments for all #ifdef statements. All #endif's, as well as
nested braces, should be commented to reference their start.

We need to provide comments before every function as well.
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
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,v 1.2 2002/09/18 23:26:16 rabbi Exp $ */
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 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 #endif /* USE_NCURSES */
107 return (-1);
108 }

  ViewVC Help
Powered by ViewVC 1.1.5