home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG005.ARC / DISC.C < prev    next >
Text File  |  1979-12-31  |  6KB  |  156 lines

  1. /*                  DISC MAP                 Dave Nowlan                     
  2. .po0
  3.                         May 85            */
  4. #include "bdscio.h"
  5. #include "wdefines.h"
  6.  
  7. #define CURRENT_DRIVE    25
  8. #define SEARCH_FIRST    17
  9. #define SEARCH_NEXT    18
  10. #define SET_DRIVE    14
  11.  
  12. char    fcb[36];            /* file control block for searches */
  13. char    text[36];            /* to hold the results of sprintf's */
  14. struct    Window    map,headings,fileline,action;    /* set up the windows */
  15. /*---------------------------------------------------------------------------*/
  16. main()
  17. {    char    c;            
  18.     char    orig_drive;        /* current drive when we came in */
  19.     char    *Wgets();        /* Wgets returns the address of chars*/
  20.     int     i,j,n;
  21.     int    x;            /* character to show on the map */
  22.  
  23.     initial();
  24.     orig_drive = bdos(CURRENT_DRIVE);
  25.  
  26. loop:    do {    c=getdrive(orig_drive);        
  27.     }    while (c < 'A' || c > 'P');
  28.     sprintf(text,"%cDrive %c selected %c", Home, c, Clrpage);
  29.     Wputs(fileline,text);
  30.  
  31.     c -= 'A';
  32.     Wputchar(map,Clear);        /* clear the scrren map */
  33.      bdos(SET_DRIVE,c);        /* set to the drive selected by user */
  34.     setfcb(fcb,"*.*");        /* initialise fcb to get all files */
  35.     fcb[0]='?';    fcb[12]='?';    /* for all users and for all extents */
  36.     i = bdos(SEARCH_FIRST,fcb);     /* get first directory entry if any */
  37.     if (i == 255)
  38.     {    Wputchar(fileline,Home);
  39.         Wputs(fileline," No files on drive ");
  40.         Wputchar(fileline,c+'A');
  41.         Wputchar(fileline,Clrpage);
  42.         goto loop;            
  43.     }    
  44.     x='A';                /* set first character for the map */
  45.     while (i != 255)        /* keep going until it runs out */
  46.     {    x = do_an_entry((0x80 + i * 32),x);
  47.         i = bdos(SEARCH_NEXT,fcb);
  48.     }
  49.     sprintf(text,"%cAll files on drive %c displayed%c",Home,c+'A',Clrpage);
  50.     Wputs(fileline,text);
  51.     Wputchar(action,Home);        /* go to origin of the action window */
  52.     Wputs(action,"Press any key to continue");
  53.     Wputchar(action,Clrpage);    /* clear rest of the action window */
  54.     c = Wgetchar(action);        /* wait until any key pressed */
  55.     goto loop;
  56. }
  57. /*---------------------------------------------------------------------------*/
  58. do_an_entry(entry,x)        /* routine to display directory entry */
  59. char    entry[];        /* the directory entry */
  60. int    x;            /* character to be xused on the display */
  61. {    char    c;
  62.     int    i,j,n;
  63.     struct    Window    *wp1,*wp2;    /* pointers to window structures */
  64.  
  65.     wp1=&fileline;            /* point to the fileline window */
  66.     wp2=↦            /* point to the map window */
  67.     wp1->Fore += 1;    
  68.     if ((wp1->Fore) > 7)
  69.         wp1->Fore=1;        /* get colour for next file */
  70.     wp2->Fore=wp1->Fore;
  71.  
  72.     Wputchar(fileline,Home);    /* go to start of fileline */
  73.     sprintf(text," %2x ", entry[0]);        /* user byte */
  74.     Wputs(fileline,text);
  75.     for (i=1; i<9; i++)
  76.         Wputchar(fileline,entry[i]);        /* primary name */è    Wputchar(fileline,'.');
  77.     for (; i<12; i++)
  78.         Wputchar(fileline,entry[i]);        /* secondary name */è    sprintf(text,"%3d", entry[12]);            /* extent number */
  79.     Wputs(fileline,text);
  80.  
  81.     if (entry[0]==0xe5)        /* see if this file is deleted */
  82.     {    Wputs(fileline," D E L E T E D ");
  83.         Wputchar(fileline,Clrpage);
  84.         return(x);
  85.     }    
  86.     for (i=16; i<32; i++)        /* for each of the allocation units */
  87.     {    n=entry[i];
  88.         sprintf(text," %2x",n);    /* print on the fileline */
  89.         Wputs(fileline,text);
  90.         if (n==0)        /* do not show on map if zero */
  91.             continue;
  92.         n *= 8;            /* allocation unit times 8 */
  93.         for (j=0; j<8; j++,n++)
  94.         {    wp2->CursX = (n / 20) + 2;    /* column number */
  95.             wp2->CursY = (n % 20);        /* row number */
  96.             Wputchar(map,x);
  97.         }
  98.     }
  99.     Wputchar(fileline,Clrpage);
  100.     if (++x == Delete)
  101.         x='!';            /* set next character for display */
  102.     else if (x==96)
  103.         x++;
  104.     return(x);
  105. }
  106. /*---------------------------------------------------------------------------*/
  107. initial()        /* routine to clear screen and set up the windows */
  108. {    struct    Window    *wp;        /* pointer to a window */
  109.     Winitial(TRUE,TRUE,TRUE,TRUE);    /* Initial call to set up Screen */
  110.      
  111.     wp=↦            /* point to the map window */
  112.     wp->Column=0;    wp->Row=0;    /* map starts at 0,0 */
  113.     wp->Width=80;    wp->Depth=20;    /* and is 20 lines of 80 characters */
  114.     wp->Fore=1;    wp->Back=0;    /* set up as red on black */
  115.  
  116.     wp=&headings;            /* point to the headings windows */
  117.     wp->Column=0;    wp->Row=20;    /* headings start on line 20 */
  118.     wp->Width=80;    wp->Depth=3;    /* and go for 3 lines */
  119.     wp->Fore=7;    wp->Back=0;    /* and are white on black */
  120.     Wputchar(headings,Home);    /* go to origin of the window */
  121.     Wputs(headings,"          1         2         3         ");
  122.     Wputs(headings,"4         5         6         7         ");
  123.     Wputs(headings,"0123456789012345678901234567890123456789");
  124.     Wputs(headings,"0123456789012345678901234567890123456789");
  125.     Wputchar(headings,Clrpage);    /* and clear the rest of it */
  126.  
  127.     wp=&fileline;            /* point to the file line */
  128.     wp->Column=0;    wp->Row=22;    /* line starts at 23,0 */
  129.     wp->Width=80;    wp->Depth=1;    /* and is 1 line of 80 characters */
  130.     wp->Fore=1;    wp->Back=0;    /* set up red on black */
  131.     Wputchar(fileline,Clear);    /* clear the window */
  132.  
  133.     wp=&action;            /* point to the file line */
  134.     wp->Column=0;    wp->Row=23;    /* line starts at 24,0 */
  135.     wp->Width=80;    wp->Depth=1;    /* and is 1 line of 80 characters */
  136.     wp->Fore=7;    wp->Back=0;    /* set up white on black */
  137.     Wputchar(action,Clear);        /* clear the window */
  138.     return;
  139. }
  140. /*---------------------------------------------------------------------------*/
  141. getdrive(orig_drive)            /* routine to get drive to map */
  142. char    orig_drive;            /* drive when we came in */
  143. {    char    c;    
  144.     Wputchar(action,Clear);        /* clear the window */
  145.     Wputs(action,"Which drive (A B C D)? or RETURN to exit ");
  146.     c = Wgetchar();            /* get the character */
  147.     if (c==10 || c==13)        /* if return reset drive and exit */
  148.     {    bdos(SET_DRIVE,orig_drive);
  149.         exit();            
  150.     }
  151.     return(toupper(c));        /* return the drive */
  152. }
  153. /*---------------------------------------------------------------------------*/
  154. /* the window routines must be included somewhere OUTSIDE a function */
  155. #include "windows.c"
  156.