Commit | Line | Data |
---|---|---|
69695f33 MW |
1 | |
2 | /* Copyright (c) 1995 by Arkkra Enterprises */ | |
3 | /* All rights reserved */ | |
4 | ||
5 | /* command processing function for Mup/Ghostscript display program. | |
6 | * Given a input input character, does the appropriate command */ | |
7 | ||
8 | ||
9 | /* The user interface commands are: | |
10 | * + or <space> or ^e or ^f scroll forwards 1/8" | |
11 | * - or <backsp> or ^y or ^b scroll backwards 1/8" | |
12 | * f or <enter> or ^d scroll forwards 1" | |
13 | * b or ^u scroll backwards 1" | |
14 | * h or ? help | |
15 | * m toggle between full page and scrolled mode | |
16 | * n go to top of next page | |
17 | * p go to top of previous page | |
18 | * q quit | |
19 | * r repaint current page | |
20 | * Num\n go to page Num | |
21 | * Upper case versions work too. | |
22 | * ZZ is synonym for quit | |
23 | */ | |
24 | ||
25 | #include "mupdisp.h" | |
26 | ||
27 | /* bitmap for the help screen. Have to manually make sure this is smaller | |
28 | * than the minimum screen/window size */ | |
29 | #include "help.bm" | |
30 | \f | |
31 | ||
32 | /* command processing function for Mup/Ghostscript display program. | |
33 | * Given a input input character, does the appropriate command */ | |
34 | ||
35 | void | |
36 | do_cmd(c) | |
37 | ||
38 | int c; /* character read from user */ | |
39 | ||
40 | { | |
41 | static int line = 0; /* current line on page that | |
42 | * is at top of screen */ | |
43 | static int got1z = 0; /* if got one Z for vi-like ZZ exit */ | |
44 | static int pgnum = -1; /* page number */ | |
45 | static int count = 0; /* how many times called */ | |
46 | static int lasterr = 0; /* value of count for last error */ | |
47 | static int goofs = 0; /* how many consecutive user errors */ | |
48 | ||
49 | ||
50 | /* count of times called, to implement auto-help if user goofs too | |
51 | * many times in a row */ | |
52 | count++; | |
53 | ||
54 | c = tolower(c); | |
55 | ||
56 | switch(c) { | |
57 | ||
58 | case '0': case '1': | |
59 | case '2': case '3': | |
60 | case '4': case '5': | |
61 | case '6': case '7': | |
62 | case '8': case '9': | |
63 | /* gathering page number for specific page */ | |
64 | if (pgnum < 0) { | |
65 | /* first digit, so initialize page number */ | |
66 | pgnum = 0; | |
67 | } | |
68 | pgnum = (pgnum * 10) + c - '0'; | |
69 | break; | |
70 | ||
71 | case '+': | |
72 | case ' ': | |
73 | case '\5': /* control-E for vi users */ | |
74 | case '\6': /* control-F for emacs users */ | |
75 | /* scroll forward a little bit */ | |
76 | if (Fullpgmode) { | |
77 | ( *(Conf_info_p->error) ) ("command invalid in full page mode"); | |
78 | } | |
79 | else { | |
80 | line = scroll(line, 9); | |
81 | } | |
82 | break; | |
83 | ||
84 | case '-': | |
85 | case '\b': | |
86 | case '\31': /* control-Y for vi users */ | |
87 | case '\2': /* control-B for emacs users */ | |
88 | /* backward a little bit */ | |
89 | if (Fullpgmode) { | |
90 | ( *(Conf_info_p->error) ) ("command invalid in full page mode"); | |
91 | } | |
92 | else { | |
93 | line = scroll(line, -9); | |
94 | } | |
95 | break; | |
96 | ||
97 | case '\n': | |
98 | case '\r': | |
99 | if (pgnum >= 0) { | |
100 | /* ending page number command */ | |
101 | if (getpginfo(pgnum) == YES) { | |
102 | ( *(Conf_info_p->draw) ) (0, Fullpgmode); | |
103 | line = 0; | |
104 | } | |
105 | else { | |
106 | ( *(Conf_info_p->error) ) ("invalid page number"); | |
107 | } | |
108 | pgnum = -1; | |
109 | break; | |
110 | } | |
111 | /* else fall through to moving forward on page*/ | |
112 | /*FALLTHRU*/ | |
113 | ||
114 | case 'f': | |
115 | case '\4': /* control-D */ | |
116 | case '\16': /* control-N */ | |
117 | /* forward an inch */ | |
118 | if (Fullpgmode) { | |
119 | ( *(Conf_info_p->error) ) ("command invalid in full page mode"); | |
120 | } | |
121 | else { | |
122 | line = scroll(line, 72); | |
123 | } | |
124 | break; | |
125 | ||
126 | case 'b': | |
127 | case '\25': /* control-U */ | |
128 | case '\20': /* control-P */ | |
129 | /* back an inch */ | |
130 | if (Fullpgmode) { | |
131 | ( *(Conf_info_p->error) ) ("command invalid in full page mode"); | |
132 | } | |
133 | else { | |
134 | line = scroll(line, -72); | |
135 | } | |
136 | break; | |
137 | ||
138 | case 'h': | |
139 | case '?': | |
140 | /* display help screen */ | |
141 | ( *(Conf_info_p->bitmap) ) (Help_bitmap, Help_width, Help_height); | |
142 | break; | |
143 | ||
144 | case 'n': | |
145 | /* go to next page */ | |
146 | if (Currpage_p->next != (struct Pginfo *) 0) { | |
147 | Currpage_p = Currpage_p->next; | |
148 | line = 0; | |
149 | ( *(Conf_info_p->draw) ) (line, Fullpgmode); | |
150 | } | |
151 | else { | |
152 | ( *(Conf_info_p->error) ) ("already at last page"); | |
153 | } | |
154 | break; | |
155 | ||
156 | case 'p': | |
157 | /* go to previous page */ | |
158 | if (Currpage_p->prev != (struct Pginfo *) 0) { | |
159 | Currpage_p = Currpage_p->prev; | |
160 | line = 0; | |
161 | ( *(Conf_info_p->draw) ) (line, Fullpgmode); | |
162 | } | |
163 | else { | |
164 | ( *(Conf_info_p->error) ) ("already at first page"); | |
165 | } | |
166 | break; | |
167 | ||
168 | case 'q': | |
169 | /* quit */ | |
170 | ( *(Conf_info_p->cleanup) ) (0); | |
171 | break; | |
172 | ||
173 | case 'r': | |
174 | /* repaint current screen */ | |
175 | /* if redraw is because window was resized, make sure we don't | |
176 | * run off the bottom */ | |
177 | if (line + Conf_info_p->vlines > LINES_PER_PAGE * Conf_info_p->adjust) { | |
178 | line = LINES_PER_PAGE * Conf_info_p->adjust - Conf_info_p->vlines; | |
179 | } | |
180 | ( *(Conf_info_p->draw) ) (line, Fullpgmode); | |
181 | break; | |
182 | ||
183 | case 'z': | |
184 | /* 2 Z's is symonym for quit, to match with common | |
185 | * way to exit vi */ | |
186 | if (got1z) { | |
187 | ( *(Conf_info_p->cleanup) ) (0); | |
188 | } | |
189 | break; | |
190 | ||
191 | case 'm': | |
192 | /* switch between full page and scrolled modes */ | |
193 | Fullpgmode = (Fullpgmode == YES ? NO : YES); | |
194 | line = 0; | |
195 | ( *(Conf_info_p->draw) ) (line, Fullpgmode); | |
196 | break; | |
197 | ||
198 | default: | |
199 | ( *(Conf_info_p->error) ) ("unknown command"); | |
200 | /* auto-help feature: | |
201 | * if user puts in something illegal too many times in a row, | |
202 | * figure they're confused and desperate, so give them the | |
203 | * help screen */ | |
204 | if (lasterr == count - 1) { | |
205 | goofs++; | |
206 | if (goofs > 9) { | |
207 | ( *(Conf_info_p->bitmap) ) (Help_bitmap, | |
208 | Help_width, Help_height); | |
209 | goofs = 0; | |
210 | } | |
211 | } | |
212 | else { | |
213 | goofs = 1; | |
214 | } | |
215 | lasterr = count; | |
216 | break; | |
217 | } | |
218 | ||
219 | /* set flag if got Z, so can check for Z consecutive Z's for | |
220 | * vi-style exit */ | |
221 | got1z = (c == 'Z' || c == 'z'); | |
222 | } |