[REBOL] [REBOL] Updating a file as a port Re:(3)

2000-01-26 Thread icimjs

Hi Jim,

>Hi Elan,
>
>Gee, you really just need to open the file with /lines. The default is read 
>and write. ;-)
>

you may want to hint at that in the info returned by help open ;-) 

>> help open
Opens a new port connection.
Arguments:
spec --  (file url port object block)
Refinements:
/binary -- Preserves contents exactly.
/string -- Translates all line terminators.
/direct -- Opens the port without buffering.
/new -- Creates a file. (Need not already exist.)
/read -- Read only. Disables write operations.
/write -- Write only.  Disables read operations.
/wait -- Waits for data.
/lines -- Handles data as lines.
/with -- Specifies alternate line termination.
end-of-line --  (char string)
/allow -- Specifies the protection attributes when created.
access --  (block)
/mode -- Block of above refinements.
args --  (block)
/custom -- Allows special refinements.
params --  (block)

;- Elan >> [: - )]



[REBOL] [REBOL] Updating a file as a port Re:(3)

2000-01-26 Thread icimjs

Hi Jim,

oops, guess I haven't quite outgrown C myself.

At 03:32 PM 1/26/00 -0800, you wrote:
>At 02:17 PM 1/26/00 -0800, you wrote:
>>The /write refinement disables read operations!
>>
>>
>>Solution:
>>
>>Use the /mode refinement with a block [lines read write] like this:
>
>Hi Elan,
>
>Gee, you really just need to open the file with /lines. The default is read 
>and write. ;-)
>
>  - jim
>
>
>
>

;- Elan >> [: - )]



[REBOL] [REBOL] Updating a file as a port Re:(2)

2000-01-26 Thread jimg

At 02:17 PM 1/26/00 -0800, you wrote:
>The /write refinement disables read operations!
>
>
>Solution:
>
>Use the /mode refinement with a block [lines read write] like this:

Hi Elan,

Gee, you really just need to open the file with /lines. The default is read 
and write. ;-)

  - jim




[REBOL] [REBOL] Updating a file as a port Re:

2000-01-26 Thread icimjs

Hi Tim,

1. Your code causes an error, before it completes executing:
>> fp: open/lines/write %test.txt
>>   forall fp
** Script Error: forall expected body argument of type: block.
** Where: forall fp


2. help open states that:
>> help open
Opens a new port connection.
Arguments:
spec --  (file url port object block)
Refinements:
/write -- Write only.  Disables read operations.

The /write refinement disables read operations!


Solution:

Use the /mode refinement with a block [lines read write] like this:

>> print read %test.txt
line one
line two
line three
line five

>> fp: open/mode %test.txt [lines read write]

forall fp [ 
  if found? find first fp "three" [ 
insert next fp "line four" 
  ] 
]
== false
>> update fp
>> close fp
>> print read %test.txt
line one
line two
line three
line four
line five



;- Elan >> [: - )]



[REBOL] [REBOL] Updating a file as a port

2000-01-26 Thread tjohnson

Hello All:
test file is test.txt
contents are:
line one 
line two
line three
line five

;The following code seeks to identify the third line and
;inset a line after it:
fp: open/lines/write %test.txt
  forall fp
  [
if(find first fp "three") ; identify third line
[
  print first fp  ; tell user it's been found
  insert fp "line four"   ; insert?
]
  ]
update fp ; "post"
close fp
;;Two questions:
;; 1)the inserted line ist not being inserted. Why and How?
;; 2)What code can I insert so that rebol will not prompt
;;   for permission.

Thanks
Tim