[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.5 and 1.6

version 1.5, 2001/01/29 01:58:07 version 1.6, 2001/05/04 22:00:35
Line 4 
Line 4 
  *      File commands.   *      File commands.
  */   */
   
   #include <libgen.h>
 #include "def.h"  #include "def.h"
   
 static char     *itos   __P((char *, unsigned int));  
   
 /*  /*
  * Insert a file into the current buffer.  Real easy - just call the   * Insert a file into the current buffer.  Real easy - just call the
  * insertfile routine with the file name.   * insertfile routine with the file name.
Line 100 
Line 99 
         unsigned int     count = 1;          unsigned int     count = 1;
   
         for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {          for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
                 if (fncmp(bp->b_fname, fname) == 0)                  if (strcmp(bp->b_fname, fname) == 0)
                         return bp;                          return bp;
         }          }
         /* new buffer name */          /* new buffer name */
         makename(bname, fname);          strcpy(bname, basename(fname));
         cp = bname + strlen(bname);          cp = bname + strlen(bname);
         while (bfind(bname, FALSE) != NULL) {          for (count = 1; bfind(bname, FALSE) != NULL; count++)
                 /* add "<count>" to the name */                  sprintf(cp, "<%d>", count);
                 *cp = '<';  
                 (VOID)strcpy(itos(cp, ++count) + 1, ">");  
         }  
         return bfind(bname, TRUE);          return bfind(bname, TRUE);
 }  }
   
 /*  /*
  * Put the decimal representation of num into a buffer.  Hacked to be  
  * faster, smaller, and less general.  
  */  
 static char *  
 itos(bufp, num)  
         char            *bufp;  
         unsigned int     num;  
 {  
         if (num >= 10) {  
                 bufp = itos(bufp, num / 10);  
                 num %= 10;  
         }  
         *++bufp = '0' + num;  
         return bufp;  
 }  
   
 /*  
  * Read the file "fname" into the current buffer.  Make all of the text   * Read the file "fname" into the current buffer.  Make all of the text
  * in the buffer go away, after checking for unsaved changes.  This is   * in the buffer go away, after checking for unsaved changes.  This is
  * called by the "read" command, the "visit" command, and the mainline   * called by the "read" command, the "visit" command, and the mainline
Line 337 
Line 316 
         }          }
         /* return false if error */          /* return false if error */
         return s != FIOERR;          return s != FIOERR;
 }  
   
 /*  
  * Fabriacte a buffer name from a given filename.  This routing knows  
  * about the syntax of file names on the target system.  
  * BDC1         left scan delimiter.  
  * BDC2         optional second left scan delimiter.  
  * BDC3         optional right scan delimiter.  
  */  
 VOID  
 makename(bname, fname)  
         char *bname, *fname;  
 {  
         char *cp1, *cp2;  
   
         cp1 = &fname[0];  
         while (*cp1 != 0)  
                 ++cp1;  
   
         /* insure at least 1 character */  
         --cp1;  
 #ifdef BDC2  
         while (cp1 != &fname[0] && cp1[-1] != BDC1 && cp1[-1] != BDC2)  
                 --cp1;  
 #else /* BDC2 */  
         while (cp1 != &fname[0] && cp1[-1] != BDC1)  
                 --cp1;  
 #endif /* BDC2 */  
         cp2 = &bname[0];  
   
 #ifdef BDC3  
         while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != BDC3)  
                 *cp2++ = *cp1++;  
 #else /* BDC3 */  
         while (cp2 != &bname[NBUFN - 1] && *cp1 != 0)  
                 *cp2++ = *cp1++;  
 #endif /* BDC3 */  
         *cp2 = 0;  
 }  }
   
 /*  /*

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6