[asterisk-bugs] [Asterisk 0016461]: [patch] for reading and writing to text file
Asterisk Bug Tracker
noreply at bugs.digium.com
Thu May 27 04:48:37 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 04:48 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
======================================================================
----------------------------------------------------------------------
(0122548) skyman (reporter) - 2010-05-27 04:48
https://issues.asterisk.org/view.php?id=16461#c122548
----------------------------------------------------------------------
I have not done the "replace" just "write" and "append". I change to the
"replace".
I propose that :
Read mode (char) :
------------------
;reads the the entire content of the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt)})
;reads the 10th to end of file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,10)})
;reads the 10th to 19th character in the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,10,20)})
Read mode (Line) :
------------------
; reads the 3th line of the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3,L1)})
; reads the 3th and 4th line of the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3,L2)})
; reads all lines of the file from the third .
exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3)})
; reads the last three lines of the file.
exten => s,1,Set(foo=${FILE(/tmp/test.txt,L-1,L3)})
Replace mode (char) :
---------------------
; Replace the first char of the file with "bar"
Set(FILE(/tmp/foo.txt,1,1)=bar)
; Replace 10 chars begining at the 19th of the file with "bar"
Set(FILE(/tmp/foo.txt,19,10)=bar)
; Replace all chars from the 19th with "bar"
Set(FILE(/tmp/foo.txt,19,-1)=bar)
; Append "bar"
Set(FILE(/tmp/foo.txt,-1)=bar)
Replace mode (Line) :
---------------------
; Replace the first line of the file with "bar"
Set(FILE(/tmp/foo.txt,L1,L1)=bar)
; Replace the last line of the file with "bar"
Set(FILE(/tmp/foo.txt,L-1,L1)=bar)
; Append "bar" to the file + a newline
Set(FILE(/tmp/foo.txt,L0)=bar)
I think it's better like that :
Set(FILE(/tmp/foo.txt,L-1)=bar)
and/or
Set(FILE(/tmp/foo.txt,L-1,L0)=bar)
for the last example
; Tricky: truncate the file and write "bar" to the file (simply, replace
lines 1-999999 with "bar")
Set(FILE(/tmp/foo.txt,L1,L999999)=bar)
I think it's better like that :
Set(FILE(/tmp/foo.txt,L1,L-1)=bar)
and/or
Set(FILE(/tmp/foo.txt,L0,L-1)=bar)
your opinion ?
Issue History
Date Modified Username Field Change
======================================================================
2010-05-27 04:48 skyman Note Added: 0122548
======================================================================
More information about the asterisk-bugs
mailing list