[asterisk-bugs] [Asterisk 0016461]: [patch] for reading and writing to text file
Asterisk Bug Tracker
noreply at bugs.digium.com
Wed May 26 11:21:01 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-26 11:21 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
======================================================================
----------------------------------------------------------------------
(0122497) skyman (reporter) - 2010-05-26 11:21
https://issues.asterisk.org/view.php?id=16461#c122497
----------------------------------------------------------------------
I change the "file-format" to reflect the system on which it will be
compiled.
For the ".read2", i do like that ?
static struct ast_custom_function file_function = {
.name = "FILE",
.read2 = file_read
.write = file_write
};
New description of FILE function :
<function name="FILE" language="en_US">
<synopsis>
Read or write file.
</synopsis>
<syntax>
<parameter name="filename" required="true" />
<parameter name="offset" required="true">
<para>reading mode</para>
<para>Maybe specified as any number. If negative,
<replaceable>offset</replaceable> specifies the number
of bytes back from the end of the file.</para>
<para>if the offset is prefixing with the 'L' character, the offset is
to be interpreted as a line number</para>
<para>writing mode</para>
<para>Offset may be one of the following :</para>
<para>w - write (all the previous content will be deleted).</para>
<para>a - the string will be added to the end of file.</para>
</parameter>
<parameter name="length" required="true">
<para>reading mode</para>
<para>If specified, will limit the length of the data read to that
size. If negative,
trims <replaceable>length</replaceable> bytes from the end of the
file.</para>
<para>if the length is prefixing with the 'L' character, the offset is
to be interpreted as a number of lines to be read</para>
<para>writing mode</para>
<para>Length may be one of the following :</para>
<para>0 - write the string only.</para>
<para>1 - write the string and append a newline.</para>
</parameter>
<parameter name="format">
<para>Format may be one of the following :</para>
<para>u - Unix newline format (default except for CYGWIN).</para>
<para>d - Dos newline format (default for CYGWIN).</para>
<para>m - Mac newline format</para>
</parameter>
</syntax>
<description>
<para>Example for read mode :</para>
<para>;reads the 10th to 19th character in the file.</para>
<para>exten => s,1,Set(foo=${FILE(/tmp/test.txt,10,20)})</para>
<para>; reads the 3th line of the file.</para>
<para>exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3,L1)})</para>
<para>; reads the 3th and 4th line of the file.</para>
<para>exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3,L2)})</para>
<para>; reads the 3th line of a DOS formated file.</para>
<para>exten => s,1,Set(foo=${FILE(/tmp/test.txt,L3,L1,d)})</para>
<para></para>
<para>Example for write mode</para>
<para>; append "test" to the file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,a,0)=test)</para>
<para>; append "test" and a Unix newline to the file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,a,1)=test)</para>
<para>; append "test" and a DOS newline to the file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,a,1,d)=test)</para>
<para></para>
<para>; erase all the content of the file and write "test" to the
file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,w,0)=test)</para>
<para>; erase all the content of the file and write "test" with a Unix
(DOS for CYGWIN) newline to the file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,w,1)=test)</para>
<para>; erase all the content of the file and write "test" with a DOS
newline to the file.</para>
<para>exten => s,1,Set(FILE(/tmp/test.txt,w,1,d)=test)</para>
</description>
</function>
It's ok like this ?
Thanks for your help.
Issue History
Date Modified Username Field Change
======================================================================
2010-05-26 11:21 skyman Note Added: 0122497
======================================================================
More information about the asterisk-bugs
mailing list