dslinux/user/bitchx/dll/aim Makefile.in README aim.c aim.h bx.patch cmd.c toc.c util.c

stsp stsp at user.in-berlin.de
Sun Jul 2 15:18:32 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/bitchx/dll/aim
In directory antilope:/tmp/cvs-serv9280/dll/aim

Added Files:
	Makefile.in README aim.c aim.h bx.patch cmd.c toc.c util.c 
Log Message:
Adding pristine copy of BitchX so I can branch from it.


--- NEW FILE: README ---
Quite a bit borrowed from the napster module written by panasync. 
libtoc (backened) was written (put together) by me also, and is mostly
composed of code from gaim (see freshmeat).

bx.patch is a small patch to modify bx to allow custom module completion
routines. If not patched, just remove -DBITCHX_PATCH from CFLAGS in the
Makefile

--- NEW FILE: Makefile.in ---
SHELL = @SHELL@

srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
topdir = @topdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = @oldincludedir@

local_dir = $(HOME)

# Where the BitchX binary will be installed.
# "make install" will compile and install the program.
INSTALL_IRC = @INSTALL_IRC@

# Where the BitchX library will be. Generally this is the place that
# you put the scripts, help pages and translation tables. It is
# very important that you set this correctly.
IRCLIB = @IRCLIB@

CC = @CC@
DEFS = @INCLUDES@
LIBS = @LIBS@

# Tcl library.
TCL_LIBS = @TCL_LIBS@

# These are for Tcl support.
TCL_OBJS = @TCL_OBJS@
# You don't have the following, so you'll want to leave this blank.
TCL_SRCS = @TCL_SRCS@

# Set this to -g if you want to be able to debug the client, otherwise
# use -O to have the compiler do some optimization instead.
CFLAGS = @CFLAGS@

# Set this to -s if you want the binary to be stripped.
LDFLAGS = @LDFLAGS@

# These are for the cd device player.
CD_SRCS = @CD_SRCS@
CD_OBJS = @CD_OBJS@

# This is the executable suffix for the target operating system.
EXEEXT = @EXEEXT@

# Extra files.
DEFAULT_CTOOLZ_DIR = @DEFAULT_CTOOLZ_DIR@
DEFAULT_MSGLOGFILE = @DEFAULT_MSGLOGFILE@
DEFAULT_BITCHX_HELP_FILE = @DEFAULT_BITCHX_HELP_FILE@
DEFAULT_SCRIPT_HELP_FILE = @DEFAULT_SCRIPT_HELP_FILE@
DEFAULT_BITCHX_KICK_FILE = @DEFAULT_BITCHX_KICK_FILE@
DEFAULT_BITCHX_QUIT_FILE = @DEFAULT_BITCHX_QUIT_FILE@
DEFAULT_BITCHX_IRCNAME_FILE = @DEFAULT_BITCHX_IRCNAME_FILE@

# Full path of the directory for BitchX help files.
HELPDIR = @HELPDIR@

# Full path of the directory for the BitchX scripts.
INSTALL_SCRIPT = @INSTALL_SCRIPT@

# Default setting for IRCPATH where BitchX will look for
# its script files if the environment variable is undefined.
# Usually, this should contain the same path as used for INSTALL_SCRIPT in
# the Makefile, but it can contain multiple path elements
# separated by colons. The path MUST lead to an existing directory,
# because the 'global' script is expected to be found there.
IRCPATH = @IRCPATH@

# Path for TRANSLATION variable.
TRANSLATION_PATH = @TRANSLATION_PATH@

# This command will be used to install the BitchX help files. If you don't
# want to install them, replace with the following:
# INSTALL_HELP_CMD = @echo The help files have not been installed.
INSTALL_HELP_CMD = @INSTALL_HELP_CMD@

# This is where the optional plugins will be copied to.
PLUGINDIR = @PLUGINDIR@

# Plugin flags.
SHLIB_LD = @SHLIB_LD@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_SUFFIX = @SHLIB_SUFFIX@

# This command will be used to install the BitchX files on Win32/OS2EMX
# systems.
WINNT_INSTALL = @WINNT_INSTALL@

# This program allows you to use screen/xterm's to put new BitchX windows
# on new screen/xterm windows.
INSTALL_WSERV = @INSTALL_WSERV@

# This program allows you to screen BitchX and reattach to it later.
INSTALL_SCRBX = @INSTALL_SCRBX@

# Set gzip and bzip2 options.
GZIP_ENV = @GZIP_ENV@
BZIP2 = @BZIP2@

# Standard programs.
RM = @RM@
LN = @LN_S@
CP = @CP@
MV = @MV@

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

VERSION = @VERSION@
_VERSION_ = @_VERSION_@

MAKE_BIN = @MAKE@
MAKE = $(MAKE_BIN) $(MFLAGS)
MFLAGS = \
	'local_dir=$(HOME)'			\
	'INSTALL_IRC=$(INSTALL_IRC)'		\
	'IRCLIB=$(IRCLIB)'			\
	'CC=$(CC)'				\
	'CFLAGS=$(CFLAGS)'			\
	'HELPDIR=$(HELPDIR)'			\
        'INSTALL_WSERV=$(INSTALL_WSERV)'	\
	'IRCPATH=$(IRCPATH)'			\
	'TRANSLATION_PATH=$(TRANSLATION_PATH)'	\
	'LDFLAGS=$(LDFLAGS)'			\
	'LIBS=$(LIBS)'				\
	'LN=$(LN)'				\
	'RM=$(RM)'				\
	'TCL_SRCS=$(TCL_SRCS)'			\
	'TCL_OBJS=$(TCL_OBJS)'			\
	'CD_PLAY=$(CD_PLAY)'			\
	'CD_SRCS=$(CD_SRCS)'			\
	'CD_OBJS=$(CD_OBJS)'			\
	'TCL_LIBS=$(TCL_LIBS)'			\
	'PLUGINDIR=$(PLUGINDIR)'		\
	'_VERSION_=$(_VERSION_)'		\
	'VERSION=$(VERSION)'			\
	'INSTALL_DATA=$(INSTALL_DATA)'		\
	'INSTALL_SCRIPT=$(INSTALL_SCRIPT)'	\
	'EXEEXT=$(EXEEXT)'			\
	'SHLIB_CFLAGS=$(SHLIB_CFLAGS)'		\
	'SHLIB_SUFFIX=$(SHLIB_SUFFIX)'

## Makefile starts here.

AIMDEFS = $(DEFS) -I$(srcdir)/toc

PLUGIN_NAME = aim

OBJS = toc.o util.o cmd.o aim.o $(topdir)/source/compat.o

all: Makefile toc aim$(SHLIB_SUFFIX)

Makefile: Makefile.in
	cd $(topdir) \
	  && ./config.status

$(topdir)/source/compat.o: $(top_srcdir)/source/compat.c
	$(CC) $(AIMDEFS) $(CFLAGS) \
		-c $(top_srcdir)/source/compat.c -o $(topdir)/source/compat.o

toc.o: $(srcdir)/toc.c
	$(CC) $(AIMDEFS) $(CFLAGS) -c $(srcdir)/toc.c

util.o: $(srcdir)/util.c
	$(CC) $(AIMDEFS) $(CFLAGS) -c $(srcdir)/util.c

cmd.o: $(srcdir)/cmd.c
	$(CC) $(AIMDEFS) $(CFLAGS) -c $(srcdir)/cmd.c

aim.o: $(srcdir)/aim.c
	$(CC) $(AIMDEFS) $(CFLAGS) -c $(srcdir)/aim.c

aim$(SHLIB_SUFFIX): $(OBJS) 
	$(SHLIB_LD) $(OBJS) $(SHLIB_CFLAGS) -o aim$(SHLIB_SUFFIX) -Ltoc -ltoc

dummy:

toc: dummy
	@(cd toc && $(MAKE) all)

clean:
	cd toc && $(MAKE) clean
	$(RM) *~ *.o *.so *.a *.dll *.def .#*

distclean: clean
	cd toc && $(MAKE) distclean
	$(RM) Makefile

install:
	$(INSTALL) $(PLUGIN_NAME)$(SHLIB_SUFFIX) $(PLUGINDIR)

--- NEW FILE: aim.c ---
/*
 * AOL Instant Messanger Module for BitchX 
 *
 * By Nadeem Riaz (nads at bleh.org)
 *
 * aim.c
 *
 * Window, Init, Cleanup, and Version Routines
 */


#include <irc.h>
#include <struct.h>
#include <hook.h>
#include <ircaux.h>
#include <output.h>
#include <lastlog.h>
#include <status.h>
#include <vars.h>
#include <window.h>
#include <input.h>
#include <module.h>
#define INIT_MODULE
#include <modval.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "toc.h"
#include "aim.h"


char *name = "aim";
char *timer_id;

#ifdef BITCHX_PATCH
struct tab_key_struct tks;

int do_aim_tabkey_overwrite(int x, char *p, int *c, char **s) {
	if ( get_dllint_var("aim_window") && current_window == get_window_by_name("AIM") ) 
		return 1;
	else
		return 0;
}

char * get_next_buddy_complete() {
	char *bud = NULL;
	int a;
	LLE t;	
	/* 
	 * This is about as badly written as humany possible 
	 * ^- some would say its even worse than that
	 */
	while ( 1 ) {
		if ( tks.list == 1 ) {
			/* We traverse the buddy list forwards */
			LL mems;
			if ( tks.pos > groups->items ) {
				break;
			}
			t = groups->head;
			for (a=0; a < tks.pos; a++) 
				t = t->next;
			mems = ((struct group *)t->data)->members;			
			if ( tks.subpos == -1 )
				tks.subpos = 1;			
			if ( tks.subpos > mems->items ) {
				tks.pos++;
				continue;
			}
			t = mems->head;
			for (a=0; a<tks.subpos; a++) 
				t = t->next;
			tks.subpos++;
			bud = t->key;
			break;			
		} else {		
			/* Traverse the msd'd them list in reverse (last msg'd = first completed) */	
			t = msgdthem->head;
			tks.list = 0;			
			/* If we haven't msg'd anyone yet, go through the buddy list */
			if ( msgdthem == NULL || msgdthem->items == 0) {
				debug_printf("msgdthem == null or has no items");
				tks.list = 1;
				tks.pos = 1;
				tks.subpos = -1;
				continue;
			}
			/* Initilization */			
			if ( tks.pos == -1 ) {
				debug_printf("set tks.pos to %d",msgdthem->items);
				tks.pos = msgdthem->items;
			}
			for (a=0; a < tks.pos; a++) {
				t = t->next;
			}
			bud = t->key;
			debug_printf("tks.pos == %d name = %s",tks.pos,t->key);
			tks.pos--;
			/* No more msg'd them nicks, next call we switch over to buddy list */
			if ( tks.pos == 0 ) {
				tks.list = 1;
				tks.pos = 1;
				tks.subpos = -1;
			}
			break;
		}	
	}				
	return bud;
}

char * aim_tabkey_overwrite(int x, char *p, int *c, char **s) {
	char *z = NULL;	
	char *bud = NULL;
	char *t;
	(*c) = 0;	
	
	if ( state != STATE_ONLINE )
		return NULL;
	
	bud = get_next_buddy_complete();
		
	if ( bud == NULL )
		return NULL;
	debug_printf("bud = %s",bud);
	t = (char *) malloc(strlen(bud)+50);
	sprintf(t,"/amsg %s  ",bud);
	m_s3cat(&z,space,t);
	(*c) = 1;
	return z;
}

char * amsg_complete_func(int x, char *p, int *c, char **s) {
	/* statusprintf("x = %d",x); */
	char *z = NULL;
	char *inp;
	int wc;
	LLE g,m;
	LL l;	
	(*c) = 0;
	if ( state != STATE_ONLINE )
		return NULL;
	
		
	l = CreateLL();
	
	debug_printf("possible = '%s' len = %d",p,strlen(p));
	inp = m_strdup( get_input() ? get_input() : empty_string);
	wc = word_count(inp);
	debug_printf("input = %s wc = %d",inp,wc);
	new_free(&inp);
	if ( wc > 2 ) 
		return NULL;	
	
	/* First go through people we've msg'd already */
	for ( TLL(msgdus,g) ) {
		if ( p && my_strnicmp(p, g->key, strlen(p)) ) 
			continue;
		AddToLL(l,g->key,NULL);		
	}
	
	/* Then people who msg'd us */	
	for ( TLL(msgdthem,g) ) {
		if ( p && my_strnicmp(p, g->key, strlen(p)) ) 
			continue;
		if ( ! FindInLL(l,g->key) )
			AddToLL(l,g->key,NULL);		
	}	
	
	/* And last, the Buddy */
	for ( TLL(groups,g) ) {
		struct group *grp = (struct group *)g->data;
		for ( TLL(grp->members,m) ) {
			struct buddy *bud = (struct buddy *)m->data;
			if ( p && my_strnicmp(p, bud->name, strlen(p)) ) 
				continue;
			if ( ! FindInLL(l,bud->name) )
				AddToLL(l,bud->name,NULL);
		}
	}
	
	if ( l->items == 1 && ! strcasecmp(l->head->next->key,p) ) {
		char *bud = NULL;
		(*c) = 1;
		bud = get_next_buddy_complete();
		debug_printf("We are going to go to get_next_buddy_comp!");
		if ( bud )
			m_s3cat(&z,space,bud);
		else 
			debug_printf("set z  to null because bud is null");	
	} else {
		for( TLL(l,g) ) {
			(*c)++;
			debug_printf("adding %s",g->key);
			m_s3cat(&z,space,g->key);	
		}
	}

	debug_printf("in test func!, p = %s",p);
	FreeLL(l);
	return (z);
}
#endif /* BITCHX_PATCH */

/* Window code, straight from nap module by panasync */

void update_aim_window(Window *tmp) {
	char statbuff[1024];
	char st[1024];
	char *t;
	char s[80];
	int numbuds_online, numbuds_total;
	
	if ( state == STATE_ONLINE ) {	
		t= ctime(&login_time);
		t[strlen(t)-6] = '\0'; /* remove \n, year, & space -- NOT Y10K READY !@! */
		sprintf(st,"Online since: %s", t);
	} else
		strcpy(st,"Offline");
	
	if ( is_idle ) {
		strcpy(s,"(Idle)");
	} else if ( is_away ) {
		strcpy(s,"(Away)");
	} else {
		strcpy(s,"");
	}
	
	/* Find the number of buddies online */
	numbuds_online = numbuds_total = 0;
	if ( groups != NULL ) {
		LLE g,b;
		struct group *grp;
		struct buddy *bud;		
		for ( TLL(groups,g) ) {
			grp = (struct  group *) g->data;
			numbuds_total +=  grp->members->items;
			for( TLL(grp->members,b) ) {
				bud = (struct buddy *) b->data;
				if ( bud->present)
					numbuds_online++;
			}
		}	
	} 
	sprintf(statbuff, " Buddies: %d/%d Lag: %d Evil: %d  %s %%>%s ", numbuds_online, numbuds_total,(lag_ms / 1000000),my_evil,s,st);
	set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, statbuff);
	
	sprintf(statbuff, " %%>%s ", st);
	set_wset_string_var(tmp->wset, STATUS_FORMAT2_WSET, statbuff);

	update_window_status(tmp, 1);
}

int build_aim_status(Window *tmp)
{
	Window *tmp1;
	if (!(tmp1 = tmp))
		tmp1 = get_window_by_name("AIM");
	if (tmp1)
	{
		update_aim_window(tmp1);
		build_status(tmp1, NULL, 0);
		update_all_windows();
		return 1;
	}
	return 0;
}


void toggle_aimwin_hide (Window *win, char *unused, int onoff) {
	Window *tmp;
	if ((tmp = get_window_by_name("AIM")))
	{
		if (onoff)
		{
			if (tmp->screen)
				hide_window(tmp);
			build_aim_status(tmp);
			update_all_windows();
			cursor_to_input();
		}
		else
		{
			show_window(tmp);
			resize_window(2, tmp, 6);
			build_aim_status(tmp);
			update_all_windows();
			cursor_to_input();
		}
	}
}

void toggle_aimwin (Window *win, char *unused, int onoff){
	Window *tmp;
	if (onoff)
	{
		if ((tmp = get_window_by_name("AIM")))
			return;
		if ((tmp = new_window(win->screen)))
		{
			resize_window(2, tmp, 6);
			tmp->name = m_strdup("AIM");
#undef query_cmd
			tmp->query_cmd = m_strdup("asay");  
			tmp->double_status = 0;
			tmp->absolute_size = 1;
			tmp->update_window_status = update_aim_window;
			tmp->server = -2;
                	set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, NULL);
                	set_wset_string_var(tmp->wset, STATUS_FORMAT2_WSET, NULL);
                	set_wset_string_var(tmp->wset, STATUS_FORMAT3_WSET, NULL);
                	set_wset_string_var(tmp->wset, STATUS_FORMAT_WSET, NULL);

			if (get_dllint_var("aim_window_hidden"))
				hide_window(tmp);
			else
				set_screens_current_window(tmp->screen, tmp);
			build_aim_status(tmp);
			update_all_windows();
			cursor_to_input();
		}
	}
	else
	{
		if ((tmp = get_window_by_name("AIM")))
		{
			if (tmp == target_window)
				target_window = NULL;
			delete_window(tmp);
			update_all_windows();
			cursor_to_input();
			                        
		}
	}
}


char *Aim_Version(IrcCommandDll *intp) {
	return AIM_VERSION;
}

int Aim_Cleanup(IrcCommandDll **interp, Function_ptr *global_table) {
	if ( state == STATE_ONLINE )
		toc_signoff();
#ifdef BITCHX_PATCH	
	overwrite_tabkey_comp(NULL,NULL);
	debug_printf("Didn't remove completions, thats probably gonna cause problems");
#endif		
	remove_module_proc(VAR_PROC, name, NULL, NULL);
	remove_module_proc(COMMAND_PROC,name,NULL,NULL);			
	remove_module_proc(ALIAS_PROC,name,NULL,NULL);		
	return 3;
}


int Aim_Init(IrcCommandDll **interp, Function_ptr *global_table) {
	char buffer[BIG_BUFFER_SIZE+1];
	char *p;
	initialize_module(name);
	
	add_module_proc(VAR_PROC, name, "aim_user", NULL, STR_TYPE_VAR, 0, NULL, NULL);	
	add_module_proc(VAR_PROC, name, "aim_pass", NULL, STR_TYPE_VAR, 0, NULL, NULL);	
	add_module_proc(VAR_PROC, name, "aim_prompt", (char *)convert_output_format("%K[%YAIM%K]%n ", NULL, NULL), STR_TYPE_VAR, 0, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_permdeny_mode", NULL, INT_TYPE_VAR, 1, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_toc_host", TOC_HOST, STR_TYPE_VAR, 0, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_toc_port", NULL, INT_TYPE_VAR, TOC_PORT, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_auth_host", AUTH_HOST, STR_TYPE_VAR, 0, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_auth_port", NULL, INT_TYPE_VAR, AUTH_PORT, NULL, NULL);		
	add_module_proc(VAR_PROC, name, "aim_permdeny_mode", NULL, INT_TYPE_VAR, 1, NULL, NULL);
	add_module_proc(VAR_PROC, name, "aim_minutes_to_idle", NULL, INT_TYPE_VAR, time_to_idle/60, achange_idle, NULL);
	add_module_proc(VAR_PROC, name, "aim_window", NULL, BOOL_TYPE_VAR, 0, toggle_aimwin, NULL);
	add_module_proc(VAR_PROC, name, "aim_window_hidden", NULL, BOOL_TYPE_VAR, 0, toggle_aimwin_hide, NULL);
	

	add_module_proc(COMMAND_PROC, name, "amsg", "amsg", 0, 0, amsg, "<screen name|buddy chat> <message> instant messages");
	add_module_proc(COMMAND_PROC, name, "asignon", "asignon", 0, 0, asignon, "logs into aol instant messanger");
	add_module_proc(COMMAND_PROC, name, "asignoff", "asignoff", 0, 0, asignoff, "logs off of aol instant messanger");	
	add_module_proc(COMMAND_PROC, name, "abl", "abl", 0, 0, abl, "<command> <args...> Modify your buddy list\n/abl show -- Shows buddy list\n/abl add [group] <buddy> -- Adds buddy to group in buddy list\n/abl del <buddy> Removes buddy from buddy llist\n/abl addg <group> Create group group\n/abl delg <group> <newgroup|1> delete group group");	
	add_module_proc(COMMAND_PROC, name, "apd", "apd", 0, 0, apd, "<command> <args...> Modify your permit/deny lists\n/apd show -- Shows your permit & deny list\n/apd mode <permitall|denyall|permitsome|denysome> -- change your mode\n/apd addp <sn> -- Adds sn to your permit list\n/apd delp <sn> -- Removes sn from your permit list\n/apd addd <sn> -- Adds <sn> to your deny list\n/apd deld <sn> -- Removes sn from your deny list");
	add_module_proc(COMMAND_PROC, name, "adir", "adir", 0, 0, adir, "<command> <args...> Use the user directory\n/adir get <sn> Get sn's dir info\n/adir search -- Not implemented yet\n/adir set <first name> <middle name> <last name> <maiden name> <city> <state> <country> <email> <allow web searches? 1|0>");
	add_module_proc(COMMAND_PROC, name, "awarn", "awarn", 0, 0, awarn, "<aim screen name> [anon] warns user");	
	add_module_proc(COMMAND_PROC, name, "awhois", "awhois", 0, 0, awhois, "<screen name> displays info on sn (sn has to be in buddy list)");	
	add_module_proc(COMMAND_PROC, name, "asave", "asave", 0, 0, asave, "Saves AIM settings");	
	add_module_proc(COMMAND_PROC, name, "asay", "asay", 0, 0, achat, "<message> send a message to the current buddy chat");	
	add_module_proc(COMMAND_PROC, name, "apart", "apart", 0, 0, achat, "<buddy chat> leave buddy chat");	
	add_module_proc(COMMAND_PROC, name, "ajoin", "ajoin", 0, 0, achat, "<buddy chat> join buddy chat (first searches invite list, if its in it then joins that one, otherwise creats anew)");
	add_module_proc(COMMAND_PROC, name, "achats", "achats", 0, 0, achat, "display buddy chats you are on"); 
	add_module_proc(COMMAND_PROC, name, "ainvite", "ainvite", 0, 0, achat, "<screen name> <buddy chat> <msg> invite user to buddy chat with msg");		
	add_module_proc(COMMAND_PROC, name, "anames", "anames", 0, 0, achat, "<buddy chat>");			
	add_module_proc(COMMAND_PROC, name, "acwarn", "acwarn", 0, 0, achat, "<buddy chat> <screen name> <anon>");			
	add_module_proc(COMMAND_PROC, name, "aaway", "aaway", 0, 0, aaway, "<away msg> Go away or come back if away");						
	add_module_proc(COMMAND_PROC, name, "aquery", "aquery", 0, 0, aquery, "query user");						
	add_module_proc(COMMAND_PROC, name, "ainfo", "ainfo", 0, 0, ainfo, "<command> <args>\n/ainfo set <your info...> Sets your info\n/ainfo get <screen name> Retreives sn's info");						

#ifdef BITCHX_PATCH	
	add_completion_type("amsg", 2, CUSTOM_COMPLETION, &amsg_complete_func);
	overwrite_tabkey_comp(&do_aim_tabkey_overwrite,&aim_tabkey_overwrite);
#endif
	
	statusprintf("Aol Instant Messanger Module Loaded");
	sprintf(buffer, "$0+AIM %s by panasync - $2 $3", AIM_VERSION);
	fset_string_var(FORMAT_VERSION_FSET, buffer);
	snprintf(buffer, BIG_BUFFER_SIZE, "%s/AIM.sav", get_string_var(CTOOLZ_DIR_VAR));
	p  = expand_twiddle(buffer);
	load("LOAD", p, empty_string, NULL);
	new_free(&p);	
	bx_init_toc();
	return 0;	
}

--- NEW FILE: cmd.c ---
/*
 * AOL Instant Messanger Module for BitchX 
 *
 * By Nadeem Riaz (nads at bleh.org)
 *
 * cmd.c
 *
 * User commands (aliases) (client -> libtoc)
 */



#include <irc.h>
#include <struct.h>
#include <hook.h>
#include <ircaux.h>
#include <output.h>
#include <lastlog.h>
#include <status.h>
#include <vars.h>
#include <window.h>
#include <sys/stat.h>
#include <module.h>
#include <modval.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "toc.h"
#include "aim.h"

char current_chat[512];
char away_message[2048];
LL msgdus;
LL msgdthem;

/* Commands */

void asignon(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg) {
	char *user;
	char *pass;
	char *tochost,*authhost;
	int tocport, authport;
	int x;	
	
	if ( state == STATE_ONLINE ) {
		statusprintf("You are already online.");
		statusprintf("Please disconnect first (/asignoff), before trying to reoconnect.");
		return;
	}
	
	user = get_dllstring_var("aim_user");
	pass = get_dllstring_var("aim_pass");
	tochost = get_dllstring_var("aim_toc_host");
	authhost = get_dllstring_var("aim_auth_host");
	x = get_dllint_var("aim_permdeny");
	tocport = get_dllint_var("aim_toc_port");
	authport = get_dllint_var("aim_auth_port");
	

	if ( ! VALID_ARG(user) || ! VALID_ARG(pass) ) {
		statusprintf("Please set your password and user name, by doing");
		statusprintf("/set aim_user <user name>");
		statusprintf("/set aim_pass <password>");
		return;
	}

	/* This doent change anything-- should rm it */
	if ( x < 1 || x > 4) 
		permdeny = PERMIT_PERMITALL;
	else 
		permdeny = x;
	

	if ( VALID_ARG(tochost) )
		strncpy(aim_host,tochost,513);
	if ( tocport > 0 && tocport < (64*1024) ) 
		aim_port = tocport;
	if ( VALID_ARG(authhost) )
		strncpy(login_host,authhost,513);
	if ( authport > 0 && authport < (64*1024) )
		login_port = authport;
			
	if ( toc_login(user,pass) < 0) {
		statusprintf("Couldn't connect to instant messanger");
	}
	if ( get_dllint_var("aim_window") )
		build_aim_status(get_window_by_name("AIM"));		
	
	msgdthem = CreateLL();
	msgdus = CreateLL();
}



void asignoff(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	if ( state != STATE_ONLINE ) {
		statusprintf("Please connect to aim first (/aconnect)");
		return;
	}	
	delete_timer("aimtime");
	toc_signoff();	
	if ( get_dllint_var("aim_window") )
		build_aim_status(get_window_by_name("AIM"));	
	FreeLL(msgdthem);
	FreeLL(msgdus);
}

void amsg(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *nick,*nnick,*loc;
	
	CHECK_TOC_ONLINE();
	
	/* loc = msg, nick = username to send msg to */
	loc = LOCAL_COPY(args);
	nick = new_next_arg(loc, &loc);
	
	REQUIRED_ARG(nick,command,helparg);
	
	if ( nick[0] == '#' ) {
		struct buddy_chat *b;
		nick++;
		REQUIRED_ARG(nick,command,helparg);
		b = (struct buddy_chat *) find_buddy_chat(nick);
		if ( ! b ) {
			statusprintf("Error not on buddy chat %s", nick);
			return;
		}
		/* chatprintf("sent msg %s to buddy chat %s",loc,nick); */
		serv_chat_send(b->id,loc);
	} else {
		char *ruser,*rnick;
		nnick = (char *) malloc(strlen(nick)+10);
		rnick = rm_space(nick);
		ruser = rm_space(get_dllstring_var("aim_user"));
		sprintf(nnick,"%s at AIM",rnick);
		msgprintf("%s", cparse(fget_string_var(FORMAT_SEND_MSG_FSET), 
			"%s %s %s %s",update_clock(GET_TIME), 
			nnick, ruser, loc));
		serv_send_im(nick,loc);
		RemoveFromLLByKey(msgdthem,rnick);
		AddToLL(msgdthem,rnick,NULL);
#ifdef BITCHX_PATCH
		tks.list = 0;
		tks.pos = -1;
#endif		
		free(rnick); free(ruser);
	}	
	
	debug_printf("sending msg to %s '%s'",nick,loc);	
	return;
}

void abl(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg) {
	char *cmd,*loc;
	
	CHECK_TOC_ONLINE();
	
	/* loc = msg, nick = username to send msg to */
	loc = LOCAL_COPY(args);
	cmd = new_next_arg(loc, &loc);
	
	REQUIRED_ARG(cmd,command,helparg);
	
	if  ( ! strcasecmp(cmd,"show" ) ) {
			struct buddy *b;
			LLE tg,tb;
			LL mems;
			for ( TLL(groups,tg) ) {
				mems = ((struct group *) tg->data)->members;
				statusprintf("Group: %s", tg->key);
				for ( TLL(mems,tb) ) {
					b = (struct buddy *)tb->data;
					statusprintf("\t\t%s %d",b->name,b->present);
				}
			}
	} else if ( ! strcasecmp(cmd,"add") ) {
		char *buddy,*group;
		group = new_next_arg(loc, &loc);
		REQUIRED_ARG(group,command,helparg);

		if ( ! VALID_ARG(loc) ) {
	        	buddy = group;
	        	group = (char *) malloc(strlen("Buddies")+2);
        		strcpy(group,"Buddies");
		} else {
		        buddy = new_next_arg(loc,&loc);
		}

		if ( user_add_buddy(group,buddy) > 0 ) {
			statusprintf("Added buddy %s to group %s",buddy,group);
		} else {
        		statusprintf("%s is already in your buddy list",buddy);
		}	       
	} else if ( ! strcasecmp(cmd,"del") ) {
		char *buddy;
		buddy = new_next_arg(loc,&loc);
		REQUIRED_ARG(buddy,command,helparg);

		if ( user_remove_buddy(buddy) > 0 ) {
			statusprintf("Removed buddy %s",buddy);
		} else {
			statusprintf("%s is not in your buddy list",buddy);
		}
	} else if ( ! strcasecmp(cmd,"addg") ) {
		char *group;
		struct group *g;
		group = new_next_arg(loc,&loc);	
		REQUIRED_ARG(group,command,helparg);	

		g = find_group(group);
		if ( g  ) {
			statusprintf("Group %s already exists",args);
			return;
		}

		add_group(group);
		statusprintf("Created group %s",group);
	} else if ( ! strcasecmp(cmd,"delg") ) {
		char *group,*newgroup;
		int ret;

		group = new_next_arg(loc, &loc);
		newgroup = new_next_arg(loc,&loc);
		REQUIRED_ARG(group,command,helparg);
		
		if ( ! VALID_ARG(newgroup) ) {
			statusprintf("Usage: /abl delg <old group> 1 (delete group and all buddies in it)");
			statusprintf("       /abl delg <old group>  <new group> (delete group and move all buddies in it to new group)");
			return;
		} 	

		if ( ! strcasecmp(newgroup,"1") ) 
			ret = remove_group(group,NULL,2);
		else 
			ret = remove_group(group,newgroup,1);
		if ( ret > 0 ) 
			statusprintf("Removed group %s",group);	
		else 
			statusprintf("Group %s doesn't exist",group);		
	} else 
		statusprintf("Error unknown buddy list management command: %s", cmd);
}	

void awarn(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *buddy,*mode,*loc;
	mode = NULL;
	
	CHECK_TOC_ONLINE();
	
	loc = LOCAL_COPY(args);
	buddy = new_next_arg(loc, &loc);
	mode = new_next_arg(loc,&loc);
	
	REQUIRED_ARG(buddy,command,helparg);	
	
	if ( VALID_ARG(mode) && ! strcasecmp(mode,"anon") ) {
		serv_warn(buddy,1);
	} else {
		serv_warn(buddy,0);
	}
	statusprintf("Warned: %s",buddy);
}

void apd(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *cmd,*loc;
	loc = LOCAL_COPY(args);
	cmd = new_next_arg(loc,&loc);

	CHECK_TOC_ONLINE();
	
	REQUIRED_ARG(cmd,command,helparg);

	if ( ! strcasecmp(cmd,"show") ) { 
		LLE t;
		statusprintf("User Mode: %s",((permdeny >= 1 && permdeny <= 4) ? PERMIT_MODES[permdeny] : "ERROR: Unknown"));
		statusprintf("Permit:");
		ResetLLPosition(permit);
		while ( (t=GetNextLLE(permit)) ) {
			statusprintf("\t\t%s",t->key);
		}
		
		ResetLLPosition(deny);
		statusprintf("Deny:");
		while ( (t=GetNextLLE(deny)) ) {
			statusprintf("\t\t%s",t->key);
		}		
	} else if ( ! strcasecmp(cmd,"mode") )  {
		char *mode;
		int newmode;
		mode = new_next_arg(loc,&loc);		
		REQUIRED_ARG(mode,command,helparg);

		if ( ! strcasecmp(mode,"permitall") )  {
			newmode = PERMIT_PERMITALL;
		} else if ( ! strcasecmp(mode,"denyall") ) {
			newmode = PERMIT_DENYALL;
		} else if ( ! strcasecmp(mode,"denysome") ) {
			newmode = PERMIT_DENYSOME;
		} else if ( ! strcasecmp(mode,"permitsome") ) {
			newmode = PERMIT_PERMITSOME;
		} else {
			userage(command,helparg);
			return;
		}
	
		if ( newmode == permdeny ) {
			statusprintf("We are already in %s mode",mode);
			return;
		} else {
			permdeny = newmode;
			set_dllint_var("aim_permdeny_mode",permdeny);
			serv_set_permit_deny();
			serv_save_config();
		}

		statusprintf("Switch to %s mode",mode);				
	} else if ( !strcasecmp(cmd,"addp") ) {
		char *buddy;
		buddy = new_next_arg(loc,&loc);
		REQUIRED_ARG(buddy,command,helparg);
		
		if ( add_permit(buddy) < 0 ) {
			statusprintf("%s is already in your permit list!");
			return;
		}	
		if ( permdeny != PERMIT_PERMITSOME ) 
			statusprintf("Note: although %s will be added to your permit list, no tangible change will occur because you are in the improper mode (see help on apermdeny)",buddy);
		statusprintf("Added %s to your permit list",buddy);		
	} else if ( !strcasecmp(cmd,"delp") ) {
		char *buddy;
		buddy = new_next_arg(loc,&loc);
		REQUIRED_ARG(buddy,command,helparg);
		
		if ( remove_permit(buddy) < 0 )
			statusprintf("%s is not in your permit list!",buddy);
		else 
			statusprintf("Remvoed %s from your permit list",buddy);					
	} else if ( !strcasecmp(cmd,"addd") ) {
		char *buddy;
		buddy = new_next_arg(loc,&loc);
		REQUIRED_ARG(buddy,command,helparg);	
		
		if ( add_deny(buddy) < 0 ) {
			statusprintf("%s is already in your deny list!");
			return;
		}
		if ( permdeny != PERMIT_DENYSOME ) 
			statusprintf("Note: although %s will be added to your deny list, no tangible change will occur because you are in the improper mode (see help on apermdeny)",buddy);
		statusprintf("Added %s to your deny list",buddy);		
	} else if ( !strcasecmp(cmd,"deld") ) {	
		char *buddy;
		buddy = new_next_arg(loc,&loc);
		REQUIRED_ARG(buddy,command,helparg);
		
		if ( remove_deny(buddy) < 0 )
			statusprintf("%s is not in your deny list!",buddy);
		else 
			statusprintf("Remvoed %s from your deny list",buddy);				
	} else 
		statusprintf("Error unknown permit/deny cmd %s",cmd);
}

void awhois(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *buddy,*loc;
	struct buddy *b;
	loc = LOCAL_COPY(args);
	buddy = new_next_arg(loc,&loc);

	CHECK_TOC_ONLINE();
	
	REQUIRED_ARG(buddy,command,helparg);
	
	b = find_buddy(buddy);
	if ( ! b ) {
		statusprintf("%s is not in your buddy list and thus I have no info stored on him/her",buddy);
		return;
	}

	statusprintf("%s", cparse("ÚÄÄÄÄÄ---Ä--ÄÄ-ÄÄÄÄÄÄ---Ä--ÄÄ-ÄÄÄÄÄÄÄÄÄ--- --  -", NULL));
        statusprintf("%s", cparse("| User       : $0-", "%s", b->name));
        statusprintf("%s", cparse("³ Class      : $0-", "%s", ((b->uc <= 5 && b->uc >= 0) ? USER_CLASSES[b->uc] : "Unknown")));
        statusprintf("%s", cparse("³ Evil       : $0-", "%d", b->evil));
	statusprintf("%s", cparse("³ SignOn     : $0-", "%s", my_ctime(b->signon)));
        statusprintf("%s", cparse(": Idle       : $0-", "%d", b->idle));
}

void asave (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	IrcVariableDll *newv = NULL;
	FILE *outf = NULL;
	char *expanded = NULL;
	char buffer[BIG_BUFFER_SIZE+1];
	if (get_string_var(CTOOLZ_DIR_VAR))
		snprintf(buffer, BIG_BUFFER_SIZE, "%s/AIM.sav", get_string_var(CTOOLZ_DIR_VAR));
	else
		sprintf(buffer, "~/AIM.sav");
	expanded = expand_twiddle(buffer);
	if (!expanded || !(outf = fopen(expanded, "w")))
	{
		statusprintf("error opening %s", expanded ? expanded : buffer);
		new_free(&expanded);
		return;
	}
	for (newv = dll_variable; newv; newv = newv->next)
	{
		if (!my_strnicmp(newv->name, name, 3))
		{
			if (newv->type == STR_TYPE_VAR)
			{
				if (newv->string)
					fprintf(outf, "SET %s %s\n", newv->name, newv->string);
			}
			else if (newv->type == BOOL_TYPE_VAR)
				fprintf(outf, "SET %s %s\n", newv->name, on_off(newv->integer));
			else
				fprintf(outf, "SET %s %d\n", newv->name, newv->integer);
		}
	}

	/* Buddy list, perm/deny list, etc. stored on AIM server */
	
	/*
	 * Not sure what that does?
	if (do_hook(MODULE_LIST, "NAP SAVE %s", buffer))
		nap_say("Finished saving Napster variables to %s", buffer);
	 */
	statusprintf("Finished saving AIM variables to %s",buffer);
	fclose(outf);	
	new_free(&expanded);
	return;
}

void achat (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *arg1, *arg2, *arg3, *loc;

	loc = LOCAL_COPY(args);
	
	debug_printf("in achat!");
	
	CHECK_TOC_ONLINE();
	
	if ( ! strcasecmp(command,"asay") ) {
		if ( VALID_ARG(current_chat) ) {
			struct buddy_chat *b;
			b = find_buddy_chat(current_chat);
			if ( ! b ) {
				statusprintf("Not on a buddy chat");
				return;
			}
			serv_chat_send(b->id,loc);
		} else 
			statusprintf("Not on a buddy chat");
	} else if ( ! strcasecmp(command,"ajoin") ) {
		arg1 = new_next_arg(loc,&loc);
		REQUIRED_ARG(arg1,command,helparg);
		if ( arg1[0] == '#' )
			arg1++;		
		REQUIRED_ARG(arg1,command,helparg);
		if ( find_buddy_chat(arg1) ) {
			strncpy(current_chat,arg1,511);
			return;
		} 
		buddy_chat_join(arg1);
	} else if ( ! strcasecmp(command,"apart") ) {
		arg1 = new_next_arg(loc,&loc);
		if ( VALID_ARG(arg1) && arg1[0] == '#' )
			arg1++;
		if ( VALID_ARG(arg1) ) {		
			if ( buddy_chat_leave(arg1) ) {
				if ( ! strcasecmp(arg1,current_chat) ) {
					/* Replace Current Chat */
					strcpy(current_chat,"");
				}
			} else 
				statusprintf("Not on buddy chat %s",arg1);
		} else {
			if ( VALID_ARG(current_chat) ) {
				buddy_chat_leave(current_chat);
				/* Repalce Current Chat */
				strcpy(current_chat,"");
			} else 
				statusprintf("Not on a buddy chat");			
		}		
	} else if ( ! strcasecmp(command,"ainvite") ) {
		arg1 = new_next_arg(loc,&loc);
		arg2 = new_next_arg(loc,&loc);
		arg3 = new_next_arg(loc,&loc);
		REQUIRED_ARG(arg1,command,helparg);
		if ( arg1[0] == '#' ) 
			arg1++;
		REQUIRED_ARG(arg1,command,helparg);
		REQUIRED_ARG(arg2,command,helparg);
		REQUIRED_ARG(arg3,command,helparg);
		
		if ( buddy_chat_invite(arg1,arg2,arg3) < 0 ) {
			statusprintf("Not on buddy chat %s",arg1);
		}
	} else if ( !strcasecmp(command,"achats") ) {
		LLE t;
		statusprintf("Currently on: ");
		ResetLLPosition(buddy_chats);
		while ( (t=GetNextLLE(buddy_chats)) ) {
			statusprintf("\t\t%s",t->key);
		}
	} else if ( ! strcasecmp(command,"anames") ) {
		char *chat;
		arg1 = new_next_arg(loc,&loc);
		if ( VALID_ARG(arg1) ) 
			chat = arg1;
		else
			chat  = current_chat;
		if  ( VALID_ARG(chat) ) {
			struct buddy_chat *b;
			LLE t;
			b = find_buddy_chat(chat);
			if ( ! b ) {
				statusprintf("Not on buddy chat %s",chat);
				return;
			}
			statusprintf("Names on %s",b->name);
			ResetLLPosition(b->in_room);
			while ( (t=GetNextLLE(b->in_room)) ) {
				statusprintf("%s",t->key);
			}		
		} else 
			statusprintf("Not on a buddy chat");
	} else if ( ! strcasecmp(command,"acwarn") ) {
		int anon = 0;
		char *chat = NULL, *user = NULL, *mode = NULL;
		arg1 = new_next_arg(loc,  &loc);
		arg2 = new_next_arg(loc,&loc);
		arg3 = new_next_arg(loc,&loc);
		if ( VALID_ARG(arg1) && VALID_ARG(arg2) && VALID_ARG(arg3) ) {
			chat = arg1;
			user = arg2;
			mode = arg3;
		} else if ( VALID_ARG(arg1) && VALID_ARG(arg2) ) {
			chat = current_chat;
			user = arg1;
			mode = arg2;
		} else if ( VALID_ARG(arg1) ) {
			chat = current_chat;
			user = arg2;
			mode = NULL;
		}
		if ( VALID_ARG(mode) && ! strcasecmp(mode,"anon") )
			anon = 1;
		if ( chat[0] == '#' ) {
			chat++; 
			REQUIRED_ARG(chat,command,helparg);
		}
		if ( buddy_chat_warn(chat,user,1) < 0 )
			statusprintf("Not on buddy chat %s",chat);
		else
			statusprintf("Buddy Chat Warned %s",user);
	} else
		debug_printf("Unknown command in achat %s",command);
}

void adir (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *cmd,*loc;

	loc = LOCAL_COPY(args);
	cmd = new_next_arg(loc,&loc);
	
	CHECK_TOC_ONLINE();
	REQUIRED_ARG(cmd,command,helparg);
	if ( !strcasecmp(cmd,"get") ) {
		char *sn;
		sn = new_next_arg(loc,&loc);
		REQUIRED_ARG(sn,command,helparg);
		
		serv_get_dir(sn);
	} else if ( ! strcasecmp(cmd,"search") ) {
		int fields = 0;
		char *field,*data;
		char *first,*middle,*last,*maiden;
		char *city,*state,*country,*email;
		first = middle = last = maiden = NULL;
		city = state = country = email = NULL;
				
		field = new_next_arg(loc,&loc);
		while ( VALID_ARG(field) ) {
			data = new_next_arg(loc,&loc);
			if ( VALID_ARG(data) ) {
				fields++;
				if ( ! strcasecmp(field,"first") || ! strcasecmp(field,"-first") )
					first = data;
				else if ( ! strcasecmp(field,"middle") || ! strcasecmp(field,"-middle") )
					middle = data;
				else if ( ! strcasecmp(field,"last") || ! strcasecmp(field,"-last") )
					last = data;
				else if ( ! strcasecmp(field,"maiden") || ! strcasecmp(field,"-maiden") )
					maiden = data;
				else if ( ! strcasecmp(field,"city") || ! strcasecmp(field,"-city") )
					city = data;
				else if ( ! strcasecmp(field,"state") || ! strcasecmp(field,"-state") )
					state = data;
				else if ( ! strcasecmp(field,"country") || ! strcasecmp(field,"-country") )
					country = data;
				else if ( ! strcasecmp(field,"email") || ! strcasecmp(field,"-email") )	
					email = data;
				else
					statusprintf("Illegal field: %s",field);
			} else {
				statusprintf("No search item for field %s",field);
			}
			serv_dir_search(first,middle,last,maiden,city,state,country,email);
		}
	} else if ( ! strcasecmp(cmd,"set") ) {
		char *first = new_next_arg(loc,&loc);
		char *middle = new_next_arg(loc,&loc);
		char *last = new_next_arg(loc,&loc);
		char *maiden = new_next_arg(loc,&loc);
		char *city = new_next_arg(loc,&loc);
		char *state =new_next_arg(loc,&loc);
		char *country = new_next_arg(loc,&loc);
		char *email = new_next_arg(loc,&loc);
		char *allow = new_next_arg(loc,&loc);
		int x; 
		
		REQUIRED_ARG(allow,command,helparg);
		if ( atoi(allow) ) {
			x = 1;
		} else {
			x = 0;
		}
		/* apparently sending email messes this up? */
		serv_set_dir(first,middle,last,maiden,city,state,country,email,x);
	} else
		debug_printf("Unknown command in adir %s",command);
}

void achange_idle(Window *w, char *s, int i) {
	time_to_idle = i * 60;
	debug_printf("time to idle = %d",time_to_idle);
}

void aaway (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg) {
	char *loc;

	loc = LOCAL_COPY(args);
	CHECK_TOC_ONLINE();
		
	serv_set_away(args);
	
	if ( is_away ) {
		strncpy(away_message,args,2047);
		statusprintf("You are now marked as away");
	} else 
		statusprintf("You are now back.");
		
	if ( get_dllint_var("aim_window") )
		build_aim_status(get_window_by_name("AIM"));			
}

void aquery(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg) {
	Window *tmp = NULL;
	char *loc,*n,*msg;
	char say[10] = "say";
	
	CHECK_TOC_ONLINE();
	loc = LOCAL_COPY(args);
	n = new_next_arg(loc,&loc);
	
	if ( get_dllint_var("aim_window") ) {
		strcpy(say,"asay");
		tmp = get_window_by_name("AIM");
	}
	if ( ! tmp ) 
		tmp = current_window;
	
	if ( VALID_ARG(n) ) {
#ifdef BITCHX_PATCH
		msg = (char *) malloc(strlen(n)+50);
		sprintf(msg,"-cmd amsg %s",n);
		debug_printf("Querying: %s",msg);
		window_query(tmp,&msg,NULL);
#else
	
		msg = (char *) malloc(strlen(n)+10);
		sprintf(msg,"amsg %s",n);
		debug_printf("nick = '%s' msg = '%s'",n,msg);
#undef query_cmd 
		tmp->query_cmd = m_strdup("amsg");
#undef query_nick
		tmp->query_nick = m_strdup(n);
		update_input(tmp);
#endif
	} else {
#undef query_cmd	
		tmp->query_cmd = m_strdup(say);
	}	
	debug_printf("Leaking memory in aquery");
}

void ainfo(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg) {
	char *cmd,*loc;

	loc = LOCAL_COPY(args);
	cmd = new_next_arg(loc,&loc);
	
	CHECK_TOC_ONLINE();
	REQUIRED_ARG(cmd,command,helparg);
	
	if ( ! strcasecmp(cmd,"get") ) {
		char *nick = new_next_arg(loc,&loc);
		REQUIRED_ARG(nick,command,helparg);
		
		serv_get_info(nick);
	} else if ( ! strcasecmp(cmd,"set") ) {
		REQUIRED_ARG(loc,command,helparg);
		serv_set_info(loc);
	} else 
		statusprintf("Unknown command sent to ainfo: '%s'", cmd);
}

--- NEW FILE: toc.c ---
/*
 * AOL Instant Messanger Module for BitchX 
 *
 * By Nadeem Riaz (nads at bleh.org)
 *
 * toc.c
 *
 * Interface to libtoc (libtoc -> client)
 */


#include <irc.h>
#include <struct.h>
#include <hook.h>
#include <ircaux.h>
#include <output.h>
#include <lastlog.h>
#include <status.h>
#include <vars.h>
#include <window.h>
#include <sys/stat.h>
#include <module.h>
#include <modval.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "toc.h"
#include "aim.h"

int sock_read_id;
void (*chatprintf)(char *, ...) = statusprintf;

/* LIBToc Call back functions */

int toc_add_input_stream(int fd,int (*func)(int)) {
	sock_read_id = add_socketread(fd, 0, 0, "bleh", func, func);	
        return 1;
}

int toc_remove_input_stream(int fd) {
	close_socketread(sock_read_id);
        return 1;
}

int toc_main_interface(int type, char **args) {
	
	switch (type) {
		case TOC_IM_IN: {
			char *msg, *nick;		
			nick = rm_space(args[0]);
			msg = strip_html(args[1]);
			RemoveFromLLByKey(msgdus,nick);
			AddToLL(msgdus,nick,NULL);	
			msgprintf("%s", cparse(fget_string_var(FORMAT_MSG_FSET), 
				"%s %s %s %s",update_clock(GET_TIME), 
				nick, "AIM", msg));			
			if ( is_away ) 
				serv_send_im(args[0],away_message);
			free(nick);
			break;
		}
		case TOC_TRANSLATED_ERROR:
		case TOC_CONNECT_MSGS:
			statusprintf(args[0]);
			break;
		case TOC_BUDDY_LOGGED_OFF:
			statusprintf("%s logged off",args[0]);
			if ( get_dllint_var("aim_window") )
				build_aim_status(get_window_by_name("AIM"));
			break;
		case TOC_BUDDY_LOGGED_ON:
			statusprintf("%s logged on", args[0]);
			if ( get_dllint_var("aim_window") )
				build_aim_status(get_window_by_name("AIM"));
			break;
		case TOC_EVILED:
			statusprintf("You have been warned by %s.", ((args[0] == NULL) ? "an anonymous person" : args[0])); 
			statusprintf("Your new warning level is %s%%" , args[1]);
			if ( get_dllint_var("aim_window") )
				build_aim_status(get_window_by_name("AIM"));
			break;
		case TOC_CHAT_JOIN:
			chatprintf("Joined buddy chat %s",args[1]);
			strncpy(current_chat,args[1],511);
			break;
		case TOC_BUDDY_LEFT_CHAT:
			chatprintf("%s left %s",args[1],args[0]);
			break;
		case TOC_BUDDY_JOIN_CHAT:
			chatprintf("%s joined %s",args[1],args[0]);
			break;
		case TOC_CHAT_LEFT:
			chatprintf("Left chat id: %s",args[0]);	
			break;
		case TOC_CHAT_IN: {
			char *e,*name,*chat;
			/* chatprintf("got msg from chat: <%s at AIM> %s",args[1],args[3]); */
			/* Need to take better action here */
			e = strip_html(args[3]);
			name = rm_space(args[1]);
			chat = rm_space(args[4]);
			msgprintf("%s",cparse(fget_string_var(FORMAT_PUBLIC_OTHER_FSET), "%s %s %s %s", update_clock(GET_TIME), name, chat, e));			
			free(name); free(chat);
			break;
		}
		case TOC_GOTO_URL: 
			statusprintf("GOTO_URL: %s",args[0]);
			break;
		case TOC_CHAT_INVITE:
			statusprintf("Invited to %s by %s '%s'",args[0],args[2],args[3]);
			break;
		case TOC_LAG_UPDATE:
		case TOC_WENT_IDLE:
			if ( get_dllint_var("aim_window") )
				build_aim_status(get_window_by_name("AIM"));
			break;					
		case TOC_DIR_STATUS:
			if ( atoi(args[0]) == 1 )
				statusprintf("Directory information successfully changed.");
			else
				statusprintf("Error altering directory information, error code: %s",args[0]);
			break;
		default:
			statusprintf("INTERNAL ERROR: Unknown toc type: %d",type);
	}
	return 1;
}

int toc_timer(int type, char **args) {
	timer_id = add_timer(0,"aimtime",20000,0,&check_idle,NULL,NULL,0,"aimtime");
	return 1;
}

/* int toc_buddy_logged_on( */

void bx_init_toc() {
	init_toc();
	strcpy(current_chat,"");
	/* Setup Hanlders */
	install_handler(TOC_IM_IN,&toc_main_interface);
	install_handler(TOC_TRANSLATED_ERROR,&toc_main_interface);
	install_handler(TOC_CONNECT_MSGS,&toc_main_interface);
	install_handler(TOC_BUDDY_LOGGED_ON,&toc_main_interface);
	install_handler(TOC_BUDDY_LOGGED_OFF,&toc_main_interface);
	install_handler(TOC_EVILED,&toc_main_interface);	
	install_handler(TOC_CHAT_JOIN,&toc_main_interface);
	install_handler(TOC_BUDDY_LEFT_CHAT,&toc_main_interface);
	install_handler(TOC_BUDDY_JOIN_CHAT,&toc_main_interface);
	install_handler(TOC_CHAT_LEFT,&toc_main_interface);
	install_handler(TOC_CHAT_IN,&toc_main_interface);
	install_handler(TOC_CHAT_INVITE,&toc_main_interface);
	install_handler(TOC_GOTO_URL,&toc_main_interface);
	install_handler(TOC_LAG_UPDATE,&toc_main_interface);
	install_handler(TOC_WENT_IDLE,&toc_main_interface);
	install_handler(TOC_DIR_STATUS,&toc_main_interface);
	install_handler(TOC_REINSTALL_TIMER,&toc_timer);	
}

--- NEW FILE: bx.patch ---
--- .//dll/fserv/fserv.c.orig	Tue Jan 18 21:00:07 2000
+++ .//dll/fserv/fserv.c	Tue Jan 18 21:00:19 2000
@@ -1162,7 +1162,7 @@
         add_module_proc(HOOK_PROC, "Fserv", NULL, "*", MSG_LIST, 1, NULL, search_proc);
         add_module_proc(HOOK_PROC, "Fserv", NULL, "*", PUBLIC_OTHER_LIST, 1, NULL, search_proc);
 
-	add_completion_type("fsload", 3, FILE_COMPLETION);
+	add_completion_type("fsload", 3, FILE_COMPLETION,NULL);
 
 	add_timer(0, empty_string, get_dllint_var("fserv_time"), 1, impress_me, NULL, NULL, -1, "fserv");
 	strcpy(FSstr, cparse(FS, NULL, NULL));
@@ -1177,4 +1177,4 @@
 	put_it("%s for help with this fserv, /fshelp", FSstr);
 	return 0;
 }
- 
\ No newline at end of file
+ 
--- .//dll/nap/nap.c.orig	Wed Jan 19 14:17:52 2000
+++ .//dll/nap/nap.c	Tue Jan 18 21:01:34 2000
@@ -2139,8 +2139,8 @@
 	add_module_proc(VAR_PROC, nap_name, "napster_format", NULL, STR_TYPE_VAR, 0, set_numeric_string, NULL);
 	add_module_proc(VAR_PROC, nap_name, "napster_dir", NULL, STR_TYPE_VAR, 0, NULL, NULL);
 
-	add_completion_type("nload", 4, FILE_COMPLETION);
-	add_completion_type("nreload", 4, FILE_COMPLETION);
+	add_completion_type("nload", 4, FILE_COMPLETION,NULL);
+	add_completion_type("nreload", 4, FILE_COMPLETION,NULL);
 
 	naphelp(NULL, NULL, NULL, NULL, NULL);
 	sprintf(buffer, "$0+Napster %s by panasync - $2 $3", nap_version);
--- .//include/module.h.orig	Tue Jan 18 01:24:49 2000
+++ .//include/module.h	Tue Jan 18 20:29:36 2000
@@ -633,7 +633,14 @@
 	CHECK_EXT_MAIL,
 	DEFAULT_OUTPUT_FUNCTION,
 	DEFAULT_STATUS_OUTPUT_FUNCTION,
-	NUMBER_OF_GLOBAL_FUNCTIONS
+	NUMBER_OF_GLOBAL_FUNCTIONS,
+
+/* window.c again */
+	WINDOW_QUERY,
+
+/* input.c again */
+
+	OVERWRITE_TABKEY_COMP
 };
 
 extern Function_ptr global_table[];
--- .//include/modval.h.orig	Tue Jan 18 16:50:22 2000
+++ .//include/modval.h	Tue Jan 18 20:28:58 2000
@@ -360,7 +360,8 @@
 #define getnextnick(x, y, z, a) ((NickTab *) (global[GETNEXTNICK]((int)x, (char *)y, (char *)z, (char *)a)))
 #define getchannick(x, y) ((char *) (global[GETCHANNICK]((char *)x, (char *)y)))
 #define lookup_nickcompletion(x, y) ((NickList *) (global[LOOKUP_NICKCOMPLETION]((ChannelList *)x, (char *)y)))
-#define add_completion_type(x, y, z) ((int) (global[ADD_COMPLETION_TYPE]((char *)x, (int)y, (enum completion)z)))
+#define add_completion_type(x, y, z, a) ((int) (global[ADD_COMPLETION_TYPE]((char *)x, (int)y, (enum completion)z, a)))
+#define overwrite_tabkey_comp(a,b) (global[OVERWRITE_TABKEY_COMP](a,b))
 
 /* names.c */
 #define is_channel(x) ((int) (global[IS_CHANNEL]((char *)x)))
--- .//include/input.h.orig	Tue Jan 18 16:23:49 2000
+++ .//include/input.h	Thu Jan 20 17:05:28 2000
@@ -157,11 +157,15 @@
 	DCC_COMPLETION,
 	LOAD_COMPLETION,
 	SERVER_COMPLETION,
-	CDCC_COMPLETION
+	CDCC_COMPLETION,
+	CUSTOM_COMPLETION,
+	TABKEY_OVERWRITE
 };
 
-	char	*get_completions	(enum completion, char *, int *, char **);
-	int	add_completion_type	(char *, int, enum completion);
+	char	*get_completions	(enum completion *, char *, int *, char **, char * (*)(int, char *, int *, char **));
+	int	add_completion_type	(char *, int, enum completion, char * (*)(int, char *, int *, char **));
+
+void overwrite_tabkey_comp(int (*)(int, char *, int *, char **), char * (*)(int, char *, int *, char **));
 
 extern	NickTab *tabkey_array;
 extern	NickTab *autoreply_array;
--- .//source/modules.c.orig	Tue Jan 18 01:38:07 2000
+++ .//source/modules.c	Tue Jan 18 20:53:49 2000
@@ -423,6 +423,7 @@
 	global_table[RECALCULATE_WINDOW_CURSOR]	= (Function_ptr) recalculate_window_cursor;
 	global_table[MAKE_WINDOW_CURRENT]	= (Function_ptr) make_window_current;
 	global_table[CLEAR_SCROLLBACK]		= (Function_ptr) clear_scrollback;
+	global_table[WINDOW_QUERY]		= (Function_ptr) window_query;
 	
 	global_table[RESET_DISPLAY_TARGET]	= (Function_ptr) reset_display_target;
 	global_table[SET_DISPLAY_TARGET]	= (Function_ptr) set_display_target;
@@ -475,6 +476,7 @@
 	global_table[GETCHANNICK]		= (Function_ptr) getchannick;
 	global_table[LOOKUP_NICKCOMPLETION]	= (Function_ptr) lookup_nickcompletion;
 	global_table[ADD_COMPLETION_TYPE]	= (Function_ptr) add_completion_type;
+	global_table[OVERWRITE_TABKEY_COMP]	= (Function_ptr) overwrite_tabkey_comp;
 		
 /* names.c */			
 	global_table[IS_CHANOP]			= (Function_ptr) is_chanop;
--- .//source/input.c.orig	Tue Jan 18 15:58:30 2000
+++ .//source/input.c	Thu Jan 20 20:10:02 2000
@@ -62,6 +62,9 @@
 NickTab *tabkey_array = NULL, *autoreply_array = NULL;
 
 
+int (*do_over_write_tabkey_complete)(int, char *, int *, char **) = NULL;
+char * (*over_write_tabkey_complete_func)(int, char *, int *, char **) = NULL;
+
 
 const int WIDTH = 10;
 
@@ -2119,7 +2122,8 @@
 	struct _ext_name_type *next;
 	char *name;
 	int len;
-	enum completion type;
+	enum completion type;	
+	char * (*comp_func)(int, char *, int *, char **); 
 } Ext_Name_Type;
 
 Ext_Name_Type *ext_completion = NULL;
@@ -2161,7 +2165,14 @@
 	return NULL;
 }
 
-char *get_completions(enum completion type, char *possible, int *count, char **suggested)
+void overwrite_tabkey_comp(int (*check)(int, char *, int *, char **) , char * (*overwrite)(int, char *, int *, char **) ) 
+{
+	do_over_write_tabkey_complete = check;
+	over_write_tabkey_complete_func = overwrite;
+	return;
+}
+
+char *get_completions(enum completion *t, char *possible, int *count, char **suggested, char * (*cf)(int, char *, int *, char **))
 {
 char *booya = NULL;
 char *path = NULL;
@@ -2169,6 +2180,7 @@
 glob_t globbers;
 int numglobs = 0, i;
 int globtype = GLOB_MARK;
+enum completion type = *t;
 
 #if defined(__EMX__) || defined(WINNT)
 	if (possible && *possible)
@@ -2191,6 +2203,18 @@
 		case TABKEY_COMPLETION:
 		{
 			NickTab *n = tabkey_array;
+			/*
+			 * bad hack
+			 * better idea would be to make this into a list
+			 * and allow multiple modules to create over writes
+			 * then, go to the first module that says it wants to
+			 * do a tab_complete 
+			 */
+			if ( do_over_write_tabkey_complete != NULL && over_write_tabkey_complete_func != NULL && do_over_write_tabkey_complete((int) type, possible, count, suggested) ) {
+				*t = TABKEY_OVERWRITE;
+				return over_write_tabkey_complete_func((int) type, possible, count, suggested);
+			}
+			/* put_it("opted not do!"); */
 			*count = 0;
 			if (possible)
 			{
@@ -2377,6 +2401,18 @@
 #endif
 			break;
 		}
+		case CUSTOM_COMPLETION: 
+		{
+			char *c;
+			if ( cf == NULL ) {
+				return NULL; 
+				/* put_it("CF IS NULL!"); */
+			}
+			c = cf((int)type, possible, count ,suggested);
+			/* put_it(c); */
+			return c;
+			break;
+		}
 		default:
 			return NULL;
 	}
@@ -2507,6 +2543,7 @@
 int got_space = 0;
 char *get = NULL;
 Ext_Name_Type *extcomp = ext_completion;
+char * (*cf)(int, char *, int *, char **) = NULL;
 
 	/* 
 	 * is this the != second word, then just complete from the 
@@ -2597,6 +2634,7 @@
 						case CDCC:
 							if (wcount == 2 || wcount == 3)
 								type = CDCC_COMPLETION;
+								
 							break;
 					}
 					break;
@@ -2609,6 +2647,7 @@
 					if (!my_strnicmp(p, extcomp->name, extcomp->len))
 					{
 						type = extcomp->type;
+						cf = extcomp->comp_func; 
 						break;
 					}
 				}
@@ -2628,7 +2667,7 @@
 #endif
 do_more_tab:
 	count = 0;
-	if ((get = get_completions(type, possible, &count, &suggested)))
+	if ((get = get_completions(&type, possible, &count, &suggested, cf)))
 	{
 		char buffer[BIG_BUFFER_SIZE+1];
 		char *p = NULL;
@@ -2640,8 +2679,11 @@
 				p = extract(get_input(), 0, wcount - 2);
 			else if (suggested && *suggested)
 				p = m_3dup("/", suggested, "");
-			if (type == TABKEY_COMPLETION)
+				
+			if (type == TABKEY_COMPLETION) 
 				snprintf(buffer, BIG_BUFFER_SIZE, "%s %s%s%s ", (p && *p == '/') ? p : "/m", get, (p && (*p != '/'))?space:empty_string, (p && (*p != '/'))?p:empty_string);
+			else if ( type == TABKEY_OVERWRITE ) 
+				snprintf(buffer, BIG_BUFFER_SIZE, "%s",get);
 			else
 			{
 				if (wcount == 1 && got_space)
@@ -2729,10 +2771,11 @@
 				case SERVER_COMPLETION:
 				case TABKEY_COMPLETION:
 				case CHAN_COMPLETION:
+				case CUSTOM_COMPLETION:
 				{
 					char *n, *use = get;
 					n = new_next_arg(use, &use);
-					count = 0;
+					count = 0;					
 					while (n && *n)
 					{
 						strmcat(buffer, n, BIG_BUFFER_SIZE);
@@ -2750,6 +2793,7 @@
 						put_it("%s", convert_output_format(fget_string_var(FORMAT_COMPLETE_FSET),"%s", buffer));
 					break;
 				}
+				case TABKEY_OVERWRITE:
 				case NO_COMPLETION:
 					break;
 				default:
@@ -2776,15 +2820,16 @@
 	return;
 }
 
-int add_completion_type(char *name, int len, enum completion type)
+int add_completion_type(char *name, int len, enum completion type, char * (*cf)(int, char *, int *, char **)) 
 {
-Ext_Name_Type *new;
+	Ext_Name_Type *new;
 	if (!find_in_list((List **)&ext_completion, name, 0))
 	{
 		new = (Ext_Name_Type *)new_malloc(sizeof(Ext_Name_Type));
 		new->name = m_strdup(name);
 		new->len = len;
 		new->type = type;
+		new->comp_func =cf;
 		add_to_list((List **)&ext_completion, (List *)new);
 		return 1;
 	}
--- .//source/functions.c.orig	Tue Jan 18 16:44:28 2000
+++ .//source/functions.c	Thu Jan 20 17:10:53 2000
@@ -7020,8 +7020,9 @@
 #ifdef WANT_TABKEY
 char *ret, *possible;
 int count = 0; /* 6 */
+enum completion comp_type = 3;
 	possible = next_arg(input, &input);
-	ret = get_completions(3, possible, &count, NULL);
+	ret = get_completions(&comp_type, possible, &count, NULL, NULL);
 	return m_sprintf("%d %s", count, ret ? ret : empty_string);
 #else
 	RETURN_EMPTY;
@@ -7033,8 +7034,9 @@
 #ifdef WANT_TABKEY
 char *ret, *possible;
 int count = 0;/* 4 */
+enum completion comp_type = 7;
 	possible = next_arg(input, &input);
-	ret = get_completions(7, possible, &count, NULL);
+	ret = get_completions(&comp_type, possible, &count, NULL, NULL);
 	return m_sprintf("%d %s", count, ret ? ret : empty_string);
 #else
 	RETURN_EMPTY;

--- NEW FILE: aim.h ---
#ifndef _AIM_H
#define _AIM_H

#define AIM_VERSION "0.02"
#define AIM_DEBUG_LOG "/tmp/aim-bx.log"

/* Twice the actual length, we should never have problems */
#define MAX_STATUS_MSG_LEN 4096
#define cparse convert_output_format

/* Macro Fun */
#define CHECK_TOC_ONLINE() if ( state != STATE_ONLINE ) { statusprintf("Please connect to aim first (/asignon)"); return; }
#define VALID_ARG(x) !(!x || ! *x || ! strcasecmp(x,""))
#define REQUIRED_ARG(x,y,z) if ( ! VALID_ARG(x) ) { userage(y,z); return; }


/* cmd.c */

void asignon(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg);
void asignoff(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void amsg(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void abl(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg);
void apd(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg);
void awarn(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void apermdeny(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void aspermdeny(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void aarpermitdeny(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void awhois(IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void asave (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void achat (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void adir (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void aaway (IrcCommandDll *intp, char *command, char *args, char *subargs, char *helparg);
void aquery(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg);
void ainfo(IrcCommandDll *intp, char *command, char *args, char *subargs,char *helparg);
void achange_idle(Window *w, char *s, int i);

extern char current_chat[512];
extern char away_message[2048];
extern LL msgdus;
extern LL msgdthem;


/* toc.c */
void bx_init_toc();
int toc_add_input_stream(int fd,int (*func)(int));
int toc_remove_input_stream(int fd) ;
int toc_main_interface(int type, char **args);
int toc_timer(int type, char **args);

extern void (*chatprintf)(char *, ...);


/* aim.c */
#ifdef BITCHX_PATCH
char * amsg_complete_func(int, char *, int *, char **);
char * get_next_buddy_complete();
int do_aim_tabkey_overwrite(int x, char *p, int *c, char **s);
char * aim_tabkey_overwrite(int x, char *p, int *c, char **s);
#endif
void update_aim_window(Window *tmp);
int build_aim_status(Window *tmp);
void toggle_aimwin_hide (Window *win, char *unused, int onoff);
void toggle_aimwin (Window *win, char *unused, int onoff);
int Aim_Cleanup(IrcCommandDll **interp, Function_ptr *global_table);
int Aim_Init(IrcCommandDll **interp, Function_ptr *global_table);
char *Aim_Version(IrcCommandDll *intp);

extern char *name;
extern char *timer_id;
#ifdef BITCHX_PATCH
struct tab_key_struct {
	int list;
	int pos;
	int subpos;
};
extern struct tab_key_struct tks;
#endif


/* util.c */

void statusprintf(char *fmt, ...);
void statusput(int log_type, char *buf);
void msgprintf(char *fmt, ...);
void debug_printf(char *fmt, ...);
char *rm_space(char *s);

#endif /* _AIM_H */

--- NEW FILE: util.c ---
/*
 * AOL Instant Messanger Module for BitchX 
 *
 * By Nadeem Riaz (nads at bleh.org)
 *
 * util.c
 *
 * utility/misc functions
 */

#include <irc.h>
#include <struct.h>
#include <hook.h>
#include <ircaux.h>
#include <output.h>
#include <lastlog.h>
#include <status.h>
#include <vars.h>
#include <window.h>
#include <module.h>
#include <modval.h>

#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "toc.h"
#include "aim.h"


void statusprintf(char *fmt, ...)
{
        char data[MAX_STATUS_MSG_LEN];
	char *sfmt, *prompt;
	va_list ptr;
	
	/* Tack on prompt */
	prompt = get_dllstring_var("aim_prompt");
	sfmt = (char *) malloc(strlen(prompt) + strlen(fmt)+5);	
	strcpy(sfmt,prompt);
	strcat(sfmt," ");
	strcat(sfmt,fmt);
	
        va_start(ptr, fmt);
        vsnprintf(data, MAX_STATUS_MSG_LEN - 1 , sfmt, ptr);
        va_end(ptr);
	free(sfmt);
        statusput(LOG_CRAP,data);
        return;  
}

void statusput(int log_type, char *buf) {	
	int lastlog_level;
	lastlog_level = set_lastlog_msg_level(log_type);

	if (get_dllint_var("aim_window") > 0)
		if (!(target_window = get_window_by_name("AIM")))
			target_window = current_window;
	
	if (window_display && buf)
	{
		add_to_log(irclog_fp, 0, buf, 0);
		add_to_screen(buf);
	}

	target_window = NULL;
	set_lastlog_msg_level(lastlog_level);
	return;
}

void msgprintf(char *fmt, ...)
{
        char data[MAX_STATUS_MSG_LEN];
	va_list ptr;
	
        va_start(ptr, fmt);
        vsnprintf(data, MAX_STATUS_MSG_LEN - 1 , fmt, ptr);
        va_end(ptr);
        statusput(LOG_CRAP,data);
        return;  
}

void debug_printf(char *fmt, ...)
{
#ifdef DEBUG_AIM
	FILE *fp;
        char data[MAX_OUTPUT_MSG_LEN];
        va_list ptr;	
	if ( ! (fp=fopen(AIM_DEBUG_LOG,"a")) ) {
		perror("ERROR couldn't open debug log file!@$\n");
	}	
        va_start(ptr, fmt);
        vsnprintf(data, MAX_OUTPUT_MSG_LEN - 1 , fmt, ptr);
        va_end(ptr);
	fprintf(fp,"%s\n",data);
	fflush(fp);
        fclose(fp);
        return;  
#endif
}

char *rm_space(char *s) {
	char *rs;
	int x,y;
	rs = (char *) malloc(strlen(s) + 1);	
	x = y = 0;
	
	for (x =0; x<strlen(s);x++) {
		if ( s[x] != ' ' ) {  
			rs[y] = s[x];
			y++;
		}
	}
	rs[y] = '\0';
	return rs;
}

/* 
 * Still dont like split args routines in bitchx (new_next_arg)
 * It doesnt allow for args with "'s in them, next_arg doesnt allow
 * for args with spaces !@$. Need a *real* split routne that can handle
 * both (with escaping)
 */

/*
char **split_args(char *args,int max;) {
	int x;
	char *list[32];
	int arg = 0;
	int escape  = 0;
	int open_quote = 0;
	for (x=0;x<strlen(args);x++) {
		if ( args[x] == '\' ) {
			if ( ! escape ) {
				escape = 1;
				continue;
			}
		} else ( ! escape && args[x] == '"' ) {
			if ( open_quote ) {
				push(@args,$warg);
				$warg ="";
				arg++;
				$argbegin = $x+1;
				open_quote = 0;
			} else {
				open_quote = 1;
			}
			continue;
		} elsif ( ! $escape && ! $open_quote && substr($text,$x,1) eq " " ) {
			if ( ! $space ) {
				push(@args,$warg);
				$warg ="";
				$arg++;				
				$space = 1;
			}
			$argbegin = $x+1;
			next;
		} 
		if ( $space ) {
			$argbegin = $x;
			$space = 0;			
		} elsif ( $escape ) {
			$escape = 0;
		}
		$warg .= substr($text,$x,1);
	}		
	}
}


*/




More information about the dslinux-commit mailing list