/* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from
a single source file called builtins.def. */
-/* Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#include "../bashansi.h"
#include <stdio.h>
+#include <errno.h>
#include "stdc.h"
#define DOCFILE "builtins.texi"
+#ifndef errno
+extern int errno;
+#endif
+
static char *xmalloc (), *xrealloc ();
#if !defined (__STDC__) && !defined (strcpy)
/* Non-zero means to not do any productions. */
int inhibit_production = 0;
-#if !defined (OLDCODE)
-int no_long_document = 0;
-#endif /* !OLDCODE */
+/* Non-zero means to produce separate help files for each builtin, named by
+ the builtin name, in `./helpfiles'. */
+int separate_helpfiles = 0;
+
+/* The name of a directory into which the separate external help files will
+ eventually be installed. */
+char *helpfile_directory;
/* The name of a directory to precede the filename when reporting
errors. */
void write_longdocs ();
void write_builtins ();
+int write_helpfiles ();
+
void free_defs ();
void add_documentation ();
void must_be_building ();
void remove_trailing_whitespace ();
+
+#define document_name(b) ((b)->docname ? (b)->docname : (b)->name)
+
\f
/* For each file mentioned on the command line, process it and
write the information to STRUCTFILE and EXTERNFILE, while
only_documentation = 1;
documentation_file = fopen (documentation_filename, "w");
}
-#if !defined (OLDCODE)
- else if (strcmp (arg, "-nodocument") == 0)
- no_long_document = 1;
-#endif /* !OLDCODE */
+ else if (strcmp (arg, "-H") == 0)
+ {
+ separate_helpfiles = 1;
+ helpfile_directory = argv[arg_index++];
+ }
else
{
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
fclose (externfile);
}
+ if (separate_helpfiles)
+ {
+ write_helpfiles (saved_builtins);
+ }
+
if (documentation_file)
{
fprintf (documentation_file, "@end ftable\n");
}
/* Flags that mean something to write_documentation (). */
-#define STRING_ARRAY 1
-#define TEXINFO 2
+#define STRING_ARRAY 1
+#define TEXINFO 2
+#define PLAINTEXT 4
char *structfile_header[] = {
"/* builtins.c -- the built in shell commands. */",
"/* This file is manufactured by ./mkbuiltins, and should not be",
" edited by hand. See the source to mkbuiltins for details. */",
"",
- "/* Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.",
+ "/* Copyright (C) 1987-2002 Free Software Foundation, Inc.",
"",
" This file is part of GNU Bash, the Bourne Again SHell.",
"",
fprintf (externfile, "extern int %s __P((WORD_LIST *));\n",
builtin->function);
- fprintf (externfile, "extern char *%s_doc[];\n",
- builtin->docname ? builtin->docname : builtin->name);
+ fprintf (externfile, "extern char * const %s_doc[];\n",
+ document_name (builtin));
}
/* Write the structure definition. */
"BUILTIN_ENABLED | STATIC_BUILTIN",
(builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
(builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
- builtin->docname ? builtin->docname : builtin->name);
+ document_name (builtin));
fprintf
(structfile, " \"%s\", (char *)NULL },\n",
builtin->shortdoc ? builtin->shortdoc : builtin->name);
- /* Save away this builtin for later writing of the
- long documentation strings. */
- save_builtin (builtin);
}
+ if (structfile || separate_helpfiles)
+ /* Save away this builtin for later writing of the
+ long documentation strings. */
+ save_builtin (builtin);
+
/* Write out the matching #endif, if neccessary. */
if (builtin->dependencies)
{
{
register int i;
register BUILTIN_DESC *builtin;
+ char *dname;
+ char *sarray[2];
for (i = 0; i < builtins->sindex; i++)
{
write_ifdefs (stream, builtin->dependencies->array);
/* Write the long documentation strings. */
- fprintf (stream, "char *%s_doc[] =",
- builtin->docname ? builtin->docname : builtin->name);
- write_documentation (stream, builtin->longdoc->array, 0, STRING_ARRAY);
+ dname = document_name (builtin);
+ fprintf (stream, "char * const %s_doc[] =", dname);
+
+ if (separate_helpfiles)
+ {
+ int l = strlen (helpfile_directory) + strlen (dname) + 1;
+ sarray[0] = (char *)xmalloc (l + 1);
+ sprintf (sarray[0], "%s/%s", helpfile_directory, dname);
+ sarray[1] = (char *)NULL;
+ write_documentation (stream, sarray, 0, STRING_ARRAY);
+ free (sarray[0]);
+ }
+ else
+ write_documentation (stream, builtin->longdoc->array, 0, STRING_ARRAY);
if (builtin->dependencies)
write_endifs (stream, builtin->dependencies->array);
if (string_array)
fprintf (stream, " {\n#if defined (HELP_BUILTIN)\n");
-#if !defined (OLDCODE)
- /* XXX -- clean me up; for experiment only */
- if (no_long_document)
- goto end_of_document;
-#endif /* !OLDCODE */
-
for (i = 0, texinfo = (flags & TEXINFO); line = documentation[i]; i++)
{
/* Allow #ifdef's to be written out verbatim. */
fprintf (stream, "%s\n", line);
}
-#if !defined (OLDCODE)
-end_of_document:
-#endif /* !OLDCODE */
-
if (string_array)
fprintf (stream, "#endif /* HELP_BUILTIN */\n (char *)NULL\n};\n");
}
+int
+write_helpfiles (builtins)
+ ARRAY *builtins;
+{
+ char *helpfile, *bname;
+ FILE *helpfp;
+ int i, hdlen;
+ BUILTIN_DESC *builtin;
+
+ i = mkdir ("helpfiles", 0777);
+ if (i < 0 && errno != EEXIST)
+ {
+ fprintf (stderr, "write_helpfiles: helpfiles: cannot create directory\n");
+ return -1;
+ }
+
+ hdlen = strlen ("helpfiles/");
+ for (i = 0; i < builtins->sindex; i++)
+ {
+ builtin = (BUILTIN_DESC *)builtins->array[i];
+
+ bname = document_name (builtin);
+ helpfile = (char *)xmalloc (hdlen + strlen (bname) + 1);
+ sprintf (helpfile, "helpfiles/%s", bname);
+
+ helpfp = fopen (helpfile, "w");
+ if (helpfp == 0)
+ {
+ fprintf (stderr, "write_helpfiles: cannot open %s\n", helpfile);
+ free (helpfile);
+ continue;
+ }
+
+ write_documentation (helpfp, builtin->longdoc->array, 4, PLAINTEXT);
+
+ fflush (helpfp);
+ fclose (helpfp);
+ free (helpfile);
+ }
+ return 0;
+}
+
static int
_find_in_table (name, name_table)
char *name, *name_table[];