#define MAX_IRC_MSG_LEN 512
#include "rxtxbuf.h"

/**** main.c */

extern unsigned int rxbuflen;
extern unsigned int txbuflen;

extern unsigned char err;
extern unsigned char trip;
extern char reconnect_timeout;

/**** these are in txbuf.s: */

/* clears the transmit buffer. */
void txbuf_init(void);
/* append \x01 (CTCP marker) character */
void txbuf_append_01(void);
/* append a space */
void txbuf_append_spc(void);
/* append an arbitrary character */
void txbuf_append_chr(char c);
/* appends a string to the transmit buffer, updates txbuflen. */
void txbuf_append_str(const char *str);
/* clears the transmit buffer, then appends a string to it. */
void txbuf_set_str(const char *str);
/* sends a string. clears transmit buffer first, then clears it again on exit. */
void txbuf_send_str(const char *str);

/****************************/

/* convenience macro */
#define txbuf_append_str2(s1, s2) do { txbuf_append_str(s1); txbuf_append_str(s2); } while(0)

/* as txbuf_set_str(), but multiple strings. */
/* making them macros actually makes the code smaller. */
#define txbuf_set_str2(s1, s2) do { txbuf_set_str(s1); txbuf_append_str(s2); } while(0)
#define txbuf_set_str3(s1, s2, s3) do { txbuf_set_str(s1); txbuf_append_str(s2); txbuf_append_str(s3); } while(0)

/* sends whatever's in the transmit buffer, then clears it. if nothing was
   in the buffer, nothing gets sent. */
void txbuf_send(void);

void print_error(unsigned char err);

/* does exactly what you think */
void fn_disconnect(void);

/**** irc.c */
#define MAX_MSG_ARGS 8
extern char numbuf[10];
extern char *msg_src, *msg_cmd, *msg_dest, *msg_text;
extern char *msg_args[MAX_MSG_ARGS];
extern char msg_argcount;
extern char irc_away;
extern char bell_type;
extern char start_latch;
extern char last_pm_nick[33];
extern char last_chan[33];

/* call this once, right after TCP connection is established. */
void irc_register(void);

/* does all the work. doesn't return until we get disconnected from
   the IRC server (via /quit or error). */
void irc_loop(void);

void print_errnum(void);

void __fastcall__ bell(void); /* see src/bell.s */

void start_keystroke(char c);

/**** cmd.c */
void cmd_command(char *cmd);
void cmd_execute(void);
void cmd_rejoin_chans(void);
void cmd_ctcp_ping(char *nick);
void cmd_send_pm(char *args);
void cmd_ctcp_ping(char *nick);
void cmd_server_ping(void);
unsigned int read_rtclok(void); /* irc.c needs this one so it's not static */

/* see isnum.s */
extern char __fastcall__ isnum(char c);

/* see a2uint.s */
extern unsigned int __fastcall__ a2uint(char *str);

/* nextarg.s */
extern char *nextarg(char *arg);
