KERMIT.LST 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. Listing:
  2. 1 (* Release 3.10 *)
  3. 2 (*-------------------------------------------------------------------------*
  4. 3 * *
  5. 4 * KERMIT.MOD - COMMS Toolkit KERMIT file protocol *
  6. 5 * *
  7. 6 * COPYRIGHT (C) 1988..1992 Clarion Software Corporation. *
  8. 7 * All Rights Reserved *
  9. 8 * *
  10. 9 *--------------------------------------------------------------------------*)
  11. 10
  12. 11 IMPLEMENTATION MODULE Kermit;
  13. 12 IMPORT ComSetup,Filenames,FIO,FTSupport,Lib,RS232,SPRINTF,Str;
  14. 13
  15. 14 CONST
  16. 15 TooMany = "Too many retries";
  17. ***** ^ not supported yet
  18. 16 UserAbort = "User Abort";
  19. ***** ^ not supported yet
  20. 17 FileOpened = "File Opened";
  21. ***** ^ not supported yet
  22. 18 FileClosed = "File Closed";
  23. ***** ^ not supported yet
  24. 19 EndSession = "Session Ends";
  25. ***** ^ not supported yet
  26. 20 XParams = "Exchanging Params";
  27. ***** ^ not supported yet
  28. 21 OK = 0;
  29. 22 SOH = 1;
  30. 23 CHKLNTH = 1;
  31. 24 YES = ORD("Y");
  32. ***** ^ undeclared identifier
  33. ***** ^ not supported yet
  34. 25 NO = ORD("N");
  35. ***** ^ undeclared identifier
  36. ***** ^ not supported yet
  37. 26 MAXTRIES = 5;
  38. 27 MAXPACK = 512; (* My maximum extended-length packet size *)
  39. 28 MAXWINDO = 6; (* My window size *)
  40. 29 (* Kermit Packet Types *)
  41. 30 DATA = 100H+ORD('D');
  42. ***** ^ undeclared identifier
  43. ***** ^ not supported yet
  44. 31 ACK = 100H+ORD('Y');
  45. ***** ^ undeclared identifier
  46. ***** ^ not supported yet
  47. 32 NAK = 100H+ORD('N');
  48. ***** ^ undeclared identifier
  49. ***** ^ not supported yet
  50. 33 SENDINIT = 100H+ORD('S');
  51. ***** ^ undeclared identifier
  52. ***** ^ not supported yet
  53. 34 ENDSESS = 100H+ORD('B');
  54. ***** ^ undeclared identifier
  55. ***** ^ not supported yet
  56. 35 FILEHDR = 100H+ORD('F');
  57. ***** ^ undeclared identifier
  58. ***** ^ not supported yet
  59. 36 EOFILE = 100H+ORD('Z');
  60. ***** ^ undeclared identifier
  61. ***** ^ not supported yet
  62. 37 ERROR = 100H+ORD('E');
  63. ***** ^ undeclared identifier
  64. ***** ^ not supported yet
  65. 38 QRSRVD = 100H+ORD('Q');
  66. ***** ^ undeclared identifier
  67. ***** ^ not supported yet
  68. 39 TIMEOUT = 100H+ORD('T');
  69. ***** ^ undeclared identifier
  70. ***** ^ not supported yet
  71. 40 ATTR = 100H+ORD('A');
  72. ***** ^ undeclared identifier
  73. ***** ^ not supported yet
  74. 41 (* flags = Bit Numbers for Capability mask *)
  75. 42 XLPKTS = 1; (* True if extended length packets are supported *)
  76. 43 WINDOWS = 2; (* True if sliding windows are supported *)
  77. 44 ATTPKTS = 3; (* True if attribute packets are supported *)
  78. 45
  79. 46 TYPE
  80. 47 DefaultRec = RECORD
  81. 48 MaxL : CARDINAL; (* The max length packet to send *)
  82. 49 Time : CARDINAL; (* The timeout while waiting for a pkt *)
  83. 50 NPad : CARDINAL; (* The number of pad characters to send *)
  84. 51 PadC : CARDINAL; (* The pad character to use *)
  85. 52 Eoln : CARDINAL; (* The end of line character to use *)
  86. 53 QCtl : CARDINAL; (* The char to use as Ctrl-Quote *)
  87. 54 QBin : CARDINAL; (* The char used for 8th bit quoting *)
  88. 55 Chkt : CARDINAL; (* The frame check type to use *)
  89. 56 Rept : CARDINAL; (* The char used for repeat encoding *)
  90. 57 Capa : BITSET; (* Remote's capability mask *)
  91. ***** ^ undeclared identifier
  92. 58 WSiz : CARDINAL; (* Window Size *)
  93. 59 XLen : CARDINAL; (* Extended Packet Length *)
  94. 60 END;
  95. ***** ^ not supported yet
  96. 61 Buffer = ARRAY[0..MAXPACK-1] OF CHAR;
  97. ***** ^ not supported yet
  98. ***** ^ not supported yet
  99. 62 TableEntry = RECORD
  100. 63 PacketNo : CARDINAL; (* seq no of this packet *)
  101. 64 Acked : BOOLEAN; (* true if this entry is ok *)
  102. 65 Sent : CARDINAL; (* number of times this pkt sent *)
  103. 66 Data : Buffer; (* the actual packet contents *)
  104. 67 Lenth : CARDINAL; (* Bytes of data in this pkt *)
  105. 68 FilePos : LONGCARD; (* the new file pointer *)
  106. ***** ^ undeclared identifier
  107. 69 END;
  108. ***** ^ not supported yet
  109. 70
  110. 71 VAR
  111. 72 Tries : CARDINAL; (* Number of attempts to send/receive *)
  112. 73 SeqNo : CARDINAL; (* The sequence number I use/expect next *)
  113. 74 WindowSize : CARDINAL; (* The current window size *)
  114. 75 SizeToSend : CARDINAL; (* Maximum size packet I can send *)
  115. 76 Default : DefaultRec; (* Settings for various protocol options *)
  116. ***** ^ not supported yet
  117. 77 f : FIO.File; (* The file being sent/received *)
  118. ***** ^ not supported yet
  119. 78
  120. 79 (*...............................................*)
  121. 80
  122. 81 PROCEDURE InitVars;
  123. 82 BEGIN
  124. 83 FTSupport.Errors:=0;
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 84 FTSupport.LastMessage:='';
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. 85 FTSupport.XferMode := 'CHK';
  131. ***** ^ not supported yet
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. 86 FTSupport.Transferred:=0;
  135. ***** ^ not supported yet
  136. ***** ^ not supported yet
  137. 87 FTSupport.Aborted := FALSE;
  138. ***** ^ not supported yet
  139. ***** ^ not supported yet
  140. 88 FTSupport.SizeInBytes:=0;
  141. ***** ^ not supported yet
  142. ***** ^ not supported yet
  143. 89 WindowSize := MAXWINDO;
  144. 90 END InitVars;
  145. ***** ^ not supported yet
  146. 91
  147. 92 (*...............................................*)
  148. 93
  149. 94 PROCEDURE Min(a,b:CARDINAL):CARDINAL;
  150. 95 BEGIN
  151. 96 IF a<b THEN
  152. 97 RETURN(a);
  153. 98 ELSE
  154. 99 RETURN(b);
  155. 100 END;
  156. 101 END Min;
  157. ***** ^ not supported yet
  158. 102
  159. 103 (*...............................................*)
  160. 104
  161. 105 PROCEDURE Max(a,b:CARDINAL):CARDINAL;
  162. 106 BEGIN
  163. 107 IF a>b THEN
  164. 108 RETURN(a);
  165. 109 ELSE
  166. 110 RETURN(b);
  167. 111 END;
  168. 112 END Max;
  169. ***** ^ not supported yet
  170. 113
  171. 114 (*...............................................*)
  172. 115
  173. 116 PROCEDURE ToChar(x:CARDINAL):CARDINAL;
  174. 117 BEGIN
  175. 118 RETURN x+20H;
  176. 119 END ToChar;
  177. ***** ^ not supported yet
  178. 120
  179. 121 (*...............................................*)
  180. 122
  181. 123 PROCEDURE UnChar(x:CARDINAL):CARDINAL;
  182. 124 BEGIN
  183. 125 RETURN x-20H;
  184. 126 END UnChar;
  185. ***** ^ not supported yet
  186. 127
  187. 128 (*...............................................*)
  188. 129
  189. 130 PROCEDURE Ctrl(x:CARDINAL):CARDINAL;
  190. 131 BEGIN
  191. 132 RETURN CARDINAL(BITSET(x) / BITSET(40H));
  192. ***** ^ undeclared identifier
  193. ***** ^ not supported yet
  194. ***** ^ undeclared identifier
  195. ***** ^ not supported yet
  196. 133 END Ctrl;
  197. ***** ^ not supported yet
  198. 134
  199. 135 (*...............................................*)
  200. 136
  201. 137 PROCEDURE Receive(TLimit:CARDINAL):CARDINAL;
  202. 138 VAR
  203. 139 c : CHAR;
  204. 140 BEGIN
  205. 141 LOOP
  206. 142 IF RS232.SerialRead(c,TLimit*10) THEN
  207. ***** ^ not supported yet
  208. ***** ^ not supported yet
  209. ***** ^ not supported yet
  210. 143 IF (ORD(c)=SOH) OR (c>=' ') THEN
  211. ***** ^ undeclared identifier
  212. ***** ^ not supported yet
  213. 144 RETURN ORD(c);
  214. ***** ^ undeclared identifier
  215. ***** ^ not supported yet
  216. 145 END;
  217. 146 ELSE
  218. 147 RETURN TIMEOUT;
  219. 148 END;
  220. 149 END;
  221. 150 END Receive;
  222. ***** ^ not supported yet
  223. 151
  224. 152 (*...............................................*)
  225. 153
  226. 154 PROCEDURE Msg(s:ARRAY OF CHAR);
  227. ***** ^ not supported yet
  228. 155 VAR
  229. 156 Lnth : CARDINAL;
  230. 157 BEGIN
  231. 158 Lnth := Str.Length(s);
  232. ***** ^ not supported yet
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. 159 Lib.Move(ADR(s),ADR(FTSupport.LastMessage),Lnth);
  236. ***** ^ not supported yet
  237. ***** ^ not supported yet
  238. ***** ^ undeclared identifier
  239. ***** ^ not supported yet
  240. ***** ^ undeclared identifier
  241. ***** ^ not supported yet
  242. ***** ^ not supported yet
  243. ***** ^ not supported yet
  244. 160 FTSupport.LastMessage[Lnth] := 0C;
  245. ***** ^ not supported yet
  246. ***** ^ not supported yet
  247. ***** ^ not supported yet
  248. 161 FTSupport.UpdateStatus;
  249. ***** ^ not supported yet
  250. ***** ^ not supported yet
  251. 162 END Msg;
  252. ***** ^ not supported yet
  253. 163
  254. 164 (*...............................................*)
  255. 165
  256. 166 PROCEDURE Error(s:ARRAY OF CHAR);
  257. ***** ^ not supported yet
  258. 167 BEGIN
  259. 168 INC(FTSupport.Errors);
  260. ***** ^ undeclared identifier
  261. ***** ^ not supported yet
  262. ***** ^ not supported yet
  263. 169 Msg(s);
  264. ***** ^ not supported yet
  265. ***** ^ not supported yet
  266. 170 END Error;
  267. ***** ^ not supported yet
  268. 171
  269. 172 (*...............................................*)
  270. 173
  271. 174 PROCEDURE SendPacket(tipe,SeqNo,DataLnth:CARDINAL);
  272. 175 VAR
  273. 176 i,p,CheckSum : CARDINAL;
  274. 177 Buff : ARRAY[0..MAXPACK+15] OF CHAR;
  275. ***** ^ not supported yet
  276. ***** ^ not supported yet
  277. 178 Extended : BOOLEAN;
  278. 179
  279. 180 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  280. 181
  281. 182 PROCEDURE sPutChar(c:CARDINAL);
  282. 183 BEGIN
  283. 184 Buff[p] := CHR(c);
  284. ***** ^ not supported yet
  285. ***** ^ not supported yet
  286. ***** ^ undeclared identifier
  287. ***** ^ not supported yet
  288. 185 CheckSum := (CheckSum+c) MOD 100H;
  289. 186 INC(p);
  290. ***** ^ undeclared identifier
  291. ***** ^ not supported yet
  292. 187 END sPutChar;
  293. ***** ^ not supported yet
  294. 188
  295. 189 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  296. 190
  297. 191 BEGIN (* SendPacket *)
  298. 192 i:=0;
  299. 193 p:=1;
  300. 194 CheckSum:=0;
  301. 195 WITH Default DO
  302. ***** ^ not supported yet
  303. 196 Extended := (XLPKTS IN Capa) AND (DataLnth>MaxL-(2+CHKLNTH));
  304. ***** ^ not supported yet
  305. ***** ^ not supported yet
  306. 197 END;
  307. ***** ^ not supported yet
  308. 198 Buff[0]:=CHR(SOH);
  309. ***** ^ not supported yet
  310. ***** ^ not supported yet
  311. ***** ^ undeclared identifier
  312. ***** ^ not supported yet
  313. 199 IF Extended THEN
  314. 200 sPutChar(ToChar(0))
  315. ***** ^ not supported yet
  316. ***** ^ not supported yet
  317. ***** ^ not supported yet
  318. 201 ELSE
  319. 202 sPutChar(ToChar(DataLnth+2+CHKLNTH))
  320. ***** ^ not supported yet
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. 203 END;
  324. 204 sPutChar(ToChar(SeqNo));
  325. ***** ^ not supported yet
  326. ***** ^ not supported yet
  327. ***** ^ not supported yet
  328. 205 sPutChar(tipe-100H);
  329. ***** ^ not supported yet
  330. ***** ^ not supported yet
  331. 206 IF Extended THEN
  332. 207 sPutChar(ToChar((DataLnth+CHKLNTH) DIV 95));
  333. ***** ^ not supported yet
  334. ***** ^ not supported yet
  335. ***** ^ not supported yet
  336. 208 sPutChar(ToChar((DataLnth+CHKLNTH) MOD 95));
  337. ***** ^ not supported yet
  338. ***** ^ not supported yet
  339. ***** ^ not supported yet
  340. 209 sPutChar(ToChar((CheckSum+(CheckSum>>6)) MOD 64));
  341. ***** ^ not supported yet
  342. ***** ^ not supported yet
  343. ***** ^ not supported yet
  344. 210 END;
  345. 211 WHILE i<DataLnth DO sPutChar(ORD(FTSupport.FBuff[i]));
  346. ***** ^ not supported yet
  347. ***** ^ undeclared identifier
  348. ***** ^ not supported yet
  349. ***** ^ not supported yet
  350. ***** ^ not supported yet
  351. 212 INC(i)
  352. ***** ^ undeclared identifier
  353. ***** ^ not supported yet
  354. 213 END;
  355. 214 Buff[p] := CHR(ToChar((CheckSum+(CheckSum>>6)) MOD 64));
  356. ***** ^ not supported yet
  357. ***** ^ not supported yet
  358. ***** ^ undeclared identifier
  359. ***** ^ not supported yet
  360. ***** ^ not supported yet
  361. 215 Buff[p+1] := CHR(Default.Eoln);
  362. ***** ^ not supported yet
  363. ***** ^ not supported yet
  364. ***** ^ undeclared identifier
  365. ***** ^ not supported yet
  366. ***** ^ not supported yet
  367. 216 RS232.SerialWrite(Buff,p+2);
  368. ***** ^ not supported yet
  369. ***** ^ not supported yet
  370. ***** ^ not supported yet
  371. ***** ^ not supported yet
  372. 217 END SendPacket;
  373. ***** ^ not supported yet
  374. 218
  375. 219 (*...............................................*)
  376. 220
  377. 221 (* Read a packet and return the packet type. *)
  378. 222 PROCEDURE ReadPacket(VAR SeqNo,Lnth:CARDINAL; SkipSOH:BOOLEAN):CARDINAL;
  379. 223 CONST
  380. 224 BadChecksum = "Bad Checksum";
  381. ***** ^ not supported yet
  382. 225 TYPE
  383. 226 RdStates = (Mark,Len,Seq,Type,LenX1,LenX2,HChk,Data,Check,Err);
  384. 227 VAR
  385. 228 Extended : BOOLEAN;
  386. 229 Timeout,rslt,
  387. 230 PacketType,Cnt,
  388. 231 HCheck,CheckSum : CARDINAL;
  389. 232 RdState : RdStates;
  390. ***** ^ not supported yet
  391. 233 BEGIN
  392. 234 RdState:=Mark;
  393. ***** ^ not supported yet
  394. ***** ^ not supported yet
  395. 235 Timeout:=Default.Time;
  396. ***** ^ not supported yet
  397. ***** ^ not supported yet
  398. 236 Timeout := Max(Timeout,10);
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. 237 LOOP
  402. 238 IF SkipSOH THEN
  403. 239 rslt:=SOH;
  404. 240 ELSE
  405. 241 rslt:=Receive(Timeout);
  406. ***** ^ not supported yet
  407. ***** ^ not supported yet
  408. 242 END;
  409. 243 IF rslt = TIMEOUT THEN
  410. 244 Error("Timeout");
  411. ***** ^ not supported yet
  412. ***** ^ not supported yet
  413. 245 RETURN TIMEOUT;
  414. 246 ELSIF rslt = SOH THEN
  415. 247 SkipSOH:=FALSE;
  416. 248 RdState:=Len;
  417. ***** ^ not supported yet
  418. ***** ^ not supported yet
  419. 249 CheckSum:=0;
  420. 250 Cnt:=0;
  421. 251 Extended:=FALSE;
  422. 252 ELSE
  423. 253 IF RdState # Check THEN
  424. ***** ^ not supported yet
  425. ***** ^ not supported yet
  426. 254 CheckSum := CARDINAL(BITSET(CheckSum+rslt)*BITSET(0FFH));
  427. ***** ^ undeclared identifier
  428. ***** ^ not supported yet
  429. ***** ^ undeclared identifier
  430. ***** ^ not supported yet
  431. 255 END;
  432. 256 CASE RdState OF
  433. ***** ^ not supported yet
  434. 257 Mark : (* do nothing, as SOH should have been trapped above *)|
  435. ***** ^ not supported yet
  436. 258 Len : Lnth:=UnChar(rslt);
  437. ***** ^ not supported yet
  438. ***** ^ not supported yet
  439. ***** ^ not supported yet
  440. 259 Extended:=(Lnth=0);
  441. 260 IF NOT Extended THEN
  442. 261 DEC(Lnth,2+CHKLNTH);
  443. ***** ^ undeclared identifier
  444. ***** ^ not supported yet
  445. 262 END;
  446. 263 RdState:=Seq; |
  447. ***** ^ not supported yet
  448. ***** ^ not supported yet
  449. 264 Seq : SeqNo:=UnChar(rslt);
  450. ***** ^ not supported yet
  451. ***** ^ not supported yet
  452. ***** ^ not supported yet
  453. 265 RdState:=Type; |
  454. ***** ^ not supported yet
  455. ***** ^ not supported yet
  456. 266 Type : PacketType := 100H+rslt;
  457. ***** ^ not supported yet
  458. 267 IF Extended THEN
  459. 268 RdState := LenX1
  460. ***** ^ not supported yet
  461. ***** ^ not supported yet
  462. 269 ELSIF Lnth>0 THEN
  463. 270 RdState:=Data
  464. ***** ^ not supported yet
  465. ***** ^ not supported yet
  466. 271 ELSE
  467. 272 RdState:=Check
  468. ***** ^ not supported yet
  469. ***** ^ not supported yet
  470. 273 END; |
  471. 274 LenX1 : Lnth:=UnChar(rslt);
  472. ***** ^ not supported yet
  473. ***** ^ not supported yet
  474. ***** ^ not supported yet
  475. 275 RdState:=LenX2; |
  476. ***** ^ not supported yet
  477. ***** ^ not supported yet
  478. 276 LenX2 : Lnth := (Lnth*95+UnChar(rslt)) - CHKLNTH;
  479. ***** ^ not supported yet
  480. ***** ^ not supported yet
  481. ***** ^ not supported yet
  482. 277 HCheck:=CheckSum;
  483. 278 RdState := HChk; |
  484. ***** ^ not supported yet
  485. ***** ^ not supported yet
  486. 279 HChk : IF rslt=ToChar((HCheck+(HCheck>>6)) MOD 64) THEN
  487. ***** ^ not supported yet
  488. ***** ^ not supported yet
  489. ***** ^ not supported yet
  490. 280 IF Lnth>0 THEN
  491. 281 RdState:=Data;
  492. ***** ^ not supported yet
  493. ***** ^ not supported yet
  494. 282 ELSE
  495. 283 RdState:=Check;
  496. ***** ^ not supported yet
  497. ***** ^ not supported yet
  498. 284 END;
  499. 285 ELSE
  500. 286 Error(BadChecksum);
  501. ***** ^ not supported yet
  502. ***** ^ not supported yet
  503. 287 RETURN TIMEOUT;
  504. 288 END; |
  505. 289 Data : FTSupport.FBuff[Cnt] := CHR(rslt);
  506. ***** ^ not supported yet
  507. ***** ^ not supported yet
  508. ***** ^ not supported yet
  509. ***** ^ not supported yet
  510. ***** ^ undeclared identifier
  511. ***** ^ not supported yet
  512. 290 INC(Cnt);
  513. ***** ^ undeclared identifier
  514. ***** ^ not supported yet
  515. 291 IF Cnt=Lnth THEN
  516. 292 RdState:=Check;
  517. ***** ^ not supported yet
  518. ***** ^ not supported yet
  519. 293 END; |
  520. 294 Check : IF rslt=ToChar((CheckSum+(CheckSum>>6)) MOD 64) THEN
  521. ***** ^ not supported yet
  522. ***** ^ not supported yet
  523. ***** ^ not supported yet
  524. 295 IF PacketType=ERROR THEN
  525. 296 Msg("Error Packet received");
  526. ***** ^ not supported yet
  527. ***** ^ not supported yet
  528. 297 END;
  529. 298 RETURN PacketType;
  530. 299 ELSE
  531. 300 Error(BadChecksum); RETURN TIMEOUT;
  532. ***** ^ not supported yet
  533. ***** ^ not supported yet
  534. 301 END; |
  535. 302 Err : (* purge modem buffer *);
  536. ***** ^ not supported yet
  537. 303 END;
  538. 304 END;
  539. 305 END;
  540. 306 END ReadPacket;
  541. ***** ^ not supported yet
  542. 307
  543. 308 (*...............................................*)
  544. 309
  545. 310 PROCEDURE NxtPktNo(SeqNo:CARDINAL):CARDINAL;
  546. 311 BEGIN
  547. 312 RETURN CARDINAL(BITSET(SeqNo+1) * BITSET(3FH));
  548. ***** ^ undeclared identifier
  549. ***** ^ not supported yet
  550. ***** ^ undeclared identifier
  551. ***** ^ not supported yet
  552. 313 END NxtPktNo;
  553. ***** ^ not supported yet
  554. 314
  555. 315 (*...............................................*)
  556. 316
  557. 317 PROCEDURE SendInitParms(tipe:CARDINAL);
  558. 318 VAR
  559. 319 MyCapas : BITSET;
  560. ***** ^ undeclared identifier
  561. 320 BEGIN
  562. 321 (* This line says that I can use attribute and extended length packets *)
  563. 322 MyCapas := {WINDOWS,XLPKTS,ATTPKTS};
  564. ***** ^ not supported yet
  565. ***** ^ not supported yet
  566. ***** ^ not supported yet
  567. ***** ^ not supported yet
  568. 323 WITH Default DO
  569. ***** ^ not supported yet
  570. 324 WindowSize := Min(MAXWINDO,WSiz);
  571. ***** ^ not supported yet
  572. ***** ^ not supported yet
  573. 325 FTSupport.FBuff[ 0] := CHR(ToChar(MaxL));
  574. ***** ^ not supported yet
  575. ***** ^ not supported yet
  576. ***** ^ not supported yet
  577. ***** ^ undeclared identifier
  578. ***** ^ not supported yet
  579. ***** ^ not supported yet
  580. 326 FTSupport.FBuff[ 1] := CHR(ToChar(Time));
  581. ***** ^ not supported yet
  582. ***** ^ not supported yet
  583. ***** ^ not supported yet
  584. ***** ^ undeclared identifier
  585. ***** ^ not supported yet
  586. ***** ^ not supported yet
  587. 327 FTSupport.FBuff[ 2] := CHR(ToChar(0));
  588. ***** ^ not supported yet
  589. ***** ^ not supported yet
  590. ***** ^ not supported yet
  591. ***** ^ undeclared identifier
  592. ***** ^ not supported yet
  593. ***** ^ not supported yet
  594. 328 FTSupport.FBuff[ 3] := CHR(Ctrl(0));
  595. ***** ^ not supported yet
  596. ***** ^ not supported yet
  597. ***** ^ not supported yet
  598. ***** ^ undeclared identifier
  599. ***** ^ not supported yet
  600. ***** ^ not supported yet
  601. 329 FTSupport.FBuff[ 4] := CHR(ToChar(Eoln));
  602. ***** ^ not supported yet
  603. ***** ^ not supported yet
  604. ***** ^ not supported yet
  605. ***** ^ undeclared identifier
  606. ***** ^ not supported yet
  607. ***** ^ not supported yet
  608. 330 FTSupport.FBuff[ 5] := CHR(QCtl);
  609. ***** ^ not supported yet
  610. ***** ^ not supported yet
  611. ***** ^ not supported yet
  612. ***** ^ undeclared identifier
  613. ***** ^ not supported yet
  614. 331 FTSupport.FBuff[ 6] := 'Y';
  615. ***** ^ not supported yet
  616. ***** ^ not supported yet
  617. ***** ^ not supported yet
  618. 332 FTSupport.FBuff[ 7] := '1';
  619. ***** ^ not supported yet
  620. ***** ^ not supported yet
  621. ***** ^ not supported yet
  622. 333 FTSupport.FBuff[ 8] := CHR(Rept);
  623. ***** ^ not supported yet
  624. ***** ^ not supported yet
  625. ***** ^ not supported yet
  626. ***** ^ undeclared identifier
  627. ***** ^ not supported yet
  628. 334 FTSupport.FBuff[ 9] := CHR(ToChar(CARDINAL(MyCapas)));
  629. ***** ^ not supported yet
  630. ***** ^ not supported yet
  631. ***** ^ not supported yet
  632. ***** ^ undeclared identifier
  633. ***** ^ not supported yet
  634. ***** ^ not supported yet
  635. 335 FTSupport.FBuff[10] := CHR(ToChar(WindowSize)); (* Window Size *)
  636. ***** ^ not supported yet
  637. ***** ^ not supported yet
  638. ***** ^ not supported yet
  639. ***** ^ undeclared identifier
  640. ***** ^ not supported yet
  641. ***** ^ not supported yet
  642. 336 FTSupport.FBuff[11] := CHR(ToChar(MAXPACK DIV 95)); (* pkt lnth - High bits *)
  643. ***** ^ not supported yet
  644. ***** ^ not supported yet
  645. ***** ^ not supported yet
  646. ***** ^ undeclared identifier
  647. ***** ^ not supported yet
  648. ***** ^ not supported yet
  649. 337 FTSupport.FBuff[12] := CHR(ToChar(MAXPACK MOD 95)); (* pkt lnth - Low bits *)
  650. ***** ^ not supported yet
  651. ***** ^ not supported yet
  652. ***** ^ not supported yet
  653. ***** ^ undeclared identifier
  654. ***** ^ not supported yet
  655. ***** ^ not supported yet
  656. 338 END;
  657. ***** ^ not supported yet
  658. 339 SendPacket(tipe,SeqNo,13);
  659. ***** ^ not supported yet
  660. ***** ^ not supported yet
  661. 340 END SendInitParms;
  662. ***** ^ not supported yet
  663. 341
  664. 342 (*...............................................*)
  665. 343
  666. 344 PROCEDURE GetInitParams():CARDINAL;
  667. 345 TYPE
  668. 346 InitStates = (maxl,time,npad,padc,eol,qctl,qbin,chkt,rept,capas,capas2,windo,maxlx1,maxlx2,done);
  669. 347 VAR
  670. 348 rslt,p,c,Seq,Lnth : CARDINAL;
  671. 349 temp : BITSET;
  672. ***** ^ undeclared identifier
  673. 350 State : InitStates;
  674. ***** ^ not supported yet
  675. 351 BEGIN
  676. 352 IF Tries=MAXTRIES THEN
  677. 353 Error(TooMany);
  678. ***** ^ not supported yet
  679. ***** ^ not supported yet
  680. 354 RETURN(ERROR);
  681. 355 END;
  682. 356 INC(Tries);
  683. ***** ^ undeclared identifier
  684. ***** ^ not supported yet
  685. 357 rslt := ReadPacket(Seq,Lnth,FALSE);
  686. ***** ^ not supported yet
  687. ***** ^ not supported yet
  688. 358 IF (rslt # SENDINIT) AND (rslt # ACK) THEN
  689. 359 RETURN(rslt);
  690. 360 END;
  691. 361 (* Set defaults *)
  692. 362 WITH Default DO
  693. ***** ^ not supported yet
  694. 363 Capa:={};
  695. ***** ^ not supported yet
  696. ***** ^ not supported yet
  697. 364 p:=0;
  698. 365 State:=maxl;
  699. ***** ^ not supported yet
  700. ***** ^ not supported yet
  701. 366 LOOP
  702. 367 IF p<Lnth THEN
  703. 368 c:=ORD(FTSupport.FBuff[p]);
  704. ***** ^ undeclared identifier
  705. ***** ^ not supported yet
  706. ***** ^ not supported yet
  707. ***** ^ not supported yet
  708. 369 INC(p)
  709. ***** ^ undeclared identifier
  710. ***** ^ not supported yet
  711. 370 ELSE
  712. 371 c:=0;
  713. 372 END;
  714. 373 CASE State OF
  715. ***** ^ not supported yet
  716. 374 maxl : MaxL:=UnChar(c);
  717. ***** ^ not supported yet
  718. ***** ^ not supported yet
  719. ***** ^ not supported yet
  720. ***** ^ not supported yet
  721. 375 State:=time; |
  722. ***** ^ not supported yet
  723. ***** ^ not supported yet
  724. 376 time : Time:=UnChar(c);
  725. ***** ^ not supported yet
  726. ***** ^ not supported yet
  727. ***** ^ not supported yet
  728. ***** ^ not supported yet
  729. 377 State:=npad; |
  730. ***** ^ not supported yet
  731. ***** ^ not supported yet
  732. 378 npad : NPad:=UnChar(c);
  733. ***** ^ not supported yet
  734. ***** ^ not supported yet
  735. ***** ^ not supported yet
  736. ***** ^ not supported yet
  737. 379 IF NPad=0 THEN
  738. ***** ^ not supported yet
  739. 380 INC(p);
  740. ***** ^ undeclared identifier
  741. ***** ^ not supported yet
  742. 381 State:=eol;
  743. ***** ^ not supported yet
  744. ***** ^ not supported yet
  745. 382 ELSE
  746. 383 State:=padc;
  747. ***** ^ not supported yet
  748. ***** ^ not supported yet
  749. 384 END; |
  750. 385 padc : PadC:=Ctrl(c);
  751. ***** ^ not supported yet
  752. ***** ^ not supported yet
  753. ***** ^ not supported yet
  754. ***** ^ not supported yet
  755. 386 State:=eol; |
  756. ***** ^ not supported yet
  757. ***** ^ not supported yet
  758. 387 eol : Eoln:=UnChar(c);
  759. ***** ^ not supported yet
  760. ***** ^ not supported yet
  761. ***** ^ not supported yet
  762. ***** ^ not supported yet
  763. 388 State:=qctl; |
  764. ***** ^ not supported yet
  765. ***** ^ not supported yet
  766. 389 qctl : QCtl:=c;
  767. ***** ^ not supported yet
  768. ***** ^ not supported yet
  769. ***** ^ incompatible assignment
  770. 390 State:=qbin; |
  771. ***** ^ not supported yet
  772. ***** ^ not supported yet
  773. 391 (* optional features *)
  774. 392 qbin : IF (c=YES) OR (c=NO) THEN
  775. ***** ^ not supported yet
  776. 393 QBin:=0;
  777. ***** ^ not supported yet
  778. ***** ^ incompatible assignment
  779. 394 ELSE
  780. 395 QBin:=c;
  781. ***** ^ not supported yet
  782. ***** ^ incompatible assignment
  783. 396 END;
  784. 397 State:=chkt; |
  785. ***** ^ not supported yet
  786. ***** ^ not supported yet
  787. 398 chkt : (* Ignore frame check type for the moment *)
  788. ***** ^ not supported yet
  789. 399 State := rept; |
  790. ***** ^ not supported yet
  791. ***** ^ not supported yet
  792. 400 rept : IF c=32 THEN
  793. ***** ^ not supported yet
  794. 401 Rept:=0;
  795. ***** ^ not supported yet
  796. ***** ^ incompatible assignment
  797. 402 ELSE
  798. 403 Rept:=c;
  799. ***** ^ not supported yet
  800. ***** ^ incompatible assignment
  801. 404 END;
  802. 405 State:=capas; |
  803. ***** ^ not supported yet
  804. ***** ^ not supported yet
  805. 406 capas : IF c<32 THEN
  806. ***** ^ not supported yet
  807. 407 Capa:={};
  808. ***** ^ not supported yet
  809. ***** ^ not supported yet
  810. 408 ELSE
  811. 409 Capa:=BITSET(UnChar(c));
  812. ***** ^ not supported yet
  813. ***** ^ undeclared identifier
  814. ***** ^ not supported yet
  815. ***** ^ not supported yet
  816. 410 END;
  817. 411 IF 0 IN Capa THEN
  818. ***** ^ not supported yet
  819. 412 State:=capas2;
  820. ***** ^ not supported yet
  821. ***** ^ not supported yet
  822. 413 ELSE
  823. 414 State:=windo;
  824. ***** ^ not supported yet
  825. ***** ^ not supported yet
  826. 415 END; |
  827. 416 capas2 : IF c<32 THEN
  828. ***** ^ not supported yet
  829. 417 temp:={};
  830. ***** ^ not supported yet
  831. ***** ^ not supported yet
  832. 418 ELSE
  833. 419 temp:=BITSET(UnChar(c));
  834. ***** ^ not supported yet
  835. ***** ^ undeclared identifier
  836. ***** ^ not supported yet
  837. ***** ^ not supported yet
  838. 420 END;
  839. 421 IF NOT (0 IN Capa) THEN
  840. ***** ^ not supported yet
  841. 422 State:=windo;
  842. ***** ^ not supported yet
  843. ***** ^ not supported yet
  844. 423 END; |
  845. 424 windo : IF c<32 THEN
  846. ***** ^ not supported yet
  847. 425 WSiz:=0;
  848. ***** ^ not supported yet
  849. ***** ^ incompatible assignment
  850. 426 ELSE
  851. 427 WSiz:=UnChar(c);
  852. ***** ^ not supported yet
  853. ***** ^ not supported yet
  854. ***** ^ not supported yet
  855. 428 END;
  856. 429 State:=maxlx1; |
  857. ***** ^ not supported yet
  858. ***** ^ not supported yet
  859. 430 maxlx1 : IF c<32 THEN
  860. ***** ^ not supported yet
  861. 431 XLen:=0;
  862. ***** ^ not supported yet
  863. ***** ^ incompatible assignment
  864. 432 ELSE
  865. 433 XLen:=UnChar(c);
  866. ***** ^ not supported yet
  867. ***** ^ not supported yet
  868. ***** ^ not supported yet
  869. 434 END;
  870. 435 State:=maxlx2; |
  871. ***** ^ not supported yet
  872. ***** ^ not supported yet
  873. 436 maxlx2 : IF c>31 THEN
  874. ***** ^ not supported yet
  875. 437 XLen := XLen+(UnChar(c)<<6);
  876. ***** ^ not supported yet
  877. ***** ^ not supported yet
  878. ***** ^ not supported yet
  879. ***** ^ not supported yet
  880. ***** ^ arithmetic operand must be numeric
  881. 438 END;
  882. 439 State:=done; |
  883. ***** ^ not supported yet
  884. ***** ^ not supported yet
  885. 440 done : EXIT; |
  886. ***** ^ not supported yet
  887. 441 END;
  888. 442 END;
  889. 443 END;
  890. ***** ^ not supported yet
  891. 444 RETURN rslt;
  892. 445 END GetInitParams;
  893. ***** ^ not supported yet
  894. 446
  895. 447 (*...............................................*)
  896. 448
  897. 449 PROCEDURE WriteData(Lnth:CARDINAL;VAR FBuff,Buff:ARRAY OF CHAR;WriteIt:BOOLEAN):CARDINAL;
  898. ***** ^ not supported yet
  899. 450 (* Get data from an incoming packet into a file. *)
  900. 451 VAR
  901. 452 i,rep,c,BuffPtr : CARDINAL;
  902. 453 SetBit8 : BOOLEAN;
  903. 454
  904. 455 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  905. 456
  906. 457 PROCEDURE wPutChar(c:CARDINAL);
  907. 458 BEGIN
  908. 459 IF WriteIt AND (BuffPtr=MAXPACK) THEN
  909. 460 INC(FTSupport.Transferred,MAXPACK);
  910. ***** ^ undeclared identifier
  911. ***** ^ not supported yet
  912. ***** ^ not supported yet
  913. ***** ^ not supported yet
  914. 461 FIO.WrBin(f,Buff,MAXPACK);
  915. ***** ^ not supported yet
  916. ***** ^ not supported yet
  917. ***** ^ not supported yet
  918. ***** ^ not supported yet
  919. ***** ^ not supported yet
  920. 462 BuffPtr := 0;
  921. 463 END;
  922. 464 Buff[BuffPtr] := CHR(c);
  923. ***** ^ not supported yet
  924. ***** ^ not supported yet
  925. ***** ^ undeclared identifier
  926. ***** ^ not supported yet
  927. 465 INC(BuffPtr);
  928. ***** ^ undeclared identifier
  929. ***** ^ not supported yet
  930. 466 END wPutChar;
  931. ***** ^ not supported yet
  932. 467
  933. 468 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  934. 469
  935. 470 PROCEDURE Low(In:CARDINAL):CARDINAL;
  936. 471 BEGIN
  937. 472 RETURN CARDINAL(BITSET(In) - BITSET{7});
  938. ***** ^ undeclared identifier
  939. ***** ^ not supported yet
  940. ***** ^ undeclared identifier
  941. 473 END Low;
  942. 474
  943. 475 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  944. 476
  945. 477 BEGIN (* WriteData *)
  946. 478 BuffPtr:=0;
  947. 479 i:=0;
  948. 480 WITH Default DO
  949. 481 WHILE i<Lnth DO
  950. 482 rep := 1;
  951. 483 c:=ORD(FBuff[i]);
  952. 484 INC(i); (* Get character *)
  953. 485 IF c=Rept THEN
  954. 486 rep := UnChar(ORD(FBuff[i]));
  955. 487 c := ORD(FBuff[i+1]);
  956. 488 INC(i,2);
  957. 489 END;
  958. 490 SetBit8:=FALSE;
  959. 491 IF c=QBin THEN
  960. 492 SetBit8 := TRUE;
  961. 493 c:=ORD(FBuff[i]);
  962. 494 INC(i);
  963. 495 END;
  964. 496 IF c=QCtl THEN (* Control quote? *)
  965. 497 c:=ORD(FBuff[i]);
  966. 498 INC(i); (* Get the quoted character *)
  967. 499 IF (Low(c) # QCtl) & (Low(c) # QBin) & (Low(c) # Rept) THEN
  968. 500 c:=Ctrl(c);
  969. 501 END;
  970. 502 END;
  971. 503 IF SetBit8 THEN
  972. 504 c := CARDINAL(BITSET(c)+{7});
  973. 505 END;
  974. 506 WHILE rep>0 DO
  975. 507 wPutChar(c);
  976. 508 DEC(rep); (* Put the char in the file *)
  977. 509 END;
  978. 510 END;
  979. 511 END;
  980. 512 IF (WriteIt) AND (BuffPtr>0) THEN
  981. 513 FIO.WrBin(f,Buff,BuffPtr);
  982. 514 INC(FTSupport.Transferred,LONGCARD(BuffPtr));
  983. 515 END;
  984. 516 IF WriteIt THEN
  985. 517 FTSupport.UpdateStatus
  986. 518 END;
  987. 519 RETURN BuffPtr;
  988. 520 END WriteData;
  989. 521
  990. 522 (*...............................................*)
  991. 523
  992. 524 PROCEDURE GetFileHeader():CARDINAL;
  993. 525 VAR
  994. 526 rslt,Seq,Lnth : CARDINAL;
  995. 527 BEGIN
  996. 528 LOOP
  997. 529 IF Tries=MAXTRIES THEN
  998. 530 Error(TooMany);
  999. 531 RETURN(ERROR);
  1000. 532 END;
  1001. 533 INC(Tries);
  1002. 534 rslt := ReadPacket(Seq,Lnth,FALSE);
  1003. 535 CASE rslt OF
  1004. 536 FILEHDR : Lnth := WriteData(Lnth,FTSupport.FBuff,FTSupport.FileSpec,FALSE);
  1005. 537 FTSupport.FileSpec[Lnth] := 0C;
  1006. 538 FTSupport.CompleteFilename;
  1007. 539 FTSupport.NewFilename;
  1008. 540 f := FIO.Create(FTSupport.FileSpec);
  1009. 541 IF FIO.IOresult() # 0 THEN
  1010. 542 Error("File Create Error"); RETURN ERROR
  1011. 543 END;
  1012. 544 Msg(FileOpened); RETURN rslt; |
  1013. 545 TIMEOUT : SendPacket(NAK,NxtPktNo(SeqNo),0); |
  1014. 546 ERROR,
  1015. 547 SENDINIT,
  1016. 548 EOFILE,
  1017. 549 ENDSESS : RETURN rslt; |
  1018. 550 ELSE
  1019. 551 RETURN ERROR;
  1020. 552 END;
  1021. 553 END;
  1022. 554 END GetFileHeader;
  1023. 555
  1024. 556 (*...............................................*)
  1025. 557
  1026. 558 PROCEDURE GetFileAttributes(Lnth:CARDINAL);
  1027. 559 VAR
  1028. 560 attr : CHAR;
  1029. 561 p,rslt,len : CARDINAL;
  1030. 562 BEGIN
  1031. 563 (* Run along attribute data looking for "Size in Bytes" attribute. *)
  1032. 564 (* This is the only attribute we can actually use. *)
  1033. 565 p:=0;
  1034. 566 WHILE p<Lnth DO
  1035. 567 attr:=FTSupport.FBuff[p];
  1036. 568 INC(p);
  1037. 569 len:=UnChar(ORD(FTSupport.FBuff[p]));
  1038. 570 INC(p);
  1039. 571 IF attr='1' THEN (* found Size in bytes *)
  1040. 572 FTSupport.SizeInBytes := 0;
  1041. 573 WHILE len>0 DO
  1042. 574 FTSupport.SizeInBytes := FTSupport.SizeInBytes*10+LONGCARD(ORD(FTSupport.FBuff[p])-48);
  1043. 575 INC(p);
  1044. 576 DEC(len);
  1045. 577 END;
  1046. 578 FTSupport.UpdateStatus;
  1047. 579 ELSE
  1048. 580 INC(p,len);
  1049. 581 END;
  1050. 582 END;
  1051. 583 END GetFileAttributes;
  1052. 584
  1053. 585 (*...............................................*)
  1054. 586
  1055. 587 PROCEDURE GetFileData():CARDINAL;
  1056. 588 VAR
  1057. 589 i,p,rslt,Seq,Lnth,
  1058. 590 first,last : CARDINAL;
  1059. 591 RcvTable : ARRAY[0..MAXWINDO-1] OF TableEntry;
  1060. 592 WriteBuff : Buffer;
  1061. 593
  1062. 594 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1063. 595
  1064. 596 PROCEDURE NAKit(Seq:CARDINAL);
  1065. 597 BEGIN
  1066. 598 SendPacket(NAK,Seq,0);
  1067. 599 END NAKit;
  1068. 600
  1069. 601 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1070. 602
  1071. 603 PROCEDURE InitReceiveTable(FirstSeqNo:CARDINAL);
  1072. 604 VAR
  1073. 605 i : CARDINAL;
  1074. 606 BEGIN
  1075. 607 first:=0;
  1076. 608 last:=WindowSize-1;
  1077. 609 FOR i:=0 TO WindowSize-1 DO
  1078. 610 WITH RcvTable[i] DO
  1079. 611 PacketNo := CARDINAL(BITSET(FirstSeqNo+i+1)*BITSET(3FH));
  1080. 612 Acked := FALSE;
  1081. 613 Lenth := 0;
  1082. 614 END;
  1083. 615 END;
  1084. 616 END InitReceiveTable;
  1085. 617
  1086. 618 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1087. 619
  1088. 620 PROCEDURE Duplicate(Seq:CARDINAL; VAR Index:CARDINAL):BOOLEAN;
  1089. 621 VAR
  1090. 622 i : CARDINAL;
  1091. 623 BEGIN
  1092. 624 FOR i:=0 TO WindowSize-1 DO
  1093. 625 IF Seq=RcvTable[i].PacketNo THEN
  1094. 626 Index:=i;
  1095. 627 RETURN(TRUE)
  1096. 628 END;
  1097. 629 END;
  1098. 630 RETURN FALSE;
  1099. 631 END Duplicate;
  1100. 632
  1101. 633 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1102. 634
  1103. 635 PROCEDURE MostWanted():CARDINAL;
  1104. 636 VAR
  1105. 637 i,p : CARDINAL;
  1106. 638 BEGIN
  1107. 639 p:=first;
  1108. 640 FOR i:=0 TO WindowSize-1 DO
  1109. 641 IF NOT RcvTable[p].Acked THEN
  1110. 642 RETURN(p);
  1111. 643 END;
  1112. 644 p := (p+1) MOD WindowSize;
  1113. 645 END;
  1114. 646 RETURN NxtPktNo(RcvTable[last].PacketNo);
  1115. 647 END MostWanted;
  1116. 648
  1117. 649 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1118. 650
  1119. 651 PROCEDURE RotateTable():CARDINAL;
  1120. 652 VAR
  1121. 653 i,NextPkt :CARDINAL;
  1122. 654 BEGIN
  1123. 655 NextPkt := NxtPktNo(RcvTable[last].PacketNo);
  1124. 656 (* Ok, now rotate the window. Not physically, just adjust the *)
  1125. 657 (* first and last pointers. *)
  1126. 658 last:=first;
  1127. 659 first:=(first+1) MOD WindowSize;
  1128. 660 WITH RcvTable[last] DO (* write old contents then clear entry *)
  1129. 661 IF NOT Acked THEN
  1130. 662 RETURN(ERROR);
  1131. 663 END;
  1132. 664 IF Lenth>0 THEN
  1133. 665 i:=WriteData(Lenth,Data,WriteBuff,TRUE);
  1134. 666 END;
  1135. 667 Acked:=FALSE;
  1136. 668 PacketNo:=NextPkt;
  1137. 669 Lenth:=0;
  1138. 670 END;
  1139. 671 RETURN OK;
  1140. 672 END RotateTable;
  1141. 673
  1142. 674 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1143. 675
  1144. 676 PROCEDURE StoreData(Index,Lnth:CARDINAL);
  1145. 677 BEGIN
  1146. 678 WITH RcvTable[Index] DO
  1147. 679 IF Acked THEN
  1148. 680 Msg("Duplicate Packet");
  1149. 681 END;
  1150. 682 Acked:=TRUE;
  1151. 683 Lenth:=Lnth;
  1152. 684 Lib.Move(ADR(FTSupport.FBuff),ADR(Data),Lenth);
  1153. 685 END;
  1154. 686 END StoreData;
  1155. 687
  1156. 688 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1157. 689
  1158. 690 BEGIN (* GetFileData *)
  1159. 691 InitReceiveTable(SeqNo); (* initialise receive table *)
  1160. 692 LOOP
  1161. 693 IF FTSupport.AbortRequested() THEN
  1162. 694 Msg(UserAbort);
  1163. 695 RETURN ERROR;
  1164. 696 END;
  1165. 697 IF Tries=MAXTRIES THEN
  1166. 698 Msg(TooMany);
  1167. 699 RETURN(ERROR);
  1168. 700 END;
  1169. 701 INC(Tries);
  1170. 702 rslt := ReadPacket(Seq,Lnth,FALSE);
  1171. 703 CASE rslt OF
  1172. 704 DATA : Tries := 0;
  1173. 705 IF Duplicate(Seq,i) THEN
  1174. 706 SendPacket(ACK,Seq,0);
  1175. 707 StoreData(i,Lnth);
  1176. 708 ELSE (* new packet *)
  1177. 709 i:=0;
  1178. 710 SendPacket(ACK,Seq,0);
  1179. 711 REPEAT
  1180. 712 INC(i);
  1181. 713 IF RotateTable()=ERROR THEN
  1182. 714 Error("Out of Sequence!");
  1183. 715 RETURN ERROR;
  1184. 716 END;
  1185. 717 UNTIL Seq=RcvTable[last].PacketNo;
  1186. 718 StoreData(last,Lnth);
  1187. 719 IF i>1 THEN (* NAK any packets skipped *)
  1188. 720 p:=first;
  1189. 721 FOR i:=0 TO WindowSize-1 DO
  1190. 722 WITH RcvTable[p] DO
  1191. 723 IF NOT Acked THEN
  1192. 724 Error("NAK: Packets Skipped");
  1193. 725 NAKit(PacketNo);
  1194. 726 END;
  1195. 727 END;
  1196. 728 p := (p+1) MOD WindowSize;
  1197. 729 END;
  1198. 730 END;
  1199. 731 END; |
  1200. 732 ATTR : Tries := 0;
  1201. 733 SendPacket(ACK,Seq,0);
  1202. 734 GetFileAttributes(Lnth);
  1203. 735 InitReceiveTable(Seq); |
  1204. 736 TIMEOUT : Error("NAK: Timeout");
  1205. 737 NAKit(MostWanted()); |
  1206. 738 ERROR : RETURN rslt; |
  1207. 739 FILEHDR : RETURN rslt; |
  1208. 740 EOFILE : p:=first;
  1209. 741 FOR i:=0 TO WindowSize-1 DO
  1210. 742 WITH RcvTable[p] DO
  1211. 743 IF Acked AND (Lenth>0) THEN
  1212. 744 Lnth := WriteData(Lenth,Data,WriteBuff,TRUE);
  1213. 745 END;
  1214. 746 END;
  1215. 747 p := (p+1) MOD WindowSize;
  1216. 748 END;
  1217. 749 RETURN EOFILE; |
  1218. 750 ELSE
  1219. 751 RETURN ERROR;
  1220. 752 END;
  1221. 753 SeqNo := Seq;
  1222. 754 END;
  1223. 755 END GetFileData;
  1224. 756
  1225. 757 (*...............................................*)
  1226. 758
  1227. 759 PROCEDURE RxStateMachine():CARDINAL;
  1228. 760 TYPE
  1229. 761 RxStates = (rSendInit,rFHeader,rFData);
  1230. 762 VAR
  1231. 763 rslt : CARDINAL;
  1232. 764 RxState : RxStates;
  1233. 765 BEGIN
  1234. 766 RxState := rSendInit;
  1235. 767 SeqNo := 0; (* Start Sequence Number *)
  1236. 768 Default.Time := 15; (* default timeout for Send-Init packet *)
  1237. 769 Default.Eoln := 13;
  1238. 770 Tries := 0;
  1239. 771 LOOP
  1240. 772 CASE RxState OF
  1241. 773 rSendInit : rslt := GetInitParams();
  1242. 774 IF rslt=ERROR THEN
  1243. 775 RETURN ERROR
  1244. 776 ELSIF rslt=SENDINIT THEN
  1245. 777 SendInitParms(ACK);
  1246. 778 Tries := 0;
  1247. 779 RxState:=rFHeader;
  1248. 780 ELSE (* timeout *)
  1249. 781 SendPacket(NAK,SeqNo,0);
  1250. 782 END; |
  1251. 783 rFHeader : InitVars;
  1252. 784 rslt := GetFileHeader();
  1253. 785 IF rslt=ERROR THEN
  1254. 786 RETURN ERROR
  1255. 787 ELSIF rslt=SENDINIT THEN
  1256. 788 SendInitParms(ACK);
  1257. 789 ELSIF rslt=EOFILE THEN
  1258. 790 SendPacket(ACK,SeqNo,0);
  1259. 791 ELSIF rslt=ENDSESS THEN
  1260. 792 SeqNo := NxtPktNo(SeqNo);
  1261. 793 SendPacket(ACK,SeqNo,0);
  1262. 794 Msg(EndSession);
  1263. 795 RETURN OK;
  1264. 796 ELSIF rslt=FILEHDR THEN
  1265. 797 SeqNo := NxtPktNo(SeqNo);
  1266. 798 SendPacket(ACK,SeqNo,0);
  1267. 799 Tries := 0;
  1268. 800 RxState := rFData;
  1269. 801 END; |
  1270. 802 rFData : rslt := GetFileData();
  1271. 803 IF rslt=ERROR THEN
  1272. 804 RETURN ERROR
  1273. 805 ELSIF rslt=FILEHDR THEN
  1274. 806 SendPacket(ACK,SeqNo,0);
  1275. 807 ELSIF rslt=EOFILE THEN
  1276. 808 SeqNo := NxtPktNo(SeqNo);
  1277. 809 SendPacket(ACK,SeqNo,0);
  1278. 810 Msg(FileClosed);
  1279. 811 FIO.Close(f);
  1280. 812 Tries := 0;
  1281. 813 RxState := rFHeader;
  1282. 814 END; |
  1283. 815 END;
  1284. 816 END;
  1285. 817 END RxStateMachine;
  1286. 818
  1287. 819 (*...............................................*)
  1288. 820
  1289. 821 PROCEDURE KermitReceive():CARDINAL;
  1290. 822 VAR
  1291. 823 rslt:CARDINAL;
  1292. 824 BEGIN
  1293. 825 InitVars;
  1294. 826 FTSupport.OpenStatusWindow('SuperKermit Download');
  1295. 827 rslt := RxStateMachine();
  1296. 828 IF rslt=ERROR THEN
  1297. 829 SendPacket(ERROR,SeqNo,0);
  1298. 830 END;
  1299. 831 FIO.Close(f);
  1300. 832 FTSupport.CloseStatusWindow;
  1301. 833 RETURN rslt;
  1302. 834 END KermitReceive;
  1303. 835
  1304. 836 (*...............................................*)
  1305. 837
  1306. 838 PROCEDURE GetPath(Wild:ARRAY OF CHAR; VAR Path:ARRAY OF CHAR):BOOLEAN;
  1307. 839 VAR
  1308. 840 Drive,Ext : ARRAY[0..4] OF CHAR;
  1309. 841 Name : ARRAY[0..12] OF CHAR;
  1310. 842 BEGIN
  1311. 843 IF NOT Filenames.ParseFilename(Wild,Drive,Path,Name,Ext) THEN
  1312. 844 RETURN(FALSE);
  1313. 845 END;
  1314. 846 Name := '';
  1315. 847 Ext:='';
  1316. 848 Filenames.MakeFilename(Drive,Path,Name,Ext,Path);
  1317. 849 RETURN TRUE;
  1318. 850 END GetPath;
  1319. 851
  1320. 852 (*...............................................*)
  1321. 853
  1322. 854 PROCEDURE SendMyParams():CARDINAL;
  1323. 855 VAR
  1324. 856 rslt : CARDINAL;
  1325. 857 BEGIN
  1326. 858 Msg(XParams);
  1327. 859 WITH Default DO
  1328. 860 WITH ComSetup.Setup.Kermit DO
  1329. 861 MaxL:=90;
  1330. 862 Time:=15;
  1331. 863 NPad:=NumPadChars;
  1332. 864 PadC:=ORD(PadChar);
  1333. 865 Eoln:=ORD(EolChar);
  1334. 866 QCtl:=ORD(CtlQuote);
  1335. 867 QBin:=ORD(EightBitQuote);
  1336. 868 Chkt:=1;
  1337. 869 Rept:=ORD(ReptPrefix);
  1338. 870 Capa:={WINDOWS,XLPKTS,ATTPKTS};
  1339. 871 WSiz:=MAXWINDO;
  1340. 872 XLen:=MAXPACK;
  1341. 873 END;
  1342. 874 END;
  1343. 875 Tries:=0;
  1344. 876 LOOP
  1345. 877 SendInitParms(SENDINIT);
  1346. 878 rslt := GetInitParams();
  1347. 879 CASE rslt OF
  1348. 880 ACK : (* this is what I want*)
  1349. 881 WITH Default DO
  1350. 882 IF WINDOWS IN Capa THEN
  1351. 883 WindowSize := Max(1,Min(WSiz,MAXWINDO));
  1352. 884 ELSE
  1353. 885 WindowSize := 1;
  1354. 886 END;
  1355. 887 IF (QBin=YES) OR (QBin=NO) THEN
  1356. 888 QBin:=0;
  1357. 889 END;
  1358. 890 IF XLPKTS IN Capa THEN
  1359. 891 SizeToSend := Min(MAXPACK,XLen-CHKLNTH)
  1360. 892 ELSE
  1361. 893 SizeToSend := MaxL-(CHKLNTH+2)
  1362. 894 END;
  1363. 895 END;
  1364. 896 SeqNo := NxtPktNo(SeqNo);
  1365. 897 RS232.FlushInBuf;
  1366. 898 RETURN ACK; |
  1367. 899 TIMEOUT : (* loop again *) |
  1368. 900 ELSE
  1369. 901 RETURN ERROR;
  1370. 902 END;
  1371. 903 END;
  1372. 904 END SendMyParams;
  1373. 905
  1374. 906 (*...............................................*)
  1375. 907
  1376. 908 PROCEDURE SendMessage(tipe,DataLnth:CARDINAL):CARDINAL;
  1377. 909 VAR
  1378. 910 rslt,Seq,Lnth : CARDINAL;
  1379. 911 BEGIN
  1380. 912 Tries := 0;
  1381. 913 LOOP
  1382. 914 SendPacket(tipe,SeqNo,DataLnth);
  1383. 915 rslt := ReadPacket(Seq,Lnth,FALSE);
  1384. 916 IF (rslt=ERROR) OR (rslt=ACK) THEN
  1385. 917 SeqNo := NxtPktNo(SeqNo);
  1386. 918 RETURN(rslt);
  1387. 919 END;
  1388. 920 END;
  1389. 921 END SendMessage;
  1390. 922
  1391. 923 (*...............................................*)
  1392. 924
  1393. 925 PROCEDURE SendFileHeader(VAR Path:ARRAY OF CHAR):CARDINAL;
  1394. 926 (* send file header and lnth attribute *)
  1395. 927 VAR
  1396. 928 rslt,Lnth : CARDINAL;
  1397. 929 BEGIN
  1398. 930 Lnth:=Str.Length(FTSupport.FileSpec);
  1399. 931 Str.Copy(FTSupport.FBuff,FTSupport.FileSpec);
  1400. 932 rslt := SendMessage(FILEHDR,Lnth);
  1401. 933 IF rslt # ACK THEN
  1402. 934 RETURN(rslt);
  1403. 935 END;
  1404. 936 IF Path[0] # 0C THEN
  1405. 937 Str.Concat(FTSupport.FileSpec,Path,FTSupport.FileSpec);
  1406. 938 END;
  1407. 939 f := FIO.Open(FTSupport.FileSpec);
  1408. 940 IF FIO.IOresult() # 0 THEN
  1409. 941 RETURN(ERROR);
  1410. 942 END;
  1411. 943 IF NOT (ATTPKTS IN Default.Capa) THEN
  1412. 944 RETURN(ACK);
  1413. 945 END;
  1414. 946 FTSupport.SizeInBytes := FIO.Size(f);
  1415. 947 SPRINTF.SPrintF1("1$%u",FTSupport.SizeInBytes,FTSupport.FBuff);
  1416. 948 Lnth := Str.Length(FTSupport.FBuff);
  1417. 949 FTSupport.FBuff[1] := CHR(ToChar(Lnth-2));
  1418. 950 FTSupport.NewFilename;
  1419. 951 Msg(FileOpened);
  1420. 952 RETURN SendMessage(ATTR,Lnth);
  1421. 953 END SendFileHeader;
  1422. 954
  1423. 955 (*...............................................*)
  1424. 956
  1425. 957 PROCEDURE SendFileData():CARDINAL;
  1426. 958 TYPE
  1427. 959 SetOfChar = SET OF CHAR;
  1428. 960 VAR
  1429. 961 rslt,rptr,
  1430. 962 bytesread,
  1431. 963 NextToSend,first,
  1432. 964 last,pbstack : CARDINAL;
  1433. 965 Stack : ARRAY[0..1] OF CARDINAL;
  1434. 966 CtrlChars : SetOfChar;
  1435. 967 RxPos : LONGCARD;
  1436. 968 SndTable : ARRAY[0..MAXWINDO-1] OF TableEntry;
  1437. 969 ReadBuff : Buffer;
  1438. 970
  1439. 971 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1440. 972
  1441. 973 PROCEDURE PushBack(c:CARDINAL);
  1442. 974 BEGIN
  1443. 975 Stack[pbstack]:=c;
  1444. 976 INC(pbstack);
  1445. 977 END PushBack;
  1446. 978
  1447. 979 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1448. 980
  1449. 981 PROCEDURE GetChar(VAR c:CARDINAL):CARDINAL;
  1450. 982 BEGIN
  1451. 983 IF pbstack>0 THEN
  1452. 984 DEC(pbstack);
  1453. 985 c:=Stack[pbstack];
  1454. 986 ELSE
  1455. 987 WHILE rptr=bytesread DO
  1456. 988 IF bytesread<MAXPACK THEN
  1457. 989 c:=0FFFFH;
  1458. 990 RETURN(c);
  1459. 991 END;
  1460. 992 bytesread := FIO.RdBin(f,ReadBuff,MAXPACK);
  1461. 993 INC(RxPos,LONGCARD(bytesread));
  1462. 994 rptr := 0;
  1463. 995 END;
  1464. 996 c := ORD(ReadBuff[rptr]);
  1465. 997 INC(rptr);
  1466. 998 END;
  1467. 999 RETURN c;
  1468. 1000 END GetChar;
  1469. 1001
  1470. 1002 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1471. 1003
  1472. 1004 PROCEDURE FillBuffer(Index:CARDINAL);
  1473. 1005 VAR
  1474. 1006 wptr,c,c2,nextc,
  1475. 1007 rep,SafetyMargin: CARDINAL;
  1476. 1008 BEGIN
  1477. 1009 WITH SndTable[Index] DO
  1478. 1010 wptr:=0;
  1479. 1011 SafetyMargin:=SizeToSend-5;
  1480. 1012 IF Default.QBin=0 THEN
  1481. 1013 INC(SafetyMargin);
  1482. 1014 END;
  1483. 1015 WHILE (wptr<=SafetyMargin) AND (GetChar(c) # 0FFFFH) DO
  1484. 1016 rep:=1;
  1485. 1017 IF Default.Rept>0 THEN (* are we allowed repeated chars? *)
  1486. 1018 (* count repeated chars *)
  1487. 1019 WHILE (rep<94) AND (GetChar(nextc)=c) DO
  1488. 1020 INC(rep);
  1489. 1021 END;
  1490. 1022 IF rep<94 THEN
  1491. 1023 PushBack(nextc);
  1492. 1024 END;
  1493. 1025 IF rep>1 THEN
  1494. 1026 IF rep=2 THEN (* not worth compressing *)
  1495. 1027 PushBack(c);
  1496. 1028 ELSE
  1497. 1029 Data[wptr]:=CHR(Default.Rept);
  1498. 1030 INC(wptr);
  1499. 1031 Data[wptr]:=CHR(ToChar(rep));
  1500. 1032 INC(wptr);
  1501. 1033 END;
  1502. 1034 END;
  1503. 1035 END;
  1504. 1036 c2 := CARDINAL(BITSET(c)*BITSET(127));
  1505. 1037 IF (Default.QBin>0) AND (c>127) THEN
  1506. 1038 c:=c2;
  1507. 1039 Data[wptr]:=CHR(Default.QBin);
  1508. 1040 INC(wptr);
  1509. 1041 END;
  1510. 1042 IF CHR(c) IN CtrlChars THEN
  1511. 1043 Data[wptr]:=CHR(Default.QCtl);
  1512. 1044 INC(wptr);
  1513. 1045 IF (c2<32) OR (c2=127) THEN
  1514. 1046 c:=Ctrl(c);
  1515. 1047 END;
  1516. 1048 END;
  1517. 1049 Data[wptr]:=CHR(c);
  1518. 1050 INC(wptr);
  1519. 1051 END;
  1520. 1052 Lenth := wptr;
  1521. 1053 FilePos := RxPos;
  1522. 1054 END;
  1523. 1055 END FillBuffer;
  1524. 1056
  1525. 1057 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1526. 1058
  1527. 1059 PROCEDURE InitSndTable;
  1528. 1060 VAR
  1529. 1061 i : CARDINAL;
  1530. 1062 BEGIN
  1531. 1063 CtrlChars := SetOfChar{0C..CHR(31),CHR(127),CHR(128)..CHR(159),CHR(255)};
  1532. 1064 INCL(CtrlChars,CHR(Default.Rept));
  1533. 1065 INCL(CtrlChars,CHR(Default.QBin));
  1534. 1066 INCL(CtrlChars,CHR(Default.QCtl));
  1535. 1067 pbstack:=0;
  1536. 1068 rptr:=0FFFFH;
  1537. 1069 bytesread:=rptr;
  1538. 1070 first:=0;
  1539. 1071 last:=WindowSize-1;
  1540. 1072 RxPos := 0;
  1541. 1073 FOR i:=0 TO WindowSize-1 DO
  1542. 1074 WITH SndTable[i] DO
  1543. 1075 PacketNo:=(SeqNo+i) MOD 64;
  1544. 1076 Acked:=FALSE;
  1545. 1077 Sent := 0;
  1546. 1078 END;
  1547. 1079 FillBuffer(i);
  1548. 1080 END;
  1549. 1081 END InitSndTable;
  1550. 1082
  1551. 1083 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1552. 1084
  1553. 1085 PROCEDURE SendIt(Index:CARDINAL):CARDINAL;
  1554. 1086 BEGIN
  1555. 1087 WITH SndTable[Index] DO
  1556. 1088 IF Lenth=0 THEN
  1557. 1089 RETURN(OK);
  1558. 1090 END;
  1559. 1091 IF Sent=MAXTRIES THEN
  1560. 1092 RETURN(ERROR);
  1561. 1093 END;
  1562. 1094 INC(Sent);
  1563. 1095 Lib.Move(ADR(Data),ADR(FTSupport.FBuff),Lenth);
  1564. 1096 SendPacket(DATA,PacketNo,Lenth);
  1565. 1097 END;
  1566. 1098 RETURN OK;
  1567. 1099 END SendIt;
  1568. 1100
  1569. 1101 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1570. 1102
  1571. 1103 PROCEDURE WindowClosed():BOOLEAN;
  1572. 1104 (* Try and find the next packet to send by searching for the next *)
  1573. 1105 (* packet which has not yet been sent and which has length>0. If *)
  1574. 1106 (* one is found then the window has not yet closed, otherwise it *)
  1575. 1107 (* is closed. *)
  1576. 1108 VAR
  1577. 1109 i,p : CARDINAL;
  1578. 1110 BEGIN
  1579. 1111 p:=NextToSend;
  1580. 1112 FOR i:=0 TO WindowSize-1 DO
  1581. 1113 WITH SndTable[p] DO
  1582. 1114 IF (Sent=0) AND (Lenth>0) THEN
  1583. 1115 NextToSend:=p;
  1584. 1116 RETURN(FALSE);
  1585. 1117 END;
  1586. 1118 END;
  1587. 1119 p := (p+1) MOD WindowSize;
  1588. 1120 END;
  1589. 1121 RETURN TRUE;
  1590. 1122 END WindowClosed;
  1591. 1123
  1592. 1124 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1593. 1125
  1594. 1126 PROCEDURE Done():BOOLEAN;
  1595. 1127 VAR
  1596. 1128 i : CARDINAL;
  1597. 1129 BEGIN
  1598. 1130 FOR i:=0 TO WindowSize-1 DO
  1599. 1131 IF SndTable[i].Lenth>0 THEN
  1600. 1132 RETURN(FALSE);
  1601. 1133 END;
  1602. 1134 END;
  1603. 1135 RETURN TRUE;
  1604. 1136 END Done;
  1605. 1137
  1606. 1138 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1607. 1139
  1608. 1140 PROCEDURE TestReply():CARDINAL;
  1609. 1141 VAR
  1610. 1142 next,rslt,Seq,
  1611. 1143 Lnth,i,ptr : CARDINAL;
  1612. 1144 GotSOH : BOOLEAN;
  1613. 1145 c : CHAR;
  1614. 1146 BEGIN
  1615. 1147 LOOP
  1616. 1148 IF FTSupport.AbortRequested() THEN
  1617. 1149 Msg(UserAbort);
  1618. 1150 RETURN(ERROR);
  1619. 1151 END;
  1620. 1152 IF Done() THEN
  1621. 1153 RETURN(OK);
  1622. 1154 END;
  1623. 1155 Tries:=0;
  1624. 1156 GotSOH:=FALSE;
  1625. 1157 IF WindowClosed() THEN
  1626. 1158 (* force a wait for a reply *)
  1627. 1159 rslt := ReadPacket(Seq,Lnth,FALSE);
  1628. 1160 ELSE
  1629. 1161 (* Flush input buffer, looking out for a reply *)
  1630. 1162 IF RS232.SerialRead(c,0) THEN
  1631. 1163 REPEAT
  1632. 1164 UNTIL (ORD(c)=SOH) OR (NOT RS232.SerialRead(c,0));
  1633. 1165 GotSOH := (ORD(c)=SOH);
  1634. 1166 END;
  1635. 1167 IF GotSOH THEN
  1636. 1168 rslt := ReadPacket(Seq,Lnth,TRUE);
  1637. 1169 ELSE
  1638. 1170 RETURN OK;
  1639. 1171 END
  1640. 1172 END;
  1641. 1173 CASE rslt OF
  1642. 1174 ACK : ptr:=first;
  1643. 1175 FOR i:=0 TO WindowSize-1 DO
  1644. 1176 WITH SndTable[ptr] DO
  1645. 1177 IF PacketNo=Seq THEN
  1646. 1178 Acked:=TRUE;
  1647. 1179 END;
  1648. 1180 END;
  1649. 1181 ptr := (ptr+1) MOD WindowSize;
  1650. 1182 END;
  1651. 1183 (* Rotate the table *)
  1652. 1184 WHILE SndTable[first].Acked DO
  1653. 1185 FTSupport.Transferred := SndTable[first].FilePos;
  1654. 1186 FTSupport.UpdateStatus;
  1655. 1187 next := NxtPktNo(SndTable[last].PacketNo);
  1656. 1188 last:=first;
  1657. 1189 first:=(first+1) MOD WindowSize;
  1658. 1190 WITH SndTable[last] DO
  1659. 1191 PacketNo:=next;
  1660. 1192 Acked:=FALSE;
  1661. 1193 Sent:=0;
  1662. 1194 END;
  1663. 1195 FillBuffer(last);
  1664. 1196 END;
  1665. 1197 IF WindowSize=1 THEN
  1666. 1198 RETURN(OK);
  1667. 1199 END; |
  1668. 1200 NAK : ptr:=first;
  1669. 1201 FOR i:=0 TO WindowSize-1 DO
  1670. 1202 WITH SndTable[ptr] DO
  1671. 1203 IF PacketNo=Seq THEN
  1672. 1204 IF SendIt(ptr)=ERROR THEN
  1673. 1205 RETURN(ERROR);
  1674. 1206 END;
  1675. 1207 END;
  1676. 1208 END;
  1677. 1209 ptr := (ptr+1) MOD WindowSize;
  1678. 1210 END; |
  1679. 1211 TIMEOUT : (* resend the oldest UnAcked packet *)
  1680. 1212 IF SendIt(first)=ERROR THEN
  1681. 1213 RETURN(ERROR);
  1682. 1214 END; |
  1683. 1215 ELSE
  1684. 1216 RETURN ERROR;
  1685. 1217 END;
  1686. 1218 END;
  1687. 1219 END TestReply;
  1688. 1220
  1689. 1221 (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  1690. 1222
  1691. 1223 BEGIN (* SendFileData *)
  1692. 1224 InitSndTable;
  1693. 1225 NextToSend:=0;
  1694. 1226 rslt:=OK;
  1695. 1227 LOOP
  1696. 1228 IF Done() THEN
  1697. 1229 EXIT;
  1698. 1230 END;
  1699. 1231 rslt := SendIt(NextToSend);
  1700. 1232 IF rslt=ERROR THEN
  1701. 1233 EXIT;
  1702. 1234 END;
  1703. 1235 NextToSend := (NextToSend+1) MOD WindowSize;
  1704. 1236 rslt := TestReply();
  1705. 1237 IF rslt=ERROR THEN
  1706. 1238 EXIT;
  1707. 1239 END;
  1708. 1240 END;
  1709. 1241 SeqNo := SndTable[first].PacketNo;
  1710. 1242 IF rslt # ERROR THEN
  1711. 1243 rslt:=OK;
  1712. 1244 END;
  1713. 1245 RETURN rslt;
  1714. 1246 END SendFileData;
  1715. 1247
  1716. 1248 (*...............................................*)
  1717. 1249
  1718. 1250 PROCEDURE TxStateMachine(VAR Wild:ARRAY OF CHAR):CARDINAL;
  1719. 1251 TYPE
  1720. 1252 TxStates = (TxInit,TxSendInit,TxSendHdr,TxSendData,TxSendEOF,TxEndSess);
  1721. 1253 VAR
  1722. 1254 State : TxStates;
  1723. 1255 GotFile : BOOLEAN;
  1724. 1256 rslt : CARDINAL;
  1725. 1257 Path : ARRAY[0..80] OF CHAR;
  1726. 1258 Dir : FIO.DirEntry;
  1727. 1259 BEGIN
  1728. 1260 State := TxInit;
  1729. 1261 SeqNo := 0;
  1730. 1262 LOOP
  1731. 1263 IF FTSupport.AbortRequested() THEN RETURN(ERROR) END;
  1732. 1264 CASE State OF
  1733. 1265 TxInit : IF NOT GetPath(Wild,Path) THEN
  1734. 1266 RETURN(ERROR);
  1735. 1267 END;
  1736. 1268 GotFile := FIO.ReadFirstEntry(Wild,FIO.FileAttr{},Dir);
  1737. 1269 IF NOT GotFile THEN
  1738. 1270 Error("No Matching Files");
  1739. 1271 RETURN ERROR;
  1740. 1272 END;
  1741. 1273 Str.Copy(FTSupport.FileSpec,Dir.Name);
  1742. 1274 State:=TxSendInit; |
  1743. 1275 TxSendInit : IF SendMyParams() # ACK THEN
  1744. 1276 RETURN(ERROR);
  1745. 1277 END;
  1746. 1278 State:=TxSendHdr; |
  1747. 1279 TxSendHdr : FTSupport.Transferred:=0;
  1748. 1280 IF SendFileHeader(Path) # ACK THEN
  1749. 1281 RETURN(ERROR);
  1750. 1282 END;
  1751. 1283 State := TxSendData; |
  1752. 1284 TxSendData : IF SendFileData()=ERROR THEN
  1753. 1285 RETURN(ERROR);
  1754. 1286 END;
  1755. 1287 State := TxSendEOF; |
  1756. 1288 TxSendEOF : IF SendMessage(EOFILE,0) # ACK THEN
  1757. 1289 RETURN(ERROR);
  1758. 1290 END;
  1759. 1291 FIO.Close(f);
  1760. 1292 Msg(FileClosed);
  1761. 1293 GotFile := FIO.ReadNextEntry(Dir);
  1762. 1294 IF GotFile THEN
  1763. 1295 State:=TxSendHdr;
  1764. 1296 ELSE
  1765. 1297 State:=TxEndSess;
  1766. 1298 END;
  1767. 1299 Str.Copy(FTSupport.FileSpec,Dir.Name); |
  1768. 1300 TxEndSess : IF SendMessage(ENDSESS,0) # ACK THEN
  1769. 1301 RETURN(ERROR);
  1770. 1302 END;
  1771. 1303 Msg(EndSession);
  1772. 1304 RETURN OK; |
  1773. 1305 END;
  1774. 1306 END;
  1775. 1307 END TxStateMachine;
  1776. 1308
  1777. 1309 (*...............................................*)
  1778. 1310
  1779. 1311 PROCEDURE KermitSend(wild:ARRAY OF CHAR):CARDINAL;
  1780. 1312 VAR
  1781. 1313 rslt : CARDINAL;
  1782. 1314 BEGIN
  1783. 1315 InitVars;
  1784. 1316 FTSupport.OpenStatusWindow('SuperKermit Upload');
  1785. 1317 rslt := TxStateMachine(wild);
  1786. 1318 IF rslt=ERROR THEN
  1787. 1319 SendPacket(ERROR,SeqNo,0);
  1788. 1320 END;
  1789. 1321 FIO.Close(f);
  1790. 1322 FTSupport.CloseStatusWindow;
  1791. 1323 RETURN rslt;
  1792. 1324 END KermitSend;
  1793. 1325
  1794. 1326 (*...............................................*)
  1795. 1327
  1796. 1328 END Kermit.
  1797. 1329
  1798. 467 errors