Hi Elan:
Thanks for the advice as always, I think I will
email you a little later about what I'm up to in the
big picture.... might interest you.
Let me comment your include code as follows:
I will include entire code and text file at end
of this message.
At 10:48 AM 2/9/00 -0800, you wrote:
>Hi Tim,
>
>why don't you simply use save or write? You don't need to open a port >(fp),
I want to read/write a file on an ftp site. That's a whole
'nother issue, I seem to have turned up some Rebol bugs in
that area, have been dealing with Holger and Help desk,
but as I test I used the port approach..
>just use:
>
>foreach txt insert_txt [
> write/append/lines %some-file.txt txt
>]
>
>and you're done.
>
>insert always inserts at the head of a series, that's why your getting the
>stuff in reverse. If for some reason you prefer using a port, then use
>insert tail like this:
>
>foreach txt insert_txt [
> insert tail fp txt
>]
This actually inserts(appends) the text at the END of the file,
I want to insert it between two markers.
>You can also use append instead of "insert tail".
>
>If you want a newline, this works as well:
>
>foreach txt insert_txt [
> insert tail fp txt
> insert tail fp newline
>]
This generates an error message from rebol:
** Script Error: find expected series argument of type: series
port bitset.
** Where: if find first fp "begin insert here"
>or
>
>foreach txt insert_txt [
> insert tail fp join txt [newline]
>]
This inserts three BLANK lines (carriage returns
only at the END of the file. Again, not what I'm
after
remove-text: func [fp1[file!]] ;[any-type!]]
[
insert_txt: ["first new line" "second new line" "third new line"]
fp: open/lines fp1
remove_flag: false
lines-done: 0
while [ not tail? fp ]
[
if find first fp "begin insert here"
[
print "found"
remove_flag: true
]
either remove_flag
[
either find first fp "end insert here"
[
remove_flag: false
print "done"
foreach txt insert_txt
[
insert tail fp txt
insert tail fp newline
;insert tail fp join txt [newline]
]
;insert first fp insert_txt
fp: next fp
]
[ {else}
either zero? lines-done
[
print "setting lines-done"
lines-done: 1
fp: next fp
]
[ {else}
print ["Removing " first fp]
remove fp
]
]
]
[{else} fp: next fp ]
]
update fp
close fp
]
remove-text %test.txt
;; input test file is as follows
file begins here
<!--begin insert here-->
original line one
original line two
original line three
<!--end insert here-->
file ends here
;; The output that I am looking for would be:
file begins here
<!--begin insert here-->
first new line
second new line
third new line
<!--end insert here-->
file ends here