Subject: bash build fix
From: [email-masked] (Hugh Winkler)

27 Aug 1998 03:49:37 -0700
Message-ID: <[email-masked]>
Reply-To: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
To: <[email-masked]>

Building bash using B19.1 failed, until I made changes as below to the
function extract_info() in file mkbuiltins.c

mkbuild was translating .def files incorrectly. The problem arises because
read() returns the number of characters in the file, after converting
CR/LFs. This number is smaller than that returned by stat()in finfo.st_size.

Someone reported the problem on this list:
http://www.cygnus.com/ml/gnu-win32/1998-May/0012.html
but no solution ever was posted.

Hugh Winkler
Scout Systems, Inc.

/*
* repaired implementation of extract_info()
*/

void
extract_info (filename, structfile, externfile)
     char *filename;
     FILE *structfile, *externfile;
{
  register int i;
  DEF_FILE *defs;
  struct stat finfo;
  char *buffer, *line;
  int fd;
  int nread;

  if (stat (filename, &finfo) == -1)
    file_error (filename);

  fd = open (filename, O_RDONLY, 0666);

  if (fd == -1)
    file_error (filename);

  buffer = xmalloc (1 + (int)finfo.st_size);

#ifdef __CYGWIN32__
  if ((nread=read (fd, buffer, finfo.st_size)) < finfo.st_size/2)
#else
  if ((nread=read (fd, buffer, finfo.st_size)) != finfo.st_size)
#endif
    file_error (filename);

  close (fd);

  /* Create and fill in the initial structure describing this file. */
  defs = (DEF_FILE *)xmalloc (sizeof (DEF_FILE));
  defs->filename = filename;
  defs->lines = array_create (sizeof (char *));
  defs->line_number = 0;
  defs->production = (char *)NULL;
  defs->output = (FILE *)NULL;
  defs->builtins = (ARRAY *)NULL;

  /* Build the array of lines. */
  i = 0;
  while (i < nread)
    {
      array_add (&buffer[i], defs->lines);

      while (buffer[i] != '\n' && i < nread) //hvw
	i++;
      buffer[i++] = '\0';

    }

  /* Begin processing the input file.  We don't write any output
     until we have a file to write output to. */
  output_cpp_line_info = 1;

  /* Process each line in the array. */
  for (i = 0; line = defs->lines->array[i]; i++)
    {
      defs->line_number = i;

      if (*line == '$')
	{
	  register int j;
	  char *directive;
	  HANDLER_ENTRY *handler;

	  /* Isolate the directive. */
	  for (j = 0; line[j] && !whitespace (line[j]); j++);

	  directive = xmalloc (j);
	  strncpy (directive, line + 1, j - 1);
	  directive[j -1] = '\0';

	  /* Get the function handler and call it. */
	  handler = find_directive (directive);

	  if (!handler)
	    {
	      line_error (defs, "Unknown directive `%s'", directive);
	      free (directive);
	      continue;
	    }
	  else
	    {
	      /* Advance to the first non-whitespace character. */
	      while (whitespace (line[j]))
		j++;

	      /* Call the directive handler with the FILE, and ARGS. */
	      (*(handler->function)) (directive, defs, line + j);
	    }
	  free (directive);
	}
      else
	{
	  if (building_builtin)
	    add_documentation (defs, line);
	  else if (defs->output)
	    {
	      if (output_cpp_line_info)
		{
		  /* If we're handed an absolute pathname, don't prepend
		     the directory name. */
		  if (defs->filename[0] == '/')
		    fprintf (defs->output, "#line %d \"%s\"\n",
			     defs->line_number + 1, defs->filename);
		  else
		    fprintf (defs->output, "#line %d \"%s%s\"\n",
			     defs->line_number + 1,
			     error_directory ? error_directory : "./",
			     defs->filename);
		  output_cpp_line_info = 0;
		}

	      fprintf (defs->output, "%s\n", line);
	    }
	}
    }

  /* Close the production file. */
  if (defs->output)
    fclose (defs->output);

  /* The file has been processed.  Write the accumulated builtins to
     the builtins.c file, and write the extern definitions to the
     builtext.h file. */
  write_builtins (defs, structfile, externfile);

  free (buffer);
  free_defs (defs);
}

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".