home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / DiffUtils.sit.hqx / DiffUtils / src / util.c < prev    next >
Text File  |  1993-11-15  |  19KB  |  781 lines

  1. /* Support routines for GNU DIFF.
  2.    Copyright (C) 1988, 1989, 1992, 1993 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 2, 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. #include "diff.h"
  21.  
  22. #ifdef macintosh
  23. /* I don't like the current Apple perror. Sorry. */
  24.  
  25. void perror(const char * msg)
  26. {
  27.     int cur_errno = errno;
  28.     
  29.     if (msg)
  30.         fprintf(stderr, "%s: %s\n", msg, strerror(cur_errno));
  31.     else
  32.         fprintf(stderr, "%s\n", strerror(cur_errno));
  33.   
  34.     errno = cur_errno;
  35. }
  36. #endif
  37.  
  38. /* Queue up one-line messages to be printed at the end,
  39.    when -l is specified.  Each message is recorded with a `struct msg'.  */
  40.  
  41. struct msg
  42. {
  43.   struct msg *next;
  44.   char const *format;
  45.   char const *arg1;
  46.   char const *arg2;
  47.   char const *arg3;
  48.   char const *arg4;
  49. };
  50.  
  51. /* Head of the chain of queues messages.  */
  52.  
  53. static struct msg *msg_chain;
  54.  
  55. /* Tail of the chain of queues messages.  */
  56.  
  57. static struct msg **msg_chain_end = &msg_chain;
  58.  
  59. /* Use when a system call returns non-zero status.
  60.    TEXT should normally be the file name.  */
  61.  
  62. void
  63. perror_with_name (text)
  64.      char const *text;
  65. {
  66.   int e = errno;
  67.   fprintf (stderr, "%s: ", program);
  68.   errno = e;
  69.   perror (text);
  70. }
  71.  
  72. /* Use when a system call returns non-zero status and that is fatal.  */
  73.  
  74. void
  75. pfatal_with_name (text)
  76.      char const *text;
  77. {
  78.   int e = errno;
  79.   print_message_queue ();
  80.   fprintf (stderr, "%s: ", program);
  81.   errno = e;
  82.   perror (text);
  83.   exit (2);
  84. }
  85.  
  86. /* Print an error message from the format-string FORMAT
  87.    with args ARG1 and ARG2.  */
  88.  
  89. void
  90. error (format, arg, arg1)
  91.      char const *format, *arg, *arg1;
  92. {
  93.   fprintf (stderr, "%s: ", program);
  94.   fprintf (stderr, format, arg, arg1);
  95.   fprintf (stderr, "\n");
  96. }
  97.  
  98. /* Print an error message containing the string TEXT, then exit.  */
  99.  
  100. void
  101. fatal (m)
  102.      char const *m;
  103. {
  104.   print_message_queue ();
  105.   error ("%s", m, 0);
  106.   exit (2);
  107. }
  108.  
  109. /* Like printf, except if -l in effect then save the message and print later.
  110.    This is used for things like "binary files differ" and "Only in ...".  */
  111.  
  112. void
  113. message (format, arg1, arg2)
  114.      char const *format, *arg1, *arg2;
  115. {
  116.   message5 (format, arg1, arg2, 0, 0);
  117. }
  118.  
  119. void
  120. message5 (format, arg1, arg2, arg3, arg4)
  121.      char const *format, *arg1, *arg2, *arg3, *arg4;
  122. {
  123.   if (paginate_flag)
  124.     {
  125.       struct msg *new = (struct msg *) xmalloc (sizeof (struct msg));
  126.       new->format = format;
  127.       new->arg1 = concat (arg1, "", "");
  128.       new->arg2 = concat (arg2, "", "");
  129.       new->arg3 = arg3 ? concat (arg3, "", "") : 0;
  130.       new->arg4 = arg4 ? concat (arg4, "", "") : 0;
  131.       new->next = 0;
  132.       *msg_chain_end = new;
  133.       msg_chain_end = &new->next;
  134.     }
  135.   else
  136.     {
  137.       if (sdiff_help_sdiff)
  138.     putchar (' ');
  139.       printf (format, arg1, arg2, arg3, arg4);
  140.     }
  141. }
  142.  
  143. /* Output all the messages that were saved up by calls to `message'.  */
  144.  
  145. void
  146. print_message_queue ()
  147. {
  148.   struct msg *m;
  149.  
  150.   for (m = msg_chain; m; m = m->next)
  151.     printf (m->format, m->arg1, m->arg2, m->arg3, m->arg4);
  152. }
  153.  
  154. /* Call before outputting the results of comparing files NAME0 and NAME1
  155.    to set up OUTFILE, the stdio stream for the output to go to.
  156.  
  157.    Usually, OUTFILE is just stdout.  But when -l was specified
  158.    we fork off a `pr' and make OUTFILE a pipe to it.
  159.    `pr' then outputs to our stdout.  */
  160.  
  161. static char const *current_name0;
  162. static char const *current_name1;
  163. static int current_depth;
  164.  
  165. void
  166. setup_output (name0, name1, depth)
  167.      char const *name0, *name1;
  168.      int depth;
  169. {
  170.   current_name0 = name0;
  171.   current_name1 = name1;
  172.   current_depth = depth;
  173.   outfile = 0;
  174. }
  175.  
  176. static pid_t pr_pid;
  177.  
  178. void
  179. begin_output ()
  180. {
  181.   char *name;
  182.  
  183.   if (outfile != 0)
  184.     return;
  185.  
  186.   /* Construct the header of this piece of diff.  */
  187.   name = xmalloc (strlen (current_name0) + strlen (current_name1)
  188.           + strlen (switch_string) + 7);
  189.   /* Posix.2 section 4.17.6.1.1 specifies this format.  But there are some
  190.      bugs in the first printing (IEEE Std 1003.2-1992 p 251 l 3304):
  191.      it says that we must print only the last component of the pathnames,
  192.      and it requires two spaces after "diff" if there are no options.
  193.      These requirements are silly and do not match historical practice.  */
  194.   sprintf (name, "diff%s %s %s", switch_string, current_name0, current_name1);
  195.  
  196. #ifndef macintosh
  197.   if (paginate_flag)
  198.     {
  199.       int pipes[2];
  200.       int desc;
  201.  
  202.       /* Fork a `pr' and make OUTFILE a pipe to it.  */
  203.       if (pipe (pipes) < 0)
  204.     pfatal_with_name ("pipe");
  205.  
  206.       fflush (stdout);
  207.  
  208.       pr_pid = vfork ();
  209.       if (pr_pid < 0)
  210.     pfatal_with_name ("vfork");
  211.  
  212.       if (pr_pid == 0)
  213.     {
  214.       close (pipes[1]);
  215.       if (pipes[0] != STDIN_FILENO)
  216.         {
  217.           if (dup2 (pipes[0], STDIN_FILENO) < 0)
  218.         pfatal_with_name ("dup2");
  219.           close (pipes[0]);
  220.         }
  221.  
  222.       execl (PR_FILE_NAME, PR_FILE_NAME, "-f", "-h", name, 0);
  223.       pfatal_with_name (PR_FILE_NAME);
  224.     }
  225.       else
  226.     {
  227.       close (pipes[0]);
  228.       outfile = fdopen (pipes[1], "w");
  229.     } 
  230.     }
  231.   else
  232. #endif
  233.     {
  234.  
  235.       /* If -l was not specified, output the diff straight to `stdout'.  */
  236.  
  237.       outfile = stdout;
  238.  
  239.       /* If handling multiple files (because scanning a directory),
  240.      print which files the following output is about.  */
  241.       if (current_depth > 0)
  242.     printf ("%s\n", name);
  243.     }
  244.  
  245.   free (name);
  246.  
  247.   /* A special header is needed at the beginning of context output.  */
  248.   switch (output_style)
  249.     {
  250.     case OUTPUT_CONTEXT:
  251.       print_context_header (files, 0);
  252.       break;
  253.  
  254.     case OUTPUT_UNIFIED:
  255.       print_context_header (files, 1);
  256.       break;
  257.  
  258.     default:
  259.       break;
  260.     }
  261. }
  262.  
  263. /* Call after the end of output of diffs for one file.
  264.    Close OUTFILE and get rid of the `pr' subfork.  */
  265.  
  266. void
  267. finish_output ()
  268. {
  269. #ifndef macintosh
  270.   if (outfile != 0 && outfile != stdout)
  271.     {
  272.       int wstatus;
  273.       if (ferror (outfile))
  274.     fatal ("write error");
  275.       if (fclose (outfile) != 0)
  276.     pfatal_with_name ("write error");
  277. #if HAVE_WAITPID
  278.       if (waitpid (pr_pid, &wstatus, 0) < 0)
  279.     pfatal_with_name ("waitpid");
  280. #else
  281.       for (;;) {
  282.     pid_t w = wait (&wstatus);
  283.     if (w < 0)
  284.       pfatal_with_name ("wait");
  285.     if (w == pr_pid)
  286.       break;
  287.       }
  288. #endif
  289.       if (! WIFEXITED (wstatus) || WEXITSTATUS (wstatus) != 0)
  290.     fatal ("subsidiary pr failed");
  291.     }
  292. #endif
  293.  
  294.   outfile = 0;
  295. }
  296.  
  297. /* Compare two lines (typically one from each input file)
  298.    according to the command line options.
  299.    Return 1 if the lines differ, like `memcmp'.  */
  300.  
  301. int
  302. line_cmp (s1, len1, s2, len2)
  303.      char const *s1, *s2;
  304.      size_t len1, len2;
  305. {
  306.   register unsigned char const *t1, *t2;
  307.   register unsigned char end_char = line_end_char;
  308.  
  309.   /* Check first for exact identity.
  310.      If that is true, return 0 immediately.
  311.      This detects the common case of exact identity
  312.      faster than complete comparison would.  */
  313.  
  314.   if (len1 == len2 && memcmp (s1, s2, len1) == 0)
  315.     return 0;
  316.  
  317.   /* Not exactly identical, but perhaps they match anyway
  318.      when case or white space is ignored.  */
  319.  
  320.   if (ignore_case_flag | ignore_space_change_flag | ignore_all_space_flag)
  321.     {
  322.       t1 = (unsigned char const *) s1;
  323.       t2 = (unsigned char const *) s2;
  324.  
  325.       while (1)
  326.     {
  327.       register unsigned char c1 = *t1++;
  328.       register unsigned char c2 = *t2++;
  329.  
  330.       /* Ignore horizontal white space if -b or -w is specified.  */
  331.  
  332.       if (ignore_all_space_flag)
  333.         {
  334.           /* For -w, just skip past any white space.  */
  335.           while (isspace (c1) && c1 != end_char) c1 = *t1++;
  336.           while (isspace (c2) && c2 != end_char) c2 = *t2++;
  337.         }
  338.       else if (ignore_space_change_flag)
  339.         {
  340.           /* For -b, advance past any sequence of white space in line 1
  341.          and consider it just one Space, or nothing at all
  342.          if it is at the end of the line.  */
  343.           if (isspace (c1))
  344.         {
  345.           while (c1 != end_char)
  346.             {
  347.               c1 = *t1++;
  348.               if (! isspace (c1))
  349.             {
  350.               --t1;
  351.               c1 = ' ';
  352.               break;
  353.             }
  354.             }
  355.         }
  356.  
  357.           /* Likewise for line 2.  */
  358.           if (isspace (c2))
  359.         {
  360.           while (c2 != end_char)
  361.             {
  362.               c2 = *t2++;
  363.               if (! isspace (c2))
  364.             {
  365.               --t2;
  366.               c2 = ' ';
  367.               break;
  368.             }
  369.             }
  370.         }
  371.         }
  372.  
  373.       /* Upcase all letters if -i is specified.  */
  374.  
  375.       if (ignore_case_flag)
  376.         {
  377.           if (islower (c1))
  378.         c1 = toupper (c1);
  379.           if (islower (c2))
  380.         c2 = toupper (c2);
  381.         }
  382.  
  383.       if (c1 != c2)
  384.         break;
  385.       if (c1 == end_char)
  386.         return 0;
  387.     }
  388.     }
  389.  
  390.   return (1);
  391. }
  392.  
  393. /* Find the consecutive changes at the start of the script START.
  394.    Return the last link before the first gap.  */
  395.  
  396. struct change *
  397. find_change (start)
  398.      struct change *start;
  399. {
  400.   return start;
  401. }
  402.  
  403. struct change *
  404. find_reverse_change (start)
  405.      struct change *start;
  406. {
  407.   return start;
  408. }
  409.  
  410. /* Divide SCRIPT into pieces by calling HUNKFUN and
  411.    print each piece with PRINTFUN.
  412.    Both functions take one arg, an edit script.
  413.  
  414.    HUNKFUN is called with the tail of the script
  415.    and returns the last link that belongs together with the start
  416.    of the tail.
  417.  
  418.    PRINTFUN takes a subscript which belongs together (with a null
  419.    link at the end) and prints it.  */
  420.  
  421. void
  422. print_script (script, hunkfun, printfun)
  423.      struct change *script;
  424.      struct change * (*hunkfun) PARAMS((struct change *));
  425.      void (*printfun) PARAMS((struct change *));
  426. {
  427.   struct change *next = script;
  428.  
  429.   while (next)
  430.     {
  431.       struct change *this, *end;
  432.  
  433.       /* Find a set of changes that belong together.  */
  434.       this = next;
  435.       end = (*hunkfun) (next);
  436.  
  437.       /* Disconnect them from the rest of the changes,
  438.      making them a hunk, and remember the rest for next iteration.  */
  439.       next = end->link;
  440.       end->link = 0;
  441. #ifdef DEBUG
  442.       debug_script (this);
  443. #endif
  444.  
  445.       /* Print this hunk.  */
  446.       (*printfun) (this);
  447.  
  448.       /* Reconnect the script so it will all be freed properly.  */
  449.       end->link = next;
  450.     }
  451. }
  452.  
  453. /* Print the text of a single line LINE,
  454.    flagging it with the characters in LINE_FLAG (which say whether
  455.    the line is inserted, deleted, changed, etc.).  */
  456.  
  457. void
  458. print_1_line (line_flag, line)
  459.      char const *line_flag;
  460.      char const * const *line;
  461. {
  462.   char const *text = line[0], *limit = line[1]; /* Help the compiler.  */
  463.   FILE *out = outfile; /* Help the compiler some more.  */
  464.   char const *flag_format = 0;
  465.  
  466.   /* If -T was specified, use a Tab between the line-flag and the text.
  467.      Otherwise use a Space (as Unix diff does).
  468.      Print neither space nor tab if line-flags are empty.  */
  469.  
  470.   if (line_flag && *line_flag)
  471.     {
  472.       flag_format = tab_align_flag ? "%s\t" : "%s ";
  473.       fprintf (out, flag_format, line_flag);
  474.     }
  475.  
  476.   output_1_line (text, limit, flag_format, line_flag);
  477.  
  478.   if ((!line_flag || line_flag[0]) && limit[-1] != '\n'
  479.       && line_end_char == '\n')
  480.     fprintf (out, "\n\\ No newline at end of file\n");
  481. }
  482.  
  483. /* Output a line from TEXT up to LIMIT.  Without -t, output verbatim.
  484.    With -t, expand white space characters to spaces, and if FLAG_FORMAT
  485.    is nonzero, output it with argument LINE_FLAG after every
  486.    internal carriage return, so that tab stops continue to line up.  */
  487.  
  488. void
  489. output_1_line (text, limit, flag_format, line_flag)
  490.      char const *text, *limit, *flag_format, *line_flag;
  491. {
  492.   if (!tab_expand_flag)
  493.     fwrite (text, sizeof (char), limit - text, outfile);
  494.   else
  495.     {
  496.       register FILE *out = outfile;
  497.       register unsigned char c;
  498.       register char const *t = text;
  499.       register unsigned column = 0;
  500.  
  501.       while (t < limit)
  502.     switch ((c = *t++))
  503.       {
  504.       case '\t':
  505.         {
  506.           unsigned spaces = TAB_WIDTH - column % TAB_WIDTH;
  507.           column += spaces;
  508.           do
  509.         putc (' ', out);
  510.           while (--spaces);
  511.         }
  512.         break;
  513.  
  514.       case '\r':
  515.         putc (c, out);
  516.         if (flag_format && t < limit && *t != '\n')
  517.           fprintf (out, flag_format, line_flag);
  518.         column = 0;
  519.         break;
  520.  
  521.       case '\b':
  522.         if (column == 0)
  523.           continue;
  524.         column--;
  525.         putc (c, out);
  526.         break;
  527.  
  528.       default:
  529.         if (isprint (c))
  530.           column++;
  531.         putc (c, out);
  532.         break;
  533.       }
  534.     }
  535. }
  536.  
  537. int
  538. change_letter (inserts, deletes)
  539.      int inserts, deletes;
  540. {
  541.   if (!inserts)
  542.     return 'd';
  543.   else if (!deletes)
  544.     return 'a';
  545.   else
  546.     return 'c';
  547. }
  548.  
  549. /* Translate an internal line number (an index into diff's table of lines)
  550.    into an actual line number in the input file.
  551.    The internal line number is LNUM.  FILE points to the data on the file.
  552.  
  553.    Internal line numbers count from 0 starting after the prefix.
  554.    Actual line numbers count from 1 within the entire file.  */
  555.  
  556. int
  557. translate_line_number (file, lnum)
  558.      struct file_data const *file;
  559.      int lnum;
  560. {
  561.   return lnum + file->prefix_lines + 1;
  562. }
  563.  
  564. void
  565. translate_range (file, a, b, aptr, bptr)
  566.      struct file_data const *file;
  567.      int a, b;
  568.      int *aptr, *bptr;
  569. {
  570.   *aptr = translate_line_number (file, a - 1) + 1;
  571.   *bptr = translate_line_number (file, b + 1) - 1;
  572. }
  573.  
  574. /* Print a pair of line numbers with SEPCHAR, translated for file FILE.
  575.    If the two numbers are identical, print just one number.
  576.  
  577.    Args A and B are internal line numbers.
  578.    We print the translated (real) line numbers.  */
  579.  
  580. void
  581. print_number_range (sepchar, file, a, b)
  582.      char sepchar;
  583.      struct file_data *file;
  584.      int a, b;
  585. {
  586.   int trans_a, trans_b;
  587.   translate_range (file, a, b, &trans_a, &trans_b);
  588.  
  589.   /* Note: we can have B < A in the case of a range of no lines.
  590.      In this case, we should print the line number before the range,
  591.      which is B.  */
  592.   if (trans_b > trans_a)
  593.     fprintf (outfile, "%d%c%d", trans_a, sepchar, trans_b);
  594.   else
  595.     fprintf (outfile, "%d", trans_b);
  596. }
  597.  
  598. /* Look at a hunk of edit script and report the range of lines in each file
  599.    that it applies to.  HUNK is the start of the hunk, which is a chain
  600.    of `struct change'.  The first and last line numbers of file 0 are stored in
  601.    *FIRST0 and *LAST0, and likewise for file 1 in *FIRST1 and *LAST1.
  602.    Note that these are internal line numbers that count from 0.
  603.  
  604.    If no lines from file 0 are deleted, then FIRST0 is LAST0+1.
  605.  
  606.    Also set *DELETES nonzero if any lines of file 0 are deleted
  607.    and set *INSERTS nonzero if any lines of file 1 are inserted.
  608.    If only ignorable lines are inserted or deleted, both are
  609.    set to 0.  */
  610.  
  611. void
  612. analyze_hunk (hunk, first0, last0, first1, last1, deletes, inserts)
  613.      struct change *hunk;
  614.      int *first0, *last0, *first1, *last1;
  615.      int *deletes, *inserts;
  616. {
  617.   int l0, l1, show_from, show_to;
  618.   int i;
  619.   int trivial = ignore_blank_lines_flag || ignore_regexp_list;
  620.   struct change *next;
  621.  
  622.   show_from = show_to = 0;
  623.  
  624.   *first0 = hunk->line0;
  625.   *first1 = hunk->line1;
  626.  
  627.   next = hunk;
  628.   do
  629.     {
  630.       l0 = next->line0 + next->deleted - 1;
  631.       l1 = next->line1 + next->inserted - 1;
  632.       show_from += next->deleted;
  633.       show_to += next->inserted;
  634.  
  635.       for (i = next->line0; i <= l0 && trivial; i++)
  636.     if (!ignore_blank_lines_flag || files[0].linbuf[i][0] != '\n')
  637.       {
  638.         struct regexp_list *r;
  639.         char const *line = files[0].linbuf[i];
  640.         int len = files[0].linbuf[i + 1] - line;
  641.  
  642.         for (r = ignore_regexp_list; r; r = r->next)
  643.           if (0 <= re_search (&r->buf, line, len, 0, len, 0))
  644.         break;    /* Found a match.  Ignore this line.  */
  645.         /* If we got all the way through the regexp list without
  646.            finding a match, then it's nontrivial.  */
  647.         if (!r)
  648.           trivial = 0;
  649.       }
  650.  
  651.       for (i = next->line1; i <= l1 && trivial; i++)
  652.     if (!ignore_blank_lines_flag || files[1].linbuf[i][0] != '\n')
  653.       {
  654.         struct regexp_list *r;
  655.         char const *line = files[1].linbuf[i];
  656.         int len = files[1].linbuf[i + 1] - line;
  657.  
  658.         for (r = ignore_regexp_list; r; r = r->next)
  659.           if (0 <= re_search (&r->buf, line, len, 0, len, 0))
  660.         break;    /* Found a match.  Ignore this line.  */
  661.         /* If we got all the way through the regexp list without
  662.            finding a match, then it's nontrivial.  */
  663.         if (!r)
  664.           trivial = 0;
  665.       }
  666.     }
  667.   while ((next = next->link) != 0);
  668.  
  669.   *last0 = l0;
  670.   *last1 = l1;
  671.  
  672.   /* If all inserted or deleted lines are ignorable,
  673.      tell the caller to ignore this hunk.  */
  674.  
  675.   if (trivial)
  676.     show_from = show_to = 0;
  677.  
  678.   *deletes = show_from;
  679.   *inserts = show_to;
  680. }
  681.  
  682. /* malloc a block of memory, with fatal error message if we can't do it. */
  683.  
  684. VOID *
  685. xmalloc (size)
  686.      size_t size;
  687. {
  688.   register VOID *value;
  689.  
  690.   if (size == 0)
  691.     size = 1;
  692.  
  693.   value = (VOID *) malloc (size);
  694.  
  695.   if (!value)
  696.     fatal ("memory exhausted");
  697.   return value;
  698. }
  699.  
  700. /* realloc a block of memory, with fatal error message if we can't do it. */
  701.  
  702. VOID *
  703. xrealloc (old, size)
  704.      VOID *old;
  705.      size_t size;
  706. {
  707.   register VOID *value;
  708.  
  709.   if (size == 0)
  710.     size = 1;
  711.  
  712.   value = (VOID *) realloc (old, size);
  713.  
  714.   if (!value)
  715.     fatal ("memory exhausted");
  716.   return value;
  717. }
  718.  
  719. /* Concatenate three strings, returning a newly malloc'd string.  */
  720.  
  721. char *
  722. concat (s1, s2, s3)
  723.      char const *s1, *s2, *s3;
  724. {
  725.   size_t len = strlen (s1) + strlen (s2) + strlen (s3);
  726.   char *new = xmalloc (len + 1);
  727.   sprintf (new, "%s%s%s", s1, s2, s3);
  728.   return new;
  729. }
  730.  
  731. /* Yield the newly malloc'd pathname
  732.    of the file in DIR whose filename is FILE.  */
  733.  
  734. char *
  735. dir_file_pathname (dir, file)
  736.      char const *dir, *file;
  737. {
  738. #ifndef macintosh
  739.   return concat (dir, "/" + (*dir && dir[strlen (dir) - 1] == '/'), file);
  740. #else
  741.   char * lastcolon;
  742.   char * tmpstr;
  743.   
  744.   if (lastcolon = strrchr(dir, DIRSEPCH))
  745.     return concat (dir, DIRSEPSTR + !lastcolon[1], file);
  746.   
  747.   tmpstr    = concat (DIRSEPSTR, dir, "");
  748.   lastcolon = concat (tmpstr, DIRSEPSTR, file);
  749.   
  750.   free(tmpstr);
  751.   
  752.   return lastcolon;
  753. #endif
  754. }
  755.  
  756. void
  757. debug_script (sp)
  758.      struct change *sp;
  759. {
  760.   fflush (stdout);
  761.   for (; sp; sp = sp->link)
  762.     fprintf (stderr, "%3d %3d delete %d insert %d\n",
  763.          sp->line0, sp->line1, sp->deleted, sp->inserted);
  764.   fflush (stderr);
  765. }
  766.  
  767. #if !HAVE_MEMCHR
  768. char *
  769. memchr (s, c, n)
  770.      char const *s;
  771.      int c;
  772.      size_t n;
  773. {
  774.   unsigned char const *p = (unsigned char const *) s, *lim = p + n;
  775.   for (;  p < lim;  p++)
  776.     if (*p == c)
  777.       return (char *) p;
  778.   return 0;
  779. }
  780. #endif
  781.