home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / libs / bignum / examples / src / add.c next >
Encoding:
C/C++ Source or Header  |  1997-01-21  |  1.6 KB  |  71 lines

  1. #define __USE_SYSBASE
  2. #include <proto/exec.h>
  3. #include <exec/memory.h>
  4. #include <proto/dos.h>
  5. #include <proto/BigNum.h>
  6. #include <proto/timer.h>
  7. #include <devices/timer.h>
  8. #include <string.h>
  9.  
  10. #define MEM MEMF_FAST|MEMF_CLEAR
  11. #define TEMPLATE "Two Numbers/M"
  12. #define TXT "Two Numbers !\n"
  13. #define WARN "Needs BigNum.library v37 !!\n"
  14.  
  15. void maine(void)
  16. {
  17.  struct DosLibrary *DOSBase;
  18.  struct ExecBase *SysBase;
  19.  struct Library *BigNumBase;
  20.  struct Library *TimerBase;
  21.  struct timerequest *tr;
  22.  struct timeval aa,bb;
  23.  struct RDArgs *rdargs;
  24.  long opts=0;
  25.  PtrBigNum x,y,z;
  26.  
  27.  SysBase=*((struct ExecBase **)4);
  28.  if(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))
  29.  {
  30.   if(BigNumBase=OpenLibrary("BigNum.library",37))
  31.   {
  32.    if(tr=(struct timerequest *)AllocVec(sizeof(struct timerequest),MEM))
  33.    {
  34.     if(!(OpenDevice("timer.device",UNIT_MICROHZ,(struct IORequest *)tr,0)))
  35.     {
  36.      TimerBase=(struct Library *)tr->tr_node.io_Device;
  37.      if(rdargs=ReadArgs(TEMPLATE,&opts,NULL))
  38.      {
  39.       if(opts)
  40.       {
  41.        x=BigNumInit();
  42.        y=BigNumInit();
  43.        z=BigNumInit();
  44.        BigNumStrToBigNum(x,((char **)opts)[0]);
  45.        BigNumStrToBigNum(y,((char **)opts)[1]);
  46.        GetSysTime(&aa);
  47.        BigNumAdd(x,y,z);
  48.        GetSysTime(&bb);
  49.        SubTime(&bb,&aa);
  50.        BigNumPrint(z);
  51.        Printf("\n(%ld.%05ld s)\n\n",bb.tv_secs,bb.tv_micro);
  52.        BigNumFree(3);
  53.       }
  54.       else
  55.        Printf(TXT);
  56.       FreeArgs(rdargs);
  57.      }
  58.      CloseDevice((struct IORequest *)tr);
  59.     }
  60.     else
  61.      PrintFault(IoErr(),NULL);
  62.     FreeVec(tr);
  63.    }  
  64.    CloseLibrary(BigNumBase);
  65.   }
  66.   else
  67.    Printf(WARN);
  68.   CloseLibrary((struct Library *)DOSBase);
  69.  }
  70. }
  71.