void HRA_fetch_a(SV *self, SV *attr, char *t) { dXSARGS; SP -= 3; if(GIMME_V == G_VOID) { XSRETURN(0); } SV *aobj = attr_get(self, attr, t, 0); if(!aobj) { HR_DEBUG("Can't find attribute!"); XSRETURN_EMPTY; } else { HR_DEBUG("Found aobj=%p", aobj); } hrattr_simple *aptr = attr_from_sv(SvRV(aobj)); HR_DEBUG("Attrhash=%p", aptr->attrhash); int nkeys = hv_iterinit(aptr->attrhash); HR_DEBUG("We have %d keys", nkeys); if(GIMME_V == G_SCALAR) { HR_DEBUG("Scalar return value requested"); XSRETURN_IV(nkeys); } HR_DEBUG("Will do some stack voodoo"); EXTEND(sp, nkeys); HE *cur = hv_iternext(aptr->attrhash); for(; cur != NULL; cur = hv_iternext(aptr->attrhash)) { XPUSHs(sv_mortalcopy(hv_iterval(aptr->attrhash, cur))); } PUTBACK; }
static XS (XS_Xchat_get_info) { SV *temp = NULL; dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::get_info(id)"); } else { SV *id = ST (0); const char *RETVAL; RETVAL = xchat_get_info (ph, SvPV_nolen (id)); if (RETVAL == NULL) { XSRETURN_UNDEF; } if (!strncmp ("win_ptr", SvPV_nolen (id), 7)) { XSRETURN_IV (PTR2IV (RETVAL)); } else { if ( !strncmp ("libdirfs", SvPV_nolen (id), 8) || !strncmp ("xchatdirfs", SvPV_nolen (id), 10) ) { XSRETURN_PV (RETVAL); } else { temp = newSVpv (RETVAL, 0); SvUTF8_on (temp); PUSHMARK (SP); XPUSHs (sv_2mortal (temp)); PUTBACK; } } } }
static XS (XS_HexChat_plugin_pref_delete) { dMARK; dAX; XSRETURN_IV ((IV) hexchat_pluginpref_delete (ph, SvPV_nolen (ST (0)))); }
static XS (XS_HexChat_plugin_pref_set) { dMARK; dAX; XSRETURN_IV ((IV) hexchat_pluginpref_set_str (ph, SvPV_nolen (ST (0)), SvPV_nolen (ST (1)))); }
static XS (XS_Xchat_get_context) { dXSARGS; if (items != 0) { xchat_print (ph, "Usage: Xchat::get_context()"); } else { XSRETURN_IV (PTR2IV (xchat_get_context (ph))); } }
static XS (XS_Xchat_find_context) { char *server = NULL; char *chan = NULL; xchat_context *RETVAL; dXSARGS; if (items > 2) xchat_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)); /* xchat_printf( ph, "XSUB - find_context( %s, NULL )", chan ); */ } /* else { xchat_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)); /* xchat_printf( ph, "XSUB - find_context( %s, NULL )", SvPV_nolen(ST(0) )); */ } /* else { xchat_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)); /* xchat_printf( ph, "XSUB - find_context( NULL, %s )", SvPV_nolen(ST(1) )); */ } /* else { xchat_print( ph, "XSUB - 2 arg NULL server" ); } */ break; } RETVAL = xchat_find_context (ph, server, chan); if (RETVAL != NULL) { /* xchat_print (ph, "XSUB - context found"); */ XSRETURN_IV (PTR2IV (RETVAL)); } else { /* xchat_print (ph, "XSUB - context not found"); */ XSRETURN_UNDEF; } } }
static XS (XS_Xchat_nickcmp) { dXSARGS; if (items != 2) { xchat_print (ph, "Usage: Xchat::nickcmp(s1, s2)"); } else { XSRETURN_IV ((IV) xchat_nickcmp (ph, SvPV_nolen (ST (0)), SvPV_nolen (ST (1)))); } }
static XS (XS_Xchat_set_context) { xchat_context *ctx; dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::set_context(ctx)"); } else { ctx = INT2PTR (xchat_context *, SvUV (ST (0))); XSRETURN_IV ((IV) xchat_set_context (ph, ctx)); } }
static XS (XS_Xchat_emit_print) { char *event_name; int RETVAL; int count; dXSARGS; if (items < 1) { xchat_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 = xchat_emit_print (ph, event_name, NULL); break; case 2: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), NULL); break; case 3: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), SvPV_nolen (ST (2)), NULL); break; case 4: RETVAL = xchat_emit_print (ph, event_name, SvPV_nolen (ST (1)), SvPV_nolen (ST (2)), SvPV_nolen (ST (3)), NULL); break; case 5: RETVAL = xchat_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); } }
/* 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)); } }
/* 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; xchat_hook *hook; HookData *data; dXSARGS; if (items != 5) { xchat_print (ph, "Usage: Xchat::Internal::hook_command(name, priority, callback, help_text, userdata)"); } else { name = SvPV_nolen (ST (0)); pri = (int) SvIV (ST (1)); callback = ST (2); /* leave the help text has 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); data = NULL; data = malloc (sizeof (HookData)); if (data == NULL) { XSRETURN_UNDEF; } data->callback = sv_mortalcopy (callback); SvREFCNT_inc (data->callback); data->userdata = sv_mortalcopy (userdata); SvREFCNT_inc (data->userdata); data->depth = 0; data->package = NULL; hook = xchat_hook_command (ph, name, pri, command_cb, help_text, data); XSRETURN_IV (PTR2IV (hook)); } }
/* Xchat::Internal::hook_timer(timeout, callback, userdata) */ static XS (XS_Xchat_hook_timer) { int timeout; SV *callback; SV *userdata; xchat_hook *hook; SV *package; HookData *data; dXSARGS; if (items != 4) { xchat_print (ph, "Usage: Xchat::Internal::hook_timer(timeout, callback, userdata, package)"); } else { timeout = (int) SvIV (ST (0)); callback = ST (1); data = NULL; userdata = ST (2); package = ST (3); data = malloc (sizeof (HookData)); if (data == NULL) { XSRETURN_UNDEF; } data->callback = sv_mortalcopy (callback); SvREFCNT_inc (data->callback); data->userdata = sv_mortalcopy (userdata); SvREFCNT_inc (data->userdata); data->ctx = xchat_get_context (ph); data->package = sv_mortalcopy (package); SvREFCNT_inc (data->package); hook = xchat_hook_timer (ph, timeout, timer_cb, data); data->hook = hook; XSRETURN_IV (PTR2IV (hook)); } }
static XS (XS_Xchat_get_list) { SV *name; xchat_list *list; const char *const *fields; int count = 0; /* return value for scalar context */ dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::get_list(name)"); } else { SP -= items; /*remove the argument list from the stack */ name = ST (0); list = xchat_list_get (ph, SvPV_nolen (name)); if (list == NULL) { XSRETURN_EMPTY; } if (GIMME_V == G_SCALAR) { while (xchat_list_next (ph, list)) { count++; } xchat_list_free (ph, list); XSRETURN_IV ((IV) count); } fields = xchat_list_fields (ph, SvPV_nolen (name)); while (xchat_list_next (ph, list)) { XPUSHs (list_item_to_sv (list, fields)); } xchat_list_free (ph, list); PUTBACK; return; } }
static XS (XS_Xchat_register) { char *name, *version, *desc, *filename; void *gui_entry; dXSARGS; if (items != 4) { xchat_printf (ph, "Usage: Xchat::Internal::register(scriptname, version, desc, filename)"); } else { name = SvPV_nolen (ST (0)); version = SvPV_nolen (ST (1)); desc = SvPV_nolen (ST (2)); filename = SvPV_nolen (ST (3)); gui_entry = xchat_plugingui_add (ph, filename, name, desc, version, NULL); XSRETURN_IV (PTR2IV (gui_entry)); } }
/* Xchat::Internal::hook_server(name, priority, callback, userdata) */ static XS (XS_Xchat_hook_server) { char *name; int pri; SV *callback; SV *userdata; SV *package; hexchat_hook *hook; HookData *data; dXSARGS; if (items != 5) { hexchat_print (ph, "Usage: Xchat::Internal::hook_server(name, priority, callback, userdata, package)"); } else { name = SvPV_nolen (ST (0)); pri = (int) SvIV (ST (1)); callback = ST (2); userdata = ST (3); package = ST (4); 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_server (ph, name, pri, server_cb, data); XSRETURN_IV (PTR2IV (hook)); } }
/* Xchat::Internal::hook_server(name, priority, callback, userdata) */ static XS (XS_Xchat_hook_server) { char *name; int pri; SV *callback; SV *userdata; xchat_hook *hook; HookData *data; dXSARGS; if (items != 4) { xchat_print (ph, "Usage: Xchat::Internal::hook_server(name, priority, callback, userdata)"); } else { name = SvPV_nolen (ST (0)); pri = (int) SvIV (ST (1)); callback = ST (2); userdata = ST (3); data = NULL; data = malloc (sizeof (HookData)); if (data == NULL) { XSRETURN_UNDEF; } data->callback = sv_mortalcopy (callback); SvREFCNT_inc (data->callback); data->userdata = sv_mortalcopy (userdata); SvREFCNT_inc (data->userdata); data->depth = 0; data->package = NULL; hook = xchat_hook_server (ph, name, pri, server_cb, data); XSRETURN_IV (PTR2IV (hook)); } }
static XS (XS_Xchat_get_prefs) { const char *str; int integer; SV *temp = NULL; dXSARGS; if (items != 1) { xchat_print (ph, "Usage: Xchat::get_prefs(name)"); } else { switch (xchat_get_prefs (ph, SvPV_nolen (ST (0)), &str, &integer)) { case 0: XSRETURN_UNDEF; break; case 1: temp = newSVpv (str, 0); SvUTF8_on (temp); SP -= items; sp = mark; XPUSHs (sv_2mortal (temp)); PUTBACK; break; case 2: XSRETURN_IV (integer); break; case 3: if (integer) { XSRETURN_YES; } else { XSRETURN_NO; } } } }