> Some general pointers beyond those I already mentioned:
>
> Define a few syntax reassignments at the top of the DEC Pascal:
>
> {--- Command Substitution ---}
>
> {$define WRITEV WRITESTR}
> {$define READV READSTR}
>
> {--- Type Substitution ---}
>
> {$define uint cardinal}
> {$define sngl single}
> {$define dble double}
> {$define zero(a) DEC_zero(a, #0, sizeof(a))}
>
> {--- File Handling ---}
>
> {$define status(a) IOResult}
> {$define open(a, b) assign(a,b)}
>
> {--- Read enumerated types / booleans from files ---}
>
> {$define readlnenum(a,b,c) readenum(a,b,c);readln(a)}
> {$define readlnbool(a,b) readbool(a,b);readln(a)}
>
> Then create a UNIT for inclusion in the Pascal modules to do some other
> bits:
>
> UNIT OS_linux;
>
> INTERFACE
>
> USES
> const_type;
>
> TYPE
> Tstring = String(2048);
> Pstring = ^String;
>
> FUNCTION LoCaseStr(CONST s : string) : Tstring; asmname
> '_p_locase_str';
> PROCEDURE LoCaseString(VAR s : string); asmname '_p_locase_string';
> PROCEDURE DEC_zero(VAR param; ch : char; size : longint ); asmname
> 'memset';
>
> FUNCTION pad(str : string; fill : char; size : integer) : linestring;
> PROCEDURE linux_reset( VAR ip_file : TEXT);
>
> PROCEDURE ReadBool (VAR f : TEXT; VAR ans : BOOLEAN);
> PROCEDURE ReadEnum (VAR f : TEXT; VAR ans; CONST IDs : ARRAY OF
> PString);
> PROCEDURE WriteEnum (VAR f : TEXT; VAR EnumVal; CONST IDs : ARRAY [m ..
> n : Integer] OF PString);
>
> CONST {This is just an example}
> ModeIDs : ARRAY [0..2] of PString = (@'interactive',
> @'batch',
> @'batch_with_display');
>
> IMPLEMENTATION
> {*************************************************************************
> *******************************************}
> FUNCTION pad(str : STRING; fill : CHAR; size : Integer) : linestring;
>
> VAR
> returned_string : linestring;
> i, len_str : INTEGER;
>
> BEGIN
> returned_string := str;
>
> len_str := length(str);
> IF len_str > 255 THEN
> len_str := 255;
>
> FOR i := (len_str+1) TO size DO
> returned_string := returned_string + fill;
>
> pad := returned_string;
> END;
> {*************************************************************************
> *******************************************}
>
> {*************************************************************************
> *******************************************}
> PROCEDURE linux_reset( VAR ip_file : TEXT);
>
> BEGIN
> {$I-} { Disable I/O error checking }
> reset(ip_file);
> {$I+}
> END;
> {*************************************************************************
> *******************************************}
>
> {*************************************************************************
> *******************************************}
> {*** Enumerated types
> ***}
> {*************************************************************************
> *******************************************}
> PROCEDURE ReadWord (VAR f : TEXT; VAR s : String);
>
> CONST
> SpaceCharacters = [' ',#9];
> WordChars = ['A'..'Z', 'a'..'z', '_', '0'..'9']; {
> Allowed characters }
>
> BEGIN
> s:= '';
> WHILE f^ IN SpaceCharacters DO {
> Skip over whitespace and blank lines }
> IF EOLN(f)
> THEN READLN(f)
> ELSE GET(f);
>
> WHILE NOT EOF (f) AND NOT EOLn (f) AND (f^ IN WordChars) DO {
> Build string from WordChar characters }
> BEGIN
> s:= s + f^;
> GET (f)
> END
> END;
> {*************************************************************************
> *******************************************}
>
> {*************************************************************************
> *******************************************}
> PROCEDURE ReadBool (VAR f : TEXT; VAR ans : BOOLEAN);
>
> VAR s : TString;
>
> BEGIN
> ReadWord (f, s);
> { Read word from text file }
> LoCaseString (s);
> { Change to lower case }
> IF s = 'false' THEN
> { Assign logical based on value }
> ans := FALSE
> ELSE IF s = 'true' THEN
> ans := TRUE
> ELSE
> BEGIN
> writeln('Error reading boolean from file.');
> halt
> END
> END;
> {*************************************************************************
> *******************************************}
>
> {*************************************************************************
> *******************************************}
> PROCEDURE ReadEnum (VAR f : TEXT; VAR ans; CONST IDs : ARRAY OF PString);
>
> TYPE
> enum = (z_a, z_b, z_c, z_d, z_e, z_f, z_g, z_h, z_i, z_j, z_k, z_l,
> z_m); { Dummy enumerated type }
>
> VAR
> s : TString;
> temp : enum;
>
> BEGIN
> ReadWord (f, s); { Read
> word from text file }
> LoCaseString (s); { Change
> to lower case }
> temp:= Low(enum); { Select
> first value }
> WHILE (temp <= enum(High (IDs))) AND { While
> value < max value AND}
> (LoCaseStr (IDs [ord(temp)]^) <> s) DO Inc (temp); {
> string not yet found, increase value}
>
> IF ord(temp) <= High (IDs) { If
> string was found }
> THEN
> enum(ans) := temp { assign
> value to variable }
> ELSE
> BEGIN
> writeln('Error reading enumerated type from file.');
> halt
> END
> END;
> {*************************************************************************
> *******************************************}
>
> {*************************************************************************
> *******************************************}
> PROCEDURE WriteEnum (VAR f : TEXT; VAR EnumVal; CONST IDs : ARRAY [m .. n
> : Integer] OF PString);
>
> TYPE
> enum = (z_a, z_b, z_c, z_d, z_e, z_f, z_g, z_h, z_i, z_j, z_k, z_l,
> z_m); { Dummy enumerated type }
>
> BEGIN
> WRITE (f, IDs [ord(enum(EnumVal))]^)
> END;
> {*************************************************************************
> *******************************************}
> END.
>
> Using {*V*} for DEC syntax and {*L*} for gpc syntax, module headers look
> like this:
>
> {*V*}[INHERIT('gen_lib.pen','globals.pen')]MODULE example_mod;
> {*L*}{MODULE example_mod interface;}
> {*L*}{ export example_mod =(task1);}
> {*L*}{ PROCEDURE task1(request:integer);}
> {*L*}{END.}
>
> {*L*}{MODULE example_mod implementation;}
> {*L*}{#INCLUDE <os_linux.h>}
> {*L*}{USES os_linux, gen_lib, globals;}
> VAR
> ...
> [GLOBAL]PROCEDURE task1(request:integer);
>
> Unit headers look like this:
>
> {*V*}[ENVIRONMENT ('globals.pen')]MODULE globals_mod;
> {*L*}{UNIT globals;}
> {*L*}{#include <os_linux.h>}
> {*L*}{INTERFACE}
>
> VAR
> ...
>
> {*L*}{IMPLEMENTATION}
>
> END.
>
> And some other changes are:
>
> {*V*} a:= ZERO;
> {*L*} zero(a);
> {*V*} a : array [1..3] of double:= ZERO;
> {*L*} a : array [1..3] of double:= (0,0,0);
> {*V*} OPEN(myfile,"filename.dat",ERROR:=CONTINUE, HISTORY:= OLD);
> {*L*} OPEN(myfile,"filename.dat"); linux_reset(myfile);
> {*V*}READLN(myfile,Booleanvar);
> {*L*}READLNBOOL(myfile, Booleanvar);
> {*V*}READLN(myfile,Enumeratedvar);
> {*L*}READLNENUM(myfile, Enumeratedvar, EnumstringIDs);
>
> Where ERROR:=CONTINUE is used with READLN, bracket the READLN with {I-}
> and {I+}. These are compiler directives recognised by GNU Pascal (and
> ignored by DEC Pascal) which disable I/O error checking.
>
> Replace SYS$OUTPUT with /dev/stdout.
> Replace SYS$INPUT with /dev/stdin.
>
> Regards
>
> David Wood
> QinetiQ Farnborough
The Information contained in this E-Mail and any subsequent correspondence
is private and is intended solely for the intended recipient(s).
For those other than the recipient any disclosure, copying, distribution,
or any action taken or omitted to be taken in reliance on such information
is prohibited and may be unlawful.