fixincl.c extract_quoted_files rewrite

korbb@egcs.cygnus.com korbb@egcs.cygnus.com
Fri May 7 09:40:00 GMT 1999


Reply-To: ddsinc09@ix.netcom.com


This is not really a full rewrite, it just bypasses
the output phase if if a new procedure "quoted_file_exists"
returns zero (false).  I have tried it successfully
on my box (i386 Linux :)

 - Bruce


int
quoted_file_exists (pz_path, pz_file)
     char* pz_path;
     char* pz_file;
{
  char z[ MAXPATHLEN ];
  char* pz;
  strcpy( z, pz_path );
  pz = z + strlen( z );
  if (pz[-1] != '/')
    *pz++ = '/';
  for (;;) {
    char ch = *pz_file++;
    if (! isgraph( ch ))
      return 0;
    if (ch == '"')
      break;
    *pz++ = ch;
  }
  *pz = '\0';
  {
    struct stat s;
    if (stat (z, &s) != 0)
      return 0;
    return S_ISREG( s.st_mode );
  }
}


void
extract_quoted_files (pz_data, pz_file_name, p_re_match)
     char *pz_data;
     const char *pz_file_name;
     regmatch_t *p_re_match;
{
  char *pz_dir_end = strrchr (pz_file_name, '/');
  char *pz_incl_quot = pz_data;

  fprintf (stderr, "Quoted includes in %s\n", pz_file_name);

  /*  Set "pz_file_name" to point to the containing subdirectory of the source
      If there is none, then it is in our current direcory, ".".   */

  if (pz_dir_end == (char *) NULL)
    pz_file_name = ".";
  else
    *pz_dir_end = '\0';

  for (;;)
    {
      pz_incl_quot += p_re_match->rm_so;

      /*  Skip forward to the included file name */
      while (isspace (*pz_incl_quot))
        pz_incl_quot++;
      while (isspace (*++pz_incl_quot))
        ;
      pz_incl_quot += sizeof ("include") - 1;
      while (*pz_incl_quot++ != '"')
        ;

      if (quoted_file_exists (pz_file_name, pz_incl_quot))
        {
          /* Print the source directory and the subdirectory
             of the file in question.  */
          printf ("%s  %s/", pz_src_dir, pz_file_name);
          pz_dir_end = pz_incl_quot;

          /* Append to the directory the relative path of the desired file */
          while (*pz_incl_quot != '"')
            putc (*pz_incl_quot++, stdout);

          /* Now print the destination directory appended with the
             relative path of the desired file */
          printf ("  %s/%s/", pz_dest_dir, pz_file_name);
          while (*pz_dir_end != '"')
            putc (*pz_dir_end++, stdout);

          /* End of entry */
          putc ('\n', stdout);
        }

      /* Find the next entry */
      if (regexec (&incl_quote_re, pz_incl_quot, 1, p_re_match, 0) != 0)
        break;
    }
}


More information about the Gcc-patches mailing list