home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DOWN.ZIP / DOWN.C next >
Text File  |  1988-11-02  |  4KB  |  234 lines

  1. #include <os2.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <search.h>
  6.  
  7. char subdir[99][32]
  8.    , buf[64]
  9.    , search[32]
  10.    ;
  11.  
  12. USHORT wCount
  13.      ;
  14.  
  15. HDIR hDirectory
  16.    ;
  17.  
  18. ULONG ulMask
  19.     ;
  20.  
  21. FILEFINDBUF ffbDirentry
  22.           ;
  23.  
  24. list_dirs(char *);
  25.  
  26.  
  27. void main(int argc
  28.          , char *argv[]
  29.          )
  30. {
  31. int count
  32.   , j
  33.   ;
  34.  
  35. if (argc > 1)
  36.     {
  37.     strcpy( search
  38.           , argv[1]
  39.           );
  40.           
  41.     if (strchr( search, '?') != NULL)
  42.         {
  43.         printf("\nuse:  down [?] [-?] [subdir]");
  44.         printf("\nVersion 3.0  (C) Copyright 1988 QMI\n");
  45.         DosExit(1,0);
  46.         }
  47.  
  48.     if (DosChdir( search
  49.                 , 0L
  50.                 ) == 0
  51.        )
  52.         {
  53.  
  54.         wCount = sizeof(buf);
  55.  
  56.         DosQCurDir( 0
  57.                   , buf
  58.                   , &wCount
  59.                   );
  60.         DosQCurDisk( &wCount
  61.                    , &ulMask
  62.                    );
  63.         printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
  64.         DosExit(1,0);
  65.         }
  66.     else
  67.         {
  68.         strcat( search, "*.*");
  69.         }
  70.     }
  71. else
  72.     strcpy(search, "*.*");
  73.  
  74. count = list_dirs( search);
  75.  
  76. if (count == 0)
  77.     {
  78.     printf("\nNo subdirectories found...\n");
  79.     DosExit(1,0);
  80.     }
  81.  
  82. if (count == 1)
  83.     {
  84.     wCount = sizeof(buf);
  85.  
  86.     DosQCurDir( 0
  87.               , buf
  88.               , &wCount
  89.               );
  90.     DosQCurDisk( &wCount
  91.                , &ulMask
  92.                );
  93.     printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
  94.  
  95.     DosExit(1,0);
  96.     }
  97.  
  98. printf("\n\nDirectory Change to: ");
  99. gets(buf);
  100. j = atoi(buf);
  101. if (j)
  102.     {
  103.     if ((j > 0) && (j <= count))
  104.         DosChdir( subdir[j]
  105.                 , 0L
  106.                 );
  107.     }
  108. else
  109.     {
  110.     DosChdir( buf
  111.             , 0L
  112.             );
  113.     }
  114.  
  115. wCount = sizeof(buf);
  116.  
  117. DosQCurDir( 0
  118.           , buf
  119.           , &wCount
  120.           );
  121. DosQCurDisk( &wCount
  122.            , &ulMask
  123.            );
  124. printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
  125.  
  126. DosExit(1,0);
  127. }
  128.  
  129. list_dirs(char  *search)
  130. {
  131. int at,i,j = 0, n1, n2;
  132. int dcount
  133.   , count = 0;
  134.  
  135. wCount = 1;
  136.  
  137. hDirectory = 0xFFFF;
  138.  
  139. if (DosFindFirst( search
  140.                 , &hDirectory
  141.                 , (USHORT) 0x0010
  142.                 , &ffbDirentry
  143.                 , (USHORT) sizeof(ffbDirentry)
  144.                 , &wCount
  145.                 , 0L
  146.                 ) == 0
  147.    )
  148.     {
  149.     at = ffbDirentry.attrFile;
  150.     if ((at == 0x0010) && (at != 0x0008) && (ffbDirentry.achName[0] != '.'))
  151.         strcpy(subdir[++count], ffbDirentry.achName);
  152.     }
  153. else
  154.     {
  155.     printf("\nNo directory found that matches specification...\n");
  156.     DosExit(1,0);
  157.     }
  158.  
  159. while (TRUE)
  160.     {
  161.     wCount = 1;
  162.  
  163.     if (!DosFindNext( hDirectory
  164.                     , &ffbDirentry
  165.                     , (USHORT) sizeof(ffbDirentry)
  166.                     , &wCount
  167.                     )
  168.        )
  169.         {
  170.         at = ffbDirentry.attrFile;
  171.         if ((at == 0x0010) && (at != 0x0008) && (ffbDirentry.achName[0] != '.'))
  172.             strcpy(subdir[++count], ffbDirentry.achName);
  173.         }
  174.     else
  175.         break;
  176.     }
  177.  
  178. subdir[count+1][0] = '\0';
  179. subdir[count+2][0] = '\0';
  180.  
  181. switch (count)
  182. {
  183. case 0:
  184.     break;
  185.  
  186. case 1:
  187.     DosChdir( subdir[1]
  188.             , 0L
  189.             );
  190.     break;
  191.  
  192. default:
  193.     qsort( subdir[1]
  194.          , count
  195.          , 32
  196.          , strcmp
  197.          );
  198.  
  199.     dcount = count/3;
  200.     switch(count%3)
  201.     {
  202.     case 0:
  203.         n1 = dcount;
  204.         n2 = n1 + dcount;
  205.         break;
  206.     case 1:
  207.         n1 = dcount + 1;
  208.         n2 = n1 + dcount;
  209.         break;
  210.     case 2:
  211.         n1 = dcount + 1;
  212.         n2 = n1 + dcount + 1;
  213.         break;
  214.     }
  215.     for (i=1; i<=dcount; i++)
  216.         {
  217.         printf("\n%3d.  %-16s%3d.  %-16s%3d.  %-12s", i, subdir[i], i+n1, subdir[i+n1], i+n2, subdir[i+n2]);
  218.         }
  219.     switch (count%3)
  220.     {
  221.     case 0:
  222.         break;
  223.     case 1:
  224.         printf("\n%3d.  %-12s", dcount+1, subdir[dcount+1]);
  225.         break;
  226.     case 2:
  227.         printf("\n%3d.  %-16s%3d.  %-12s", dcount+1, subdir[dcount+1], dcount+n1+1, subdir[dcount+n1+1]);
  228.         break;
  229.     }
  230. return( count);
  231. }
  232. return( count);
  233. }
  234.