util: parseline can return error, unsigned int -> int
This commit is contained in:
parent
5c8840493f
commit
02f91017fd
30
util.c
30
util.c
|
@ -56,26 +56,30 @@ printlink(const char *link, const char *baseurl, FILE *fp)
|
|||
* 'fields' is a list of pointer with a maximum size of 'maxfields'.
|
||||
* 'line' buffer is allocated using malloc, 'size' will contain the
|
||||
* allocated buffer size.
|
||||
* returns: amount of fields read. */
|
||||
unsigned int
|
||||
* returns: amount of fields read or -1 on error. */
|
||||
int
|
||||
parseline(char **line, size_t *size, char **fields,
|
||||
unsigned int maxfields, int separator, FILE *fp)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
char *prev, *s;
|
||||
unsigned int i;
|
||||
|
||||
if(getline(line, size, fp) > 0) {
|
||||
for(prev = *line; (s = strchr(prev, separator)) && i <= maxfields; i++) {
|
||||
*s = '\0';
|
||||
fields[i] = prev;
|
||||
prev = s + 1;
|
||||
}
|
||||
if(getline(line, size, fp) <= 0)
|
||||
return -1;
|
||||
|
||||
for(prev = *line, i = 0;
|
||||
(s = strchr(prev, separator)) && i <= maxfields;
|
||||
i++) {
|
||||
*s = '\0';
|
||||
fields[i] = prev;
|
||||
/* make non-parsed fields empty. */
|
||||
for(i++; i < maxfields; i++)
|
||||
fields[i] = "";
|
||||
prev = s + 1;
|
||||
}
|
||||
return i;
|
||||
fields[i++] = prev;
|
||||
/* make non-parsed fields empty. */
|
||||
for(; i < maxfields; i++)
|
||||
fields[i] = "";
|
||||
|
||||
return (int)i;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
2
util.h
2
util.h
|
@ -23,7 +23,7 @@ enum { FieldUnixTimestamp = 0, FieldTimeFormatted, FieldTitle, FieldLink,
|
|||
FieldContent, FieldContentType, FieldId, FieldAuthor, FieldFeedType,
|
||||
FieldFeedName, FieldFeedUrl, FieldBaseSiteUrl, FieldLast };
|
||||
|
||||
unsigned int parseline(char **, size_t *, char **, unsigned int, int, FILE *);
|
||||
int parseline(char **, size_t *, char **, unsigned int, int, FILE *);
|
||||
void printfeednameid(const char *, FILE *);
|
||||
void printhtmlencoded(const char *, FILE *);
|
||||
void printlink(const char *, const char *, FILE *);
|
||||
|
|
Loading…
Reference in New Issue