aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2018-03-01 16:24:41 -0800
committerPaul Eggert2018-03-01 16:25:42 -0800
commit2038b6a1dd2a4a27ac363a0901276255c37e79d8 (patch)
tree03974e4e84353003a72abb8ff446420985f10f8d /lib-src
parente58f9a45d6a31be4ca379e10a866766e0993f49e (diff)
downloademacs-2038b6a1dd2a4a27ac363a0901276255c37e79d8.tar.gz
emacs-2038b6a1dd2a4a27ac363a0901276255c37e79d8.zip
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.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/make-docfile.c95
1 files changed, 54 insertions, 41 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 61d53dc59d6..a5ed6e36071 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -43,6 +43,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
43#include <string.h> 43#include <string.h>
44 44
45#include <binary-io.h> 45#include <binary-io.h>
46#include <c-ctype.h>
46#include <intprops.h> 47#include <intprops.h>
47#include <min-max.h> 48#include <min-max.h>
48#include <unlocked-io.h> 49#include <unlocked-io.h>
@@ -341,7 +342,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state)
341 state->pending_newlines = 2; 342 state->pending_newlines = 2;
342 state->pending_spaces = 0; 343 state->pending_spaces = 0;
343 344
344 /* Skip any whitespace between the keyword and the 345 /* Skip any spaces and newlines between the keyword and the
345 usage string. */ 346 usage string. */
346 int c; 347 int c;
347 do 348 do
@@ -361,6 +362,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state)
361 fatal ("Unexpected EOF after keyword"); 362 fatal ("Unexpected EOF after keyword");
362 } 363 }
363 while (c != ' ' && c != ')'); 364 while (c != ' ' && c != ')');
365
364 put_char ('f', state); 366 put_char ('f', state);
365 put_char ('n', state); 367 put_char ('n', state);
366 368
@@ -415,7 +417,7 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment,
415 417
416 c = getc (infile); 418 c = getc (infile);
417 if (comment) 419 if (comment)
418 while (c == '\n' || c == '\r' || c == '\t' || c == ' ') 420 while (c_isspace (c))
419 c = getc (infile); 421 c = getc (infile);
420 422
421 while (c != EOF) 423 while (c != EOF)
@@ -425,15 +427,14 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment,
425 if (c == '\\') 427 if (c == '\\')
426 { 428 {
427 c = getc (infile); 429 c = getc (infile);
428 if (c == '\n' || c == '\r') 430 switch (c)
429 { 431 {
432 case '\n': case '\r':
430 c = getc (infile); 433 c = getc (infile);
431 continue; 434 continue;
435 case 'n': c = '\n'; break;
436 case 't': c = '\t'; break;
432 } 437 }
433 if (c == 'n')
434 c = '\n';
435 if (c == 't')
436 c = '\t';
437 } 438 }
438 439
439 if (c == ' ') 440 if (c == ' ')
@@ -504,10 +505,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs)
504 char c = *p; 505 char c = *p;
505 506
506 /* Notice when a new identifier starts. */ 507 /* Notice when a new identifier starts. */
507 if ((('A' <= c && c <= 'Z') 508 if ((c_isalnum (c) || c == '_')
508 || ('a' <= c && c <= 'z')
509 || ('0' <= c && c <= '9')
510 || c == '_')
511 != in_ident) 509 != in_ident)
512 { 510 {
513 if (!in_ident) 511 if (!in_ident)
@@ -550,11 +548,8 @@ write_c_args (char *func, char *buf, int minargs, int maxargs)
550 else 548 else
551 while (ident_length-- > 0) 549 while (ident_length-- > 0)
552 { 550 {
553 c = *ident_start++; 551 c = c_toupper (*ident_start++);
554 if (c >= 'a' && c <= 'z') 552 if (c == '_')
555 /* Upcase the letter. */
556 c += 'A' - 'a';
557 else if (c == '_')
558 /* Print underscore as hyphen. */ 553 /* Print underscore as hyphen. */
559 c = '-'; 554 c = '-';
560 putchar (c); 555 putchar (c);
@@ -960,7 +955,7 @@ scan_c_stream (FILE *infile)
960 { 955 {
961 c = getc (infile); 956 c = getc (infile);
962 } 957 }
963 while (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r'); 958 while (c == ',' || c_isspace (c));
964 959
965 /* Read in the identifier. */ 960 /* Read in the identifier. */
966 do 961 do
@@ -972,8 +967,8 @@ scan_c_stream (FILE *infile)
972 fatal ("identifier too long"); 967 fatal ("identifier too long");
973 c = getc (infile); 968 c = getc (infile);
974 } 969 }
975 while (! (c == ',' || c == ' ' || c == '\t' 970 while (! (c == ',' || c_isspace (c)));
976 || c == '\n' || c == '\r')); 971
977 input_buffer[i] = '\0'; 972 input_buffer[i] = '\0';
978 memcpy (name, input_buffer, i + 1); 973 memcpy (name, input_buffer, i + 1);
979 974
@@ -981,7 +976,8 @@ scan_c_stream (FILE *infile)
981 { 976 {
982 do 977 do
983 c = getc (infile); 978 c = getc (infile);
984 while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); 979 while (c_isspace (c));
980
985 if (c != '"') 981 if (c != '"')
986 continue; 982 continue;
987 c = read_c_string_or_comment (infile, -1, false, 0); 983 c = read_c_string_or_comment (infile, -1, false, 0);
@@ -1022,7 +1018,8 @@ scan_c_stream (FILE *infile)
1022 int scanned = 0; 1018 int scanned = 0;
1023 do 1019 do
1024 c = getc (infile); 1020 c = getc (infile);
1025 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 1021 while (c_isspace (c));
1022
1026 if (c < 0) 1023 if (c < 0)
1027 goto eof; 1024 goto eof;
1028 ungetc (c, infile); 1025 ungetc (c, infile);
@@ -1072,7 +1069,7 @@ scan_c_stream (FILE *infile)
1072 int d = getc (infile); 1069 int d = getc (infile);
1073 if (d == EOF) 1070 if (d == EOF)
1074 goto eof; 1071 goto eof;
1075 while (1) 1072 while (true)
1076 { 1073 {
1077 if (c == '*' && d == '/') 1074 if (c == '*' && d == '/')
1078 break; 1075 break;
@@ -1087,13 +1084,14 @@ scan_c_stream (FILE *infile)
1087 if (c == EOF) 1084 if (c == EOF)
1088 goto eof; 1085 goto eof;
1089 } 1086 }
1090 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 1087 while (c_isspace (c));
1088
1091 /* Check for 'attributes:' token. */ 1089 /* Check for 'attributes:' token. */
1092 if (c == 'a' && stream_match (infile, "ttributes:")) 1090 if (c == 'a' && stream_match (infile, "ttributes:"))
1093 { 1091 {
1094 char *p = input_buffer; 1092 char *p = input_buffer;
1095 /* Collect attributes up to ')'. */ 1093 /* Collect attributes up to ')'. */
1096 while (1) 1094 while (true)
1097 { 1095 {
1098 c = getc (infile); 1096 c = getc (infile);
1099 if (c == EOF) 1097 if (c == EOF)
@@ -1115,7 +1113,7 @@ scan_c_stream (FILE *infile)
1115 continue; 1113 continue;
1116 } 1114 }
1117 1115
1118 while (c == ' ' || c == '\n' || c == '\r' || c == '\t') 1116 while (c_isspace (c))
1119 c = getc (infile); 1117 c = getc (infile);
1120 1118
1121 if (c == '"') 1119 if (c == '"')
@@ -1125,17 +1123,18 @@ scan_c_stream (FILE *infile)
1125 c = getc (infile); 1123 c = getc (infile);
1126 if (c == ',') 1124 if (c == ',')
1127 { 1125 {
1128 c = getc (infile); 1126 do
1129 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
1130 c = getc (infile); 1127 c = getc (infile);
1131 while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z')) 1128 while (c_isspace (c));
1129
1130 while (c_isalpha (c))
1132 c = getc (infile); 1131 c = getc (infile);
1133 if (c == ':') 1132 if (c == ':')
1134 { 1133 {
1135 doc_keyword = true; 1134 doc_keyword = true;
1136 c = getc (infile); 1135 do
1137 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
1138 c = getc (infile); 1136 c = getc (infile);
1137 while (c_isspace (c));
1139 } 1138 }
1140 } 1139 }
1141 1140
@@ -1186,8 +1185,14 @@ scan_c_stream (FILE *infile)
1186 /* Copy arguments into ARGBUF. */ 1185 /* Copy arguments into ARGBUF. */
1187 *p++ = c; 1186 *p++ = c;
1188 do 1187 do
1189 *p++ = c = getc (infile); 1188 {
1189 c = getc (infile);
1190 if (c < 0)
1191 goto eof;
1192 *p++ = c;
1193 }
1190 while (c != ')'); 1194 while (c != ')');
1195
1191 *p = '\0'; 1196 *p = '\0';
1192 /* Output them. */ 1197 /* Output them. */
1193 fputs ("\n\n", stdout); 1198 fputs ("\n\n", stdout);
@@ -1243,25 +1248,32 @@ scan_c_stream (FILE *infile)
1243static void 1248static void
1244skip_white (FILE *infile) 1249skip_white (FILE *infile)
1245{ 1250{
1246 char c = ' '; 1251 int c;
1247 while (c == ' ' || c == '\t' || c == '\n' || c == '\r') 1252 do
1248 c = getc (infile); 1253 c = getc (infile);
1254 while (c_isspace (c));
1255
1249 ungetc (c, infile); 1256 ungetc (c, infile);
1250} 1257}
1251 1258
1252static void 1259static void
1253read_lisp_symbol (FILE *infile, char *buffer) 1260read_lisp_symbol (FILE *infile, char *buffer)
1254{ 1261{
1255 char c; 1262 int c;
1256 char *fillp = buffer; 1263 char *fillp = buffer;
1257 1264
1258 skip_white (infile); 1265 skip_white (infile);
1259 while (1) 1266 while (true)
1260 { 1267 {
1261 c = getc (infile); 1268 c = getc (infile);
1262 if (c == '\\') 1269 if (c == '\\')
1263 *(++fillp) = getc (infile); 1270 {
1264 else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')') 1271 c = getc (infile);
1272 if (c < 0)
1273 return;
1274 *fillp++ = c;
1275 }
1276 else if (c_isspace (c) || c == '(' || c == ')' || c < 0)
1265 { 1277 {
1266 ungetc (c, infile); 1278 ungetc (c, infile);
1267 *fillp = 0; 1279 *fillp = 0;
@@ -1381,7 +1393,7 @@ scan_lisp_file (const char *filename, const char *mode)
1381 1393
1382 /* Read the length. */ 1394 /* Read the length. */
1383 while ((c = getc (infile), 1395 while ((c = getc (infile),
1384 c >= '0' && c <= '9')) 1396 c_isdigit (c)))
1385 { 1397 {
1386 if (INT_MULTIPLY_WRAPV (length, 10, &length) 1398 if (INT_MULTIPLY_WRAPV (length, 10, &length)
1387 || INT_ADD_WRAPV (length, c - '0', &length) 1399 || INT_ADD_WRAPV (length, c - '0', &length)
@@ -1413,7 +1425,7 @@ scan_lisp_file (const char *filename, const char *mode)
1413 while (c == '\n' || c == '\r') 1425 while (c == '\n' || c == '\r')
1414 c = getc (infile); 1426 c = getc (infile);
1415 /* Skip the following line. */ 1427 /* Skip the following line. */
1416 while (c != '\n' && c != '\r') 1428 while (! (c == '\n' || c == '\r' || c < 0))
1417 c = getc (infile); 1429 c = getc (infile);
1418 } 1430 }
1419 continue; 1431 continue;
@@ -1451,7 +1463,7 @@ scan_lisp_file (const char *filename, const char *mode)
1451 continue; 1463 continue;
1452 } 1464 }
1453 else 1465 else
1454 while (c != ')') 1466 while (! (c == ')' || c < 0))
1455 c = getc (infile); 1467 c = getc (infile);
1456 skip_white (infile); 1468 skip_white (infile);
1457 1469
@@ -1595,7 +1607,8 @@ scan_lisp_file (const char *filename, const char *mode)
1595 } 1607 }
1596 } 1608 }
1597 skip_white (infile); 1609 skip_white (infile);
1598 if ((c = getc (infile)) != '\"') 1610 c = getc (infile);
1611 if (c != '\"')
1599 { 1612 {
1600 fprintf (stderr, "## autoload of %s unparsable (%s)\n", 1613 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
1601 buffer, filename); 1614 buffer, filename);