From mboxrd@z Thu Jan 1 00:00:00 1970 Path: quimby.gnus.org!not-for-mail From: Tak Ota Newsgroups: gmane.emacs.devel Subject: Re: lost argument and doc string Date: Wed, 13 Feb 2002 23:36:51 -0800 (PST) Organization: Sony Electronics Inc. Message-ID: <20020213.233651.60851324.Takaaki.Ota@am.sony.com> References: <20020213.122241.01370041.Takaaki.Ota@am.sony.com> NNTP-Posting-Host: quimby2.netfonds.no Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: quimby2.netfonds.no 1013673046 23312 195.204.10.66 (14 Feb 2002 07:50:46 GMT) X-Complaints-To: usenet@quimby2.netfonds.no NNTP-Posting-Date: 14 Feb 2002 07:50:46 GMT Cc: eliz@is.elta.co.il, lektu@terra.es, emacs-devel@gnu.org, andrewi@gnu.org Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby2.netfonds.no with esmtp (Exim 3.12 #1 (Debian)) id 16bGfF-00063t-00 for ; Thu, 14 Feb 2002 08:50:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16bGU6-0002aU-00; Thu, 14 Feb 2002 02:39:14 -0500 Original-Received: from mail6.fw-bc.sony.com ([160.33.98.73]) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16bGRz-0002Sp-00; Thu, 14 Feb 2002 02:37:03 -0500 Original-Received: from mail1.bc.in.sel.sony.com (mail1.bc.in.sel.sony.com [43.144.65.11]) by mail6.fw-bc.sony.com (8.8.8/8.8.8) with ESMTP id HAA06939; Thu, 14 Feb 2002 07:29:55 GMT Original-Received: by mail1.bc.in.sel.sony.com id HAA21789; Thu, 14 Feb 2002 07:36:54 GMT Original-To: jasonr@gnu.org In-Reply-To: X-Telephone: +1-858-942-3239 X-Fax------: +1-858-942-9142 X-SnailMail: 16450 West Bernardo Drive MZ7205, San Diego, CA 92127-1804 X-Mailer: Mew version 3.0.53 on Emacs 21.2.50.1 / Mule 5.0 (SAKAKI) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: quimby.gnus.org gmane.emacs.devel:1113 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1113 13 Feb 2002 21:02:42 +0000: Jason Rumney wrote: > > > Be careful that the following does the right thing: > > > > > > (defvar string-variable "String value" "\ > > > This is the documentation for a string variable.") > > > > > > > > > That seems like the only logical reason for the current convention. > > > > But my point is that they are all eventually processed by > > `read_c_string_or_comment' later, which takes care of backslash > > The backslash wasn't what I was concerned about. We need to make sure > that "String value" is not picked up as a documentation string in the > above case. That is the only reason I can think of where the current > convention might be useful. Thanks for the advice. How about the change below? It does more elaborate lisp object parsing. Also it consolidates some redundant code repetitions. -Tak Index: make-docfile.c =================================================================== RCS file: /cvsroot/emacs/emacs/lib-src/make-docfile.c,v retrieving revision 1.50 diff -u -r1.50 make-docfile.c --- make-docfile.c 5 Jan 2002 23:37:58 -0000 1.50 +++ make-docfile.c 14 Feb 2002 07:33:43 -0000 @@ -323,7 +323,7 @@ at the beginning of a line will be removed, and *SAW_USAGE set to true if any were encountered. */ -int +static int read_c_string_or_comment (infile, printflag, comment, saw_usage) FILE *infile; int printflag; @@ -414,7 +414,7 @@ /* Write to file OUT the argument names of function FUNC, whose text is in BUF. MINARGS and MAXARGS are the minimum and maximum number of arguments. */ -void +static void write_c_args (out, func, buf, minargs, maxargs) FILE *out; char *func, *buf; @@ -501,7 +501,7 @@ Looks for DEFUN constructs such as are defined in ../src/lisp.h. Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ -int +static int scan_c_file (filename, mode) char *filename, *mode; { @@ -765,7 +765,7 @@ An entry is output only if DOCSTRING has \ newline just after the opening " */ -void +static void skip_white (infile) FILE *infile; { @@ -775,10 +775,10 @@ ungetc (c, infile); } -void -read_lisp_symbol (infile, buffer) +static void +read_lisp_symbol (infile, buffer, filename) FILE *infile; - char *buffer; + char *buffer, *filename; { char c; char *fillp = buffer; @@ -789,7 +789,7 @@ c = getc (infile); if (c == '\\') *(++fillp) = getc (infile); - else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')') + else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')' || c == '[' || c == ']') { ungetc (c, infile); *fillp = 0; @@ -800,11 +800,138 @@ } if (! buffer[0]) - fprintf (stderr, "## expected a symbol, got '%c'\n", c); + fprintf (stderr, "## expected a symbol, got '%c' in %s\n", c, filename); skip_white (infile); } +static int +read_quoted_lisp_symbol (infile, buffer, filename, form) + FILE *infile; + char *buffer, *filename, *form; +{ + register int c; + + c = getc (infile); + if (c == '\'') + read_lisp_symbol (infile, buffer, filename); + else + { + if (c != '(') + { + fprintf (stderr, + "## unparsable name in %s in %s\n", + form, filename); + return 1; + } + read_lisp_symbol (infile, buffer, filename); + if (strcmp (buffer, "quote")) + { + fprintf (stderr, + "## unparsable name in %s in %s\n", + form, filename); + return 1; + } + read_lisp_symbol (infile, buffer, filename); + c = getc (infile); + if (c != ')') + { + fprintf (stderr, + "## unparsable quoted name in %s in %s\n", + form, filename); + return 1; + } + } + return 0; +} + +static int +read_lisp_char (infile) + FILE *infile; +{ + int c; + + continuation: + if ((c = getc (infile)) != '\\') + return c; + + switch (c = getc (infile)) + { + case '\n': case '\r': + goto continuation; + case 'a': return 7; + case 'b': return 8; + case 't': return 9; + case 'n': return 10; + case 'v': return 11; + case 'f': return 12; + case 'r': return 13; + case 'e': return 27; + case '\\': return 92; + case 'd': return 127; + case 'C': + if ((c = getc (infile)) != '-') + return c; /* ignore the syntax error */ + /* follow through */ + case '^': + c = getc (infile); + return ((c < 'a' ? c : c - 32) - '@') & 127; + } + return c; +} + +static int +skip_lisp_object (infile, filename) + FILE *infile; + char *filename; +{ + int c; + + skip_white (infile); + c = getc (infile); + switch (c) + { + case EOF: + return 0; + case '?': + read_lisp_char (infile); + return 1; + case '\'': + return skip_lisp_object (infile, filename); + case '\"': + do + { + c = read_lisp_char (infile); + } + while (c != '\"' && c != EOF); + return 1; + case '(': case '[': + { + int term = c == '(' ? ')' : ']'; + while (1) + { + skip_white (infile); + c = getc (infile); + if (c == term) + return 1; + if (c == EOF) + return 0; + ungetc (c, infile); + skip_lisp_object (infile, filename); + } + } + case ')': case ']': + return 0; + default: + ungetc (c, infile); + { + char buffer[BUFSIZ]; + read_lisp_symbol (infile, buffer, filename); + } + return 1; + } +} + int scan_lisp_file (filename, mode) char *filename, *mode; @@ -880,46 +1007,21 @@ if (c != '(') continue; - read_lisp_symbol (infile, buffer); + read_lisp_symbol (infile, buffer, filename); if (! strcmp (buffer, "defun") || ! strcmp (buffer, "defmacro") || ! strcmp (buffer, "defsubst")) { type = 'F'; - read_lisp_symbol (infile, buffer); + read_lisp_symbol (infile, buffer, filename); - /* Skip the arguments: either "nil" or a list in parens */ + /* Skip the arguments */ + skip_lisp_object (infile, filename); - c = getc (infile); - if (c == 'n') /* nil */ - { - if ((c = getc (infile)) != 'i' - || (c = getc (infile)) != 'l') - { - fprintf (stderr, "## unparsable arglist in %s (%s)\n", - buffer, filename); - continue; - } - } - else if (c != '(') - { - fprintf (stderr, "## unparsable arglist in %s (%s)\n", - buffer, filename); - continue; - } - else - while (c != ')') - c = getc (infile); skip_white (infile); - - /* If the next three characters aren't `dquote bslash newline' - then we're not reading a docstring. - */ - if ((c = getc (infile)) != '"' - || (c = getc (infile)) != '\\' - || ((c = getc (infile)) != '\n' && c != '\r')) - { + if ((c = getc (infile)) != '\"') + { #ifdef DEBUG fprintf (stderr, "## non-docstring in %s (%s)\n", buffer, filename); @@ -931,24 +1033,16 @@ else if (! strcmp (buffer, "defvar") || ! strcmp (buffer, "defconst")) { - char c1 = 0, c2 = 0; type = 'V'; - read_lisp_symbol (infile, buffer); + read_lisp_symbol (infile, buffer, filename); if (saved_string == 0) { + /* Skip the value */ + skip_lisp_object (infile, filename); - /* Skip until the end of line; remember two previous chars. */ - while (c != '\n' && c != '\r' && c >= 0) - { - c2 = c1; - c1 = c; - c = getc (infile); - } - - /* If two previous characters were " and \, - this is a doc string. Otherwise, there is none. */ - if (c2 != '"' || c1 != '\\') + skip_white (infile); + if ((c = getc (infile)) != '\"') { #ifdef DEBUG fprintf (stderr, "## non-docstring in %s (%s)\n", @@ -961,53 +1055,15 @@ else if (! strcmp (buffer, "custom-declare-variable")) { - char c1 = 0, c2 = 0; type = 'V'; - c = getc (infile); - if (c == '\'') - read_lisp_symbol (infile, buffer); - else - { - if (c != '(') - { - fprintf (stderr, - "## unparsable name in custom-declare-variable in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - if (strcmp (buffer, "quote")) - { - fprintf (stderr, - "## unparsable name in custom-declare-variable in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - c = getc (infile); - if (c != ')') - { - fprintf (stderr, - "## unparsable quoted name in custom-declare-variable in %s\n", - filename); - continue; - } - } + if (read_quoted_lisp_symbol (infile, buffer, filename, "custom-declare-variable")) + continue; if (saved_string == 0) { - /* Skip to end of line; remember the two previous chars. */ - while (c != '\n' && c != '\r' && c >= 0) - { - c2 = c1; - c1 = c; - c = getc (infile); - } - - /* If two previous characters were " and \, - this is a doc string. Otherwise, there is none. */ - if (c2 != '"' || c1 != '\\') + skip_white (infile); + if ((c = getc (infile)) != '\"') { #ifdef DEBUG fprintf (stderr, "## non-docstring in %s (%s)\n", @@ -1020,51 +1076,15 @@ else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias")) { - char c1 = 0, c2 = 0; type = 'F'; - c = getc (infile); - if (c == '\'') - read_lisp_symbol (infile, buffer); - else - { - if (c != '(') - { - fprintf (stderr, "## unparsable name in fset in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - if (strcmp (buffer, "quote")) - { - fprintf (stderr, "## unparsable name in fset in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - c = getc (infile); - if (c != ')') - { - fprintf (stderr, - "## unparsable quoted name in fset in %s\n", - filename); - continue; - } - } + if (read_quoted_lisp_symbol (infile, buffer, filename, "fset")) + continue; if (saved_string == 0) { - /* Skip to end of line; remember the two previous chars. */ - while (c != '\n' && c != '\r' && c >= 0) - { - c2 = c1; - c1 = c; - c = getc (infile); - } - - /* If two previous characters were " and \, - this is a doc string. Otherwise, there is none. */ - if (c2 != '"' || c1 != '\\') + skip_white (infile); + if ((c = getc (infile)) != '\"') { #ifdef DEBUG fprintf (stderr, "## non-docstring in %s (%s)\n", @@ -1078,34 +1098,10 @@ else if (! strcmp (buffer, "autoload")) { type = 'F'; - c = getc (infile); - if (c == '\'') - read_lisp_symbol (infile, buffer); - else - { - if (c != '(') - { - fprintf (stderr, "## unparsable name in autoload in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - if (strcmp (buffer, "quote")) - { - fprintf (stderr, "## unparsable name in autoload in %s\n", - filename); - continue; - } - read_lisp_symbol (infile, buffer); - c = getc (infile); - if (c != ')') - { - fprintf (stderr, - "## unparsable quoted name in autoload in %s\n", - filename); - continue; - } - } + + if (read_quoted_lisp_symbol (infile, buffer, filename, "autoload")) + continue; + skip_white (infile); if ((c = getc (infile)) != '\"') { @@ -1117,13 +1113,10 @@ skip_white (infile); if (saved_string == 0) - { - /* If the next three characters aren't `dquote bslash newline' - then we're not reading a docstring. */ - if ((c = getc (infile)) != '"' - || (c = getc (infile)) != '\\' - || ((c = getc (infile)) != '\n' && c != '\r')) - { + { + skip_white (infile); + if ((c = getc (infile)) != '\"') + { #ifdef DEBUG fprintf (stderr, "## non-docstring in %s (%s)\n", buffer, filename); @@ -1152,8 +1145,8 @@ dynamic doc string in saved_string or gobble a doc string from the input file. - In the latter case, the opening quote (and leading - backslash-newline) have already been read. */ + In the latter case, the opening quote has already been + read. */ putc (037, outfile); putc (type, outfile); _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel