[asterisk-commits] tilghman: branch tilghman/issue16461 r271624 - in /team/tilghman/issue16461: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 21 16:47:40 CDT 2010
Author: tilghman
Date: Mon Jun 21 16:47:35 2010
New Revision: 271624
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=271624
Log:
More tests, add missing 'd' option for writeline mode
Modified:
team/tilghman/issue16461/funcs/func_env.c
team/tilghman/issue16461/tests/test_func_file.c
Modified: team/tilghman/issue16461/funcs/func_env.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/issue16461/funcs/func_env.c?view=diff&rev=271624&r1=271623&r2=271624
==============================================================================
--- team/tilghman/issue16461/funcs/func_env.c (original)
+++ team/tilghman/issue16461/funcs/func_env.c Mon Jun 21 16:47:35 2010
@@ -92,6 +92,9 @@
</option>
<option name="a">
<para>In write mode only, the append option is used to append to the end of the file, instead of overwriting the existing file.</para>
+ </option>
+ <option name="d">
+ <para>In write mode and line mode only, the delete option is used to eliminate a line, instead of setting it to blank.</para>
</option>
</optionlist>
</parameter>
@@ -1005,26 +1008,31 @@
fseeko(ff, offset_offset, SEEK_SET);
if (fwrite(value, 1, vlength, ff) < vlength) {
ast_log(LOG_ERROR, "Short write?!!\n");
- } else if (fwrite(format2term(newline_format), 1, strlen(format2term(newline_format)), ff) < strlen(format2term(newline_format))) {
+ } else if (!strchr(args.options, 'd') && fwrite(format2term(newline_format), 1, strlen(format2term(newline_format)), ff) < strlen(format2term(newline_format))) {
ast_log(LOG_ERROR, "Short write?!!\n");
}
fclose(ff);
- } else if (length_offset - offset_offset > vlength + strlen(format2term(newline_format))) {
+ } else if (length_offset - offset_offset > vlength + (strchr(args.options, 'd') ? 0 : strlen(format2term(newline_format)))) {
/* More complex case - need to shorten file */
+ off_t cur;
fseeko(ff, offset_offset, SEEK_SET);
if (fwrite(value, 1, vlength, ff) < vlength) {
ast_log(LOG_ERROR, "Short write?!!\n");
fclose(ff);
return -1;
- }
- while (ftello(ff) < flength) {
+ } else if (!strchr(args.options, 'd') && fwrite(format2term(newline_format), 1, strlen(format2term(newline_format)), ff) < strlen(format2term(newline_format))) {
+ ast_log(LOG_ERROR, "Short write?!!\n");
+ fclose(ff);
+ return -1;
+ }
+ while ((cur = ftello(ff)) < flength) {
fseek(ff, length_offset - offset_offset, SEEK_CUR);
if (fread(fbuf, 1, sizeof(fbuf), ff) < sizeof(fbuf)) {
ast_log(LOG_ERROR, "Short read?!!\n");
fclose(ff);
return -1;
}
- fseek(ff, offset_offset - length_offset, SEEK_CUR);
+ fseek(ff, cur + offset_offset - length_offset, SEEK_SET);
if (fwrite(fbuf, 1, sizeof(fbuf), ff) < sizeof(fbuf)) {
ast_log(LOG_ERROR, "Short write?!!\n");
fclose(ff);
@@ -1038,11 +1046,12 @@
fclose(ff);
} else {
/* Most complex case - need to lengthen file */
- off_t lastwritten;
+ size_t vlen = vlength + (strchr(args.options, 'd') ? 0 : strlen(format2term(newline_format)));
int64_t origlen = length_offset - offset_offset;
- fseeko(ff, vlength - origlen, SEEK_END);
+ off_t lastwritten = flength + vlen - origlen;
+ fseeko(ff, vlen - origlen, SEEK_END);
while (offset_offset + sizeof(fbuf) < ftello(ff)) {
- fseeko(ff, -1 * (sizeof(fbuf) + (vlength - origlen)), SEEK_CUR);
+ fseeko(ff, -1 * (sizeof(fbuf) + (vlen - origlen)), SEEK_CUR);
if (fread(fbuf, 1, sizeof(fbuf), ff) < sizeof(fbuf)) {
ast_log(LOG_ERROR, "Short read?!!\n");
fclose(ff);
@@ -1054,8 +1063,8 @@
fclose(ff);
return -1;
}
- }
- lastwritten = ftello(ff) - sizeof(fbuf);
+ lastwritten = ftello(ff) - sizeof(fbuf);
+ }
fseek(ff, length_offset, SEEK_SET);
if (fread(fbuf, 1, sizeof(fbuf), ff) < sizeof(fbuf)) {
ast_log(LOG_ERROR, "Short read?!!\n");
@@ -1067,9 +1076,10 @@
ast_log(LOG_ERROR, "Short write?!!\n");
fclose(ff);
return -1;
- }
- if (fwrite(format2term(newline_format), 1, strlen(format2term(newline_format)), ff) < strlen(format2term(newline_format))) {
+ } else if (!strchr(args.options, 'd') && fwrite(format2term(newline_format), 1, strlen(format2term(newline_format)), ff) < strlen(format2term(newline_format))) {
ast_log(LOG_ERROR, "Short write?!!\n");
+ fclose(ff);
+ return -1;
} else if (fwrite(fbuf, 1, (foplen = lastwritten - ftello(ff)), ff) < foplen) {
ast_log(LOG_ERROR, "Short write?!!\n");
}
Modified: team/tilghman/issue16461/tests/test_func_file.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/issue16461/tests/test_func_file.c?view=diff&rev=271624&r1=271623&r2=271624
==============================================================================
--- team/tilghman/issue16461/tests/test_func_file.c (original)
+++ team/tilghman/issue16461/tests/test_func_file.c Mon Jun 21 16:47:35 2010
@@ -110,6 +110,87 @@
{ "123456789", "0,-8", "fg", "fg23456789" },
{ "123456789", "-9,1", "fg", "fg23456789" },
{ "123456789", "-9,-8", "fg", "fg23456789" },
+ /* Single line replace, same length */
+ { "123\n456\n789\n", "0,1,l", "abc", "abc\n456\n789\n" },
+ { "123\n456\n789\n", "-3,1,l", "abc", "abc\n456\n789\n" },
+ { "123\n456\n789\n", "0,-2,l", "abc", "abc\n456\n789\n" },
+ { "123\n456\n789\n", "-3,-2,l", "abc", "abc\n456\n789\n" },
+ { "123\n456\n789\n", "1,1,l", "abc", "123\nabc\n789\n" },
+ { "123\n456\n789\n", "1,-1,l", "abc", "123\nabc\n789\n" },
+ { "123\n456\n789\n", "-2,1,l", "abc", "123\nabc\n789\n" },
+ { "123\n456\n789\n", "-2,-1,l", "abc", "123\nabc\n789\n" },
+ /* Single line replace, one character short */
+ { "123\n456\n789\n", "0,1,l", "ab", "ab\n456\n789\n" },
+ { "123\n456\n789\n", "-3,1,l", "ab", "ab\n456\n789\n" },
+ { "123\n456\n789\n", "0,-2,l", "ab", "ab\n456\n789\n" },
+ { "123\n456\n789\n", "-3,-2,l", "ab", "ab\n456\n789\n" },
+ { "123\n456\n789\n", "1,1,l", "ab", "123\nab\n789\n" },
+ { "123\n456\n789\n", "1,-1,l", "ab", "123\nab\n789\n" },
+ { "123\n456\n789\n", "-2,1,l", "ab", "123\nab\n789\n" },
+ { "123\n456\n789\n", "-2,-1,l", "ab", "123\nab\n789\n" },
+ /* Single line replace, one character long */
+ { "123\n456\n789\n", "0,1,l", "abcd", "abcd\n456\n789\n" },
+ { "123\n456\n789\n", "-3,1,l", "abcd", "abcd\n456\n789\n" },
+ { "123\n456\n789\n", "0,-2,l", "abcd", "abcd\n456\n789\n" },
+ { "123\n456\n789\n", "-3,-2,l", "abcd", "abcd\n456\n789\n" },
+ { "123\n456\n789\n", "1,1,l", "abcd", "123\nabcd\n789\n" },
+ { "123\n456\n789\n", "1,-1,l", "abcd", "123\nabcd\n789\n" },
+ { "123\n456\n789\n", "-2,1,l", "abcd", "123\nabcd\n789\n" },
+ { "123\n456\n789\n", "-2,-1,l", "abcd", "123\nabcd\n789\n" },
+ /* Multi-line replace, same number of characters, 2 lines for 1 */
+ { "123\n456\n789\n", "0,2,l", "abcdefg", "abcdefg\n789\n" },
+ { "123\n456\n789\n", "-3,2,l", "abcdefg", "abcdefg\n789\n" },
+ { "123\n456\n789\n", "0,-1,l", "abcdefg", "abcdefg\n789\n" },
+ { "123\n456\n789\n", "-3,-1,l", "abcdefg", "abcdefg\n789\n" },
+ { "123\n456\n789\n", "1,2,l", "abcdefg", "123\nabcdefg\n" },
+ { "123\n456\n789\n", "1,,l", "abcdefg", "123\nabcdefg\n" },
+ { "123\n456\n789\n", "-2,2,l", "abcdefg", "123\nabcdefg\n" },
+ { "123\n456\n789\n", "-2,,l", "abcdefg", "123\nabcdefg\n" },
+ /* Multi-line replace, shorter number of characters, 2 lines for 1 */
+ { "123\n456\n789\n", "0,2,l", "abcd", "abcd\n789\n" },
+ { "123\n456\n789\n", "-3,2,l", "abcd", "abcd\n789\n" },
+ { "123\n456\n789\n", "0,-1,l", "abcd", "abcd\n789\n" },
+ { "123\n456\n789\n", "-3,-1,l", "abcd", "abcd\n789\n" },
+ { "123\n456\n789\n", "1,2,l", "abcd", "123\nabcd\n" },
+ { "123\n456\n789\n", "1,,l", "abcd", "123\nabcd\n" },
+ { "123\n456\n789\n", "-2,2,l", "abcd", "123\nabcd\n" },
+ { "123\n456\n789\n", "-2,,l", "abcd", "123\nabcd\n" },
+ /* Multi-line replace, longer number of characters, 2 lines for 1 */
+ { "123\n456\n789\n", "0,2,l", "abcdefghijklmnop", "abcdefghijklmnop\n789\n" },
+ { "123\n456\n789\n", "-3,2,l", "abcdefghijklmnop", "abcdefghijklmnop\n789\n" },
+ { "123\n456\n789\n", "0,-1,l", "abcdefghijklmnop", "abcdefghijklmnop\n789\n" },
+ { "123\n456\n789\n", "-3,-1,l", "abcdefghijklmnop", "abcdefghijklmnop\n789\n" },
+ { "123\n456\n789\n", "1,2,l", "abcdefghijklmnop", "123\nabcdefghijklmnop\n" },
+ { "123\n456\n789\n", "1,,l", "abcdefghijklmnop", "123\nabcdefghijklmnop\n" },
+ { "123\n456\n789\n", "-2,2,l", "abcdefghijklmnop", "123\nabcdefghijklmnop\n" },
+ { "123\n456\n789\n", "-2,,l", "abcdefghijklmnop", "123\nabcdefghijklmnop\n" },
+ /* Insert line */
+ { "123\n456\n789\n", "0,0,l", "abcd", "abcd\n123\n456\n789\n" },
+ { "123\n456\n789\n", "-3,0,l", "abcd", "abcd\n123\n456\n789\n" },
+ { "123\n456\n789\n", "1,0,l", "abcd", "123\nabcd\n456\n789\n" },
+ { "123\n456\n789\n", "-2,0,l", "abcd", "123\nabcd\n456\n789\n" },
+ { "123\n456\n789\n", "2,0,l", "abcd", "123\n456\nabcd\n789\n" },
+ { "123\n456\n789\n", "-1,0,l", "abcd", "123\n456\nabcd\n789\n" },
+ { "123\n456\n789\n", "3,0,l", "abcd", "123\n456\n789\nabcd\n" },
+ { "123\n456\n789\n", ",,la", "abcd", "123\n456\n789\nabcd\n" },
+ /* Single line, replace with blank line */
+ { "123\n456\n789\n", "0,1,l", "", "\n456\n789\n" },
+ { "123\n456\n789\n", "-3,1,l", "", "\n456\n789\n" },
+ { "123\n456\n789\n", "0,-2,l", "", "\n456\n789\n" },
+ { "123\n456\n789\n", "-3,-2,l", "", "\n456\n789\n" },
+ { "123\n456\n789\n", "1,1,l", "", "123\n\n789\n" },
+ { "123\n456\n789\n", "1,-1,l", "", "123\n\n789\n" },
+ { "123\n456\n789\n", "-2,1,l", "", "123\n\n789\n" },
+ { "123\n456\n789\n", "-2,-1,l", "", "123\n\n789\n" },
+ /* Single line, delete */
+ { "123\n456\n789\n", "0,1,ld", "", "456\n789\n" },
+ { "123\n456\n789\n", "-3,1,ld", "", "456\n789\n" },
+ { "123\n456\n789\n", "0,-2,ld", "", "456\n789\n" },
+ { "123\n456\n789\n", "-3,-2,ld", "", "456\n789\n" },
+ { "123\n456\n789\n", "1,1,ld", "", "123\n789\n" },
+ { "123\n456\n789\n", "1,-1,ld", "", "123\n789\n" },
+ { "123\n456\n789\n", "-2,1,ld", "", "123\n789\n" },
+ { "123\n456\n789\n", "-2,-1,ld", "", "123\n789\n" },
};
static char *file2display(struct ast_str **buf, ssize_t len, const char *input)
More information about the asterisk-commits
mailing list