[BACK]Return to pch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / patch

Diff for /src/usr.bin/patch/pch.c between version 1.24 and 1.25

version 1.24, 2003/07/25 02:12:45 version 1.25, 2003/07/28 18:35:36
Line 9 
Line 9 
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #include "EXTERN.h"  
 #include "common.h"  #include "common.h"
 #include "util.h"  #include "util.h"
 #include "INTERN.h"  
 #include "pch.h"  #include "pch.h"
   
 /* Patch (diff listing) abstract type. */  /* Patch (diff listing) abstract type. */
Line 30 
Line 29 
 static LINENUM  p_max;          /* max allowed value of p_end */  static LINENUM  p_max;          /* max allowed value of p_end */
 static LINENUM  p_context = 3;  /* # of context lines */  static LINENUM  p_context = 3;  /* # of context lines */
 static LINENUM  p_input_line = 0;       /* current line # from patch file */  static LINENUM  p_input_line = 0;       /* current line # from patch file */
 static char     **p_line = NULL;        /* the text of the hunk */  static char     **p_line = NULL;/* the text of the hunk */
 static short    *p_len = NULL;  /* length of each line */  static short    *p_len = NULL;  /* length of each line */
 static char     *p_char = NULL;/* +, -, and ! */  static char     *p_char = NULL; /* +, -, and ! */
 static int      hunkmax = INITHUNKMAX;  /* size of above arrays to begin with */  static int      hunkmax = INITHUNKMAX;  /* size of above arrays to begin with */
 static int      p_indent;       /* indent to patch */  static int      p_indent;       /* indent to patch */
 static LINENUM  p_base;         /* where to intuit this time */  static LINENUM  p_base;         /* where to intuit this time */
Line 42 
Line 41 
 static LINENUM  p_hunk_beg;     /* line number of current hunk */  static LINENUM  p_hunk_beg;     /* line number of current hunk */
 static LINENUM  p_efake = -1;   /* end of faked up lines--don't free */  static LINENUM  p_efake = -1;   /* end of faked up lines--don't free */
 static LINENUM  p_bfake = -1;   /* beg of faked up lines */  static LINENUM  p_bfake = -1;   /* beg of faked up lines */
   static FILE     *pfp = NULL;    /* patch file pointer */
   static char     *bestguess = NULL;      /* guess at correct filename */
   
 static void     grow_hunkmax(void);  static void     grow_hunkmax(void);
 static int      intuit_diff_type(void);  static int      intuit_diff_type(void);
 static void     next_intuit_at(long, long);  static void     next_intuit_at(LINENUM, LINENUM);
 static void     skip_to(long, long);  static void     skip_to(LINENUM, LINENUM);
 static char     *pgets(char *, int, FILE *);  static char     *pgets(char *, int, FILE *);
   
   
 /*  /*
  * Prepare to look for the next patch in the patch file.   * Prepare to look for the next patch in the patch file.
  */   */
 void  void
 re_patch(void)  re_patch(void)
 {  {
         p_first = NULL;          p_first = 0;
         p_newfirst = NULL;          p_newfirst = 0;
         p_ptrn_lines = NULL;          p_ptrn_lines = 0;
         p_repl_lines = NULL;          p_repl_lines = 0;
         p_end = (LINENUM) - 1;          p_end = (LINENUM) - 1;
         p_max = NULL;          p_max = 0;
         p_indent = 0;          p_indent = 0;
 }  }
   
Line 68 
Line 70 
  * Open the patch file at the beginning of time.   * Open the patch file at the beginning of time.
  */   */
 void  void
 open_patch_file(char *filename)  open_patch_file(const char *filename)
 {  {
         if (filename == NULL || !*filename || strEQ(filename, "-")) {          struct stat filestat;
   
           if (filename == NULL || *filename == '\0' || strEQ(filename, "-")) {
                 pfp = fopen(TMPPATNAME, "w");                  pfp = fopen(TMPPATNAME, "w");
                 if (pfp == NULL)                  if (pfp == NULL)
                         pfatal("can't create %s", TMPPATNAME);                          pfatal("can't create %s", TMPPATNAME);
Line 115 
Line 119 
          * since p_len can move into p_line's old space, and p_char can move into           * since p_len can move into p_line's old space, and p_char can move into
          * p_len's old space.  Not on PDP-11's however.  But it doesn't matter.           * p_len's old space.  Not on PDP-11's however.  But it doesn't matter.
          */           */
         assert(p_line != NULL &&p_len != NULL &&p_char != NULL);          assert(p_line != NULL && p_len != NULL && p_char != NULL);
   
         p_line = realloc(p_line, hunkmax * sizeof(char *));          p_line = realloc(p_line, hunkmax * sizeof(char *));
         p_len = realloc(p_len, hunkmax * sizeof(short));          p_len = realloc(p_len, hunkmax * sizeof(short));
         p_char = realloc(p_char, hunkmax * sizeof(char));          p_char = realloc(p_char, hunkmax * sizeof(char));
   
         if (p_line != NULL &&p_len != NULL &&p_char != NULL)          if (p_line != NULL && p_len != NULL && p_char != NULL)
                 return;                  return;
         if (!using_plan_a)          if (!using_plan_a)
                 fatal("out of memory\n");                  fatal("out of memory\n");
Line 171 
Line 175 
                 }                  }
                 ask("File to patch: ");                  ask("File to patch: ");
                 if (*buf != '\n') {                  if (*buf != '\n') {
                         if (bestguess)                          free(bestguess);
                                 free(bestguess);  
                         bestguess = savestr(buf);                          bestguess = savestr(buf);
                         filearg[0] = fetchname(buf, 0, FALSE);                          filearg[0] = fetchname(buf, 0, FALSE);
                 }                  }
Line 264 
Line 267 
                         for (t = revision; *t && !isspace(*t); t++)                          for (t = revision; *t && !isspace(*t); t++)
                                 ;                                  ;
                         *t = '\0';                          *t = '\0';
                         if (!*revision) {                          if (*revision == '\0') {
                                 free(revision);                                  free(revision);
                                 revision = NULL;                                  revision = NULL;
                         }                          }
Line 335 
Line 338 
                 else if (newname)                  else if (newname)
                         filearg[0] = savestr(newname);                          filearg[0] = savestr(newname);
         }          }
         if (bestguess) {  
                 free(bestguess);          free(bestguess);
                 bestguess = NULL;          bestguess = NULL;
         }  
         if (filearg[0] != NULL)          if (filearg[0] != NULL)
                 bestguess = savestr(filearg[0]);                  bestguess = savestr(filearg[0]);
         else if (indtmp != NULL)          else if (indtmp != NULL)
Line 371 
Line 374 
  * Remember where this patch ends so we know where to start up again.   * Remember where this patch ends so we know where to start up again.
  */   */
 static void  static void
 next_intuit_at(long file_pos, long file_line)  next_intuit_at(LINENUM file_pos, LINENUM file_line)
 {  {
         p_base = file_pos;          p_base = file_pos;
         p_bline = file_line;          p_bline = file_line;
Line 381 
Line 384 
  * Basically a verbose fseek() to the actual diff listing.   * Basically a verbose fseek() to the actual diff listing.
  */   */
 static void  static void
 skip_to(long file_pos, long file_line)  skip_to(LINENUM file_pos, LINENUM file_line)
 {  {
         char    *ret;          char    *ret;
   

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25