/*
 * readargs.c
 *
 * Author: Tomi Ollila <too@cs.hut.fi>
 *
 * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
 *                    All rights reserved.
 *
 * Created: Fri Sep 24 15:10:32 1993 too
 * Last modified: Sat Oct 16 16:57:31 1993 too
 *
 * $Id: readargs.c,v 1.1 1993/10/24 12:50:39 too Exp $
 *
 * HISTORY
 * $Log: readargs.c,v $
 * Revision 1.1  1993/10/24  12:50:39  too
 * Initial revision
 *
 * Revision 1.1  1993/10/24  12:50:39  too
 * Initial revision
 *
 */

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

#if __GNUC__
#include "inl_exec.h"
#include "inl_dos.h"
#elif __SASC
#include <proto/exec.h>
#include <proto/dos.h>
#else
#error compiler not currently supported.
#endif

#include "readargs.h"

extern struct ExecBase *	SysBase;
extern struct DosLibrary *	DOSBase;

struct readargs * readargs(char * template, int itemcount,
			   char *buffer, int buffersize)
{
  struct readargs * readargs;
  LONG memsize;

  memsize = sizeof *readargs + itemcount * sizeof (LONG);
  readargs = AllocMem(memsize, MEMF_PUBLIC|MEMF_CLEAR);

  if (readargs == NULL)
    return NULL;

  readargs->ra_Private.RDA_Source.CS_Buffer = buffer;
  readargs->ra_Private.RDA_Source.CS_Length = buffersize;
  readargs->ra_Private2 = memsize;
  
  if (ReadArgs(template, readargs->ra_Args, &readargs->ra_Private) == NULL) {
    FreeMem(readargs, memsize);
    return NULL;
  }
  return readargs;
}

void freeargs(struct readargs * rargs)
{
  FreeArgs(&rargs->ra_Private);
  FreeMem(rargs, rargs->ra_Private2);
}
