gint main (gint argc, gchar **argv) { GOptionContext *context; xmlParserCtxtPtr parser; xmlDocPtr doc; YelpTransform *transform; gchar **params; const gchar *stylesheet; gchar *file; context = g_option_context_new ("[STYLESHEET] FILE"); g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, NULL); if (files == NULL || files[0] == NULL) { g_printerr ("Usage: test-transform [OPTION...] [STYLESHEET] FILE\n"); return 1; } if (files[1] == NULL) { stylesheet = DATADIR"/yelp/xslt/db2html.xsl"; file = files[0]; } else { stylesheet = files[0]; file = files[1]; } params = g_new0 (gchar *, 7); params[0] = g_strdup ("db.chunk.extension"); params[1] = g_strdup ("\"\""); params[2] = g_strdup ("db.chunk.info_basename"); params[3] = g_strdup ("\"x-yelp-titlepage\""); params[4] = g_strdup ("db.chunk.max_depth"); params[5] = g_strdup ("2"); params[6] = NULL; transform = yelp_transform_new (stylesheet); g_object_weak_ref ((GObject *) transform, transform_destroyed, NULL); g_signal_connect (transform, "chunk-ready", (GCallback) transform_chunk, NULL); g_signal_connect (transform, "finished", (GCallback) transform_finished, NULL); g_signal_connect (transform, "error", (GCallback) transform_error, NULL); parser = xmlNewParserCtxt (); doc = xmlCtxtReadFile (parser, file, NULL, XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA | XML_PARSE_NOENT | XML_PARSE_NONET ); xmlFreeParserCtxt (parser); xmlXIncludeProcessFlags (doc, XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA | XML_PARSE_NOENT | XML_PARSE_NONET ); if (!yelp_transform_start (transform, doc, (xmlDocPtr)params, NULL)) return 1; if (random_timeout) { GRand *rand = g_rand_new (); timeout = g_rand_int_range (rand, 80, 280); g_rand_free (rand); } if (timeout >= 0) g_timeout_add (timeout, (GSourceFunc) transform_release, transform); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); return 0; }
static void info_document_process (YelpInfoDocument *info) { YelpInfoDocumentPrivate *priv = GET_PRIV (info); GFile *file = NULL; gchar *filepath = NULL; GError *error; gint params_i = 0; gchar **params = NULL; file = yelp_uri_get_file (priv->uri); if (file == NULL) { error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND, _("The file does not exist.")); yelp_document_error_pending ((YelpDocument *) info, error); g_error_free (error); goto done; } filepath = g_file_get_path (file); g_object_unref (file); if (!g_file_test (filepath, G_FILE_TEST_IS_REGULAR)) { error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND, _("The file ‘%s’ does not exist."), filepath); yelp_document_error_pending ((YelpDocument *) info, error); g_error_free (error); goto done; } priv->sections = (GtkTreeModel *) yelp_info_parser_parse_file (filepath); gtk_tree_model_foreach (priv->sections, (GtkTreeModelForeachFunc) info_sections_visit, info); priv->xmldoc = yelp_info_parser_parse_tree ((GtkTreeStore *) priv->sections); if (priv->xmldoc == NULL) { error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING, _("The file ‘%s’ could not be parsed because it is" " not a well-formed info page."), filepath); yelp_document_error_pending ((YelpDocument *) info, error); goto done; } g_mutex_lock (&priv->mutex); if (priv->state == INFO_STATE_STOP) { g_mutex_unlock (&priv->mutex); goto done; } priv->transform = yelp_transform_new (STYLESHEET); priv->chunk_ready = g_signal_connect (priv->transform, "chunk-ready", (GCallback) transform_chunk_ready, info); priv->finished = g_signal_connect (priv->transform, "finished", (GCallback) transform_finished, info); priv->error = g_signal_connect (priv->transform, "error", (GCallback) transform_error, info); params = yelp_settings_get_all_params (yelp_settings_get_default (), 0, ¶ms_i); priv->transform_running = TRUE; yelp_transform_start (priv->transform, priv->xmldoc, NULL, (const gchar * const *) params); g_strfreev (params); g_mutex_unlock (&priv->mutex); done: g_free (filepath); priv->process_running = FALSE; g_object_unref (info); }