program DB(input,output); { ----------------------------------------------- } { Program simply constructs an assembler DB file } { from ordinary text input } { } { Call it: } { DB in_file [out_file] } { } { If no out_file is give, it defaults to the name } { of the in_file with extension .DB } { ----------------------------------------------- } const FirstPos = 17; { Start of column for real text } MaxLen = 64; { Max length in assembler line } tab = ^I; CrLf = 'cr,lf'; DefExt = 'DB'; type mode = (r,w); FN = string[ 15]; ext = string[ 3]; LongStr = string[255]; var FIN : FN; FON : FN; fi : text; fo : text; Line : LongStr; procedure Help; Begin writeln('Program simply constructs an assembler DB file'); writeln('from ordinary text input'); writeln; writeln('Call it:'); writeln(' DB in_file [out_file]'); writeln; writeln('If no out_file is give, it defaults to the name'); writeln('of zhe in_file with extension .DB'); Halt; End; procedure Initialize; Begin End; procedure Extension(src:FN;var dst:FN;ex:ext); var p : integer; Begin p:=pos('.',src); if (p=0) then dst:=src else dst:=copy(src,1,pred(p)); dst:=concat(dst,'.',ex); End; procedure open(n:FN;var f:text;m:mode); Begin assign(f,n); {$I-} case m of r : reset(f); w : rewrite(f); end; if NOT (IOResult=0) then begin write('%ERROR: Cannot '); case m of r : write('open'); w : write('create'); end; writeln(' file : ',n); halt; end; {$I+} End; procedure Convert_to_DB(l:LongStr;var f:text); var i : integer; len : integer; p : integer; my_line : LongStr; Begin len:=length(l); if NOT (len=0) then my_line:='''' else my_line:=''; for i:=1 to len do begin if (l[i]=tab) then my_line:=concat(my_line,''',tab,''') else my_line:=concat(my_line+l[i]); if (l[i]='''') then my_line:=concat(my_line,''''); end; if NOT (len=0) then my_line:=concat(my_line,''','); my_line:=concat(my_line,CrLf); while NOT (length(my_line)=0) do begin write(f,tab,'db',tab); p:=length(my_line); if (p > (MaxLen-FirstPos)) then begin p:=MaxLen-FirstPos-1; repeat dec(p); until (my_line[p]=' ') OR (p=0); if (p=0) then p:=MaxLen-FirstPos-1; writeln(f,copy(my_line,1,p),''''); delete(my_line,1,p); my_line:=concat('''',my_line); end else begin writeln(f,my_line); my_line:=''; end; end; End; BEGIN Initialize; case ParamCount of 1 : begin FIN:=ParamStr(1); Extension(FIN,FON,DefExt); end; 2 : begin FIN:=ParamStr(1); FON:=ParamStr(2); end; else Help; end; open(FIN,fi,r); open(FON,fo,w); while not eof(fi) do begin readln(fi,Line); Convert_to_DB(Line,fo); end; close(fi); close(fo); END.