home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 13022 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  2.1 KB

  1. Path: sparky!uunet!bonnie.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!casgrain
  2. From: casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Help a beginner programmer
  5. Summary: Quick way to do it
  6. Message-ID: <1992Jul25.172813.26511@cc.umontreal.ca>
  7. Date: 25 Jul 92 17:28:13 GMT
  8. References: <1992Jul23.210503.13778@nntp.uoregon.edu>
  9. Sender: news@cc.umontreal.ca (Administration de Cnews)
  10. Organization: Universite de Montreal
  11. Lines: 60
  12.  
  13. In article <1992Jul23.210503.13778@nntp.uoregon.edu> eric_gorr@coglab_psych.uoregon.edu (Eric Gorr) writes:
  14. >What the procedure needs to do is read FILE #1 and when it hits a line that
  15. >only contains $$INSERT <path:file name> (or something of that nature) will
  16. >then open <path:file name> and will replace $$INSERT <path:file name> with
  17. >the lines of text in <path:file name>.  <path:file name> only contains
  18. >text.  The result of these operation will be saved in FILE #2.  It should
  19. >be able to handle multiple $$INSERT occurances in FILE #1.
  20. >
  21. >So, for example:  
  22. >
  23. >FILE #1:
  24. >aaaaaaaa
  25. >$$INSERT my_file
  26. >bbbbbbbb
  27. >
  28. >my_file:
  29. >cccccccc
  30. >
  31. >FILE #2:
  32. >aaaaaaaa
  33. >cccccccc
  34. >bbbbbbbb
  35.  
  36.     What I would do...
  37.  
  38. Assume 'infile' is file #1, 'outfile' is #2, 'insert' is the file to insert
  39. from.
  40.  
  41. var 
  42.     infile, outfile, insert: Text;
  43.     infileName, outfileName, theText : Str255;
  44.  
  45. function Extract(foobar:Str255; a,b: Integer) : Str255;
  46. begin
  47. { You write a function that returns, in an Str255, the string of }
  48. { chars between foobar[a] and foobar[b]                          }
  49. end;
  50.  
  51. infileName := 'Macintosh HD:My project:My input file';
  52. outfileName := 'Macintosh HD:My Project:Output file';
  53. Reset(infile, infileName);
  54. Rewrite(outfile, outfileName);
  55. while not eof(infile) do begin
  56.     ReadLn(infile, theText);
  57.     if Extract(theText,1,8) = '$$INSERT' then begin
  58.         Reset(insert,Extract(theText,10,StrLenght(theText));
  59.         while not eof(insert) do begin
  60.             Readln(insert, theText);
  61.             WriteLn(outfile, theText);
  62.         end;
  63.         Close(insert);
  64.     end
  65.     else Writeln(outfile, theText);
  66. end;
  67. Close(infile);  Close(outfile);
  68.  
  69. Don't forget to type the full pathnames (folders are separated by colons)!
  70.  
  71. Enjoy,
  72. Philippe Casgrain   Casgrain@ere.umontreal.ca
  73.