#include <exec/exec.h>
#include <stdio.h>
#include <stdlib.h>

#include "work:romconf/doorheader.h"
char temp[20];
char Path[200];
char *getlanguage(int i,char *s);
void LastCommand(void);
void end(void);
#define pm prompt
#define sm sendmessage
#define pu putuserstring

main(int argc,char *argv[])
{
   char infotext[200];
   char tempfile[200];
   char lang[20];
   register int i;
   int info;
   if(argc!=2)
   {
      printf(".-----------------------------------------------------.\n",1);
      printf("| Ami-Express Enter Version 1.0 Written by ByteMaster |\n");
      printf("|     /X Development Team - The Silent Achievers      |\n");
      printf("`-----------------------------------------------------'\n");
      printf("\n");
      printf(" This is a (XIM) for AmiExpress 2.30+\n");
      printf("\n");
      exit(0);
  }
  Register(argv[1][0]-'0');
  PutInfo(1,DT_ANSICOLOR);
  strcpy(infotext,argv[0]);

  do
  {
    pm("ANSI graphics (Y/n/?)? ",temp,5);
    i=0;
    info=FALSE;
    while(i<strlen(temp))
    {
      switch(temp[i])
      {
        case 'N':
        case 'n': PutInfo(0,DT_ANSICOLOR); break;
        case 'q':
        case 'Q': PutInfo(1,DT_QUICKFLAG); break;
        case '?': if(info==FALSE) { info=TRUE; showgfile(infotext);} break;
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9': strcpy(lang,getlanguage(temp[i],argv[0])); pu(lang,DT_LANGUAGE); break;
        default:
          if(temp[i]>='a' && temp[i]!='q' && temp[i]!='n' && temp[i]!='y' && temp[i]<'z')
          {  sprintf(tempfile,"%s-%c",Path,temp[i]); showgfile(tempfile); }
          else 
           if(temp[i]>='A' && temp[i]!='Q' && temp[i]!='N' && temp[i]!='Y' && temp[i]<'Z')
          { sprintf(tempfile,"%s-%c",argv[0],temp[i]); showgfile(tempfile); }
      }
      i++;
    }
  }while(info);
  ShutDown();
  end();
}
char *getlanguage(int i,char *s)
{
  char temp[200];
  FILE *fi;
  int j;
  strcpy(temp,s); strcat(temp,".cfg");
  fi=fopen(temp,"r");
  if(fi==NULL) return("");
  j=1;
  while(fgets(temp,80,fi)!=NULL)
  {
    if(j==i) { fclose(fi); return(temp); }
    j++;
  }
  fclose(fi);
  return("");
}
void LastCommand(void)
{
  sm("",1);
}
void end(void)
{
  exit(0);
}
