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

Asterisk Bug Tracker noreply at bugs.digium.com
Thu May 27 10:34:35 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-27 10:34 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
====================================================================== 

---------------------------------------------------------------------- 
 (0122563) tilghman (administrator) - 2010-05-27 10:34
 https://issues.asterisk.org/view.php?id=16461#c122563 
---------------------------------------------------------------------- 
These examples are commented incorrectly (reason in parentheses):

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

; Replace 10 chars beginning at the 20th of the file with "bar" (0-based
offsets)
Set(FILE(/tmp/foo.txt,19,10)=bar)
 
; Replace all chars from the 20th, up until the second to last with "bar"
(0-based offsets)
Set(FILE(/tmp/foo.txt,19,-1)=bar)

To do this, I would recommend the following syntax:
; reads the last three lines of the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,L-3)})
 
Negative numbers generally mean "take back from the end".  See variable
substitution, which does this already.

I just realized that truncating the file can actually be written much
simpler:
Set(FILE(/tmp/foo.txt)=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). 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-05-27 10:34 tilghman       Note Added: 0122563                          
======================================================================




More information about the asterisk-bugs mailing list