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

Diff for /src/usr.bin/mg/fileio.c between version 1.54 and 1.55

version 1.54, 2005/10/13 20:23:01 version 1.55, 2005/10/14 06:41:47
Line 19 
Line 19 
 #include <string.h>  #include <string.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <unistd.h>  #include <unistd.h>
 #include <ctype.h>  
   
 static FILE     *ffp;  static FILE     *ffp;
   
Line 400 
Line 399 
         return (TRUE);          return (TRUE);
 }  }
   
 /*  
  * dirname needs to have enough place to store an additional '/'.  
  */  
 BUFFER *  
 dired_(char *dirname)  
 {  
         BUFFER  *bp;  
         FILE    *dirpipe;  
         char     line[256];  
         int      len;  
   
         if ((dirname = adjustname(dirname)) == NULL) {  
                 ewprintf("Bad directory name");  
                 return (NULL);  
         }  
         /* this should not be done, instead adjustname() should get a flag */  
         len = strlen(dirname);  
         if (dirname[len - 1] != '/') {  
                 dirname[len++] = '/';  
                 dirname[len] = '\0';  
         }  
         if ((bp = findbuffer(dirname)) == NULL) {  
                 ewprintf("Could not create buffer");  
                 return (NULL);  
         }  
         if (bclear(bp) != TRUE)  
                 return (NULL);  
         bp->b_flag |= BFREADONLY;  
         if (snprintf(line, sizeof(line), "ls -al %s", dirname)  
             >= sizeof(line)) {  
                 ewprintf("Path too long");  
                 return (NULL);  
         }  
         if ((dirpipe = popen(line, "r")) == NULL) {  
                 ewprintf("Problem opening pipe to ls");  
                 return (NULL);  
         }  
         line[0] = line[1] = ' ';  
         while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {  
                 line[strlen(line) - 1] = '\0';  /* remove ^J     */  
                 (void) addline(bp, line);  
         }  
         if (pclose(dirpipe) == -1) {  
                 ewprintf("Problem closing pipe to ls : %s",  
                     strerror(errno));  
                 return (NULL);  
         }  
         bp->b_dotp = lforw(bp->b_linep);        /* go to first line */  
         (void) strlcpy(bp->b_fname, dirname, sizeof(bp->b_fname));  
         if ((bp->b_modes[1] = name_mode("dired")) == NULL) {  
                 bp->b_modes[0] = name_mode("fundamental");  
                 ewprintf("Could not find mode dired");  
                 return (NULL);  
         }  
         bp->b_nmodes = 1;  
         return (bp);  
 }  
   
 #define NAME_FIELD      8  
   
 int  
 d_makename(LINE *lp, char *fn, int len)  
 {  
         int      i;  
         char    *p, *ep;  
   
         strlcpy(fn, curbp->b_fname, len);  
         if ((p = lp->l_text) == NULL)  
                 return (ABORT);  
         ep = lp->l_text + llength(lp);  
         p++; /* skip action letter, if any */  
         for (i = 0; i < NAME_FIELD; i++) {  
                 while (p < ep && isspace(*p))  
                         p++;  
                 while (p < ep && !isspace(*p))  
                         p++;  
                 while (p < ep && isspace(*p))  
                         p++;  
                 if (p == ep)  
                         return (ABORT);  
         }  
         strlcat(fn, p, len);  
         return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);  
 }  
 #endif                          /* NO_DIRED */  #endif                          /* NO_DIRED */
   
 struct filelist {  struct filelist {

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.55