X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/acfa068f4a1a4652b784af1d7aaac92929399249..27e498e6e5fea8ac64c90ac13678b537b7b12302:/src/doc.c diff --git a/src/doc.c b/src/doc.c index d2d664df26..92c7b2c6dc 100644 --- a/src/doc.c +++ b/src/doc.c @@ -1,6 +1,7 @@ /* Record indices of function doc strings stored in a file. -Copyright (C) 1985-1986, 1993-1995, 1997-2012 Free Software Foundation, Inc. +Copyright (C) 1985-1986, 1993-1995, 1997-2013 Free Software Foundation, +Inc. This file is part of GNU Emacs. @@ -21,7 +22,7 @@ along with GNU Emacs. If not, see . */ #include #include -#include /* Must be after sys/types.h for USG*/ +#include /* Must be after sys/types.h for USG. */ #include #include @@ -32,7 +33,6 @@ along with GNU Emacs. If not, see . */ #include "buffer.h" #include "keyboard.h" #include "keymap.h" -#include "buildobj.h" Lisp_Object Qfunction_documentation; @@ -42,7 +42,7 @@ static ptrdiff_t get_doc_string_buffer_size; static unsigned char *read_bytecode_pointer; -/* readchar in lread.c calls back here to fetch the next byte. +/* `readchar' in lread.c calls back here to fetch the next byte. If UNREADFLAG is 1, we unread a byte. */ int @@ -57,7 +57,7 @@ read_bytecode_char (bool unreadflag) } /* Extract a doc string from a file. FILEPOS says where to get it. - If it is an integer, use that position in the standard DOC-... file. + If it is an integer, use that position in the standard DOC file. If it is (FILE . INTEGER), use FILE as the file name and INTEGER as the position in that file. But if INTEGER is negative, make it positive. @@ -83,24 +83,23 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) ptrdiff_t minsize; int offset; EMACS_INT position; - Lisp_Object file, tem; + Lisp_Object file, tem, pos; USE_SAFE_ALLOCA; if (INTEGERP (filepos)) { file = Vdoc_file_name; - position = XINT (filepos); + pos = filepos; } else if (CONSP (filepos)) { file = XCAR (filepos); - position = XINT (XCDR (filepos)); + pos = XCDR (filepos); } else return Qnil; - if (position < 0) - position = - position; + position = eabs (XINT (pos)); if (!STRINGP (Vdoc_directory)) return Qnil; @@ -144,7 +143,8 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) } #endif if (fd < 0) - error ("Cannot open doc string file \"%s\"", name); + return concat3 (build_string ("Cannot open doc string file \""), + file, build_string ("\"\n")); } /* Seek only to beginning of disk block. */ @@ -175,9 +175,9 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) if (space_left <= 0) { ptrdiff_t in_buffer = p - get_doc_string_buffer; - get_doc_string_buffer = - xpalloc (get_doc_string_buffer, &get_doc_string_buffer_size, - 16 * 1024, -1, 1); + get_doc_string_buffer + = xpalloc (get_doc_string_buffer, &get_doc_string_buffer_size, + 16 * 1024, -1, 1); p = get_doc_string_buffer + in_buffer; space_left = (get_doc_string_buffer_size - 1 - (p - get_doc_string_buffer)); @@ -214,14 +214,20 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) if (CONSP (filepos)) { int test = 1; - if (get_doc_string_buffer[offset - test++] != ' ') - return Qnil; - while (get_doc_string_buffer[offset - test] >= '0' - && get_doc_string_buffer[offset - test] <= '9') - test++; - if (get_doc_string_buffer[offset - test++] != '@' - || get_doc_string_buffer[offset - test] != '#') - return Qnil; + /* A dynamic docstring should be either at the very beginning of a "#@ + comment" or right after a dynamic docstring delimiter (in case we + pack several such docstrings within the same comment). */ + if (get_doc_string_buffer[offset - test] != '\037') + { + if (get_doc_string_buffer[offset - test++] != ' ') + return Qnil; + while (get_doc_string_buffer[offset - test] >= '0' + && get_doc_string_buffer[offset - test] <= '9') + test++; + if (get_doc_string_buffer[offset - test++] != '@' + || get_doc_string_buffer[offset - test] != '#') + return Qnil; + } } else { @@ -278,10 +284,10 @@ Invalid data in documentation file -- %c followed by code %03o", else { /* The data determines whether the string is multibyte. */ - ptrdiff_t nchars = - multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer - + offset), - to - (get_doc_string_buffer + offset)); + ptrdiff_t nchars + = multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer + + offset), + to - (get_doc_string_buffer + offset)); return make_string_from_bytes (get_doc_string_buffer + offset, nchars, to - (get_doc_string_buffer + offset)); @@ -346,6 +352,8 @@ string is passed through `substitute-command-keys'. */) } fun = Findirect_function (function, Qnil); + if (CONSP (fun) && EQ (XCAR (fun), Qmacro)) + fun = XCDR (fun); if (SUBRP (fun)) { if (XSUBR (fun)->doc == 0) @@ -399,8 +407,6 @@ string is passed through `substitute-command-keys'. */) else return Qnil; } - else if (EQ (funcar, Qmacro)) - return Fdocumentation (Fcdr (fun), raw); else goto oops; } @@ -410,16 +416,19 @@ string is passed through `substitute-command-keys'. */) xsignal1 (Qinvalid_function, fun); } - /* Check for an advised function. Its doc string - has an `ad-advice-info' text property. */ + /* Check for a dynamic docstring. These come with + a dynamic-docstring-function text property. */ if (STRINGP (doc)) { - Lisp_Object innerfunc; - innerfunc = Fget_text_property (make_number (0), - intern ("ad-advice-info"), + Lisp_Object func + = Fget_text_property (make_number (0), + intern ("dynamic-docstring-function"), doc); - if (! NILP (innerfunc)) - doc = call1 (intern ("ad-make-advised-docstring"), innerfunc); + if (!NILP (func)) + /* Pass both `doc' and `function' since `function' can be needed, and + finding `doc' can be annoying: calling `documentation' is not an + option because it would infloop. */ + doc = call2 (func, doc, function); } /* If DOC is 0, it's typically because of a dumped file missing @@ -527,6 +536,8 @@ store_function_docstring (Lisp_Object obj, ptrdiff_t offset) { tem = Fcdr (Fcdr (fun)); if (CONSP (tem) && INTEGERP (XCAR (tem))) + /* FIXME: This modifies typically pure hash-cons'd data, so its + correctness is quite delicate. */ XSETCAR (tem, make_number (offset)); } else if (EQ (tem, Qmacro)) @@ -543,7 +554,6 @@ store_function_docstring (Lisp_Object obj, ptrdiff_t offset) } } -static const char buildobj[] = BUILDOBJ; DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation, 1, 1, 0, @@ -586,32 +596,20 @@ the same file name is found in the `doc-directory'. */) /* Vbuild_files is nil when temacs is run, and non-nil after that. */ if (NILP (Vbuild_files)) - { - const char *beg, *end; - - for (beg = buildobj; *beg; beg = end) - { - ptrdiff_t len; - - while (*beg && c_isspace (*beg)) ++beg; - - for (end = beg; *end && ! c_isspace (*end); ++end) - if (*end == '/') beg = end+1; /* skip directory part */ - - len = end - beg; - if (len > 4 && end[-4] == '.' && end[-3] == 'o') - len -= 2; /* Just take .o if it ends in .obj */ - - if (len > 0) - Vbuild_files = Fcons (make_string (beg, len), Vbuild_files); - } - Vbuild_files = Fpurecopy (Vbuild_files); - } + { + static char const *const buildobj[] = + { + #include "buildobj.h" + }; + int i = sizeof buildobj / sizeof *buildobj; + while (0 <= --i) + Vbuild_files = Fcons (build_string (buildobj[i]), Vbuild_files); + Vbuild_files = Fpurecopy (Vbuild_files); + } fd = emacs_open (name, O_RDONLY, 0); if (fd < 0) - report_file_error ("Opening doc string file", - Fcons (build_string (name), Qnil)); + report_file_error ("Opening doc string file", build_string (name)); Vdoc_file_name = filename; filled = 0; pos = 0; @@ -624,11 +622,10 @@ the same file name is found in the `doc-directory'. */) break; buf[filled] = 0; - p = buf; end = buf + (filled < 512 ? filled : filled - 128); - while (p != end && *p != '\037') p++; + p = memchr (buf, '\037', end - buf); /* p points to ^_Ffunctionname\n or ^_Vvarname\n or ^_Sfilename\n. */ - if (p != end) + if (p) { end = strchr (p, '\n'); @@ -747,9 +744,7 @@ Otherwise, return a new string, without any text properties. */) or a specified local map (which means search just that and the global map). If non-nil, it might come from Voverriding_local_map, or from a \\ construct in STRING itself.. */ - keymap = KVAR (current_kboard, Voverriding_terminal_local_map); - if (NILP (keymap)) - keymap = Voverriding_local_map; + keymap = Voverriding_local_map; bsize = SBYTES (string); bufp = buf = xmalloc (bsize);