Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gkermit / gproto.c
blob0f1a6e07ecf8be50a3021ddfc1291c0472672f47
2 /* WARNING -- This C source program generated by gwart preprocessor. */
3 /* Do not edit this file; edit the gwart-format source file instead, */
4 /* and then run it through gwart to produce a new C source file. */
6 /* G P R O T O -- Protocol module for gkermit */ /* -*-C-*- */
8 /*
9 Author:
10 Frank da Cruz
11 The Kermit Project
12 Columbia University
13 612 West 115th Street
14 New York NY 10025-7799 USA
15 http://www.columbia.edu/kermit/
16 kermit@columbia.edu
18 Copyright (C) 1999,
19 The Trustees of Columbia University in the City of New York.
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 2 of the License, or
24 (at your option) any later version.
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <stdio.h>
36 #include "gkermit.h"
38 _MYPROTOTYPE( int closof, (void) ); /* Close output file */
39 _MYPROTOTYPE( VOID errpkt, (char *) ); /* Send Error packet */
41 extern char * xdata, *rdatap, **cmlist, *cmarg, *rpar(), strbuf[], filnam[];
42 extern int start, bctu, bctr, delay, cx, cz, failure, attributes, datalen;
43 extern int streamok, streaming, timint;
44 extern FILE * db;
46 static int x;
48 static VOID
49 streamon() { /* Start streaming if negotiated */
50 x = 0;
51 if (streamok > 0) {
52 streaming = 1;
53 timint = 0;
57 /* Declare gwart states (like lex) */
59 #define ssini 1
60 #define ssfil 2
61 #define ssdat 3
62 #define ssatt 4
63 #define sseot 5
64 #define sseof 6
65 #define sipkt 7
66 #define srini 8
67 #define srfil 9
68 #define srdat 10
69 #define sratt 11
71 /* Packets are read by the input() function, which returns the packet type */
72 /* that serves as the input to the state machine, which follows... */
75 #define BEGIN state =
77 int state = 0;
79 int
80 gwart()
82 int c,actno;
83 extern short tbl[];
84 while (1) {
85 c = input() - 32;
86 if (c < 0 || c > 95) c = 0;
87 if ((actno = tbl[c + state*96]) != -1)
88 switch(actno) {
89 case 1:
90 { /* Start state for Send. */
91 tinit(); /* Initialize transaction. */
92 if (sinit('S') < 0) { errpkt("sinit"); } /* Build and send the S packet. */
93 else BEGIN ssini;
95 break;
96 case 2:
97 { /* Receive ACK to I packet */
98 spar(rdatap); /* Set parameters from it */
99 bctu = bctr; /* Switch to negotiated block check */
100 if (gnfile() > 0) { /* Is there a file to send? */
101 if (sfile() < 0) { /* Yes, open it, send F packet, */
102 errpkt("sfile");
103 } else { /* No error */
104 streamon();
105 BEGIN ssfil;
107 } else { /* No files to send, */
108 if (seot() < 0) { errpkt("seot"); } /* so send EOT packet. */
109 else BEGIN sseot;
112 break;
113 case 3:
114 { /* Receive ACK to File header packet */
115 if (attributes) { /* If attributes negotiated */
116 if (sattr() < 0) { /* Send file attributes */
117 errpkt("sattr");
118 } else
119 BEGIN ssatt;
120 } else if ((x = sdata()) == 0) { /* Otherwise send first Data packet */
121 if (seof("") < 0) { /* Empty file - send EOF */
122 errpkt("seof");
123 } else {
124 BEGIN sseof;
126 } else if (x < 0) { /* Error */
127 errpkt("sdata");
128 } else { /* OK - switch to Data state */
129 BEGIN ssdat;
132 break;
133 case 4:
134 { /* Receive ACK to Attribute packet */
135 if (*rdatap == 'N') { /* Check for refusal */
136 seof("D");
137 BEGIN sseof;
138 } else if ((x = sdata()) == 0) { /* Otherwise send first Data packet */
139 if (seof("") < 0) { /* Empty file - send EOF */
140 errpkt("seof");
141 } else {
142 BEGIN sseof;
144 } else if (x < 0) { /* Error */
145 errpkt("sdata");
146 } else { /* OK - switch to Data state */
147 BEGIN ssdat;
150 break;
151 case 5:
152 { /* Receive ACK to Data packet */
153 if (*rdatap == 'X') /* Check for file cancellation */
154 cx = 1;
155 else if (*rdatap == 'Z') /* Check for batch cancellation */
156 cz = 1;
157 if ((x = sdata()) == 0) { /* Send data packet if data left. */
158 if (seof((cx | cz) ? "D" : "") < 0) { /* If not, send Z packet */
159 errpkt("seof");
160 } else {
161 BEGIN sseof;
163 } else if (x < 0) /* Fatal error sending data */
164 errpkt("sdata");
166 break;
167 case 6:
168 { /* Receive ACK to EOF */
169 if (gnfile() > 0) { /* Get next file from list */
170 if (sfile() > 0)
171 BEGIN ssfil;
172 else { errpkt("sfile"); }
173 } else { /* No more files */
174 seot(); /* Send EOT */
175 BEGIN sseot;
178 break;
179 case 7:
180 { return(failure); }
181 break;
182 case 8:
183 { tinit(); rinit(); BEGIN srini; }
184 break;
185 case 9:
186 { /* Receive S packet */
187 spar(rdatap); /* Set parameters from it */
188 ack1(rpar()); /* ACK with our parameters */
189 bctu = bctr; /* Switch to negotiated block check */
190 streamon();
191 BEGIN srfil; /* Wait for file or EOT */
193 break;
194 case 10:
195 { ack(); return(failure); }
196 break;
197 case 11:
198 { /* Receive File header packet */
199 if (rcvfil() < 0) {
200 errpkt("rcvfil");
201 } else {
202 encstr(filnam);
203 ack1(xdata);
204 streamon();
205 BEGIN sratt;
208 break;
209 case 12:
210 { /* Receive Attribute packet */
211 if (gattr(rdatap) == 0) {
212 ack();
213 } else {
214 ack1("\"");
217 break;
218 case 13:
219 { /* Receive first Data packet */
220 if (decode(datalen) < 0) {
221 errpkt("Packet decoding error");
222 } else {
223 ack();
224 BEGIN srdat;
227 break;
228 case 14:
229 { /* Empty file */
230 if (*rdatap == 'D') /* Check for Discard directive */
231 cx = 1;
232 if (closof() < 0) { /* Close the output file */
233 errpkt("closof");
234 } else {
235 ack(); /* Send ACK */
236 BEGIN srfil; /* Wait for another file or EOT */
239 break;
240 case 15:
241 { /* Receive Data packet */
242 if (decode(datalen) < 0)
243 errpkt("Packet decoding error");
244 else
245 ack();
247 break;
248 case 16:
249 { /* Receive EOF packet */
250 if (*rdatap == 'D') /* Check for Discard directive */
251 cx = 1;
252 if (closof() < 0) { /* Close the output file */
253 errpkt("closof");
254 } else {
255 ack(); /* Send ACK */
256 BEGIN srfil; /* Wait for another file or EOT */
259 break;
260 case 17:
261 { /* Start state for Get */
262 tinit(); /* Initialize transaction */
263 ginit(); /* Initialize Get */
264 sinit('I'); /* Send I packet */
265 BEGIN sipkt;
267 break;
268 case 18:
269 { /* Receive ACK for I packet */
270 spar(rdatap); /* Set parameters from it */
271 if (scmd('R',cmarg) < 0) /* Send GET packet file filespec */
272 errpkt("scmd");
273 else
274 BEGIN srini; /* Wait for S packet */
276 break;
277 case 19:
278 { return(failure = 1); }
279 break;
280 case 20:
281 { errpkt("Unknown packet type"); }
282 break;
288 short tbl[] = {
289 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
290 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
291 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
292 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
293 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
294 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
295 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
296 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
297 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
298 20, 20, 20, 20, 20, 20, 20, 20, 20, 2, 20, 20, 20, 20, 20, 20,
299 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
300 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
301 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
302 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
303 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
304 20, 20, 20, 20, 20, 20, 20, 20, 20, 3, 20, 20, 20, 20, 20, 20,
305 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
306 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
307 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
308 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
309 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
310 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 20, 20, 20, 20, 20, 20,
311 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
312 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
313 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
314 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
315 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
316 20, 20, 20, 20, 20, 20, 20, 20, 20, 4, 20, 20, 20, 20, 20, 20,
317 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
318 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
319 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
320 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
321 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
322 20, 20, 20, 20, 20, 20, 20, 20, 20, 7, 20, 20, 20, 20, 20, 20,
323 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
324 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
325 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
326 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
327 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
328 20, 20, 20, 20, 20, 20, 20, 20, 20, 6, 20, 20, 20, 20, 20, 20,
329 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
330 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
331 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
332 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
333 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
334 20, 20, 20, 20, 20, 20, 20, 20, 20, 18, 20, 20, 20, 20, 20, 20,
335 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
336 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
337 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
338 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
339 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
340 20, 20, 20, 9, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
341 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
342 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
343 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
344 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
345 20, 20, 10, 20, 20, 19, 11, 20, 20, 20, 20, 20, 20, 20, 20, 20,
346 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
347 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
348 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
349 -1, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
350 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
351 20, 20, 20, 20, 15, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
352 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 16, 20, 20, 20, 20, 20,
353 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
354 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20, 20,
355 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
356 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
357 20, 12, 20, 20, 13, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
358 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 14, 20, 20, 20, 20, 20,
359 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
360 20, 20, 17, 1, 20, 20, 8, 20, 20, 20, 20, 20, 20, 20, 20,20