commit aba5d6fd5232a5aa23a2215ae558efcb7eead9ca Author: Raphaƫl Droz Date: Thu Mar 7 17:52:06 2013 +0100 ldif and vcard parsers: don't return end-of-file as an error and avoid unecessary roundtrips and warnings in writephonebook(). diff --git a/common/ldif.c b/common/ldif.c index 6e40313..aa82fc2 100644 --- a/common/ldif.c +++ b/common/ldif.c @@ -174,7 +174,7 @@ GNOKII_API int gn_ldif2phonebook(FILE *f, gn_phonebook_entry *entry) while (1) { if (!fgets(buf, 1024, f)) - return -1; + return 1; if (BEGINS("dn:")) break; } diff --git a/common/vcard.c b/common/vcard.c index a1887de..937208f 100644 --- a/common/vcard.c +++ b/common/vcard.c @@ -348,7 +348,7 @@ GNOKII_API int gn_vcard2phonebook(FILE *f, gn_phonebook_entry *entry) while (1) { if (!fgets(buf, 1024, f)) - return -1; + return 1; if (BEGINS("BEGIN:VCARD")) break; } diff --git a/gnokii/gnokii-phonebook.c b/gnokii/gnokii-phonebook.c index ba05a23..79f4482 100644 --- a/gnokii/gnokii-phonebook.c +++ b/gnokii/gnokii-phonebook.c @@ -280,6 +280,7 @@ gn_error writephonebook(int argc, char *argv[], gn_data *data, struct gn_statema */ char *line, oline[MAX_INPUT_LINE_LEN]; int i; + int parser_ret_val; struct option options[] = { { "overwrite", 0, NULL, 'o'}, @@ -340,13 +341,17 @@ gn_error writephonebook(int argc, char *argv[], gn_data *data, struct gn_statema entry.location = default_location; switch (type) { case 1: - if (gn_vcard2phonebook(stdin, &entry)) - error = GN_ERR_WRONGDATAFORMAT; + parser_ret_val = gn_vcard2phonebook(stdin, &entry); + if(parser_ret_val < 0) error = GN_ERR_WRONGDATAFORMAT; + else if(parser_ret_val == 1) goto out; // no more entry break; + case 2: - if (gn_ldif2phonebook(stdin, &entry)) - error = GN_ERR_WRONGDATAFORMAT; + parser_ret_val = gn_ldif2phonebook(stdin, &entry); + if(parser_ret_val < 0) error = GN_ERR_WRONGDATAFORMAT; + else if(parser_ret_val == 1) goto out; // no more entry break; + default: if (!gn_line_get(stdin, line, MAX_INPUT_LINE_LEN)) goto out; /* it means we read an empty line, but that's not an error */