home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / prnout / src / wc.c < prev   
Text File  |  1990-06-14  |  7KB  |  339 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <ctype.h>
  4. #include    <msdos.cf>
  5. #include    "defs.h"
  6.  
  7. #define DSP_X   36
  8. #define DSP_Y   0
  9. #define MAX     22
  10.  
  11. #define DIR_FLG 0x10
  12.  
  13. typedef struct _WCBUF {
  14.     struct _WCBUF       *next;
  15.     short int           att;
  16.     unsigned short int  time,date;
  17.     unsigned long       size;
  18.     char                name[14];
  19. } WCBUF;
  20.  
  21. static short int    cmp_mode=0;
  22. static WCBUF        *topwp=NULL;
  23.  
  24. void    chdrv(no)
  25. int    no;
  26. {
  27.     Registers.AX.R = 0x0E00;
  28.     Registers.DX.R = no;
  29.     calldos();
  30. }
  31. void    chdir(char *name)
  32. {
  33.     Registers.AX.R = 0x3B00;
  34.     Registers.DX.R = (int)name;
  35.     Registers.DS.R = getds();
  36.     calldos();
  37.     if ( name[1] == ':' ) {
  38.     Registers.AX.R = 0x0E00;
  39.     Registers.DX.R = (*name & 0xDF) - 'A';
  40.     calldos();
  41.     }
  42. }
  43. int    retdir(char *name)
  44. {
  45.     Registers.AX.R = 0x4700;
  46.     Registers.DX.R = 0x0000;
  47.     Registers.SI.R = (int)name+3;
  48.     Registers.DS.R = getds();
  49.     calldos();
  50.  
  51.     Registers.AX.R = 0x1900;
  52.     calldos();
  53.  
  54.     *(name++) = 'A' + (Registers.AX.R & 0xFF);
  55.     *(name++) = ':';
  56.     *(name++) = '\\';
  57.     if ( *name != '\0' )
  58.     strcat(name,"\\");
  59.     return (Registers.AX.R & 0xFF);
  60. }
  61. char    *subname(name)
  62. register char   *name;
  63. {
  64.     if ( *name == '.' ) {
  65.     while ( *name != '\0' ) name++;
  66.     return name;
  67.     }
  68.     while ( *name != '\0' ) {
  69.     if ( *(name++) == '.' )
  70.         break;
  71.     }
  72.     return name;
  73. }
  74. int    name_cmp(sp,dp)
  75. char    *sp,*dp;
  76. {
  77.     int     cd;
  78.  
  79.     if ( (cd = strcmp(subname(sp),subname(dp))) != 0 )
  80.     return cd;
  81.     return strcmp(sp,dp);
  82. }
  83. int    size_cmp(sl,dl)
  84. unsigned long *sl,*dl;
  85. {
  86.     if ( *sl == *dl ) return 0;
  87.     if ( *sl > *dl )  return (-1);
  88.     return 1;
  89. }
  90. int     date_cmp(swp,dwp)
  91. WCBUF   *swp,*dwp;
  92. {
  93.     int     cd;
  94.  
  95.     if ( (cd = dwp->date - swp->date) != 0 )
  96.     return cd;
  97.     return (int)(dwp->time - swp->time);
  98. }
  99. int     cmpname(swp,dwp)
  100. WCBUF   *swp,*dwp;
  101. {
  102.     if ( (swp->att & DIR_FLG) != (dwp->att & DIR_FLG) )
  103.     return (swp->att & DIR_FLG ? (-1):1);
  104.     switch(cmp_mode) {
  105.     case 0: return name_cmp(swp->name,dwp->name);
  106.     case 1: return size_cmp(&swp->size,&dwp->size);
  107.     case 2: return date_cmp(swp,dwp);
  108.     }
  109. }
  110. WCBUF   *wc_read(arg,mode)
  111. char    *arg;
  112. int     mode;
  113. {
  114.     static int   opflg=FALSE;
  115.     static struct {
  116.     unsigned char      dd_dmy[22];
  117.     unsigned short int dd_time,dd_date;
  118.     unsigned long      dd_size;
  119.     char               dd_name[13];
  120.     } dma;
  121.     WCBUF    *wp;
  122.  
  123.     if ( opflg == FALSE ) {
  124.         Registers.AX.R = 0x1A00;
  125.         Registers.DX.R = (int)&dma;
  126.         Registers.DS.R = getds();
  127.         calldos(); 
  128.         Registers.AX.R = 0x4E00;
  129.         Registers.CX.R = mode;
  130.         Registers.DX.R = (int)arg;
  131.         Registers.DS.R = getds();
  132.         opflg = TRUE;
  133.     } else
  134.         Registers.AX.R = 0x4F00;
  135.  
  136.     calldos();
  137.     if ( (Registers.Flags & 0x0001) != 0 ) {
  138.         opflg = FALSE;
  139.     return NULL;
  140.     }
  141.     if ( (wp = (WCBUF *)malloc(sizeof(WCBUF))) != NULL ) {
  142.     wp->next = NULL;
  143.     wp->att = dma.dd_dmy[21];
  144.     wp->date = dma.dd_date;
  145.     wp->time = dma.dd_time;
  146.     wp->size = dma.dd_size;
  147.     strcpy(wp->name,dma.dd_name);
  148.     }
  149.     return wp;
  150. }
  151. WCBUF   *wc_sort(sp,dp)
  152. WCBUF   *sp,*dp;
  153. {
  154.     if ( sp == NULL )
  155.     return dp;
  156.     if ( cmpname(sp,dp) >= 0 ) {
  157.     dp->next = sp;
  158.     return dp;
  159.     }
  160.     sp->next = wc_sort(sp->next,dp);
  161.     return sp;
  162. }
  163. void    wc_del(wp)
  164. WCBUF   *wp;
  165. {
  166.     if ( wp->next != NULL )
  167.     wc_del(wp->next);
  168.     free(wp);
  169. }
  170. int     wc_open(wild)
  171. char    *wild;
  172. {
  173.     int     max;
  174.     WCBUF   *wp;
  175.  
  176.     if ( topwp != NULL )
  177.     wc_del(topwp);
  178.     topwp = NULL;
  179.  
  180.     for ( max = 0 ; (wp = wc_read("*.*",DIR_FLG)) != NULL ; ) {
  181.     if ( (wp->att & DIR_FLG) != 0 ) {
  182.         topwp = wc_sort(topwp,wp);
  183.         max++;
  184.     } else
  185.         free(wp);
  186.     }
  187.     for ( ; (wp = wc_read(wild,0x21)) != NULL ; max++ )
  188.     topwp = wc_sort(topwp,wp);
  189.     return max;
  190. }
  191. void    list_file(no,wp,sw)
  192. int     no;
  193. WCBUF   *wp;
  194. int    sw;
  195. {
  196.     char    *p,tmp[20];
  197.  
  198.     strcpy(tmp,wp->name);
  199.     p = subname(tmp);
  200.     if ( *p != '\0' ) {
  201.     *(p-1) = '\0';
  202.     p = subname(wp->name);
  203.     }
  204.     locate(DSP_X+2,DSP_Y+1+no);
  205.     color(sw == FALSE ? STD_COL:(cmp_mode == 0 ? CMP_COL:HIT_COL));
  206.     printf("%-8s %-3s ",tmp,p);
  207.     color(sw == FALSE ? STD_COL:(cmp_mode == 1 ? CMP_COL:HIT_COL));
  208.     if ( wp->att & DIR_FLG )
  209.     printf("<DIR>    ");
  210.     else
  211.     printf("%8ld ",wp->size);
  212.     color(sw == FALSE ? STD_COL:(cmp_mode == 2 ? CMP_COL:HIT_COL));
  213.     printf("%02d-%02d-%02d %02d:%02d",
  214.     80+(wp->date >> 9),
  215.     (wp->date >> 5) & 0x0F,
  216.     wp->date & 0x1F,
  217.     wp->time >> 11,
  218.     (wp->time >> 5) & 0x3F);
  219.     color(STD_COL);
  220. }
  221. char    *sel_file(file)
  222. char    *file;
  223. {
  224.     int     ch,i,x=DSP_X,y=DSP_Y;
  225.     int     top,max,no,no_old;
  226.     WCBUF   *wp,*wpb[22];
  227.     char    *p,tmp[80];
  228.     char    where[80];
  229.  
  230.     if ( *file != '\0' && *(file+1) == ':' ) {
  231.     chdrv(toupper(*file)-'A');
  232.     file += 2;
  233.     }
  234.     strcpy(tmp,file);
  235.     p = tmp;
  236.     while ( *p != '\0' ) p++;
  237.     while ( p > tmp ) {
  238.         if ( *(--p) == '\\' ) {
  239.             *(p++) = '\0';
  240.             break;
  241.     }
  242.     }
  243.     if ( p != tmp ) {
  244.         file = p;
  245.     if ( tmp[0] == '\0' )
  246.         strcpy(tmp,"\\");
  247.         chdir(tmp);
  248.     }
  249.     if ( *file == '\0' )
  250.     file = "*.*";
  251.  
  252.     G_era();
  253.     wind(DSP_X,DSP_Y,38,MAX);
  254. /************************
  255.     locate(DSP_X,DSP_Y);
  256.     repchr(1,0x98); repchr(38,0x95); repchr(1,0x99);
  257.     for ( i = 1 ; i <= MAX ; i++ ) {
  258.     locate(DSP_X,DSP_Y+i);
  259.     repchr(1,0x96); repchr(38,0x20); repchr(1,0x96);
  260.     }
  261.     locate(DSP_X,DSP_Y+MAX+1);
  262.     repchr(1,0x9a); repchr(38,0x95); repchr(1,0x9b);
  263. *************************/
  264. REDIR:
  265.     retdir(where); strcat(where,file);
  266.     locate(1,1); printf("%-34s",where);
  267.  
  268.     if ( (max = wc_open(file)) == 0 ) {
  269.     file = NULL;
  270.     goto ENDOF;
  271.     }
  272.     for ( i = 0,wp = topwp ; i < MAX ; i++ ) {
  273.     wpb[i] = wp;
  274.     if ( wp != NULL ) {
  275.         list_file(i,wp,FALSE);
  276.         wp = wp->next;
  277.     } else {
  278.         locate(DSP_X+2,DSP_Y+1+i);
  279.         repchr(36,0x20);
  280.     }
  281.     }
  282.     top = no = 0; no_old = (-1);
  283.     for ( ; ; ) {
  284.     if ( no < top || no >= (top+MAX) ) {
  285.         while ( no < top || no >= (top+MAX) )
  286.             top += (no < top ? (-MAX):MAX);
  287.         wp = topwp;
  288.         for ( i = 0 ; i < top && wp != NULL ; i++,wp = wp->next );
  289.         for ( i = 0 ; i < MAX ; i++ ) {
  290.         wpb[i] = wp;
  291.         if ( wp != NULL ) {
  292.             list_file(i,wp,FALSE);
  293.             wp = wp->next;
  294.         } else {
  295.             locate(DSP_X+2,DSP_Y+1+i);
  296.             repchr(36,0x20);
  297.         }
  298.         }
  299.         no_old = (-1);
  300.     }
  301.     if ( no != no_old ) {
  302.         if ( no_old >= 0 )
  303.         list_file(no_old-top,wpb[no_old-top],FALSE);
  304.         list_file(no-top,wpb[no-top],TRUE);
  305.         no_old = no;
  306.     }
  307.     ch = get_key();
  308.     if ( ch == '\x0D' ) {
  309.         if ( wpb[no-top]->att & DIR_FLG ) {
  310.         chdir(wpb[no-top]->name);
  311.         goto REDIR;
  312.         }
  313.         file = wpb[no-top]->name;
  314.         break;
  315.     } else if ( ch == '\x1B' ) {
  316.         file = NULL;
  317.         break;
  318.     } else if ( ch == '\x1E' ) {
  319.         if ( --no < 0 )
  320.         no = max-1;
  321.     } else if ( ch == '\x1F' ) {
  322.         if ( ++no >= max )
  323.         no = 0;
  324.     } else if ( ch == ' ' ) {
  325.         if ( ++cmp_mode > 2 )
  326.         cmp_mode = 0;
  327.         goto REDIR;
  328.     }
  329.     }
  330. ENDOF:
  331.     for ( i = 0 ; i <= MAX+1 ; i++ ) {
  332.     locate(DSP_X,DSP_Y+i);
  333.     repchr(40,0x20);
  334.     }
  335.     pp_box(0,0);
  336.     dsp_flg = FALSE;
  337.     return file;
  338. }
  339.