]>
Commit | Line | Data |
---|---|---|
3b3cb07f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
3b3cb07f | 6 | #ifndef lint |
7 | static char rcsid_mailmaint_c[] = "$Header$"; | |
8 | ||
9 | #endif lint | |
10 | ||
11 | /***********************************************************************/ | |
12 | /* mailmaint.c - pjlevine - 20 August 1987 | |
13 | ||
14 | */ | |
15 | /***********************************************************************/ | |
16 | #include <stdio.h> | |
17 | #include <pwd.h> | |
18 | #include <menu.h> | |
19 | #include <signal.h> | |
20 | #include <strings.h> | |
21 | #include <curses.h> | |
22 | #include </usr/include/sys/types.h> | |
23 | #include <ctype.h> | |
24 | #include "mit-copyright.h" | |
25 | ||
26 | #define STARTCOL 0 | |
27 | #define STARTROW 3 | |
28 | #define SECONDCOL 30 | |
29 | #define DISPROW 15 | |
30 | #define LISTMAX 50 | |
31 | #define LISTSIZE 32 | |
32 | #define CTL(ch) ((ch) & 037) | |
33 | #define MAX(A,B) ((A) > (B) ? (A) : (B)) | |
34 | ||
35 | static char *whoami; | |
36 | static int status; | |
37 | static void scream(); | |
38 | char *ds(); | |
39 | static int bool_answer(); | |
40 | ||
41 | typedef struct list_info { | |
42 | char *acl; | |
43 | char *desc; | |
44 | char *expdate; | |
45 | } List_info; | |
46 | ||
47 | static char *ascbuff={"0123456789"}; | |
48 | static int print_2(), print_1(); | |
49 | static List_info *current_li = (List_info *) NULL; | |
50 | static int get_list_info(); | |
51 | static int fetch_list_info(); | |
52 | ||
53 | char *malloc(); | |
54 | char *rindex(); | |
55 | char *strcpy(); | |
56 | char *getlogin(); | |
57 | char *strsave(); | |
58 | char *getenv(); | |
59 | ||
60 | typedef struct _menu { | |
61 | int num_items; | |
62 | char *title; | |
63 | char **items; | |
64 | }MENU; | |
65 | ||
66 | MENU *main_menu, *help_menu; | |
67 | ||
68 | int position[2], oldpos[2]; | |
69 | int level, found_some, currow, page, num_members; | |
70 | int moreflg, toggle, first_time; | |
71 | char *uname; | |
72 | ||
73 | ||
74 | /****************************************************/ | |
75 | main(argc, argv) | |
76 | int argc; | |
77 | char *argv[]; | |
78 | ||
79 | { | |
80 | ||
81 | int use_menu = 1; | |
82 | char buf[BUFSIZ]; | |
83 | ||
84 | init_sms_err_tbl(); | |
85 | init_krb_err_tbl(); | |
86 | ||
87 | if (getenv("TERM") == (char *) NULL) { | |
88 | printf("Please set your TERM environment variable\n"); | |
89 | goto punt; | |
90 | } | |
91 | if (getenv("TERMCAP") == (char *) NULL) { | |
92 | printf("Please set your TERMCAP environment variable\n"); | |
93 | goto punt; | |
94 | } | |
95 | if ((whoami = rindex(argv[0], '/')) == NULL) | |
96 | whoami = argv[0]; | |
97 | else | |
98 | whoami++; | |
99 | uname = (char *) calloc(20, 1); | |
100 | if ((current_li = (List_info *) malloc(sizeof(List_info))) | |
101 | == (List_info *) NULL) { | |
102 | (void) sprintf(buf, ": allocating list info"); | |
103 | goto punt; | |
104 | } else { | |
105 | current_li->acl = (char *) NULL; | |
106 | current_li->desc = (char *) NULL; | |
107 | current_li->expdate = (char *) NULL; | |
108 | } | |
109 | if ((uname = getlogin()) == NULL) { | |
110 | struct passwd *getpwuid(); | |
111 | uname = getpwuid(getuid())->pw_name; | |
112 | } | |
113 | uname = (uname && strlen(uname))? ds(uname): ""; | |
114 | ||
115 | printf("Connecting to database for %s...please hold on.\n", uname); | |
116 | ||
117 | status = sms_connect(); | |
118 | if (status) { | |
119 | (void) sprintf(buf, "\nConnection to SMS server failed"); | |
120 | goto punt; | |
121 | } | |
122 | ||
123 | status = sms_auth(); | |
124 | if (status) { | |
125 | (void) sprintf(buf, "\nAuthorization failed.\n"); | |
126 | goto punt; | |
127 | } | |
128 | ||
129 | if (use_menu) { | |
130 | initscr(); | |
131 | if ((LINES < 24) || (COLS < 60)) { | |
132 | printf("Display window too small.\n\n"); | |
133 | ||
134 | printf("Current window parameters are (%d lines, %d columns)\n", LINES, COLS); | |
135 | printf("Please resize your window\n"); | |
136 | printf("to at least 24 lines and 60 columns.\n"); | |
137 | exit(0); | |
138 | } | |
139 | raw(); | |
140 | noecho(); | |
141 | position[0] = oldpos[0] = 1; | |
142 | level = 0; | |
143 | pack_main_menu(); | |
144 | pack_help_menu(); | |
145 | display_menu(main_menu); | |
146 | get_main_input(); | |
147 | cls(); | |
148 | endwin(); | |
149 | } | |
150 | sms_disconnect(); | |
151 | exit(0); | |
152 | ||
153 | punt: | |
154 | com_err(whoami, status, buf); | |
155 | /* sms_disconnect(); */ | |
156 | exit(1); | |
157 | } | |
158 | ||
159 | /****************************************************/ | |
160 | get_main_input() | |
161 | { | |
162 | int c; | |
163 | int retflg; | |
164 | ||
165 | while(1) { | |
166 | oldpos[level] = position[level]; | |
167 | retflg = 0; | |
168 | currow = DISPROW+2; | |
169 | page = 1; | |
170 | toggle = num_members = moreflg = 0; | |
171 | c = getchar(); | |
172 | if (c == 13) { | |
173 | if (position[level] == 7) | |
174 | c = 'q'; | |
175 | else | |
176 | c = ascbuff[position[level]]; | |
177 | retflg = 1; | |
178 | } | |
179 | switch(c) { | |
180 | case 'L' & 037: /* clear screen */ | |
181 | display_menu(main_menu); | |
182 | break; | |
183 | case 'q': case 'Q': /*quit*/ | |
184 | position[level] = 7; | |
185 | highlight(main_menu); | |
186 | if (retflg) { | |
187 | cls(); | |
188 | return; | |
189 | } | |
190 | break; | |
191 | case '1': /* show all lists */ | |
192 | position[level] = 1; | |
193 | if (retflg) { | |
194 | show_all(); | |
195 | } | |
196 | break; | |
197 | case '2': /* get all members of a list */ | |
198 | position[level] = 2; | |
199 | if (retflg) { | |
200 | list_members(); | |
201 | } | |
202 | break; | |
203 | case '3': /* display list which user is a recipient */ | |
204 | position[level] = 3; | |
205 | if (retflg) { | |
206 | list_by_member(); | |
207 | } | |
208 | break; | |
209 | case '4': /* show description */ | |
210 | position[level] = 4; | |
211 | if (retflg) { | |
212 | show_list_info(); | |
213 | } | |
214 | break; | |
215 | case '5': /* add to list */ | |
216 | position[level] = 5; | |
217 | if (retflg) { | |
218 | add_member(); | |
219 | } | |
220 | break; | |
221 | case '6': /* delete */ | |
222 | position[level] = 6; | |
223 | if (retflg) { | |
224 | delete_member(); | |
225 | } | |
226 | break; | |
227 | case 27: /* up arrow */ | |
228 | c = getchar(); | |
229 | if (c == 91) { | |
230 | c = getchar(); | |
231 | if (c == 65) { | |
232 | position[level]--; | |
233 | if (!position[level]) | |
234 | position[level] = 7; | |
235 | } | |
236 | else { | |
237 | if (c == 66) { | |
238 | position[level]++; | |
239 | if (position[level] > 7) | |
240 | position[level] = 1; | |
241 | } | |
242 | } | |
243 | } | |
244 | break; | |
245 | default: | |
246 | printf("%c", 7); | |
247 | break; | |
248 | } | |
249 | highlight(main_menu); | |
250 | } | |
251 | } | |
252 | /****************************************************/ | |
253 | show_list_info() | |
254 | { | |
255 | char *argv[2]; | |
256 | char *buf; | |
257 | char c; | |
258 | ||
259 | show_text(DISPROW, STARTCOL, "Show information about a list.\n\r"); | |
260 | buf = (char *) calloc(1024, 1); | |
261 | if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) { | |
262 | printf("\n\r"); | |
263 | if (fetch_list_info(buf, current_li) == 0) { | |
264 | (void) sprintf(buf, "Description: %s\n\r", current_li->desc); | |
265 | if (strlen(buf) > 60) | |
266 | display_buff(buf); | |
267 | else | |
268 | show_text(currow, STARTCOL, buf); | |
269 | currow++; | |
270 | (void) sprintf(buf, "List Administrator: %s", current_li->acl); | |
271 | show_text(currow, STARTCOL, buf); | |
272 | currow++; | |
273 | (void) sprintf(buf, "Expiration date: %s", current_li->expdate); | |
274 | show_text(currow, STARTCOL, buf); | |
275 | currow++; | |
276 | } | |
277 | else { | |
278 | show_text(currow, STARTCOL, "madm: No such list found."); | |
279 | currow++; | |
280 | } | |
281 | show_text(currow, STARTCOL, "Press any Key to continue..."); | |
282 | c = getchar(); | |
283 | } | |
284 | clrwin(DISPROW); | |
285 | } | |
286 | /****************************************************/ | |
287 | display_buff(buf) | |
288 | char *buf; | |
289 | { | |
290 | int i, cnt; | |
291 | char *printbuf; | |
292 | int maxcol; | |
293 | ||
294 | maxcol = COLS; | |
295 | if (maxcol >= 80) | |
296 | maxcol = 80; | |
297 | ||
298 | cnt = 0; | |
299 | printbuf = (char *) calloc(maxcol, 1); | |
300 | for(i=0; i<=strlen(buf); i++) { | |
301 | printbuf[cnt] = buf[i]; | |
302 | cnt++; | |
303 | if (cnt >= maxcol) { | |
304 | start_display_buff(printbuf); | |
305 | cnt = 0; | |
306 | free(printbuf); | |
307 | printbuf = (char *) calloc(maxcol, 1); | |
308 | } | |
309 | } | |
310 | if (strlen(buf)%maxcol != 0) { | |
311 | start_display_buff(printbuf); | |
312 | free(printbuf); | |
313 | } | |
314 | return(0); | |
315 | } | |
316 | /****************************************************/ | |
317 | start_display_buff(buff) | |
318 | char *buff; | |
319 | { | |
320 | char c; | |
321 | char buffer[5]; | |
322 | ||
323 | num_members++; | |
324 | if (moreflg) | |
325 | return; | |
326 | if (currow >= LINES-2) { | |
327 | page++; | |
328 | currow++; | |
329 | mvcur(0,0,currow,STARTCOL); | |
330 | refresh(); | |
331 | if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) { | |
332 | printf("Flushing query..."); | |
333 | moreflg = 1; | |
334 | return(0); | |
335 | } | |
336 | clrwin(DISPROW+2); | |
337 | currow = DISPROW+2; | |
338 | show_text(currow, STARTCOL, "continued"); | |
339 | currow++; | |
340 | } | |
341 | show_text(currow, STARTCOL, buff); | |
342 | currow++; | |
343 | } | |
344 | /****************************************************/ | |
345 | add_member() | |
346 | { | |
347 | char *argv[3]; | |
348 | char *buf; | |
349 | char c; | |
350 | ||
351 | show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r"); | |
352 | buf = (char *) calloc(LISTMAX, 1); | |
353 | if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) { | |
354 | printf("\r\n"); | |
355 | argv[0] = strsave(buf); | |
356 | argv[1] = strsave("user"); | |
357 | argv[2] = strsave(uname); | |
358 | if (status = sms_query("add_member_to_list", 3, argv, | |
359 | scream, (char *) NULL)) { | |
360 | printf("\r\n"); | |
361 | com_err(whoami, status, " found.\n"); | |
362 | } | |
363 | else { | |
364 | sprintf(buf, "User %s added to list\r", uname); | |
365 | show_text(DISPROW+3, STARTCOL, buf); | |
366 | } | |
367 | currow = DISPROW+4; | |
368 | show_text(DISPROW+4, STARTCOL, "Press any Key to continue..."); | |
369 | c = getchar(); | |
370 | } | |
371 | clrwin(DISPROW); | |
372 | } | |
373 | ||
374 | /****************************************************/ | |
375 | delete_member() | |
376 | { | |
377 | char *argv[3]; | |
378 | char *buf; | |
379 | char c; | |
380 | ||
381 | show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r"); | |
382 | buf = (char *) calloc(LISTMAX, 1); | |
383 | if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) { | |
384 | printf("\r\n"); | |
385 | argv[0] = strsave(buf); | |
386 | argv[1] = strsave("user"); | |
387 | argv[2] = strsave(uname); | |
388 | if (status = sms_query("delete_member_from_list", 3, argv, | |
389 | scream, (char *) NULL)) { | |
390 | printf("\r\n"); | |
391 | com_err(whoami, status, " found.\n"); | |
392 | } | |
393 | else { | |
394 | sprintf(buf, "User %s deleted from list\r", uname); | |
395 | show_text(DISPROW+3, STARTCOL, buf); | |
396 | } | |
397 | currow=DISPROW+4; | |
398 | show_text(DISPROW+4, STARTCOL, "Press any Key to continue..."); | |
399 | c = getchar(); | |
400 | } | |
401 | clrwin(DISPROW); | |
402 | } | |
403 | /****************************************************/ | |
404 | list_by_member(argc, argv) | |
405 | ||
406 | { | |
407 | char *argv[3]; | |
408 | char *buf; | |
409 | char c; | |
410 | ||
411 | argv[1] = strsave("user"); | |
412 | argv[2] = strsave(uname); | |
413 | buf = (char *) calloc(BUFSIZ, 1); | |
414 | sprintf(buf, "%s is on the following lists:\r", uname); | |
415 | show_text(DISPROW, STARTCOL, buf); | |
416 | mvcur(0,0,currow, STARTCOL); | |
417 | refresh(); | |
418 | if (status = sms_query("get_lists_of_member", 2, argv+1, | |
419 | print_1, (char *) NULL)) { | |
420 | printf("\r\n"); | |
421 | com_err(whoami, status, " in get_lists_of_member"); | |
422 | } | |
423 | show_text(currow, STARTCOL, "Press any Key to continue..."); | |
424 | c = getchar(); | |
425 | clrwin(DISPROW); | |
426 | return; | |
427 | } | |
428 | /****************************************************/ | |
429 | show_all() | |
430 | { | |
431 | char c; | |
432 | ||
433 | show_text(DISPROW, STARTCOL, "This function may take a while...proceed[y]?"); | |
434 | c = getchar(); | |
435 | if (c == 'n' || c == 'N') { | |
436 | erase_line(DISPROW, STARTCOL); | |
437 | return; | |
438 | } | |
439 | move(DISPROW+1, STARTCOL); | |
440 | addstr("Processing query...please hold"); | |
441 | refresh(); | |
442 | list_all_groups(); | |
443 | } | |
444 | ||
445 | /****************************************************/ | |
446 | static int | |
447 | print_1(argc, argv, callback) | |
448 | int argc; | |
449 | char *argv[], *callback; | |
450 | { | |
451 | char buf[BUFSIZ]; | |
452 | ||
453 | /* no newline 'cause Put_message adds one */ | |
454 | (void) sprintf(buf, "%s\r", argv[0]); | |
455 | start_display(buf); | |
456 | ||
457 | return (0); | |
458 | } | |
459 | /****************************************************/ | |
460 | static int | |
461 | print_all(argc, argv, callback) | |
462 | int argc; | |
463 | char *argv[], *callback; | |
464 | { | |
465 | char buf[BUFSIZ]; | |
466 | if (moreflg) | |
467 | return; | |
468 | if (first_time) { | |
469 | erase_line(DISPROW+1, STARTCOL); | |
470 | show_text(DISPROW+1, STARTCOL, "All mailing lists:"); | |
471 | first_time = 0; | |
472 | } | |
473 | (void) sprintf(buf, "%s\r", argv[0]); | |
474 | start_display(buf); | |
475 | ||
476 | return (0); | |
477 | } | |
478 | ||
479 | /****************************************************/ | |
480 | list_all_groups() | |
481 | { | |
482 | ||
483 | first_time = 1; | |
484 | if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL, | |
485 | print_all, (char *) NULL)) { | |
486 | printf("\r\n"); | |
487 | com_err(whoami, status, " in list_all_groups\n"); | |
488 | } | |
489 | end_display(); | |
490 | ||
491 | return (DM_NORMAL); /* HA! */ | |
492 | } | |
493 | /****************************************************/ | |
494 | list_members() | |
495 | { | |
496 | char *argv[1]; | |
497 | char *buf; | |
498 | char buffer[80]; | |
499 | ||
500 | found_some = 0; | |
501 | move(DISPROW, STARTCOL); | |
502 | mvcur(0,0,DISPROW,STARTCOL); | |
503 | refresh(); | |
504 | buf = (char *) calloc(LISTMAX, 1); | |
505 | if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) { | |
506 | sprintf(buffer, "The members of list '%s' are:", buf); | |
507 | show_text(DISPROW+1, STARTCOL, buffer); | |
508 | argv[0] = buf; | |
509 | if (status = sms_query("get_members_of_list", 1, argv, | |
510 | print_2, (char *) NULL)) { | |
511 | printf("\r\n"); | |
512 | com_err(whoami, status, " found.\n"); | |
513 | currow++; | |
514 | } | |
515 | if (!found_some) { | |
516 | show_text(currow, STARTCOL,"List is empty (no members)."); | |
517 | currow++; | |
518 | } | |
519 | end_display(); | |
520 | return; | |
521 | } | |
522 | clrwin(DISPROW); | |
523 | return (DM_NORMAL); /* HA! */ | |
524 | } | |
525 | ||
526 | /****************************************************/ | |
527 | static int | |
528 | print_2(argc, argv, callback) | |
529 | int argc; | |
530 | char *argv[], *callback; | |
531 | { | |
532 | char buf[BUFSIZ]; | |
533 | ||
534 | found_some = 1; | |
535 | (void) sprintf(buf, "%s %s", argv[0], argv[1]); | |
536 | start_display(buf); | |
537 | ||
538 | return (0); | |
539 | } | |
540 | /****************************************************/ | |
541 | start_display(buff) | |
542 | char *buff; | |
543 | { | |
544 | char c; | |
545 | char *buffer; | |
546 | ||
547 | num_members++; | |
548 | if (moreflg) | |
549 | return; | |
550 | buffer = (char *) calloc(50, 1); | |
551 | if (currow >= LINES-2) { | |
552 | page++; | |
553 | currow++; | |
554 | mvcur(0,0,currow,STARTCOL); | |
555 | refresh(); | |
556 | if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) { | |
557 | printf("Flushing query..."); | |
558 | moreflg = 1; | |
559 | return(0); | |
560 | } | |
561 | clrwin(DISPROW+2); | |
562 | currow = DISPROW+2; | |
563 | sprintf(buffer, "Continued (Page %d)", page); | |
564 | show_text(currow, STARTCOL, buffer); | |
565 | currow++; | |
566 | toggle = 0; | |
567 | } | |
568 | if (!toggle) | |
569 | show_text(currow, STARTCOL, buff); | |
570 | else { | |
571 | show_text(currow, SECONDCOL, buff); | |
572 | currow++; | |
573 | } | |
574 | toggle = !toggle; | |
575 | } | |
576 | /****************************************************/ | |
577 | end_display() | |
578 | { | |
579 | char *buffer, c; | |
580 | ||
581 | if (moreflg) { | |
582 | clrwin(DISPROW); | |
583 | return; | |
584 | } | |
585 | ||
586 | buffer = (char *) calloc(50, 1); | |
587 | currow++; | |
588 | sprintf(buffer, "End of List. %d Total Members\r", num_members); | |
589 | show_text(currow, STARTCOL, buffer); | |
590 | currow++; | |
591 | show_text(currow, STARTCOL, "Press any key to continue..."); | |
592 | c = getchar(); | |
593 | clrwin(DISPROW); | |
594 | ||
595 | } | |
596 | /****************************************************/ | |
597 | display_menu(menu) | |
598 | MENU *menu; | |
599 | { | |
600 | int i; | |
601 | ||
602 | cls(); | |
603 | title(menu->title); | |
604 | mvcur(0,0,STARTROW, STARTCOL); | |
605 | refresh(); | |
606 | for(i=0; i<=menu->num_items-1; i++) { | |
607 | move(STARTROW+i, STARTCOL); | |
608 | standend(); | |
609 | addstr(menu->items[i]); | |
610 | refresh(); | |
611 | } | |
612 | center_text(STARTROW+menu->num_items+2, | |
613 | "Enter a number, <up arrow>, or <down arrow>."); | |
614 | if (!level) | |
615 | center_text(STARTROW+menu->num_items+3, | |
616 | "Press 'q' to exit, <return> to confirm choice."); | |
617 | else | |
618 | center_text(STARTROW+menu->num_items+3, | |
619 | "Press 'q' to exit, 'r' for main menu, <return> to confirm choice."); | |
620 | ||
621 | if (!level) | |
622 | highlight(main_menu); | |
623 | } | |
624 | ||
625 | /****************************************************/ | |
626 | pack_main_menu() | |
627 | { | |
628 | char *buf; | |
629 | ||
630 | main_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
631 | main_menu->num_items = 7; | |
632 | main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items); | |
633 | ||
634 | buf = (char *) calloc(50, 1); | |
635 | sprintf(buf, "Mail List Program for %s", uname); | |
636 | main_menu->title = strsave(buf); | |
637 | main_menu->items[0] = strsave("1. Show all mailing lists."); | |
638 | main_menu->items[1] = strsave("2. Get all members of a mailing list."); | |
639 | main_menu->items[2] = strsave("3. Display lists of which you are a member."); | |
640 | main_menu->items[3] = strsave("4. Show description of list."); | |
641 | main_menu->items[4] = strsave("5. Add yourself to a mailing list."); | |
642 | main_menu->items[5] = strsave("6. Delete yourself from a mailing list."); | |
643 | main_menu->items[6] = strsave("q. Quit."); | |
644 | } | |
645 | ||
646 | /****************************************************/ | |
647 | pack_help_menu() | |
648 | { | |
649 | help_menu = (MENU *) malloc((unsigned) sizeof(MENU)); | |
650 | help_menu->num_items = 5; | |
651 | help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items); | |
652 | ||
653 | help_menu->title = strsave("madm is designed as a basic mail list administration program."); | |
654 | help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like"); | |
655 | help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the"); | |
656 | help_menu->items[2] = strsave("program listmaint."); | |
657 | help_menu->items[3] = strsave(" "); | |
658 | help_menu->items[4] = strsave("Press any key to continue."); | |
659 | } | |
660 | /****************************************************/ | |
661 | func_help_menu() | |
662 | { | |
663 | int i; | |
664 | char c; | |
665 | ||
666 | show_text(currow, STARTCOL, help_menu->title); | |
667 | for(i=0;i<=help_menu->num_items-1;i++) { | |
668 | currow++; | |
669 | show_text(currow, STARTCOL, help_menu->items[i]); | |
670 | } | |
671 | c=getchar(); | |
672 | clrwin(DISPROW); | |
673 | } | |
674 | /****************************************************/ | |
675 | highlight(menu) | |
676 | MENU *menu; | |
677 | { | |
678 | ||
679 | ||
680 | if (oldpos[level] != position[level]) { | |
681 | move(STARTROW+oldpos[level]-1, STARTCOL); | |
682 | standend(); | |
683 | addstr(menu->items[oldpos[level]-1]); | |
684 | refresh(); | |
685 | } | |
686 | ||
687 | move(STARTROW+position[level]-1, STARTCOL); | |
688 | standout(); | |
689 | addstr(menu->items[position[level]-1]); | |
690 | refresh(); | |
691 | standend(); | |
692 | refresh(); | |
693 | } | |
694 | ||
695 | /****************************************************/ | |
696 | title(buff) | |
697 | char *buff; | |
698 | { | |
699 | move(0, MAX(0, (COLS - strlen(buff))>>1)); | |
700 | standout(); | |
701 | addstr(buff); | |
702 | refresh(); | |
703 | standend(); | |
704 | } | |
705 | /****************************************************/ | |
706 | rvid(row, buff) | |
707 | int row; | |
708 | char *buff; | |
709 | { | |
710 | move(row, STARTCOL); | |
711 | mvcur(0,0,row,STARTCOL); | |
712 | addstr(buff); | |
713 | standout(); | |
714 | refresh(); | |
715 | move(row, STARTCOL); | |
716 | mvcur(0,0,row,STARTCOL); | |
717 | refresh(); | |
718 | printf("%s", buff); | |
719 | standend(); | |
720 | refresh(); | |
721 | } | |
722 | ||
723 | ||
724 | /****************************************************/ | |
725 | center_text(row, buff) | |
726 | int row; | |
727 | char *buff; | |
728 | { | |
729 | move(row, MAX(0, (COLS - strlen(buff))>>1)); | |
730 | addstr(buff); | |
731 | refresh(); | |
732 | } | |
733 | ||
734 | /****************************************************/ | |
735 | show_text(row, col, buff) | |
736 | int row, col; | |
737 | char *buff; | |
738 | { | |
739 | mvcur(0,0,row,col); | |
740 | refresh(); | |
741 | printf("%s", buff); | |
742 | } | |
743 | ||
744 | /****************************************************/ | |
745 | erase_line(row, col) | |
746 | int row, col; | |
747 | { | |
748 | char *buff; | |
749 | int i; | |
750 | ||
751 | buff = (char *) calloc(COLS, 1); | |
752 | for(i=0; i<=COLS-2; i++) | |
753 | buff[i] = ' '; | |
754 | buff[i] = 0; /* just to be sure ! */ | |
755 | move(row, col); | |
756 | mvcur(0,0,row,col); | |
757 | printf("%s", buff); | |
758 | refresh(); | |
759 | } | |
760 | ||
761 | /****************************************************/ | |
762 | cls() | |
763 | { | |
764 | clear(); | |
765 | refresh(); | |
766 | } | |
767 | ||
768 | /****************************************************/ | |
769 | clrwin(erase_row) | |
770 | int erase_row; | |
771 | { | |
772 | int i; | |
773 | char *buff; | |
774 | int maxcol; | |
775 | ||
776 | maxcol = COLS; | |
777 | if (maxcol > 80) | |
778 | maxcol = 80; /* limit width */ | |
779 | ||
780 | buff = (char *) calloc(maxcol+1, 1); | |
781 | for(i=0; i<=maxcol-1; i++) | |
782 | buff[i] = ' '; | |
783 | buff[i] = 0; /* just to be sure ! */ | |
784 | mvcur(0,0,erase_row, STARTCOL); | |
785 | refresh(); | |
786 | for(i=erase_row; i<=currow-1; i++) { | |
787 | printf("%s\n\r", buff); | |
788 | } | |
789 | printf("%s", buff); | |
790 | mvcur(erase_row,STARTCOL,STARTROW+oldpos[level]-1, STARTCOL); | |
791 | refresh(); | |
792 | } | |
793 | ||
794 | /****************************************************/ | |
795 | char *strsave(s) | |
796 | char *s; | |
797 | { | |
798 | char *p; | |
799 | ||
800 | if ((p = (char *) calloc(1, strlen(s)+1)) != NULL) { | |
801 | strcpy(p, s); | |
802 | } | |
803 | else | |
804 | printf("error in alloc\n\r"); | |
805 | return(p); | |
806 | } | |
807 | /****************************************************/ | |
808 | /* jean's routine ??? */ | |
809 | static void scream() | |
810 | { | |
811 | com_err(whoami, status, "\nAn SMS update returned a value -- programmer \ | |
812 | botch\n"); | |
813 | sms_disconnect(); | |
814 | exit(1); | |
815 | } | |
816 | /****************************************************/ | |
817 | static int fetch_list_info(list, li) | |
818 | char *list; | |
819 | List_info *li; | |
820 | { | |
821 | char *argv[1]; | |
822 | ||
823 | argv[0] = list; | |
824 | if ((status = sms_query("get_list_info", 1, argv, | |
825 | get_list_info, (char *) NULL)) == 0) { | |
826 | return status; | |
827 | } | |
828 | else { | |
829 | com_err(whoami, status, " found.\n"); | |
830 | return status; | |
831 | } | |
832 | } | |
833 | ||
834 | /* ARGSUSED */ | |
835 | static int get_list_info(argc, argv) | |
836 | int argc; | |
837 | char **argv; | |
838 | { | |
839 | ||
840 | if (current_li->acl) | |
841 | free(current_li->acl); | |
842 | current_li->acl = strsave(argv[2]); | |
843 | if (current_li->desc) | |
844 | free(current_li->desc); | |
845 | current_li->desc = strsave(argv[3]); | |
846 | if (current_li->expdate) | |
847 | free(current_li->expdate); | |
848 | current_li->expdate = strsave(argv[4]); | |
849 | return (0); | |
850 | } | |
851 | ||
852 | ||
853 | ||
854 | ||
855 | /****************************************************/ | |
856 | /* Prompt the user for input */ | |
857 | int Prompt(prompt, buf, buflen) | |
858 | char *prompt; | |
859 | char *buf; | |
860 | int buflen; | |
861 | { | |
862 | int c; | |
863 | char *p; | |
864 | int y, x, oldx; | |
865 | ||
866 | printf("%s", prompt); | |
867 | refresh(); | |
868 | for (p = buf; abs(strlen(p)-strlen(buf)) <= buflen;) { | |
869 | refresh(); | |
870 | c = getchar(); | |
871 | switch (c) { | |
872 | case CTL('C'): | |
873 | return 0; | |
874 | case CTL('Z'): | |
875 | return 0; | |
876 | case CTL('L'): | |
877 | cls(); | |
878 | display_menu(main_menu); | |
879 | return 0; | |
880 | case '\n': | |
881 | case '\r': | |
882 | printf("\r"); | |
883 | *p = '\0'; | |
884 | if (strlen(buf) < 1) /* only /n or /r in buff */ | |
885 | return -1; | |
886 | else | |
887 | return 1; | |
888 | case '\b': | |
889 | case '\177': | |
890 | if (p > buf) { | |
891 | p--; | |
892 | x--; | |
893 | printf("\b"); | |
894 | printf(" "); | |
895 | printf("\b"); | |
896 | } | |
897 | break; | |
898 | case CTL('U'): | |
899 | case CTL('G'): | |
900 | case CTL('['): | |
901 | x = oldx; | |
902 | p = buf; | |
903 | break; | |
904 | default: | |
905 | if (abs(strlen(p)-strlen(buf)) >= buflen) { | |
906 | printf("%c", 7); | |
907 | break; | |
908 | } | |
909 | if (isprint(c)) { | |
910 | (void) addch(c); | |
911 | *p++ = c; | |
912 | x++; | |
913 | } else | |
914 | putchar(CTL('G')); | |
915 | break; | |
916 | } | |
917 | } | |
918 | } | |
919 | ||
920 | /* | |
921 | * duplicate string | |
922 | */ | |
923 | char *ds(str) | |
924 | char *str; | |
925 | { | |
926 | register char *newstr = malloc((unsigned) strlen(str) + 1); | |
927 | ||
928 | if (newstr == (char *) NULL) | |
929 | return ((char *) NULL); | |
930 | else | |
931 | return (strcpy(newstr, str)); | |
932 | } | |
933 | ||
934 | int bool_query(name, argc, argv) | |
935 | char *name; | |
936 | int argc; | |
937 | char *argv[]; | |
938 | { | |
939 | int result = 0; | |
940 | sms_query(name, argc, argv, bool_answer, (caddr_t) &result); | |
941 | return result; | |
942 | } | |
943 | ||
944 | static int bool_answer(argc, argv, arg) | |
945 | int argc; | |
946 | char *argv[]; | |
947 | caddr_t arg; | |
948 | { | |
949 | int *result = (int *) arg; | |
950 | if (strcmp(argv[0], "true") == 0) | |
951 | *result = 1; | |
952 | else if (strcmp(argv[0], "false") == 0) | |
953 | *result = 0; | |
954 | return; | |
955 | } | |
956 | ||
957 | /* | |
958 | * Local Variables: | |
959 | * mode: c | |
960 | * c-indent-level: 4 | |
961 | * c-continued-statement-offset: 4 | |
962 | * c-brace-offset: -4 | |
963 | * c-argdecl-indent: 4 | |
964 | * c-label-offset: -4 | |
965 | * End: | |
966 | */ |