/* zcall.h */

#include <stdio.h>
#include <string.h>
#include <exec/types.h>
#include <exec/errors.h>
#include <libraries/locale.h>
#include <devices/serial.h>
#include <dos/dos.h>
#include <dos.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/timer.h>
#include <proto/utility.h>
#include <proto/locale.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/timer_pragmas.h>
#include <pragmas/locale_pragmas.h>
#include <clib/alib_protos.h>

#define GETSTR(strnum) ((cat) ? GetCatalogStr(cat,strnum,uc_strings[strnum]) : uc_strings[strnum])
#define BUFFER_SIZE         512
#define BUFFER_SIZE_S       64
#define BUFFER_SIZE_SCR     64
#define BUFFER_SIZE_PATTERN 64
#define MAX_BREAKCHARS  16

#define ZC_VERSION "$VER: UCall V 1.9 (" __DATE__ " " __TIME__ ")"
#define UCALL_CONFIG "ucall-config"
#define BREAK_TIME    500000
#define ADDITIONAL_FLAGS 0

#define RETURN_ABBRUCH 10
#define CLEANUP_RESTART -1

#define P_NOVALID    0
#define P_DEVICE     1
#define P_UNIT       2
#define P_BAUD       3
#define P_INIT       4
#define P_BUSY       5
#define P_NOCARRIER  6
#define P_NODIALTONE 7
#define P_DELAYED    8
#define P_ERROR      9
#define P_CONNECT    10
#define P_XPRLIB     11
#define P_XPROPT     12
#define P_DATABITS   13
#define P_PARITY     14
#define P_STOPBITS   15
#define P_RTS        16
#define P_XON        17
#define P_BUFFER     18
#define P_OK         19


#define C_CRLF       1
#define C_WCONNECT   2
#define C_MSG        3
#define C_WAIT       4  
#define C_SEND       5      
#define C_COMMENT    6
#define C_SENDFILE   7
#define C_GETFILE    8
#define C_SHLOG      9
#define C_TIMEOUT   10
#define C_REPEAT    11
#define C_SYSTEM    12
#define C_WORKDIR   13
#define C_GOTO      14
#define C_LABEL     15
#define C_IF        16
#define C_END       17
#define C_GOSUB     18
#define C_RETURN    19
#define C_TIMELABEL 20
#define C_SETFLAG   21
#define C_CLEARFLAG 22
#define C_IFFLAG    23
#define C_PROTOCOL  24
#define C_PROTMSG   25
#define C_SET       26
#define C_RESETLINE 27
#define C_LBSIZE    28
#define C_DELAY     29
#define C_SETENV    30
#define C_GETENV    31
#define C_IFVAR     32
#define C_TEXTFILE  33

#define V_OK         1
#define V_ERROR      2
#define V_CONNECT    3
#define V_NOCARRIER  4
#define V_NODIALTONE 5
#define V_DEVICE     6
#define V_DELAYED    7
#define V_XPRLIB     8
#define V_XPROPTS    9
#define V_BUSY      10
#define V_BUFFER    11
#define V_BAUD      12
#define V_UNIT      13
#define V_DATABITS  14
#define V_STOPBITS  15
#define V_PARITY    16
#define V_LINE      17
#define V_DATE      18
#define V_CONFIG    19
#define V_SCRIPT    20
#define V_FILEINFO  21
#define V_TIME      22
#define V_HANDSHAKE 23
#define V_FILENAME  24
#define V_FILESIZE  25
#define V_LBSIZE    26

#define FLAG_UPLOAD     0
#define FLAG_DOWNLOAD   1
#define FLAG_TIMEOUT    2

#define LABEL_STRING "LABEL"
#define LABELINTRO  "!##"

/****************************************************************/
/*                                                              */
/*  Metaxpr-Kruscht .....Tnx to Snoopy ;)                       */
/*                                                              */
/****************************************************************/

long  TransferSetupShared(struct IOExtSer *read, struct IOExtSer *write,UBYTE *lib);
long  ReceiveFile(UBYTE *name, long wd, struct Screen *screen);
long  SendFile(UBYTE *name, long wd, struct Screen *screen);
long  SetOptions(UBYTE *opts);

#pragma libcall metaxprbase TransferSetupShared 3c a9803
#pragma libcall metaxprbase SetOptions          36 801
#pragma libcall metaxprbase SendFile            2a 90803
#pragma libcall metaxprbase ReceiveFile         24 90803


struct params
       {
        UBYTE *text;
        ULONG  n;
       };

struct c_node
       {
        struct Node   node;
        UBYTE         cmd[BUFFER_SIZE_S];
        UBYTE         sub[BUFFER_SIZE_S];
       };
       
struct r_node
       {
        struct Node    node;
        struct Node    *ziel;
       };

struct var_node
       {
        struct Node    node;
        UBYTE         *text;
       };
                     
struct user_param
       {
        UBYTE cfgfile   [BUFFER_SIZE];
        UBYTE script    [BUFFER_SIZE];
        UBYTE connect   [BUFFER_SIZE_S];
        UBYTE device    [BUFFER_SIZE_S];
        UBYTE nocarrier [BUFFER_SIZE_S];
        UBYTE busy      [BUFFER_SIZE_S];
        UBYTE nodialtone[BUFFER_SIZE_S];
        UBYTE delayed   [BUFFER_SIZE_S];
        UBYTE error     [BUFFER_SIZE_S];
        UBYTE ok        [BUFFER_SIZE_S];
        UBYTE xprlib    [BUFFER_SIZE_S];
        UBYTE xpropt    [BUFFER_SIZE_S];
        UBYTE data;
        UBYTE parity;
        UBYTE stop;
        UBYTE handshake;
        ULONG unit;
        ULONG baud; 
        ULONG bufsize;
        ULONG lbsize;
       };
       
void __stdargs main(int argc, char *argv[]);
int __regargs IsZcConf(UBYTE *buffer);
int ser_setup(void);
void __regargs ser_cleanup(ULONG rc);
int __regargs SerRead(struct IOExtSer *ioreq, BYTE *data, ULONG length);
int __regargs SerWrite(struct IOExtSer *ioreq, BYTE *data, ULONG length);
int makecall(void);
UBYTE __regargs *skipeol(UBYTE *buffer);
int opentimerdevice(void);
void closetimerdevice(void);
int __regargs readconfig(UBYTE *filename);
ULONG __regargs checkline(UBYTE *buffer);
void __regargs parseline(UBYTE *buffer,ULONG what);
int  __regargs IsZcConf(UBYTE *buffer);
int __regargs read_line(UBYTE *buffer,UBYTE *chrs,UBYTE n);
int __regargs readscript(UBYTE *filename);
void __regargs parsecomm(UBYTE *cmd);
void __regargs waitstring(UBYTE *string);
void __regargs makestring(UBYTE *dest,UBYTE *source);
void __regargs timeout_start(ULONG sec);
void timeout_end(void);
void __regargs timerdelay(ULONG sec);
void var_x(UBYTE **dest,UBYTE **source,ULONG what);
void freebuffers(void);
int getbuffers(void);
void multiple_if(UBYTE *line);
int check_sigs(ULONG signals);
void getlocale(void);
void releaselocale(void);
void __asm __saveds locale_date_func(register __a1 UBYTE chr);
void maketime(UBYTE *to);

