home *** CD-ROM | disk | FTP | other *** search
- program append (datafile, comfile);
-
- (*
-
- This program illustrates a method of initializing variables
- in Turbo Pascal. It examines a Turbo .com file to find out where
- the program intends to set its data segment register and then
- assumes that the first user variable in the .com file is at the same
- offset in its data segment as the first user variable in Append.
- (That is a fair assumption seeing that you have this source and
- can compile it with the same compiler you use to compile the .com
- file, which you should.)
-
- Having figured out where the .com file's variables will reside,
- Append copies a file of raw data into that spot in the .com file.
- That is a crude way to specify the data--better to read the Turbo source
- and translate {$special comments} next to the variable declarations
- into the data that initializes them. Any takers?
-
- Some limitations: the modified .com file must be smaller than
- 64 K. or it won't run and the whole idea is applicable only to .com
- files; it can't do anything for programs run in Turbo's "run from memory"
- mode.
-
- Calling sequence: APPEND datafile comfile
- where datafile contains the raw data (in order and in the proper format)
- to be appended to comfile. See the example program and data at the end
- of this file.
-
- Rob Steele
- Compuserve 72267,557
-
- *)
-
- var
- first_user_var : byte;
- datafile, comfile : file;
- rtl_end : integer;
- rtl_init_params : array [1..16] of integer;
- temp : ^byte;
-
- begin
- assign (datafile, paramstr(1));
- reset (datafile, 1);
- assign (comfile, paramstr(2));
- reset (comfile, 1);
-
- seek (comfile, 1);
- blockread (comfile, rtl_end, 2);
- seek (comfile, rtl_end + 6);
- blockread (comfile, rtl_init_params, sizeof(rtl_init_params));
- seek (comfile, rtl_init_params [4] shl 4 + ofs(first_user_var) - 256);
-
- getmem (temp, filesize(datafile));
- blockread (datafile, temp^, filesize(datafile));
- blockwrite (comfile, temp^, filesize(datafile));
- close (comfile);
- close (datafile);
- end.
-
-
- (*
- Seperate the following program into a file called test.pas
- and the three lines following that into a file called test.dat.
- Compile test.pas to a .com file and then run Append against it:
-
- append test.dat test.com
- *)
-
- program test (output);
-
- var
- first_line : array [1..32] of char;
- second_line : array [1..58] of char;
- third_line : array [1..68] of char;
-
- begin
- write ('1: ', first_line);
- write ('2: ', second_line);
- write ('3: ', third_line);
- end.
-
-
- This should be the first line.
- This is raw data to initialize the variable second_line.
- Note that text files naturally have a CR and LF between each line.