/*! \brief Runs a page hook. * \par Function Description * Runs a hook called \a name, which should expect the single #PAGE \a * page as its argument. * * \param name name of hook to run * \param page #PAGE argument for hook. */ void g_run_hook_page (const char *name, PAGE *page) { SCM args = scm_list_1 (edascm_from_page (page)); scm_run_hook (g_get_hook_by_name (name), args); scm_remember_upto_here_1 (args); }
/*! \brief Runs a object hook with a single OBJECT. * \par Function Description * Runs a hook called \a name, which should expect a list of #OBJECT * smobs as its argument, with a single-element list containing only \a obj. * * \see g_run_hook_object_list() * * \param name name of hook to run. * \param obj #OBJECT argument for hook. */ void g_run_hook_object (const char *name, OBJECT *obj) { SCM args = scm_list_1 (scm_list_1 (edascm_from_object (obj))); scm_run_hook (g_get_hook_by_name (name), args); scm_remember_upto_here_1 (args); }
/*! \brief Runs a object hook for a list of objects. * \par Function Description * Runs a hook called \a name, which should expect a list of #OBJECT * smobs as its argument, with \a obj_lst as the argument list. * * \see g_run_hook_object() * * \param name name of hook to run. * \param obj_lst list of #OBJECT smobs as hook argument. */ void g_run_hook_object_list (const char *name, GList *obj_lst) { SCM lst = SCM_EOL; GList *iter; for (iter = obj_lst; iter != NULL; iter = g_list_next (iter)) { lst = scm_cons (edascm_from_object ((OBJECT *) iter->data), lst); } SCM args = scm_list_1 (scm_reverse_x (lst, SCM_EOL)); scm_run_hook (g_get_hook_by_name (name), args); scm_remember_upto_here_2 (lst, args); }
void run_hook(const char *hook_name, SCM args) { SCM hook_symb = scm_from_utf8_symbol(hook_name); SCM hook = scm_eval(hook_symb, scm_interaction_environment()); if (scm_is_false(scm_defined_p(hook_symb, SCM_UNDEFINED))) { fprintf(stderr, "error: %s undefined\n", hook_name); return; } else if (scm_is_false(scm_hook_p(hook))) { fprintf(stderr, "error: %s is not a hook!\n", hook_name); return; } if (scm_is_false(scm_hook_empty_p(hook))) scm_run_hook(hook, args); }
static void ft_disconnect_function (LmConnection *conn, LmDisconnectReason reason, gpointer user_data) { lm_connection_unref (state.conn); state.conn = NULL; ft_roster_flush (); // TODO: ft_file_flush (); scm_run_hook (ex_disconnect_hook, scm_list_n (scm_from_int (reason), SCM_UNDEFINED)); /* set conn_status after hook so that discon hook procedures can get the previous state from ft-get-conn-status. helps in deciding if an automatic reconnection logic (dont auto reconnect if previous state was not FT_AUTH, etc) */ do_set_conn_status (FT_DEAD); return; }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ static void o_copy_end_generic(GSCHEM_TOPLEVEL *w_current, int multiple) { GList *new_objects; GList *iter; OBJECT *object; o_place_end (w_current, w_current->second_wx, w_current->second_wy, multiple, &new_objects); /* Run the copy component hook for all new components */ for (iter = new_objects; iter != NULL; iter = g_list_next (iter)) { object = iter->data; if ( (object->type == OBJ_COMPLEX) && (scm_hook_empty_p(copy_component_hook) == SCM_BOOL_F)) { scm_run_hook(copy_component_hook, scm_cons (g_make_attrib_smob_list(w_current, object), SCM_EOL)); } } g_list_free (new_objects); }
/*! \brief Opens a new page from a file. * \par Function Description * This function opens the file whose name is <B>filename</B> in a * new PAGE of <B>toplevel</B>. * * If there is no page for <B>filename</B> in <B>toplevel</B>'s list * of pages, it creates a new PAGE, loads the file in it and returns * a pointer on the new page. Otherwise it returns a pointer on the * existing page. * * If the filename passed is NULL, this function creates an empty, * untitled page. The name of the untitled page is build from * configuration data ('untitled-name') and a counter for uniqueness. * * The opened page becomes the current page of <B>toplevel</B>. * * \param [in] w_current The toplevel environment. * \param [in] filename The name of the file to open or NULL for a blank page. * \returns A pointer on the new page. * * \bug This code should check to make sure any untitled filename * does not conflict with a file on disk. */ PAGE* x_window_open_page (GSCHEM_TOPLEVEL *w_current, const gchar *filename) { TOPLEVEL *toplevel = w_current->toplevel; PAGE *old_current, *page; gchar *fn; g_return_val_if_fail (toplevel != NULL, NULL); /* Generate untitled filename if none was specified */ if (filename == NULL) { gchar *cwd, *tmp; cwd = g_get_current_dir (); tmp = g_strdup_printf ("%s_%d.sch", toplevel->untitled_name, ++w_current->num_untitled); fn = g_build_filename (cwd, tmp, NULL); g_free(cwd); g_free(tmp); } else { fn = g_strdup (filename); } /* Return existing page if it is already loaded */ page = s_page_search (toplevel, fn); if ( page != NULL ) { g_free(fn); return page; } old_current = toplevel->page_current; page = s_page_new (toplevel, fn); s_page_goto (toplevel, page); /* Load from file if necessary, otherwise just print a message */ if (filename != NULL) { GError *err = NULL; if (!quiet_mode) s_log_message (_("Loading schematic [%s]\n"), fn); if (!f_open (toplevel, page, (gchar *) fn, &err)) { GtkWidget *dialog; g_warning ("%s\n", err->message); dialog = gtk_message_dialog_new (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", err->message); gtk_window_set_title (GTK_WINDOW (dialog), _("Failed to load file")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free (err); } else { gtk_recent_manager_add_item (recent_manager, g_filename_to_uri(fn, NULL, NULL)); } } else { if (!quiet_mode) s_log_message (_("New file [%s]\n"), toplevel->page_current->page_filename); } if (scm_is_false (scm_hook_empty_p (new_page_hook))) scm_run_hook (new_page_hook, scm_cons (g_make_page_smob (toplevel, page), SCM_EOL)); a_zoom_extents (w_current, s_page_objects (toplevel->page_current), A_PAN_DONT_REDRAW); o_undo_savestate (w_current, UNDO_ALL); if ( old_current != NULL ) s_page_goto (toplevel, old_current); /* This line is generally un-needed, however if some code * wants to open a page, yet not bring it to the front, it is * needed needed to add it into the page manager. Otherwise, * it will get done in x_window_set_current_page(...) */ x_pagesel_update (w_current); /* ??? */ g_free (fn); return page; }
SCM _run_hook(void * data) { SCM** d = (SCM**)data; return scm_run_hook(*(d[0]),*(d[1])); }
static LmHandlerResult ft_msg_msg_handler (LmMessageHandler *handler, LmConnection *conn, LmMessage *msg, gpointer user_data) { LmMessageNode *root, *body, *x; const char *from, *msg_str, *type; char *ts = NULL; char *new_from = NULL; root = lm_message_get_node (msg); if (!root) goto out; body = lm_message_node_get_child (root, "body"); if (!body) goto out; from = lm_message_node_get_attribute (msg->node, "from"); if (!from) goto out; msg_str = lm_message_node_get_value (body); type = lm_message_node_get_attribute (msg->node, "type"); if (type && g_ascii_strcasecmp (type, "chat") != 0) { PRINTF (_("[message of type '%s']"), type); goto out; } // Offline messages for (x = root->children; x != NULL; x = x->next) { if (!g_ascii_strcasecmp (x->name, "x")) { const char *xmlns = lm_message_node_get_attribute (x, "xmlns"); if (xmlns && !g_ascii_strcasecmp (xmlns, "jabber:x:delay")) { ts = parse_timestamp ((char *)lm_message_node_get_attribute (x, "stamp")); } } } set_hook_return (0); { FtRosterItem *item = NULL; char *nickname; new_from = g_strdup (from); item = ft_roster_lookup (new_from); if (!item) nickname = NULL; else nickname = item->nickname; scm_run_hook (ex_message_receive_hook, scm_list_n (ts ? scm_from_locale_string (ts) : scm_from_locale_string (""), scm_from_locale_string (new_from), nickname ? scm_from_locale_string (nickname) : scm_from_locale_string (""), scm_from_locale_string (msg_str), SCM_UNDEFINED)); } if (get_hook_return () == 1) goto out; PRINTF ("%s: %s", new_from, msg_str); out: if (ts) g_free (ts); if (new_from) g_free (new_from); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }