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

Diff for /src/usr.bin/mg/file.c between version 1.31 and 1.32

version 1.31, 2005/03/10 18:27:47 version 1.32, 2005/04/03 02:09:28
Line 19 
Line 19 
   
         bufp = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);          bufp = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
         if (bufp == NULL)          if (bufp == NULL)
                 return ABORT;                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return FALSE;                  return (FALSE);
         adjf = adjustname(bufp);          adjf = adjustname(bufp);
         if (adjf == NULL)          if (adjf == NULL)
                 return (FALSE);                  return (FALSE);
         return insertfile(adjf, NULL, FALSE);          return (insertfile(adjf, NULL, FALSE));
 }  }
   
 /*  /*
Line 43 
Line 43 
   
         bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);          bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
         if (bufp == NULL)          if (bufp == NULL)
                 return ABORT;                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return FALSE;                  return (FALSE);
         adjf = adjustname(fname);          adjf = adjustname(fname);
         if (adjf == NULL)          if (adjf == NULL)
                 return (FALSE);                  return (FALSE);
         if ((bp = findbuffer(adjf)) == NULL)          if ((bp = findbuffer(adjf)) == NULL)
                 return FALSE;                  return (FALSE);
         curbp = bp;          curbp = bp;
         if (showbuffer(bp, curwp, WFHARD) != TRUE)          if (showbuffer(bp, curwp, WFHARD) != TRUE)
                 return FALSE;                  return (FALSE);
         if (bp->b_fname[0] == 0) {          if (bp->b_fname[0] == 0) {
                 int status;                  int status;
   
                 if ((status = readin(adjf)) != TRUE)                  if ((status = readin(adjf)) != TRUE)
                         killbuffer(bp);                          killbuffer(bp);
                 return status;                  return (status);
         }          }
         return TRUE;          return (TRUE);
 }  }
   
 int  int
Line 75 
Line 75 
         curbp->b_flag |= BFREADONLY;          curbp->b_flag |= BFREADONLY;
         return (TRUE);          return (TRUE);
 }  }
   
 /*  /*
  * Pop to a file in the other window.  Same as the last function, but uses   * Pop to a file in the other window.  Same as the last function, but uses
  * popbuf instead of showbuffer.   * popbuf instead of showbuffer.
Line 89 
Line 90 
   
         if ((bufp = eread("Find file in other window: ", fname, NFILEN,          if ((bufp = eread("Find file in other window: ", fname, NFILEN,
             EFNEW | EFCR | EFFILE)) == NULL)              EFNEW | EFCR | EFFILE)) == NULL)
                 return ABORT;                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return FALSE;                  return (FALSE);
         adjf = adjustname(fname);          adjf = adjustname(fname);
         if (adjf == NULL)          if (adjf == NULL)
                 return (FALSE);                  return (FALSE);
         if ((bp = findbuffer(adjf)) == NULL)          if ((bp = findbuffer(adjf)) == NULL)
                 return FALSE;                  return (FALSE);
         if ((wp = popbuf(bp)) == NULL)          if ((wp = popbuf(bp)) == NULL)
                 return FALSE;                  return (FALSE);
         curbp = bp;          curbp = bp;
         curwp = wp;          curwp = wp;
         if (bp->b_fname[0] == 0) {          if (bp->b_fname[0] == 0) {
Line 106 
Line 107 
   
                 if ((status = readin(adjf)) != TRUE)                  if ((status = readin(adjf)) != TRUE)
                         killbuffer(bp);                          killbuffer(bp);
                 return status;                  return (status);
         }          }
         return TRUE;          return (TRUE);
 }  }
   
 /*  /*
  * given a file name, either find the buffer it uses, or create a new   * Given a file name, either find the buffer it uses, or create a new
  * empty buffer to put it in.   * empty buffer to put it in.
  */   */
 BUFFER *  BUFFER *
Line 124 
Line 125 
   
         for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {          for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
                 if (strcmp(bp->b_fname, fname) == 0)                  if (strcmp(bp->b_fname, fname) == 0)
                         return bp;                          return (bp);
         }          }
         i = strlcpy(bname, basename(fname), sizeof(bname));          i = strlcpy(bname, basename(fname), sizeof(bname));
         remain = sizeof(bname) - i;          remain = sizeof(bname) - i;
         for (count = 2; bfind(bname, FALSE) != NULL; count++)          for (count = 2; bfind(bname, FALSE) != NULL; count++)
                 snprintf(&bname[i], remain, "<%d>", count);                  snprintf(&bname[i], remain, "<%d>", count);
   
         return bfind(bname, TRUE);          return (bfind(bname, TRUE));
 }  }
   
 /*  /*
Line 149 
Line 150 
   
         /* might be old */          /* might be old */
         if (bclear(curbp) != TRUE)          if (bclear(curbp) != TRUE)
                 return TRUE;                  return (TRUE);
         if ((status = insertfile(fname, fname, TRUE)) != TRUE) {          if ((status = insertfile(fname, fname, TRUE)) != TRUE) {
                 ewprintf("File is not readable: %s", fname);                  ewprintf("File is not readable: %s", fname);
                 return FALSE;                  return (FALSE);
         }          }
   
         /*          /*
Line 175 
Line 176 
                 }                  }
         }          }
   
         /* We need to set the READONLY flag after we insert the file */          /* We need to set the READONLY flag after we insert the file. */
         if (access(fname, W_OK) && errno != ENOENT)          if (access(fname, W_OK) && errno != ENOENT)
                 curbp->b_flag |= BFREADONLY;                  curbp->b_flag |= BFREADONLY;
         else          else
Line 184 
Line 185 
         if (startrow)          if (startrow)
                 gotoline(FFARG, startrow);                  gotoline(FFARG, startrow);
   
         return status;          return (status);
 }  }
   
 /*  /*
Line 198 
Line 199 
  * Insert a file in the current buffer, after dot.  Set mark at the end of   * Insert a file in the current buffer, after dot.  Set mark at the end of
  * the text inserted; point at the beginning.  Return a standard status.   * the text inserted; point at the beginning.  Return a standard status.
  * Print a summary (lines read, error message) out as well.  Unless the   * Print a summary (lines read, error message) out as well.  Unless the
  * NO_BACKUP conditional is set, this routine also does the read end of   * NO_BACKUP conditional is set, this routine also does the read end of
  * backup processing.  The BFBAK flag, if set in a buffer, says that a   * backup processing.  The BFBAK flag, if set in a buffer, says that a
  * backup should be taken.  It is set when a file is read in, but not on   * backup should be taken.  It is set when a file is read in, but not on
  * a new file.  (You don't need to make a backup copy of nothing.)   * a new file.  (You don't need to make a backup copy of nothing.)
Line 341 
Line 342 
         bp->b_flag |= BFCHG;          bp->b_flag |= BFCHG;
 #endif /* !NO_BACKUP */  #endif /* !NO_BACKUP */
         /*          /*
          * if the insert was at the end of buffer, set lp1 to the end of           * If the insert was at the end of buffer, set lp1 to the end of
          * buffer line, and lp2 to the beginning of the newly inserted text.           * buffer line, and lp2 to the beginning of the newly inserted text.
          * (Otherwise lp2 is set to NULL.)  This is used below to set           * (Otherwise lp2 is set to NULL.)  This is used below to set
          * pointers in other windows correctly if they are also at the end of           * pointers in other windows correctly if they are also at the end of
Line 372 
Line 373 
                 undo_enable(x);                  undo_enable(x);
   
         /* return false if error */          /* return false if error */
         return s != FIOERR;          return (s != FIOERR);
 }  }
   
 /*  /*
Line 391 
Line 392 
   
         if ((bufp = eread("Write file: ", fname, NFILEN,          if ((bufp = eread("Write file: ", fname, NFILEN,
             EFNEW | EFCR | EFFILE)) == NULL)              EFNEW | EFCR | EFFILE)) == NULL)
                 return ABORT;                  return (ABORT);
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return FALSE;                  return (FALSE);
   
         adjfname = adjustname(fname);          adjfname = adjustname(fname);
         if (adjfname == NULL)          if (adjfname == NULL)
Line 417 
Line 418 
 #endif /* !NO_BACKUP */  #endif /* !NO_BACKUP */
                 upmodes(curbp);                  upmodes(curbp);
         }          }
         return s;          return (s);
 }  }
   
 /*  /*
Line 434 
Line 435 
 int  int
 filesave(int f, int n)  filesave(int f, int n)
 {  {
         return buffsave(curbp);          return (buffsave(curbp));
 }  }
   
 /*  /*
Line 453 
Line 454 
         /* return, no changes */          /* return, no changes */
         if ((bp->b_flag & BFCHG) == 0) {          if ((bp->b_flag & BFCHG) == 0) {
                 ewprintf("(No changes need to be saved)");                  ewprintf("(No changes need to be saved)");
                 return TRUE;                  return (TRUE);
         }          }
   
         /* must have a name */          /* must have a name */
Line 467 
Line 468 
                 s = fbackupfile(bp->b_fname);                  s = fbackupfile(bp->b_fname);
                 /* hard error */                  /* hard error */
                 if (s == ABORT)                  if (s == ABORT)
                         return FALSE;                          return (FALSE);
                 /* softer error */                  /* softer error */
                 if (s == FALSE &&                  if (s == FALSE &&
                     (s = eyesno("Backup error, save anyway")) != TRUE)                      (s = eyesno("Backup error, save anyway")) != TRUE)
                         return s;                          return (s);
         }          }
 #endif /* !NO_BACKUP */  #endif /* !NO_BACKUP */
         if ((s = writeout(bp, bp->b_fname)) == TRUE) {          if ((s = writeout(bp, bp->b_fname)) == TRUE) {
Line 482 
Line 483 
 #endif /* !NO_BACKUP */  #endif /* !NO_BACKUP */
                 upmodes(bp);                  upmodes(bp);
         }          }
         return s;          return (s);
 }  }
   
 #ifndef NO_BACKUP  #ifndef NO_BACKUP
Line 502 
Line 503 
         else          else
                 makebackup = !makebackup;                  makebackup = !makebackup;
         ewprintf("Backup files %sabled", makebackup ? "en" : "dis");          ewprintf("Backup files %sabled", makebackup ? "en" : "dis");
         return TRUE;          return (TRUE);
 }  }
 #endif /* !NO_BACKUP */  #endif /* !NO_BACKUP */
   
Line 537 
Line 538 
         } else          } else
                 /* ignore close error if it is a write error */                  /* ignore close error if it is a write error */
                 (void)ffclose(bp);                  (void)ffclose(bp);
         return s == FIOSUC;          return (s == FIOSUC);
 }  }
   
 /*  /*

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.32