X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=lib-src%2Fmake-docfile.c;h=aeee24a58bc6e4c271a09efcd0dae8b3d2dae33a;hp=2db8dc8724d970d76aca4f53526ec97ed7283c8d;hb=dbf2768f7b146e97e37a27316f70bb313f1acf15;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910 diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 2db8dc8..aeee24a 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -1,6 +1,7 @@ /* Generate doc-string file for XEmacs from source files. Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. - Copyright (C) 1995 Board of Trustees, University of Illinois + Copyright (C) 1995 Board of Trustees, University of Illinois. + Copyright (C) 1998, 1999 J. Kean Johnston. This file is part of XEmacs. @@ -39,46 +40,44 @@ Boston, MA 02111-1307, USA. */ */ #define NO_SHORTNAMES /* Tell config not to load remap.h */ -#include <../src/config.h> +#include #include #include #if __STDC__ || defined(STDC_HEADERS) #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include #endif -#include - -#if defined(MSDOS) || defined(__CYGWIN32__) +#ifdef CYGWIN #include -#endif /* MSDOS */ -#ifdef WINDOWSNT +#endif +#ifdef WIN32_NATIVE #include #include #include #include -#endif /* WINDOWSNT */ +#endif /* WIN32_NATIVE */ -#if defined(DOS_NT) || defined(__CYGWIN32__) +#ifndef WIN32_NATIVE +#include +#endif /* not WIN32_NATIVE */ + +#if defined(WIN32_NATIVE) || defined(CYGWIN) #define READ_TEXT "rt" #define READ_BINARY "rb" #define WRITE_BINARY "wb" #define APPEND_BINARY "ab" -#else /* not DOS_NT */ +#else /* not WIN32_NATIVE */ #define READ_TEXT "r" #define READ_BINARY "r" #define WRITE_BINARY "w" #define APPEND_BINARY "a" -#endif /* not DOS_NT */ - -#ifdef MSDOS -/* s/msdos.h defines this as sys_chdir, but we're not linking with the - file where that function is defined. */ -#undef chdir -#endif +#endif /* not WIN32_NATIVE */ /* Stdio stream for output to the DOC file. */ static FILE *outfile; @@ -90,14 +89,14 @@ enum c_file } Current_file_type; -static int scan_file (CONST char *filename); +static int scan_file (const char *filename); static int read_c_string (FILE *, int, int); -static void write_c_args (FILE *out, CONST char *func, char *buf, int minargs, +static void write_c_args (FILE *out, const char *func, char *buf, int minargs, int maxargs); -static int scan_c_file (CONST char *filename, CONST char *mode); +static int scan_c_file (const char *filename, const char *mode); static void skip_white (FILE *); static void read_lisp_symbol (FILE *, char *); -static int scan_lisp_file (CONST char *filename, CONST char *mode); +static int scan_lisp_file (const char *filename, const char *mode); #define C_IDENTIFIER_CHAR_P(c) \ (('A' <= c && c <= 'Z') || \ @@ -108,10 +107,13 @@ static int scan_lisp_file (CONST char *filename, CONST char *mode); /* Name this program was invoked with. */ char *progname; +/* Set to 1 if this was invoked by ellcc */ +int ellcc = 0; + /* Print error message. `s1' is printf control string, `s2' is arg for it. */ static void -error (CONST char *s1, CONST char *s2) +error (const char *s1, const char *s2) { fprintf (stderr, "%s: ", progname); fprintf (stderr, s1, s2); @@ -121,7 +123,7 @@ error (CONST char *s1, CONST char *s2) /* Print error message and exit. */ static void -fatal (CONST char *s1, CONST char *s2) +fatal (const char *s1, const char *s2) { error (s1, s2); exit (1); @@ -187,19 +189,10 @@ main (int argc, char **argv) outfile = stdout; /* Don't put CRs in the DOC file. */ -#ifdef MSDOS +#ifdef WIN32_NATIVE _fmode = O_BINARY; -#if 0 /* Suspicion is that this causes hanging. - So instead we require people to use -o on MSDOS. */ - (stdout)->_flag &= ~_IOTEXT; _setmode (fileno (stdout), O_BINARY); -#endif - outfile = 0; -#endif /* MSDOS */ -#ifdef WINDOWSNT - _fmode = O_BINARY; - _setmode (fileno (stdout), O_BINARY); -#endif /* WINDOWSNT */ +#endif /* WIN32_NATIVE */ /* If first two args are -o FILE, output to FILE. */ i = 1; @@ -213,6 +206,12 @@ main (int argc, char **argv) outfile = fopen (argv[i + 1], APPEND_BINARY); i += 2; } + if (argc > i + 1 && !strcmp (argv[i], "-E")) + { + outfile = fopen (argv[i + 1], APPEND_BINARY); + i += 2; + ellcc = 1; + } if (argc > i + 1 && !strcmp (argv[i], "-d")) { chdir (argv[i + 1]); @@ -227,6 +226,9 @@ main (int argc, char **argv) if (outfile == 0) fatal ("No output file specified", ""); + if (ellcc) + fprintf (outfile, "{\n"); + first_infile = i; for (; i < argc; i++) { @@ -249,6 +251,8 @@ main (int argc, char **argv) } putc ('\n', outfile); + if (ellcc) + fprintf (outfile, "}\n\n"); #ifndef VMS exit (err_count > 0); #endif /* VMS */ @@ -259,15 +263,15 @@ main (int argc, char **argv) /* Return 1 if file is not found, 0 if it is found. */ static int -scan_file (CONST char *filename) +scan_file (const char *filename) { int len = strlen (filename); - if (len > 4 && !strcmp (filename + len - 4, ".elc")) + if (ellcc == 0 && len > 4 && !strcmp (filename + len - 4, ".elc")) { Current_file_type = elc_file; return scan_lisp_file (filename, READ_BINARY); } - else if (len > 3 && !strcmp (filename + len - 3, ".el")) + else if (ellcc == 0 && len > 3 && !strcmp (filename + len - 3, ".el")) { Current_file_type = el_file; return scan_lisp_file (filename, READ_TEXT); @@ -288,44 +292,59 @@ char buf[128]; Convert escape sequences \n and \t to newline and tab; discard \ followed by newline. */ +#define MDGET do { prevc = c; c = getc (infile); } while (0) static int read_c_string (FILE *infile, int printflag, int c_docstring) { - register int c; + register int prevc = 0, c = 0; char *p = buf; int start = -1; - c = getc (infile); + MDGET; while (c != EOF) { while ((c_docstring || c != '"') && c != EOF) { - if (start) + if (c == '*') { - if (c == '*') + int cc = getc (infile); + if (cc == '/') { - int cc = getc (infile); - if (cc == '/') - break; - else - ungetc (cc, infile); + if (prevc != '\n') + { + if (printflag > 0) + { + if (ellcc) + fprintf (outfile, "\\n\\"); + putc ('\n', outfile); + } + else if (printflag < 0) + *p++ = '\n'; + } + break; } + else + ungetc (cc, infile); + } - if (start != -1) + if (start == 1) + { + if (printflag > 0) { - if (printflag > 0) - putc ('\n', outfile); - else if (printflag < 0) - *p++ = '\n'; + if (ellcc) + fprintf (outfile, "\\n\\"); + putc ('\n', outfile); } + else if (printflag < 0) + *p++ = '\n'; } if (c == '\\') { - c = getc (infile); + MDGET; if (c == '\n') { - c = getc (infile); + MDGET; start = 1; continue; } @@ -340,28 +359,35 @@ read_c_string (FILE *infile, int printflag, int c_docstring) { start = 0; if (printflag > 0) - putc (c, outfile); + { + if (ellcc && c == '"') + putc ('\\', outfile); + putc (c, outfile); + } else if (printflag < 0) *p++ = c; } - c = getc (infile); + MDGET; } /* look for continuation of string */ if (Current_file_type == c_file) { - while (isspace (c = getc (infile))) - ; + do + { + MDGET; + } + while (isspace (c)); if (c != '"') break; } else { - c = getc (infile); + MDGET; if (c != '"') break; /* If we had a "", concatenate the two strings. */ } - c = getc (infile); + MDGET; } if (printflag < 0) @@ -374,7 +400,7 @@ read_c_string (FILE *infile, int printflag, int c_docstring) MINARGS and MAXARGS are the minimum and maximum number of arguments. */ static void -write_c_args (FILE *out, CONST char *func, char *buff, int minargs, +write_c_args (FILE *out, const char *func, char *buff, int minargs, int maxargs) { register char *p; @@ -407,10 +433,10 @@ write_c_args (FILE *out, CONST char *func, char *buff, int minargs, static char lo[] = "Lisp_Object"; if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident && (strncmp (p, lo, sizeof (lo) - 1) == 0) && - isspace(*(p + sizeof (lo) - 1))) + isspace((unsigned char) (* (p + sizeof (lo) - 1)))) { p += (sizeof (lo) - 1); - while (isspace (*p)) + while (isspace ((unsigned char) (*p))) p++; c = *p; } @@ -464,7 +490,8 @@ write_c_args (FILE *out, CONST char *func, char *buff, int minargs, need_space = 0; #endif } - putc ('\n', out); /* XEmacs addition */ + if (!ellcc) + putc ('\n', out); /* XEmacs addition */ } /* Read through a c file. If a .o file is named, @@ -473,7 +500,7 @@ write_c_args (FILE *out, CONST char *func, char *buff, int minargs, Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ static int -scan_c_file (CONST char *filename, CONST char *mode) +scan_c_file (const char *filename, const char *mode) { FILE *infile; register int c; @@ -482,7 +509,7 @@ scan_c_file (CONST char *filename, CONST char *mode) register int defvarperbufferflag = 0; register int defvarflag; int minargs, maxargs; - int l = strlen (filename); + size_t l = strlen (filename); char f[MAXPATHLEN]; if (l > sizeof (f)) @@ -639,9 +666,15 @@ scan_c_file (CONST char *filename, CONST char *mode) if (defunflag || defvarflag || c == '"') { - putc (037, outfile); - putc (defvarflag ? 'V' : 'F', outfile); - fprintf (outfile, "%s\n", buf); + if (ellcc) + fprintf (outfile, " CDOC%s(\"%s\", \"\\\n", + defvarflag ? "SYM" : "SUBR", buf); + else + { + putc (037, outfile); + putc (defvarflag ? 'V' : 'F', outfile); + fprintf (outfile, "%s\n", buf); + } c = read_c_string (infile, 1, (defunflag || defvarflag)); /* If this is a defun, find the arguments and print them. If @@ -673,9 +706,14 @@ scan_c_file (CONST char *filename, CONST char *mode) while (c != ')'); *p = '\0'; /* Output them. */ - fprintf (outfile, "\n\n"); + if (ellcc) + fprintf (outfile, "\\n\\\n\\n\\\n"); + else + fprintf (outfile, "\n\n"); write_c_args (outfile, buf, argbuf, minargs, maxargs); } + if (ellcc) + fprintf (outfile, "\\n\");\n\n"); } } eof: @@ -753,7 +791,7 @@ read_lisp_symbol (FILE *infile, char *buffer) } static int -scan_lisp_file (CONST char *filename, CONST char *mode) +scan_lisp_file (const char *filename, const char *mode) { FILE *infile; register int c; @@ -881,7 +919,7 @@ scan_lisp_file (CONST char *filename, CONST char *mode) /* Skip until the first newline; remember the two previous chars. */ while (c != '\n' && c >= 0) { - /* ### Kludge -- Ignore any ESC x x ISO2022 sequences */ + /* #### Kludge -- Ignore any ESC x x ISO2022 sequences */ if (c == 27) { getc (infile); @@ -1032,7 +1070,7 @@ scan_lisp_file (CONST char *filename, CONST char *mode) else { #ifdef DEBUG - fprintf (stderr, "## unrecognised top-level form, %s (%s)\n", + fprintf (stderr, "## unrecognized top-level form, %s (%s)\n", buffer, filename); #endif continue;