26 |
#include "gtksheet.h" |
#include "gtksheet.h" |
27 |
|
|
28 |
#include "pspp-dict.h" |
#include "pspp-dict.h" |
29 |
|
#include "sfm-write.h" |
30 |
|
#include "case.h" |
31 |
|
|
32 |
#define _(A) A |
#define _(A) A |
33 |
#define N_(A) A |
#define N_(A) A |
69 |
|
|
70 |
/* Return the width that an 'M' character would occupy when typeset at |
/* Return the width that an 'M' character would occupy when typeset at |
71 |
row, col */ |
row, col */ |
72 |
guint |
static guint |
73 |
M_width(GtkSheet *sheet, gint row, gint col) |
M_width(GtkSheet *sheet, gint row, gint col) |
74 |
{ |
{ |
75 |
GtkSheetCellAttr attributes; |
GtkSheetCellAttr attributes; |
255 |
return sheet; |
return sheet; |
256 |
|
|
257 |
} |
} |
258 |
|
|
259 |
|
void |
260 |
|
psppire_create_system_file(GtkSheet *sheet, PSPP_Dict *d, struct file_handle *handle) |
261 |
|
{ |
262 |
|
gint r; |
263 |
|
g_print("Saving system file\n"); |
264 |
|
|
265 |
|
const struct sfm_write_options wo = {true, false, 3}; |
266 |
|
|
267 |
|
struct sfm_writer *writer = sfm_open_writer(handle, d->dict, wo); |
268 |
|
|
269 |
|
g_assert(writer); |
270 |
|
|
271 |
|
|
272 |
|
gint var_cnt = pspp_dict_get_var_cnt(d); |
273 |
|
|
274 |
|
|
275 |
|
for (r = 0 ; r < gtk_sheet_get_rows_count(sheet) ; ++r ) |
276 |
|
{ |
277 |
|
struct ccase mycase; |
278 |
|
gint c; |
279 |
|
|
280 |
|
case_create(&mycase, dict_get_next_value_idx(d->dict)); |
281 |
|
|
282 |
|
for ( c = 0 ; c < var_cnt ; ++c ) |
283 |
|
{ |
284 |
|
struct variable *v = dict_get_var (d->dict, c); |
285 |
|
|
286 |
|
union value *value = case_data_rw (&mycase, v->fv); |
287 |
|
const gchar *text = gtk_sheet_cell_get_text (sheet, r, c); |
288 |
|
|
289 |
|
if ( v->type == ALPHA) |
290 |
|
{ |
291 |
|
memset (value->s, ' ', MAX_SHORT_STRING); |
292 |
|
|
293 |
|
if ( text) |
294 |
|
{ |
295 |
|
memcpy(value->s, text, strlen(text)); |
296 |
|
} |
297 |
|
} |
298 |
|
else |
299 |
|
{ |
300 |
|
if (text) |
301 |
|
value->f = atoi(text); |
302 |
|
else |
303 |
|
value->f = SYSMIS; |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
|
if ( ! sfm_write_case(writer, &mycase) ) |
308 |
|
g_print("Failed to write case %d\n",r); |
309 |
|
|
310 |
|
case_destroy(&mycase); |
311 |
|
|
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
sfm_close_writer(writer); |
316 |
|
} |