Introspection fixes
[gnumeric.git] / src / stf-parse.h
blob18b28898fe1f9ba2a98cba553a36223effac6497
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_STF_PARSE_H_
3 # define _GNM_STF_PARSE_H_
5 #include <glib.h>
6 #include <gnumeric.h>
8 G_BEGIN_DECLS
10 typedef enum {
11 PARSE_TYPE_NOTSET = 1 << 0,
12 PARSE_TYPE_CSV = 1 << 1,
13 PARSE_TYPE_FIXED = 1 << 2
14 } StfParseType_t;
16 /* Additive. */
17 typedef enum {
18 TRIM_TYPE_NEVER = 0,
19 TRIM_TYPE_LEFT = 1 << 0,
20 TRIM_TYPE_RIGHT = 1 << 1
21 } StfTrimType_t;
23 typedef struct {
24 StfParseType_t parsetype; /* The type of import to do */
25 StfTrimType_t trim_spaces; /* Trim spaces in fields? */
27 GSList * terminator; /* Line terminators */
28 char * locale;
30 struct _StfCompiledTerminator {
31 guchar min, max;
32 } compiled_terminator;
34 /* CSV related */
35 struct _StfSeparator {
36 GSList *str;
37 char *chr;
38 gboolean duplicates; /* See two text separators as one? */
39 } sep;
40 gunichar stringindicator; /* String indicator */
41 gboolean indicator_2x_is_single;/* 2 quote chars form a single non-terminating quote */
42 gboolean trim_seps; /* Ignore initial seps. */
44 /* Fixed width related */
45 GArray *splitpositions; /* Positions where text will be split vertically */
47 gboolean *col_autofit_array; /* 0/1 array indicating */
48 /* which col widths to autofit */
49 gboolean *col_import_array; /* 0/1 array indicating */
50 /* which cols to import */
51 unsigned int col_import_array_len;
53 GPtrArray *formats; /* Contains GOFormat *s */
54 GPtrArray *formats_decimal; /* Contains GString *s */
55 GPtrArray *formats_thousand; /* Contains GString *s */
56 GPtrArray *formats_curr; /* Contains GString *s */
58 gboolean cols_exceeded; /* This is set to TRUE if */
59 /* we tried to import more than */
60 /* SHEET_MAX_COLS columns */
61 gboolean rows_exceeded; /* Ditto rows. */
62 unsigned ref_count; /* Boxed type */
63 } StfParseOptions_t;
65 /* CREATION/DESTRUCTION of stf options struct */
67 GType stf_parse_options_get_type (void);
68 void stf_parse_options_free (StfParseOptions_t *parseoptions);
70 StfParseOptions_t *stf_parse_options_guess (char const *data);
71 StfParseOptions_t *stf_parse_options_guess_csv (char const *data);
72 void stf_parse_options_guess_formats (StfParseOptions_t *po,
73 char const *data);
75 /* MANIPULATION of stf options struct */
77 void stf_parse_options_set_type (StfParseOptions_t *parseoptions,
78 StfParseType_t const parsetype);
79 void stf_parse_options_clear_line_terminator (StfParseOptions_t *parseoptions);
80 void stf_parse_options_add_line_terminator (StfParseOptions_t *parseoptions,
81 char const *terminator);
82 void stf_parse_options_set_trim_spaces (StfParseOptions_t *parseoptions,
83 StfTrimType_t const trim_spaces);
84 void stf_parse_options_csv_set_separators (StfParseOptions_t *parseoptions,
85 char const *character, GSList const *seps);
86 void stf_parse_options_csv_set_stringindicator (StfParseOptions_t *parseoptions,
87 gunichar const stringindicator);
88 void stf_parse_options_csv_set_indicator_2x_is_single (StfParseOptions_t *parseoptions,
89 gboolean const indic_2x);
90 void stf_parse_options_csv_set_duplicates (StfParseOptions_t *parseoptions,
91 gboolean const duplicates);
92 void stf_parse_options_csv_set_trim_seps (StfParseOptions_t *parseoptions,
93 gboolean const trim_seps);
94 void stf_parse_options_fixed_splitpositions_clear (StfParseOptions_t *parseoptions);
95 void stf_parse_options_fixed_splitpositions_add (StfParseOptions_t *parseoptions,
96 int position);
97 void stf_parse_options_fixed_splitpositions_remove (StfParseOptions_t *parseoptions,
98 int position);
99 int stf_parse_options_fixed_splitpositions_count (StfParseOptions_t *parseoptions);
100 int stf_parse_options_fixed_splitpositions_nth (StfParseOptions_t *parseoptions, int n);
102 /* USING the stf structs to actually do some parsing, these are the lower-level functions and utility functions */
104 GPtrArray *stf_parse_general (StfParseOptions_t *parseoptions,
105 GStringChunk *lines_chunk,
106 char const *data,
107 char const *data_end);
108 void stf_parse_general_free (GPtrArray *lines);
109 GPtrArray *stf_parse_lines (StfParseOptions_t *parseoptions,
110 GStringChunk *lines_chunk,
111 char const *data,
112 int maxlines,
113 gboolean with_lineno);
115 void stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions,
116 char const *data,
117 char const *data_end);
119 char const *stf_parse_find_line (StfParseOptions_t *parseoptions,
120 char const *data,
121 int line);
123 /* Higher level functions, can be used for directly parsing into an application specific data container */
124 gboolean stf_parse_sheet (StfParseOptions_t *parseoptions,
125 char const *data, char const *data_end,
126 Sheet *sheet,
127 int start_col, int start_row);
129 GnmCellRegion *stf_parse_region (StfParseOptions_t *parseoptions,
130 char const *data, char const *data_end,
131 Workbook const *wb);
133 G_END_DECLS
135 #endif /* _GNM_STF_PARSE_H_ */