WIP
author"Luc Saillard <luc@saillard.org>"
Thu May 22 23:48:47 2008 +0200 (6 months ago)
changeset 480d8dac517565
parent 476abc5e22df29
child 49dca72f92aa03
WIP
src/foomatic-rip.c
src/gui.c
src/ppd.c
src/ppd.h
--- a/src/foomatic-rip.c Wed May 21 19:14:29 2008 +0200
+++ b/src/foomatic-rip.c Thu May 22 23:48:47 2008 +0200
@@ -63,12 +63,16 @@ static char *cups_filter_command;
static int parse_options(int *argc, char ***argv);
static char *string_remove_shell_escapes(char *string);
+static char *string_replace_markers(const char *string,
+ const char *cups_options_string,
+ const char *cups_profile_string);
//static char *string_remove_unprintables(char *string);
static void cups_setup_font_path_for_ghostscript(void);
static void cups_get_parameters(int argc, char **argv);
static int cups_setup_with_ppd(struct ppd_t *ppd);
static char *cups_get_filter_from_mime_type(const char *mime_type, const char *program);
static char *cups_get_filter_command(struct ppd_t *ppd);
+
void die(const char *fmt, ...);
void error(const char *fmt, ... );
void real_trace(const char *fname, const char *fmt, ... );
@@ -105,6 +109,7 @@ void error(const char *fmt, ... ) GCC_AT
+#if 0
static char postscript_accounting_prolog[] = "[{"
"%% Code for writing CUPS accounting tags on standard error"
""
@@ -198,6 +203,7 @@ static char postscript_accounting_prolog
""
"} stopped cleartomark"
"";
+#endif
@@ -404,6 +410,8 @@ cups_setup_with_ppd(struct ppd_t *ppd)
cups_setup_with_ppd(struct ppd_t *ppd)
{
const char *foomatic_no_page_accounting;
+ char *cups_option_string;
+ char *cups_filter_command_template;
/* Disable accounting ? */
foomatic_no_page_accounting = ppd_get_option_value_by_keyword_name(ppd, "FoomaticNoPageAccounting");
@@ -414,7 +422,14 @@ cups_setup_with_ppd(struct ppd_t *ppd)
}
/* Get the filter command line to use */
- cups_filter_command = cups_get_filter_command(ppd);
+ cups_filter_command_template = cups_get_filter_command(ppd);
+
+ cups_option_string = ppd_get_default_options_string(ppd);
+
+ trace("cups_option_string = \"%s\"\n", cups_option_string);
+ cups_filter_command = string_replace_markers(cups_filter_command_template, cups_option_string, NULL);
+ g_free(cups_filter_command_template);
+ g_free(cups_option_string);
return 0;
}
@@ -459,9 +474,12 @@ cups_get_filter_from_mime_type(const cha
{
char *cups_filter_path, *cups_pstoraster_path, *filter_command;
- /* Get the cups filter to use */
- /* transform the cups filter into our own command line to use */
- if (strcmp(mime_type, "application/vnd.cups-postscript") == 0)
+ /* transform the cups filter into our own command line to use
+ *
+ * %Y is a placeholder to include option settings
+ *
+ */
+ if (strcmp(mime_type, "application/vnd.cups-raster") == 0)
{
cups_filter_path = g_strdup_printf("%s/%s", cups_filters_path, program);
if (g_file_test(cups_filter_path, G_FILE_TEST_IS_EXECUTABLE) == FALSE)
@@ -560,6 +578,84 @@ string_remove_shell_escapes(char *string
return string;
}
+
+/*
+ * String that contains %A %B ... %Z need to be replace by the corresponding value
+ *
+ *
+ */
+static char *
+string_replace_markers(const char *string,
+ const char *cups_options_string,
+ const char *cups_profile_string)
+{
+ GString *string_without_marker;
+ int percent = 0;
+
+ string_without_marker = g_string_new(NULL);
+
+ while (*string)
+ {
+ if (percent)
+ {
+ switch (*string)
+ {
+ case '%':
+ g_string_append_c(string_without_marker, '%');
+ g_string_append_c(string_without_marker, *string);
+ break;
+
+ case 'Y':
+ if (cups_options_string)
+ g_string_append(string_without_marker, cups_options_string);
+ break;
+
+ case 'X':
+ if (cups_profile_string)
+ g_string_append(string_without_marker, cups_profile_string);
+ break;
+
+ default:
+ error("Unknown marker '%%%c' to replace. deleting this marker\n", *string);
+ break;
+ }
+ percent = 0;
+
+ }
+ else
+ {
+ if (*string == '%')
+ percent = 1;
+ else
+ g_string_append_c(string_without_marker, *string);
+
+ }
+ string++;
+ }
+
+ return g_string_free(string_without_marker, FALSE);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
void
die(const char *fmt, ...)
{
--- a/src/gui.c Wed May 21 19:14:29 2008 +0200
+++ b/src/gui.c Thu May 22 23:48:47 2008 +0200
@@ -378,13 +378,6 @@ waiting_lpr_finished(GPid pid, gint stat
*
*/
-static GtkWidget
-create_progressbar_dialog(void)
-{
-
-
-}
-
/*
*
*/
@@ -1021,19 +1014,6 @@ cb_cancel_clicked(GtkWidget *widget, gpo
gtk_main_quit();
}
-/*
- * This small function read stdin and write it to a tempfile
- * But updating the progress dialog ...
- *
- */
-static void
-do_print(void)
-{
-
-
-
-}
-
static void
cb_print_clicked(GtkWidget *widget, gpointer user_data)
{
--- a/src/ppd.c Wed May 21 19:14:29 2008 +0200
+++ b/src/ppd.c Thu May 22 23:48:47 2008 +0200
@@ -109,6 +109,8 @@ ppd_get_default_value_by_keyword(const s
static char *ppd_insert_value_to_spot(const char *string, int spot,
const char *new_substring, int do_free);
+
+static void ppd_set_keywords_to_be_show_in_UI(struct ppd_t *ppd);
/**
@@ -547,6 +549,7 @@ load_and_parse_ppd(const char *filename)
g_free(ppd_file);
ppd_fill_order_dependency(ppd);
+ ppd_set_keywords_to_be_show_in_UI(ppd);
return ppd;
}
@@ -589,16 +592,68 @@ ppd_reorder_keyword(struct ppd_t *ppd, s
keyword->options = g_list_sort_with_data(keyword->options, compare_options, ppd);
}
+
+
+/*
+ * our naive parser can't known which keyword should be presented to the UI.
+ * So we add an extra pass to detect *OpenUI or *JCLOpenUI keyword
+ */
+static void
+ppd_set_keywords_to_be_show_in_UI(struct ppd_t *ppd)
+{
+ struct ppd_keyword *keyword;
+ GList *options;
+
+ keyword = ppd_get_keyword_by_name(ppd, "OpenUI");
+ if (keyword == NULL)
+ return;
+
+ for (options = keyword->options; options; options = options->next)
+ {
+ struct ppd_option *option = options->data;
+
+ //trace("| name=%s | long_name=%s | enum_value=%s | value=%s |\n", option->name, option->long_name, option->enum_value, option->value);
+
+ /* We have a line:
+ *
+ * *OpenUI *PageRegion/Media Size: PickOne
+ * ^-name ^-long_name (or translation)
+ * *OpenUI *Resolution: PickOne
+ * ^- name ^- value (type)
+ *
+ * So we need to remove the * in from the name
+ */
+ if (option->name == NULL)
+ continue;
+ if (option->name[0] != '*')
+ continue;
+ if (option->value == NULL)
+ continue;
+
+ keyword = ppd_get_keyword_by_name(ppd, option->name+1);
+ if (keyword == NULL)
+ continue;
+
+ keyword->show_in_UI = TRUE;
+ }
+
+}
+
+
static void
ppd_fill_order_dependency(struct ppd_t *ppd)
{
struct ppd_keyword *keyword;
struct ppd_keyword *keyword_target;
GList *options;
+ char *old_locale;
keyword = ppd_get_keyword_by_name(ppd, "OrderDependency");
if (keyword == NULL)
return;
+
+ old_locale = setlocale(LC_NUMERIC, NULL);
+ setlocale(LC_NUMERIC, "C");
/*
* *OrderDependency: 110 AnySetup *PageSize
@@ -609,11 +664,11 @@ ppd_fill_order_dependency(struct ppd_t *
{
struct ppd_option *option = options->data;
char keyword_name[257];
- int order;
-
- if (sscanf(option->value, "%d %*s *%256s", &order, keyword_name) == 2)
- {
- trace("Order: %d for %s\n", order, keyword_name);
+ float order;
+
+ if (sscanf(option->value, "%f %*s *%256s", &order, keyword_name) == 2)
+ {
+ trace("Order: %f for %s\n", order, keyword_name);
keyword_target = ppd_get_keyword_by_name(ppd, keyword_name);
if (keyword_target)
keyword_target->order = order;
@@ -622,10 +677,12 @@ ppd_fill_order_dependency(struct ppd_t *
}
else
{
- error("Cannot parse *OrderDependency tag\n");
+ error("Cannot parse *OrderDependency tag \"%s\"\n", option->value);
}
options = options->next;
}
+
+ setlocale(LC_NUMERIC, old_locale);
keyword = ppd_get_keyword_by_name(ppd, "FoomaticRIPOption");
if (keyword == NULL)
@@ -720,6 +777,19 @@ ppd_replace_keyword(struct ppd_t *ppd, c
ppd_add_option_to_keyword(keyword, key);
return 0;
}
+
+
+
+
+
+
+
+
+
+
+
+
+
static void
print_ppd_option(struct ppd_option *option)
@@ -773,6 +843,19 @@ ppd_print_options(struct ppd_t *ppd)
}
}
+
+
+
+
+
+
+
+
+
+
+
+
+
static void
ppd_free_option(gpointer value, gpointer user_data)
{
@@ -819,6 +902,11 @@ ppd_free(struct ppd_t *ppd)
+
+
+
+
+
/**
*
* @param ppd: the ppd
@@ -926,15 +1014,11 @@ ppd_get_default_value_by_keyword(const s
{
const struct ppd_keyword *keyword;
- trace("keyword = %s\n", keyword_name);
-
keyword = ppd_get_keyword_by_name(ppd, keyword_name);
if (keyword == NULL)
return NULL;
- trace("keyword = %s\n", keyword->name);
if (keyword->default_option == NULL)
return NULL;
- trace("keyword->default_option = %s\n", keyword->default_option);
return ppd_get_option_value_by_keyword(keyword, keyword->default_option, NULL);
}
@@ -1413,6 +1497,62 @@ ppd_build_gs_cmd_line(struct ppd_t *ppd,
return 0;
}
+
+
+
+
+struct ppd_hash_table_struct
+{
+ struct ppd_t *ppd;
+ GString *options_string;
+};
+
+static void
+ppd_iter_keyword_to_return_options_string(gpointer key, gpointer value, gpointer user_data)
+{
+ struct ppd_keyword *keyword = value;
+ struct ppd_hash_table_struct *priv = user_data;
+
+ if (keyword->show_in_UI == FALSE)
+ return;
+
+ /* Don't display twice PageRegion and PageSize */
+ if (strcmp(keyword->name, "PageRegion") == 0 && g_hash_table_lookup(priv->ppd->keywords, "PageSize"))
+ return;
+
+ if (keyword->default_option)
+ {
+ g_string_append_printf(priv->options_string, "%s=%s ", keyword->name, keyword->default_option);
+ }
+ else
+ {
+ error("This keyword doesn't have a default option %s\n", keyword->name);
+ }
+
+
+}
+
+char *
+ppd_get_default_options_string(struct ppd_t *ppd)
+{
+ struct ppd_hash_table_struct priv;
+
+ priv.ppd = ppd;
+ priv.options_string = g_string_new(NULL);
+
+ g_hash_table_foreach(ppd->keywords, ppd_iter_keyword_to_return_options_string, &priv);
+
+ return g_strchomp(g_string_free(priv.options_string, FALSE));
+}
+
+
+
+
+
+
+
+
+
int
ppd_change_default_value(struct ppd_t *ppd, const char *keyword_name, const char *value)
{
--- a/src/ppd.h Wed May 21 19:14:29 2008 +0200
+++ b/src/ppd.h Thu May 22 23:48:47 2008 +0200
@@ -13,8 +13,8 @@ struct ppd_option
struct ppd_option
{
char *name; /* Ex: Model */
+ char *long_name; /* Ex: Draft Grayscale (auto-detect paper type) */
char *enum_value; /* Ex: escp2-d68 */
- char *long_name; /* Ex: Draft Grayscale (auto-detect paper type) */
char *value; /* Ex: " -sDeviceManufacturer=Epson -sDeviceModel=escp2-d68" */
};
@@ -22,7 +22,9 @@ struct ppd_keyword
{
char *name; /* Ex: *FoomaticRIPOptionSetting */
char *default_option; /* Ex: Default */
- int order; /* Ex: 1000 */
+ float order; /* Ex: 1000 */
+ int show_in_UI; /* When the keyword is surrounded by a *OpenUI *CloseUI */
+ int type;
GList *options; /* List of struct ppd_option */
};
@@ -51,6 +53,7 @@ const char *ppd_get_default_foomatic_opt
const char *ppd_get_default_foomatic_option(struct ppd_t *ppd,
const char *option_name);
+char *ppd_get_default_options_string(struct ppd_t *ppd);
#endif