1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * utils.c: Various utility routines that do not depend on the GUI of Gnumeric
6 * Miguel de Icaza (miguel@gnu.org)
7 * Jukka-Pekka Iivonen (iivonen@iki.fi)
8 * Zbigniew Chyla (cyba@gnome.pl)
10 #include <gnumeric-config.h>
11 #include <glib/gi18n-lib.h>
14 #include "gnumeric-paths.h"
19 #include "workbook-view.h"
22 #include <goffice/goffice.h>
27 #include <sys/types.h>
32 #include <gsf/gsf-impl-utils.h>
33 #include <gsf/gsf-doc-meta-data.h>
34 #include <gsf/gsf-timestamp.h>
36 #define SHEET_SELECTION_KEY "sheet-selection"
37 #define SSCONVERT_SHEET_SET_KEY "ssconvert-sheets"
39 static char *gnumeric_lib_dir
;
40 static char *gnumeric_data_dir
;
41 static char *gnumeric_locale_dir
;
42 static char *gnumeric_usr_dir
;
43 static char *gnumeric_usr_dir_unversioned
;
44 static char *gnumeric_extern_plugin_dir
;
45 static GSList
*gutils_xml_in_docs
;
48 running_in_tree (void)
50 const char *argv0
= g_get_prgname ();
55 /* Sometime we see, e.g., "lt-gnumeric" as basename. */
57 char *base
= g_path_get_basename (argv0
);
58 gboolean has_lt_prefix
= (strncmp (base
, "lt-", 3) == 0);
64 /* Look for ".libs" as final path element. */
66 const char *dotlibs
= strstr (argv0
, ".libs/");
68 (dotlibs
== argv0
|| G_IS_DIR_SEPARATOR (dotlibs
[-1])) &&
69 strchr (dotlibs
+ 6, G_DIR_SEPARATOR
) == NULL
)
76 static gboolean gutils_inited
= FALSE
;
83 // This function will end up being called twice in normal operation:
84 // once from gnm_pre_parse_init and once from gnm_init. Introspection
85 // will not get the first.
90 gchar
*dir
= g_win32_get_package_installation_directory_of_module (NULL
);
91 gnumeric_lib_dir
= g_build_filename (dir
, "lib",
92 "gnumeric", GNM_VERSION_FULL
,
94 gnumeric_data_dir
= g_build_filename (dir
, "share",
95 "gnumeric", GNM_VERSION_FULL
,
97 gnumeric_locale_dir
= g_build_filename (dir
, "share", "locale", NULL
);
98 gnumeric_extern_plugin_dir
= g_build_filename
99 (dir
, "lib", "gnumeric", GNM_API_VERSION
, "plugins",
103 if (running_in_tree ()) {
104 const char *argv0
= g_get_prgname ();
105 char *dotlibs
= g_path_get_dirname (argv0
);
106 char *top
= g_build_filename (dotlibs
, "..", "../", NULL
);
107 char *plugins
= g_build_filename (top
, PLUGIN_SUBDIR
, NULL
);
108 if (g_file_test (plugins
, G_FILE_TEST_IS_DIR
))
110 go_filename_simplify (top
, GO_DOTDOT_SYNTACTIC
,
115 if (0) g_printerr ("Running in-tree\n");
118 if (!gnumeric_lib_dir
)
119 gnumeric_lib_dir
= g_strdup (GNUMERIC_LIBDIR
);
120 gnumeric_data_dir
= g_strdup (GNUMERIC_DATADIR
);
121 gnumeric_locale_dir
= g_strdup (GNUMERIC_LOCALEDIR
);
122 gnumeric_extern_plugin_dir
= g_strdup (GNUMERIC_EXTERNPLUGINDIR
);
124 home_dir
= g_get_home_dir ();
125 gnumeric_usr_dir_unversioned
= home_dir
126 ? g_build_filename (home_dir
, ".gnumeric", NULL
)
128 gnumeric_usr_dir
= gnumeric_usr_dir_unversioned
129 ? g_build_filename (gnumeric_usr_dir_unversioned
, GNM_VERSION_FULL
, NULL
)
132 gutils_inited
= TRUE
;
136 gutils_shutdown (void)
140 g_free (gnumeric_lib_dir
);
141 gnumeric_lib_dir
= NULL
;
142 g_free (gnumeric_data_dir
);
143 gnumeric_data_dir
= NULL
;
144 g_free (gnumeric_locale_dir
);
145 gnumeric_locale_dir
= NULL
;
146 g_free (gnumeric_usr_dir
);
147 gnumeric_usr_dir
= NULL
;
148 g_free (gnumeric_usr_dir_unversioned
);
149 gnumeric_usr_dir_unversioned
= NULL
;
150 g_free (gnumeric_extern_plugin_dir
);
151 gnumeric_extern_plugin_dir
= NULL
;
153 for (l
= gutils_xml_in_docs
; l
; l
= l
->next
) {
154 GsfXMLInDoc
**pdoc
= l
->data
;
155 gsf_xml_in_doc_free (*pdoc
);
158 g_slist_free (gutils_xml_in_docs
);
159 gutils_xml_in_docs
= NULL
;
163 gnm_sys_lib_dir (void)
165 return gnumeric_lib_dir
;
169 gnm_sys_data_dir (void)
171 return gnumeric_data_dir
;
175 gnm_sys_extern_plugin_dir (void)
177 return gnumeric_extern_plugin_dir
;
181 gnm_locale_dir (void)
183 return gnumeric_locale_dir
;
187 gnm_usr_dir (gboolean versioned
)
189 return versioned
? gnumeric_usr_dir
: gnumeric_usr_dir_unversioned
;
194 all_ascii (const char *s
)
196 while ((guchar
)*s
< 0x7f) {
206 * Like strto[ld], but...
207 * 1. handles non-ascii characters
208 * 2. disallows 0x000.0p+00 and 0.0d+00
209 * 3. ensures sane errno on exit
212 gnm_utf8_strto (const char *s
, char **end
)
218 GString
const *decimal
= go_locale_get_decimal ();
219 gboolean seen_decimal
= FALSE
;
220 gboolean seen_digit
= FALSE
;
226 res
= gnm_strto (s
, end
);
227 goto handle_denormal
;
230 ascii
= g_string_sized_new (100);
236 while (g_unichar_isspace (g_utf8_get_char (p
))) {
237 p
= g_utf8_next_char (p
);
241 sign
= go_unichar_issign (g_utf8_get_char (p
));
243 g_string_append_c (ascii
, "-/+"[sign
+ 1]);
244 p
= g_utf8_next_char (p
);
248 if (strncmp (p
, decimal
->str
, decimal
->len
) == 0) {
252 go_string_append_gstring (ascii
, decimal
);
254 } else if (g_unichar_isdigit (g_utf8_get_char (p
))) {
255 g_string_append_c (ascii
, '0' + g_unichar_digit_value (g_utf8_get_char (p
)));
256 p
= g_utf8_next_char (p
);
263 /* No conversion, bail to gnm_strto for nan etc. */
264 g_string_free (ascii
, TRUE
);
265 return gnm_strto (s
, end
);
268 if (*p
== 'e' || *p
== 'E') {
271 g_string_append_c (ascii
, 'e');
272 p
= g_utf8_next_char (p
);
274 sign
= go_unichar_issign (g_utf8_get_char (p
));
276 g_string_append_c (ascii
, "-/+"[sign
+ 1]);
277 p
= g_utf8_next_char (p
);
279 while (g_unichar_isdigit (g_utf8_get_char (p
))) {
280 g_string_append_c (ascii
, '0' + g_unichar_digit_value (g_utf8_get_char (p
)));
281 p
= g_utf8_next_char (p
);
285 res
= gnm_strto (ascii
->str
, end
);
287 *end
= g_utf8_offset_to_pointer
288 (s
, spaces
+ g_utf8_pointer_to_offset (ascii
->str
, *end
));
289 g_string_free (ascii
, TRUE
);
295 if (res
!= 0 && gnm_abs (res
) < GNM_MIN
)
304 * Like strtol, but...
305 * 1. handles non-ascii characters
306 * 2. assumes base==10
307 * 3. ensures sane errno on exit
310 gnm_utf8_strtol (const char *s
, char **end
)
315 unsigned long res
= 0, lim
, limd
;
321 while (g_unichar_isspace (g_utf8_get_char (p
)))
322 p
= g_utf8_next_char (p
);
324 sign
= go_unichar_issign (g_utf8_get_char (p
));
326 p
= g_utf8_next_char (p
);
328 lim
= (-(unsigned long)LONG_MIN
) / 10u;
329 limd
= (-(unsigned long)LONG_MIN
) % 10u;
331 lim
= (unsigned long)LONG_MAX
/ 10u;
332 limd
= (unsigned long)LONG_MAX
% 10u;
335 if (!g_unichar_isdigit (g_utf8_get_char (p
))) {
341 while (g_unichar_isdigit (g_utf8_get_char (p
))) {
342 guint8 dig
= g_unichar_digit_value (g_utf8_get_char (p
));
343 p
= g_utf8_next_char (p
);
345 if (res
> lim
|| (res
== lim
&& dig
> limd
)) {
347 while (g_unichar_isdigit (g_utf8_get_char (p
)))
348 p
= g_utf8_next_char (p
);
351 return sign
< 0 ? LONG_MIN
: LONG_MAX
;
354 res
= res
* 10u + dig
;
358 return sign
< 0 ? (long)-res
: (long)res
;
363 gnm_regcomp_XL (GORegexp
*preg
, char const *pattern
, int cflags
,
364 gboolean anchor_start
, gboolean anchor_end
)
366 GString
*res
= g_string_new (NULL
);
370 g_string_append_c (res
, '^');
375 g_string_append (res
, ".*");
380 g_string_append_c (res
, '.');
385 if (pattern
[1] == '*' ||
391 pattern
= go_regexp_quote1 (res
, pattern
);
396 g_string_append_c (res
, '$');
398 retval
= go_regcomp (preg
, res
->str
, cflags
);
399 g_string_free (res
, TRUE
);
404 * gnm_excel_search_impl:
405 * @needle: the pattern to search for, see gnm_regcomp_XL.
406 * @haystack: the string to search in.
407 * @skip: zero-based search start point in characters.
409 * Returns: -1 for a non-match, or zero-based location in
412 * The is the implementation of Excel's SEARCH function.
413 * However, note that @skip and return value are zero-based.
416 gnm_excel_search_impl (const char *needle
, const char *haystack
,
423 for (i
= skip
, hay2
= haystack
; i
> 0; i
--) {
426 hay2
= g_utf8_next_char (hay2
);
429 if (gnm_regcomp_XL (&r
, needle
, GO_REG_ICASE
, FALSE
, FALSE
) == GO_REG_OK
) {
432 switch (go_regexec (&r
, hay2
, 1, &rm
, 0)) {
438 g_utf8_pointer_to_offset (hay2
, hay2
+ rm
.rm_so
);
440 g_warning ("Unexpected go_regexec result");
444 g_warning ("Unexpected regcomp result");
453 color_to_string (PangoColor color
)
455 static char result
[100];
456 sprintf (result
, "%04x:%04x:%04x", color
.red
, color
.green
, color
.blue
);
461 enum_name (GType typ
, int i
)
463 static char result
[100];
464 GEnumClass
*ec
= g_type_class_ref (typ
);
467 GEnumValue
*ev
= g_enum_get_value (ec
, i
);
468 g_type_class_unref (ec
);
470 if (ev
&& ev
->value_nick
)
471 return ev
->value_nick
;
472 if (ev
&& ev
->value_name
)
473 return ev
->value_name
;
476 sprintf (result
, "%d", i
);
481 cb_gnm_pango_attr_dump (PangoAttribute
*attr
, gpointer user_data
)
483 g_print (" start=%u; end=%u\n", attr
->start_index
, attr
->end_index
);
484 switch (attr
->klass
->type
) {
485 case PANGO_ATTR_FAMILY
:
486 g_print (" family=\"%s\"\n", ((PangoAttrString
*)attr
)->value
);
488 case PANGO_ATTR_LANGUAGE
:
489 g_print (" language=\"%s\"\n", pango_language_to_string (((PangoAttrLanguage
*)attr
)->value
));
491 case PANGO_ATTR_STYLE
:
492 g_print (" style=%s\n",
493 enum_name (PANGO_TYPE_STYLE
, ((PangoAttrInt
*)attr
)->value
));
495 case PANGO_ATTR_WEIGHT
:
496 g_print (" weight=%s\n",
497 enum_name (PANGO_TYPE_WEIGHT
, ((PangoAttrInt
*)attr
)->value
));
499 case PANGO_ATTR_VARIANT
:
500 g_print (" variant=%s\n",
501 enum_name (PANGO_TYPE_VARIANT
, ((PangoAttrInt
*)attr
)->value
));
503 case PANGO_ATTR_STRETCH
:
504 g_print (" stretch=%s\n",
505 enum_name (PANGO_TYPE_STRETCH
, ((PangoAttrInt
*)attr
)->value
));
507 case PANGO_ATTR_UNDERLINE
:
508 g_print (" underline=%s\n",
509 enum_name (PANGO_TYPE_UNDERLINE
, ((PangoAttrInt
*)attr
)->value
));
511 case PANGO_ATTR_STRIKETHROUGH
:
512 g_print (" strikethrough=%d\n", ((PangoAttrInt
*)attr
)->value
);
514 case PANGO_ATTR_RISE
:
515 g_print (" rise=%d\n", ((PangoAttrInt
*)attr
)->value
);
517 case PANGO_ATTR_FALLBACK
:
518 g_print (" fallback=%d\n", ((PangoAttrInt
*)attr
)->value
);
520 case PANGO_ATTR_LETTER_SPACING
:
521 g_print (" letter_spacing=%d\n", ((PangoAttrInt
*)attr
)->value
);
523 case PANGO_ATTR_SIZE
:
524 g_print (" size=%d%s\n",
525 ((PangoAttrSize
*)attr
)->size
,
526 ((PangoAttrSize
*)attr
)->absolute
? " abs" : "");
528 case PANGO_ATTR_SCALE
:
529 g_print (" scale=%g\n", ((PangoAttrFloat
*)attr
)->value
);
531 case PANGO_ATTR_FOREGROUND
:
532 g_print (" foreground=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
534 case PANGO_ATTR_BACKGROUND
:
535 g_print (" background=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
537 case PANGO_ATTR_UNDERLINE_COLOR
:
538 g_print (" underline_color=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
540 case PANGO_ATTR_STRIKETHROUGH_COLOR
:
541 g_print (" strikethrough_color=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
543 case PANGO_ATTR_FONT_DESC
: {
544 char *desc
= pango_font_description_to_string (((PangoAttrFontDesc
*)attr
)->desc
);
545 g_print (" font=\"%s\"\n", desc
);
550 g_print (" type=%s\n", enum_name (PANGO_TYPE_ATTR_TYPE
, attr
->klass
->type
));
557 gnm_pango_attr_dump (PangoAttrList
*list
)
559 g_print ("PangoAttrList at %p\n", list
);
560 pango_attr_list_filter (list
, cb_gnm_pango_attr_dump
, NULL
);
566 cb_gnm_pango_attr_list_equal (PangoAttribute
*a
, gpointer _sl
)
569 *sl
= g_slist_prepend (*sl
, a
);
574 * This is a bit of a hack. It might claim a difference even when things
575 * actually are equal. But not the other way around.
578 gnm_pango_attr_list_equal (PangoAttrList
const *l1
, PangoAttrList
const *l2
)
582 else if (l1
== NULL
|| l2
== NULL
)
586 GSList
*sl1
= NULL
, *sl2
= NULL
;
587 (void)pango_attr_list_filter ((PangoAttrList
*)l1
,
588 cb_gnm_pango_attr_list_equal
,
590 (void)pango_attr_list_filter ((PangoAttrList
*)l2
,
591 cb_gnm_pango_attr_list_equal
,
595 const PangoAttribute
*a1
= sl1
->data
;
596 const PangoAttribute
*a2
= sl2
->data
;
597 if (a1
->start_index
!= a2
->start_index
||
598 a1
->end_index
!= a2
->end_index
||
599 !pango_attribute_equal (a1
, a2
))
601 sl1
= g_slist_delete_link (sl1
, sl1
);
602 sl2
= g_slist_delete_link (sl2
, sl2
);
612 /* ------------------------------------------------------------------------- */
616 char *monetary_locale
;
619 * gnm_push_C_locale: (skip)
621 * Returns the current locale, and sets the locale and the value-format
622 * engine's locale to 'C'. The caller must call gnm_pop_C_locale to free the
623 * result and restore the previous locale.
626 gnm_push_C_locale (void)
628 GnmLocale
*old
= g_new0 (GnmLocale
, 1);
630 old
->num_locale
= g_strdup (go_setlocale (LC_NUMERIC
, NULL
));
631 go_setlocale (LC_NUMERIC
, "C");
632 old
->monetary_locale
= g_strdup (go_setlocale (LC_MONETARY
, NULL
));
633 go_setlocale (LC_MONETARY
, "C");
634 go_locale_untranslated_booleans ();
640 * gnm_pop_C_locale: (skip)
641 * @locale: #GnmLocale
643 * Frees the result of gnm_push_C_locale and restores the original locale.
646 gnm_pop_C_locale (GnmLocale
*locale
)
648 /* go_setlocale restores bools to locale translation */
649 go_setlocale (LC_MONETARY
, locale
->monetary_locale
);
650 g_free (locale
->monetary_locale
);
651 go_setlocale (LC_NUMERIC
, locale
->num_locale
);
652 g_free (locale
->num_locale
);
656 /* ------------------------------------------------------------------------- */
659 gnm_debug_flag (const char *flag
)
662 key
.key
= (char *)flag
;
665 return g_parse_debug_string (g_getenv ("GNM_DEBUG"), &key
, 1) != 0;
668 /* ------------------------------------------------------------------------- */
671 gnm_string_add_number (GString
*buf
, gnm_float d
)
673 size_t old_len
= buf
->len
;
678 gnm_float l10
= gnm_log10 (FLT_RADIX
);
679 digits
= (int)gnm_ceil (GNM_MANT_DIG
* l10
) +
680 (l10
== (int)l10
? 0 : 1);
683 g_string_append_printf (buf
, "%.*" GNM_FORMAT_g
, digits
- 1, d
);
684 d2
= gnm_strto (buf
->str
+ old_len
, NULL
);
687 g_string_truncate (buf
, old_len
);
688 g_string_append_printf (buf
, "%.*" GNM_FORMAT_g
, digits
, d
);
692 /* ------------------------------------------------------------------------- */
695 gnm_insert_meta_date (GODoc
*doc
, char const *name
)
697 GValue
*value
= g_new0 (GValue
, 1);
699 GsfTimestamp
*ts
= gsf_timestamp_new ();
701 g_get_current_time (&tm
);
704 gsf_timestamp_set_time (ts
, tm
.tv_sec
);
705 g_value_init (value
, GSF_TIMESTAMP_TYPE
);
706 gsf_timestamp_to_value (ts
, value
);
707 gsf_timestamp_free (ts
);
709 gsf_doc_meta_data_insert (go_doc_get_meta_data (doc
),
714 /* ------------------------------------------------------------------------- */
717 * gnm_object_get_bool:
719 * @name: property name
721 * Returns: the value of @o's boolean property @name.
724 gnm_object_get_bool (gpointer o
, const char *name
)
727 g_object_get (o
, name
, &b
, NULL
);
732 * gnm_object_has_readable_prop:
734 * @property: property name
735 * @typ: property's type or %G_TYPE_NONE. (Exact type, not is-a.)
736 * @pres: (out) (optional): location to store property value.
738 * Returns: %TRUE if @obj has a readable property named @property
742 gnm_object_has_readable_prop (gconstpointer obj
, const char *property
,
743 GType typ
, gpointer pres
)
751 klass
= G_OBJECT_GET_CLASS (G_OBJECT (obj
));
752 spec
= g_object_class_find_property (klass
, property
);
754 !(G_PARAM_READABLE
& spec
->flags
) ||
755 (typ
!= G_TYPE_NONE
&& spec
->value_type
!= typ
))
759 g_object_get (G_OBJECT (obj
), property
, pres
, NULL
);
763 /* ------------------------------------------------------------------------- */
766 gnm_float_equal (gnm_float
const *a
, const gnm_float
*b
)
772 gnm_float_hash (gnm_float
const *d
)
775 gnm_float mant
= gnm_frexp (gnm_abs (*d
), &expt
);
776 guint h
= ((guint
)(0x80000000u
* mant
)) ^ expt
;
782 /* ------------------------------------------------------------------------- */
785 GnmHashTableOrder order
;
790 cb_compare (gconstpointer a_
, gconstpointer b_
, gpointer user_data
)
792 struct cb_compare
*user
= user_data
;
793 gpointer
*a
= (gpointer
)a_
;
794 gpointer
*b
= (gpointer
)b_
;
796 return user
->order (a
[0], a
[1], b
[0], b
[1], user
->user
);
801 * gnm_hash_table_foreach_ordered:
803 * @callback: (scope async): #GHFunc
804 * @order: (scope async): Ordering function
805 * @user: user data for callback and order
807 * Like g_hash_table_foreach, but with an ordering imposed.
810 gnm_hash_table_foreach_ordered (GHashTable
*h
,
812 GnmHashTableOrder order
,
818 GHashTableIter hiter
;
821 /* Gather all key-value pairs */
822 data
= g_ptr_array_new ();
823 g_hash_table_iter_init (&hiter
, h
);
824 while (g_hash_table_iter_next (&hiter
, &key
, &value
)) {
825 g_ptr_array_add (data
, key
);
826 g_ptr_array_add (data
, value
);
829 /* Sort according to given ordering */
832 g_qsort_with_data (data
->pdata
,
833 data
->len
/ 2, 2 * sizeof (gpointer
),
837 /* Call user callback with all pairs */
838 for (ui
= 0; ui
< data
->len
; ui
+= 2)
839 callback (g_ptr_array_index (data
, ui
),
840 g_ptr_array_index (data
, ui
+ 1),
844 g_ptr_array_free (data
, TRUE
);
847 /* ------------------------------------------------------------------------- */
850 gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc
**pdoc
)
852 gutils_xml_in_docs
= g_slist_prepend (gutils_xml_in_docs
, pdoc
);
855 /* ------------------------------------------------------------------------- */
858 * gnm_file_saver_get_sheet:
860 * @wbv: #WorkbookView
862 * For a single-sheet saver, this function determines what sheet to save.
864 * Returns: (transfer none): the sheet to export
867 gnm_file_saver_get_sheet (GOFileSaver
const *fs
, WorkbookView
const *wbv
)
872 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), NULL
);
873 g_return_val_if_fail (go_file_saver_get_save_scope (fs
) ==
874 GO_FILE_SAVE_SHEET
, NULL
);
875 g_return_val_if_fail (GNM_IS_WORKBOOK_VIEW (wbv
), NULL
);
877 wb
= wb_view_get_workbook (wbv
);
879 sel
= g_object_get_data (G_OBJECT (wb
), SHEET_SELECTION_KEY
);
882 return g_ptr_array_index (sel
, 0);
883 g_critical ("Someone messed up sheet selection");
886 return wb_view_cur_sheet (wbv
);
890 * gnm_file_saver_get_sheets:
892 * @wbv: #WorkbookView
893 * @default_all: If %TRUE, all sheets will be selected by default; if %FALSE,
894 * this function will return %NULL if no sheets were explicitly selected.
896 * For a workbook-scope saver, this function determines what sheets to save.
898 * Returns: (transfer container) (element-type Sheet): the sheets to export
900 * Note: the return value should be unreffed, not freed.
903 gnm_file_saver_get_sheets (GOFileSaver
const *fs
,
904 WorkbookView
const *wbv
,
905 gboolean default_all
)
908 GPtrArray
*sel
, *sheets
;
910 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), NULL
);
911 g_return_val_if_fail (go_file_saver_get_save_scope (fs
) ==
912 GO_FILE_SAVE_WORKBOOK
, NULL
);
913 g_return_val_if_fail (GNM_IS_WORKBOOK_VIEW (wbv
), NULL
);
915 wb
= wb_view_get_workbook (wbv
);
916 sel
= g_object_get_data (G_OBJECT (wb
), SHEET_SELECTION_KEY
);
917 sheets
= g_object_get_data (G_OBJECT (wb
), SSCONVERT_SHEET_SET_KEY
);
919 g_ptr_array_ref (sel
);
921 sel
= g_ptr_array_ref (sheets
);
922 else if (default_all
) {
924 sel
= g_ptr_array_new ();
925 for (i
= 0; i
< workbook_sheet_count (wb
); i
++) {
926 Sheet
*sheet
= workbook_sheet_by_index (wb
, i
);
927 g_ptr_array_add (sel
, sheet
);
935 gnm_file_saver_common_export_option (GOFileSaver
const *fs
,
937 const char *key
, const char *value
,
943 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), FALSE
);
944 g_return_val_if_fail (GNM_IS_WORKBOOK (wb
), FALSE
);
945 g_return_val_if_fail (key
!= NULL
, FALSE
);
946 g_return_val_if_fail (value
!= NULL
, FALSE
);
948 if (strcmp (key
, "sheet") == 0) {
950 Sheet
*sheet
= workbook_sheet_by_name (wb
, value
);
954 *err
= g_error_new (go_error_invalid (), 0,
955 _("Unknown sheet \"%s\""),
960 sheets
= g_object_get_data (G_OBJECT (wb
), SSCONVERT_SHEET_SET_KEY
);
962 sheets
= g_ptr_array_new ();
963 g_object_set_data_full (G_OBJECT (wb
),
964 SSCONVERT_SHEET_SET_KEY
,
966 (GDestroyNotify
)g_ptr_array_unref
);
968 g_ptr_array_add (sheets
, sheet
);
974 *err
= g_error_new (go_error_invalid (), 0,
975 _("Invalid export option \"%s\" for format %s"),
977 go_file_saver_get_id (fs
));