make-docfile: minor fixes and cleanups
* lib-src/make-docfile.c: Include c-ctype.h. (read_c_string_or_comment, write_c_args, scan_c_stream, skip_white) (read_lisp_symbol, scan_lisp_file): Prefer c_isspace etc. to listing characters by hand. (read_c_string_or_comment): Simplify. (scan_c_stream, read_lisp_symbol): Use true for boolean 1. (scan_c_stream): Fix typo (c >= 'Z' && c <= 'Z'). Minor rewrites to avoid duplicate code. (scan_c_stream, read_lisp_symbol, scan_lisp_file): Avoid infloop if at EOF. (skip_white, read_lisp_symbol): Don’t stuff getc result into ‘char’, as this mishandles EOF.
This commit is contained in:
parent
e58f9a45d6
commit
2038b6a1dd
1 changed files with 54 additions and 41 deletions
|
@ -43,6 +43,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
|||
#include <string.h>
|
||||
|
||||
#include <binary-io.h>
|
||||
#include <c-ctype.h>
|
||||
#include <intprops.h>
|
||||
#include <min-max.h>
|
||||
#include <unlocked-io.h>
|
||||
|
@ -341,7 +342,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state)
|
|||
state->pending_newlines = 2;
|
||||
state->pending_spaces = 0;
|
||||
|
||||
/* Skip any whitespace between the keyword and the
|
||||
/* Skip any spaces and newlines between the keyword and the
|
||||
usage string. */
|
||||
int c;
|
||||
do
|
||||
|
@ -361,6 +362,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state)
|
|||
fatal ("Unexpected EOF after keyword");
|
||||
}
|
||||
while (c != ' ' && c != ')');
|
||||
|
||||
put_char ('f', state);
|
||||
put_char ('n', state);
|
||||
|
||||
|
@ -415,7 +417,7 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment,
|
|||
|
||||
c = getc (infile);
|
||||
if (comment)
|
||||
while (c == '\n' || c == '\r' || c == '\t' || c == ' ')
|
||||
while (c_isspace (c))
|
||||
c = getc (infile);
|
||||
|
||||
while (c != EOF)
|
||||
|
@ -425,15 +427,14 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment,
|
|||
if (c == '\\')
|
||||
{
|
||||
c = getc (infile);
|
||||
if (c == '\n' || c == '\r')
|
||||
switch (c)
|
||||
{
|
||||
case '\n': case '\r':
|
||||
c = getc (infile);
|
||||
continue;
|
||||
case 'n': c = '\n'; break;
|
||||
case 't': c = '\t'; break;
|
||||
}
|
||||
if (c == 'n')
|
||||
c = '\n';
|
||||
if (c == 't')
|
||||
c = '\t';
|
||||
}
|
||||
|
||||
if (c == ' ')
|
||||
|
@ -504,10 +505,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs)
|
|||
char c = *p;
|
||||
|
||||
/* Notice when a new identifier starts. */
|
||||
if ((('A' <= c && c <= 'Z')
|
||||
|| ('a' <= c && c <= 'z')
|
||||
|| ('0' <= c && c <= '9')
|
||||
|| c == '_')
|
||||
if ((c_isalnum (c) || c == '_')
|
||||
!= in_ident)
|
||||
{
|
||||
if (!in_ident)
|
||||
|
@ -550,11 +548,8 @@ write_c_args (char *func, char *buf, int minargs, int maxargs)
|
|||
else
|
||||
while (ident_length-- > 0)
|
||||
{
|
||||
c = *ident_start++;
|
||||
if (c >= 'a' && c <= 'z')
|
||||
/* Upcase the letter. */
|
||||
c += 'A' - 'a';
|
||||
else if (c == '_')
|
||||
c = c_toupper (*ident_start++);
|
||||
if (c == '_')
|
||||
/* Print underscore as hyphen. */
|
||||
c = '-';
|
||||
putchar (c);
|
||||
|
@ -960,7 +955,7 @@ scan_c_stream (FILE *infile)
|
|||
{
|
||||
c = getc (infile);
|
||||
}
|
||||
while (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r');
|
||||
while (c == ',' || c_isspace (c));
|
||||
|
||||
/* Read in the identifier. */
|
||||
do
|
||||
|
@ -972,8 +967,8 @@ scan_c_stream (FILE *infile)
|
|||
fatal ("identifier too long");
|
||||
c = getc (infile);
|
||||
}
|
||||
while (! (c == ',' || c == ' ' || c == '\t'
|
||||
|| c == '\n' || c == '\r'));
|
||||
while (! (c == ',' || c_isspace (c)));
|
||||
|
||||
input_buffer[i] = '\0';
|
||||
memcpy (name, input_buffer, i + 1);
|
||||
|
||||
|
@ -981,7 +976,8 @@ scan_c_stream (FILE *infile)
|
|||
{
|
||||
do
|
||||
c = getc (infile);
|
||||
while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
|
||||
while (c_isspace (c));
|
||||
|
||||
if (c != '"')
|
||||
continue;
|
||||
c = read_c_string_or_comment (infile, -1, false, 0);
|
||||
|
@ -1022,7 +1018,8 @@ scan_c_stream (FILE *infile)
|
|||
int scanned = 0;
|
||||
do
|
||||
c = getc (infile);
|
||||
while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
|
||||
while (c_isspace (c));
|
||||
|
||||
if (c < 0)
|
||||
goto eof;
|
||||
ungetc (c, infile);
|
||||
|
@ -1072,7 +1069,7 @@ scan_c_stream (FILE *infile)
|
|||
int d = getc (infile);
|
||||
if (d == EOF)
|
||||
goto eof;
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
if (c == '*' && d == '/')
|
||||
break;
|
||||
|
@ -1087,13 +1084,14 @@ scan_c_stream (FILE *infile)
|
|||
if (c == EOF)
|
||||
goto eof;
|
||||
}
|
||||
while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
|
||||
while (c_isspace (c));
|
||||
|
||||
/* Check for 'attributes:' token. */
|
||||
if (c == 'a' && stream_match (infile, "ttributes:"))
|
||||
{
|
||||
char *p = input_buffer;
|
||||
/* Collect attributes up to ')'. */
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
c = getc (infile);
|
||||
if (c == EOF)
|
||||
|
@ -1115,7 +1113,7 @@ scan_c_stream (FILE *infile)
|
|||
continue;
|
||||
}
|
||||
|
||||
while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
while (c_isspace (c))
|
||||
c = getc (infile);
|
||||
|
||||
if (c == '"')
|
||||
|
@ -1125,17 +1123,18 @@ scan_c_stream (FILE *infile)
|
|||
c = getc (infile);
|
||||
if (c == ',')
|
||||
{
|
||||
c = getc (infile);
|
||||
while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
do
|
||||
c = getc (infile);
|
||||
while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z'))
|
||||
while (c_isspace (c));
|
||||
|
||||
while (c_isalpha (c))
|
||||
c = getc (infile);
|
||||
if (c == ':')
|
||||
{
|
||||
doc_keyword = true;
|
||||
c = getc (infile);
|
||||
while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
do
|
||||
c = getc (infile);
|
||||
while (c_isspace (c));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1186,8 +1185,14 @@ scan_c_stream (FILE *infile)
|
|||
/* Copy arguments into ARGBUF. */
|
||||
*p++ = c;
|
||||
do
|
||||
*p++ = c = getc (infile);
|
||||
{
|
||||
c = getc (infile);
|
||||
if (c < 0)
|
||||
goto eof;
|
||||
*p++ = c;
|
||||
}
|
||||
while (c != ')');
|
||||
|
||||
*p = '\0';
|
||||
/* Output them. */
|
||||
fputs ("\n\n", stdout);
|
||||
|
@ -1243,25 +1248,32 @@ scan_c_stream (FILE *infile)
|
|||
static void
|
||||
skip_white (FILE *infile)
|
||||
{
|
||||
char c = ' ';
|
||||
while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
||||
int c;
|
||||
do
|
||||
c = getc (infile);
|
||||
while (c_isspace (c));
|
||||
|
||||
ungetc (c, infile);
|
||||
}
|
||||
|
||||
static void
|
||||
read_lisp_symbol (FILE *infile, char *buffer)
|
||||
{
|
||||
char c;
|
||||
int c;
|
||||
char *fillp = buffer;
|
||||
|
||||
skip_white (infile);
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
c = getc (infile);
|
||||
if (c == '\\')
|
||||
*(++fillp) = getc (infile);
|
||||
else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')')
|
||||
{
|
||||
c = getc (infile);
|
||||
if (c < 0)
|
||||
return;
|
||||
*fillp++ = c;
|
||||
}
|
||||
else if (c_isspace (c) || c == '(' || c == ')' || c < 0)
|
||||
{
|
||||
ungetc (c, infile);
|
||||
*fillp = 0;
|
||||
|
@ -1381,7 +1393,7 @@ scan_lisp_file (const char *filename, const char *mode)
|
|||
|
||||
/* Read the length. */
|
||||
while ((c = getc (infile),
|
||||
c >= '0' && c <= '9'))
|
||||
c_isdigit (c)))
|
||||
{
|
||||
if (INT_MULTIPLY_WRAPV (length, 10, &length)
|
||||
|| INT_ADD_WRAPV (length, c - '0', &length)
|
||||
|
@ -1413,7 +1425,7 @@ scan_lisp_file (const char *filename, const char *mode)
|
|||
while (c == '\n' || c == '\r')
|
||||
c = getc (infile);
|
||||
/* Skip the following line. */
|
||||
while (c != '\n' && c != '\r')
|
||||
while (! (c == '\n' || c == '\r' || c < 0))
|
||||
c = getc (infile);
|
||||
}
|
||||
continue;
|
||||
|
@ -1451,7 +1463,7 @@ scan_lisp_file (const char *filename, const char *mode)
|
|||
continue;
|
||||
}
|
||||
else
|
||||
while (c != ')')
|
||||
while (! (c == ')' || c < 0))
|
||||
c = getc (infile);
|
||||
skip_white (infile);
|
||||
|
||||
|
@ -1595,7 +1607,8 @@ scan_lisp_file (const char *filename, const char *mode)
|
|||
}
|
||||
}
|
||||
skip_white (infile);
|
||||
if ((c = getc (infile)) != '\"')
|
||||
c = getc (infile);
|
||||
if (c != '\"')
|
||||
{
|
||||
fprintf (stderr, "## autoload of %s unparsable (%s)\n",
|
||||
buffer, filename);
|
||||
|
|
Loading…
Add table
Reference in a new issue