(put_char): New function.
[bpt/emacs.git] / lib-src / make-docfile.c
index 9796db4..8a74de4 100644 (file)
@@ -198,6 +198,42 @@ scan_file (filename)
 \f
 char buf[128];
 
+/* Add CH to either outfile, if PRINTFLAG is positive, or to the buffer
+   whose end is pointed to by BUFP, if PRINTFLAG is negative.
+   If the counters pointed to by PENDING_NEWLINES and PENDING_SPACES are
+   non-zero, that many newlines and spaces are output before CH, and
+   the counters are zeroed.  */
+
+static INLINE void
+put_char (ch, printflag, bufp, pending_newlines, pending_spaces)
+     int ch, printflag;
+     char **bufp;
+     unsigned *pending_newlines, *pending_spaces;
+{
+  int out_ch;
+  do
+    {
+      if (*pending_newlines > 0)
+       {
+         (*pending_newlines)--;
+         out_ch = '\n';
+       }
+      else if (*pending_spaces > 0)
+       {
+         (*pending_spaces)--;
+         out_ch = ' ';
+       }
+      else
+       out_ch = ch;
+
+      if (printflag > 0)
+       putc (out_ch, outfile);
+      else if (printflag < 0)
+       *(*bufp)++ = out_ch;
+    }
+  while (out_ch != ch);
+}
+
 /* Skip a C string or C-style comment from INFILE, and return the
    character that follows.  COMMENT non-zero means skip a comment.  If
    PRINTFLAG is positive, output string contents to outfile.  If it is
@@ -210,6 +246,7 @@ read_c_string_or_comment (infile, printflag, comment)
      int printflag;
 {
   register int c;
+  unsigned pending_spaces = 0, pending_newlines = 0;
   char *p = buf;
 
   if (comment)
@@ -239,14 +276,21 @@ read_c_string_or_comment (infile, printflag, comment)
                c = '\t';
            }
          
-         if (printflag > 0)
-           putc (c, outfile);
-         else if (printflag < 0)
-           *p++ = c;
+         if (c == ' ')
+           pending_spaces++;
+         else if (c == '\n')
+           {
+             pending_newlines++;
+             pending_spaces = 0;
+           }
+         else
+           put_char (c, printflag, &p, &pending_newlines, &pending_spaces);
+
          c = getc (infile);
        }
 
-      c = getc (infile);
+      if (c != EOF)
+       c = getc (infile);
 
       if (comment)
        {
@@ -255,6 +299,8 @@ read_c_string_or_comment (infile, printflag, comment)
              c = getc (infile);
              break;
            }
+         
+         put_char ('*', printflag, &p, &pending_newlines, &pending_spaces);
        }
       else
        {
@@ -395,6 +441,8 @@ scan_c_file (filename, mode)
   c = '\n';
   while (!feof (infile))
     {
+      int doc_keyword = 0;
+
       if (c != '\n' && c != '\r')
        {
          c = getc (infile);
@@ -461,8 +509,9 @@ scan_c_file (filename, mode)
        continue;
       c = read_c_string_or_comment (infile, -1, 0);
 
-      /* DEFVAR_LISP ("name", addr /\* doc *\/)
-        DEFVAR_LISP ("name", addr, doc)  */
+      /* DEFVAR_LISP ("name", addr, "doc")
+        DEFVAR_LISP ("name", addr /\* doc *\/)
+        DEFVAR_LISP ("name", addr, doc: /\* doc *\/)  */
 
       if (defunflag)
        commas = 5;
@@ -501,7 +550,7 @@ scan_c_file (filename, mode)
            goto eof;
          c = getc (infile);
        }
-      
+
       while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
        c = getc (infile);
       
@@ -512,9 +561,18 @@ scan_c_file (filename, mode)
        c = getc (infile);
       if (c == ',')
        {
-          c = getc (infile);
-          while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
-            c = getc (infile);
+         c = getc (infile);
+         while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
+           c = getc (infile);
+         while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z'))
+           c = getc (infile);
+         if (c == ':')
+           {
+             doc_keyword = 1;
+             c = getc (infile);
+             while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
+               c = getc (infile);
+           }
        }
 
       if (c == '"'
@@ -538,13 +596,16 @@ scan_c_file (filename, mode)
             won't give the names of the arguments, so we shouldn't bother
             trying to find them.
 
-            Old:  DEFUN (..., "DOC") (args)
-            New:  DEFUN (..., /\* DOC *\/ (args))  */
+            Various doc-string styles:
+             0: DEFUN (..., "DOC") (args)            [!comment]
+             1: DEFUN (..., /\* DOC *\/ (args))      [comment && !doc_keyword]
+             2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
+         */
          if (defunflag && maxargs != -1)
            {
              char argbuf[1024], *p = argbuf;
 
-             if (!comment)
+             if (!comment || doc_keyword)
                while (c != ')')
                  {
                    if (c < 0)