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