home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d763 / infoq.lha / InfoQ / InfoQ.c < prev    next >
C/C++ Source or Header  |  1992-11-21  |  6KB  |  208 lines

  1. /*****************************************************************************\
  2.  * InfoQ.c                       DICE/LATTICE C/SAS C/AZTEC C + AmigaOS 2.04 *
  3.  *                 _                                                         *
  4.  *            _   // (c)1992 by "Quarky" Dieter Temme                        *
  5.  *            \\ //                                                          *
  6.  * :ts=4       \X/ --- Freeware --- ONLY AMIGA MAKES IT POSSIBLE             *
  7.  *                                                                           *
  8.  * replaces the Shell's standard Info command                                *
  9. \*****************************************************************************/
  10.  
  11. #define PRGNAME "InfoQ"
  12. #define VERSION "1.0"
  13. #define PRGDATE "24.9.92"
  14.  
  15. #include "amigacompq.h"
  16.  
  17. #include <string.h>
  18. #include <exec/types.h>
  19. #include <clib/dos_protos.h>
  20. #include <clib/exec_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <dos/datetime.h>
  23. #include <dos/dos.h>
  24. #include <dos/dosextens.h>
  25. #include <exec/libraries.h>
  26.  
  27. #ifdef PRAGMAS_
  28.  #include <pragmas/dos_lib.h>
  29.  #include <pragmas/exec_lib.h>
  30.  #include <pragmas/utility_lib.h>
  31. #endif
  32.  
  33. #ifdef LATTICE
  34.  int CXBRK(void) { return 0; }  /* Disable Lattice CTRL-C handling */
  35.  int chkabort(void) { return 0; }
  36. #endif
  37.  
  38. #ifdef AZTEC_C
  39.  void _wb_parse(void) {    extern long Enable_Abort; Enable_Abort= FALSE; }
  40.  void _cli_parse(void) { extern long _argc; _argc= 1; }
  41.  void _abort(void) {} /* Disable Aztec CTRL-C handling */
  42. #endif
  43.  
  44. TEXT VersionString[]= "\0$VER: " PRGNAME " " VERSION " (" PRGDATE ")";
  45.  
  46. extern struct Library *SysBase;
  47. struct Library *UtilityBase;
  48.  
  49.  
  50. /*==== print number formatted in KBytes or MBytes ====*/
  51. void PrintNum_(ULONG num)
  52. {    ULONG n;
  53.  
  54.     if (num>>10)
  55.     {    n= ((num*100)>>10)%100;
  56.         n= '0'+n/10+((n%10) >= 5);
  57.         Printf(" %4ld.%lcM", num>>10, n);
  58.     } else
  59.         Printf(" %6ldK", num);
  60. }
  61.  
  62. /*==== main program (Shell) ====*/
  63. int main(int argc, TEXT *argv[])
  64. {    static struct InfoData id;
  65.     static TEXT *argray[3];
  66.     struct DosList *ndl, *dlist;
  67.     struct RDArgs *rdargs;
  68.     BOOL first= TRUE;
  69.     struct Process *proc;
  70.     struct Window *win;
  71.  
  72.     /*- exit if called from Workbench -*/
  73.     if (!argc) return RETURN_FAIL;
  74.  
  75.     /*- exit if version of OS is not >= 2.04 -*/
  76.     if (SysBase->lib_Version < 37)
  77.     {    Write(Output(), "Sorry, you'll need at least AmigaOS 2.04!\n", 42);
  78.         return RETURN_FAIL;
  79.     }
  80.  
  81.     /*- open utility.library -*/
  82.     if (!(UtilityBase= OpenLibrary("utility.library", 37)))
  83.     {    PutStr("Couldn't open 'utility.library'\n");
  84.         return RETURN_FAIL;
  85.     }
  86.  
  87.     /*- read arguments -*/
  88.     rdargs= ReadArgs("DISKS/S,VOLS=VOLUMES/S,DEVICES/M", argray, NULL);
  89.  
  90.     /*- lock list of devices and volumes -*/
  91.     ndl= dlist= LockDosList(LDF_DEVICES|LDF_VOLUMES|LDF_READ);
  92.  
  93.     /*- avoid requesters -*/
  94.     proc= (struct Process *)FindTask(NULL);
  95.     win= proc->pr_WindowPtr;
  96.     proc->pr_WindowPtr= (struct Window *)~0;
  97.  
  98.     /*- show devices -*/
  99.     if (argray[2] || argray[0] || !argray[1])
  100.     {    static char *dstate[]=
  101.         {    "Read Only ",
  102.             "Validating",
  103.             "Read/Write"
  104.         };
  105.         TEXT name[108];
  106.  
  107.         while (ndl= NextDosEntry(ndl, LDF_DEVICES|LDF_READ))
  108.         {    /* continue if no file device */
  109.             if (!ndl->dol_Task) continue;
  110.  
  111.             /* get device name */
  112.             {    TEXT *str= ((TEXT *)BADDR(ndl->dol_Name));
  113.                 CopyMem(str+1, name, *str);
  114.                 name[*str]= ':';
  115.                 name[*str+1]= '\0';
  116.             }
  117.  
  118.             /* if device names given, select device */
  119.             if (argray[2])
  120.             {    TEXT **strarray= (TEXT **)argray[2];
  121.                 while (*strarray && Stricmp(*strarray, name)) strarray++;
  122.                 if (!*strarray) continue;
  123.             }
  124.  
  125.             /* print device information */
  126.             {    BPTR lock;
  127.  
  128.                 /* if first device to print, print title */
  129.                 if (first)
  130.                 {    if (!argray[2]) PutStr("Disks:\n");
  131.                     PutStr("Unit      Size    Used    Free "
  132.                         "Full Errs   Status   Name\n");
  133.                     first= FALSE;
  134.                 }
  135.  
  136.                 /* if not lockable print status */
  137.                 lock= Lock(name, ACCESS_READ);
  138.                 if (!lock)
  139.                 {    TEXT *s;
  140.  
  141.                     switch (IoErr())
  142.                     {    case ERROR_NO_DISK:
  143.                             s= "No disk present";
  144.                             goto print;
  145.                         case ERROR_NOT_A_DOS_DISK:
  146.                             s= "Unreadable disk";
  147. print:                        Printf("%-6s   %s\n", name, s);
  148.                     }
  149.                 } else if (Info(lock, &id))
  150.                 {    ULONG size, used;
  151.  
  152.                     Printf("%-6s", name);
  153.                     size= (id.id_NumBlocks*id.id_BytesPerBlock)>>10;
  154.                     used= (id.id_NumBlocksUsed*id.id_BytesPerBlock)>>10;
  155.                     NameFromLock(lock, name, 108);
  156.                     name[strlen(name)-1]= '\0';
  157.                     PrintNum_(size);
  158.                     PrintNum_(used);
  159.                     PrintNum_(size-used);
  160.                     if (size&0xfe000000) /* for "bigger" disks */
  161.                     {    size>>= 7;
  162.                         used>>= 7;
  163.                     }
  164.                     Printf("%4ld%% %3ld %11s %s\n", 
  165.                         (100*used+size-1)/size, id.id_NumSoftErrors,
  166.                         ((id.id_DiskState >= ID_WRITE_PROTECTED)
  167.                             && (id.id_DiskState <= ID_VALIDATED))?
  168.                             dstate[id.id_DiskState-ID_WRITE_PROTECTED] : "",
  169.                         name);
  170.                     UnLock(lock);
  171.                 }
  172.             }
  173.         }
  174.     }
  175.  
  176.     /*- show volumes -*/
  177.     if (argray[1] || (!argray[2] && !argray[0]))
  178.     {    static struct DateTime dt;
  179.         TEXT ds[LEN_DATSTRING];
  180.         dt.dat_StrDate= ds;
  181.  
  182.         if (!first) PutStr("\n");
  183.         PutStr("Volumes:\n");
  184.         ndl= dlist;
  185.  
  186.         while (ndl= NextDosEntry(ndl, LDF_VOLUMES|LDF_READ))
  187.         {    Printf("%-30s", &((TEXT *)BADDR(ndl->dol_Name))[1]);
  188.             PutStr(ndl->dol_Task? " [Mounted]" : "          ");
  189.             CopyMem(&ndl->dol_misc.dol_volume.dol_VolumeDate, &dt,
  190.                 sizeof(struct DateStamp));
  191.             if (DateToStr(&dt)) Printf(" created %s", ds);
  192.             PutStr("\n");
  193.         }
  194.     }
  195.  
  196.     /*- reset window pointer of our process -*/
  197.     proc->pr_WindowPtr= win;
  198.  
  199.     /*- unlock list of devices and volumes -*/
  200.     UnLockDosList(LDF_DEVICES|LDF_VOLUMES|LDF_READ);
  201.  
  202.     /*- free arguments -*/
  203.     FreeArgs(rdargs);
  204.  
  205.     /*- close library -*/
  206.     CloseLibrary(UtilityBase);
  207. }
  208.