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