{ TASFIX } (* Les Walters 0954-81036 Tasfix.exe is a small utility to modify files downloaded from the Z88 to a PC via Laplink. A problem arises where the first character of each line is lost when loaded into TASWORD. Tasfix solves this problem by inserting a Linefeed charcter {10} after each carrige return {13} If an error ocurs during execution the program will halt and set the DOS errorlevel to 1 ( for use in batch files ) Running TASFIX Tasfix should normally be invoked with two command line parameters . eg TASFIX [ infile outfile ] where infile is the file transfered from the Z88 and outfile is the file for use by TASWORD. NOTE infile and outfile must be valid filenames and must be different. Wild cards (* ? ) are not allowed. If a third paramater eg TASFIX [Infile outfile anything] specifies that the file will be printed on screen during conversion. NOTE the third parameter can be anything . If no parameters are specified then the user will be prompted for Infile and Outfile and reminded to use the command line option. TASFIX ? from the dos command line will provide a limmited degree of help. *) uses crt,dos; var screen,infile,outfile:text; j,k,l,item:integer; p1,p2,p3,{ comand line parameters} timenow,today,ts:string; hour, minute,second,s100:word; dodump:boolean; procedure gettoday; var s1,s2:string; year,month,day,dayofweek : word; begin getdate(year,month,day,dayofweek); str(year:5,s1); today := s1; str(month :3,s1); today:= s1+today; str(day :3,s1); today:= s1 + today; end;{gettoday} procedure gettimenow(var now:string); var s:string; begin; gettime( hour,minute,second,s100); str(hour:3,s); now := s; str(minute:3,s); now := now + s; str(second:3,s); now := now + s; str(s100:4,s); now :=now+s; timenow:= today + ' : '+ now; end; Procedure Instruct(s:string);{write informer top left} var x,y:integer; begin; x:= wherex;y := wherey; gotoxy( 1,1); write(s:80); gotoxy(x,y); end; procedure togglebool(var bool:boolean); {toggle the value } var q:boolean; begin; q :=bool; if q =true then bool := false; if q = false then bool := true; { swaps the value passed } end;{togglebool} Procedure readN(prompt:string;var N :integer); var ts,s1, s:string; e,j,x,x1,x2,y,y1 :integer; ch,ch1:char; begin; str(n,s);{ get n into string rep } str(n,ts); x:= wherex;y:= wherey; write(prompt); x1:= wherex;y1:=wherey; write(s); j:= length(s); repeat; ch := readkey; case ch of #0 :begin; ch1 := readkey ;{ get fun keyscase ch } case ch1 of #77: begin; {rt arr } end; #75,#83: begin;delete(s,j,1);;write(chr(8),' '); write(' '); { del} dec(j); end; #82: begin;{ ins} end; #72 : begin; inc(item); {enter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; #80 : begin; dec(item); {enter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; end;{ch1} end; #8: begin;delete(s,j,1); ;write(chr(8),' ');{ del} dec(j); write(' '); end; #27,^M: begin; {enter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; '0'..'9' : begin; inc(j); if s= ts then begin; { first ch } j:= 1; s:= ch; gotoxy(x1,y1); for x2 := 1 to length (ts) do write(' ');{ clear the prev display } { zap s}{ change col } {add char } end;{if} if j > 1 then begin; s:=s+ch; { add char } end; end; end;{case} gotoxy(x1,y1);write(s);{}; val(s,n,e); if n > 0 then begin; str(n,s1); if s1<>s then begin;write(^G); gotoxy(x1,y1); write(' Number to large '); repeat; until keypressed; gotoxy(x1,y1);write(' '); s:= ts; j := length(s); end; end;{n>0} if j < 0 then j := 0; until true = false; end;{readn} procedure readB( prompt:string;var bool:boolean); var x1,y1, x,y : integer; ch : char; begin; x :=wherex; y := wherey; write(prompt); x1:= wherex; y1:= wherey; case bool of true: write( ' YES '); false: write( ' NO '); end;{case} repeat; ch := readkey; { cope with function keys} { flush Kbd buffer and exit } if ch = #0 then begin ch := readkey; ch:= ' '; exit;end; if ch = #27 then exit; gotoxy(x1,y1); if ch <> ^M then togglebool(bool); case bool of true: write( ' YES '); false: write( ' NO '); end;{case} until ch = ^M; gotoxy(x,y); end;{readB} procedure ReadS( prompt:string; var S:string); var j,k,i,x1,y1,x2,x,y : integer; ts :string; ch,ch1:char; begin; x:=wherex;y:=wherey; write(prompt); ts:= S; x1 := wherex;y1:=wherey; write(s); j:= length(s); repeat; ch := readkey; case ch of #0 :begin; ch1 := readkey ;{ get fun keyscase ch } case ch1 of #75: begin; {left arr}delete(s,j,1); dec(j);write(chr(8),' '); write(' ');end; #77: begin; s:= s+ts[length(s)];inc(j);{rt arr } end; #83: begin;delete(s,j,1); { del} dec(j);write(chr(8),' ' ); write(' '); end; #82: begin;{ ins}inc(j); s[j] := ' '; end; #80: begin; inc(item); {inter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; #72 : begin; dec(item); {enter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; end;{ch1} end; #8: begin;delete(s,j,1); { del} dec(j);write(chr(8),' '); write(' '); end; #27,^M: begin; {enter accept current display } gotoxy(x,y);write(prompt,s); {}; gotoxy(x,y); exit; end; ' '..'~' : begin; inc(j); if s= ts then begin; { first ch } j:= 1; s:= ch; gotoxy(x1,y1); { zap s}{ change col } {add char } for x2 := 1 to length (ts) do write(' '); end;{if} if j > 1 then begin; s:=s+ch; { add char } end; end; end;{case} gotoxy(x1,y1);write(s);{}; if j < 1 then j := 1; until true = false; end; procedure Transfer; begin; gettoday; { second check } if p1 = p2 then begin; Writeln(^G, ' Error ..... file names incorrectly defined '); halt(1); end; {$I-} assign(infile,p1); reset(infile); if ioresult <> 0 then begin;writeln(' Error ',^G,p1,' not found '); halt(1);{ signal error to dos } end; assign(outfile,p2); rewrite(outfile); if ioresult <> 0 then begin; Writeln( ' Unable to open ', p2,^G); halt(1); end; writeln; writeln(' Tranfering ', p1,' to ',p2); while not eof(infile) do begin; readln(infile,ts); write(outfile,ts,chr(13),chr(10)); if dodump then writeln(ts); end; close(infile);close(outfile); {$I+} if ioresult = 0 then writeln(p1,' Transfered to Tasword format file ',p2); gettimenow(timenow); writeln( timenow); halt(0); end; Procedure showhelp; begin; clrscr; writeln; writeln(' This is TASFIX [ infile outfile ] '); Writeln(' Tasfix converts files created on the Z88 and tranfered to the PC'); writeln(' to a Tasword readable format '); writeln; writeln(' If called with no parameters the user is prompted for filenames'); writeln(' If called with parameters file transfer is automatic '); writeln(' eg TASFIX Pipdream.doc Tasword.doc '); writeln; writeln(' If a third parameter if specified the file will be shown on screen '); writeln(' Eg TASFIX Pipdream.doc Tasword.doc Anything '); writeln;writeln;writeln; writeln(' This utility was commissioned by Les Walters 0954-81036 '); writeln(' and writen by Jon Prinz 0532-759379 '); writeln;writeln; writeln(' Press any key to return to DOS'); repeat; gettimenow(timenow); instruct( timenow); until keypressed; halt(1); end; Procedure Getnames; const maxitem = 7; var s:string; ch,ch1:char; item,j,y,x:integer; begin; s := 'N'; item := 1; clrscr; gotoxy(1,20); write(' TASFIX ver 1.0 5/3/89'); dodump:= false; gotoxy(1,1); y:=1; gotoxy(1,10); writeln( ' Use the arrow keys to move between items '); writeln( ' to continue '); for item := 0 to 10 do begin; case item of 4: begin; gotoxy(1,item); write(' Infile :' ,p1);end; 5: begin; gotoxy(1,item); write(' Outfile :' ,p2);end; 6: begin; gotoxy(1,item); write(' Show file:' ,dodump);end; 7:begin; gotoxy(1,item); write(' EXIT Y|N -',s);end; end;{case item} end;{ item loop} gettoday; repeat ch := readkey; case ch of #0: { funckey}begin; ch1 := readkey; case ch1 of #72 : dec(item); #80 : inc(item); end;{case} end;{#0} ^M:inc(item); #27: exit; {??} { escape/ exit saving all the data as defaults } end;{case} if item < 4 then item := maxitem; if item > maxitem then item := 4; case item of 4: begin; gotoxy(1,item); instruct(' The Pipe Dream format file name '); reads(' Infile :' ,p1);end; 5: begin; gotoxy(1,item); instruct(' The Tasword format file name '); reads(' Outfile :' ,p2);end; 6: begin; gotoxy(1,item); instruct(' Display the file on screen during conversion '); readB(' Show file:' ,dodump);end; 7:begin; gotoxy(1,item); INstruct(' Enter to continue '); reads(' EXIT Y|N -',s);end; end;{case item} gettimenow(timenow); instruct(timenow); until( s = 'Y') or (s = 'y'); end; Begin; {main} gettoday; { if there are three parameters } dodump := false; if paramstr(3) > '' then dodump := true; p1 := paramstr(1);{ get into string representation for readS } p2 := paramstr(2); p3 := paramstr(3); if( p1 = p2 ) and (p1 > '')then begin; writeln( ' ERROR infilename is the same as outfilename',^G); writeln(p1, ' = ',p2); writeln(' Try again '); halt(1);{ dos exit code = errorlevel = 1 for use by batch file ? } { quits and reports error to DOS } end; if (p1='') then begin; getnames; transfer; halt(0); end; { If there are two parameters} { if there are < 2 paramters } { if p1= ? } if (p1 = '?') OR (p2 = '') then begin; showhelp; halt(0); end; if p1 <> p2 then transfer; { do it } end.