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; }
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) { xchat_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)) { xchat_printf (ph, "Error in timer callback %s", SvPV_nolen (ERRSV)); if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ retVal = XCHAT_EAT_ALL; } else { if (count != 1) { xchat_print (ph, "Timer handler should only return 1 value."); retVal = XCHAT_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 ("Xchat::unhook", G_EVAL); SPAGAIN; } } } PUTBACK; FREETMPS; LEAVE; return retVal; }
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; }
void FidlParser::add_root_object(ast::ASTNode* object) { if (ast::Package* package = dynamic_cast<ast::Package*>(object)) { root_node_->add_child(object); set_current_package(package); } else if (ast::ImportDecl* import = dynamic_cast<ast::ImportDecl*>(object)) { current_package()->add_child(object); ast::StringConstant const* filename = dynamic_cast<ast::StringConstant const*>(&(import->filename())); assert(filename); parse_import(filename->value()); } else { current_package()->add_child(object); } }
static int print_cb (char *word[], void *userdata) { HookData *data = (HookData *) userdata; SV *temp = NULL; int retVal = 0; int count = 1; int last_index = 31; /* must be initialized after SAVETMPS */ AV *wd = NULL; dSP; ENTER; SAVETMPS; if (data->depth) return HEXCHAT_EAT_NONE; wd = newAV (); sv_2mortal ((SV *) wd); /* need to scan backwards to find the index of the last element since some events such as "DCC Timeout" can have NULL elements in between non NULL elements */ while (last_index >= 0 && (word[last_index] == NULL || word[last_index][0] == 0)) { last_index--; } for (count = 1; count <= last_index; count++) { if (word[count] == NULL) { av_push (wd, &PL_sv_undef); } else if (word[count][0] == 0) { av_push (wd, newSVpvn ("",0)); } else { temp = newSVpv (word[count], 0); SvUTF8_on (temp); av_push (wd, temp); } } /*hexchat_printf (ph, "Recieved %d words in print callback", av_len (wd)+1); */ PUSHMARK (SP); XPUSHs (newRV_noinc ((SV *) wd)); 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 print callback %s", SvPV_nolen (ERRSV)); if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ retVal = HEXCHAT_EAT_NONE; } else { if (count != 1) { hexchat_print (ph, "Print handler should only return 1 value."); retVal = HEXCHAT_EAT_NONE; } else { retVal = POPi; } } PUTBACK; FREETMPS; LEAVE; return retVal; }