home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / dif115as.zip / DIFF.C < prev    next >
C/C++ Source or Header  |  1992-02-22  |  20KB  |  723 lines

  1. /* GNU DIFF main routine.
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU DIFF is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU DIFF; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* GNU DIFF was written by Mike Haertel, David Hayes,
  21.    Richard Stallman and Len Tower.  */
  22.  
  23. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  24. This port is also distributed under the terms of the GNU General
  25. Public License as published by the Free Software Foundation.
  26.  
  27. Please note that this file is not identical to the original GNU release,
  28. you should have received this code as patch to the official release.
  29.  
  30. $Header: e:/gnu/diff/RCS/diff.c 1.15.0.2 91/03/12 17:06:09 tho Exp $  */
  31.  
  32. #define GDIFF_MAIN
  33. #include "regex.h"
  34. #include "diff.h"
  35. #include "getopt.h"
  36.  
  37. #ifdef __STDC__
  38. extern  void main (int argc, char **argv);
  39. static    void usage(void);
  40. static    char *option_list(char * *, int);
  41. static    void specify_style(enum output_style);
  42. static  int compare_files(char *, char *, char *, char *, int);
  43. extern  int getopt(int, char * *, char *);
  44. #else
  45. static    void usage();
  46. static    char *option_list();
  47. static    void specify_style();
  48. static  int compare_files();
  49. extern  int getopt();
  50. #endif /* __STDC__ */
  51.  
  52. /* Nonzero for -r: if comparing two directories,
  53.    compare their common subdirectories recursively.  */
  54.  
  55. int recursive;
  56.  
  57. /* For debugging: don't do discard_confusing_lines.  */
  58.  
  59. int no_discards;
  60.  
  61. /* Return a string containing the command options with which diff was invoked.
  62.    Spaces appear between what were separate ARGV-elements.
  63.    There is a space at the beginning but none at the end.
  64.    If there were no options, the result is an empty string.
  65.  
  66.    Arguments: OPTIONVEC, a vector containing separate ARGV-elements, and COUNT,
  67.    the length of that vector.  */
  68.  
  69. static char *
  70. option_list (optionvec, count)
  71.      char **optionvec;  /* Was `vector', but that collides on Alliant.  */
  72.      int count;
  73. {
  74.   int i;
  75.   int length = 0;
  76.   char *result;
  77.  
  78.   for (i = 0; i < count; i++)
  79.     length += strlen (optionvec[i]) + 1;
  80.  
  81.   result = (char *) xmalloc (length + 1);
  82.   result[0] = 0;
  83.  
  84.   for (i = 0; i < count; i++)
  85.     {
  86.       strcat (result, " ");
  87.       strcat (result, optionvec[i]);
  88.     }
  89.  
  90.   return result;
  91. }
  92.  
  93. /* The numbers 129 and 130 that appear in the fourth element
  94.    for the context and unidiff entries are used as a way of
  95.    telling the big switch in `main' how to process those options.  */
  96.  
  97. static struct option longopts[] =
  98. {
  99.   {"ignore-blank-lines", 0, 0, 'B'},
  100.   {"context", 2, 0, 129},
  101.   {"ifdef", 1, 0, 'D'},
  102.   {"show-function-line", 1, 0, 'F'},
  103.   {"speed-large-files", 0, 0, 'H'},
  104.   {"ignore-matching-lines", 1, 0, 'I'},
  105.   {"file-label", 1, 0, 'L'},
  106.   {"entire-new-files", 0, 0, 'N'},
  107.   {"new-files", 0, 0, 'N'},
  108.   {"starting-file", 1, 0, 'S'},
  109.   {"initial-tab", 0, 0, 'T'},
  110.   {"text", 0, 0, 'a'},
  111.   {"all-text", 0, 0, 'a'},
  112.   {"ascii", 0, 0, 'a'},
  113.   {"ignore-space-change", 0, 0, 'b'},
  114.   {"minimal", 0, 0, 'd'},
  115.   {"ed", 0, 0, 'e'},
  116.   {"reversed-ed", 0, 0, 'f'},
  117.   {"ignore-case", 0, 0, 'i'},
  118.   {"print", 0, 0, 'l'},
  119.   {"rcs", 0, 0, 'n'},
  120.   {"show-c-function", 0, 0, 'p'},
  121.   {"binary", 0, 0, 'q'},
  122.   {"brief", 0, 0, 'q'},
  123.   {"recursive", 0, 0, 'r'},
  124.   {"report-identical-files", 0, 0, 's'},
  125.   {"expand-tabs", 0, 0, 't'},
  126.   {"ignore-all-space", 0, 0, 'w'},
  127.   {"unified", 2, 0, 130},
  128.   {"version", 0, 0, 'v'},
  129.   {0, 0, 0, 0}
  130. };
  131.  
  132. #ifdef __STDC__
  133. void
  134. #endif /* __STDC__ */
  135. main (argc, argv)
  136.      int argc;
  137.      char *argv[];
  138. {
  139.   int val;
  140.   int c;
  141.   int prev = -1;
  142.   int longind;
  143.   extern char *version_string;
  144.  
  145.   program = argv[0];
  146.  
  147.   /* Do our initializations. */
  148.   output_style = OUTPUT_NORMAL;
  149.   always_text_flag = FALSE;
  150.   ignore_space_change_flag = FALSE;
  151.   ignore_all_space_flag = FALSE;
  152.   length_varies = FALSE;
  153.   ignore_case_flag = FALSE;
  154.   ignore_blank_lines_flag = FALSE;
  155.   ignore_regexp = 0;
  156.   function_regexp = 0;
  157.   print_file_same_flag = FALSE;
  158.   entire_new_file_flag = FALSE;
  159.   no_details_flag = FALSE;
  160.   context = -1;
  161.   line_end_char = '\n';
  162.   tab_align_flag = FALSE;
  163.   tab_expand_flag = FALSE;
  164.   recursive = FALSE;
  165.   paginate_flag = FALSE;
  166.   ifdef_string = NULL;
  167.   heuristic = FALSE;
  168.   dir_start_file = NULL;
  169.   msg_chain = NULL;
  170.   msg_chain_end = NULL;
  171.   no_discards = 0;
  172.  
  173.   /* Decode the options.  */
  174.  
  175.   while ((c = getopt_long (argc, argv,
  176.                "0123456789abBcC:dD:efF:hHiI:lL:nNpqrsS:tTuvw",
  177.                longopts, &longind)) != EOF)
  178.     {
  179.       if (c == 0)        /* Long option. */
  180.     c = longopts[longind].val;
  181.       switch (c)
  182.     {
  183.       /* All digits combine in decimal to specify the context-size.  */
  184.     case '1':
  185.     case '2':
  186.     case '3':
  187.     case '4':
  188.     case '5':
  189.     case '6':
  190.     case '7':
  191.     case '8':
  192.     case '9':
  193.     case '0':
  194.       if (context == -1)
  195.         context = 0;
  196.       /* If a context length has already been specified,
  197.          more digits allowed only if they follow right after the others.
  198.          Reject two separate runs of digits, or digits after -C.  */
  199.       else if (prev < '0' || prev > '9')
  200.         fatal ("context length specified twice");
  201.  
  202.       context = context * 10 + c - '0';
  203.       break;
  204.  
  205.     case 'a':
  206.       /* Treat all files as text files; never treat as binary.  */
  207.       always_text_flag = 1;
  208.       break;
  209.  
  210.     case 'b':
  211.       /* Ignore changes in amount of whitespace.  */
  212.       ignore_space_change_flag = 1;
  213.       length_varies = 1;
  214.       break;
  215.  
  216.     case 'B':
  217.       /* Ignore changes affecting only blank lines.  */
  218.       ignore_blank_lines_flag = 1;
  219.       break;
  220.  
  221.     case 'C':
  222.     case 129:        /* +context[=lines] */
  223.     case 130:        /* +unified[=lines] */
  224.       if (optarg)
  225.         {
  226.           if (context >= 0)
  227.         fatal ("context length specified twice");
  228.           {
  229.         char *p;
  230.         for (p = optarg; *p; p++)
  231.           if (*p < '0' || *p > '9')
  232.             fatal ("invalid context length argument");
  233.           }
  234.           context = atoi (optarg);
  235.         }
  236.  
  237.       /* Falls through.  */
  238.     case 'c':
  239.       /* Make context-style output.  */
  240.       specify_style (c == 130 ? OUTPUT_UNIFIED : OUTPUT_CONTEXT);
  241.       break;
  242.  
  243.     case 'd':
  244.       /* Don't discard lines.  This makes things slower (sometimes much
  245.          slower) but will find a guaranteed minimal set of changes.  */
  246.       no_discards = 1;
  247.       break;
  248.  
  249.     case 'D':
  250.       /* Make merged #ifdef output.  */
  251.       specify_style (OUTPUT_IFDEF);
  252.       ifdef_string = optarg;
  253.       break;
  254.  
  255.     case 'e':
  256.       /* Make output that is a valid `ed' script.  */
  257.       specify_style (OUTPUT_ED);
  258.       break;
  259.  
  260.     case 'f':
  261.       /* Make output that looks vaguely like an `ed' script
  262.          but has changes in the order they appear in the file.  */
  263.       specify_style (OUTPUT_FORWARD_ED);
  264.       break;
  265.  
  266.     case 'F':
  267.       /* Show, for each set of changes, the previous line that
  268.          matches the specified regexp.  Currently affects only
  269.          context-style output.  */
  270.       function_regexp = optarg;
  271.       break;
  272.  
  273.     case 'h':
  274.       /* Split the files into chunks of around 1500 lines
  275.          for faster processing.  Usually does not change the result.
  276.  
  277.          This currently has no effect.  */
  278.       break;
  279.  
  280.     case 'H':
  281.       /* Turn on heuristics that speed processing of large files
  282.          with a small density of changes.  */
  283.       heuristic = 1;
  284.       break;
  285.  
  286.     case 'i':
  287.       /* Ignore changes in case.  */
  288.       ignore_case_flag = 1;
  289.       break;
  290.  
  291.     case 'I':
  292.       /* Ignore changes affecting only lines that match the
  293.          specified regexp.  */
  294.       ignore_regexp = optarg;
  295.       break;
  296.  
  297.     case 'l':
  298.       /* Pass the output through `pr' to paginate it.  */
  299.       paginate_flag = 1;
  300.       break;
  301.  
  302.     case 'L':
  303.       /* Specify file labels for `-c' output headers.  */
  304.       if (!file_label[0])
  305.         file_label[0] = optarg;
  306.       else if (!file_label[1])
  307.         file_label[1] = optarg;
  308.       else
  309.         fatal ("too many file label options");
  310.       break;
  311.  
  312.     case 'n':
  313.       /* Output RCS-style diffs, like `-f' except that each command
  314.          specifies the number of lines affected.  */
  315.       specify_style (OUTPUT_RCS);
  316.       break;
  317.  
  318.     case 'N':
  319.       /* When comparing directories, if a file appears only in one
  320.          directory, treat it as present but empty in the other.  */
  321.       entire_new_file_flag = 1;
  322.       break;
  323.  
  324.     case 'p':
  325.       /* Make context-style output and show name of last C function.  */
  326.       specify_style (OUTPUT_CONTEXT);
  327.       function_regexp = "^[_a-zA-Z]";
  328.       break;
  329.  
  330.     case 'q':
  331.       no_details_flag = 1;
  332.       break;
  333.  
  334.     case 'r':
  335.       /* When comparing directories, 
  336.          recursively compare any subdirectories found.  */
  337.       recursive = 1;
  338.       break;
  339.  
  340.     case 's':
  341.       /* Print a message if the files are the same.  */
  342.       print_file_same_flag = 1;
  343.       break;
  344.  
  345.     case 'S':
  346.       /* When comparing directories, start with the specified
  347.          file name.  This is used for resuming an aborted comparison.  */
  348.       dir_start_file = optarg;
  349.       break;
  350.  
  351.     case 't':
  352.       /* Expand tabs to spaces in the output so that it preserves
  353.          the alignment of the input files.  */
  354.       tab_expand_flag = 1;
  355.       break;
  356.  
  357.     case 'T':
  358.       /* Use a tab in the output, rather than a space, before the
  359.          text of an input line, so as to keep the proper alignment
  360.          in the input line without changing the characters in it.  */
  361.       tab_align_flag = 1;
  362.       break;
  363.  
  364.     case 'v':
  365.       printf ("GNU diff version %s\n", version_string);
  366.       break;
  367.  
  368.     case 'u':
  369.       /* Output the context diff in unidiff format.  */
  370.       specify_style (OUTPUT_UNIFIED);
  371.       break;
  372.  
  373.     case 'w':
  374.       /* Ignore horizontal whitespace when comparing lines.  */
  375.       ignore_all_space_flag = 1;
  376.       length_varies = 1;
  377.       break;
  378.  
  379.     default:
  380.       usage ();
  381.     }
  382.       prev = c;
  383.     }
  384.  
  385.   if (optind != argc - 2)
  386.     usage ();
  387.  
  388.   if (ignore_regexp)
  389.     {
  390.       char *val;
  391.       bzero (&ignore_regexp_compiled, sizeof ignore_regexp_compiled);
  392.       val = re_compile_pattern (ignore_regexp, strlen (ignore_regexp),
  393.                 &ignore_regexp_compiled);
  394.       if (val != 0)
  395.     error ("%s: %s", ignore_regexp, val);
  396.       ignore_regexp_compiled.fastmap = (char *) xmalloc (256);
  397.     }
  398.  
  399.   if (function_regexp)
  400.     {
  401.       char *val;
  402.       bzero (&function_regexp_compiled, sizeof function_regexp_compiled);
  403.       val = re_compile_pattern (function_regexp, strlen (function_regexp),
  404.                 &function_regexp_compiled);
  405.       if (val != 0)
  406.     error ("%s: %s", function_regexp, val);
  407.       function_regexp_compiled.fastmap = (char *) xmalloc (256);
  408.     }
  409.  
  410.   if (output_style != OUTPUT_CONTEXT && output_style != OUTPUT_UNIFIED)
  411.     context = 0;
  412.   else if (context == -1)
  413.     /* Default amount of context for -c.  */
  414.     context = 3;
  415.  
  416.   switch_string = option_list (argv + 1, optind - 1);
  417.  
  418.   val = compare_files (0, argv[optind], 0, argv[optind + 1], 0);
  419.  
  420.   /* Print any messages that were saved up for last.  */
  421.   print_message_queue ();
  422.  
  423.   if (ferror (stdout) || fclose (stdout) != 0)
  424.     fatal ("write error");
  425.   exit (val);
  426. }
  427.  
  428. void
  429. usage ()
  430. {
  431.   fprintf (stderr, "\
  432. Usage: diff [-#] [-abBcdefhHilnNprstTuvw] [-C lines] [-F regexp] [-I regexp]\n\
  433.        [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
  434.        [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
  435.        [+show-function-line=regexp]\n");
  436.   fprintf (stderr, "\
  437.        [+speed-large-files] [+ignore-matching-lines=regexp] [+new-file]\n\
  438.        [+initial-tab] [+starting-file=file] [+text] [+all-text] [+ascii]\n\
  439.        [+minimal] [+ignore-space-change] [+ed] [+reversed-ed] [+ignore-case]\n");
  440.   fprintf (stderr, "\
  441.        [+print] [+rcs] [+show-c-function] [+binary] [+brief] [+recursive]\n\
  442.        [+report-identical-files] [+expand-tabs] [+ignore-all-space]\n\
  443.        [+file-label=label [+file-label=label]] [+version] path1 path2\n");
  444.   exit (2);
  445.  
  446. void
  447. specify_style (style)
  448.      enum output_style style;
  449. {
  450.   if (output_style != OUTPUT_NORMAL
  451.       && output_style != style)
  452.     error ("conflicting specifications of output style");
  453.   output_style = style;
  454. }
  455.  
  456. /* Compare two files (or dirs) with specified names
  457.    DIR0/NAME0 and DIR1/NAME1, at level DEPTH in directory recursion.
  458.    (if DIR0 is 0, then the name is just NAME0, etc.)
  459.    This is self-contained; it opens the files and closes them.
  460.  
  461.    Value is 0 if files are identical, 1 if different,
  462.    2 if there is a problem opening them.  */
  463.  
  464. int
  465. compare_files (dir0, name0, dir1, name1, depth)
  466.      char *dir0, *dir1;
  467.      char *name0, *name1;
  468.      int depth;
  469. {
  470.   static char Standard_Input[] = "Standard Input";
  471.   struct file_data inf[2];
  472.   register int i;
  473.   int val;
  474.   int errorcount = 0;
  475.   int stat_result[2];
  476.  
  477.   /* If this is directory comparison, perhaps we have a file
  478.      that exists only in one of the directories.
  479.      If so, just print a message to that effect.  */
  480.  
  481.   if (! entire_new_file_flag && (name0 == 0 || name1 == 0))
  482.     {
  483.       char *name = name0 == 0 ? name1 : name0;
  484.       char *dir = name0 == 0 ? dir1 : dir0;
  485.       message ("Only in %s: %s\n", dir, name);
  486.       /* Return 1 so that diff_dirs will return 1 ("some files differ").  */
  487.       return 1;
  488.     }
  489.  
  490.   /* Mark any nonexistent file with -1 in the desc field.  */
  491.   /* Mark unopened files (i.e. directories) with -2. */
  492.  
  493.   inf[0].desc = name0 == 0 ? -1 : -2;
  494.   inf[1].desc = name1 == 0 ? -1 : -2;
  495.  
  496.   /* Now record the full name of each file, including nonexistent ones.  */
  497.  
  498.   if (name0 == 0)
  499.     name0 = name1;
  500.   if (name1 == 0)
  501.     name1 = name0;
  502.  
  503.   inf[0].name = dir0 == 0 ? name0 : concat (dir0, "/", name0);
  504.   inf[1].name = dir1 == 0 ? name1 : concat (dir1, "/", name1);
  505.  
  506.   /* Stat the files.  Record whether they are directories.
  507.      Record in stat_result whether stat fails.  */
  508.  
  509.   for (i = 0; i <= 1; i++)
  510.     {
  511.       bzero (&inf[i].stat, sizeof(struct stat));
  512.       inf[i].dir_p = 0;
  513.       stat_result[i] = 0;
  514.  
  515.       if (inf[i].desc != -1)
  516.     {
  517.       char *filename = inf[i].name;
  518.  
  519.       stat_result[i] = 
  520.         strcmp (filename, "-")
  521.           ? stat (filename, &inf[i].stat)
  522.           : fstat (0, &inf[i].stat);
  523.           
  524.       if (stat_result[i] < 0)
  525.         {
  526.           perror_with_name (filename);
  527.           errorcount = 1;
  528.         }
  529.       else
  530.         inf[i].dir_p = 
  531.           S_IFDIR == (inf[i].stat.st_mode & S_IFMT)
  532.           && strcmp (filename, "-");
  533.     }
  534.     }
  535.  
  536.   /* See if the two named files are actually the same physical file.
  537.      If so, we know they are identical without actually reading them.  */
  538.  
  539. #ifndef MSDOS
  540.   if (output_style != OUTPUT_IFDEF
  541.       && inf[0].stat.st_ino == inf[1].stat.st_ino
  542.       && inf[0].stat.st_dev == inf[1].stat.st_dev
  543.       && stat_result[0] == 0
  544.       && stat_result[1] == 0)
  545.     {
  546.       val = 0;
  547.       goto done;
  548.     }
  549. #endif /* MSDOS */
  550.  
  551.   if (name0 == 0)
  552.     inf[0].dir_p = inf[1].dir_p;
  553.   if (name1 == 0)
  554.     inf[1].dir_p = inf[0].dir_p;
  555.  
  556.   /* Open the files and record their descriptors.  */
  557.  
  558.   for (i = 0; i <= 1; i++)
  559.     {
  560.       if (inf[i].desc == -1)
  561.     ;
  562.       else if (!strcmp (inf[i].name, "-"))
  563.     {
  564.       inf[i].desc = 0;
  565.       inf[i].name = Standard_Input;
  566.     }
  567.       /* Don't bother opening if stat already failed.  */
  568.       else if (stat_result[i] == 0 && ! inf[i].dir_p)
  569.     {
  570.       char *filename = inf[i].name;
  571.  
  572.       inf[i].desc = open (filename, O_RDONLY, 0);
  573.       if (0 > inf[i].desc)
  574.         {
  575.           perror_with_name (filename);
  576.           errorcount = 1;
  577.         }
  578.     }
  579.     }
  580.  
  581.   if (errorcount)
  582.     {
  583.  
  584.       /* If either file should exist but fails to be opened, return 2.  */
  585.  
  586.       val = 2;
  587.  
  588.     }
  589.   else if (inf[0].dir_p && inf[1].dir_p)
  590.     {
  591.       if (output_style == OUTPUT_IFDEF)
  592.     fatal ("-D option not supported with directories");
  593.  
  594.       /* If both are directories, compare the files in them.  */
  595.  
  596.       if (depth > 0 && !recursive)
  597.     {
  598.       /* But don't compare dir contents one level down
  599.          unless -r was specified.  */
  600.       message ("Common subdirectories: %s and %s\n",
  601.            inf[0].name, inf[1].name);
  602.       val = 0;
  603.     }
  604.       else
  605.     {
  606.       val = diff_dirs (inf[0].name, inf[1].name, 
  607.                compare_files, depth, 0, 0);
  608.     }
  609.  
  610.     }
  611.   else if (depth == 0 && (inf[0].dir_p || inf[1].dir_p))
  612.     {
  613.  
  614.       /* If only one is a directory, and it was specified in the command line,
  615.      use the file in that dir whose basename matches the other file.  */
  616.  
  617.       int dir_arg = (inf[0].dir_p ? 0 : 1);
  618.       int fnm_arg = (inf[0].dir_p ? 1 : 0);
  619.       char *p = rindex (inf[fnm_arg].name, '/');
  620.       char *filename = concat (inf[dir_arg].name,  "/",
  621.                    (p ? p+1 : inf[fnm_arg].name));
  622.  
  623.       if (inf[fnm_arg].name == Standard_Input)
  624.     fatal ("can't compare - to a directory");
  625.  
  626.       inf[dir_arg].desc = open (filename, O_RDONLY, 0);
  627.  
  628.       if (0 > inf[dir_arg].desc)
  629.     {
  630.       perror_with_name (filename);
  631.       val = 2;
  632.     }
  633.       else
  634.     {
  635.       /* JF: patch from the net to check and make sure we can really free
  636.          this.  If it's from argv[], freeing it is a *really* bad idea */
  637.       if (0 != (dir_arg ? dir1 : dir0))
  638.         free (inf[dir_arg].name);
  639.       inf[dir_arg].name = filename;
  640.       if (fstat (inf[dir_arg].desc, &inf[dir_arg].stat) < 0)
  641.         pfatal_with_name (inf[dir_arg].name);
  642.  
  643.       inf[dir_arg].dir_p
  644.         = (S_IFDIR == (inf[dir_arg].stat.st_mode & S_IFMT));
  645.       if (inf[dir_arg].dir_p)
  646.         {
  647.           error ("%s is a directory but %s is not",
  648.              inf[dir_arg].name, inf[fnm_arg].name);
  649.           val = 1;
  650.         }
  651.       else
  652.         val = diff_2_files (inf, depth);
  653.     }
  654.  
  655.     }
  656.   else if (depth > 0 && (inf[0].dir_p || inf[1].dir_p))
  657.     {
  658.       /* Perhaps we have a subdirectory that exists only in one directory.
  659.      If so, just print a message to that effect.  */
  660.  
  661.       if (inf[0].desc == -1 || inf[1].desc == -1)
  662.     {
  663.       if (entire_new_file_flag && recursive)
  664.         val = diff_dirs (inf[0].name, inf[1].name, compare_files, depth,
  665.                  inf[0].desc == -1, inf[1].desc == -1);
  666.       else
  667.         {
  668.           char *dir = (inf[0].desc == -1) ? dir1 : dir0;
  669.           message ("Only in %s: %s\n", dir, name0);
  670.           val = 1;
  671.         }
  672.     }
  673.       else
  674.     {
  675.       /* We have a subdirectory in one directory
  676.          and a file in the other.  */
  677.  
  678.       if (inf[0].dir_p)
  679.         message ("%s is a directory but %s is not\n",
  680.              inf[0].name, inf[1].name);
  681.       else
  682.         message ("%s is a directory but %s is not\n",
  683.              inf[1].name, inf[0].name);
  684.       /* This is a difference.  */
  685.       val = 1;
  686.     }
  687.     }
  688.   else
  689.     {
  690.  
  691.       /* Both exist and both are ordinary files.  */
  692.  
  693.       val = diff_2_files (inf, depth);
  694.  
  695.     }
  696.  
  697.   /* Now the comparison has been done, if no error prevented it,
  698.      and VAL is the value this function will return.  */
  699.  
  700.   if (inf[0].desc >= 0)
  701.     close (inf[0].desc);
  702.   if (inf[1].desc >= 0)
  703.     close (inf[1].desc);
  704.  
  705.  done:
  706.   if (val == 0 && !inf[0].dir_p)
  707.     {
  708.       if (print_file_same_flag)
  709.     message ("Files %s and %s are identical\n",
  710.          inf[0].name, inf[1].name);
  711.     }
  712.   else
  713.     fflush (stdout);
  714.  
  715.   if (dir0 != 0)
  716.     free (inf[0].name);
  717.   if (dir1 != 0)
  718.     free (inf[1].name);
  719.  
  720.   return val;
  721. }
  722.