#if !defined(__alffnspt_h) // Sentry, use file only if it's not already included.
#define __alffnspt_h
/*  Project Tec3270

	 SUBSYSTEM:    Tec3270.exe (Tec3270 application)
	 FILE:         alffnspt.h
	 AUTHOR:       Alcindo Ferreira Filho

	 OVERVIEW:

    ALFFScript Class Definition, the Tec3270 Script
    (Script File For Connections) class.

    COPYRIGHT:    © 1998-2007
                  Alcindo Ferreira Filho
                  <alcindo@inttec.com.br>

    LICENSE:      Tec3270_License (docs/Tec3270_License.txt)
*/
#include <owl\window.h>
#include <owl\opensave.h>

//{{ALFFScript}}
/* Open Script File and ProcessScript Methods Return Codes */
#define OPERATIONOK     	 0
#define CONNECTOK           1
#define MUSTSENDDATA        2
#define NOFILENAME     		-10
#define INVALIDOPEN    		-11
#define CANCELOPEN     		-12
#define SUCCESSFULOPEN 		-13
#define FILENOTOPENED  		-14
#define ENDOFFILE      		-15
#define INVALIDSCRIPTTAG	-16
#define INVALIDSCRIPTFILE 	-17
#define INVALIDPARM        -18
#define LOOKFORNOTFOUND    -19

/* Carriage Return (CR) and Line Feed (LF) ASCII Codes */
#define LF        0x0A
#define CR        0x0D

/* Maximum Script File Record Length */
#define MAXTEXTSIZE    256

/* Buffer Pointer status */
#define BUFFEREMPTY    -1

/* Script File PARSING defines */
#define COMMAND         1
#define PARM            2

/* Script File Command IDs */
#define IF              0
#define CONNECT		   1
#define CONNECT_TEC3270 11
#define CONNECTPORT     12
#define TERMINAL        13
#define TITLE           14
#define PORT            15
#define GOTOLABEL       2
#define MOVECURSOR      21
#define TYPE            3
#define KEY             4
#define PASSWORD        5
#define LOOKFOR         6
#define LOOKLIST        7
#define LABEL           8
#define PROMPT          9
#define MESSAGE         91
#define EXIT            99

#define SCPTPARMSIZE    4
struct ScriptCommand
{
 int commandId;
 string parm[SCPTPARMSIZE];
};


class
ALFFScript : public ifstream
{
	public:
	 ALFFScript(TWindow* pParent);

	 virtual ~ALFFScript();
    char far* GetClassName() {return "ALFFScript";}
	 /* Get Log File Name  ......  */
	 char* GetFileName();

	 /* Open Script Data File and PreCompile it */
	 int Open(const char* scriptFileName);

    /* Get Script File Status: Opened or Not Opened */
    bool IsOpened() {return fileOpened;}

	 /* Get Script Line Text as it is passed */
	 int GetNextCommand(ScriptCommand* command);

    /* Get Command Description from command ID */
    string GetCommandDescription(ScriptCommand* comando);

	 /* Close the File */
	 void Close();


    /* Define Script File States */

    enum ScriptState {BEFORECONNECT, AFTERCONNECT};


    /* Set Script File State */

    void SetState(ScriptState state) {estado = state;}


    /* Get Script File State */

    ScriptState GetState() {return estado;}


    /* Get Keyboard Function Key code from KEY command */

    int GetKeyCommand(char* key);


    /* Set Next Command Equal Last Command, That Is Repeat it */

    bool SetNextCommandSame();


  protected:
    char* lineBuffer;
    char* lineBufPtr;
    int   bufCount;
    bool  fileOpened;
    bool  endOfFile;
    bool  firstRead;
    bool  nextCommandSame;
    int   maxSameCommand;
    ScriptState  estado;
    ScriptCommand lastCommand;
	 TWindow* scriptParent;

	 char* FileName;

	 TOpenSaveDialog::TData fileData;

	 void TidyFileName();
    int GetToken(string* tokenStr, char** buffer, int* length, int type);
};
//{{ALFFScript}}
#endif
