error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"
char *load_file  _P_((const char *));void process  _P_((char *, const char *));void run_compiles ();void wait_for_pid _P_(( pid_t ));void initialize ();#include "fixincl.x"/* * * * * * * * * * * * * * * * * * * * *  MAIN ROUTINE */intmain (argc, argv)     int argc;     char **argv;{  static const char gnu_lib_mark[] =    "This file is part of the GNU C Library";#ifndef NO_BOGOSITY_LIMITS# define BOGUS_LIMIT    MINIMUM_MAXIMUM_LINES  size_t loop_ct;#endif  char *apz_names[BOGUS_LIMIT];  size_t file_name_ct;  /* Before anything else, ensure we can allocate our file name buffer. */  file_name_buf = (char *) malloc (NAME_TABLE_SIZE);  if (file_name_buf == (char *) NULL)    {      fprintf (stderr, "fixincl cannot allocate 0x%08X bytes\n",               NAME_TABLE_SIZE);      exit (EXIT_FAILURE);    }  switch (argc)    {    case 1:      break;    case 2:      if (strcmp (argv[1], "-v") == 0)        {          static const char zFmt[] = "echo '%s'";          /* The 'version' option is really used to test that:               1.  The program loads correctly (no missing libraries)               2.  we can correctly run our server shell process               3.  that we can compile all the regular expressions.           */          run_compiles ();          sprintf (file_name_buf, zFmt, program_id);          fputs (file_name_buf + 5, stdout);          exit (strcmp (run_shell (file_name_buf), program_id));        }      freopen (argv[1], "r", stdin);      break;    default:      fputs ("fixincl ERROR:  too many command line arguments\n", stderr);      exit (EXIT_FAILURE);    }  initialize ();#ifndef NO_BOGOSITY_LIMITS  /*  Some systems only allow so many calls to fork(2).      This is inadequate for this program.  Consequently,      we must let a grandfather process spawn children      that then spawn all the processes that do the real work.      */  for (;;)    {      file_name_ct = 0;      {        char *pz_buf = file_name_buf;        /* Only the parent process can read from stdin without confusing           the world. (How does the child tell the parent to skip           forward?  Pipes and files behave differently.)  */        while (  (file_name_ct < BOGUS_LIMIT)              && (pz_buf < (file_name_buf + NAME_TABLE_SIZE - MAXPATHLEN)))          {            if (fgets (pz_buf, MAXPATHLEN, stdin) == (char *) NULL)              break;            while (isspace (*pz_buf))              pz_buf++;            if ((*pz_buf == '\0') || (*pz_buf == '#'))              continue;            apz_names[file_name_ct++] = pz_buf;            pz_buf += strlen (pz_buf);            while (isspace (pz_buf[-1]))              pz_buf--;            *pz_buf++ = '\0';          }      }      /*  IF we did not get any files this time thru          THEN we must be done.  */      if (file_name_ct == 0)        return EXIT_SUCCESS;      fflush (stdout);      fflush (stderr);      {        pid_t child = fork ();        if (child == NULLPROCESS)          break;        if (child == NOPROCESS)          {            fprintf (stderr, "Error %d (%s) forking in main\n",                     errno, strerror (errno));            exit (EXIT_FAILURE);          }#ifdef DEBUG        fprintf (stderr, "Waiting for %d to complete %d files\n",                 child, file_name_ct);#endif        wait_for_pid( child, file_name_ct );      }    }#else#error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"#endif  /*     Here we are the child of the grandparent process.  The parent     of all the little fixup processes.  We ignore the deaths of     our children.  */  signal (SIGCLD,  SIG_IGN);  /*  For every file specified in stdandard in      (except as throttled for bogus reasons)...      */  for (loop_ct = 0; loop_ct < file_name_ct; loop_ct++)    {      char *pz_data;      char *pz_file_name = apz_names[loop_ct];      if (access (pz_file_name, R_OK) != 0)        {          int erno = errno;          fprintf (stderr, "Cannot access %s from %s\n\terror %d (%s)\n",                   pz_file_name, getcwd ((char *) NULL, MAXPATHLEN),                   erno, strerror (erno));        }      else if (pz_data = load_file (pz_file_name), (pz_data != (char *) NULL))        {          if (strstr (pz_data, gnu_lib_mark) == (char *) NULL)            process (pz_data, pz_file_name);          free ((void *) pz_data);        }    }  return EXIT_SUCCESS;}/* * * * * * * * * * * * */voidinitialize(){  static const char var_not_found[] =    "fixincl ERROR:  %s environment variable not defined\n";  {    static const char var[] = "TARGET_MACHINE";    pz_machine = getenv (var);    if (pz_machine == (char *) NULL)      {        fprintf (stderr, var_not_found, var);        exit (EXIT_FAILURE);      }  }  {    static const char var[] = "DESTDIR";    pz_dest_dir = getenv (var);    if (pz_dest_dir == (char *) NULL)      {        fprintf (stderr, var_not_found, var);        exit (EXIT_FAILURE);      }  }  {    static const char var[] = "SRCDIR";    pz_src_dir = getenv (var);    if (pz_src_dir == (char *) NULL)      {        fprintf (stderr, var_not_found, var);        exit (EXIT_FAILURE);      }  }  {    static const char var[] = "FIND_BASE";    pz_find_base = getenv (var);    if (pz_find_base == (char *) NULL)      {        fprintf (stderr, var_not_found, var);        exit (EXIT_FAILURE);      }    find_base_len = strlen( pz_find_base );  }  /*  Compile all the regular expressions now.      That way, it is done only once for the whole run.      */  run_compiles ();  signal (SIGQUIT, SIG_IGN);  signal (SIGIOT,  SIG_IGN);  signal (SIGPIPE, SIG_IGN);  signal (SIGALRM, SIG_IGN);  signal (SIGTERM, SIG_IGN);  /*     Make sure that if we opened a server process, we close it now.     This is the grandparent process.  We don't need the server anymore     and our children should make their own.  */  close_server ();  (void)wait ( (int*)NULL );}/* * * * * * * * * * * * *    wait_for_pid  -  Keep calling `wait(2)' until it returns   the process id we are looking for.  Not every system has   `waitpid(2)'.  We also ensure that the children exit with success. */voidwait_for_pid( pid_t child, int file_name_ct ){  for (;;) {    int status;    pid_t dead_kid = wait (&status);    if (dead_kid == child)      {        if (! WIFEXITED( status ))          {            fprintf (stderr, "child process %d is hung on signal %d\n",                     child, WSTOPSIG( status ));            exit (EXIT_FAILURE);          }        if (WEXITSTATUS( status ) != 0)          {            fprintf (stderr, "child process %d exited with status %d\n",                     child, WEXITSTATUS( status ));            exit (EXIT_FAILURE);          }        break; /* normal child completion */      }    /*       IF there is an error, THEN see if it is retryable.       If it is not retryable, then break out of this loop.  */    if (dead_kid == NOPROCESS)      {        switch (errno) {        case EINTR:        case EAGAIN:          break;        default:          fprintf (stderr, "Error %d (%s) waiting for %d to finish\n",                   errno, strerror( errno ), child );          /* FALLTHROUGH */        case ECHILD: /* no children to wait for?? */          return;        }      }  } done_waiting:;}/* * * * * * * * * * * * *    load_file loads all the contents of a file into malloc-ed memory.   Its argument is the name of the file to read in; the returned   result is the NUL terminated contents of the file.  The file   is presumed to be an ASCII text file containing no NULs.  */char *load_file (pz_file_name)     const char *pz_file_name;{  char *pz_data;  size_t file_size;  {    struct stat stbf;        if (stat (pz_file_name, &stbf) != 0)      {        fprintf (stderr, "error %d (%s) stat-ing %s\n",                 errno, strerror (errno), pz_file_name);        return (char *) NULL;      }    file_size = stbf.st_size;  }  if (file_size == 0)    return (char *) NULL;  pz_data = (char *) malloc ((file_size + 16) & ~0x00F);  if (pz_data == (char *) NULL)    {      fprintf (stderr, "error:  could not malloc %d bytes\n",               file_size);      exit (EXIT_FAILURE);    }  {    FILE *fp = fopen (pz_file_name, "r");    size_t size_left = file_size;    char *read_ptr = pz_data;    if (fp == (FILE *) NULL)      {        fprintf (stderr, "error %d (%s) opening %s\n", errno,                 strerror (errno), pz_file_name);        free ((void *) pz_data);        return (char *) NULL;      }    do      {        size_t sizeRead = fread ((void *) read_ptr, 1, size_left, fp);        if (sizeRead == 0)          {            if (feof (fp))              break;            if (ferror (fp))              {                int err = errno;                if (err != EISDIR)                  fprintf (stderr, "error %d (%s) reading %s\n", err,                           strerror (err), pz_file_name);                free ((void *) pz_data);                fclose (fp);                return (char *) NULL;              }          }        read_ptr += sizeRead;        size_left -= sizeRead;      }    while (size_left != 0);    *read_ptr = '\0';    fclose (fp);  }  return pz_data;}