home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / APPEND.ZIP / APPEND.PAS
Encoding:
Pascal/Delphi Source File  |  1986-01-29  |  2.7 KB  |  87 lines

  1. program append (datafile, comfile);
  2.  
  3. (*
  4.  
  5.     This program illustrates a method of initializing variables
  6. in Turbo Pascal.  It examines a Turbo .com file to find out where
  7. the program intends to set its data segment register and then
  8. assumes that the first user variable in the .com file is at the same
  9. offset in its data segment as the first user variable in Append.
  10. (That is a fair assumption seeing that you have this source and
  11. can compile it with the same compiler you use to compile the .com
  12. file, which you should.)
  13.  
  14.     Having figured out where the .com file's variables will reside,
  15. Append copies a file of raw data into that spot in the .com file.
  16. That is a crude way to specify the data--better to read the Turbo source
  17. and translate {$special comments} next to the variable declarations
  18. into the data that initializes them.  Any takers?
  19.  
  20.     Some limitations: the modified .com file must be smaller than
  21. 64 K. or it won't run and the whole idea is applicable only to .com
  22. files; it can't do anything for programs run in Turbo's "run from memory"
  23. mode.
  24.  
  25.     Calling sequence: APPEND datafile comfile
  26. where datafile contains the raw data (in order and in the proper format)
  27. to be appended to comfile.  See the example program and data at the end
  28. of this file.
  29.  
  30.                                  Rob Steele
  31.                                  Compuserve 72267,557
  32.  
  33. *)
  34.  
  35. var
  36.     first_user_var : byte;
  37.     datafile, comfile : file;
  38.     rtl_end : integer;
  39.     rtl_init_params : array [1..16] of integer;
  40.     temp : ^byte;
  41.  
  42. begin
  43.     assign (datafile, paramstr(1));
  44.     reset (datafile, 1);
  45.     assign (comfile, paramstr(2));
  46.     reset (comfile, 1);
  47.  
  48.     seek (comfile, 1);
  49.     blockread (comfile, rtl_end, 2);
  50.     seek (comfile, rtl_end + 6);
  51.     blockread (comfile, rtl_init_params, sizeof(rtl_init_params));
  52.     seek (comfile, rtl_init_params [4] shl 4 + ofs(first_user_var) - 256);
  53.  
  54.     getmem (temp, filesize(datafile));
  55.     blockread (datafile, temp^, filesize(datafile));
  56.     blockwrite (comfile, temp^, filesize(datafile));
  57.     close (comfile);
  58.     close (datafile);
  59. end.
  60.  
  61.  
  62. (*
  63.     Seperate the following program into a file called test.pas
  64. and the three lines following that into a file called test.dat.
  65. Compile test.pas to a .com file and then run Append against it:
  66.  
  67.        append test.dat test.com
  68. *)
  69.  
  70. program test (output);
  71.  
  72. var
  73.     first_line : array [1..32] of char;
  74.     second_line : array [1..58] of char;
  75.     third_line : array [1..68] of char;
  76.  
  77. begin
  78.     write ('1: ', first_line);
  79.     write ('2: ', second_line);
  80.     write ('3: ', third_line);
  81. end.
  82.  
  83.  
  84. This should be the first line.
  85. This is raw data to initialize the variable second_line.
  86. Note that text files naturally have a CR and LF between each line.
  87.