[asterisk-bugs] [Asterisk 0016461]: [patch] for reading and writing to text file

Asterisk Bug Tracker noreply at bugs.digium.com
Mon May 31 06:19:38 CDT 2010


A NOTE has been added to this issue. 
====================================================================== 
https://issues.asterisk.org/view.php?id=16461 
====================================================================== 
Reported By:                skyman
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   16461
Category:                   Functions/NewFeature
Reproducibility:            N/A
Severity:                   feature
Priority:                   normal
Status:                     feedback
Asterisk Version:           1.6.1.11 
JIRA:                       SWP-1478 
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2009-12-17 09:55 CST
Last Modified:              2010-05-31 06:19 CDT
====================================================================== 
Summary:                    [patch] for reading and writing to text file
Description: 
this patch adds 7 functions in func_env :
FILE_FORMAT
FILE_COUNT_LINE
FILE_READ_LINE
FILE_WRITE
FILE_WRITE_LINE
FILE_APPEND
FILE_APPEND_LINE
====================================================================== 

---------------------------------------------------------------------- 
 (0122658) skyman (reporter) - 2010-05-31 06:19
 https://issues.asterisk.org/view.php?id=16461#c122658 
---------------------------------------------------------------------- 
Sorry, i write comments to quicly
But, I suggest another approach :

;reads the 10th to end of file (1-based offsets, 9th to end in 0-based).
exten => s,1,Set(foo=${FILE(/tmp/test.txt,10)})
 
;reads the 10th to 29th character in the file (9 to 28 0-based).
exten => s,1,Set(foo=${FILE(/tmp/test.txt,10,20)})

; Replace 10 chars beginning at the 19th of the file with "bar" (1-based
offsets)
Set(FILE(/tmp/foo.txt,19,10)=bar)

; Replace all chars from the 19th to last with "bar"
(1-based offsets)
Set(FILE(/tmp/foo.txt,19,-1)=bar)


I stand by my suggestion that appending to the file use the L0 line
specification, or if you think it's more clear, L-0 (take back 0 lines
from
the end). 

I prefer to keep L-1 for add a line :
exten => s,1,Set(${FILE(/tmp/test.txt,L-1)}=bar)

And to add a string :
exten => s,1,Set(${FILE(/tmp/test.txt,-1)}=bar)


I reserved the '0' for 'begin of file' :
; truncate the file and write 'bar'
Set(FILE(/tmp/foo.txt)=bar)

; equivalent to
Set(FILE(/tmp/foo.txt,L0)=bar) 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-05-31 06:19 skyman         Note Added: 0122658                          
======================================================================




More information about the asterisk-bugs mailing list