aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/make-docfile.c
diff options
context:
space:
mode:
authorJoakim Verona2012-05-30 14:08:12 +0200
committerJoakim Verona2012-05-30 14:08:12 +0200
commit70700d8c47a35b19e29607ac5f0ed322bdd78249 (patch)
tree4fa00d3fac00025354f0b6e23dcda1b58689a094 /lib-src/make-docfile.c
parent44fce8ffe7198991c41c985ff4e67ec7d407907e (diff)
parent72cb32cf2f0938dd7dc733eed77b1ed1e497b053 (diff)
downloademacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.tar.gz
emacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.zip
upstream
Diffstat (limited to 'lib-src/make-docfile.c')
-rw-r--r--lib-src/make-docfile.c153
1 files changed, 53 insertions, 100 deletions
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index b33b13f34ce..1314a7b6829 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -35,7 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 35
36#include <config.h> 36#include <config.h>
37 37
38/* defined to be emacs_main, sys_fopen, etc. in config.h */ 38/* Defined to be emacs_main, sys_fopen, etc. in config.h. */
39#undef main 39#undef main
40#undef fopen 40#undef fopen
41#undef chdir 41#undef chdir
@@ -66,7 +66,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
66#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) 66#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
67#endif 67#endif
68 68
69/* Use this to suppress gcc's `...may be used before initialized' warnings. */ 69/* Use this to suppress gcc's `...may be used before initialized' warnings. */
70#ifdef lint 70#ifdef lint
71# define IF_LINT(Code) Code 71# define IF_LINT(Code) Code
72#else 72#else
@@ -226,7 +226,7 @@ put_filename (char *filename)
226 226
227 for (tmp = filename; *tmp; tmp++) 227 for (tmp = filename; *tmp; tmp++)
228 { 228 {
229 if (IS_DIRECTORY_SEP(*tmp)) 229 if (IS_DIRECTORY_SEP (*tmp))
230 filename = tmp + 1; 230 filename = tmp + 1;
231 } 231 }
232 232
@@ -675,14 +675,14 @@ scan_c_file (char *filename, const char *mode)
675 675
676 if (infile == NULL && extension == 'o') 676 if (infile == NULL && extension == 'o')
677 { 677 {
678 /* try .m */ 678 /* Try .m. */
679 filename[strlen (filename) - 1] = 'm'; 679 filename[strlen (filename) - 1] = 'm';
680 infile = fopen (filename, mode); 680 infile = fopen (filename, mode);
681 if (infile == NULL) 681 if (infile == NULL)
682 filename[strlen (filename) - 1] = 'c'; /* don't confuse people */ 682 filename[strlen (filename) - 1] = 'c'; /* Don't confuse people. */
683 } 683 }
684 684
685 /* No error if non-ex input file */ 685 /* No error if non-ex input file. */
686 if (infile == NULL) 686 if (infile == NULL)
687 { 687 {
688 perror (filename); 688 perror (filename);
@@ -800,8 +800,8 @@ scan_c_file (char *filename, const char *mode)
800 input_buffer[i++] = c; 800 input_buffer[i++] = c;
801 c = getc (infile); 801 c = getc (infile);
802 } 802 }
803 while (! (c == ',' || c == ' ' || c == '\t' || 803 while (! (c == ',' || c == ' ' || c == '\t'
804 c == '\n' || c == '\r')); 804 || c == '\n' || c == '\r'));
805 input_buffer[i] = '\0'; 805 input_buffer[i] = '\0';
806 806
807 name = xmalloc (i + 1); 807 name = xmalloc (i + 1);
@@ -820,7 +820,7 @@ scan_c_file (char *filename, const char *mode)
820 commas = 3; 820 commas = 3;
821 else if (defvarflag) 821 else if (defvarflag)
822 commas = 1; 822 commas = 1;
823 else /* For DEFSIMPLE and DEFPRED */ 823 else /* For DEFSIMPLE and DEFPRED. */
824 commas = 2; 824 commas = 2;
825 825
826 while (commas) 826 while (commas)
@@ -838,9 +838,9 @@ scan_c_file (char *filename, const char *mode)
838 if (c < 0) 838 if (c < 0)
839 goto eof; 839 goto eof;
840 ungetc (c, infile); 840 ungetc (c, infile);
841 if (commas == 2) /* pick up minargs */ 841 if (commas == 2) /* Pick up minargs. */
842 scanned = fscanf (infile, "%d", &minargs); 842 scanned = fscanf (infile, "%d", &minargs);
843 else /* pick up maxargs */ 843 else /* Pick up maxargs. */
844 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ 844 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
845 maxargs = -1; 845 maxargs = -1;
846 else 846 else
@@ -893,7 +893,7 @@ scan_c_file (char *filename, const char *mode)
893 fprintf (outfile, "%s\n", input_buffer); 893 fprintf (outfile, "%s\n", input_buffer);
894 894
895 if (comment) 895 if (comment)
896 getc (infile); /* Skip past `*' */ 896 getc (infile); /* Skip past `*'. */
897 c = read_c_string_or_comment (infile, 1, comment, &saw_usage); 897 c = read_c_string_or_comment (infile, 1, comment, &saw_usage);
898 898
899 /* If this is a defun, find the arguments and print them. If 899 /* If this is a defun, find the arguments and print them. If
@@ -979,7 +979,7 @@ scan_c_file (char *filename, const char *mode)
979 problem because byte-compiler output follows this convention. 979 problem because byte-compiler output follows this convention.
980 The NAME and DOCSTRING are output. 980 The NAME and DOCSTRING are output.
981 NAME is preceded by `F' for a function or `V' for a variable. 981 NAME is preceded by `F' for a function or `V' for a variable.
982 An entry is output only if DOCSTRING has \ newline just after the opening " 982 An entry is output only if DOCSTRING has \ newline just after the opening ".
983 */ 983 */
984 984
985static void 985static void
@@ -1020,6 +1020,32 @@ read_lisp_symbol (FILE *infile, char *buffer)
1020} 1020}
1021 1021
1022static int 1022static int
1023search_lisp_doc_at_eol (FILE *infile)
1024{
1025 char c = 0, c1 = 0, c2 = 0;
1026
1027 /* Skip until the end of line; remember two previous chars. */
1028 while (c != '\n' && c != '\r' && c >= 0)
1029 {
1030 c2 = c1;
1031 c1 = c;
1032 c = getc (infile);
1033 }
1034
1035 /* If two previous characters were " and \,
1036 this is a doc string. Otherwise, there is none. */
1037 if (c2 != '"' || c1 != '\\')
1038 {
1039#ifdef DEBUG
1040 fprintf (stderr, "## non-docstring in %s (%s)\n",
1041 buffer, filename);
1042#endif
1043 return 0;
1044 }
1045 return 1;
1046}
1047
1048static int
1023scan_lisp_file (const char *filename, const char *mode) 1049scan_lisp_file (const char *filename, const char *mode)
1024{ 1050{
1025 FILE *infile; 1051 FILE *infile;
@@ -1033,7 +1059,7 @@ scan_lisp_file (const char *filename, const char *mode)
1033 if (infile == NULL) 1059 if (infile == NULL)
1034 { 1060 {
1035 perror (filename); 1061 perror (filename);
1036 return 0; /* No error */ 1062 return 0; /* No error. */
1037 } 1063 }
1038 1064
1039 c = '\n'; 1065 c = '\n';
@@ -1110,7 +1136,7 @@ scan_lisp_file (const char *filename, const char *mode)
1110 type = 'F'; 1136 type = 'F';
1111 read_lisp_symbol (infile, buffer); 1137 read_lisp_symbol (infile, buffer);
1112 1138
1113 /* Skip the arguments: either "nil" or a list in parens */ 1139 /* Skip the arguments: either "nil" or a list in parens. */
1114 1140
1115 c = getc (infile); 1141 c = getc (infile);
1116 if (c == 'n') /* nil */ 1142 if (c == 'n') /* nil */
@@ -1154,39 +1180,18 @@ scan_lisp_file (const char *filename, const char *mode)
1154 || ! strcmp (buffer, "defconst") 1180 || ! strcmp (buffer, "defconst")
1155 || ! strcmp (buffer, "defcustom")) 1181 || ! strcmp (buffer, "defcustom"))
1156 { 1182 {
1157 char c1 = 0, c2 = 0;
1158 type = 'V'; 1183 type = 'V';
1159 read_lisp_symbol (infile, buffer); 1184 read_lisp_symbol (infile, buffer);
1160 1185
1161 if (saved_string == 0) 1186 if (saved_string == 0)
1162 { 1187 if (!search_lisp_doc_at_eol (infile))
1163 1188 continue;
1164 /* Skip until the end of line; remember two previous chars. */
1165 while (c != '\n' && c != '\r' && c >= 0)
1166 {
1167 c2 = c1;
1168 c1 = c;
1169 c = getc (infile);
1170 }
1171
1172 /* If two previous characters were " and \,
1173 this is a doc string. Otherwise, there is none. */
1174 if (c2 != '"' || c1 != '\\')
1175 {
1176#ifdef DEBUG
1177 fprintf (stderr, "## non-docstring in %s (%s)\n",
1178 buffer, filename);
1179#endif
1180 continue;
1181 }
1182 }
1183 } 1189 }
1184 1190
1185 else if (! strcmp (buffer, "custom-declare-variable") 1191 else if (! strcmp (buffer, "custom-declare-variable")
1186 || ! strcmp (buffer, "defvaralias") 1192 || ! strcmp (buffer, "defvaralias")
1187 ) 1193 )
1188 { 1194 {
1189 char c1 = 0, c2 = 0;
1190 type = 'V'; 1195 type = 'V';
1191 1196
1192 c = getc (infile); 1197 c = getc (infile);
@@ -1221,31 +1226,12 @@ scan_lisp_file (const char *filename, const char *mode)
1221 } 1226 }
1222 1227
1223 if (saved_string == 0) 1228 if (saved_string == 0)
1224 { 1229 if (!search_lisp_doc_at_eol (infile))
1225 /* Skip to end of line; remember the two previous chars. */ 1230 continue;
1226 while (c != '\n' && c != '\r' && c >= 0)
1227 {
1228 c2 = c1;
1229 c1 = c;
1230 c = getc (infile);
1231 }
1232
1233 /* If two previous characters were " and \,
1234 this is a doc string. Otherwise, there is none. */
1235 if (c2 != '"' || c1 != '\\')
1236 {
1237#ifdef DEBUG
1238 fprintf (stderr, "## non-docstring in %s (%s)\n",
1239 buffer, filename);
1240#endif
1241 continue;
1242 }
1243 }
1244 } 1231 }
1245 1232
1246 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias")) 1233 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
1247 { 1234 {
1248 char c1 = 0, c2 = 0;
1249 type = 'F'; 1235 type = 'F';
1250 1236
1251 c = getc (infile); 1237 c = getc (infile);
@@ -1278,26 +1264,8 @@ scan_lisp_file (const char *filename, const char *mode)
1278 } 1264 }
1279 1265
1280 if (saved_string == 0) 1266 if (saved_string == 0)
1281 { 1267 if (!search_lisp_doc_at_eol (infile))
1282 /* Skip to end of line; remember the two previous chars. */ 1268 continue;
1283 while (c != '\n' && c != '\r' && c >= 0)
1284 {
1285 c2 = c1;
1286 c1 = c;
1287 c = getc (infile);
1288 }
1289
1290 /* If two previous characters were " and \,
1291 this is a doc string. Otherwise, there is none. */
1292 if (c2 != '"' || c1 != '\\')
1293 {
1294#ifdef DEBUG
1295 fprintf (stderr, "## non-docstring in %s (%s)\n",
1296 buffer, filename);
1297#endif
1298 continue;
1299 }
1300 }
1301 } 1269 }
1302 1270
1303 else if (! strcmp (buffer, "autoload")) 1271 else if (! strcmp (buffer, "autoload"))
@@ -1339,23 +1307,10 @@ scan_lisp_file (const char *filename, const char *mode)
1339 continue; 1307 continue;
1340 } 1308 }
1341 read_c_string_or_comment (infile, 0, 0, 0); 1309 read_c_string_or_comment (infile, 0, 0, 0);
1342 skip_white (infile);
1343 1310
1344 if (saved_string == 0) 1311 if (saved_string == 0)
1345 { 1312 if (!search_lisp_doc_at_eol (infile))
1346 /* If the next three characters aren't `dquote bslash newline' 1313 continue;
1347 then we're not reading a docstring. */
1348 if ((c = getc (infile)) != '"'
1349 || (c = getc (infile)) != '\\'
1350 || ((c = getc (infile)) != '\n' && c != '\r'))
1351 {
1352#ifdef DEBUG
1353 fprintf (stderr, "## non-docstring in %s (%s)\n",
1354 buffer, filename);
1355#endif
1356 continue;
1357 }
1358 }
1359 } 1314 }
1360 1315
1361#ifdef DEBUG 1316#ifdef DEBUG
@@ -1373,12 +1328,10 @@ scan_lisp_file (const char *filename, const char *mode)
1373 continue; 1328 continue;
1374 } 1329 }
1375 1330
1376 /* At this point, we should either use the previous 1331 /* At this point, we should either use the previous dynamic doc string in
1377 dynamic doc string in saved_string 1332 saved_string or gobble a doc string from the input file.
1378 or gobble a doc string from the input file. 1333 In the latter case, the opening quote (and leading backslash-newline)
1379 1334 have already been read. */
1380 In the latter case, the opening quote (and leading
1381 backslash-newline) have already been read. */
1382 1335
1383 putc (037, outfile); 1336 putc (037, outfile);
1384 putc (type, outfile); 1337 putc (type, outfile);