#include "starappl.h"
#include "gui/window.h"
#include "starmenu.h"
#include "struc/starpasr.h"
#include <stdarg.h>

id starParser;

@implementation WDCSTARApplication

#define numOfDics 3

- initWithName:(char*)aName,...{
  va_list alist;
  int n, i; 
  char** argvptr;
  char* dirNamePtr;
  char dicName[80];
  char* dictionaryNames[numOfDics]={"ddl1.1", "CIFcore.dic", "cifdic.m94" };
  va_start(alist, aName);
  n=va_arg(alist, int);
  argvptr=va_arg(alist, char**);
  va_end(alist);
  printf("Launch %s please wait.\n", argvptr[0]); 
  [super initWithName:aName, n, argvptr];
  _mainWindow=[[WDCWindow alloc] initWithName:"Main Window" managedBy: self];
  [[self setArg:"width" to:(char*)600] setArg:"height" to:(char*)400];
  _mainMenu=[[WDCSTARMainMenu alloc] 
	     initWithName : "Main Menu" managedBy : _mainWindow];
  [self setSTARParser:[WDCStarParser alloc]];
  if (n>1) {
    dirNamePtr=argvptr[1];
  }
  else
    dirNamePtr="/pb2/weider/cif/ciflib/bin/dic/";
  for (i=0; i<numOfDics; i++){
    strcpy(dicName, dirNamePtr);
    if (dirNamePtr[strlen(dirNamePtr)-1]!='/') strcat(dicName, "/");
    strcat(dicName, dictionaryNames[i]);
    printf("Reading dictionary %s please wait.\n", dicName);
    [[self getSTARParser] parseDictionary: dicName];
  }
  printf("%s is ready now.\n", argvptr[0]);
  return self;
}

- setSTARParser:aParser
{
  starParser=_starParser=aParser;
  return self;
}

- getSTARParser
{
  return _starParser;
}

- getMainWindow
{
  return _mainWindow;
}

- getMainMenu
{
  return _mainMenu;
}

@end
