-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrzsz-3.17.sh
6479 lines (6479 loc) · 223 KB
/
rzsz-3.17.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 12/08/1991 16:22 UTC by caf@omen
# Source directory /u/caf/src/modem/3
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 3277 -rw-r--r-- README
# 4518 -rw-r--r-- Makefile
# 6259 -rw-r--r-- zmodem.h
# 18384 -rw-r--r-- zm.c
# 4424 -rw-r--r-- zmr.c
# 35578 -rw-r--r-- sz.c
# 27957 -rw-r--r-- rz.c
# 8737 -rw-r--r-- crctab.c
# 2486 -rw-r--r-- mailer.rz
# 8796 -rw-r--r-- crc.c
# 9549 -rw-r--r-- rbsb.c
# 4057 -rw-r--r-- minirb.c
# 1517 -rw-r--r-- crc.doc
# 10690 -rw-r--r-- rz.doc
# 17035 -rw-r--r-- sz.doc
# 22 -rw-r--r-- gz
# 738 -rw-r--r-- zupl.t
#
# ============= README ==============
if test -f 'README' -a X"$1" != X"-c"; then
echo 'x - skipping README (File already exists)'
else
echo 'x - extracting README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'README' &&
Rz and sz are Unix programs designed to support dial-in XMODEM,
YMODEM, and ZMODEM transfers via the controlling TTY port.
X
The contents of this archive can be uploaded to a remote Unix or
XXenix system by ZCOMM or Professional-YAM using the supplied
zupl.t script. Connect to your Unix/Xenix system, select an
empty directory, and then give the YAM/ZCOMM command: "source
zupl.t". This will upload minirb.c, compile it, and then use
minirb to bootstrap upload the rz/sz files.
X
Once these files are on your Unix system, you can type "make".
The Makefile will list the various systems it knows how to
compile the programs for, and the command to do so (e.g.,
"make bsd").
X
The Makefile is self explanatory; just say "make".
X
Rz and sz work best with comm programs that properly support
ZMODEM command and file AutoDownload (Pro-YAM and ZCOMM).
X
The "GSZ" shareware program allows ZMODEM file transfers with
traditional DOS comm programs. GSZ provides a "mini term
function" that supports ZMODEM AutoDownload. GSZ (part of
GSZ.ZIP) and ZCOMM (ZCOMMEXE.ZIP, ZCOMMDOC.ZIP, ZCOMMHLP.ZIP)
are available on TeleGodzilla and other fine bulletin boards.
X
Rz ans Sz are Copyrighted shareware programs. Commercial Use of
these programs is subject to licensing conditions detailed in
the rz.c source code. "Commercial Use" includes use of this
program to receive files from commercial and/or shareware
programs not published by Omen Technology INC. Please print the
"mailer.rz" file, fill out the form and return same with your
registration.
X
Previous versions of rz and sz (April 1988) are Public Domain.
X
The Man pages are formatted for those without Unix nroff.
For best results, use less(1) (available on comp.sources.misc)
as your manual page reader.
X
Oct 30 1991: Changed shar programs to aid net.digestion.
Rs and sz now use the same version number.
X
Oct 4 1991: Fixed bug in rz crash recovery.
X
Sep 1991: Major hacking to work around SVR4 bug. Append and crash
recovery of shrinking files corrected. Sz now supports rename.
Sz -c changed to zcommand, rx -c file changed to rc file.
X
Feb 1991: various corrections and simplifications. Sz now
stores critical error messages for post mortem display.
X
VMS systems are now supported with native VMS versions in
RZSZ.TLB. The rz and sz in RZSZ.TLB support wild cards and
VMS record types.
X
May 1989: Corrections for undefined variable and multiply
defined rdchk() on some systems.
X
New for 1989: ZMODEM compression and other compatible
extensions have been added to the rz and sz programs.
Please read the comments in the rz.c and sz.c source code
for licensing information.
X
X
In order for us to handle problem reports, we must have the
exact error messages displayed by Professional-YAM. If you are
not using an Omen Technology product to talk to rz/sz, and have
not registered rz/sz, please contact the author of the program
you are using for support. Some heavily marketed programs do
not fully support the ZMODEM protocol.
X
Chuck Forsberg WA7KGX ...!tektronix!reed!omen!caf
Author of YMODEM, ZMODEM, Professional-YAM, ZCOMM, and GSZ
X Omen Technology Inc "The High Reliability Software"
17505-V NW Sauvie IS RD Portland OR 97231 503-621-3406
TeleGodzilla:621-3746 FAX:621-3735 CIS:70007,2304 Genie:CAF
SHAR_EOF
chmod 0644 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 3277 -eq "$Wc_c" ||
echo 'README: original size 3277, current size' "$Wc_c"
fi
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
# Makefile for Unix/Xenix rz and sz programs
# the makefile is not too well tested yet
CC=cc
OFLAG= -O
X
X
ARCFILES= README rbsb.c gz *.t minirb.c zmodem.h \
X zm.c zmr.c crctab.c sz.c rz.c mailer.rz crc.c
X
nothing:
X @echo
X @echo "Please study the #ifdef's in crctab.c, rbsb.c, rz.c and sz.c,"
X @echo "make any necessary hacks for oddball or merged SYSV/BSD systems,"
X @echo "then type 'make SYSTEM' where SYSTEM is one of:"
X @echo
X @echo " sysvr4 SYSTEM 5.4 Unix"
X @echo " sysvr3 SYSTEM 5.3 Unix with mkdir(2)"
X @echo " sysv SYSTEM 3/5 Unix"
X @echo " xenix Xenix"
X @echo " x386 386 Xenix"
X @echo " bsd Berkeley 4.x BSD, Ultrix, V7"
X @echo " tandy Tandy 6000 Xenix"
X @echo " dnix DIAB Dnix 5.2"
X @echo " dnix5r3 DIAB Dnix 5.3"
X @echo
X @echo " doc Format the man pages with nroff"
X @echo
X
usenet:doc
X shar -s "...!reed!omen!caf" -c -a -n rzsz -o /tmp/rzsz -l52 \
X README Makefile zmodem.h zm.c rz.c rbsb.c \
X crc.c crctab.c minirb.c mailer.rz zmr.c *.doc gz sz.c *.t
X
shar:doc
X shar -c README Makefile zmodem.h zm.c \
X zmr.c sz.c rz.c crctab.c \
X mailer.rz crc.c rbsb.c minirb.c *.doc gz *.t >/tmp/rzsz
X
unixforum: shar
X compress /tmp/rzsz.sh
X
unix:
X undos $(ARCFILES)
X
dos:
X todos $(ARCFILES)
X
arc:doc
X rm -f /tmp/rzsz.arc
X arc aq /tmp/rzsz README Makefile zmodem.h zm.c sz.c rz.c \
X mailer.rz crctab.c rbsb.c \
X zmr.c crc.c *.doc gz *.t minirb.c
X chmod og-w /tmp/rzsz.arc
X mv /tmp/rzsz.arc /u/t/yam
X
doc:rz.doc sz.doc crc.doc
X
rz.doc:rz.1
X nroff -man rz.1 | col >rz.doc
X
sz.doc:sz.1
X nroff -man sz.1 | col >sz.doc
X
crc.doc:crc.1
X nroff -man crc.1 | col >crc.doc
X
zoo: doc
X rm -f /tmp/rzsz.zoo
X zoo ah /tmp/rzsz README Makefile zmodem.h zm.c sz.c rz.c \
X mailer.rz crctab.c rbsb.c *.doc \
X zmr.c crc.c gz *.t minirb.c
X touch /tmp/rzsz.zoo
X chmod og-w /tmp/rzsz.zoo
X mv /tmp/rzsz.zoo /u/t/yam
X rm -f rzsz.zip
X zip rzsz readme mailer.rz makefile zmodem.h zm.c sz.c rz.c
X zip rzsz crctab.c rbsb.c *.doc
X zip rzsz zmr.c crc.c gz *.t minirb.c
X mv rzsz.zip /u/t/yam
X
tar:doc
X tar cvf /tmp/rzsz.tar README Makefile zmodem.h zm.c sz.c rz.c \
X mailer.rz crctab.c rbsb.c \
X zmr.c crc.c *.1 *.doc gz *.t minirb.c
X
tags:
X ctags sz.c rz.c zm.c zmr.c rbsb.c
X
.PRECIOUS:rz sz
X
xenix:
X $(CC) $(CFLAGS) $(OFLAG) -M0 -K -i -DTXBSIZE=16384 -DNFGVMIN -DREADCHECK sz.c -lx -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X $(CC) $(CFLAGS) $(OFLAG) -M0 -K -i -DMD rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X
x386:
X $(CC) $(CFLAGS) $(OFLAG) -DMD rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X $(CC) $(CFLAGS) $(OFLAG) -DTXBSIZE=32768 -DNFGVMIN -DREADCHECK sz.c -lx -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
sysv:
X $(CC) $(CFLAGS) $(OFLAG) -DMD rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DSV -DTXBSIZE=32768 -DNFGVMIN sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
sysvr3:
X $(CC) $(CFLAGS) $(OFLAG) -DMD=2 rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DSV -DTXBSIZE=32768 -DNFGVMIN sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
sysvr4:
X $(CC) $(CFLAGS) $(OFLAG) -DMD=2 rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DSV -DTXBSIZE=32768 sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
odt:
X cc -Za -n -DMD=2 rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X cc -Za -n -DSV -DTXBSIZE=32768 sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
bsd:
X $(CC) $(CFLAGS) $(OFLAG) -DMD=2 -Dstrchr=index -DV7 rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DV7 -DTXBSIZE=32768 -DNFGVMIN sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
tandy:
X $(CC) $(CFLAGS) $(OFLAGS) -n -DMD -DT6K sz.c -lx -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X $(CC) $(CFLAGS) $(OFLAGS) -n -DMD -DT6K rz.c -lx -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X
dnix:
X $(CC) $(CFLAGS) $(OFLAG) -DMD rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DSV -DTXBSIZE=32768 -DNFGVMIN -DREADCHECK sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
dnix5r3:
X $(CC) $(CFLAGS) $(OFLAG) -DMD=2 rz.c -o rz
X size rz
X -ln rz rb
X -ln rz rx
X -ln rz rc
X $(CC) $(CFLAGS) $(OFLAG) -DSV -DTXBSIZE=32768 -DNFGVMIN -DREADCHECK sz.c -o sz
X size sz
X -ln sz sb
X -ln sz sx
X -ln sz zcommand
X -ln sz zcommandi
X
X
sz: nothing
sb: nothing
rz: nothing
rb: nothing
SHAR_EOF
chmod 0644 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 4518 -eq "$Wc_c" ||
echo 'Makefile: original size 4518, current size' "$Wc_c"
fi
# ============= zmodem.h ==============
if test -f 'zmodem.h' -a X"$1" != X"-c"; then
echo 'x - skipping zmodem.h (File already exists)'
else
echo 'x - extracting zmodem.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zmodem.h' &&
/*
X * Z M O D E M . H Manifest constants for ZMODEM
X * application to application file transfer protocol
X * Copyright 1991 Omen Technology Inc All Rights Reserved
X * 04-17-89 Chuck Forsberg Omen Technology Inc
X */
#define ZPAD '*' /* 052 Padding character begins frames */
#define ZDLE 030 /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
#define ZDLEE (ZDLE^0100) /* Escaped ZDLE as transmitted */
#define ZBIN 'A' /* Binary frame indicator (CRC-16) */
#define ZHEX 'B' /* HEX frame indicator */
#define ZBIN32 'C' /* Binary frame with 32 bit FCS */
#define ZBINR32 'D' /* RLE packed Binary frame with 32 bit FCS */
#define ZVBIN 'a' /* Binary frame indicator (CRC-16) */
#define ZVHEX 'b' /* HEX frame indicator */
#define ZVBIN32 'c' /* Binary frame with 32 bit FCS */
#define ZVBINR32 'd' /* RLE packed Binary frame with 32 bit FCS */
#define ZRESC 0176 /* RLE flag/escape character */
#define ZMAXHLEN 16 /* Max header information length NEVER CHANGE */
#define ZMAXSPLEN 1024 /* Max subpacket length NEVER CHANGE */
X
/* Frame types (see array "frametypes" in zm.c) */
#define ZRQINIT 0 /* Request receive init */
#define ZRINIT 1 /* Receive init */
#define ZSINIT 2 /* Send init sequence (optional) */
#define ZACK 3 /* ACK to above */
#define ZFILE 4 /* File name from sender */
#define ZSKIP 5 /* To sender: skip this file */
#define ZNAK 6 /* Last packet was garbled */
#define ZABORT 7 /* Abort batch transfers */
#define ZFIN 8 /* Finish session */
#define ZRPOS 9 /* Resume data trans at this position */
#define ZDATA 10 /* Data packet(s) follow */
#define ZEOF 11 /* End of file */
#define ZFERR 12 /* Fatal Read or Write error Detected */
#define ZCRC 13 /* Request for file CRC and response */
#define ZCHALLENGE 14 /* Receiver's Challenge */
#define ZCOMPL 15 /* Request is complete */
#define ZCAN 16 /* Other end canned session with CAN*5 */
#define ZFREECNT 17 /* Request for free bytes on filesystem */
#define ZCOMMAND 18 /* Command from sending program */
#define ZSTDERR 19 /* Output to standard error, data follows */
X
/* ZDLE sequences */
#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
#define ZCRCG 'i' /* CRC next, frame continues nonstop */
#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
#define ZRUB0 'l' /* Translate to rubout 0177 */
#define ZRUB1 'm' /* Translate to rubout 0377 */
X
/* zdlread return values (internal) */
/* -1 is general error, -2 is timeout */
#define GOTOR 0400
#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
#define GOTCAN (GOTOR|030) /* CAN*5 seen */
X
/* Byte positions within header array */
#define ZF0 3 /* First flags byte */
#define ZF1 2
#define ZF2 1
#define ZF3 0
#define ZP0 0 /* Low order 8 bits of position */
#define ZP1 1
#define ZP2 2
#define ZP3 3 /* High order 8 bits of file position */
X
/* Bit Masks for ZRINIT flags byte ZF0 */
#define CANFDX 01 /* Rx can send and receive true FDX */
#define CANOVIO 02 /* Rx can receive data during disk I/O */
#define CANBRK 04 /* Rx can send a break signal */
#define CANRLE 010 /* Receiver can decode RLE */
#define CANLZW 020 /* Receiver can uncompress */
#define CANFC32 040 /* Receiver can use 32 bit Frame Check */
#define ESCCTL 0100 /* Receiver expects ctl chars to be escaped */
#define ESC8 0200 /* Receiver expects 8th bit to be escaped */
X
/* Bit Masks for ZRINIT flags byte ZF1 */
#define CANVHDR 01 /* Variable headers OK */
X
/* Parameters for ZSINIT frame */
#define ZATTNLEN 32 /* Max length of attention string */
#define ALTCOFF ZF1 /* Offset to alternate canit string, 0 if not used */
/* Bit Masks for ZSINIT flags byte ZF0 */
#define TESCCTL 0100 /* Transmitter expects ctl chars to be escaped */
#define TESC8 0200 /* Transmitter expects 8th bit to be escaped */
X
/* Parameters for ZFILE frame */
/* Conversion options one of these in ZF0 */
#define ZCBIN 1 /* Binary transfer - inhibit conversion */
#define ZCNL 2 /* Convert NL to local end of line convention */
#define ZCRESUM 3 /* Resume interrupted file transfer */
/* Management include options, one of these ored in ZF1 */
#define ZMSKNOLOC 0200 /* Skip file if not present at rx */
/* Management options, one of these ored in ZF1 */
#define ZMMASK 037 /* Mask for the choices below */
#define ZMNEWL 1 /* Transfer if source newer or longer */
#define ZMCRC 2 /* Transfer if different file CRC or length */
#define ZMAPND 3 /* Append contents to existing file (if any) */
#define ZMCLOB 4 /* Replace existing file */
#define ZMNEW 5 /* Transfer if source newer */
X /* Number 5 is alive ... */
#define ZMDIFF 6 /* Transfer if dates or lengths different */
#define ZMPROT 7 /* Protect destination file */
#define ZMCHNG 8 /* Change filename if destination exists */
/* Transport options, one of these in ZF2 */
#define ZTLZW 1 /* Lempel-Ziv compression */
#define ZTRLE 3 /* Run Length encoding */
/* Extended options for ZF3, bit encoded */
#define ZXSPARS 64 /* Encoding for sparse file operations */
#define ZCANVHDR 01 /* Variable headers OK */
/* Receiver window size override */
#define ZRWOVR 4 /* byte position for receive window override/256 */
X
/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
#define ZCACK1 1 /* Acknowledge, then do command */
X
long rclhdr();
X
/* Globals used by ZMODEM functions */
extern Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
extern Rxtype; /* Type of header received */
extern Rxcount; /* Count of data bytes received */
extern Rxtimeout; /* Tenths of seconds to wait for something */
extern long Rxpos; /* Received file position */
extern long Txpos; /* Transmitted file position */
extern Txfcs32; /* TURE means send binary frames with 32 bit FCS */
extern Crc32t; /* Display flag indicating 32 bit CRC being sent */
extern Crc32; /* Display flag indicating 32 bit CRC being received */
extern Znulls; /* Number of nulls to send at beginning of ZDATA hdr */
extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
extern char *Altcan; /* Alternate canit string */
X
/* End of ZMODEM.H */
SHAR_EOF
chmod 0644 zmodem.h ||
echo 'restore of zmodem.h failed'
Wc_c="`wc -c < 'zmodem.h'`"
test 6259 -eq "$Wc_c" ||
echo 'zmodem.h: original size 6259, current size' "$Wc_c"
fi
# ============= zm.c ==============
if test -f 'zm.c' -a X"$1" != X"-c"; then
echo 'x - skipping zm.c (File already exists)'
else
echo 'x - extracting zm.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zm.c' &&
/*
X * Z M . C
X * Copyright 1991 Omen Technology Inc All Rights Reserved
X * ZMODEM protocol primitives
X * 05-24-89 Chuck Forsberg Omen Technology Inc
X *
X * Entry point Functions:
X * zsbhdr(type, hdr) send binary header
X * zshhdr(type, hdr) send hex header
X * zgethdr(hdr, eflag) receive header - binary or hex
X * zsdata(buf, len, frameend) send data
X * zrdata(buf, len) receive data
X * stohdr(pos) store position data in Txhdr
X * long rclhdr(hdr) recover position offset from header
X *
X *
X * This version implements numerous enhancements including ZMODEM
X * Run Length Encoding and variable length headers. These
X * features were not funded by the original Telenet development
X * contract.
X *
X * This software may be freely used for non commercial and
X * educational (didactic only) purposes. This software may also
X * be freely used to support file transfer operations to or from
X * licensed Omen Technology products. Any programs which use
X * part or all of this software must be provided in source form
X * with this notice intact except by written permission from Omen
X * Technology Incorporated.
X *
X * Use of this software for commercial or administrative purposes
X * except when exclusively limited to interfacing Omen Technology
X * products requires a per port license payment of $20.00 US per
X * port (less in quantity). Use of this code by inclusion,
X * decompilation, reverse engineering or any other means
X * constitutes agreement to these conditions and acceptance of
X * liability to license the materials and payment of reasonable
X * legal costs necessary to enforce this license agreement.
X *
X *
X * Omen Technology Inc FAX: 503-621-3745
X * Post Office Box 4681
X * Portland OR 97208
X *
X * This code is made available in the hope it will be useful,
X * BUT WITHOUT ANY WARRANTY OF ANY KIND OR LIABILITY FOR ANY
X * DAMAGES OF ANY KIND.
X *
X */
X
#ifndef CANFDX
#include "zmodem.h"
int Rxtimeout = 100; /* Tenths of seconds to wait for something */
#endif
X
#ifndef UNSL
#define UNSL
#endif
X
X
/* Globals used by ZMODEM functions */
int Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
int Rxtype; /* Type of header received */
int Rxhlen; /* Length of header received */
int Rxcount; /* Count of data bytes received */
char Rxhdr[ZMAXHLEN]; /* Received header */
char Txhdr[ZMAXHLEN]; /* Transmitted header */
long Rxpos; /* Received file position */
long Txpos; /* Transmitted file position */
int Txfcs32; /* TURE means send binary frames with 32 bit FCS */
int Crc32t; /* Controls 32 bit CRC being sent */
X /* 1 == CRC32, 2 == CRC32 + RLE */
int Crc32r; /* Indicates/controls 32 bit CRC being received */
X /* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */
int Usevhdrs; /* Use variable length headers */
int Znulls; /* Number of nulls to send at beginning of ZDATA hdr */
char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
char *Altcan; /* Alternate canit string */
X
static lastsent; /* Last char we sent */
static Not8bit; /* Seven bits seen on header */
X
static char *frametypes[] = {
X "No Response to Error Correction Request", /* -4 */
X "No Carrier Detect", /* -3 */
X "TIMEOUT", /* -2 */
X "ERROR", /* -1 */
#define FTOFFSET 4
X "ZRQINIT",
X "ZRINIT",
X "ZSINIT",
X "ZACK",
X "ZFILE",
X "ZSKIP",
X "ZNAK",
X "ZABORT",
X "ZFIN",
X "ZRPOS",
X "ZDATA",
X "ZEOF",
X "ZFERR",
X "ZCRC",
X "ZCHALLENGE",
X "ZCOMPL",
X "ZCAN",
X "ZFREECNT",
X "ZCOMMAND",
X "ZSTDERR",
X "xxxxx"
#define FRTYPES 22 /* Total number of frame types in this array */
X /* not including psuedo negative entries */
};
X
static char badcrc[] = "Bad CRC";
X
/* Send ZMODEM binary header hdr of type type */
zsbhdr(len, type, hdr)
register char *hdr;
{
X register int n;
X register unsigned short crc;
X
#ifndef DSZ
X vfile("zsbhdr: %c %d %s %lx", Usevhdrs?'v':'f', len,
X frametypes[type+FTOFFSET], rclhdr(hdr));
#endif
X if (type == ZDATA)
X for (n = Znulls; --n >=0; )
X xsendline(0);
X
X xsendline(ZPAD); xsendline(ZDLE);
X
X switch (Crc32t=Txfcs32) {
X case 2:
X zsbh32(len, hdr, type, Usevhdrs?ZVBINR32:ZBINR32);
X flushmo(); break;
X case 1:
X zsbh32(len, hdr, type, Usevhdrs?ZVBIN32:ZBIN32); break;
X default:
X if (Usevhdrs) {
X xsendline(ZVBIN);
X zsendline(len);
X }
X else
X xsendline(ZBIN);
X zsendline(type);
X crc = updcrc(type, 0);
X
X for (n=len; --n >= 0; ++hdr) {
X zsendline(*hdr);
X crc = updcrc((0377& *hdr), crc);
X }
X crc = updcrc(0,updcrc(0,crc));
X zsendline(crc>>8);
X zsendline(crc);
X }
X if (type != ZDATA)
X flushmo();
}
X
X
/* Send ZMODEM binary header hdr of type type */
zsbh32(len, hdr, type, flavour)
register char *hdr;
{
X register int n;
X register UNSL long crc;
X
X xsendline(flavour);
X if (Usevhdrs)
X zsendline(len);
X zsendline(type);
X crc = 0xFFFFFFFFL; crc = UPDC32(type, crc);
X
X for (n=len; --n >= 0; ++hdr) {
X crc = UPDC32((0377 & *hdr), crc);
X zsendline(*hdr);
X }
X crc = ~crc;
X for (n=4; --n >= 0;) {
X zsendline((int)crc);
X crc >>= 8;
X }
}
X
/* Send ZMODEM HEX header hdr of type type */
zshhdr(len, type, hdr)
register char *hdr;
{
X register int n;
X register unsigned short crc;
X
#ifndef DSZ
X vfile("zshhdr: %c %d %s %lx", Usevhdrs?'v':'f', len,
X frametypes[type+FTOFFSET], rclhdr(hdr));
#endif
X sendline(ZPAD); sendline(ZPAD); sendline(ZDLE);
X if (Usevhdrs) {
X sendline(ZVHEX);
X zputhex(len);
X }
X else
X sendline(ZHEX);
X zputhex(type);
X Crc32t = 0;
X
X crc = updcrc(type, 0);
X for (n=len; --n >= 0; ++hdr) {
X zputhex(*hdr); crc = updcrc((0377 & *hdr), crc);
X }
X crc = updcrc(0,updcrc(0,crc));
X zputhex(crc>>8); zputhex(crc);
X
X /* Make it printable on remote machine */
X sendline(015); sendline(0212);
X /*
X * Uncork the remote in case a fake XOFF has stopped data flow
X */
X if (type != ZFIN && type != ZACK)
X sendline(021);
X flushmo();
}
X
/*
X * Send binary array buf of length length, with ending ZDLE sequence frameend
X */
static char *Zendnames[] = { "ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW"};
zsdata(buf, length, frameend)
register char *buf;
{
X register unsigned short crc;
X
#ifndef DSZ
X vfile("zsdata: %d %s", length, Zendnames[frameend-ZCRCE&3]);
#endif
X switch (Crc32t) {
X case 1:
X zsda32(buf, length, frameend); break;
X case 2:
X zsdar32(buf, length, frameend); break;
X default:
X crc = 0;
X for (;--length >= 0; ++buf) {
X zsendline(*buf); crc = updcrc((0377 & *buf), crc);
X }
X xsendline(ZDLE); xsendline(frameend);
X crc = updcrc(frameend, crc);
X
X crc = updcrc(0,updcrc(0,crc));
X zsendline(crc>>8); zsendline(crc);
X }
X if (frameend == ZCRCW)
X xsendline(XON);
X if (frameend != ZCRCG)
X flushmo();
}
X
zsda32(buf, length, frameend)
register char *buf;
{
X register int c;
X register UNSL long crc;
X
X crc = 0xFFFFFFFFL;
X for (;--length >= 0; ++buf) {
X c = *buf & 0377;
X if (c & 0140)
X xsendline(lastsent = c);
X else
X zsendline(c);
X crc = UPDC32(c, crc);
X }
X xsendline(ZDLE); xsendline(frameend);
X crc = UPDC32(frameend, crc);
X
X crc = ~crc;
X for (c=4; --c >= 0;) {
X zsendline((int)crc); crc >>= 8;
X }
}
X
/*
X * Receive array buf of max length with ending ZDLE sequence
X * and CRC. Returns the ending character or error code.
X * NB: On errors may store length+1 bytes!
X */
zrdata(buf, length)
register char *buf;
{
X register int c;
X register unsigned short crc;
X register char *end;
X register int d;
X
X switch (Crc32r) {
X case 1:
X return zrdat32(buf, length);
X case 2:
X return zrdatr32(buf, length);
X }
X
X crc = Rxcount = 0; end = buf + length;
X while (buf <= end) {
X if ((c = zdlread()) & ~0377) {
crcfoo:
X switch (c) {
X case GOTCRCE:
X case GOTCRCG:
X case GOTCRCQ:
X case GOTCRCW:
X crc = updcrc((d=c)&0377, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = updcrc(c, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = updcrc(c, crc);
X if (crc & 0xFFFF) {
X zperr(badcrc);
X return ERROR;
X }
X Rxcount = length - (end - buf);
#ifndef DSZ
X vfile("zrdata: %d %s", Rxcount,
X Zendnames[d-GOTCRCE&3]);
#endif
X return d;
X case GOTCAN:
X zperr("Sender Canceled");
X return ZCAN;
X case TIMEOUT:
X zperr("TIMEOUT");
X return c;
X default:
X garbitch(); return c;
X }
X }
X *buf++ = c;
X crc = updcrc(c, crc);
X }
#ifdef DSZ
X garbitch();
#else
X zperr("Data subpacket too long");
#endif
X return ERROR;
}
X
zrdat32(buf, length)
register char *buf;
{
X register int c;
X register UNSL long crc;
X register char *end;
X register int d;
X
X crc = 0xFFFFFFFFL; Rxcount = 0; end = buf + length;
X while (buf <= end) {
X if ((c = zdlread()) & ~0377) {
crcfoo:
X switch (c) {
X case GOTCRCE:
X case GOTCRCG:
X case GOTCRCQ:
X case GOTCRCW:
X d = c; c &= 0377;
X crc = UPDC32(c, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = UPDC32(c, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = UPDC32(c, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = UPDC32(c, crc);
X if ((c = zdlread()) & ~0377)
X goto crcfoo;
X crc = UPDC32(c, crc);
X if (crc != 0xDEBB20E3) {
X zperr(badcrc);
X return ERROR;
X }
X Rxcount = length - (end - buf);
#ifndef DSZ
X vfile("zrdat32: %d %s", Rxcount,
X Zendnames[d-GOTCRCE&3]);
#endif
X return d;
X case GOTCAN:
X zperr("Sender Canceled");
X return ZCAN;
X case TIMEOUT:
X zperr("TIMEOUT");
X return c;
X default:
X garbitch(); return c;
X }
X }
X *buf++ = c;
X crc = UPDC32(c, crc);
X }
X zperr("Data subpacket too long");
X return ERROR;
}
X
garbitch()
{
X zperr("Garbled data subpacket");
}
X
/*
X * Read a ZMODEM header to hdr, either binary or hex.
X * eflag controls local display of non zmodem characters:
X * 0: no display
X * 1: display printing characters only
X * 2: display all non ZMODEM characters
X *
X * Set Rxhlen to size of header (default 4) (valid iff good hdr)
X * On success, set Zmodem to 1, set Rxpos and return type of header.
X * Otherwise return negative on error.
X * Return ERROR instantly if ZCRCW sequence, for fast error recovery.
X */
zgethdr(hdr, eflag)
char *hdr;
{
X register int c, n, cancount;
X
X n = Zrwindow + Effbaud; /* Max bytes before start of frame */
X Rxframeind = Rxtype = 0;
X
startover:
X cancount = 5;
again:
X /* Return immediate ERROR if ZCRCW sequence seen */
X switch (c = readline(Rxtimeout)) {
X case 021: case 0221:
X goto again;
X case RCDO:
X case TIMEOUT:
X goto fifi;
X case CAN:
gotcan:
X if (--cancount <= 0) {
X c = ZCAN; goto fifi;
X }
X switch (c = readline(1)) {
X case TIMEOUT:
X goto again;
X case ZCRCW:
X switch (readline(1)) {
X case TIMEOUT:
X c = ERROR; goto fifi;
X case RCDO:
X goto fifi;
X default:
X goto agn2;
X }
X case RCDO:
X goto fifi;
X default:
X break;
X case CAN:
X if (--cancount <= 0) {
X c = ZCAN; goto fifi;
X }
X goto again;
X }
X /* **** FALL THRU TO **** */
X default:
agn2:
X if ( --n == 0) {
X c = GCOUNT; goto fifi;
X }
X goto startover;
X case ZPAD|0200: /* This is what we want. */
X Not8bit = c;
X case ZPAD: /* This is what we want. */
X break;
X }
X cancount = 5;
splat:
X switch (c = noxrd7()) {
X case ZPAD:
X goto splat;
X case RCDO:
X case TIMEOUT: