128
129
* Important API note: This function is the core of the implementation of
129
130
* svn_subst_build_keywords (all versions), and as such must implement the
130
* tolerance of NULL and zero inputs that that function's documention
131
* tolerance of NULL and zero inputs that that function's documentation
133
134
* The format codes:
1122
1123
/* skip current EOL */
1123
1124
len += b->eol_str_len;
1125
/* Check 4 bytes at once to allow for efficient pipelining
1126
and to reduce loop condition overhead. */
1127
while ((p + len + 4) <= end)
1129
if (interesting[(unsigned char)p[len]]
1130
|| interesting[(unsigned char)p[len+1]]
1131
|| interesting[(unsigned char)p[len+2]]
1132
|| interesting[(unsigned char)p[len+3]])
1138
/* Found an interesting char or EOF in the next 4 bytes.
1139
Find its exact position. */
1140
while ((p + len) < end && !interesting[(unsigned char)p[len]])
1128
/* Check 4 bytes at once to allow for efficient pipelining
1129
and to reduce loop condition overhead. */
1130
while ((p + len + 4) <= end)
1132
if (interesting[(unsigned char)p[len]]
1133
|| interesting[(unsigned char)p[len+1]]
1134
|| interesting[(unsigned char)p[len+2]]
1135
|| interesting[(unsigned char)p[len+3]])
1141
/* Found an interesting char or EOF in the next 4 bytes.
1142
Find its exact position. */
1143
while ((p + len) < end
1144
&& !interesting[(unsigned char)p[len]])
1149
/* use our optimized sub-routine to find the next EOL */
1150
const char *start = p + len;
1152
= svn_eol__find_eol_start((char *)start, end - start);
1154
/* EOL will be NULL if we did not find a line ending */
1155
len += (eol ? eol : end) - start;
1143
1158
while (b->nl_translation_skippable ==
1144
1159
svn_tristate_true && /* can potentially skip EOLs */
1145
1160
p + len + 2 < end && /* not too close to EOF */
1146
eol_unchanged (b, p + len)); /* EOL format already ok */
1161
eol_unchanged(b, p + len)); /* EOL format already ok */
1148
1163
while ((p + len) < end && !interesting[(unsigned char)p[len]])
1277
1292
svn_stringbuf_setempty(b->readbuf);
1278
1293
b->readbuf_off = 0;
1279
SVN_ERR(svn_stream_read(b->stream, b->buf, &readlen));
1294
SVN_ERR(svn_stream_read_full(b->stream, b->buf, &readlen));
1280
1295
buf_stream = svn_stream_from_stringbuf(b->readbuf, b->iterpool);
1282
1297
SVN_ERR(translate_chunk(buf_stream, b->in_baton, b->buf,
1527
1542
baton->buf = apr_palloc(result_pool, SVN__TRANSLATION_BUF_SIZE);
1529
1544
/* Setup the stream methods */
1530
svn_stream_set_read(s, translated_stream_read);
1545
svn_stream_set_read2(s, NULL /* only full read support */,
1546
translated_stream_read);
1531
1547
svn_stream_set_write(s, translated_stream_write);
1532
1548
svn_stream_set_close(s, translated_stream_close);
1533
1549
svn_stream_set_mark(s, translated_stream_mark);
1699
1715
/* If nothing else worked, write out the internal representation to
1700
a file that can be edited by the user.
1702
### this only writes the first line!
1716
a file that can be edited by the user. */
1704
1717
if (create_using_internal_representation)
1706
apr_file_t *new_file;
1707
SVN_ERR(svn_io_open_unique_file3(&new_file, &dst_tmp,
1708
svn_dirent_dirname(dst, pool),
1709
svn_io_file_del_none,
1712
SVN_ERR(svn_io_file_write_full(new_file,
1713
contents->data, contents->len, NULL,
1716
SVN_ERR(svn_io_file_close(new_file, pool));
1719
svn_stream_t *new_stream;
1722
SVN_ERR(svn_stream_open_unique(&new_stream, &dst_tmp,
1723
svn_dirent_dirname(dst, pool),
1724
svn_io_file_del_none,
1728
svn_stringbuf_appendcstr(contents, "\n");
1729
len = contents->len;
1730
SVN_ERR(svn_stream_write(new_stream, contents->data, &len));
1731
SVN_ERR(svn_stream_copy3(svn_stream_disown(source, pool), new_stream,
1719
1735
/* Do the atomic rename from our temporary location. */
1720
return svn_io_file_rename(dst_tmp, dst, pool);
1736
return svn_error_trace(svn_io_file_rename(dst_tmp, dst, pool));
1765
1781
SVN_ERR(svn_stream_open_readonly(&src_stream, src, pool, pool));
1768
return svn_error_trace(create_special_file_from_stream(src_stream,
1784
SVN_ERR(create_special_file_from_stream(src_stream, dst, pool));
1786
return svn_error_trace(svn_stream_close(src_stream));
1771
1788
/* else !expand */
1836
1853
if (btn->read_stream)
1837
1854
/* We actually found a file to read from */
1838
return svn_stream_read(btn->read_stream, buffer, len);
1855
return svn_stream_read_full(btn->read_stream, buffer, len);
1840
1857
return svn_error_createf(APR_ENOENT, NULL,
1841
"Can't read special file: File '%s' not found",
1858
_("Can't read special file: File '%s' not found"),
1842
1859
svn_dirent_local_style(btn->path, btn->pool));
1925
1942
baton->write_stream = svn_stream_from_stringbuf(baton->write_content, pool);
1927
1944
*stream = svn_stream_create(baton, pool);
1928
svn_stream_set_read(*stream, read_handler_special);
1945
svn_stream_set_read2(*stream, NULL /* only full read support */,
1946
read_handler_special);
1929
1947
svn_stream_set_write(*stream, write_handler_special);
1930
1948
svn_stream_set_close(*stream, close_handler_special);