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

Diff for /src/usr.bin/patch/patch.c between version 1.36 and 1.37

version 1.36, 2003/08/10 18:39:43 version 1.37, 2003/08/10 21:28:48
Line 68 
Line 68 
 bool            toutkeep = false;  bool            toutkeep = false;
 bool            trejkeep = false;  bool            trejkeep = false;
 bool            warn_on_invalid_line;  bool            warn_on_invalid_line;
   bool            last_line_missing_eol;
   
 #ifdef DEBUGGING  #ifdef DEBUGGING
 int             debug = 0;  int             debug = 0;
Line 93 
Line 94 
 static void     apply_hunk(LINENUM);  static void     apply_hunk(LINENUM);
 static void     init_output(const char *);  static void     init_output(const char *);
 static void     init_reject(const char *);  static void     init_reject(const char *);
 static void     copy_till(LINENUM);  static void     copy_till(LINENUM, bool);
 static void     spew_output(void);  static void     spew_output(void);
 static void     dump_line(LINENUM);  static void     dump_line(LINENUM, bool);
 static bool     patch_match(LINENUM, LINENUM, LINENUM);  static bool     patch_match(LINENUM, LINENUM, LINENUM);
 static bool     similar(const char *, const char *, int);  static bool     similar(const char *, const char *, int);
 static __dead void usage(void);  static __dead void usage(void);
Line 732 
Line 733 
   
         while (old <= lastline) {          while (old <= lastline) {
                 if (pch_char(old) == '-') {                  if (pch_char(old) == '-') {
                         copy_till(where + old - 1);                          copy_till(where + old - 1, false);
                         if (do_defines) {                          if (do_defines) {
                                 if (def_state == OUTSIDE) {                                  if (def_state == OUTSIDE) {
                                         fputs(not_defined, ofp);                                          fputs(not_defined, ofp);
Line 748 
Line 749 
                 } else if (new > pat_end) {                  } else if (new > pat_end) {
                         break;                          break;
                 } else if (pch_char(new) == '+') {                  } else if (pch_char(new) == '+') {
                         copy_till(where + old - 1);                          copy_till(where + old - 1, false);
                         if (do_defines) {                          if (do_defines) {
                                 if (def_state == IN_IFNDEF) {                                  if (def_state == IN_IFNDEF) {
                                         fputs(else_defined, ofp);                                          fputs(else_defined, ofp);
Line 770 
Line 771 
 #endif  #endif
                         my_exit(2);                          my_exit(2);
                 } else if (pch_char(new) == '!') {                  } else if (pch_char(new) == '!') {
                         copy_till(where + old - 1);                          copy_till(where + old - 1, false);
                         if (do_defines) {                          if (do_defines) {
                                 fputs(not_defined, ofp);                                  fputs(not_defined, ofp);
                                 def_state = IN_IFNDEF;                                  def_state = IN_IFNDEF;
Line 802 
Line 803 
                 }                  }
         }          }
         if (new <= pat_end && pch_char(new) == '+') {          if (new <= pat_end && pch_char(new) == '+') {
                 copy_till(where + old - 1);                  copy_till(where + old - 1, false);
                 if (do_defines) {                  if (do_defines) {
                         if (def_state == OUTSIDE) {                          if (def_state == OUTSIDE) {
                                 fputs(if_defined, ofp);                                  fputs(if_defined, ofp);
Line 846 
Line 847 
   
 /*  /*
  * Copy input file to output, up to wherever hunk is to be applied.   * Copy input file to output, up to wherever hunk is to be applied.
    * If endoffile is true, treat the last line specially since it may
    * lack a newline.
  */   */
 static void  static void
 copy_till(LINENUM lastline)  copy_till(LINENUM lastline, bool endoffile)
 {  {
         if (last_frozen_line > lastline)          if (last_frozen_line > lastline)
                 fatal("misordered hunks! output would be garbled\n");                  fatal("misordered hunks! output would be garbled\n");
         while (last_frozen_line < lastline)          while (last_frozen_line < lastline) {
                 dump_line(++last_frozen_line);                  if (++last_frozen_line == lastline && endoffile)
                           dump_line(last_frozen_line, !last_line_missing_eol);
                   else
                           dump_line(last_frozen_line, true);
           }
 }  }
   
 /*  /*
Line 867 
Line 874 
                 say("il=%ld lfl=%ld\n", input_lines, last_frozen_line);                  say("il=%ld lfl=%ld\n", input_lines, last_frozen_line);
 #endif  #endif
         if (input_lines)          if (input_lines)
                 copy_till(input_lines); /* dump remainder of file */                  copy_till(input_lines, true);   /* dump remainder of file */
         fclose(ofp);          fclose(ofp);
         ofp = NULL;          ofp = NULL;
 }  }
Line 876 
Line 883 
  * Copy one line from input to output.   * Copy one line from input to output.
  */   */
 static void  static void
 dump_line(LINENUM line)  dump_line(LINENUM line, bool write_newline)
 {  {
         char    *s;          char    *s;
   
Line 884 
Line 891 
         if (s == NULL)          if (s == NULL)
                 return;                  return;
         /* Note: string is not NUL terminated. */          /* Note: string is not NUL terminated. */
         for (; putc(*s, ofp) != '\n'; s++)          for (; *s != '\n'; s++)
                 ;                  putc(*s, ofp);
           if (write_newline)
                   putc('\n', ofp);
 }  }
   
 /*  /*

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.37