[BACK]Return to sftp-int.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/Attic/sftp-int.c between version 1.59 and 1.60

version 1.59, 2003/05/15 03:39:07 version 1.60, 2003/05/15 03:43:59
Line 55 
Line 55 
 /* Seperators for interactive commands */  /* Seperators for interactive commands */
 #define WHITESPACE " \t\r\n"  #define WHITESPACE " \t\r\n"
   
   /* Define what type of ls view (0 - multi-column) */
   #define LONG_VIEW 1             /* Full view ala ls -l */
   #define SHORT_VIEW 2            /* Single row view ala ls -1 */
   
 /* Commands for interactive mode */  /* Commands for interactive mode */
 #define I_CHDIR         1  #define I_CHDIR         1
 #define I_CHGRP         2  #define I_CHGRP         2
Line 309 
Line 313 
                 for(; strchr(WHITESPACE, *cp) == NULL; cp++) {                  for(; strchr(WHITESPACE, *cp) == NULL; cp++) {
                         switch (*cp) {                          switch (*cp) {
                         case 'l':                          case 'l':
                                 *lflag = 1;                                  *lflag = LONG_VIEW;
                                 break;                                  break;
                           case '1':
                                   *lflag = SHORT_VIEW;
                                   break;
                         default:                          default:
                                 error("Invalid flag -%c", *cp);                                  error("Invalid flag -%c", *cp);
                                 return(-1);                                  return(-1);
Line 560 
Line 567 
 static int  static int
 do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)  do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
 {  {
         int n;          int n, c = 1, colspace = 0, columns = 1;
         SFTP_DIRENT **d;          SFTP_DIRENT **d;
   
         if ((n = do_readdir(conn, path, &d)) != 0)          if ((n = do_readdir(conn, path, &d)) != 0)
                 return (n);                  return (n);
   
         /* Count entries for sort */          if (!(lflag & SHORT_VIEW)) {
         for (n = 0; d[n] != NULL; n++)                  int m = 0, width = 80;
                 ;                  struct winsize ws;
   
                   /* Count entries for sort and find longest filename */
                   for (n = 0; d[n] != NULL; n++)
                           m = MAX(m, strlen(d[n]->filename));
   
                   if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
                           width = ws.ws_col;
   
                   columns = width / (m + 2);
                   colspace = width / columns;
           }
   
         qsort(d, n, sizeof(*d), sdirent_comp);          qsort(d, n, sizeof(*d), sdirent_comp);
   
         for (n = 0; d[n] != NULL; n++) {          for (n = 0; d[n] != NULL; n++) {
Line 579 
Line 597 
                 fname = path_strip(tmp, strip_path);                  fname = path_strip(tmp, strip_path);
                 xfree(tmp);                  xfree(tmp);
   
                 if (lflag) {                  if (lflag & LONG_VIEW) {
                         char *lname;                          char *lname;
                         struct stat sb;                          struct stat sb;
   
Line 589 
Line 607 
                         printf("%s\n", lname);                          printf("%s\n", lname);
                         xfree(lname);                          xfree(lname);
                 } else {                  } else {
                         /* XXX - multicolumn display would be nice here */                          printf("%-*s", colspace, fname);
                         printf("%s\n", fname);                          if (c >= columns) {
                                   printf("\n");
                                   c = 1;
                           } else
                                   c++;
                 }                  }
   
                 xfree(fname);                  xfree(fname);
         }          }
   
           if (!(lflag & LONG_VIEW) && (c != 1))
                   printf("\n");
   
         free_sftp_dirents(d);          free_sftp_dirents(d);
         return (0);          return (0);
 }  }
Line 606 
Line 631 
     int lflag)      int lflag)
 {  {
         glob_t g;          glob_t g;
         int i;          int i, c = 1, colspace = 0, columns = 1;
         Attrib *a;          Attrib *a;
         struct stat sb;  
   
         memset(&g, 0, sizeof(g));          memset(&g, 0, sizeof(g));
   
Line 635 
Line 659 
                 }                  }
         }          }
   
           if (!(lflag & SHORT_VIEW)) {
                   int m = 0, width = 80;
                   struct winsize ws;
   
                   /* Count entries for sort and find longest filename */
                   for (i = 0; g.gl_pathv[i]; i++)
                           m = MAX(m, strlen(g.gl_pathv[i]));
   
                   if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
                           width = ws.ws_col;
   
                   columns = width / (m + 2);
                   colspace = width / columns;
           }
   
         for (i = 0; g.gl_pathv[i]; i++) {          for (i = 0; g.gl_pathv[i]; i++) {
                 char *fname, *lname;                  char *fname;
   
                 fname = path_strip(g.gl_pathv[i], strip_path);                  fname = path_strip(g.gl_pathv[i], strip_path);
   
                 if (lflag) {                  if (lflag & LONG_VIEW) {
                           char *lname;
                           struct stat sb;
   
                         /*                          /*
                          * XXX: this is slow - 1 roundtrip per path                           * XXX: this is slow - 1 roundtrip per path
                          * A solution to this is to fork glob() and                           * A solution to this is to fork glob() and
Line 656 
Line 698 
                         printf("%s\n", lname);                          printf("%s\n", lname);
                         xfree(lname);                          xfree(lname);
                 } else {                  } else {
                         /* XXX - multicolumn display would be nice here */                          printf("%-*s", colspace, fname);
                         printf("%s\n", fname);                          if (c >= columns) {
                                   printf("\n");
                                   c = 1;
                           } else
                                   c++;
                 }                  }
                 xfree(fname);                  xfree(fname);
         }          }
   
           if (!(lflag & LONG_VIEW) && (c != 1))
                   printf("\n");
   
         if (g.gl_pathc)          if (g.gl_pathc)
                 globfree(&g);                  globfree(&g);

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.60