This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bash build fix

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:
but no solution ever was posted.

Hugh Winkler
Scout Systems, Inc.

* repaired implementation of extract_info()

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)
  if ((nread=read (fd, buffer, finfo.st_size)) != finfo.st_size)
    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
      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);
	      /* Advance to the first non-whitespace character. */
	      while (whitespace (line[j]))

	      /* Call the directive handler with the FILE, and ARGS. */
	      (*(handler->function)) (directive, defs, line + j);
	  free (directive);
	  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);
		    fprintf (defs->output, "#line %d \"%s%s\"\n",
			     defs->line_number + 1,
			     error_directory ? error_directory : "./",
		  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
"" with one line of text: "help".

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]