+/*-----------------------------------------------------.
+| Do a getc, but give error message if EOF encountered |
+`-----------------------------------------------------*/
+
+int
+xgetc (FILE *f)
+{
+ int c = getc (f);
+ if (c == EOF)
+ fatal (_("unexpected end of file"));
+ return c;
+}
+
+
+/*---------------------------------------------------------------.
+| Read one literal character from FINPUT, process \-escapes, and |
+| return the character. |
+`---------------------------------------------------------------*/
+
+char
+literalchar (void)
+{
+ int c;
+ int res;
+
+ c = xgetc (finput);
+ if (c == '\n')
+ {
+ complain (_("unescaped newline in constant"));
+ ungetc (c, finput);
+ res = '?';
+ }
+ else if (c != '\\')
+ {
+ res = c;
+ }
+ else
+ {
+ c = xgetc (finput);
+ if (c == 't')
+ res = '\t';
+ else if (c == 'n')
+ res = '\n';
+ else if (c == 'a')
+ res = '\007';
+ else if (c == 'r')
+ res = '\r';
+ else if (c == 'f')
+ res = '\f';
+ else if (c == 'b')
+ res = '\b';
+ else if (c == 'v')
+ res = '\013';
+ else if (c == '\\')
+ res = '\\';
+ else if (c == '\'')
+ res = '\'';
+ else if (c == '\"')
+ res = '\"';
+ else if (c <= '7' && c >= '0')
+ {
+ res = 0;
+ while (c <= '7' && c >= '0')
+ {
+ res = (res * 8) + (c - '0');
+ if (res >= 256 || res < 0)
+ {
+ complain (_("octal value outside range 0...255: `\\%o'"),
+ res);
+ res &= 0xFF;
+ break;
+ }
+ c = xgetc (finput);
+ }
+ ungetc (c, finput);
+ }
+ else if (c == 'x')
+ {
+ c = xgetc (finput);
+ res = 0;
+ while (1)
+ {
+ if (c >= '0' && c <= '9')
+ res *= 16, res += c - '0';
+ else if (c >= 'a' && c <= 'f')
+ res *= 16, res += c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ res *= 16, res += c - 'A' + 10;
+ else
+ break;
+ if (res >= 256 || res < 0)
+ {
+ complain (_("hexadecimal value above 255: `\\x%x'"), res);
+ res &= 0xFF;
+ break;
+ }
+ c = xgetc (finput);
+ }
+ ungetc (c, finput);
+ }
+ else
+ {
+ char badchar [] = "c";
+ badchar[0] = c;
+ complain (_("unknown escape sequence: `\\' followed by `%s'"),
+ quote (badchar));
+ res = '?';
+ }
+ } /* has \ */
+
+ return res;
+}
+
+