Debian Codegraph @

ifcico/zmmisc.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* ### Modified on Thu 4 Jan 1996 ###
2 * - added #ifdef RZSZ3_40 code from T.Tanaka
3 */
4
5 /*
6 * Z M . C
7 * ZMODEM protocol primitives
8 * 05-24-89 Chuck Forsberg Omen Technology Inc
9 *
10 * Entry point Functions:
11 * zsbhdr(type, hdr) send binary header
12 * zshhdr(type, hdr) send hex header
13 * zgethdr(hdr, eflag) receive header - binary or hex
14 * zsdata(buf, len, frameend) send data
15 * zrdata(buf, len) receive data
16 * stohdr(pos) store position data in Txhdr
17 * long rclhdr(hdr) recover position offset from header
18 *
19 *
20 * This version implements numerous enhancements including ZMODEM
21 * Run Length Encoding and variable length headers. These
22 * features were not funded by the original Telenet development
23 * contract.
24 *
25 * This software may be freely used for non commercial and
26 * educational (didactic only) purposes. This software may also
27 * be freely used to support file transfer operations to or from
28 * licensed Omen Technology products. Any programs which use
29 * part or all of this software must be provided in source form
30 * with this notice intact except by written permission from Omen
31 * Technology Incorporated.
32 *
33 * Use of this software for commercial or administrative purposes
34 * except when exclusively limited to interfacing Omen Technology
35 * products requires a per port license payment of $20.00 US per
36 * port (less in quantity). Use of this code by inclusion,
37 * decompilation, reverse engineering or any other means
38 * constitutes agreement to these conditions and acceptance of
39 * liability to license the materials and payment of reasonable
40 * legal costs necessary to enforce this license agreement.
41 *
42 *
43 * Omen Technology Inc FAX: 503-621-3745
44 * Post Office Box 4681
45 * Portland OR 97208
46 *
47 * This code is made available in the hope it will be useful,
48 * BUT WITHOUT ANY WARRANTY OF ANY KIND OR LIABILITY FOR ANY
49 * DAMAGES OF ANY KIND.
50 *
51 */
52
53 static void zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(int);
54 static void zsbh32cxx . . $ zsbh32(5dcb74ec448a895d).(int,char*,int,int);
55 static void zsda32cxx . . $ zsda32(dcbbfe1ffd04514b).(char*,int,int);
56 static int zrdat32cxx . . $ zrdat32(6abd07ddb1a912f0).(char*,int);
57 static int noxrd7cxx . . $ noxrd7(b126dc7c1de90089).(void);
58 static int zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(char*);
59 static int zrbhdrcxx . . $ zrbhdr(1ef8e6ec083aabb9).(char*);
60 static int zrhhdrcxx . . $ zrhhdr(1ef8e6ec083aabb9).(char*);
61 static int zgethexcxx . . $ zgethex(b126dc7c1de90089).(void);
62 static int zgeth1cxx . . $ zgeth1(b126dc7c1de90089).(void);
63 static void garbitchcxx . . $ garbitch(49f6e7a06ebc5aa8).(void);
64
65 #include <stdio.h>
66 #include "xutil.h"cxx . . $ `<file>/iflib/xutil.h`/
67 #include "lutil.h"cxx . . $ `<file>/iflib/lutil.h`/
68 #include "ttyio.h"cxx . . $ `<file>/ifcico/ttyio.h`/
69 #include "zmodem.h"cxx . . $ `<file>/ifcico/zmodem.h`/
70 static int Rxtimeoutcxx . . $ Rxtimeout. = 20; /* Tenths of seconds to wait for something */
71 int Zctlesccxx . . $ Zctlesc.;
72
73 /* Globals used by ZMODEM functions */
74 int Rxframeindcxx . . $ Rxframeind.; /* ZBIN ZBIN32, or ZHEX type of frame */
75 int Rxtypecxx . . $ Rxtype.; /* Type of header received */
76 int Rxhlencxx . . $ Rxhlen.; /* Length of header received */
77 int Rxcountcxx . . $ Rxcount.; /* Count of data bytes received */
78 char Rxhdrcxx . . $ Rxhdr.[ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!]; /* Received header */
79 char Txhdrcxx . . $ Txhdr.[ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!]; /* Transmitted header */
80 long Rxposcxx . . $ Rxpos.; /* Received file position */
81 long Txposcxx . . $ Txpos.; /* Transmitted file position */
82 int Txfcs32cxx . . $ Txfcs32.; /* TURE means send binary frames with 32 bit FCS */
83 int Crc32tcxx . . $ Crc32t.; /* Controls 32 bit CRC being sent */
84 /* 1 == CRC32, 2 == CRC32 + RLE */
85 int Crc32rcxx . . $ Crc32r.; /* Indicates/controls 32 bit CRC being received */
86 /* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */
87 int Usevhdrscxx . . $ Usevhdrs.; /* Use variable length headers */
88 int Znullscxx . . $ Znulls.; /* Number of nulls to send at beginning of ZDATA hdr */
89 char Attncxx . . $ Attn.[ZATTNLENcxx . . $ `ifcico/zmodem.h:102:9`!+1]; /* Attention string rx sends to tx on err */
90 char *Altcancxx . . $ Altcan.; /* Alternate canit string */
91
92 char *txbufcxx . . $ txbuf.=NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
93 char *rxbufcxx . . $ rxbuf.=NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
94
•95 static int lastsentcxx . . $ lastsent.; /* Last char we sent */
96 static int Not8bitcxx . . $ Not8bit.; /* Seven bits seen on header */
97
98 char *frametypescxx . . $ frametypes.[] = {
99 "EMPTY", /* -16 */
100 "Can't be (-15)",
101 "Can't be (-14)",
102 "Can't be (-13)",
103 "Can't be (-12)",
104 "Can't be (-11)",
105 "Can't be (-10)",
106 "Can't be (-9)",
107 "HANGUP", /* -8 */
108 "Can't be (-7)",
109 "Can't be (-6)",
110 "Can't be (-5)",
111 "EOFILE", /* -4 */
112 "Can't be (-3)",
113 "TIMEOUT", /* -2 */
114 "ERROR", /* -1 */
115 "ZRQINIT",
116 "ZRINIT",
117 "ZSINIT",
118 "ZACK",
119 "ZFILE",
120 "ZSKIP",
121 "ZNAK",
122 "ZABORT",
123 "ZFIN",
124 "ZRPOS",
125 "ZDATA",
126 "ZEOF",
127 "ZFERR",
128 "ZCRC",
129 "ZCHALLENGE",
130 "ZCOMPL",
131 "ZCAN",
132 "ZFREECNT",
133 "ZCOMMAND",
134 "ZSTDERR",
135 "xxxxx"
136 #define FRTYPEScxx . . $ `ifcico/zmmisc.c:136:9`! 22 /* Total number of frame types in this array */
137 /* not including psuedo negative entries */
138 };
139
140 static char badcrccxx . . $ badcrc.[] = "Bad CRC";
141
142 /**** I am including this fix as a temporary solution... Gonna got the
143 entire zmodem rewritten some day. = E.C.
144 ****/
145
146 /***** Hack by mj ***********************************************************/
147 /*
148 * Buffer for outgoing frames. Sending them with single character write()'s
149 * is a waste of processor time and causes severe performance degradation
150 * on TCP and ISDN connections.
151 */
152 #define FRAME_BUFFER_SIZEcxx . . $ `ifcico/zmmisc.c:152:9`! 16384
153 static char *frame_buffercxx . . $ frame_buffer.=NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
154 static int frame_lengthcxx . . $ frame_length. = 0;
155
156 #define BUFFER_CLEARcxx . . $ `ifcico/zmmisc.c:156:9`!() do { frame_length=0; } while(0)
157 #define BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(c) do { frame_buffer[frame_length++]=(c); } while(0)
158 #define BUFFER_FLUSHcxx . . $ `ifcico/zmmisc.c:158:9`!() do { PUTcxx . . $ `ifcico/ttyio.h:16:9`!(frame_buffer, frame_length); \
159 frame_length=0; } while(0);
160 /****************************************************************************/
161
162 void get_frame_buffercxx . . $ get_frame_buffer(49f6e7a06ebc5aa8).(void)
163 {
164 if (frame_buffercxx . . $ frame_buffer. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) frame_buffercxx . . $ frame_buffer.=xmalloccxx . . $ xmalloc(f109d7e0a0ca42b3).(FRAME_BUFFER_SIZEcxx . . $ `ifcico/zmmisc.c:152:9`!);
165 }
166
167 /* Send ZMODEM binary header hdr of type type */
168 void zsbhdrcxx . . $ zsbhdr(1839e3b9b1397d59).(len, type, hdr)
169 int len,type;
170 register char *hdr;
171 {
172 register int n;
173 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
174
175 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zsbhdr: %c %d %s %lx", Usevhdrscxx . . $ Usevhdrs.?'v':'f', len,
176 frametypescxx . . $ frametypes.[type+FTOFFSETcxx . . $ `ifcico/zmodem.h:168:9`!], rclhdrcxx . . $ rclhdr(2ebcc2597f7e891d).(hdr));
177
178 BUFFER_CLEARcxx . . $ `ifcico/zmmisc.c:156:9`!();
179
180 if (type == ZDATAcxx . . $ `ifcico/zmodem.h:50:9`!)
181 for (n = Znullscxx . . $ Znulls.; --n >=0; )
182 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(0);
183
184 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZPADcxx . . $ `ifcico/zmodem.h:24:9`!); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!);
185
186 switch (Crc32tcxx . . $ Crc32t.=Txfcs32cxx . . $ Txfcs32.) {
187 case 1:
188 zsbh32cxx . . $ zsbh32(5dcb74ec448a895d).(len, hdr, type, Usevhdrscxx . . $ Usevhdrs.?ZVBIN32cxx . . $ `ifcico/zmodem.h:33:9`!:ZBIN32cxx . . $ `ifcico/zmodem.h:29:9`!); break;
189 case 2:
190 zsbh32cxx . . $ zsbh32(5dcb74ec448a895d).(len, hdr, type, Usevhdrscxx . . $ Usevhdrs.?ZVBINR32cxx . . $ `ifcico/zmodem.h:34:9`!:ZBINR32cxx . . $ `ifcico/zmodem.h:30:9`!);
191 BUFFER_FLUSHcxx . . $ `ifcico/zmmisc.c:158:9`!(); break; /* 19960304 T.Tanaka, from rzsz 3.41 */
192 default:
193 if (Usevhdrscxx . . $ Usevhdrs.) {
194 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZVBINcxx . . $ `ifcico/zmodem.h:31:9`!);
195 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(len);
196 }
197 else
198 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZBINcxx . . $ `ifcico/zmodem.h:27:9`!);
199 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(type);
200 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(type, 0);
201
202 for (n=len; --n >= 0; ++hdr) {
203 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(*hdr);
204 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!((0377& *hdr), crc);
205 }
206 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,crc));
207 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(crc>>8);
208 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(crc);
209 }
210
211 BUFFER_FLUSHcxx . . $ `ifcico/zmmisc.c:158:9`!();
212 }
213
214
215 /* Send ZMODEM binary header hdr of type type */
216 void zsbh32cxx . . $ zsbh32(5dcb74ec448a895d).(len, hdr, type, flavour)
217 int len;
218 register char *hdr;
219 int type,flavour;
220 {
221 register int n;
222 register INT32cxx . . $ `<built-in>:451:9`! crc;
223
224 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(flavour);
225 if (Usevhdrscxx . . $ Usevhdrs.)
226 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(len);
227 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(type);
228 crc = 0xFFFFFFFFL; crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(type, crc);
229
230 for (n=len; --n >= 0; ++hdr) {
231 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!((0377 & *hdr), crc);
232 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(*hdr);
233 }
234 crc = ~crc;
235 for (n=4; --n >= 0;) {
236 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).((int)crc);
237 crc >>= 8;
238 }
239 }
240
241 /* Send ZMODEM HEX header hdr of type type */
242 void zshhdrcxx . . $ zshhdr(1839e3b9b1397d59).(len, type, hdr)
243 int len,type;
244 register char *hdr;
245 {
246 register int n;
247 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
248
249 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zshhdr: %c %d %s %lx", Usevhdrscxx . . $ Usevhdrs.?'v':'f', len,
250 frametypescxx . . $ frametypes.[type+FTOFFSETcxx . . $ `ifcico/zmodem.h:168:9`!], rclhdrcxx . . $ rclhdr(2ebcc2597f7e891d).(hdr));
251
252
253 BUFFER_CLEARcxx . . $ `ifcico/zmmisc.c:156:9`!();
254
255 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZPADcxx . . $ `ifcico/zmodem.h:24:9`!); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZPADcxx . . $ `ifcico/zmodem.h:24:9`!); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!);
256 if (Usevhdrscxx . . $ Usevhdrs.) {
257 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZVHEXcxx . . $ `ifcico/zmodem.h:32:9`!);
258 zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(len);
259 }
260 else
261 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZHEXcxx . . $ `ifcico/zmodem.h:28:9`!);
262 zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(type);
263 Crc32tcxx . . $ Crc32t. = 0;
264
265 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(type, 0);
266 for (n=len; --n >= 0; ++hdr) {
267 zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(*hdr); crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!((0377 & *hdr), crc);
268 }
269 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,crc));
270 zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(crc>>8); zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(crc);
271
272 /* Make it printable on remote machine */
273 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(015); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(0212);
274 /*
275 * Uncork the remote in case a fake XOFF has stopped data flow
276 */
277 if (type != ZFINcxx . . $ `ifcico/zmodem.h:48:9`! && type != ZACKcxx . . $ `ifcico/zmodem.h:43:9`!)
278 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(021);
279
280 BUFFER_FLUSHcxx . . $ `ifcico/zmmisc.c:158:9`!();
281 }
282
283 /*
284 * Send binary array buf of length length, with ending ZDLE sequence frameend
285 */
286 char *Zendnamescxx . . $ Zendnames.[] = { "ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW"};
287 void zsdatacxx . . $ zsdata(dcbbfe1ffd04514b).(buf, length, frameend)
288 register char *buf;
289 int length,frameend;
290 {
291 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
292
293 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zsdata: %d %s", length, Zendnamescxx . . $ Zendnames.[(frameend-ZCRCEcxx . . $ `ifcico/zmodem.h:62:9`!)&3]);
294
295
296 BUFFER_CLEARcxx . . $ `ifcico/zmmisc.c:156:9`!();
297
298 switch (Crc32tcxx . . $ Crc32t.) {
299 case 1:
300 zsda32cxx . . $ zsda32(dcbbfe1ffd04514b).(buf, length, frameend); break;
301 case 2:
302 zsdar32cxx . . $ zsdar32(dcbbfe1ffd04514b).(buf, length, frameend); break;
303 /* ### 19960304 T.Tanaka, IPAD hack */
304 default:
305 crc = 0;
306 for (;--length >= 0; ++buf) {
307 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(*buf); crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!((0377 & *buf), crc);
308 }
309 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(frameend);
310 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(frameend, crc);
311
312 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(0,crc));
313 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(crc>>8); zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(crc);
314 }
315 if (frameend == ZCRCWcxx . . $ `ifcico/zmodem.h:65:9`!)
316 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(DC1cxx . . $ `ifcico/ttyio.h:58:9`!);
317
318 BUFFER_FLUSHcxx . . $ `ifcico/zmmisc.c:158:9`!();
319 }
320
321 void zsda32cxx . . $ zsda32(dcbbfe1ffd04514b).(buf, length, frameend)
322 register char *buf;
323 int length,frameend;
324 {
325 register int c;
326 /*###*/ register unsigned INT32cxx . . $ `<built-in>:451:9`! crc;
327
328 crc = 0xFFFFFFFFL;
329 for (;--length >= 0; ++buf) {
330 c = *buf & 0377;
331 if (c & 0140)
332 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(lastsent = c);
333 else
334 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(c);
335 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
336 }
337 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!); BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(frameend);
338 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(frameend, crc);
339
340 crc = ~crc;
341 for (c=4; --c >= 0;) {
342 zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).((int)crc); crc >>= 8;
343 }
344 }
345
346 /*
347 * Receive array buf of max length with ending ZDLE sequence
348 * and CRC. Returns the ending character or error code.
349 * NB: On errors may store length+1 bytes!
350 */
351 int zrdatacxx . . $ zrdata(6abd07ddb1a912f0).(buf, length)
352 register char *buf;
353 int length;
354 {
355 register int c;
356 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
357 register char *end;
358 register int d;
359
360 switch (Crc32rcxx . . $ Crc32r.) {
361 case 1:
362 return zrdat32cxx . . $ zrdat32(6abd07ddb1a912f0).(buf, length);
363 case 2:
364 return zrdatr32cxx . . $ zrdatr32(6abd07ddb1a912f0).(buf, length);
365 /* ### 19960304 T.Tanaka, IPAD hack */
366 }
367
368 crc = Rxcountcxx . . $ Rxcount. = 0; end = buf + length;
369 while (buf <= end) {
370 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377) {
371 crcfoo:
372 switch (c) {
373 case GOTCRCEcxx . . $ `ifcico/zmodem.h:72:9`!:
374 case GOTCRCGcxx . . $ `ifcico/zmodem.h:73:9`!:
375 case GOTCRCQcxx . . $ `ifcico/zmodem.h:74:9`!:
376 case GOTCRCWcxx . . $ `ifcico/zmodem.h:75:9`!:
377 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!((((d=c))&0377), crc);
378 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
379 goto crcfoo;
380 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
381 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
382 goto crcfoo;
383 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
384 if (crc & 0xFFFF) {
385 loginfcxx . . $ loginf(d5d9ff45db7b5d36).(badcrccxx . . $ badcrc.);
386 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
387 }
388 Rxcountcxx . . $ Rxcount. = length - (end - buf);
389
390 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zrdata: %d %s", Rxcountcxx . . $ Rxcount.,
391 Zendnamescxx . . $ Zendnames.[(d-GOTCRCEcxx . . $ `ifcico/zmodem.h:72:9`!)&3]);
392
393 return d;
394 case GOTCANcxx . . $ `ifcico/zmodem.h:76:9`!:
395 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Sender Canceled");
396 return ZCANcxx . . $ `ifcico/zmodem.h:56:9`!;
397 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
398 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("TIMEOUT receiving data");
399 return c;
400 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
401 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Carrier lost while receiving");
402 return c;
403 default:
404 garbitchcxx . . $ garbitch(49f6e7a06ebc5aa8).(); return c;
405 }
406 }
407 *buf++ = c;
408 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
409 }
410 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Data subpacket too long");
411 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
412 }
413
414 int zrdat32cxx . . $ zrdat32(6abd07ddb1a912f0).(buf, length)
415 register char *buf;
416 int length;
417 {
418 register int c;
419 /*###*/ register unsigned INT32cxx . . $ `<built-in>:451:9`! crc;
420 register char *end;
421 register int d;
422
423 crc = 0xFFFFFFFFL; Rxcountcxx . . $ Rxcount. = 0; end = buf + length;
424 while (buf <= end) {
425 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377) {
426 crcfoo:
427 switch (c) {
428 case GOTCRCEcxx . . $ `ifcico/zmodem.h:72:9`!:
429 case GOTCRCGcxx . . $ `ifcico/zmodem.h:73:9`!:
430 case GOTCRCQcxx . . $ `ifcico/zmodem.h:74:9`!:
431 case GOTCRCWcxx . . $ `ifcico/zmodem.h:75:9`!:
432 d = c; c &= 0377;
433 /*loginf("zrdat32:c=%d,crc=%X.",c,crc);*/
434 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
435 /*loginf("zrdat32:c=%d,crc=%X..",c,crc);*/
436 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
437 goto crcfoo;
438 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
439 /*loginf("zrdat32:c=%d,crc=%X...",c,crc);*/
440 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
441 goto crcfoo;
442 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
443 /*loginf("zrdat32:c=%d,crc=%X....",c,crc);*/
444 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
445 goto crcfoo;
446 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
447 /*loginf("zrdat32:c=%d,crc=%X.....",c,crc);*/
448 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
449 goto crcfoo;
450 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
451 /*loginf("zrdat32:c=%d,crc=%X......",c,crc);*/
452 if (crc != 0xDEBB20E3) {
453 loginfcxx . . $ loginf(d5d9ff45db7b5d36).(badcrccxx . . $ badcrc.);
454 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
455 }
456 Rxcountcxx . . $ Rxcount. = length - (end - buf);
457
458 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zrdat32: %d %s", Rxcountcxx . . $ Rxcount.,
459 Zendnamescxx . . $ Zendnames.[(d-GOTCRCEcxx . . $ `ifcico/zmodem.h:72:9`!)&3]);
460
461 return d;
462 case GOTCANcxx . . $ `ifcico/zmodem.h:76:9`!:
463 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Sender Canceled");
464 return ZCANcxx . . $ `ifcico/zmodem.h:56:9`!;
465 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
466 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("TIMEOUT");
467 return c;
468 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
469 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Carrier lost while receiving");
470 return c;
471 default:
472 garbitchcxx . . $ garbitch(49f6e7a06ebc5aa8).(); return c;
473 }
474 }
475 *buf++ = c;
476 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
477 }
478 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Data subpacket too long");
479 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
480 }
481
482 void garbitchcxx . . $ garbitch(49f6e7a06ebc5aa8).(void)
483 {
484 loginfcxx . . $ loginf(d5d9ff45db7b5d36).("Garbled data subpacket");
485 }
486
487 /*
488 * Read a ZMODEM header to hdr, either binary or hex.
489 * eflag controls local display of non zmodem characters:
490 * 0: no display
491 * 1: display printing characters only
492 * 2: display all non ZMODEM characters
493 *
494 * Set Rxhlen to size of header (default 4) (valid iff good hdr)
495 * On success, set Zmodem to 1, set Rxpos and return type of header.
496 * Otherwise return negative on error.
497 * Return ERROR instantly if ZCRCW sequence, for fast error recovery.
498 */
499 int zgethdrcxx . . $ zgethdr(6abd07ddb1a912f0).(hdr, eflag)
500 char *hdr;
501 int eflag;
502 {
503 register int c, n, cancount, tmcount;
504
505 #ifdef RZSZ3_40
506 int Zrwindow = 1024;
507 int Baudrate = 2400;
508 n = Zrwindow + Baudrate;
509 #endif
510 Rxframeindcxx . . $ Rxframeind. = Rxtypecxx . . $ Rxtype. = 0;
511
512 startover:
513 cancount = 5;
514 tmcount = 5;
515 again:
516 /* Return immediate ERROR if ZCRCW sequence seen */
517 if (((c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0) && (c != TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!))
518 goto fifi;
519 else switch (c) {
520 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
521 if (--tmcount <= 0) {
522 c = ERRORcxx . . $ `ifcico/ttyio.h:32:9`!; goto fifi;
523 }
524 goto startover;
525 case 021: case 0221:
526 goto again;
527 case CANcxx . . $ `ifcico/ttyio.h:65:9`!:
528 gotcan:
529 if (--cancount <= 0) {
530 c = ZCANcxx . . $ `ifcico/zmodem.h:56:9`!; goto fifi;
531 }
532 switch (c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(1)) {
533 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
534 goto again;
535 case ZCRCWcxx . . $ `ifcico/zmodem.h:65:9`!:
536 switch (GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(1)) {
537 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
538 c = ERRORcxx . . $ `ifcico/ttyio.h:32:9`!; goto fifi;
539 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
540 goto fifi;
541 default:
542 goto agn2;
543 }
544 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
545 goto fifi;
546 default:
547 break;
548 case CANcxx . . $ `ifcico/ttyio.h:65:9`!:
549 if (--cancount <= 0) {
550 c = ZCANcxx . . $ `ifcico/zmodem.h:56:9`!; goto fifi;
551 }
552 goto again;
553 }
554 /* **** FALL THRU TO **** */
555 default:
556 agn2:
557 #ifdef RZSZ3_40
558 #define GCOUNT (-4)
559 if ( --n == 0) {
560 c = GCOUNT; goto fifi;
561 }
562 #endif
563 goto startover;
564 case ZPADcxx . . $ `ifcico/zmodem.h:24:9`!|0200: /* This is what we want. */
565 Not8bitcxx . . $ Not8bit. = c;
566 case ZPADcxx . . $ `ifcico/zmodem.h:24:9`!: /* This is what we want. */
567 break;
568 }
569 cancount = 5;
570 splat:
571 switch (c = noxrd7cxx . . $ noxrd7(b126dc7c1de90089).()) {
572 case ZPADcxx . . $ `ifcico/zmodem.h:24:9`!:
573 goto splat;
574 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
575 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
576 goto fifi;
577 default:
578 goto agn2;
579 case ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!: /* This is what we want. */
580 break;
581 }
582
583
584 Rxhlencxx . . $ Rxhlen. = 4; /* Set default length */
585 Rxframeindcxx . . $ Rxframeind. = c = noxrd7cxx . . $ noxrd7(b126dc7c1de90089).();
586 switch (c) {
587 case ZVBIN32cxx . . $ `ifcico/zmodem.h:33:9`!:
588 if ((Rxhlencxx . . $ Rxhlen. = c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) < 0)
589 goto fifi;
590 if (c > ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!)
591 goto agn2;
592 Crc32rcxx . . $ Crc32r. = 1; c = zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(hdr); break;
593 case ZBIN32cxx . . $ `ifcico/zmodem.h:29:9`!:
594 if (Usevhdrscxx . . $ Usevhdrs.)
595 goto agn2;
596 Crc32rcxx . . $ Crc32r. = 1; c = zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(hdr); break;
597 case ZVBINR32cxx . . $ `ifcico/zmodem.h:34:9`!:
598 if ((Rxhlencxx . . $ Rxhlen. = c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) < 0)
599 goto fifi;
600 if (c > ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!)
601 goto agn2;
602 Crc32rcxx . . $ Crc32r. = 2; c = zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(hdr); break;
603 case ZBINR32cxx . . $ `ifcico/zmodem.h:30:9`!:
604 if (Usevhdrscxx . . $ Usevhdrs.)
605 goto agn2;
606 Crc32rcxx . . $ Crc32r. = 2; c = zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(hdr); break;
607 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
608 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
609 goto fifi;
610 case ZVBINcxx . . $ `ifcico/zmodem.h:31:9`!:
611 if ((Rxhlencxx . . $ Rxhlen. = c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) < 0)
612 goto fifi;
613 if (c > ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!)
614 goto agn2;
615 Crc32rcxx . . $ Crc32r. = 0; c = zrbhdrcxx . . $ zrbhdr(1ef8e6ec083aabb9).(hdr); break;
616 case ZBINcxx . . $ `ifcico/zmodem.h:27:9`!:
617 if (Usevhdrscxx . . $ Usevhdrs.)
618 goto agn2;
619 Crc32rcxx . . $ Crc32r. = 0; c = zrbhdrcxx . . $ zrbhdr(1ef8e6ec083aabb9).(hdr); break;
620 case ZVHEXcxx . . $ `ifcico/zmodem.h:32:9`!:
621 if ((Rxhlencxx . . $ Rxhlen. = c = zgethexcxx . . $ zgethex(b126dc7c1de90089).()) < 0)
622 goto fifi;
623 if (c > ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!)
624 goto agn2;
625 Crc32rcxx . . $ Crc32r. = 0; c = zrhhdrcxx . . $ zrhhdr(1ef8e6ec083aabb9).(hdr); break;
626 case ZHEXcxx . . $ `ifcico/zmodem.h:28:9`!:
627 if (Usevhdrscxx . . $ Usevhdrs.)
628 goto agn2;
629 Crc32rcxx . . $ Crc32r. = 0; c = zrhhdrcxx . . $ zrhhdr(1ef8e6ec083aabb9).(hdr); break;
630 case CANcxx . . $ `ifcico/ttyio.h:65:9`!:
631 goto gotcan;
632 default:
633 goto agn2;
634 }
635 for (n = Rxhlencxx . . $ Rxhlen.; ++n < ZMAXHLENcxx . . $ `ifcico/zmodem.h:36:9`!; ) /* Clear unused hdr bytes */
636 hdr[n] = 0;
637 Rxposcxx . . $ Rxpos. = hdr[ZP3cxx . . $ `ifcico/zmodem.h:86:9`!] & 0377;
638 Rxposcxx . . $ Rxpos. = (Rxposcxx . . $ Rxpos.<<8) + (hdr[ZP2cxx . . $ `ifcico/zmodem.h:85:9`!] & 0377);
639 Rxposcxx . . $ Rxpos. = (Rxposcxx . . $ Rxpos.<<8) + (hdr[ZP1cxx . . $ `ifcico/zmodem.h:84:9`!] & 0377);
640 Rxposcxx . . $ Rxpos. = (Rxposcxx . . $ Rxpos.<<8) + (hdr[ZP0cxx . . $ `ifcico/zmodem.h:83:9`!] & 0377);
641 fifi:
642 switch (c) {
643 case GOTCANcxx . . $ `ifcico/zmodem.h:76:9`!:
644 c = ZCANcxx . . $ `ifcico/zmodem.h:56:9`!;
645 /* **** FALL THRU TO **** */
646 case ZNAKcxx . . $ `ifcico/zmodem.h:46:9`!:
647 case ZCANcxx . . $ `ifcico/zmodem.h:56:9`!:
648 case ERRORcxx . . $ `ifcico/ttyio.h:32:9`!:
649 case TIMEOUTcxx . . $ `ifcico/ttyio.h:33:9`!:
650 case HANGUPcxx . . $ `ifcico/ttyio.h:35:9`!:
651 default:
652 if (c >= -FTOFFSETcxx . . $ `ifcico/zmodem.h:168:9`! && c <= FRTYPEScxx . . $ `ifcico/zmmisc.c:136:9`!)
653 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zgethdr: %c %d %s %lx", Rxframeindcxx . . $ Rxframeind., Rxhlencxx . . $ Rxhlen.,
654 frametypescxx . . $ frametypes.[c+FTOFFSETcxx . . $ `ifcico/zmodem.h:168:9`!], Rxposcxx . . $ Rxpos.);
655 else
656 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zgethdr: %c %d %lx", Rxframeindcxx . . $ Rxframeind., c, Rxposcxx . . $ Rxpos.);
657 }
658 /* Use variable length headers if we got one */
659 if (c >= 0 && c <= FRTYPEScxx . . $ `ifcico/zmmisc.c:136:9`! && Rxframeindcxx . . $ Rxframeind. & 040)
660 Usevhdrscxx . . $ Usevhdrs. = 1;
661 return c;
662 }
663
664 /* Receive a binary style header (type and position) */
665 int zrbhdrcxx . . $ zrbhdr(1ef8e6ec083aabb9).(hdr)
666 register char *hdr;
667 {
668 register int c, n;
669 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
670
671 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
672 return c;
673 Rxtypecxx . . $ Rxtype. = c;
674 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, 0);
675
676 for (n=Rxhlencxx . . $ Rxhlen.; --n >= 0; ++hdr) {
677 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
678 return c;
679 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
680 *hdr = c;
681 }
682 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
683 return c;
684 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
685 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
686 return c;
687 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
688 if (crc & 0xFFFF) {
689 loginfcxx . . $ loginf(d5d9ff45db7b5d36).(badcrccxx . . $ badcrc.);
690 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
691 }
692 return Rxtypecxx . . $ Rxtype.;
693 }
694
695 /* Receive a binary style header (type and position) with 32 bit FCS */
696 int zrbhd32cxx . . $ zrbhd32(1ef8e6ec083aabb9).(hdr)
697 register char *hdr;
698 {
699 register int c, n;
700 /*###*/ register unsigned INT32cxx . . $ `<built-in>:451:9`! crc;
701
702 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
703 return c;
704 Rxtypecxx . . $ Rxtype. = c;
705 crc = 0xFFFFFFFFL; crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
706
707 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zrbhd32 c=%X crc=%lX", c, crc);
708
709 for (n=Rxhlencxx . . $ Rxhlen.; --n >= 0; ++hdr) {
710 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
711 return c;
712 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
713 *hdr = c;
714
715 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zrbhd32 c=%X crc=%lX", c, crc);
716 }
717 for (n=4; --n >= 0;) {
718 if ((c = zdlreadcxx . . $ zdlread(b126dc7c1de90089).()) & ~0377)
719 return c;
720 crc = updcrc32cxx . . $ `ifcico/zmodem.h:188:9`!(c, crc);
721
722 debugcxx . . $ debug(2bb28f3347a46b85).(11,"zrbhd32 c=%X crc=%lX", c, crc);
723 }
724 if (crc != 0xDEBB20E3) {
725 loginfcxx . . $ loginf(d5d9ff45db7b5d36).(badcrccxx . . $ badcrc.);
726 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
727 }
728 return Rxtypecxx . . $ Rxtype.;
729 }
730
731
732 /* Receive a hex style header (type and position) */
733 int zrhhdrcxx . . $ zrhhdr(1ef8e6ec083aabb9).(hdr)
734 char *hdr;
735 {
736 register int c;
737 register unsigned INT16cxx . . $ `<built-in>:452:9`! crc;
738 register int n;
739
740 if ((c = zgethexcxx . . $ zgethex(b126dc7c1de90089).()) < 0)
741 return c;
742 Rxtypecxx . . $ Rxtype. = c;
743 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, 0);
744
745 for (n=Rxhlencxx . . $ Rxhlen.; --n >= 0; ++hdr) {
746 if ((c = zgethexcxx . . $ zgethex(b126dc7c1de90089).()) < 0)
747 return c;
748 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
749 *hdr = c;
750 }
751 if ((c = zgethexcxx . . $ zgethex(b126dc7c1de90089).()) < 0)
752 return c;
753 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
754 if ((c = zgethexcxx . . $ zgethex(b126dc7c1de90089).()) < 0)
755 return c;
756 crc = updcrc16cxx . . $ `ifcico/zmodem.h:184:9`!(c, crc);
757 if (crc & 0xFFFF) {
758 loginfcxx . . $ loginf(d5d9ff45db7b5d36).(badcrccxx . . $ badcrc.); return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
759 }
760 switch ( c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(2)) {
761 case 0215:
762 Not8bitcxx . . $ Not8bit. = c;
763 /* **** FALL THRU TO **** */
764 case 015:
765 /* Throw away possible cr/lf */
766 switch (c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(2)) {
767 case 012:
768 Not8bitcxx . . $ Not8bit. |= c;
769 }
770 }
771 if (c < 0)
772 return c;
773 return Rxtypecxx . . $ Rxtype.;
774 }
775
776 /* Send a byte as two hex digits */
777 void zputhexcxx . . $ zputhex(d4f767463ce0a6b3).(c)
778 register int c;
779 {
780 static char digits[] = "0123456789abcdef";
781
782 debugcxx . . $ debug(2bb28f3347a46b85).(19,"zputhex: %02X", c & 0xff); /* 19960303 T.Tanaka */
783
784 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(digits[(c&0xF0)>>4]);
785 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(digits[(c)&0xF]);
786 }
787
788 /*
789 * Send character c with ZMODEM escape sequence encoding.
790 * Escape XON, XOFF. Escape CR following @ (Telenet net escape)
791 */
792 void zsendlinecxx . . $ zsendline(d4f767463ce0a6b3).(c)
793 int c;
794 {
795
796 /* Quick check for non control characters */
797 if (c & 0140)
798 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(lastsent = c);
799 else {
800 switch (c &= 0377) {
801 case ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!:
802 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!);
803 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`! (lastsent = (c ^= 0100));
804 break;
805 case 015:
806 case 0215:
807 if (!Zctlesccxx . . $ Zctlesc. && (lastsentcxx . . $ lastsent. & 0177) != '@')
808 goto sendit;
809 /* **** FALL THRU TO **** */
810 case 020:
811 case 021:
812 case 023:
813 case 0220:
814 case 0221:
815 case 0223:
816 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!);
817 c ^= 0100;
818 sendit:
819 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(lastsent = c);
820 break;
821 default:
822 if (Zctlesccxx . . $ Zctlesc. && ! (c & 0140)) {
823 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!);
824 c ^= 0100;
825 }
826 BUFFER_BYTEcxx . . $ `ifcico/zmmisc.c:157:9`!(lastsent = c);
827 }
828 }
829 }
830
831 /* Decode two lower case hex digits into an 8 bit byte value */
832 int zgethexcxx . . $ zgethex(b126dc7c1de90089).(void)
833 {
834 register int c;
835
836 c = zgeth1cxx . . $ zgeth1(b126dc7c1de90089).();
837 debugcxx . . $ debug(2bb28f3347a46b85).(19,"zgethex: %02X", c);
838 return c;
839 }
840 int zgeth1cxx . . $ zgeth1(b126dc7c1de90089).(void)
841 {
842 register int c, n;
843
844 if ((c = noxrd7cxx . . $ noxrd7(b126dc7c1de90089).()) < 0)
845 return c;
846 n = c - '0';
847 if (n > 9)
848 n -= ('a' - ':');
849 if (n & ~0xF)
850 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
851 if ((c = noxrd7cxx . . $ noxrd7(b126dc7c1de90089).()) < 0)
852 return c;
853 c -= '0';
854 if (c > 9)
855 c -= ('a' - ':');
856 if (c & ~0xF)
857 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
858 c += (n<<4);
859 return c;
860 }
861
862 /*
863 * Read a byte, checking for ZMODEM escape encoding
864 * including CAN*5 which represents a quick abort
865 */
866 int zdlreadcxx . . $ zdlread(b126dc7c1de90089).(void)
867 {
868 register int c;
869
870 again:
871 /* Quick check for non control characters */
872 if ((c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) & 0140)
873 return c;
874 switch (c) {
875 case ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!:
876 break;
877 case 023:
878 case 0223:
879 case 021:
880 case 0221:
881 goto again;
882 default:
883 if (Zctlesccxx . . $ Zctlesc. && !(c & 0140)) {
884 goto again;
885 }
886 return c;
887 }
888 again2:
889 if ((c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0)
890 return c;
891 if (c == CANcxx . . $ `ifcico/ttyio.h:65:9`! && (c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0)
892 return c;
893 if (c == CANcxx . . $ `ifcico/ttyio.h:65:9`! && (c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0)
894 return c;
895 if (c == CANcxx . . $ `ifcico/ttyio.h:65:9`! && (c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0)
896 return c;
897 switch (c) {
898 case CANcxx . . $ `ifcico/ttyio.h:65:9`!:
899 return GOTCANcxx . . $ `ifcico/zmodem.h:76:9`!;
900 case ZCRCEcxx . . $ `ifcico/zmodem.h:62:9`!:
901 case ZCRCGcxx . . $ `ifcico/zmodem.h:63:9`!:
902 case ZCRCQcxx . . $ `ifcico/zmodem.h:64:9`!:
903 case ZCRCWcxx . . $ `ifcico/zmodem.h:65:9`!:
904 return (c | GOTORcxx . . $ `ifcico/zmodem.h:71:9`!);
905 case ZRUB0cxx . . $ `ifcico/zmodem.h:66:9`!:
906 return 0177;
907 case ZRUB1cxx . . $ `ifcico/zmodem.h:67:9`!:
908 return 0377;
909 case 023:
910 case 0223:
911 case 021:
912 case 0221:
913 goto again2;
914 default:
915 if (Zctlesccxx . . $ Zctlesc. && ! (c & 0140)) {
916 goto again2;
917 }
918 if ((c & 0140) == 0100)
919 return (c ^ 0100);
920 break;
921 }
922 debugcxx . . $ debug(2bb28f3347a46b85).(11,"Bad escape sequence %x", c);
923 return ERRORcxx . . $ `ifcico/ttyio.h:32:9`!;
924 }
925
926 /*
927 * Read a character from the modem line with timeout.
928 * Eat parity, XON and XOFF characters.
929 */
930 int noxrd7cxx . . $ noxrd7(b126dc7c1de90089).(void)
931 {
932 register int c;
933
934 for (;;) {
935 if ((c = GETCHARcxx . . $ `ifcico/ttyio.h:18:9`!(Rxtimeout)) < 0)
936 return c;
937 switch (c &= 0177) {
938 case DC1cxx . . $ `ifcico/ttyio.h:58:9`!:
939 case DC3cxx . . $ `ifcico/ttyio.h:60:9`!:
940 continue;
941 default:
942 if (Zctlesccxx . . $ Zctlesc. && !(c & 0140))
943 continue;
944 case '\r':
945 case '\n':
946 case ZDLEcxx . . $ `ifcico/zmodem.h:25:9`!:
947 return c;
948 }
949 }
950 }
951
952 /* Store long integer pos in Txhdr */
953 void stohdrcxx . . $ stohdr(1624ee8275b10bda).(pos)
954 long pos;
955 {
956 Txhdrcxx . . $ Txhdr.[ZP0cxx . . $ `ifcico/zmodem.h:83:9`!] = pos;
957 Txhdrcxx . . $ Txhdr.[ZP1cxx . . $ `ifcico/zmodem.h:84:9`!] = pos>>8;
958 Txhdrcxx . . $ Txhdr.[ZP2cxx . . $ `ifcico/zmodem.h:85:9`!] = pos>>16;
959 Txhdrcxx . . $ Txhdr.[ZP3cxx . . $ `ifcico/zmodem.h:86:9`!] = pos>>24;
960 }
961
962 /* Recover a long integer from a header */
963 long rclhdrcxx . . $ rclhdr(2ebcc2597f7e891d).(hdr)
964 register char *hdr;
965 {
966 register long l;
967
968 l = (hdr[ZP3cxx . . $ `ifcico/zmodem.h:86:9`!] & 0377);
969 l = (l << 8) | (hdr[ZP2cxx . . $ `ifcico/zmodem.h:85:9`!] & 0377);
970 l = (l << 8) | (hdr[ZP1cxx . . $ `ifcico/zmodem.h:84:9`!] & 0377);
971 l = (l << 8) | (hdr[ZP0cxx . . $ `ifcico/zmodem.h:83:9`!] & 0377);
972 return l;
973 }
974
975 /* End of zmmisc.c */