Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
# include <unistd.h>
#endif
+#ifndef _MINIX
#include "../bashtypes.h"
#include <sys/file.h>
-#include "../posixstat.h"
-#include "../filecntl.h"
+#endif
-#if defined (HAVE_UNISTD_H)
-# include <unistd.h>
-#endif /* HAVE_UNISTD_H */
+#include "posixstat.h"
+#include "filecntl.h"
#include "../bashansi.h"
#include <stdio.h>
static int is_special_builtin ();
static int is_assignment_builtin ();
+#if !defined (HAVE_RENAME)
+static int rename ();
+#endif
+
void extract_info ();
void file_error ();
#if !defined (OLDCODE)
else if (strcmp (arg, "-nodocument") == 0)
no_long_document = 1;
-#endif /* !OLDCODE */
+#endif /* !OLDCODE */
else
{
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
{
write_longdocs (structfile, saved_builtins);
fclose (structfile);
- link (temp_struct_filename, struct_filename);
- unlink (temp_struct_filename);
+ rename (temp_struct_filename, struct_filename);
}
if (externfile)
register int i;
DEF_FILE *defs;
struct stat finfo;
+ size_t file_size;
char *buffer, *line;
- int fd;
+ int fd, nr;
if (stat (filename, &finfo) == -1)
file_error (filename);
if (fd == -1)
file_error (filename);
- buffer = xmalloc (1 + (int)finfo.st_size);
+ file_size = (size_t)finfo.st_size;
+ buffer = xmalloc (1 + file_size);
- if (read (fd, buffer, finfo.st_size) != finfo.st_size)
+ if ((nr = read (fd, buffer, file_size)) < 0)
file_error (filename);
+ /* This is needed on WIN32, and does not hurt on Unix. */
+ if (nr < file_size)
+ file_size = nr;
+
close (fd);
+ if (nr == 0)
+ {
+ fprintf (stderr, "mkbuiltins: %s: skipping zero-length file\n", filename);
+ return;
+ }
+
/* Create and fill in the initial structure describing this file. */
defs = (DEF_FILE *)xmalloc (sizeof (DEF_FILE));
defs->filename = filename;
/* Build the array of lines. */
i = 0;
- while (i < finfo.st_size)
+ while (i < file_size)
{
array_add (&buffer[i], defs->lines);
- while (buffer[i] != '\n' && i < finfo.st_size)
+ while (buffer[i] != '\n' && i < file_size)
i++;
buffer[i++] = '\0';
}
if (defs->builtins)
{
for (i = 0; builtin = (BUILTIN_DESC *)defs->builtins->array[i]; i++)
- {
+ {
free_builtin (builtin);
free (builtin);
- }
+ }
array_free (defs->builtins);
}
free (defs);
DEF_FILE *defs;
{
must_be_building (directive, defs);
- return ((BUILTIN_DESC *)defs->builtins->array[defs->builtins->sindex - 1]);
+ if (defs->builtins)
+ return ((BUILTIN_DESC *)defs->builtins->array[defs->builtins->sindex - 1]);
+ else
+ return ((BUILTIN_DESC *)NULL);
}
/* Add LINE to the long documentation for the current builtin.
builtin = current_builtin (self, defs);
+ if (builtin == 0)
+ {
+ line_error (defs, "syntax error: no current builtin for $FUNCTION directive");
+ exit (1);
+ }
if (builtin->function)
line_error (defs, "%s already has a function (%s)",
builtin->name, builtin->function);
new = (BUILTIN_DESC *)xmalloc (sizeof (BUILTIN_DESC));
- new->name = savestring (builtin->name);
- new->shortdoc = savestring (builtin->shortdoc);
- new->longdoc = copy_string_array (builtin->longdoc);
+ new->name = savestring (builtin->name);
+ new->shortdoc = savestring (builtin->shortdoc);
+ new->longdoc = copy_string_array (builtin->longdoc);
new->dependencies = copy_string_array (builtin->dependencies);
new->function =
"",
" Bash is free software; you can redistribute it and/or modify it",
" under the terms of the GNU General Public License as published by",
- " the Free Software Foundation; either version 1, or (at your option)",
+ " the Free Software Foundation; either version 2, or (at your option)",
" any later version.",
"",
" Bash is distributed in the hope that it will be useful, but WITHOUT",
"",
" You should have received a copy of the GNU General Public License",
" along with Bash; see the file COPYING. If not, write to the Free",
- " Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */",
+ " Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */",
"",
"/* The list of shell builtins. Each element is name, function, flags,",
" long-doc, short-doc. The long-doc field contains a pointer to an array",
builtin->function);
fprintf (externfile, "extern char *%s_doc[];\n",
- builtin->docname ?builtin->docname : builtin->name);
+ builtin->docname ? builtin->docname : builtin->name);
}
/* Write the structure definition. */
{
return (_find_in_table (name, assignment_builtins));
}
+
+#if !defined (HAVE_RENAME)
+static int
+rename (from, to)
+ char *from, *to;
+{
+ unlink (to);
+ if (link (from, to) < 0)
+ return (-1);
+ unlink (from);
+ return (0);
+}
+#endif /* !HAVE_RENAME */