[5258] | 1 | /* |
---|
[12439] | 2 | * $Id: sequencer.c,v 1.6 1999-02-02 20:39:51 kcr Exp $ |
---|
[5258] | 3 | * |
---|
| 4 | * Copyright (C) 1987 by the Massachusetts Institute of Technology |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #ifndef lint |
---|
[12439] | 9 | static char *rcsid_sequencer_c = "$Id: sequencer.c,v 1.6 1999-02-02 20:39:51 kcr Exp $"; |
---|
[5258] | 10 | #endif lint |
---|
| 11 | |
---|
| 12 | #include "types.h" |
---|
| 13 | #include "interface.h" |
---|
| 14 | #include "globals.h" |
---|
| 15 | #include <sys/types.h> |
---|
| 16 | #include <sys/file.h> |
---|
[12439] | 17 | #if HAVE_TERMIOS_H |
---|
| 18 | #include <termios.h> |
---|
| 19 | #else |
---|
[5258] | 20 | #include <sys/ioctl.h> |
---|
[12439] | 21 | #endif |
---|
[5258] | 22 | |
---|
[6452] | 23 | static char ss_buf[512]; |
---|
| 24 | |
---|
[5258] | 25 | static changed_meetings() |
---|
| 26 | { |
---|
| 27 | int code, n_matches, i; |
---|
| 28 | name_blk *set, *nbp; |
---|
| 29 | |
---|
| 30 | dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code); |
---|
| 31 | for (i = 0; i < n_matches; i++) { |
---|
| 32 | nbp = &set[i]; |
---|
| 33 | if (nbp->status & DSC_ST_CHANGED) { |
---|
| 34 | free(set); |
---|
| 35 | return 1; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | free(set); |
---|
| 39 | return 0; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | static unseen_transactions() |
---|
| 43 | { |
---|
| 44 | return 1; /* XXX */ |
---|
| 45 | } |
---|
| 46 | sequencer(argc, argv, ss_idx) |
---|
| 47 | int argc; |
---|
| 48 | char **argv; |
---|
| 49 | int ss_idx; |
---|
| 50 | { |
---|
| 51 | int code; |
---|
| 52 | int cmd; |
---|
[6452] | 53 | strcpy(ss_buf, "ckm"); |
---|
| 54 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
[5258] | 55 | if (code != 0) goto punt; |
---|
| 56 | |
---|
| 57 | while(changed_meetings()) { |
---|
| 58 | cmd = more_break("Hit space to go to next meeting: ", " q"); |
---|
| 59 | switch(cmd) { |
---|
| 60 | case 'q': |
---|
| 61 | return; |
---|
| 62 | |
---|
| 63 | case ' ': |
---|
| 64 | case 'n': |
---|
| 65 | break; |
---|
| 66 | } |
---|
[6452] | 67 | strcpy(ss_buf, "nm"); |
---|
| 68 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
[5258] | 69 | if (code != 0) goto punt; |
---|
| 70 | |
---|
| 71 | while (unseen_transactions()) { |
---|
| 72 | cmd = more_break("Hit space for next transaction: ", " q"); |
---|
| 73 | switch (cmd) { |
---|
| 74 | case 'q': |
---|
| 75 | return; |
---|
| 76 | case ' ': |
---|
| 77 | case 'n': |
---|
| 78 | break; |
---|
| 79 | } |
---|
[6452] | 80 | strcpy(ss_buf, "next"); |
---|
| 81 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
[5258] | 82 | if (code != 0) goto punt; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | return; |
---|
| 86 | |
---|
| 87 | punt: |
---|
| 88 | ss_perror(ss_idx, code, 0); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | * Flames to /dev/null |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | more_break(prompt, cmds) |
---|
| 96 | char *prompt; |
---|
| 97 | char *cmds; |
---|
| 98 | { |
---|
| 99 | int arg; |
---|
| 100 | char buf[1]; |
---|
[12439] | 101 | #if HAVE_TERMIOS_H |
---|
[5374] | 102 | struct termios tty, ntty; |
---|
| 103 | |
---|
| 104 | (void) tcflush(0, TCIFLUSH); |
---|
| 105 | (void) tcgetattr(0, &tty); |
---|
| 106 | ntty = tty; |
---|
| 107 | ntty.c_cc[VMIN] = 1; |
---|
| 108 | ntty.c_cc[VTIME] = 0; |
---|
| 109 | ntty.c_iflag &= ~(ICRNL); |
---|
| 110 | ntty.c_lflag &= ~(ICANON|ISIG|ECHO); |
---|
| 111 | (void) tcsetattr(0, TCSANOW, &ntty); |
---|
[12439] | 112 | #else |
---|
| 113 | struct sgttyb tty, ntty; |
---|
| 114 | |
---|
| 115 | arg = FREAD; /* Flush pending input */ |
---|
| 116 | ioctl(0, TIOCFLUSH, &arg); |
---|
| 117 | ioctl(0, TIOCGETP, &tty); /* Get parameters.. */ |
---|
| 118 | ntty = tty; |
---|
| 119 | ntty.sg_flags |= CBREAK; |
---|
| 120 | ntty.sg_flags &= ~ECHO; |
---|
| 121 | ioctl(0, TIOCSETP, &ntty); /* go to cbreak, ~echo */ |
---|
[5374] | 122 | #endif |
---|
[5258] | 123 | write(1, prompt, strlen(prompt)); |
---|
| 124 | for (;;) { |
---|
| 125 | if (read(0, buf, 1) != 1) { |
---|
| 126 | buf[0] = 'q'; |
---|
| 127 | break; |
---|
| 128 | } |
---|
[8855] | 129 | if (strchr(cmds, buf[0])) |
---|
[5258] | 130 | break; |
---|
[5374] | 131 | write(1, "\7", 1); |
---|
| 132 | } |
---|
[12439] | 133 | #if HAVE_TERMIOS_H |
---|
[5374] | 134 | (void) tcsetattr(0, TCSANOW, &tty); |
---|
| 135 | #else |
---|
[5258] | 136 | ioctl(0, TIOCSETP, &tty); |
---|
[5374] | 137 | #endif |
---|
| 138 | write(1, "\n", 1); |
---|
[5258] | 139 | return buf[0]; |
---|
| 140 | } |
---|