home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!bonnie.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!casgrain
- From: casgrain@ERE.UMontreal.CA (Casgrain Philippe)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Help a beginner programmer
- Summary: Quick way to do it
- Message-ID: <1992Jul25.172813.26511@cc.umontreal.ca>
- Date: 25 Jul 92 17:28:13 GMT
- References: <1992Jul23.210503.13778@nntp.uoregon.edu>
- Sender: news@cc.umontreal.ca (Administration de Cnews)
- Organization: Universite de Montreal
- Lines: 60
-
- In article <1992Jul23.210503.13778@nntp.uoregon.edu> eric_gorr@coglab_psych.uoregon.edu (Eric Gorr) writes:
- >What the procedure needs to do is read FILE #1 and when it hits a line that
- >only contains $$INSERT <path:file name> (or something of that nature) will
- >then open <path:file name> and will replace $$INSERT <path:file name> with
- >the lines of text in <path:file name>. <path:file name> only contains
- >text. The result of these operation will be saved in FILE #2. It should
- >be able to handle multiple $$INSERT occurances in FILE #1.
- >
- >So, for example:
- >
- >FILE #1:
- >aaaaaaaa
- >$$INSERT my_file
- >bbbbbbbb
- >
- >my_file:
- >cccccccc
- >
- >FILE #2:
- >aaaaaaaa
- >cccccccc
- >bbbbbbbb
-
- What I would do...
-
- Assume 'infile' is file #1, 'outfile' is #2, 'insert' is the file to insert
- from.
-
- var
- infile, outfile, insert: Text;
- infileName, outfileName, theText : Str255;
-
- function Extract(foobar:Str255; a,b: Integer) : Str255;
- begin
- { You write a function that returns, in an Str255, the string of }
- { chars between foobar[a] and foobar[b] }
- end;
-
- infileName := 'Macintosh HD:My project:My input file';
- outfileName := 'Macintosh HD:My Project:Output file';
- Reset(infile, infileName);
- Rewrite(outfile, outfileName);
- while not eof(infile) do begin
- ReadLn(infile, theText);
- if Extract(theText,1,8) = '$$INSERT' then begin
- Reset(insert,Extract(theText,10,StrLenght(theText));
- while not eof(insert) do begin
- Readln(insert, theText);
- WriteLn(outfile, theText);
- end;
- Close(insert);
- end
- else Writeln(outfile, theText);
- end;
- Close(infile); Close(outfile);
-
- Don't forget to type the full pathnames (folders are separated by colons)!
-
- Enjoy,
- Philippe Casgrain Casgrain@ere.umontreal.ca
-