home *** CD-ROM | disk | FTP | other *** search
- {@H
- $SYSPROG ON$
- $UCSD ON$
- $RANGE OFF$
- $DEBUG OFF$
- $PARTIAL_EVAL ON$
- $IOCHECK ON$ {@}
-
- { *** See QCAD's "Guide to Pascal Porting" for explanation of the
- [@] notation (really they are curly braces) }
-
- program DIALATE(input, output);
-
- {Maps machine notations around.
- Also maps 'ELSE' to 'OTHERWISE' or vice versa if requested}
-
- const
- NO_MACHINE= 'N';
- HOST_MACHINE= {@H 'H' {@}
- {@T} 'T' {@}
- {@V 'V' {@}
- {@A 'A' {@} ;
- SUFFIX= {@HA '.TEXT' {@}
- {@T} '.PAS' {@}
- {@V '.TXT' {@};
-
- type STRING80 = string[80];
- STRING20 = string[20];
- LONGSTRING = string[255];
- INT = -32767..32767;
-
- var CH: char;
- TO_FILE, FROM_FILE: text;
- TO_HOST, MAP_ELSE, MAP_OTHERWISE, QUIT: boolean;
- MACHINE: char;
- MACH_CHARS: set of char;
- MCHAR: char; {the one we propose to open}
- LINE: longstring;
- OSTR, ESTR: string20;
- LOSTR, LESTR: int;
-
- {**********************}
- {@HAV
- function UPCASE(CH: char): char;
- begin
- if ch in ['a'..'z'] then upcase:=chr(ord(ch)-32)
- else upcase:=ch;
- end;
- {@}
-
- {*********************}
- function RESP(STR: string80): char;
- var CH: char;
- begin
- write(str);
- {@HAV read(input, ch); {@}
- {@T} read(kbd, ch); write(ch); {@}
- resp:=upcase(ch);
- writeln;
- end;
-
- {**********************}
- function YESRESP(STR: string80): boolean;
- begin
- yesresp:=(resp(str) in ['y', 'Y']);
- end;
-
- {***********************}
- function FINDPOS(PAT, STR: longstring; SX: int): int;
- label 99;
- var PX, TSX: int;
- begin
- while sx<length(str)-length(pat) do begin
- px:=1;
- tsx:=sx;
- while (px<=length(pat)) and
- (pat[px]=str[tsx]) do begin
- px:=px+1;
- tsx:=tsx+1;
- end;
- if px>length(pat) then begin
- findpos:=sx;
- goto 99;
- end;
- sx:=sx+1; {try the next position}
- end;
- findpos:=0;
- 99: end;
-
- {*********************}
- procedure MAP(var STR: longstring);
- var PS, FLEN: int;
- CLOSEIT: boolean;
- TSTR: longstring;
- begin
- str:=concat(str, ' '); {add a guard field}
- if machine<>no_machine then begin
- ps:=pos('{@', str);
- if ps>0 then begin
- while ps>0 do begin
- closeit:=false;
- ps:=ps+2;
- if (str[ps]='}') or (str[ps]=' ') then closeit:=true
- else
- repeat
- if (str[ps] = mchar) then closeit:=true;
- ps:=ps+1;
- until (str[ps]='}') or (str[ps]=' ');
- if closeit then str[ps]:='}' else str[ps]:=' ';
- ps:=ps+1;
- ps:=findpos('{@', str, ps); {look for another one}
- end
- end
- end;
- if map_else then begin
- ps:=pos(estr, str);
- if ps>0 then begin
- tstr:=concat(copy(str, 1, ps-1), ostr,
- copy(str, ps+lestr, length(str)-ps-lestr+1));
- str:=tstr;
- end
- end;
- if map_otherwise then begin
- ps:=pos(ostr, str);
- if ps>0 then begin
- tstr:=concat(copy(str, 1, ps-1), estr,
- copy(str, ps+lostr, length(str)-ps-lostr+1));
- str:=tstr;
- end
- end;
- if str[length(str)]=' ' then str[0]:=pred(str[0]);
- end;
-
- {*************************}
- procedure MAPIT;
- begin
- while not(eof(from_file)) do begin
- readln(from_file, line);
- map(line);
- writeln(to_file, line);
- end
- end;
-
- {@H $IOCHECK OFF$ {@}
- {$I-}
- {*****************************}
- function OPENFILES: boolean;
- label 1, 2, 99;
- var FNAME: string80;
- begin
- openfiles:=false;
- 2:
- write('FROM file name? ');
- readln(fname);
- if length(fname)=0 then goto 99;
- if not(fname[length(fname)] in [':', '.']) then
- fname:=fname+suffix;
- {@T} assign(from_file, fname); {@}
- reset(from_file {@HA , fname {@} );
- if ioresult<>0 then begin
- writeln('Unable to open ', fname);
- goto 2;
- end;
- 1:
- write('TO file name? ');
- readln(fname);
- if length(fname)=0 then goto 99;
- if not(fname[length(fname)] in [':', '.']) then
- fname:=fname+suffix;
- {@T} assign(to_file, fname); {@}
- rewrite(to_file {@HA , fname {@} );
- if ioresult<>0 then begin
- writeln('Unable to open ', fname);
- goto 1;
- end;
- openfiles:=true;
- 99:
- end;
-
- {************************}
- procedure CLOSEFILES;
- begin
- close(from_file);
- close(to_file {@H ,'LOCK' {@}
- {@A , LOCK {@});
- if ioresult<>0 then writeln('Unable to close TO_FILE');
- end;
- {@H $IOCHECK ON$ {@}
- {$I+}
-
- {*********************}
- procedure CHECK(var M: char);
- begin
- m:=upcase(m);
- if not(m in mach_chars) then begin
- writeln('machine ', m, ' unrecognized');
- m:= no_machine;
- end
- end;
-
- {**********************}
- procedure SET_ELSE;
- begin {Turbo is the only machine that requires 'ELSE' in a
- case statement. All others require 'OTHERWISE'}
- if machine=no_machine then begin
- map_else:=false;
- map_otherwise:=false;
- end
- else begin
- map_otherwise:=(to_host and (host_machine='T')) or
- (not(to_host) and (machine='T'));
- {otherwise --> else}
- map_else:=not(map_otherwise);
- end
- end;
-
- {******************}
- procedure OPTIONS;
- var MORE: boolean;
-
- procedure SHOW_HELP;
- begin
- writeln;
- writeln('DIALATE is used to translate Pascals on different machines,');
- writeln('currently: Turbo/MS-DOS, VAX/VMS, Apple Macintosh, HP Pascal.');
- writeln;
- writeln('TO: sets translation path host => target machine');
- writeln('FROM: sets translation path target machine => host');
- writeln('MACHINE: sets target machine to one listed above');
- writeln('CONTINUE: finishes setup');
- writeln;
- writeln('After selecting CONTINUE, you will then be asked for the');
- writeln('input and output file names. Pressing <ENTER> for the input');
- writeln('name will bring you back to the menu.');
- writeln;
- end;
-
- begin { options }
- more:=true;
- writeln;
- while (more and (not quit)) do
- begin
- if to_host then write(machine) else write('Host');
- write(' --> ');
- if to_host then writeln('host') else writeln(machine);
- case upcase(resp(
- 'T(o/F(rom, M(achine, C(ontinue, H(elp, Q(uit ? ')) of
- 'C': more:=false;
- 'T': to_host:=true;
- 'F': to_host:=false;
- 'M': machine:=resp('T(urbo, V(ax, A(pple, H(P, N(none? ');
- 'H': show_help;
- 'Q': quit := true;
- ELSE ;
- end;
- check(machine);
- set_else;
- if not(more) and
- not(machine in mach_chars) then more:=true;
- end;
- if to_host then mchar:=host_machine
- else mchar:=machine;
- end;
-
- procedure INIT_VARS;
- begin
- map_else:=false;
- map_otherwise:=false;
- to_host := true;
- machine:= no_machine;
- quit := false;
- end;
-
- begin
- writeln('DIALATE Pascal program mapper: host machine ', host_machine);
- mach_chars:=['T', 'V', 'A', 'H', no_machine];
- estr:=concat(' ELSE', ' ');
- lestr:=length(estr);
- ostr:=concat(' OTHERWISE', ' ');
- lostr:=length(ostr);
- init_vars;
- repeat
- options;
- if (not quit) then
- while openfiles do begin mapit; closefiles; end;
- until quit;
- end.