fileio: add support for quoting to pkg_fgetline().

feature/tap-sh
William Pitcock 2012-07-30 01:53:32 -05:00
parent dde296193f
commit ee2e6054aa
1 changed files with 30 additions and 1 deletions

View File

@ -21,6 +21,7 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
{
char *s = line;
char *end = line + size - 1;
bool quoted = false;
int c = '\0', c2;
if (s == NULL)
@ -28,9 +29,22 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
while (s < end && (c = getc(stream)) != EOF)
{
if (c == '\n')
if (c == '\\')
{
quoted = true;
continue;
}
else if (c == '\n')
{
*s++ = c;
if (quoted)
{
quoted = false;
continue;
}
break;
}
else if (c == '\r')
@ -38,9 +52,24 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
*s++ = '\n';
if ((c2 = getc(stream)) == '\n')
{
if (quoted)
{
quoted = false;
continue;
}
break;
}
ungetc(c2, stream);
if (quoted)
{
quoted = false;
continue;
}
break;
}
else