home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / c / avail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.1 KB  |  83 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: avail.c,v 1.7 1997/01/27 00:22:36 ldp Exp $
  4.  
  5.     Desc: Avail CLI command
  6.     Lang: english
  7. */
  8. #include <exec/execbase.h>
  9. #include <exec/memory.h>
  10. #include <proto/exec.h>
  11. #include <dos/dos.h>
  12. #include <proto/dos.h>
  13. #include <utility/tagitem.h>
  14.  
  15. int main (int argc, char ** argv)
  16. {
  17.     IPTR args[4]={ 0, 0, 0, 0 };
  18.     struct RDArgs *rda;
  19.     LONG error=0;
  20.  
  21.     rda=ReadArgs("CHIP/S,FAST/S,TOTAL/S,FLUSH/S",args,NULL);
  22.     if(rda!=NULL)
  23.     {
  24.     ULONG chip[4], fast[4], total[4];
  25.     if(args[0]+args[1]+args[2]>1)
  26.     {
  27.         FPuts(Output(),"Only one of CHIP, FAST or TOTAL allowed\n");
  28.         FreeArgs(rda);
  29.         return RETURN_FAIL;
  30.     }else if(args[0])
  31.     {
  32.         if(args[3])
  33.         FreeVec(AllocVec(~0ul/2,MEMF_CHIP));
  34.         chip[0]=AvailMem(MEMF_CHIP);
  35.         if(VPrintf("%ld\n",chip)<0)
  36.         error=RETURN_ERROR;
  37.     }else if(args[1])
  38.     {
  39.         if(args[3])
  40.         FreeVec(AllocVec(~0ul/2,MEMF_FAST));
  41.         fast[0]=AvailMem(MEMF_FAST);
  42.         if(VPrintf("%ld\n",fast)<0)
  43.         error=RETURN_ERROR;
  44.     }else if(args[2])
  45.     {
  46.         if(args[3])
  47.         FreeVec(AllocVec(~0ul/2,MEMF_ANY));
  48.         total[0]=AvailMem(MEMF_ANY);
  49.         if(VPrintf("%ld\n",total)<0)
  50.         error=RETURN_ERROR;
  51.     }else
  52.     {
  53.         Forbid();
  54.         if(args[3])
  55.         FreeVec(AllocVec(~0ul/2,MEMF_ANY));
  56.         chip[0]=AvailMem(MEMF_CHIP);
  57.         chip[2]=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  58.         chip[3]=AvailMem(MEMF_CHIP|MEMF_LARGEST);
  59.         chip[1]=chip[2]-chip[0];
  60.         fast[0]=AvailMem(MEMF_FAST);
  61.         fast[2]=AvailMem(MEMF_FAST|MEMF_TOTAL);
  62.         fast[3]=AvailMem(MEMF_FAST|MEMF_LARGEST);
  63.         fast[1]=fast[2]-fast[0];
  64.         total[0]=AvailMem(MEMF_ANY);
  65.         total[2]=AvailMem(MEMF_ANY|MEMF_TOTAL);
  66.         total[3]=AvailMem(MEMF_ANY|MEMF_LARGEST);
  67.         total[1]=total[2]-total[0];
  68.         Permit();
  69.  
  70.         if(PutStr("Type  Available    In-Use   Maximum   Largest\n")<0||
  71.            VPrintf("chip %10.ld%10.ld%10.ld%10.ld\n",chip)<0||
  72.            VPrintf("fast %10.ld%10.ld%10.ld%10.ld\n",fast)<0||
  73.            VPrintf("total%10.ld%10.ld%10.ld%10.ld\n",total)<0)
  74.         error=RETURN_ERROR;
  75.     }
  76.     FreeArgs(rda);
  77.     }else
  78.     error=RETURN_FAIL;
  79.     if(error)
  80.     PrintFault(IoErr(),"Avail");
  81.     return error;
  82. }
  83.