/* Program: GetAvailMem [CHIP|FAST|ALL]
   Desc: Program that gets available memory and returns the
   result in a global env. variable.
   Author: P Hutchison 3/12/93
   Modifications:
   1. Use Proto headers (25/6/95)
   2. Use PutStr() instead of printf() and improve prototyping (28/9/95)
*/

#include <proto/exec.h>
#include <proto/dos.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <dos/dos.h>
#include <dos/var.h>
#include <string.h>

main(int argc, char *argv[])
{
   struct DOSBase *DOSBase;
   ULONG avail;
   UBYTE name[7];
   UBYTE buf[10];
   
   strcpy(name, "Memory");
   buf[0] = (char)NULL;
   
   if (DOSBase = (struct DOSBase *)OpenLibrary("dos.library",36L))
   {
    avail = 0;  
    if (argc > 1) /* NB: Command name counts as 1 also! */
    {
      if (stricmp(argv[1], "CHIP") == 0)     /* Get amount of memory */
            avail = AvailMem(MEMF_CHIP);
      if (stricmp(argv[1], "FAST") == 0) 
            avail = AvailMem(MEMF_FAST);
      if (stricmp(argv[1], "ALL") == 0) 
            avail = AvailMem(MEMF_ANY);
   
      stcl_d(buf, avail);                /* Convert value to ASCII */

      SetVar(name, buf, -1, GVF_GLOBAL_ONLY); /* Set env. variable */
    } else
      PutStr("Format: GetAvailMem [CHIP|FAST|ALL]\n"); 
    CloseLibrary((struct Library *)DOSBase);
   }
}
      
