1
/* gen-helpfiles - create files containing builtin help text */
3
/* Copyright (C) 2012 Free Software Foundation, Inc.
5
This file is part of GNU Bash, the Bourne Again SHell.
7
Bash is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
Bash is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with Bash. If not, see <http://www.gnu.org/licenses/>.
21
/* This links with a specially-generated version of builtins.c and takes
22
the long_doc members of each struct builtin element and writes those to
23
the file named by the `handle' member of the struct builtin element. */
25
#if !defined (CROSS_COMPILING)
27
#else /* CROSS_COMPILING */
28
/* A conservative set of defines based on POSIX/SUS3/XPG6 */
29
# define HAVE_UNISTD_H
30
# define HAVE_STRING_H
31
# define HAVE_STDLIB_H
34
#endif /* CROSS_COMPILING */
36
#if defined (HAVE_UNISTD_H)
38
# include <sys/types.h>
44
# include "../bashtypes.h"
45
# if defined (HAVE_SYS_FILE_H)
46
# include <sys/file.h>
50
#include "posixstat.h"
53
#include "../bashansi.h"
59
#include "../builtins.h"
60
#include "tmpbuiltins.h"
62
#if defined (USING_BASH_MALLOC)
67
#undef free /* defined in xmalloc.h */
74
#if !defined (__STDC__) && !defined (strcpy)
75
extern char *strcpy ();
76
#endif /* !__STDC__ && !strcpy */
78
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
80
/* Flag values that builtins can have. */
81
#define BUILTIN_FLAG_SPECIAL 0x01
82
#define BUILTIN_FLAG_ASSIGNMENT 0x02
83
#define BUILTIN_FLAG_POSIX_BUILTIN 0x04
87
/* Non-zero means to produce separate help files for each builtin, named by
88
the builtin name, in `./helpfiles'. */
89
int separate_helpfiles = 0;
91
/* Non-zero means to create single C strings for each `longdoc', with
92
embedded newlines, for ease of translation. */
93
int single_longdoc_strings = 1;
95
/* The name of a directory into which the separate external help files will
96
eventually be installed. */
97
char *helpfile_directory;
99
/* Forward declarations. */
101
int write_helpfiles __P((struct builtin *));
103
/* For each file mentioned on the command line, process it and
104
write the information to STRUCTFILE and EXTERNFILE, while
105
creating the production file if neccessary. */
113
while (arg_index < argc && argv[arg_index][0] == '-')
115
char *arg = argv[arg_index++];
117
if (strcmp (arg, "-noproduction") == 0)
119
else if (strcmp (arg, "-H") == 0)
120
helpfile_directory = argv[arg_index++];
121
else if (strcmp (arg, "-S") == 0)
122
single_longdoc_strings = 0;
125
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
130
write_helpfiles(shell_builtins);
135
/* Write DOCUMENTATION to STREAM, perhaps surrounding it with double-quotes
136
and quoting special characters in the string. Handle special things for
137
internationalization (gettext) and the single-string vs. multiple-strings
140
write_documentation (stream, documentation, indentation)
149
fprintf (stream, "%*s%s\n", indentation, " ", documentation);
153
write_helpfiles (builtins)
154
struct builtin *builtins;
156
char *helpfile, *bname, *fname;
161
i = mkdir ("helpfiles", 0777);
162
if (i < 0 && errno != EEXIST)
164
fprintf (stderr, "write_helpfiles: helpfiles: cannot create directory\n");
168
hdlen = strlen ("helpfiles/");
169
for (i = 0; i < num_shell_builtins; i++)
173
fname = (char *)b.handle;
174
helpfile = (char *)malloc (hdlen + strlen (fname) + 1);
177
fprintf (stderr, "gen-helpfiles: cannot allocate memory\n");
180
sprintf (helpfile, "helpfiles/%s", fname);
182
helpfp = fopen (helpfile, "w");
185
fprintf (stderr, "write_helpfiles: cannot open %s\n", helpfile);
190
write_documentation (helpfp, b.long_doc[0], 4);