/*
    LaunchWPL.c
    Based upon launch.c and loadscript.c, this program combines the
    functions of both for single script WPL programs.
    Modification by Robert Williamson 13/04/94

    Launch.c and LoadScript.c 
    Copyright (C) 1988,1989,1991 Michael Richardson
    Copyright (C) 1992 Russell McOrmond

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
*/

#include <exec/types.h>
#include <exec/libraries.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <proto/exec.h>

#include "wpl_pragmas.h"
#include "wpl.h"
struct Library *WPLBase;

void main(int argc,char *argv[])
{
  long ret;
  printf("\n WPL Mailer Launcher v1.02 by Robert Williamson\n");
  if (argc!=3 && argc!=7) {
    printf("\n USAGE: %s <scriptname> <full path to file> <portname> <script!label> <priority> <stack>",argv[0]);
    printf("\n        or <scriptname> to flush wpl program\n");
    exit(999);
  }
  if(!(WPLBase=OpenLibrary("wpl.library",0l))) {
    printf("Failed to open wpl.library\n");
    exit(666);
  }
  if(wpi_loadscript(argv[1],argv[2])) {
    printf(" %s OK\n",argv[1]);
    if(argv[2]!="") {
      ret=wpi_launch(argv[3],argv[4],atoi(argv[5]),atoi(argv[6]));
      printf(" Launch %s returned: %ld\n",argv[4],ret);
    }
  } else {
    printf(" %s ERROR\n",argv[1]);
    ret=5;
  } 	
  CloseLibrary(WPLBase);
  exit(ret);
}

