{ex4.source 00/02/10 nm -e ex4p.debugboo} $pagewidth 120, lines 44$ $standard_level 'os_features'$ $type_coercion 'representation'$ $tables on, statement_number on, code_offsets on$ $list_code on$ $optimize off$ {=============================================================== Disclaimer: This program has several sloppy coding practices that can (and have) led to problems. They were put in to help demonstrate program aborts ... I don't *really* code that way! --------------------------------------------------------------- Note: This program uses PRINT in an effort to avoid using the Pascal/XL I/O package (e.g., writeln). This shortens the amount of code emitted by the compiler, which makes it easier to use as a tool for teaching about Debug. --------------------------------------------------------------- Program description: Open a file, read first record, display it. --------------------------------------------------------------- Exercise 4.1: What filename is the program trying to open? ===============================================================} program ex4; const ccg = 0; ccl = 1; cce = 2; type pac80 = packed array [1..80] of char; var buf : string [80]; c : char; fid : shortint; filename : pac80; inx1 : integer; inx2 : integer; ktr : integer; len : integer; seed : integer; {used to generate "random" number} Procedure fclose; intrinsic; Function fopen : shortint; intrinsic; Function fread : shortint; intrinsic; Procedure print; intrinsic; Procedure terminate; intrinsic; {*************************************************} begin filename := 'abcdefghijklmnopqrstuvwxyz'; seed := 12345; for ktr := 1 to 20 do begin {Calculate two "random" indices (inx1 and inx2)...} seed := (seed div 10) * (seed div 7); inx1 := (seed mod 26) + 1; inx2 := (seed div 26) mod 26 + 1; seed := seed mod 10000; {swap bytes at inx1 and inx2...} c := filename [inx1]; filename [inx1] := filename [inx2]; filename [inx2] := c; end; filename [9] := ' '; fid := fopen (filename, 3, 0); if fid = 0 then begin buf := 'Failed to open file!'; print (buf, -strlen (buf), 0); terminate; end; len := fread (fid, buf, -80); if ccode = cce then begin setstrlen (buf, len); print (buf, -len, 0); end; fclose (fid, 0, 0); fid := 0; end.