1 | /* |
---|
2 | * $Id: sequencer.c,v 1.7 1999-02-08 14:46:54 danw 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.7 1999-02-08 14:46:54 danw 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 | #if HAVE_TERMIOS_H |
---|
18 | #include <termios.h> |
---|
19 | #else |
---|
20 | #include <sys/ioctl.h> |
---|
21 | #endif |
---|
22 | |
---|
23 | static char ss_buf[512]; |
---|
24 | |
---|
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; |
---|
53 | strcpy(ss_buf, "ckm"); |
---|
54 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
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 | } |
---|
67 | strcpy(ss_buf, "nm"); |
---|
68 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
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 | } |
---|
80 | strcpy(ss_buf, "next"); |
---|
81 | ss_execute_line(ss_idx, ss_buf, &code); |
---|
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]; |
---|
101 | #if HAVE_TERMIOS_H |
---|
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); |
---|
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 */ |
---|
122 | #endif |
---|
123 | write(1, prompt, strlen(prompt)); |
---|
124 | for (;;) { |
---|
125 | if (read(0, buf, 1) != 1) { |
---|
126 | buf[0] = 'q'; |
---|
127 | break; |
---|
128 | } |
---|
129 | if (strchr(cmds, buf[0])) |
---|
130 | break; |
---|
131 | write(1, "\7", 1); |
---|
132 | } |
---|
133 | #if HAVE_TERMIOS_H |
---|
134 | (void) tcsetattr(0, TCSANOW, &tty); |
---|
135 | #else |
---|
136 | ioctl(0, TIOCSETP, &tty); |
---|
137 | #endif |
---|
138 | write(1, "\n", 1); |
---|
139 | return buf[0]; |
---|
140 | } |
---|