aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorMiles Bader2001-10-21 09:21:46 +0000
committerMiles Bader2001-10-21 09:21:46 +0000
commitd097ad5744fa30738e3c5503719677a465cecc67 (patch)
treebe31af72df2857de2539902a2da5f4ea772d38a4 /lib-src
parent71431a0ea1b24f0a69aa840c0aa94c23e88f3c8d (diff)
downloademacs-d097ad5744fa30738e3c5503719677a465cecc67.tar.gz
emacs-d097ad5744fa30738e3c5503719677a465cecc67.zip
(read_c_string_or_comment): Add SAW_USAGE parameter, and implement
scanning for a `usage:' keyword. (scan_c_file): Pass SAW_USAGE argument to read_c_string_or_comment. Don't output a usage-string if there was one in the doc string.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/make-docfile.c77
1 files changed, 68 insertions, 9 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 8a74de40301..ed786b0951e 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -238,16 +238,26 @@ put_char (ch, printflag, bufp, pending_newlines, pending_spaces)
238 character that follows. COMMENT non-zero means skip a comment. If 238 character that follows. COMMENT non-zero means skip a comment. If
239 PRINTFLAG is positive, output string contents to outfile. If it is 239 PRINTFLAG is positive, output string contents to outfile. If it is
240 negative, store contents in buf. Convert escape sequences \n and 240 negative, store contents in buf. Convert escape sequences \n and
241 \t to newline and tab; discard \ followed by newline. */ 241 \t to newline and tab; discard \ followed by newline.
242 If SAW_USAGE is non-zero, then any occurances of the string `usage:'
243 at the beginning of a line will be removed, and *SAW_USAGE set to
244 true if any were encountered. */
242 245
243int 246int
244read_c_string_or_comment (infile, printflag, comment) 247read_c_string_or_comment (infile, printflag, comment, saw_usage)
245 FILE *infile; 248 FILE *infile;
246 int printflag; 249 int printflag;
250 int *saw_usage;
247{ 251{
248 register int c; 252 register int c;
249 unsigned pending_spaces = 0, pending_newlines = 0; 253 unsigned pending_spaces = 0, pending_newlines = 0;
250 char *p = buf; 254 char *p = buf;
255 /* When this keyword occurs at the beginning of a line, we remove it,
256 and set *SAW_USAGE to true. */
257 static char usage_keyword[] = "usage:";
258 /* The current point we've reached in an occurance of USAGE_KEYWORD in
259 the input stream. */
260 char *cur_usage_ptr = usage_keyword;
251 261
252 if (comment) 262 if (comment)
253 { 263 {
@@ -258,6 +268,9 @@ read_c_string_or_comment (infile, printflag, comment)
258 else 268 else
259 c = getc (infile); 269 c = getc (infile);
260 270
271 if (saw_usage)
272 *saw_usage = 0;
273
261 while (c != EOF) 274 while (c != EOF)
262 { 275 {
263 while (c != EOF && (comment ? c != '*' : c != '"')) 276 while (c != EOF && (comment ? c != '*' : c != '"'))
@@ -284,7 +297,52 @@ read_c_string_or_comment (infile, printflag, comment)
284 pending_spaces = 0; 297 pending_spaces = 0;
285 } 298 }
286 else 299 else
287 put_char (c, printflag, &p, &pending_newlines, &pending_spaces); 300 {
301 if (saw_usage
302 && *cur_usage_ptr == c
303 && (cur_usage_ptr > usage_keyword || pending_newlines > 0))
304 /* We might be looking at USAGE_KEYWORD at some point.
305 Keep looking until we know for sure. */
306 {
307 if (*++cur_usage_ptr == '\0')
308 /* Saw the whole keyword. Set *SAW_USAGE to true. */
309 {
310 *saw_usage = 1;
311
312 /* Reset the scanning pointer. */
313 cur_usage_ptr = usage_keyword;
314
315 /* Canonicalize whitespace preceding a usage string. */
316 pending_newlines = 2;
317 pending_spaces = 0;
318
319 /* Skip any whitespace between the keyword and the
320 usage string. */
321 do
322 c = getc (infile);
323 while (c == ' ' || c == '\n');
324
325 continue; /* This just skips the getc at end-of-loop. */
326 }
327 }
328 else
329 {
330 if (cur_usage_ptr > usage_keyword)
331 /* We scanned the beginning of a potential usage
332 keyword, but it was a false alarm. Output the
333 part we scanned. */
334 {
335 char *p;
336 for (p = usage_keyword; p < cur_usage_ptr; p++)
337 put_char (*p, printflag, &p,
338 &pending_newlines, &pending_spaces);
339 cur_usage_ptr = usage_keyword;
340 }
341
342 put_char (c, printflag, &p,
343 &pending_newlines, &pending_spaces);
344 }
345 }
288 346
289 c = getc (infile); 347 c = getc (infile);
290 } 348 }
@@ -507,7 +565,7 @@ scan_c_file (filename, mode)
507 c = getc (infile); 565 c = getc (infile);
508 if (c != '"') 566 if (c != '"')
509 continue; 567 continue;
510 c = read_c_string_or_comment (infile, -1, 0); 568 c = read_c_string_or_comment (infile, -1, 0, 0);
511 569
512 /* DEFVAR_LISP ("name", addr, "doc") 570 /* DEFVAR_LISP ("name", addr, "doc")
513 DEFVAR_LISP ("name", addr /\* doc *\/) 571 DEFVAR_LISP ("name", addr /\* doc *\/)
@@ -555,7 +613,7 @@ scan_c_file (filename, mode)
555 c = getc (infile); 613 c = getc (infile);
556 614
557 if (c == '"') 615 if (c == '"')
558 c = read_c_string_or_comment (infile, 0, 0); 616 c = read_c_string_or_comment (infile, 0, 0, 0);
559 617
560 while (c != EOF && c != ',' && c != '/') 618 while (c != EOF && c != ',' && c != '/')
561 c = getc (infile); 619 c = getc (infile);
@@ -582,6 +640,7 @@ scan_c_file (filename, mode)
582 c == '*'))) 640 c == '*')))
583 { 641 {
584 int comment = c != '"'; 642 int comment = c != '"';
643 int saw_usage;
585 644
586 putc (037, outfile); 645 putc (037, outfile);
587 putc (defvarflag ? 'V' : 'F', outfile); 646 putc (defvarflag ? 'V' : 'F', outfile);
@@ -589,7 +648,7 @@ scan_c_file (filename, mode)
589 648
590 if (comment) 649 if (comment)
591 getc (infile); /* Skip past `*' */ 650 getc (infile); /* Skip past `*' */
592 c = read_c_string_or_comment (infile, 1, comment); 651 c = read_c_string_or_comment (infile, 1, comment, &saw_usage);
593 652
594 /* If this is a defun, find the arguments and print them. If 653 /* If this is a defun, find the arguments and print them. If
595 this function takes MANY or UNEVALLED args, then the C source 654 this function takes MANY or UNEVALLED args, then the C source
@@ -601,7 +660,7 @@ scan_c_file (filename, mode)
601 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword] 660 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
602 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword] 661 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
603 */ 662 */
604 if (defunflag && maxargs != -1) 663 if (defunflag && maxargs != -1 && !saw_usage)
605 { 664 {
606 char argbuf[1024], *p = argbuf; 665 char argbuf[1024], *p = argbuf;
607 666
@@ -1021,7 +1080,7 @@ scan_lisp_file (filename, mode)
1021 buffer, filename); 1080 buffer, filename);
1022 continue; 1081 continue;
1023 } 1082 }
1024 read_c_string_or_comment (infile, 0, 0); 1083 read_c_string_or_comment (infile, 0, 0, 0);
1025 skip_white (infile); 1084 skip_white (infile);
1026 1085
1027 if (saved_string == 0) 1086 if (saved_string == 0)
@@ -1074,7 +1133,7 @@ scan_lisp_file (filename, mode)
1074 saved_string = 0; 1133 saved_string = 0;
1075 } 1134 }
1076 else 1135 else
1077 read_c_string_or_comment (infile, 1, 0); 1136 read_c_string_or_comment (infile, 1, 0, 0);
1078 } 1137 }
1079 fclose (infile); 1138 fclose (infile);
1080 return 0; 1139 return 0;