/* script.h	-
   distributed as part of sula - an irc client for X

    (c) Tano Fotang 1998

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License , or
    (at your option) any later version.

    see the file COPYING for further information.

*/

#ifndef __script_h_
#define __script_h_


#define SCRIPT_ARGC	64 	/* max number of arguments when starting script*/
#define SCRIPT_RD_BUF	4096	/* max buffer size for reading from scripts*/
/*status*/
#define	SCR_STOPPED	( 1<<0 )	/* SIGSTOP */
#define SCR_SUSPENDED	( 1<<1 )	/* we suspended it*/
#define SCR_SLEEPING	( 1<<2 )	/* it doesnt want any more for now */
#define SCR_RESET	(~(SCR_SLEEPING|SCR_SUSPENDED|SCR_STOPPED))

#define IN_HOOK		(1<<0)
#define EXT_HOOK	(1<<1)	
typedef struct TspCmd{
	char *name;
	struct TspCmd	*next;
}spCmd;
typedef struct TS_Pipe{ 	
	int	fd;		/* */
	int	pid;		/* pid of child*/
	char	*sys_cmd;	/* program name */
	spCmd	*cmd;		/*cmds defined by script, NULL terminated*/
	int	status;		/*process stopped..; still unable to catch SIGCONT*/
} S_Pipe;
S_Pipe	*s_pipe;
int	sp_count;
#define SP_ALLOCATE	5		/* # of script buffers to allocate in a go*/
extern void list_hooks(int flag);
extern void script_start(const char *);
extern void event_setup(void);
extern void do_script(void); /* set up GUI */
/* Events */
typedef enum msgnr {
ACTION=0, CHATMSG,CLIENTINFO,CTCP_ALL,CTCP_HELP,CTCP_PING,CTCP_REPLY,
CTCP_TIME, CTCP_UNKNOWN,DCC_CHAT_REQUEST,DCC_GET_DONE,DCC_SEND_DONE,
DCC_SEND_REQUEST,ERROR,
CTCP_FINGER, INVITE ,JOIN ,JUNK ,KICK ,MODE ,
NICK, NOTE ,PART ,PING,PONG,PRIVMSG ,PRIVNOTICE ,PUBMSG,PUBNOTICE ,
QUIT, SED,SILENCE,TOPIC,USERINFO,VERSION,WALLOPS, INVALID} MsgNr;
extern int check_msg(MsgNr, const char *);
extern int check_numeric(int, const char *);

#define HK_NOISY	(1<<1)	/* only for CMD_IN;curently meaningless*/
#define HK_SUSPENDED	(1<<2) 	/* valid for both; hook suspended */
#define HK_EXCLUSIVE	(1<<3)	/* valid only for CMD_FD: send matches to me alone */
#define HK_RESET	(~(HK_NOISY | HK_SUSPENDED | HK_EXCLUSIVE))
typedef struct TOn{
	int	id;		/* make sense only for CMD_FD */
	char	*pattern;	/* pattern (wildcards) */
	int	ser_number;	/* for CMD_IN no duplicates allowed */
	int	flag;		/* flag!=0 :for CMD_FD: send to me alone and suspended.
				flag= for CMD_IN: SILENT|NOISY and suspend*/
	
	int	type;		/*  CMD_FD, CMD_IN :command defining hook*/
	union	{
		int	sp;
		char	*cmd;/* sula cmd;expand cmd and process */
	} cmd;
	struct TOn *next;
} On;

typedef struct TWant{
	MsgNr	type;		/*  */
	On	*start;
	On	*end;
}Want;

/* this should the number of msg_types, sula_cb.c*/
int MAX_ON;
Want *want; /*[MAX_ON];*/

typedef struct TNumHook{
	int	numeric;
	On	*start;
	On	*end;
	int	bf;
	struct TNumHook	*left;
	struct TNumHook	*right;
} NumHook;
typedef NumHook	*pNumHook;
NumHook	*numTree;
extern NumHook *find_numhook(int);
extern void add_hook(MsgNr,On *);
extern void add_numhook(int , On *);
extern  MsgNr get_type(const char *);/*to be removed*/
extern void *lookup_type(const char *, int *);
extern void do_internal_hook(On *, const char *msg, int);


#endif
