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

Diff for /src/usr.bin/mg/dired.c between version 1.48 and 1.49

version 1.48, 2011/01/23 00:45:03 version 1.49, 2011/08/29 11:02:06
Line 36 
Line 36 
 static int       d_shell_command(int, int);  static int       d_shell_command(int, int);
 static int       d_create_directory(int, int);  static int       d_create_directory(int, int);
 static int       d_makename(struct line *, char *, size_t);  static int       d_makename(struct line *, char *, size_t);
   static int       d_warpdot(struct line *, int *);
   static int       d_forwpage(int, int);
   static int       d_backpage(int, int);
   static int       d_forwline(int, int);
   static int       d_backline(int, int);
 static void      reaper(int);  static void      reaper(int);
   
 extern struct keymap_s helpmap, cXmap, metamap;  extern struct keymap_s helpmap, cXmap, metamap;
Line 57 
Line 62 
 static PF diredcl[] = {  static PF diredcl[] = {
         reposition,             /* ^L */          reposition,             /* ^L */
         d_findfile,             /* ^M */          d_findfile,             /* ^M */
         forwline,               /* ^N */          d_forwline,             /* ^N */
         rescan,                 /* ^O */          rescan,                 /* ^O */
         backline,               /* ^P */          d_backline,             /* ^P */
         rescan,                 /* ^Q */          rescan,                 /* ^Q */
         backisearch,            /* ^R */          backisearch,            /* ^R */
         forwisearch,            /* ^S */          forwisearch,            /* ^S */
         rescan,                 /* ^T */          rescan,                 /* ^T */
         universal_argument,     /* ^U */          universal_argument,     /* ^U */
         forwpage,               /* ^V */          d_forwpage,             /* ^V */
         rescan,                 /* ^W */          rescan,                 /* ^W */
         NULL                    /* ^X */          NULL                    /* ^X */
 };  };
Line 77 
Line 82 
         rescan,                 /* ^] */          rescan,                 /* ^] */
         rescan,                 /* ^^ */          rescan,                 /* ^^ */
         rescan,                 /* ^_ */          rescan,                 /* ^_ */
         forwline,               /* SP */          d_forwline,             /* SP */
         d_shell_command,        /* ! */          d_shell_command,        /* ! */
         rescan,                 /* " */          rescan,                 /* " */
         rescan,                 /* # */          rescan,                 /* # */
Line 99 
Line 104 
 };  };
   
 static PF diredn[] = {  static PF diredn[] = {
         forwline,               /* n */          d_forwline,             /* n */
         d_ffotherwindow,        /* o */          d_ffotherwindow,        /* o */
         backline,               /* p */          d_backline,             /* p */
         rescan,                 /* q */          rescan,                 /* q */
         d_rename,               /* r */          d_rename,               /* r */
         rescan,                 /* s */          rescan,                 /* s */
Line 116 
Line 121 
         d_undelbak              /* del */          d_undelbak              /* del */
 };  };
   
   static PF diredbp[] = {
           d_backpage              /* v */
   };
   
   static PF dirednull[] = {
           NULL
   };
   
 #ifndef DIRED_XMAPS  #ifndef DIRED_XMAPS
 #define NDIRED_XMAPS    0       /* number of extra map sections */  #define NDIRED_XMAPS    0       /* number of extra map sections */
 #endif /* DIRED_XMAPS */  #endif /* DIRED_XMAPS */
   
 static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {  static struct KEYMAPE (1 + IMAPEXT) d_backpagemap = {
         6 + NDIRED_XMAPS,          1,
         6 + NDIRED_XMAPS + IMAPEXT,          1 + IMAPEXT,
           rescan,
           {
                   {
                   'v', 'v', diredbp, NULL
                   }
           }
   };
   
   static struct KEYMAPE (7 + NDIRED_XMAPS + IMAPEXT) diredmap = {
           7 + NDIRED_XMAPS,
           7 + NDIRED_XMAPS + IMAPEXT,
         rescan,          rescan,
         {          {
 #ifndef NO_HELP  #ifndef NO_HELP
Line 138 
Line 162 
                         CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap                          CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap
                 },                  },
                 {                  {
                           CCHR('['), CCHR('['), dirednull, (KEYMAP *) &
                           d_backpagemap
                   },
                   {
                         CCHR('Z'), '+', diredcz, (KEYMAP *) & metamap                          CCHR('Z'), '+', diredcz, (KEYMAP *) & metamap
                 },                  },
                 {                  {
Line 165 
Line 193 
         funmap_add(d_findfile, "dired-find-file");          funmap_add(d_findfile, "dired-find-file");
         funmap_add(d_ffotherwindow, "dired-find-file-other-window");          funmap_add(d_ffotherwindow, "dired-find-file-other-window");
         funmap_add(d_del, "dired-flag-file-deleted");          funmap_add(d_del, "dired-flag-file-deleted");
           funmap_add(d_forwline, "dired-next-line");
         funmap_add(d_otherwindow, "dired-other-window");          funmap_add(d_otherwindow, "dired-other-window");
           funmap_add(d_backline, "dired-previous-line");
         funmap_add(d_rename, "dired-rename-file");          funmap_add(d_rename, "dired-rename-file");
           funmap_add(d_backpage, "dired-scroll-down");
           funmap_add(d_forwpage, "dired-scroll-up");
         funmap_add(d_undel, "dired-unflag");          funmap_add(d_undel, "dired-unflag");
         maps_add((KEYMAP *)&diredmap, "dired");          maps_add((KEYMAP *)&diredmap, "dired");
         dobindkey(fundamental_map, "dired", "^Xd");          dobindkey(fundamental_map, "dired", "^Xd");
Line 592 
Line 624 
         return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);          return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);
 }  }
   
   static int
   d_warpdot(struct line *dotp, int *doto)
   {
           char *tp = dotp->l_text;
           int off = 0, field = 0, len;
   
           /*
            * Find the byte offset to the (space-delimited) filename
            * field in formatted ls output.
            */
           len = llength(dotp);
           while (off < len) {
                   if (tp[off++] == ' ') {
                           if (++field == 9)
                                   break;
                           /* Skip the space. */
                           while (off < len && tp[off] == ' ')
                                   off++;
                   }
           }
           *doto = off;
           return (TRUE);
   }
   
   static int
   d_forwpage(int f, int n)
   {
           forwpage(f | FFRAND, n);
           return (d_warpdot(curwp->w_dotp, &curwp->w_doto));
   }
   
   static int
   d_backpage (int f, int n)
   {
           backpage(f | FFRAND, n);
           return (d_warpdot(curwp->w_dotp, &curwp->w_doto));
   }
   
   static int
   d_forwline (int f, int n)
   {
           forwline(f | FFRAND, n);
           return (d_warpdot(curwp->w_dotp, &curwp->w_doto));
   }
   
   static int
   d_backline (int f, int n)
   {
           backline(f | FFRAND, n);
           return (d_warpdot(curwp->w_dotp, &curwp->w_doto));
   }
   
 /*  /*
  * XXX dname needs to have enough place to store an additional '/'.   * XXX dname needs to have enough place to store an additional '/'.
  */   */
Line 601 
Line 685 
         struct buffer   *bp;          struct buffer   *bp;
         FILE    *dirpipe;          FILE    *dirpipe;
         char     line[256];          char     line[256];
         int      len, ret, counter, warp;          int      len, ret, i;
         counter = 0;  
         warp = 0;  
   
         if ((fopen(dname,"r")) == NULL) {          if ((fopen(dname,"r")) == NULL) {
                 if (errno == EACCES)                  if (errno == EACCES)
Line 640 
Line 722 
         while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {          while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
                 line[strcspn(line, "\n")] = '\0'; /* remove ^J   */                  line[strcspn(line, "\n")] = '\0'; /* remove ^J   */
                 (void) addline(bp, line);                  (void) addline(bp, line);
                 if ((strrchr(line,' ')) != NULL) {  
                         counter++;  
                         if ((strcmp((strrchr(line,' '))," ..")) == 0)  
                                 warp = counter;  
                 }  
         }          }
         if ((strrchr(line,' ')) != NULL) {  
                 if (strcmp((strrchr(line,' '))," ..") == 0)  
                         warp = counter - 1;  
         }  
         if ((strrchr(line,' ')) != NULL)  
                 bp->b_doto = strrchr(line,' ') - line + 1;  
         if (pclose(dirpipe) == -1) {          if (pclose(dirpipe) == -1) {
                 ewprintf("Problem closing pipe to ls : %s",                  ewprintf("Problem closing pipe to ls : %s",
                     strerror(errno));                      strerror(errno));
                 return (NULL);                  return (NULL);
         }          }
   
           /* Find the line with ".." on it. */
         bp->b_dotp = bfirstlp(bp);          bp->b_dotp = bfirstlp(bp);
         while (warp--)          for (i = 0; i < bp->b_lines; i++) {
                 bp->b_dotp  = lforw(bp->b_dotp);                  bp->b_dotp = lforw(bp->b_dotp);
                   d_warpdot(bp->b_dotp, &bp->b_doto);
                   if (bp->b_doto >= llength(bp->b_dotp))
                           continue;
                   if (strcmp(ltext(bp->b_dotp) + bp->b_doto, "..") == 0)
                           break;
           }
   
           /* We want dot on the entry right after "..", if possible. */
           if (++i < bp->b_lines - 2)
                   bp->b_dotp = lforw(bp->b_dotp);
           d_warpdot(bp->b_dotp, &bp->b_doto);
   
         (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname));          (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname));
         (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd));          (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd));
         if ((bp->b_modes[1] = name_mode("dired")) == NULL) {          if ((bp->b_modes[1] = name_mode("dired")) == NULL) {

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49