Example #1
0
File: perl.c Project: Farow/hexchat
/* Xchat::Internal::hook_fd(fd, callback, flags, userdata) */
static
XS (XS_Xchat_hook_fd)
{
	int fd;
	SV *callback;
	int flags;
	SV *userdata;
	SV *package;
	hexchat_hook *hook;
	HookData *data;

	dXSARGS;

	if (items != 5) {
		hexchat_print (ph,
						 "Usage: Xchat::Internal::hook_fd(fd, callback, flags, userdata)");
	} else {
		fd = (int) SvIV (ST (0));
		callback = ST (1);
		flags = (int) SvIV (ST (2));
		userdata = ST (3);
		package = ST (4);
		data = NULL;

#ifdef WIN32
		if ((flags & HEXCHAT_FD_NOTSOCKET) == 0) {
			/* this _get_osfhandle if from win32iop.h in the perl distribution,
			 *  not the one provided by Windows
			 */ 
			fd = _get_osfhandle(fd);
			if (fd < 0) {
				hexchat_print(ph, "Invalid file descriptor");
				XSRETURN_UNDEF;
			}
		}
#endif

		data = malloc (sizeof (HookData));
		if (data == NULL) {
			XSRETURN_UNDEF;
		}

		data->callback = newSVsv (callback);
		data->userdata = newSVsv (userdata);
		data->depth = 0;
		data->package = newSVsv (package);
		hook = hexchat_hook_fd (ph, fd, flags, fd_cb, data);
		data->hook = hook;

		XSRETURN_IV (PTR2IV (hook));
	}
}
Example #2
0
File: perl.c Project: Farow/hexchat
/* Xchat::print(output) */
static
XS (XS_Xchat_print)
{

	char *text = NULL;

	dXSARGS;
	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::Internal::print(text)");
	} else {
		text = SvPV_nolen (ST (0));
		hexchat_print (ph, text);
	}
	XSRETURN_EMPTY;
}
Example #3
0
void loadThemes() {
    char *hDir, *hFile, *line, *lineCap, *val;
    FILE *f;
    hexchat_print(ph,"loading themes\n");
    hDir=(char*)calloc(1024,sizeof(char));
    strcpy(hDir,hexchat_get_info(ph,"configdir"));
    hFile=str3cat(hDir,"\\","mpcInfo.theme.txt");
    f = fopen(hFile,"r");
    free(hDir);
    free(hFile);
    if(f==NULL)
    {
        hexchat_print(ph,"no theme in homedir, checking global theme");
        f=fopen("mpcInfo.theme.txt","r");
    }
    //hexchat_printf(ph,"file_desc: %p\n",f);
    if (f==NULL) hexchat_print(ph, "no theme found, using hardcoded\n");
    else {
        if (f > 0)
        {
            line=" ";
        } else
        {
            line="\0";
        }

        while (line[0]!=0)
        {
            line=readLine(f);
            val=split(line,'=');
            printf("line: %s\n",line);
            printf("val: %s\n",val);
            lineCap=toUpper(line);
            if (strcmp(lineCap,"OFF_LINE")==0) notRunTheme=themeAdd(notRunTheme,val);
            if (strcmp(lineCap,"TITLE_LINE")==0) titleTheme=themeAdd(titleTheme,val);
            if (strcmp(lineCap,"MP3_LINE")==0) mp3Theme=themeAdd(mp3Theme,val);
            if (strcmp(lineCap,"OGG_LINE")==0) mp3Theme=themeAdd(oggTheme,val);
            free(lineCap);
        }
        fclose(f);
        hexchat_print(ph, "theme loaded successfull\n");
    }
    if (notRunTheme.size==0) notRunTheme=themeAdd(notRunTheme,"Media Player Classic not running");
    if (titleTheme.size==0) titleTheme=themeAdd(titleTheme,"say Playing %title in Media Player Classic");
    if (mp3Theme.size==0) mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%mode] in Media Player Classic ");
    if (oggTheme.size==0) oggTheme=themeAdd(oggTheme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%chan channels] in Media Player Classic ");
    //mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%time|%length|%perc%|%br kbps|%frq kHz|%mode] in Media Player Classic ");
}
Example #4
0
File: lua.c Project: Cynede/hexchat
G_MODULE_EXPORT int hexchat_plugin_deinit(hexchat_plugin *plugin_handle)
{
	guint i;
	gboolean active = FALSE;
	for(i = 0; i < scripts->len; i++)
	{
		if(((script_info*)scripts->pdata[i])->status & STATUS_ACTIVE)
		{
			active = TRUE;
			break;
		}
	}
	if(interp && interp->status & STATUS_ACTIVE)
		active = TRUE;
	if(active)
	{
		hexchat_print(ph, "\00304Cannot unload the lua plugin while there are active states");
		return 0;
	}
	if(interp)
		run_unload_hooks(interp, NULL);
	destroy_interpreter();
	g_ptr_array_foreach(scripts, (GFunc)run_unload_hooks, NULL);
	g_clear_pointer(&scripts, g_ptr_array_unref);
	g_clear_pointer(&expand_buffer, g_free);
	return 1;
}
Example #5
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_unhook)
{
	hexchat_hook *hook;
	HookData *userdata;
	int retCount = 0;
	dXSARGS;
	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::unhook(hook)");
	} else {
		hook = INT2PTR (hexchat_hook *, SvUV (ST (0)));
		userdata = (HookData *) hexchat_unhook (ph, hook);

		if (userdata != NULL) {
			if (userdata->callback != NULL) {
				SvREFCNT_dec (userdata->callback);
			}

			if (userdata->userdata != NULL) {
				XPUSHs (sv_mortalcopy (userdata->userdata));
				SvREFCNT_dec (userdata->userdata);
				retCount = 1;
			}

			if (userdata->package != NULL) {
				SvREFCNT_dec (userdata->package);
			}

			free (userdata);
		}
		XSRETURN (retCount);
	}
	XSRETURN_EMPTY;
}
Example #6
0
struct tagInfo readHeader(char *file){
//if (DEBUG==1) putlog("reading header");
	FILE *f;
	//int buffer[5120];
	int versionB, layerB, bitrateB, freqB, modeB;
	int header[4];
	int count=0;
	int cc=0;
	struct tagInfo info;
	info.artist=NULL;

	f = fopen(file,"rb");
	if (f==NULL)
	{
       hexchat_print(ph,"file not found while trying to read mp3 header");
       //if (DEBUG==1) putlog("file not found while trying to read mp3 header");
       return info;
    }
	//struct tagInfo tagv2
	
	info=readID3V2(file);
	//struct tagInfo tagv1;//=readID3V1(file);
	//if 	(tagv2.artist!=NULL){info=tagv2;}
	//else {
	if (info.artist==NULL){
		//printf("searching for id3v1\n");
		//tagv1=readID3V1(file);
		info=readID3V1(file); //#####################
	}
	/*
	if (tagv1.artist!=NULL){
		//printf("Artist: %s\nTitle: %s\nAlbum: %s\nComment: %s\nGenre: %s\n",tagv1.artist,tagv1.title,tagv1.album,tagv1.comment,tagv1.genre);
		info=tagv1;
	}
	*/
	while ((count<5120)&&(cc!=EOF)&&(cc!=255)) {cc=fgetc(f);count++;}
	if ((cc==EOF)||(count==5119)) printf("no header found\n");
	else {
		//printf("located header at %i\n",count);
		header[0]=255;
		for (count=1;count<4;count++){
			header[count]=fgetc(f);
			//printf("header[%i]=%i\n",count,header[count]);
		}
		versionB=(header[1]&8)>>3;
		layerB=(header[1]&6)>>1;
		bitrateB=(header[2]&240)>>4; //4
		freqB=(header[2]&12)>>2;//2
		modeB=(header[3]&192)>>6;//6
		//printf("Mpeg: %i\nLayer: %i\nBitrate: %i\nFreq: %i\nMode: %i\n",versionB, layerB, bitrateB, freqB, modeB);
		//int Bitrate=RATES[versionB][layerB-1][bitrateB];
		//int Freq=FREQS[versionB][freqB];
		info.bitrate=RATES[versionB][layerB-1][bitrateB];
		info.freq=FREQS[versionB][freqB];
		info.mode=modeB;	
	}
	fclose(f);
	//if (DEBUG==1) putlog("header readed");
	return info;
}
Example #7
0
int
hexchat_plugin_deinit(void)
{
	hexchat_command (ph, "MENU DEL \"Window/Display Current Song (Winamp)\"");
	hexchat_print (ph, "Winamp plugin unloaded\n");
	return 1;
}
Example #8
0
File: lua.c Project: Cynede/hexchat
static void inject_string(script_info *info, char const *line)
{
	lua_State *L = info->state;
	int base, top;
	char *ret_line;
	gboolean force_ret = FALSE;

	if(line[0] == '=')
	{
		line++;
		force_ret = TRUE;
	}
	ret_line = g_strconcat("return ", line, NULL);

	lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback);
	base = lua_gettop(L);
	if(luaL_loadbuffer(L, ret_line, strlen(ret_line), "@interpreter"))
	{
		if(!force_ret)
			lua_pop(L, 1);
		if(force_ret || luaL_loadbuffer(L, line, strlen(line), "@interpreter"))
		{
			hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, ""));
			lua_pop(L, 2);
			g_free(ret_line);
			return;
		}
	}
	g_free(ret_line);
	info->status |= STATUS_ACTIVE;
	if(lua_pcall(L, 0, LUA_MULTRET, base))
	{
		char const *error = lua_tostring(L, -1);
		lua_pop(L, 2);
		hexchat_printf(ph, "Lua error: %s", error ? error : "(non-string error)");
		return;
	}
	top = lua_gettop(L);
	if(top > base)
	{
		int i;
		luaL_Buffer b;
		luaL_buffinit(L, &b);
		for(i = base + 1; i <= top; i++)
		{
			if(i != base + 1)
				luaL_addstring(&b, " ");
			tostring(L, i);
			luaL_addvalue(&b);
		}
		luaL_pushresult(&b);
		hexchat_print(ph, lua_tostring(L, -1));
		lua_pop(L, top - base + 1);
	}
	lua_pop(L, 1);
	check_deferred(info);
}
Example #9
0
struct tagInfo readID3V2(char *file){
//if (DEBUG==1) putlog("reading id3v2");
	FILE *f;
	int i, c, len;
	char header[10];
	char *tag;
	struct tagInfo ret;

	f = fopen(file,"rb");
	//hexchat_printf(ph,"file :%s",file);
	if (f==NULL)
	{
       hexchat_print(ph,"file not found whilt trying to read ID3V2");
       //if (DEBUG==1)putlog("file not found while trying to read ID3V2");
       return ret;
    }

	ret.artist=NULL;
	for (i=0;i<10;i++){
        c=fgetc(f);
        if (c==EOF){
            fclose(f);
           //putlog("found eof while reading id3v2");
           return ret;
        }
        header[i]=(char)c;
    }
	if (strstr(header,"ID3")==header){
		//hexchat_printf(ph,"found id3v2\n");
		len=0;
		for (i=6;i<10;i++) len+=(int)header[i]*iPow(256,9-i);
		
		//char *tag=(char*)malloc(sizeof(char)*len);
		tag=(char*) calloc(len,sizeof(char)); //malloc(sizeof(char)*len);
		for (i=0;i<len;i++){c=fgetc(f);tag[i]=(char)c;}
//hexchat_printf(ph,"tag length: %i\n",len);
//hexchat_printf(ph,"tag: %s\n",tag);
		fclose(f);
		ret.comment=tagExtract(tag,len,"COMM");
//hexchat_printf(ph,"Comment: %s\n",ret.comment);
		ret.genre=tagExtract(tag,len,"TCON");
		//if (strcmp(ret.genre,"(127)")==0) ret.genre="unknown";
//hexchat_printf(ph, "ret.genre = %s",ret.genre);
		if ((ret.genre!=NULL)&&(ret.genre[0]=='(')) ret.genre=extractID3Genre(ret.genre);
//hexchat_printf(ph,"genre: %s\n",ret.genre);
		ret.title=tagExtract(tag,len,"TIT2");
//hexchat_printf(ph,"Title: %s\n",ret.title);
		ret.album=tagExtract(tag,len,"TALB");
//hexchat_printf(ph,"Album: %s\n",ret.album);
		ret.artist=tagExtract(tag,len,"TPE1");
//hexchat_printf(ph,"Artist: %s\n",ret.artist);
	}
	else{fclose(f);printf("no id3v2 tag found\n"); return ret;}
	//printf("id2v2 done\n");
	//if (DEBUG==1) putlog("id3v2 readed");
	return ret;
}
Example #10
0
File: perl.c Project: Farow/hexchat
static int
fd_cb (int fd, int flags, void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (data->userdata);
	PUTBACK;

	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL);
	set_current_package (&PL_sv_undef);
	SPAGAIN;

	if (SvTRUE (ERRSV)) {
		hexchat_printf (ph, "Error in fd callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = HEXCHAT_EAT_ALL;
	} else {
		if (count != 1) {
			hexchat_print (ph, "Fd handler should only return 1 value.");
			retVal = HEXCHAT_EAT_NONE;
		} else {
			retVal = POPi;
			if (retVal == 0) {
				/* if 0 is returned, the fd is going to get unhooked */
				PUSHMARK (SP);
				XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook))));
				PUTBACK;

				call_pv ("Xchat::unhook", G_EVAL);
				SPAGAIN;

				SvREFCNT_dec (data->callback);

				if (data->userdata) {
					SvREFCNT_dec (data->userdata);
				}
				free (data);
			}
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Example #11
0
static void cmd_start (const char *nick)
{
	if (get_current_context_type () != 3)
	{
		hexchat_print (ph, "OTR: You can only use OTR in a dialog\n");
		return;
	}

	hexchat_commandf (ph, "quote PRIVMSG %s :?OTRv23?", nick);
}
Example #12
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_get_context)
{
	dXSARGS;
	if (items != 0) {
		hexchat_print (ph, "Usage: Xchat::get_context()");
	} else {
		XSRETURN_IV (PTR2IV (hexchat_get_context (ph)));
	}
}
Example #13
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_find_context)
{
	char *server = NULL;
	char *chan = NULL;
	hexchat_context *RETVAL;

	dXSARGS;
	if (items > 2)
		hexchat_print (ph, "Usage: Xchat::find_context ([channel, [server]])");
	{

		switch (items) {
		case 0:						  /* no server name and no channel name */
			/* nothing to do, server and chan are already NULL */
			break;
		case 1:						  /* channel name only */
			/* change channel value only if it is true or 0 */
			/* otherwise leave it as null */
			if (SvTRUE (ST (0)) || SvNIOK (ST (0))) {
				chan = SvPV_nolen (ST (0));
				/*                               hexchat_printf( ph, "XSUB - find_context( %s, NULL )", chan ); */
			}
			/* else { hexchat_print( ph, "XSUB - find_context( NULL, NULL )" ); } */
			/* chan is already NULL */
			break;
		case 2:						  /* server and channel */
			/* change channel value only if it is true or 0 */
			/* otherwise leave it as NULL */
			if (SvTRUE (ST (0)) || SvNIOK (ST (0))) {
				chan = SvPV_nolen (ST (0));
				/*                               hexchat_printf( ph, "XSUB - find_context( %s, NULL )", SvPV_nolen(ST(0) )); */
			}

			/* else { hexchat_print( ph, "XSUB - 2 arg NULL chan" ); } */
			/* change server value only if it is true or 0 */
			/* otherwise leave it as NULL */
			if (SvTRUE (ST (1)) || SvNIOK (ST (1))) {
				server = SvPV_nolen (ST (1));
				/*                               hexchat_printf( ph, "XSUB - find_context( NULL, %s )", SvPV_nolen(ST(1) )); */
			}
			/*  else { hexchat_print( ph, "XSUB - 2 arg NULL server" ); } */
			break;
		}

		RETVAL = hexchat_find_context (ph, server, chan);
		if (RETVAL != NULL) {
			/*                      hexchat_print (ph, "XSUB - context found"); */
			XSRETURN_IV (PTR2IV (RETVAL));
		} else {
			/*           hexchat_print (ph, "XSUB - context not found"); */
			XSRETURN_UNDEF;
		}
	}
}
Example #14
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_nickcmp)
{
	dXSARGS;
	if (items != 2) {
		hexchat_print (ph, "Usage: Xchat::nickcmp(s1, s2)");
	} else {
		XSRETURN_IV ((IV) hexchat_nickcmp (ph, SvPV_nolen (ST (0)),
													SvPV_nolen (ST (1))));
	}
}
Example #15
0
static int
timer_cb (void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (data->userdata);
	PUTBACK;

	if (data->ctx) {
		hexchat_set_context (ph, data->ctx);
	}

	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL);
	set_current_package (&PL_sv_undef);
	SPAGAIN;

	if (SvTRUE (ERRSV)) {
		hexchat_printf (ph, "Error in timer callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = HEXCHAT_EAT_ALL;
	} else {
		if (count != 1) {
			hexchat_print (ph, "Timer handler should only return 1 value.");
			retVal = HEXCHAT_EAT_NONE;
		} else {
			retVal = POPi;
			if (retVal == 0) {
				/* if 0 is return the timer is going to get unhooked */
				PUSHMARK (SP);
				XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook))));
				XPUSHs (sv_mortalcopy (data->package));
				PUTBACK;

				call_pv ("HexChat::unhook", G_EVAL);
				SPAGAIN;
			}
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Example #16
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_emit_print)
{
	char *event_name;
	int RETVAL;
	int count;

	dXSARGS;
	if (items < 1) {
		hexchat_print (ph, "Usage: Xchat::emit_print(event_name, ...)");
	} else {
		event_name = (char *) SvPV_nolen (ST (0));
		RETVAL = 0;

		/* we need to figure out the number of defined values passed in */
		for (count = 0; count < items; count++) {
			if (!SvOK (ST (count))) {
				break;
			}
		}

		switch (count) {
		case 1:
			RETVAL = hexchat_emit_print (ph, event_name, NULL);
			break;
		case 2:
			RETVAL = hexchat_emit_print (ph, event_name,
												SvPV_nolen (ST (1)), NULL);
			break;
		case 3:
			RETVAL = hexchat_emit_print (ph, event_name,
												SvPV_nolen (ST (1)),
												SvPV_nolen (ST (2)), NULL);
			break;
		case 4:
			RETVAL = hexchat_emit_print (ph, event_name,
												SvPV_nolen (ST (1)),
												SvPV_nolen (ST (2)),
												SvPV_nolen (ST (3)), NULL);
			break;
		case 5:
			RETVAL = hexchat_emit_print (ph, event_name,
												SvPV_nolen (ST (1)),
												SvPV_nolen (ST (2)),
												SvPV_nolen (ST (3)),
												SvPV_nolen (ST (4)), NULL);
			break;

		}

		XSRETURN_IV (RETVAL);
	}
}
Example #17
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_set_context)
{
	hexchat_context *ctx;
	dXSARGS;
	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::set_context(ctx)");
	} else {
		ctx = INT2PTR (hexchat_context *, SvUV (ST (0)));
		XSRETURN_IV ((IV) hexchat_set_context (ph, ctx));
	}
}
Example #18
0
struct tagInfo readID3V1(char *file){
//if (DEBUG==1) putlog("reading ID3V1");
	FILE *f;
	struct tagInfo ret;
	int res, i, c, val;
	char *tag;
	char *id;
	char *tmp;
	tag = (char*) malloc(sizeof(char)*129);
	ret.artist=NULL;
	f=fopen(file,"rb");
	if (f==NULL){
       hexchat_print(ph,"file not found while trying to read id3v1");
       //if (DEBUG==1) putlog("file not found while trying to read id3v1");
       return ret;
    }
	//int offset=getSize(file)-128;
	res=fseek(f,-128,SEEK_END);
	if (res!=0) {printf("seek failed\n");fclose(f);return ret;}
	//long int pos=ftell(f);
	//printf("position= %li\n",pos);
	for (i=0;i<128;i++) {
		c=fgetc(f);
		if (c==EOF) {hexchat_printf(ph,"read ID3V1 failed\n");fclose(f);return ret;}
		tag[i]=(char)c;
	}
	fclose(f);
	//printf("tag readed: \n");
	id=substring(tag,0,3);
	//printf("header: %s\n",id);
	if (strcmp(id,"TAG")!=0){hexchat_printf(ph,"no id3 v1 found\n");return ret;}
	ret.title=subString(tag,3,30,1);
	ret.artist=subString(tag,33,30,1);
	ret.album=subString(tag,63,30,1);
	ret.comment=subString(tag,97,30,1);
	tmp=substring(tag,127,1);
	//ret.genre=substring(tag,127,1);
	
	val=(int)tmp[0];
	if (val<0)val+=256;
	//hexchat_printf(ph, "tmp[0]=%i (%i)",val,tmp[0]);
	if ((val<148)&&(val>=0)) 
       ret.genre=GENRES[val];//#############changed
	else {
         ret.genre="unknown";
         //hexchat_printf(ph, "tmp[0]=%i (%i)",val,tmp[0]);
    }
	//hexchat_printf(ph, "tmp: \"%s\" -> %i",tmp,tmp[0]);
	//hexchat_printf(ph,"genre \"%s\"",ret.genre);
	//if (DEBUG==1) putlog("id3v1 extracted");
	return ret;
}
Example #19
0
File: lua.c Project: Cynede/hexchat
static script_info *create_script(char const *file)
{
	int base;
	char *filename_fs;
	lua_State *L;
	script_info *info = g_new0(script_info, 1);
	info->hooks = g_ptr_array_new_with_free_func((GDestroyNotify)free_hook);
	info->unload_hooks = g_ptr_array_new_with_free_func((GDestroyNotify)free_hook);
	info->filename = g_strdup(expand_path(file));
	L = luaL_newstate();
	info->state = L;
	if(!L)
	{
		hexchat_print(ph, "\00304Could not allocate memory for the script");
		destroy_script(info);
		return NULL;
	}
	prepare_state(L, info);
	lua_rawgeti(L, LUA_REGISTRYINDEX, info->traceback);
	base = lua_gettop(L);
	filename_fs = g_filename_from_utf8(info->filename, -1, NULL, NULL, NULL);
	if(!filename_fs)
	{
		hexchat_printf(ph, "Invalid filename: %s", info->filename);
		destroy_script(info);
		return NULL;
	}
	if(luaL_loadfile(L, filename_fs))
	{
		g_free(filename_fs);
		hexchat_printf(ph, "Lua syntax error: %s", luaL_optstring(L, -1, ""));
		destroy_script(info);
		return NULL;
	}
	g_free(filename_fs);
	info->status |= STATUS_ACTIVE;
	if(lua_pcall(L, 0, 0, base))
	{
		char const *error = lua_tostring(L, -1);
		hexchat_printf(ph, "Lua error: %s", error ? error : "(non-string error)");
		destroy_script(info);
		return NULL;
	}
	lua_pop(L, 1);
	if(!info->name)
	{
		hexchat_printf(ph, "Lua script didn't register with hexchat.register");
		destroy_script(info);
		return NULL;
	}
	return info;
}
Example #20
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_send_modes)
{
	AV *p_targets = NULL;
	int modes_per_line = 0;
	char sign;
	char mode;
	int i = 0;
	const char **targets;
	int target_count = 0;
	SV **elem;

	dXSARGS;
	if (items < 3 || items > 4) {
		hexchat_print (ph,
			"Usage: Xchat::send_modes( targets, sign, mode, modes_per_line)"
		);
	} else {
		if (SvROK (ST (0))) {
			p_targets = (AV*) SvRV (ST (0));
			target_count = av_len (p_targets) + 1;
			targets = malloc (target_count * sizeof (char *));
			for (i = 0; i < target_count; i++ ) {
				elem = av_fetch (p_targets, i, 0);

				if (elem != NULL) {
					targets[i] = SvPV_nolen (*elem);
				} else {
					targets[i] = "";
				}
			}
		} else{
			targets = malloc (sizeof (char *));
			targets[0] = SvPV_nolen (ST (0));
			target_count = 1;
		}
		
		if (target_count == 0) {
			XSRETURN_EMPTY;
		}

		sign = (SvPV_nolen (ST (1)))[0];
		mode = (SvPV_nolen (ST (2)))[0];

		if (items == 4 ) {
			modes_per_line = (int) SvIV (ST (3)); 
		}

		hexchat_send_modes (ph, targets, target_count, modes_per_line, sign, mode);
		free (targets);
	}
}
Example #21
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_Embed_plugingui_remove)
{
	void *gui_entry;
	dXSARGS;
	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::Embed::plugingui_remove(handle)");
	} else {
		gui_entry = INT2PTR (void *, SvUV (ST (0)));
		hexchat_plugingui_remove (ph, gui_entry);
	}
	XSRETURN_EMPTY;
}
Example #22
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_context_info)
{
	const char *const *fields;
	dXSARGS;

	if (items > 0 ) {
		hexchat_print (ph, "Usage: Xchat::Internal::context_info()");
	}
	fields = hexchat_list_fields (ph, "channels" );
	XPUSHs (list_item_to_sv (NULL, fields));
	XSRETURN (1);
}
Example #23
0
void
hexchat_printf (hexchat_plugin *ph, const char *format, ...)
{
	va_list args;
	char *buf;

	va_start (args, format);
	buf = g_strdup_vprintf (format, args);
	va_end (args);

	hexchat_print (ph, buf);
	g_free (buf);
}
Example #24
0
File: perl.c Project: Farow/hexchat
/* Xchat::Internal::command(command) */
static
XS (XS_Xchat_command)
{
	char *cmd = NULL;

	dXSARGS;
	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::Internal::command(command)");
	} else {
		cmd = SvPV_nolen (ST (0));
		hexchat_command (ph, cmd);

	}
	XSRETURN_EMPTY;
}
Example #25
0
File: perl.c Project: Farow/hexchat
static int
command_cb (char *word[], char *word_eol[], void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;
	
	if (data->depth)
		return HEXCHAT_EAT_NONE;

	/*               hexchat_printf (ph, "Recieved %d words in command callback", */
	/*                               av_len (wd)); */
	PUSHMARK (SP);
	XPUSHs (newRV_noinc ((SV *) array2av (word)));
	XPUSHs (newRV_noinc ((SV *) array2av (word_eol)));
	XPUSHs (data->userdata);
	PUTBACK;

	data->depth++;
	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL);
	set_current_package (&PL_sv_undef);
	data->depth--;
	SPAGAIN;
	if (SvTRUE (ERRSV)) {
		hexchat_printf (ph, "Error in command callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = HEXCHAT_EAT_HEXCHAT;
	} else {
		if (count != 1) {
			hexchat_print (ph, "Command handler should only return 1 value.");
			retVal = HEXCHAT_EAT_NONE;
		} else {
			retVal = POPi;
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Example #26
0
File: lua.c Project: Cynede/hexchat
static int api_hexchat_print(lua_State *L)
{
	int i, args = lua_gettop(L);
	luaL_Buffer b;
	luaL_buffinit(L, &b);
	for(i = 1; i <= args; i++)
	{
		if(i != 1)
			luaL_addstring(&b, " ");
		tostring(L, i);
		luaL_addvalue(&b);
	}
	luaL_pushresult(&b);
	hexchat_print(ph, lua_tostring(L, -1));
	return 0;
}
Example #27
0
File: perl.c Project: Farow/hexchat
/* Xchat::Internal::hook_command(name, priority, callback, help_text, userdata) */
static
XS (XS_Xchat_hook_command)
{
	char *name;
	int pri;
	SV *callback;
	char *help_text = NULL;
	SV *userdata;
	SV *package;
	hexchat_hook *hook;
	HookData *data;

	dXSARGS;

	if (items != 6) {
		hexchat_print (ph,
						 "Usage: Xchat::Internal::hook_command(name, priority, callback, help_text, userdata, package)");
	} else {
		name = SvPV_nolen (ST (0));
		pri = (int) SvIV (ST (1));
		callback = ST (2);

		/* leave the help text as NULL if the help text is undefined to avoid
		 * overriding the default help message for builtin commands */
		if (SvOK(ST (3))) {
			help_text = SvPV_nolen (ST (3));
		}

		userdata = ST (4);
		package = ST (5);
		data = NULL;

		data = malloc (sizeof (HookData));
		if (data == NULL) {
			XSRETURN_UNDEF;
		}

		data->callback = newSVsv (callback);
		data->userdata = newSVsv (userdata);
		data->depth = 0;
		data->package = newSVsv (package);
		hook = hexchat_hook_command (ph, name, pri, command_cb, help_text, data);

		XSRETURN_IV (PTR2IV (hook));
	}

}
Example #28
0
File: lua.c Project: Cynede/hexchat
static int load_script(char const *file)
{
	script_info *info = get_script_by_file(file);

	if (info != NULL)
	{
		hexchat_print(ph, "Lua script is already loaded");
		return 0;
	}

	info = create_script(file);
	if (info)
	{
		g_ptr_array_add(scripts, info);
		check_deferred(info);
	}

	return 1;
}
Example #29
0
int
hexchat_plugin_init(hexchat_plugin *plugin_handle,
                      char **plugin_name,
                      char **plugin_desc,
                      char **plugin_version,
                      char *arg)
{
	/* we need to save this for use with any hexchat_* functions */
	ph = plugin_handle;

	*plugin_name = "Winamp";
	*plugin_desc = "Winamp plugin for HexChat";
	*plugin_version = "0.5";

	hexchat_hook_command (ph, "WINAMP", HEXCHAT_PRI_NORM, winamp, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START] - control Winamp or show what's currently playing", 0);
   	hexchat_command (ph, "MENU -ishare\\music.png ADD \"Window/Display Current Song (Winamp)\" \"WINAMP\"");

	hexchat_print (ph, "Winamp plugin loaded\n");

	return 1;       /* return 1 for success */
}
Example #30
0
File: perl.c Project: Farow/hexchat
static
XS (XS_Xchat_get_list)
{
	SV *name;
	hexchat_list *list;
	const char *const *fields;
	int count = 0;					  /* return value for scalar context */
	dXSARGS;

	if (items != 1) {
		hexchat_print (ph, "Usage: Xchat::get_list(name)");
	} else {
		SP -= items;				  /*remove the argument list from the stack */

		name = ST (0);

		list = hexchat_list_get (ph, SvPV_nolen (name));

		if (list == NULL) {
			XSRETURN_EMPTY;
		}

		if (GIMME_V == G_SCALAR) {
			while (hexchat_list_next (ph, list)) {
				count++;
			}
			hexchat_list_free (ph, list);
			XSRETURN_IV ((IV) count);
		}

		fields = hexchat_list_fields (ph, SvPV_nolen (name));
		while (hexchat_list_next (ph, list)) {
			XPUSHs (list_item_to_sv (list, fields));
		}
		hexchat_list_free (ph, list);

		PUTBACK;
		return;
	}
}