2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
+ * read-md.h (read_char): Increment read_md_lineno after reading '\n'.
+ (unread_char): Decrement read_md_lineno after putting back '\n'.
+ * read-md.c (fatal_with_file_and_line): Push back any characters
+ that we decide not to add to the context.
+ (read_skip_spaces): Don't increment read_md_lineno here. Avoid using
+ fatal_expected_char in cases where '/' ends a line (for example).
+ (read_name): Don't increment read_md_lineno here.
+ (read_escape): Likewise.
+ (read_quoted_string): Likewise.
+ (read_braced_string): Likewise.
+
+2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
+
* Makefile.in (READ_MD_H): Add $(HASHTAB_H).
(build/genconstants.o): Depend on $(READ_MD_H) gensupport.h.
* genconstants.c: Include read-md.h.
if (c == EOF)
break;
if (c == '\r' || c == '\n')
- break;
+ {
+ unread_char (c);
+ break;
+ }
context[i] = c;
}
context[i] = '\0';
c = read_char ();
switch (c)
{
- case '\n':
- read_md_lineno++;
- break;
-
- case ' ': case '\t': case '\f': case '\r':
+ case ' ': case '\t': case '\f': case '\r': case '\n':
break;
case ';':
do
c = read_char ();
while (c != '\n' && c != EOF);
- read_md_lineno++;
break;
case '/':
int prevc;
c = read_char ();
if (c != '*')
- fatal_expected_char ('*', c);
+ {
+ unread_char (c);
+ fatal_with_file_and_line ("stray '/' in file");
+ }
prevc = 0;
while ((c = read_char ()) && c != EOF)
{
- if (c == '\n')
- read_md_lineno++;
- else if (prevc == '*' && c == '/')
+ if (prevc == '*' && c == '/')
break;
prevc = c;
}
if (i == 0)
fatal_with_file_and_line ("missing name or number");
- if (c == '\n')
- read_md_lineno++;
name->buffer[i] = 0;
name->string = name->buffer;
{
/* Backslash-newline is replaced by nothing, as in C. */
case '\n':
- read_md_lineno++;
return;
/* \" \' \\ are replaced by the second character. */
while (1)
{
c = read_char (); /* Read the string */
- if (c == '\n')
- read_md_lineno++;
- else if (c == '\\')
+ if (c == '\\')
{
read_escape ();
continue;
{
c = read_char (); /* Read the string */
- if (c == '\n')
- read_md_lineno++;
- else if (c == '{')
+ if (c == '{')
brace_depth++;
else if (c == '}')
brace_depth--;
static inline int
read_char (void)
{
- return getc (read_md_file);
+ int ch;
+
+ ch = getc (read_md_file);
+ if (ch == '\n')
+ read_md_lineno++;
+ return ch;
}
/* Put back CH, which was the last character read from the MD file. */
static inline void
unread_char (int ch)
{
+ if (ch == '\n')
+ read_md_lineno--;
ungetc (ch, read_md_file);
}