;/*
sc resopt link optimize debug=line idir=include: nostartup nostackcheck opt data=far wbver.c
quit
*/

/*
** Example code on how to get Workbench version and revision
**
** Written by Harry "Piru" Sintonen <sintonen@iki.fi>
** Public Domain.
**
*/

#include <exec/types.h>
#include <exec/libraries.h>
#include <exec/resident.h>
#include <exec/execbase.h>
#include <dos/dosextens.h>

#include <proto/exec.h>
#include <proto/dos.h>

int main(void)
{
  int ret = RETURN_FAIL;
  struct ExecBase *SysBase;
  struct DosLibrary *DOSBase;

  SysBase = *((struct ExecBase **) 4);

  DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37);
  if (DOSBase)
  {
    struct Library *VersionBase;

    VersionBase = OpenLibrary("version.library", 0);
    if (VersionBase)
    {
      UWORD ver, rev;

      ver = VersionBase->lib_Version;
      rev = VersionBase->lib_Revision;
      CloseLibrary(VersionBase);

      Printf("Workbench %lu.%lu\n", ver, rev);

      ret = RETURN_OK;
    }
    else
    {
      PutStr("Could not open version.library!\n");

      ret = RETURN_ERROR;
    }

    CloseLibrary((struct Library *) DOSBase);
  }

  return ret;
}