home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / ftree / ftree.c next >
Text File  |  1990-06-14  |  4KB  |  179 lines

  1. /*    FTREE.C        V1.0 L10    by MSどす    */
  2. /*    for MS-C V5.1        1989.09.25        */
  3. /*    last update        1989.09.29        */
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <string.h>
  8.  
  9. #define    BMAX    512
  10. #define    SPC_AREA "  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  "
  11. /*
  12. struct    FIND_TAG{
  13.     char    reserved[21];
  14.     char    attrib;
  15.     unsigned    wr_time;
  16.     unsigned    wr_date;
  17.     long    size;
  18.     char    name[13];
  19. } f_buf;
  20. */
  21. struct find_t f_buf;
  22.  
  23. struct    FTAG{
  24.     char    attrib;
  25.     unsigned    wr_time;
  26.     unsigned    wr_date;
  27.     long    size;
  28.     char    name[13];
  29. } f_inf[BMAX];
  30.  
  31. long    total=0;
  32. int    cnt=0;
  33. unsigned short    nesting=0,proc_flg=0;
  34. char    outbuf[256];
  35.  
  36. void ftree(char *path_name){
  37.     int    i,start;
  38.     unsigned    ret;
  39.     char    p_work[80],s_work[32];
  40.     
  41.     strcpy(p_work,path_name);
  42.     strcat(p_work,"\\*.*");
  43.     
  44.     s_work[0]=0;
  45.     for(i=0;i<nesting;i++){
  46.         strcat(s_work,"|  ");
  47.     }
  48.     strcat(s_work,"+--");
  49.     nesting ++;
  50.     if(nesting > 8){
  51.         strcpy(outbuf,"(ERROR: ディレクトリが深すぎます。表示できません。)");
  52.         puts(outbuf);    /* TOWNS */
  53.         return;
  54.     }
  55.     
  56.     /*    SET DTA        */
  57.     
  58.     ret= _dos_findfirst(p_work,0x3f,&f_buf);
  59.             /* 正常 */
  60.     start=cnt;
  61.     
  62.     while(ret==0 && cnt<BMAX){        /* ファイル検索 */
  63.         f_inf[cnt].attrib = f_buf.attrib;    /* *fbuf. */
  64.         f_inf[cnt].wr_time = f_buf.wr_time;
  65.         f_inf[cnt].wr_date = f_buf.wr_date;
  66.         f_inf[cnt].size = f_buf.size;
  67.         strncpy(f_inf[cnt].name ,f_buf.name ,13);
  68.         cnt ++;
  69.         
  70.         ret= _dos_findnext(&f_buf);
  71.     }
  72.     
  73.     for(i=start;proc_flg==0 && i<cnt;i++){    /* ファイル一覧 */
  74.         if(f_inf[i].attrib != 0x10){
  75.                         /* NOT SUB-DIR */
  76.         /*    strcpy(outbuf,s_work);
  77.             strncat(outbuf, f_inf[i].name ,13);*/
  78.             sprintf(outbuf,"%s%-13s",s_work,f_inf[i].name);
  79.             strcat(outbuf,SPC_AREA);
  80.             sprintf(&outbuf[36],"%c%c%c%c%c  %04u.%02u.%02u  %02u:%02u    %8ld"
  81.                                 ,(f_inf[i].attrib & 0x20)? 'a' : '.'
  82.                             /*    ,(f_inf[i].attrib & 0x10)? 'd' : '.' */
  83.                                 ,(f_inf[i].attrib & 0x08)? 'v' : '.'
  84.                                 ,(f_inf[i].attrib & 0x04)? 's' : '.'
  85.                                 ,(f_inf[i].attrib & 0x02)? 'h' : '.'
  86.                                 ,(f_inf[i].attrib & 0x01)? 'o' : 'w'
  87.                                 ,((f_inf[i].wr_date >>9 ) & 0x7f) + 1980
  88.                                 ,(f_inf[i].wr_date >>5 ) & 0xf
  89.                                 ,(f_inf[i].wr_date     ) & 0x1f
  90.                                 ,(f_inf[i].wr_time >>11) & 0x1f
  91.                                 ,(f_inf[i].wr_time >>5 ) & 0x3f
  92.                                 ,f_inf[i].size);
  93.             
  94.             puts(outbuf);    /* TOWNS */
  95.         }
  96.     }
  97.     
  98.     total=0;                /* 容量計算する */
  99.     for(i=start;i<cnt;i++){    
  100.         if(f_inf[i].attrib != 0x10){
  101.             total += (f_inf[i].size);    /* OVER-FLOW大丈夫かな... */
  102.         }
  103.     }
  104.     strcpy(outbuf,s_work);            /* 容量表示する */
  105. /*    outbuf[strlen(s_work)-3] = 0;*/
  106.     strcat(outbuf," ");
  107.     strcat(outbuf,SPC_AREA);
  108.     sprintf(&outbuf[42],"ファイル容量 計(約%5uKB)",(total + 512)/1024);
  109.     puts(outbuf);    /* TOWNS */
  110.  
  111.     for(i=start;i<cnt;i++){            /* サブディレクトリ一覧 */
  112.         if((f_inf[i].attrib == 0x10) && (f_inf[i].name[0] != '.')){
  113.                         /* IS SUB-DIR */
  114.             strcpy(outbuf,s_work);
  115.             strncat(outbuf,f_inf[i].name,13);
  116.             /* EGBで文字パターン変更 */
  117.             puts(outbuf);
  118.             /* EGBで文字パターン変更 */
  119.             
  120.             strcpy(p_work,path_name);
  121.             strcat(p_work,"\\");
  122.             strncat(p_work,f_inf[i].name,13);
  123.             ftree(p_work);
  124.         }
  125.     }
  126.     
  127.     cnt = start;
  128.     nesting --;
  129. }
  130.  
  131. char    drive_name[]="?:";
  132. void main(int argc,char *argv[]){
  133.     unsigned    drv;
  134.     short int    i;
  135.     struct    diskfree_t    f;
  136.     
  137.     if(argc > 3){
  138.         puts("help : FTREE -?");
  139.         return;
  140.     }
  141.  
  142.     proc_flg=0;
  143.     for(i=1;i<argc;i++){
  144.         if(argv[i][0] == '/' || argv[i][0] == '-'){
  145.             if(toupper(argv[i][1]) == 'D'){
  146.                 proc_flg=1;            /* DIRECTORY ONLY */
  147.             }
  148.             else{
  149.                 puts("使用方法:FTREE ドライブ [/D]");
  150.                 puts("          /D 指定時にはディレクトリ名のみ表示します。");
  151.                 return;
  152.             }
  153.         }
  154.         else{
  155.             drive_name[0] = toupper(argv[i][0]);
  156.         }
  157.     }
  158.     if(drive_name[0] == '?'){
  159.         _dos_getdrive(&drv);
  160.         drive_name[0] = 'A' + drv -1;
  161.     }
  162.     else{
  163.         drv = drive_name[0] +1 - 'A';
  164.     }
  165.     
  166.     cnt = 0;
  167.     puts("[FTREE  V1.0 L10  by MSどす]    アトリビュート    ファイル日付     サイズ(バイト)");
  168.     sprintf(outbuf,"%s\\",drive_name);
  169.     puts(outbuf);    /* TOWNS */
  170.     ftree(drive_name);
  171.     puts("~");
  172.     
  173.     _dos_getdiskfree(drv,&f);
  174.     sprintf(outbuf,"%dKB 使用可能です。",f.bytes_per_sector / 1024
  175.             * f.avail_clusters * f.sectors_per_cluster);
  176.     puts(outbuf);    /* TOWNS */
  177.     puts("正常終了しました");
  178. }
  179.