/*
 * umsreporttest.c 1.0 (22.1.96) by
 *   chr@quack.westfalen.de
 *
 * This example code shows the report system by the umssupport.library.
 *
 */



# include <stdio.h>
# include <stdlib.h>
# include <string.h>

# include <dos.h>
# include <dos/dos.h>
# include <dos/dosextens.h>
# include <dos/rdargs.h>
# include <exec/libraries.h>
# include <exec/types.h>
# include <exec/memory.h>

# include <clib/exec_protos.h>
# include <clib/dos_protos.h>
# include <proto/ums.h>

//# include <pragmas/umssup_pragma.h>
//# include <proto/umssup_proto.h>
# include <libraries/umssuplib.h>


/* ------------------------------------------------------------------------ */

void OpenIt(void);
void CloseIt(void);


/* Globale Variablen */
struct DosLibrary * DOSBase;
struct Library *UMSBase;
struct Library *UMSSupportBase;
UMSUserAccount account=0L;

// Diese Struktur muß deklariert werden!
struct UMSReport *rpt = NULL;

static char VersionString[] = "$VER: umssupporttest 1.0 (22.1.96)";

void main(void)
  {
  struct RDArgs  *readargs;
  LONG            rargs[3];
  char buffer[256], ToolName[256];


  OpenIt();

  rargs[0] = 0L;
  rargs[1] = 0L;
  rargs[2] = 0L;

  if (!(readargs = ReadArgs("USER/A,PASSWORD/A,TOOLNAME", rargs, NULL))) {
      PrintFault(IoErr(), NULL);
      CloseIt();
      }


  account = UMSLogin((UBYTE *) rargs[0], (UBYTE *) rargs[1]);
  if (account == 0)
    {
    printf("Kann nicht einloggen!\n");
    CloseIt();
      }

   if (rargs[2])
      strcpy(ToolName, (UBYTE *) rargs[2]);
   else
      strcpy(ToolName, "mytool");


  FreeArgs(readargs);

  rpt=UMSSupportInitReport(account, NULL, ToolName, "umsrpttest V0.1");
  if(rpt) {
     if(!UMSSupportWriteReport(rpt, NULL, NULL, "Test-Fehler", "Was für ein Fehler!!")) {
       printf("Fehler beim Report schreiben! (Err:%d --%s--)\n",UMSSupportGetErr(buffer),buffer);
       }
     else {
                             printf("         Tool: %s\n",rpt->ToolName);
                             printf("     DoReport: %d\n",rpt->WriteReport);
                             printf("    ReplyName: %s\n",rpt->ReplyName);
       if(rpt->ReplyAddr)    printf("    ReplyAddr: %s\n",rpt->ReplyAddr);
       if(rpt->ReportGroup)  printf(" report.group: %s\n",rpt->ReportGroup);
       if(rpt->ReportName)   printf("  report.name: %s\n",rpt->ReportName);
       if(rpt->ReportAddr)   printf("  report.addr: %s\n",rpt->ReportAddr);
       if(rpt->ReportFolder) printf("report.folder: %s\n",rpt->ReportFolder);
       UMSSupportFreeReport(rpt);
       }
     }
  else
     printf("Fehler beim Report erzeugen! (Err:%d --%s--)\n",UMSSupportGetErr(buffer),buffer);

  CloseIt();
  }

/* ------------------------------------------------------------------------ */

void OpenIt()
{
    if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
        {
        printf("Ohne OS 2.0 oder höher geschieht hier nix mehr! (Dosbase) \n");
        exit(RETURN_FAIL);
        }
    else if (!(UMSBase = (struct Library *) OpenLibrary("ums.library", 11L)))
        {
        printf("Keine UMS Library V11 gefunden!\n");
        if(DOSBase) CloseLibrary((struct Library *) DOSBase);
        exit(RETURN_FAIL);
        }
    else if (!(UMSSupportBase = (struct Library *) OpenLibrary("umssupport.library",0)))
        {
        printf("Keine UMSSupport Library V0.1 gefunden!\n");
        if(DOSBase) CloseLibrary((struct Library *) DOSBase);
        if(UMSBase) CloseLibrary((struct Library *) UMSBase);
        exit(RETURN_FAIL);
        }

}

/* ------------------------------------------------------------------------ */

void CloseIt()
{
    UMSLogout(account);
    if(DOSBase) CloseLibrary((struct Library *) DOSBase);
    if(UMSBase) CloseLibrary((struct Library *) UMSBase);
    if(UMSSupportBase) CloseLibrary((struct Library *) UMSSupportBase);
    exit(0L);
}

/* ------------------------------------------------------------------------ */
