/* PSPP - a program for statistical analysis.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "gl/c-ctype.h"
#include "gl/c-strcase.h"
+#include "gl/memchr2.h"
enum segmenter_state
{
int ofs;
for (ofs = 2; ofs < n; ofs++)
- if (input[ofs] == '\n')
+ if (input[ofs] == '\n' || input[ofs] == '\0')
{
- if (input[ofs - 1] == '\r')
+ if (input[ofs] == '\n' && input[ofs - 1] == '\r')
ofs--;
s->state = S_GENERAL;
{
for (; ofs < n; ofs++)
{
- if (input[ofs] == '\n')
+ if (input[ofs] == '\n' || input[ofs] == '\0')
return ofs;
else if (input[ofs] == '*')
{
static int
is_end_of_line (const char *input, size_t n, int ofs)
{
- if (input[ofs] == '\n')
+ if (input[ofs] == '\n' || input[ofs] == '\0')
return 1;
else if (input[ofs] == '\r')
{
return is_end_of_line (input, n, ofs);
}
-
static int
segmenter_parse_newline__ (const char *input, size_t n,
enum segment_type *type)
if (mblen < 0)
return -1;
- if (!lex_uc_is_space (uc) || uc == '\n')
+ if (!lex_uc_is_space (uc) || uc == '\n' || uc == '\0')
return ofs;
ofs += mblen;
case '\n':
if (ofs > 1 && input[ofs - 1] == '\r')
ofs--;
-
- if (endcmd == -2)
+ /* Fall through. */
+ case '\0':
+ if (endcmd == -2 || uc == '\0')
{
/* Blank line ends comment command. */
s->state = S_GENERAL;
s->state = end_cmd ? S_DOCUMENT_3 : S_DOCUMENT_2;
return ofs;
+ case '\0':
+ *type = SEG_DOCUMENT;
+ s->state = S_DOCUMENT_3;
+ return ofs;
+
default:
if (!lex_uc_is_space (uc))
end_cmd = false;
case SEG_UNEXPECTED_CHAR:
id[0] = '\0';
return ofs + retval;
-
- case SEG_N_TYPES:
- NOT_REACHED ();
}
ofs += retval;
}
if (mblen < 0)
return -1;
- if (uc == '\n'
+ if (uc == '\n' || uc == '\0'
|| !(lex_uc_is_space (uc) || lex_uc_is_idn (uc) || uc == '-'))
break;
segmenter_parse_full_line__ (const char *input, size_t n,
enum segment_type *type)
{
- const char *newline = memchr (input, '\n', n);
+ const char *newline = memchr2 (input, '\n', '\0', n);
if (newline == NULL)
return -1;
else
{
int ofs = newline - input;
- if (ofs == 0 || (ofs == 1 && input[0] == '\r'))
+ if (*newline == '\0')
+ {
+ assert (ofs > 0);
+ return ofs;
+ }
+ else if (ofs == 0 || (ofs == 1 && input[0] == '\r'))
{
*type = SEG_NEWLINE;
return ofs + 1;
switch (uc)
{
case '\n':
+ case '\0':
s->state = S_GENERAL;
s->substate = 0;
*type = SEG_UNQUOTED_STRING;