2 * utils.c: Various utility routines that do not depend on the GUI of Gnumeric
5 * Miguel de Icaza (miguel@gnu.org)
6 * Jukka-Pekka Iivonen (iivonen@iki.fi)
7 * Zbigniew Chyla (cyba@gnome.pl)
9 #include <gnumeric-config.h>
10 #include <glib/gi18n-lib.h>
13 #include <gnumeric-paths.h>
18 #include <workbook-view.h>
21 #include <goffice/goffice.h>
26 #include <sys/types.h>
31 #include <gsf/gsf-impl-utils.h>
32 #include <gsf/gsf-doc-meta-data.h>
33 #include <gsf/gsf-timestamp.h>
35 #define SHEET_SELECTION_KEY "sheet-selection"
36 #define SSCONVERT_SHEET_SET_KEY "ssconvert-sheets"
38 static char *gnumeric_lib_dir
;
39 static char *gnumeric_data_dir
;
40 static char *gnumeric_locale_dir
;
41 static char *gnumeric_usr_dir
;
42 static char *gnumeric_usr_dir_unversioned
;
43 static char *gnumeric_extern_plugin_dir
;
44 static GSList
*gutils_xml_in_docs
;
47 running_in_tree (void)
49 const char *argv0
= g_get_prgname ();
54 /* Sometimes we see, e.g., "lt-gnumeric" as basename. */
56 char *base
= g_path_get_basename (argv0
);
57 gboolean has_lt_prefix
= (strncmp (base
, "lt-", 3) == 0);
63 /* Look for ".libs" as final path element. */
65 const char *dotlibs
= strstr (argv0
, ".libs/");
67 (dotlibs
== argv0
|| G_IS_DIR_SEPARATOR (dotlibs
[-1])) &&
68 strchr (dotlibs
+ 6, G_DIR_SEPARATOR
) == NULL
)
75 static gboolean gutils_inited
= FALSE
;
82 // This function will end up being called twice in normal operation:
83 // once from gnm_pre_parse_init and once from gnm_init. Introspection
84 // will not get the first.
89 gchar
*dir
= g_win32_get_package_installation_directory_of_module (NULL
);
90 gnumeric_lib_dir
= g_build_filename (dir
, "lib",
91 "gnumeric", GNM_VERSION_FULL
,
93 gnumeric_data_dir
= g_build_filename (dir
, "share",
94 "gnumeric", GNM_VERSION_FULL
,
96 gnumeric_locale_dir
= g_build_filename (dir
, "share", "locale", NULL
);
97 gnumeric_extern_plugin_dir
= g_build_filename
98 (dir
, "lib", "gnumeric", GNM_API_VERSION
, "plugins",
102 if (running_in_tree ()) {
103 const char *argv0
= g_get_prgname ();
104 char *dotlibs
= g_path_get_dirname (argv0
);
105 char *top
= g_build_filename (dotlibs
, "..", "../", NULL
);
106 char *plugins
= g_build_filename (top
, PLUGIN_SUBDIR
, NULL
);
107 if (g_file_test (plugins
, G_FILE_TEST_IS_DIR
))
109 go_filename_simplify (top
, GO_DOTDOT_SYNTACTIC
,
114 if (0) g_printerr ("Running in-tree\n");
117 if (!gnumeric_lib_dir
)
118 gnumeric_lib_dir
= g_strdup (GNUMERIC_LIBDIR
);
119 gnumeric_data_dir
= g_strdup (GNUMERIC_DATADIR
);
120 gnumeric_locale_dir
= g_strdup (GNUMERIC_LOCALEDIR
);
121 gnumeric_extern_plugin_dir
= g_strdup (GNUMERIC_EXTERNPLUGINDIR
);
123 home_dir
= g_get_home_dir ();
124 gnumeric_usr_dir_unversioned
= home_dir
125 ? g_build_filename (home_dir
, ".gnumeric", NULL
)
127 gnumeric_usr_dir
= gnumeric_usr_dir_unversioned
128 ? g_build_filename (gnumeric_usr_dir_unversioned
, GNM_VERSION_FULL
, NULL
)
131 gutils_inited
= TRUE
;
135 gutils_shutdown (void)
139 g_free (gnumeric_lib_dir
);
140 gnumeric_lib_dir
= NULL
;
141 g_free (gnumeric_data_dir
);
142 gnumeric_data_dir
= NULL
;
143 g_free (gnumeric_locale_dir
);
144 gnumeric_locale_dir
= NULL
;
145 g_free (gnumeric_usr_dir
);
146 gnumeric_usr_dir
= NULL
;
147 g_free (gnumeric_usr_dir_unversioned
);
148 gnumeric_usr_dir_unversioned
= NULL
;
149 g_free (gnumeric_extern_plugin_dir
);
150 gnumeric_extern_plugin_dir
= NULL
;
152 for (l
= gutils_xml_in_docs
; l
; l
= l
->next
) {
153 GsfXMLInDoc
**pdoc
= l
->data
;
154 gsf_xml_in_doc_free (*pdoc
);
157 g_slist_free (gutils_xml_in_docs
);
158 gutils_xml_in_docs
= NULL
;
162 gnm_sys_lib_dir (void)
164 return gnumeric_lib_dir
;
168 gnm_sys_data_dir (void)
170 return gnumeric_data_dir
;
174 gnm_sys_extern_plugin_dir (void)
176 return gnumeric_extern_plugin_dir
;
180 gnm_locale_dir (void)
182 return gnumeric_locale_dir
;
186 gnm_usr_dir (gboolean versioned
)
188 return versioned
? gnumeric_usr_dir
: gnumeric_usr_dir_unversioned
;
193 all_ascii (const char *s
)
195 while ((guchar
)*s
< 0x7f) {
205 * Like strto[ld], but...
206 * 1. handles non-ascii characters
207 * 2. disallows 0x000.0p+00 and 0.0d+00
208 * 3. ensures sane errno on exit
211 gnm_utf8_strto (const char *s
, char **end
)
217 GString
const *decimal
= go_locale_get_decimal ();
218 gboolean seen_decimal
= FALSE
;
219 gboolean seen_digit
= FALSE
;
225 res
= gnm_strto (s
, end
);
226 goto handle_denormal
;
229 ascii
= g_string_sized_new (100);
235 while (g_unichar_isspace (g_utf8_get_char (p
))) {
236 p
= g_utf8_next_char (p
);
240 sign
= go_unichar_issign (g_utf8_get_char (p
));
242 g_string_append_c (ascii
, "-/+"[sign
+ 1]);
243 p
= g_utf8_next_char (p
);
247 if (strncmp (p
, decimal
->str
, decimal
->len
) == 0) {
251 go_string_append_gstring (ascii
, decimal
);
253 } else if (g_unichar_isdigit (g_utf8_get_char (p
))) {
254 g_string_append_c (ascii
, '0' + g_unichar_digit_value (g_utf8_get_char (p
)));
255 p
= g_utf8_next_char (p
);
262 /* No conversion, bail to gnm_strto for nan etc. */
263 g_string_free (ascii
, TRUE
);
264 return gnm_strto (s
, end
);
267 if (*p
== 'e' || *p
== 'E') {
270 g_string_append_c (ascii
, 'e');
271 p
= g_utf8_next_char (p
);
273 sign
= go_unichar_issign (g_utf8_get_char (p
));
275 g_string_append_c (ascii
, "-/+"[sign
+ 1]);
276 p
= g_utf8_next_char (p
);
278 while (g_unichar_isdigit (g_utf8_get_char (p
))) {
279 g_string_append_c (ascii
, '0' + g_unichar_digit_value (g_utf8_get_char (p
)));
280 p
= g_utf8_next_char (p
);
284 res
= gnm_strto (ascii
->str
, end
);
286 *end
= g_utf8_offset_to_pointer
287 (s
, spaces
+ g_utf8_pointer_to_offset (ascii
->str
, *end
));
288 g_string_free (ascii
, TRUE
);
294 if (res
!= 0 && gnm_abs (res
) < GNM_MIN
)
303 * Like strtol, but...
304 * 1. handles non-ascii characters
305 * 2. assumes base==10
306 * 3. ensures sane errno on exit
309 gnm_utf8_strtol (const char *s
, char **end
)
314 unsigned long res
= 0, lim
, limd
;
320 while (g_unichar_isspace (g_utf8_get_char (p
)))
321 p
= g_utf8_next_char (p
);
323 sign
= go_unichar_issign (g_utf8_get_char (p
));
325 p
= g_utf8_next_char (p
);
327 lim
= (-(unsigned long)LONG_MIN
) / 10u;
328 limd
= (-(unsigned long)LONG_MIN
) % 10u;
330 lim
= (unsigned long)LONG_MAX
/ 10u;
331 limd
= (unsigned long)LONG_MAX
% 10u;
334 if (!g_unichar_isdigit (g_utf8_get_char (p
))) {
340 while (g_unichar_isdigit (g_utf8_get_char (p
))) {
341 guint8 dig
= g_unichar_digit_value (g_utf8_get_char (p
));
342 p
= g_utf8_next_char (p
);
344 if (res
> lim
|| (res
== lim
&& dig
> limd
)) {
346 while (g_unichar_isdigit (g_utf8_get_char (p
)))
347 p
= g_utf8_next_char (p
);
350 return sign
< 0 ? LONG_MIN
: LONG_MAX
;
353 res
= res
* 10u + dig
;
357 return sign
< 0 ? (long)-res
: (long)res
;
362 gnm_regcomp_XL (GORegexp
*preg
, char const *pattern
, int cflags
,
363 gboolean anchor_start
, gboolean anchor_end
)
365 GString
*res
= g_string_new (NULL
);
369 g_string_append_c (res
, '^');
374 g_string_append (res
, ".*");
379 g_string_append_c (res
, '.');
384 if (pattern
[1] == '*' ||
390 pattern
= go_regexp_quote1 (res
, pattern
);
395 g_string_append_c (res
, '$');
397 retval
= go_regcomp (preg
, res
->str
, cflags
);
398 g_string_free (res
, TRUE
);
403 * gnm_excel_search_impl:
404 * @needle: the pattern to search for, see gnm_regcomp_XL.
405 * @haystack: the string to search in.
406 * @skip: zero-based search start point in characters.
408 * Returns: -1 for a non-match, or zero-based location in
411 * The is the implementation of Excel's SEARCH function.
412 * However, note that @skip and return value are zero-based.
415 gnm_excel_search_impl (const char *needle
, const char *haystack
,
422 for (i
= skip
, hay2
= haystack
; i
> 0; i
--) {
425 hay2
= g_utf8_next_char (hay2
);
428 if (gnm_regcomp_XL (&r
, needle
, GO_REG_ICASE
, FALSE
, FALSE
) == GO_REG_OK
) {
431 switch (go_regexec (&r
, hay2
, 1, &rm
, 0)) {
437 g_utf8_pointer_to_offset (hay2
, hay2
+ rm
.rm_so
);
439 g_warning ("Unexpected go_regexec result");
443 g_warning ("Unexpected regcomp result");
452 color_to_string (PangoColor color
)
454 static char result
[100];
455 sprintf (result
, "%04x:%04x:%04x", color
.red
, color
.green
, color
.blue
);
460 enum_name (GType typ
, int i
)
462 static char result
[100];
463 GEnumClass
*ec
= g_type_class_ref (typ
);
466 GEnumValue
*ev
= g_enum_get_value (ec
, i
);
467 g_type_class_unref (ec
);
469 if (ev
&& ev
->value_nick
)
470 return ev
->value_nick
;
471 if (ev
&& ev
->value_name
)
472 return ev
->value_name
;
475 sprintf (result
, "%d", i
);
480 cb_gnm_pango_attr_dump (PangoAttribute
*attr
, gpointer user_data
)
482 g_print (" start=%u; end=%u\n", attr
->start_index
, attr
->end_index
);
483 switch (attr
->klass
->type
) {
484 case PANGO_ATTR_FAMILY
:
485 g_print (" family=\"%s\"\n", ((PangoAttrString
*)attr
)->value
);
487 case PANGO_ATTR_LANGUAGE
:
488 g_print (" language=\"%s\"\n", pango_language_to_string (((PangoAttrLanguage
*)attr
)->value
));
490 case PANGO_ATTR_STYLE
:
491 g_print (" style=%s\n",
492 enum_name (PANGO_TYPE_STYLE
, ((PangoAttrInt
*)attr
)->value
));
494 case PANGO_ATTR_WEIGHT
:
495 g_print (" weight=%s\n",
496 enum_name (PANGO_TYPE_WEIGHT
, ((PangoAttrInt
*)attr
)->value
));
498 case PANGO_ATTR_VARIANT
:
499 g_print (" variant=%s\n",
500 enum_name (PANGO_TYPE_VARIANT
, ((PangoAttrInt
*)attr
)->value
));
502 case PANGO_ATTR_STRETCH
:
503 g_print (" stretch=%s\n",
504 enum_name (PANGO_TYPE_STRETCH
, ((PangoAttrInt
*)attr
)->value
));
506 case PANGO_ATTR_UNDERLINE
:
507 g_print (" underline=%s\n",
508 enum_name (PANGO_TYPE_UNDERLINE
, ((PangoAttrInt
*)attr
)->value
));
510 case PANGO_ATTR_STRIKETHROUGH
:
511 g_print (" strikethrough=%d\n", ((PangoAttrInt
*)attr
)->value
);
513 case PANGO_ATTR_RISE
:
514 g_print (" rise=%d\n", ((PangoAttrInt
*)attr
)->value
);
516 case PANGO_ATTR_FALLBACK
:
517 g_print (" fallback=%d\n", ((PangoAttrInt
*)attr
)->value
);
519 case PANGO_ATTR_LETTER_SPACING
:
520 g_print (" letter_spacing=%d\n", ((PangoAttrInt
*)attr
)->value
);
522 case PANGO_ATTR_SIZE
:
523 g_print (" size=%d%s\n",
524 ((PangoAttrSize
*)attr
)->size
,
525 ((PangoAttrSize
*)attr
)->absolute
? " abs" : "");
527 case PANGO_ATTR_SCALE
:
528 g_print (" scale=%g\n", ((PangoAttrFloat
*)attr
)->value
);
530 case PANGO_ATTR_FOREGROUND
:
531 g_print (" foreground=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
533 case PANGO_ATTR_BACKGROUND
:
534 g_print (" background=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
536 case PANGO_ATTR_UNDERLINE_COLOR
:
537 g_print (" underline_color=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
539 case PANGO_ATTR_STRIKETHROUGH_COLOR
:
540 g_print (" strikethrough_color=%s\n", color_to_string (((PangoAttrColor
*)attr
)->color
));
542 case PANGO_ATTR_FONT_DESC
: {
543 char *desc
= pango_font_description_to_string (((PangoAttrFontDesc
*)attr
)->desc
);
544 g_print (" font=\"%s\"\n", desc
);
549 g_print (" type=%s\n", enum_name (PANGO_TYPE_ATTR_TYPE
, attr
->klass
->type
));
556 gnm_pango_attr_dump (PangoAttrList
*list
)
558 g_print ("PangoAttrList at %p\n", list
);
559 pango_attr_list_filter (list
, cb_gnm_pango_attr_dump
, NULL
);
565 cb_gnm_pango_attr_list_equal (PangoAttribute
*a
, gpointer _sl
)
568 *sl
= g_slist_prepend (*sl
, a
);
573 * This is a bit of a hack. It might claim a difference even when things
574 * actually are equal. But not the other way around.
577 gnm_pango_attr_list_equal (PangoAttrList
const *l1
, PangoAttrList
const *l2
)
581 else if (l1
== NULL
|| l2
== NULL
)
585 GSList
*sl1
= NULL
, *sl2
= NULL
;
586 (void)pango_attr_list_filter ((PangoAttrList
*)l1
,
587 cb_gnm_pango_attr_list_equal
,
589 (void)pango_attr_list_filter ((PangoAttrList
*)l2
,
590 cb_gnm_pango_attr_list_equal
,
594 const PangoAttribute
*a1
= sl1
->data
;
595 const PangoAttribute
*a2
= sl2
->data
;
596 if (a1
->start_index
!= a2
->start_index
||
597 a1
->end_index
!= a2
->end_index
||
598 !pango_attribute_equal (a1
, a2
))
600 sl1
= g_slist_delete_link (sl1
, sl1
);
601 sl2
= g_slist_delete_link (sl2
, sl2
);
611 /* ------------------------------------------------------------------------- */
615 char *monetary_locale
;
618 * gnm_push_C_locale: (skip)
620 * Returns the current locale, and sets the locale and the value-format
621 * engine's locale to 'C'. The caller must call gnm_pop_C_locale to free the
622 * result and restore the previous locale.
625 gnm_push_C_locale (void)
627 GnmLocale
*old
= g_new0 (GnmLocale
, 1);
629 old
->num_locale
= g_strdup (go_setlocale (LC_NUMERIC
, NULL
));
630 go_setlocale (LC_NUMERIC
, "C");
631 old
->monetary_locale
= g_strdup (go_setlocale (LC_MONETARY
, NULL
));
632 go_setlocale (LC_MONETARY
, "C");
633 go_locale_untranslated_booleans ();
639 * gnm_pop_C_locale: (skip)
640 * @locale: #GnmLocale
642 * Frees the result of gnm_push_C_locale and restores the original locale.
645 gnm_pop_C_locale (GnmLocale
*locale
)
647 /* go_setlocale restores bools to locale translation */
648 go_setlocale (LC_MONETARY
, locale
->monetary_locale
);
649 g_free (locale
->monetary_locale
);
650 go_setlocale (LC_NUMERIC
, locale
->num_locale
);
651 g_free (locale
->num_locale
);
655 /* ------------------------------------------------------------------------- */
658 gnm_debug_flag (const char *flag
)
661 key
.key
= (char *)flag
;
664 return g_parse_debug_string (g_getenv ("GNM_DEBUG"), &key
, 1) != 0;
667 /* ------------------------------------------------------------------------- */
670 gnm_string_add_number (GString
*buf
, gnm_float d
)
672 size_t old_len
= buf
->len
;
677 gnm_float l10
= gnm_log10 (FLT_RADIX
);
678 digits
= (int)gnm_ceil (GNM_MANT_DIG
* l10
) +
679 (l10
== (int)l10
? 0 : 1);
682 g_string_append_printf (buf
, "%.*" GNM_FORMAT_g
, digits
- 1, d
);
683 d2
= gnm_strto (buf
->str
+ old_len
, NULL
);
686 g_string_truncate (buf
, old_len
);
687 g_string_append_printf (buf
, "%.*" GNM_FORMAT_g
, digits
, d
);
691 /* ------------------------------------------------------------------------- */
694 gnm_insert_meta_date (GODoc
*doc
, char const *name
)
696 GValue
*value
= g_new0 (GValue
, 1);
698 GsfTimestamp
*ts
= gsf_timestamp_new ();
700 g_get_current_time (&tm
);
703 gsf_timestamp_set_time (ts
, tm
.tv_sec
);
704 g_value_init (value
, GSF_TIMESTAMP_TYPE
);
705 gsf_timestamp_to_value (ts
, value
);
706 gsf_timestamp_free (ts
);
708 gsf_doc_meta_data_insert (go_doc_get_meta_data (doc
),
713 /* ------------------------------------------------------------------------- */
716 * gnm_object_get_bool:
718 * @name: property name
720 * Returns: the value of @o's boolean property @name.
723 gnm_object_get_bool (gpointer o
, const char *name
)
726 g_object_get (o
, name
, &b
, NULL
);
731 * gnm_object_has_readable_prop:
733 * @property: property name
734 * @typ: property's type or %G_TYPE_NONE. (Exact type, not is-a.)
735 * @pres: (out) (optional): location to store property value.
737 * Returns: %TRUE if @obj has a readable property named @property
741 gnm_object_has_readable_prop (gconstpointer obj
, const char *property
,
742 GType typ
, gpointer pres
)
750 klass
= G_OBJECT_GET_CLASS (G_OBJECT (obj
));
751 spec
= g_object_class_find_property (klass
, property
);
753 !(G_PARAM_READABLE
& spec
->flags
) ||
754 (typ
!= G_TYPE_NONE
&& spec
->value_type
!= typ
))
758 g_object_get (G_OBJECT (obj
), property
, pres
, NULL
);
762 /* ------------------------------------------------------------------------- */
765 gnm_float_equal (gnm_float
const *a
, const gnm_float
*b
)
771 gnm_float_hash (gnm_float
const *d
)
774 gnm_float mant
= gnm_frexp (gnm_abs (*d
), &expt
);
775 guint h
= ((guint
)(0x80000000u
* mant
)) ^ expt
;
781 /* ------------------------------------------------------------------------- */
784 GnmHashTableOrder order
;
789 cb_compare (gconstpointer a_
, gconstpointer b_
, gpointer user_data
)
791 struct cb_compare
*user
= user_data
;
792 gpointer
*a
= (gpointer
)a_
;
793 gpointer
*b
= (gpointer
)b_
;
795 return user
->order (a
[0], a
[1], b
[0], b
[1], user
->user
);
800 * gnm_hash_table_foreach_ordered:
802 * @callback: (scope call): #GHFunc
803 * @order: (scope call): Ordering function
804 * @user: user data for callback and order
806 * Like g_hash_table_foreach, but with an ordering imposed.
809 gnm_hash_table_foreach_ordered (GHashTable
*h
,
811 GnmHashTableOrder order
,
817 GHashTableIter hiter
;
820 /* Gather all key-value pairs */
821 data
= g_ptr_array_new ();
822 g_hash_table_iter_init (&hiter
, h
);
823 while (g_hash_table_iter_next (&hiter
, &key
, &value
)) {
824 g_ptr_array_add (data
, key
);
825 g_ptr_array_add (data
, value
);
828 /* Sort according to given ordering */
831 g_qsort_with_data (data
->pdata
,
832 data
->len
/ 2, 2 * sizeof (gpointer
),
836 /* Call user callback with all pairs */
837 for (ui
= 0; ui
< data
->len
; ui
+= 2)
838 callback (g_ptr_array_index (data
, ui
),
839 g_ptr_array_index (data
, ui
+ 1),
843 g_ptr_array_free (data
, TRUE
);
846 /* ------------------------------------------------------------------------- */
849 gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc
**pdoc
)
851 gutils_xml_in_docs
= g_slist_prepend (gutils_xml_in_docs
, pdoc
);
854 /* ------------------------------------------------------------------------- */
857 * gnm_file_saver_get_sheet:
859 * @wbv: #WorkbookView
861 * For a single-sheet saver, this function determines what sheet to save.
863 * Returns: (transfer none): the sheet to export
866 gnm_file_saver_get_sheet (GOFileSaver
const *fs
, WorkbookView
const *wbv
)
871 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), NULL
);
872 g_return_val_if_fail (go_file_saver_get_save_scope (fs
) ==
873 GO_FILE_SAVE_SHEET
, NULL
);
874 g_return_val_if_fail (GNM_IS_WORKBOOK_VIEW (wbv
), NULL
);
876 wb
= wb_view_get_workbook (wbv
);
878 sel
= g_object_get_data (G_OBJECT (wb
), SHEET_SELECTION_KEY
);
881 return g_ptr_array_index (sel
, 0);
882 g_critical ("Someone messed up sheet selection");
885 return wb_view_cur_sheet (wbv
);
889 * gnm_file_saver_get_sheets:
891 * @wbv: #WorkbookView
892 * @default_all: If %TRUE, all sheets will be selected by default; if %FALSE,
893 * this function will return %NULL if no sheets were explicitly selected.
895 * This function determines what sheets to save.
897 * Returns: (transfer container) (element-type Sheet): the sheets to export
899 * Note: the return value should be unreffed, not freed.
902 gnm_file_saver_get_sheets (GOFileSaver
const *fs
,
903 WorkbookView
const *wbv
,
904 gboolean default_all
)
907 GPtrArray
*sel
, *sheets
;
908 GOFileSaveScope save_scope
;
910 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), NULL
);
911 g_return_val_if_fail (GNM_IS_WORKBOOK_VIEW (wbv
), NULL
);
913 save_scope
= go_file_saver_get_save_scope (fs
);
914 wb
= wb_view_get_workbook (wbv
);
915 sel
= g_object_get_data (G_OBJECT (wb
), SHEET_SELECTION_KEY
);
916 sheets
= g_object_get_data (G_OBJECT (wb
), SSCONVERT_SHEET_SET_KEY
);
918 g_ptr_array_ref (sel
);
920 sel
= g_ptr_array_ref (sheets
);
921 else if (save_scope
!= GO_FILE_SAVE_WORKBOOK
) {
922 sel
= g_ptr_array_new ();
923 g_ptr_array_add (sel
, wb_view_cur_sheet (wbv
));
924 } else if (default_all
) {
926 sel
= g_ptr_array_new ();
927 for (i
= 0; i
< workbook_sheet_count (wb
); i
++) {
928 Sheet
*sheet
= workbook_sheet_by_index (wb
, i
);
929 g_ptr_array_add (sel
, sheet
);
937 gnm_file_saver_common_export_option (GOFileSaver
const *fs
,
939 const char *key
, const char *value
,
945 g_return_val_if_fail (GO_IS_FILE_SAVER (fs
), FALSE
);
946 g_return_val_if_fail (GNM_IS_WORKBOOK (wb
), FALSE
);
947 g_return_val_if_fail (key
!= NULL
, FALSE
);
948 g_return_val_if_fail (value
!= NULL
, FALSE
);
950 if (strcmp (key
, "sheet") == 0) {
952 Sheet
*sheet
= workbook_sheet_by_name (wb
, value
);
956 *err
= g_error_new (go_error_invalid (), 0,
957 _("Unknown sheet \"%s\""),
962 sheets
= g_object_get_data (G_OBJECT (wb
), SSCONVERT_SHEET_SET_KEY
);
964 sheets
= g_ptr_array_new ();
965 g_object_set_data_full (G_OBJECT (wb
),
966 SSCONVERT_SHEET_SET_KEY
,
968 (GDestroyNotify
)g_ptr_array_unref
);
970 g_ptr_array_add (sheets
, sheet
);
976 *err
= g_error_new (go_error_invalid (), 0,
977 _("Invalid export option \"%s\" for format %s"),
979 go_file_saver_get_id (fs
));