set-all: do not ignore the last unterminated line

This commit is contained in:
Frédéric Mangano 2013-01-02 10:13:41 +01:00
parent 6f6cf8024b
commit f75e484ebb
2 changed files with 10 additions and 8 deletions

View File

@ -89,10 +89,9 @@ or \fB--set\fP, which, in that case, are equivalent.
.B \-S, \-\-set-all
Sets the tags from scratch. All the original tags are deleted and new ones are
read from \fBstdin\fP. Each line must specify a \fIFIELD=VALUE\fP pair and be
LF-terminated. If the last line isnt terminated when the end of the stream is
reached, it is ignored. Invalid lines are skipped and cause a warning to be
issued. This could be useful for batch processing tags through an utility like
\fBsed\fP.
LF-terminated (except for the last line). Invalid lines are skipped and cause
a warning to be issued. Blank lines are ignored. This mode could be useful for
batch processing tags through an utility like \fBsed\fP.
.SH SEE ALSO
.BR vorbiscomment (1),
.BR sed (1)

View File

@ -379,16 +379,19 @@ int main(int argc, char **argv){
}
else{
char *raw_comment[256];
size_t raw_len = fread(raw_tags, 1, 16384, stdin);
if(raw_len == 16384)
size_t raw_len = fread(raw_tags, 1, 16383, stdin);
if(raw_len == 16383)
fputs("warning: truncating comment to 16 KiB\n", stderr);
raw_tags[raw_len] = '\0';
uint32_t raw_count = 0;
size_t field_len = 0;
int caught_eq = 0;
size_t i = 0;
char *cursor = raw_tags;
for(i=0; i<raw_len && raw_count < 256; i++){
if(raw_tags[i] == '\n'){
for(i=0; i <= raw_len && raw_count < 256; i++){
if(raw_tags[i] == '\n' || raw_tags[i] == '\0'){
if(field_len == 0)
continue;
if(caught_eq)
raw_comment[raw_count++] = cursor;
else