|
|
1.1 root 1:
2: #include "uuinstall.h"
3:
4: main()
5: {
6: char choice;
7: int position; /* position of entry within file,
8: * returned by get_entry.
9: */
10:
11: umask(0177);
12: init_curses(); /* initialize our curses stuff */
13:
14:
15: do{
16: dialflag = 0; /* set our flags to a default condition */
17: sysflag = 0;
18: portflag = 0;
19:
20: prevrow = 0; /* set up our coordinates to highlite */
21: prevcol = 1; /* an entry */
22: newrow = 0;
23: newcol = 1;
24:
25: open_menu(); /* print our opening (main) menu */
26:
27: choice = get_main_opt(); /* get user's choice of file to
28: * work with or possibly exit.
29: */
30:
31: /* Here's the scoop: Now that we have a file to work with, we need to find
32: * out what to do with it... modify, add, delete or view and entry. We call
33: * get_action() to determine this. get_action() will return a -1 if we're not
34: * going to do anything. If we're going to view, delete or edit a file, we
35: * call open_config() file to open the proper file and set up our selection
36: * screen, then we call get_entry to get the entry number in the file we
37: * will work with. If we don't select an entry with get_entry(), a -1 is
38: * returned, else we display the record.
39:
40: * display_rec() does more than just display a record. From there, we delete
41: * an entry or modify and entry.
42: */
43: switch(choice){
44: case 'd': dialflag = 1; /* work with dial file */
45: action = get_action();
46: if ((action != 'a') && (action != -1)){
47: open_config_file();
48: position = get_entry();
49: if (position != -1)
50: display_rec(position,action);
51: }
52: if(action == 'a')
53: add_dial();
54: break;
55:
56: case 'p': portflag = 1; /* work with port file */
57: action = get_action();
58: if ((action != 'a') && (action != -1)){
59: open_config_file();
60: position = get_entry();
61: if (position != -1);
62: display_rec(position,action);
63: }
64: if(action == 'a')
65: add_port();
66: break;
67:
68: case 's': sysflag = 1; /* work with sys file */
69: action = get_action();
70: if ((action != 'a') && (action != -1)){
71: open_config_file();
72: position = get_entry();
73: if(position != -1)
74: display_rec(position,action);
75: }
76: if (action == 'a')
77: add_sys();
78: break;
79:
80: case 'q': exit_program(0);
81: /* NOT REACHED */
82: }
83: choice = '\0';
84: action = '\0';
85: wclear(selwin);
86: wclear(promptwin);
87: wrefresh(selwin);
88: wrefresh(promptwin);
89: }
90: while (choice != 'q');
91: }
92:
93:
94: /* initialize curses stuff: allocate new windows, set up stdscr */
95:
96: init_curses()
97: {
98:
99: /* This is the window that will be used to display and highlight
100: * file entry selections.
101: */
102: if ((selwin = newwin(20, 80, 0 ,0)) == NULL)
103: fatal("Failed to allocate selection window.");
104:
105: /* this window will be used to display prompts and some help info */
106: if((promptwin = newwin(4, 40, 20, 0)) == NULL)
107: fatal("Failed to allocate prompt window.");
108:
109: /* this window will do the data entry and display work as well as
110: * some prompting and help functions.
111: */
112: if((portwin = newwin(24, 80, 0, 0)) == NULL)
113: fatal("Failed to allocate prompt window.");
114:
115:
116: initscr();
117: raw();
118: noecho();
119:
120: if(!has_colors()){
121: use_colors = 0;
122:
123: }else{
124: use_colors = 1;
125: start_color();
126: init_pair(1,COLOR_BLUE, COLOR_WHITE);
127: wattron(stdscr,COLOR_PAIR(1));
128: }
129:
130: clear();
131: refresh();
132: }
133:
134:
135: /* exit_program: resets curses stuff and exits program. */
136:
137: exit_program(stat)
138: int stat; /* exit status passed by calling function */
139: {
140: clear();
141: refresh();
142: echo();
143: noraw();
144: exit(stat);
145: }
146:
147: /* open_menu() prints our opening screen where we display the name of
148: * the system we happen to be and prompt to examine the port, sys or
149: * dial files.
150: */
151:
152: open_menu()
153: {
154:
155: move(3,25);
156:
157: if(use_colors){
158: init_pair(1,COLOR_WHITE, COLOR_RED);
159: }else{
160: standout();
161: }
162:
163: printw("UUCP Configuration: Main menu");
164:
165: if(use_colors)
166: init_pair(1,COLOR_BLUE, COLOR_WHITE);
167: else
168: standend();
169:
170: move(SYSLINE,5);
171: printw("<s>ys file Configuration information for specific systems");
172: move(PORTLINE,5);
173: printw("<p>ort file Information for individual ports");
174: move(DIALLINE,5);
175: printw("<d>ial file Configuration information for dialing modems");
176:
177:
178: move(20,5);
179: printw("Press the letter corresponding to the file you wish to examine");
180: move(21,27);
181: printw("or <q> to quit.");
182: refresh();
183: }
184:
185:
186: /* get_main_opt(): Gets the user's choice of which file to process,
187: * which is one of the uucp config files or to exit.
188: */
189:
190: get_main_opt()
191: {
192:
193: char ch;
194:
195: ch = ' ';
196:
197: while( (ch != 'q') && (ch != 'p') && (ch != 's') && (ch != 'd')){
198: ch = getch();
199: }
200:
201: return (ch);
202: }
203:
204:
205: /* get_action(): The user will have selected a configuration file to work
206: * with by this time. This will prompt the user to perform
207: * one of the following functions: ADD an entry, REMOVE an
208: * existing entry or MODIFY an existing entry.
209: */
210:
211: get_action()
212: {
213: char ch;
214: char file[5];
215: clear();
216:
217: move(1,34);
218: standout();
219: printw("Action menu");
220: standend();
221:
222: move(5,17);
223:
224: /* determine which file we are working with from the flag(s) set and
225: * print a small message to reflect this as a cue to the user.
226: */
227:
228: if(dialflag)
229: strcpy(file,"dial");
230: if(sysflag)
231: strcpy(file,"sys");
232: if(portflag)
233: strcpy(file, "port");
234:
235: printw("You have selected to work with the %s file.",file);
236: move(7,17);
237: printw("Do you wish to:");
238: move(8,32);
239: printw("<a>dd an entry");
240: move(9,32);
241: printw("<d>elete an existing entry");
242: move(10,32);
243: printw("<m>odify an existing entry");
244: move(11,32);
245: printw("<v>iew an existing entry");
246:
247: move(15,12);
248: printw("Press the letter corresponding to the action you wish to");
249: move(16,18);
250: printw("perform or press <RETURN> for the main menu.");
251:
252: refresh();
253:
254: do{
255: ch = getch();
256: }
257: while( (ch!='\n') && (ch!='a') && (ch!='d') && (ch!='m') && (ch!='v'));
258: clear();
259: refresh();
260:
261: if (ch == '\n')
262: ch = -1;
263:
264: return (ch);
265: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.