#include <exec/types.h>
#include <exec/exec.h>
#include <stdio.h>
#include <stdlib.h>
#include "work:romconf/doorheader.h"
#include "source:aztec/glue.h"
#define sm sendmessage
#define pm prompt
#define hk hotkey
#define gu getuserstring
void XUpload(void);
void XDownload(void);
void end(void);
void sr(char *str);
void LastCommand(void);
char FileName[200];
int nd;

struct Library *DOSBase=NL;
main(int argc,char *argv[])
{
   char CMD[100];
   Register(argv[1][0]-'0');
   DOSBase=OpenLibrary("dos.library",0L);
   nd=argv[1][0]-'0';
  do
  {
   sm("Please choose from the following:",1);
   sm("1. Upload",1);
   sm("2. Download",1);
   sm("3. Exit",1);
   hk(">:",CMD);
   if(CMD[0]=='1') { sm("1",1); XUpload(); }
   if(CMD[0]=='2') { sm("2",1); XDownload(); }
   if(CMD[0]=='3') { sm("Exit",1); }
   }while(CMD[0]!='3');
   ShutDown();
   end();
}

void end(void)
{
  CloseLibrary(DOSBase);
  exit(0);
}
void XUpload(void)
{
}

void __regargs xprsequence(void);
char *xprimage;
int xprlength;
void XDownload(void)
{
   char ScreenAddress[200];
   char command[200];
   FILE *fi;
   APTR filename;
   gu(ScreenAddress,SCREEN_ADDRESS);
   sm("Enter the complete path for the file you wish to download",1);
   pm(">:",FileName,100);
   strupr(FileName);
   sr(FileName);
   filename=(APTR)&FileName;
 /*  fi=fopen(FileName,"r");*/
   sm("",1);
   /*if(fi==NULL)
   {
     sm("That file does not exist",1);
     return;
    }
   fclose(fi);*/
  
  sprintf(command," -p xprzmodem.library -u 2 -s %s -b %08x s",ScreenAddress,filename);
  sm(command,1);
  xprimage=&command[0];
  xprlength=strlen(command);
  xprsequence();
  // Execute(command,NULL,NULL);
}

void sr(char *str)
{
   register int i;
   i=strlen(str)-1;
   while(i>0)
   {
     if(*(str+i)<=32) *(str+i)='\0'; else break;
     i--;
   }
}
void LastCommand(void)
{
}