#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include <string.h>
#include <exec/types.h>
#include <sys/commwben.h>

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

#include <dos/dos.h>
#include <proto/dos.h>
#include <clib/icon_protos.h>

///» "Program-History"
/*
** Programm-History:
**
** 1.0: initial release
**
*/
///«

///» "global variables"
char *version_information="\0$VER: EnhanceDefaultTool 1.00 by PATZ (25.01.96)";
///«

/* procedures */
///» "main"
int main(int argc,char *argv[])
{
char cmdline[257];
char tmp[257];
char *ps;

struct DiskObject  *pDiskObject;
char              **pcToolArray;
char               *ToolType;

  if(argc==0) {
    pDiskObject = (struct DiskObject *)GetDiskObject(_WBArgv[_WBArgc-1]);

    pcToolArray = pDiskObject->do_ToolTypes;

    ToolType = FindToolType(pcToolArray,"DEFTOOL");

    if(ToolType!=NULL) {
      strcpy(cmdline,ToolType);
    }
    else {
      DisplayBeep();
      exit(30);
    }

    FreeDiskObject(pDiskObject);

//    printf("cmdline: '%s'\n",cmdline);

    ps=strstr(cmdline,"%s");

//    printf("ps: '%s'\n",ps==NULL?"-":ps);

    if(ps==NULL) {
      strcat(cmdline," ");
      strcat(cmdline,_WBArgv[_WBArgc-1]);
    }
    else {
      strcpy(tmp,ps+2);
      ps[0]=0;
      strcat(ps,_WBArgv[_WBArgc-1]);
      strcat(cmdline,tmp);
    }

//    printf("cmdline: '%s'\n",cmdline);
    Execute(cmdline,NULL,NULL);
  }
  else {
    printf("This is a WB only prog!\n");
    exit(20);
  }
  exit(0);
}
///«


