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

Diff for /src/usr.bin/ssh/sftp.c between version 1.51 and 1.52

version 1.51, 2004/06/21 17:36:31 version 1.52, 2004/06/21 22:04:50
Line 51 
Line 51 
 /* SIGINT received during command processing */  /* SIGINT received during command processing */
 volatile sig_atomic_t interrupted = 0;  volatile sig_atomic_t interrupted = 0;
   
   /* I wish qsort() took a separate ctx for the comparison function...*/
   int sort_flag;
   
 int remote_glob(struct sftp_conn *, const char *, int,  int remote_glob(struct sftp_conn *, const char *, int,
     int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */      int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */
   
 /* Separators for interactive commands */  /* Separators for interactive commands */
 #define WHITESPACE " \t\r\n"  #define WHITESPACE " \t\r\n"
   
 /* Define what type of ls view */  /* ls flags */
 #define LONG_VIEW       1       /* Full view ala ls -l */  #define LONG_VIEW       0x01    /* Full view ala ls -l */
 #define SHORT_VIEW      2       /* Single row view ala ls -1 */  #define SHORT_VIEW      0x02    /* Single row view ala ls -1 */
 #define NUMERIC_VIEW    4       /* Long view with numeric uid/gid */  #define NUMERIC_VIEW    0x04    /* Long view with numeric uid/gid */
   #define NAME_SORT       0x08    /* Sort by name (default) */
   #define TIME_SORT       0x10    /* Sort by mtime */
   #define SIZE_SORT       0x20    /* Sort by file size */
   #define REVERSE_SORT    0x40    /* Reverse sort order */
   
 #define VIEW_FLAGS      (LONG_VIEW|SHORT_VIEW|NUMERIC_VIEW)  #define VIEW_FLAGS      (LONG_VIEW|SHORT_VIEW|NUMERIC_VIEW)
   #define SORT_FLAGS      (NAME_SORT|TIME_SORT|SIZE_SORT)
   
 /* Commands for interactive mode */  /* Commands for interactive mode */
 #define I_CHDIR         1  #define I_CHDIR         1
Line 332 
Line 341 
 {  {
         const char *cp = *cpp;          const char *cp = *cpp;
   
           /* Defaults */
           *lflag = NAME_SORT;
   
         /* Check for flags */          /* Check for flags */
         if (cp++[0] == '-') {          if (cp++[0] == '-') {
                 for(; strchr(WHITESPACE, *cp) == NULL; cp++) {                  for(; strchr(WHITESPACE, *cp) == NULL; cp++) {
Line 348 
Line 360 
                                 *lflag &= ~VIEW_FLAGS;                                  *lflag &= ~VIEW_FLAGS;
                                 *lflag |= NUMERIC_VIEW|LONG_VIEW;                                  *lflag |= NUMERIC_VIEW|LONG_VIEW;
                                 break;                                  break;
                           case 'S':
                                   *lflag &= ~SORT_FLAGS;
                                   *lflag |= SIZE_SORT;
                                   break;
                           case 't':
                                   *lflag &= ~SORT_FLAGS;
                                   *lflag |= TIME_SORT;
                                   break;
                           case 'r':
                                   *lflag |= REVERSE_SORT;
                                   break;
                           case 'f':
                                   *lflag &= ~SORT_FLAGS;
                                   break;
                         default:                          default:
                                 error("Invalid flag -%c", *cp);                                  error("Invalid flag -%c", *cp);
                                 return(-1);                                  return(-1);
Line 607 
Line 633 
 {  {
         SFTP_DIRENT *a = *(SFTP_DIRENT **)aa;          SFTP_DIRENT *a = *(SFTP_DIRENT **)aa;
         SFTP_DIRENT *b = *(SFTP_DIRENT **)bb;          SFTP_DIRENT *b = *(SFTP_DIRENT **)bb;
           int rmul = sort_flag & REVERSE_SORT ? -1 : 1;
   
         return (strcmp(a->filename, b->filename));  #define NCMP(a,b) (a == b ? 0 : (a < b ? 1 : -1))
           if (sort_flag & NAME_SORT)
                   return (rmul * strcmp(a->filename, b->filename));
           else if (sort_flag & TIME_SORT)
                   return (rmul * NCMP(a->a.mtime, b->a.mtime));
           else if (sort_flag & SIZE_SORT)
                   return (rmul * NCMP(a->a.size, b->a.size));
   
           fatal("Unknown ls sort type");
 }  }
   
 /* sftp ls.1 replacement for directories */  /* sftp ls.1 replacement for directories */
Line 644 
Line 679 
                 colspace = MIN(colspace, width);                  colspace = MIN(colspace, width);
         }          }
   
         qsort(d, n, sizeof(*d), sdirent_comp);          if (lflag & SORT_FLAGS) {
                   sort_flag = lflag & (SORT_FLAGS|REVERSE_SORT);
                   qsort(d, n, sizeof(*d), sdirent_comp);
           }
   
         for (n = 0; d[n] != NULL && !interrupted; n++) {          for (n = 0; d[n] != NULL && !interrupted; n++) {
                 char *tmp, *fname;                  char *tmp, *fname;

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52