source: trunk/athena/bin/discuss/client/sequencer.c @ 8855

Revision 8855, 3.0 KB checked in by ghudson, 28 years ago (diff)
BSD -> ANSI string and memory functions
Line 
1/*
2 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/discuss/client/sequencer.c,v $
3 *      $Author: ghudson $
4 *      $Header: /afs/dev.mit.edu/source/repository/athena/bin/discuss/client/sequencer.c,v 1.4 1996-09-19 22:28:30 ghudson Exp $
5 *
6 *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
8 *      $Log: not supported by cvs2svn $
9 *      Revision 1.3  1993/03/07 06:22:02  probe
10 *      ss_execute_line should not be called with read-only strings.
11 *
12 * Revision 1.2  91/07/22  01:29:03  probe
13 * POSIX integration
14 *
15 * Revision 1.1  91/07/05  00:48:53  probe
16 * Initial revision
17 *
18 */
19
20#ifndef lint
21static char *rcsid_sequencer_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/discuss/client/sequencer.c,v 1.4 1996-09-19 22:28:30 ghudson Exp $";
22#endif lint
23
24#include "types.h"
25#include "interface.h"
26#include "globals.h"
27#include <sys/types.h>
28#include <sys/file.h>
29#include <sys/ioctl.h>
30
31static char ss_buf[512];
32
33static changed_meetings()
34{
35        int code, n_matches, i;
36        name_blk *set, *nbp;
37
38        dsc_expand_mtg_set(user_id, "*", &set, &n_matches, &code);
39        for (i = 0; i < n_matches; i++) {
40                nbp = &set[i];
41                if (nbp->status & DSC_ST_CHANGED) {
42                        free(set);
43                        return 1;
44                }
45        }
46        free(set);
47        return 0;
48}
49
50static unseen_transactions()
51{
52        return 1;               /* XXX */
53}
54sequencer(argc, argv, ss_idx)
55        int argc;
56        char **argv;
57        int ss_idx;
58{
59        int code;
60        int cmd;
61        strcpy(ss_buf, "ckm");
62        ss_execute_line(ss_idx, ss_buf, &code);
63        if (code != 0) goto punt;
64
65        while(changed_meetings()) {
66                cmd = more_break("Hit space to go to next meeting: ", " q");
67                switch(cmd) {
68                case 'q':
69                        return;
70
71                case ' ':
72                case 'n':
73                        break;
74                }
75                strcpy(ss_buf, "nm");
76                ss_execute_line(ss_idx, ss_buf, &code);
77                if (code != 0) goto punt;
78               
79                while (unseen_transactions()) {
80                        cmd = more_break("Hit space for next transaction: ", " q");
81                        switch (cmd) {
82                        case 'q':
83                                return;
84                        case ' ':
85                        case 'n':
86                                break;
87                        }
88                        strcpy(ss_buf, "next");
89                        ss_execute_line(ss_idx, ss_buf, &code);
90                        if (code != 0) goto punt;
91                }
92        }
93        return;
94
95punt:
96        ss_perror(ss_idx, code, 0);
97}
98
99/*
100 * Flames to /dev/null
101 */
102
103more_break(prompt, cmds)
104        char *prompt;
105        char *cmds;
106{
107        int arg;
108        char buf[1];
109#ifndef POSIX
110        struct sgttyb tty, ntty;
111
112        arg = FREAD;                            /* Flush pending input */
113        ioctl(0, TIOCFLUSH, &arg);
114        ioctl(0, TIOCGETP, &tty);               /* Get parameters.. */
115        ntty = tty;
116        ntty.sg_flags |= CBREAK;
117        ntty.sg_flags &= ~ECHO;
118        ioctl(0, TIOCSETP, &ntty);              /* go to cbreak, ~echo */
119#else
120        struct termios tty, ntty;
121
122        (void) tcflush(0, TCIFLUSH);
123        (void) tcgetattr(0, &tty);
124        ntty = tty;
125        ntty.c_cc[VMIN] = 1;
126        ntty.c_cc[VTIME] = 0;
127        ntty.c_iflag &= ~(ICRNL);
128        ntty.c_lflag &= ~(ICANON|ISIG|ECHO);
129        (void) tcsetattr(0, TCSANOW, &ntty);
130#endif
131        write(1, prompt, strlen(prompt));
132        for (;;)  {
133                if (read(0, buf, 1) != 1) {
134                        buf[0] = 'q';
135                        break;
136                }
137                if (strchr(cmds, buf[0]))
138                        break;
139                write(1, "\7", 1);
140        }
141#ifdef POSIX
142        (void) tcsetattr(0, TCSANOW, &tty);
143#else
144        ioctl(0, TIOCSETP, &tty);
145#endif
146        write(1, "\n", 1);
147        return buf[0];
148}
Note: See TracBrowser for help on using the repository browser.