projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix broken expose callback in pspp-sheet-view
[pspp]
/
src
/
data
/
sys-file-writer.c
diff --git
a/src/data/sys-file-writer.c
b/src/data/sys-file-writer.c
index fe96d3cbba86be2212ac81b93788e892a0e3fd4a..d02369856f356a08b33e3a9e5f4a7ac8d21eb5c6 100644
(file)
--- a/
src/data/sys-file-writer.c
+++ b/
src/data/sys-file-writer.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-
9, 2000, 2006, 2007, 2009, 2010, 2011
Free Software Foundation, Inc.
+ Copyright (C) 1997-
2000, 2006-2012
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-74,6
+74,7
@@
struct sfm_writer
bool compress; /* 1=compressed, 0=not compressed. */
casenumber case_cnt; /* Number of cases written so far. */
bool compress; /* 1=compressed, 0=not compressed. */
casenumber case_cnt; /* Number of cases written so far. */
+ uint8_t space; /* ' ' in the file's character encoding. */
/* Compression buffering.
/* Compression buffering.
@@
-176,6
+177,7
@@
struct casewriter *
sfm_open_writer (struct file_handle *fh, struct dictionary *d,
struct sfm_write_options opts)
{
sfm_open_writer (struct file_handle *fh, struct dictionary *d,
struct sfm_write_options opts)
{
+ struct encoding_info encoding_info;
struct sfm_writer *w;
mode_t mode;
int i;
struct sfm_writer *w;
mode_t mode;
int i;
@@
-227,6
+229,9
@@
sfm_open_writer (struct file_handle *fh, struct dictionary *d,
goto error;
}
goto error;
}
+ get_encoding_info (&encoding_info, dict_get_encoding (d));
+ w->space = encoding_info.space[0];
+
/* Write the file header. */
write_header (w, d);
/* Write the file header. */
write_header (w, d);
@@
-311,6
+316,7
@@
calc_oct_idx (const struct dictionary *d, struct variable *target_var)
static void
write_header (struct sfm_writer *w, const struct dictionary *d)
{
static void
write_header (struct sfm_writer *w, const struct dictionary *d)
{
+ const char *dict_encoding = dict_get_encoding (d);
char prod_name[61];
char creation_date[10];
char creation_time[9];
char prod_name[61];
char creation_date[10];
char creation_time[9];
@@
-320,7
+326,10
@@
write_header (struct sfm_writer *w, const struct dictionary *d)
time_t t;
/* Record-type code. */
time_t t;
/* Record-type code. */
- write_string (w, "$FL2", 4);
+ if (is_encoding_ebcdic_compatible (dict_encoding))
+ write_string (w, EBCDIC_MAGIC, 4);
+ else
+ write_string (w, ASCII_MAGIC, 4);
/* Product identification. */
snprintf (prod_name, sizeof prod_name, "@(#) SPSS DATA FILE %s - %s",
/* Product identification. */
snprintf (prod_name, sizeof prod_name, "@(#) SPSS DATA FILE %s - %s",
@@
-708,6
+717,12
@@
write_mrsets (struct sfm_writer *w, const struct dictionary *dict,
size_t n_mrsets;
size_t i;
size_t n_mrsets;
size_t i;
+ if (is_encoding_ebcdic_compatible (encoding))
+ {
+ /* FIXME. */
+ return;
+ }
+
n_mrsets = dict_get_n_mrsets (dict);
if (n_mrsets == 0)
return;
n_mrsets = dict_get_n_mrsets (dict);
if (n_mrsets == 0)
return;
@@
-759,11
+774,12
@@
write_mrsets (struct sfm_writer *w, const struct dictionary *dict,
for (j = 0; j < mrset->n_vars; j++)
{
const char *short_name_utf8 = var_get_short_name (mrset->vars[j], 0);
for (j = 0; j < mrset->n_vars; j++)
{
const char *short_name_utf8 = var_get_short_name (mrset->vars[j], 0);
+ char *lower_name_utf8 = utf8_to_lower (short_name_utf8);
char *short_name = recode_string (encoding, "UTF-8",
char *short_name = recode_string (encoding, "UTF-8",
- short_name_utf8, -1);
- str_lowercase (short_name);
+ lower_name_utf8, -1);
ds_put_format (&s, " %s", short_name);
free (short_name);
ds_put_format (&s, " %s", short_name);
free (short_name);
+ free (lower_name_utf8);
}
ds_put_byte (&s, '\n');
}
}
ds_put_byte (&s, '\n');
}
@@
-952,6
+968,7
@@
static void
write_integer_info_record (struct sfm_writer *w,
const struct dictionary *d)
{
write_integer_info_record (struct sfm_writer *w,
const struct dictionary *d)
{
+ const char *dict_encoding = dict_get_encoding (d);
int version_component[3];
int float_format;
int codepage;
int version_component[3];
int float_format;
int codepage;
@@
-973,13
+990,21
@@
write_integer_info_record (struct sfm_writer *w,
abort ();
/* Choose codepage. */
abort ();
/* Choose codepage. */
- codepage = sys_get_codepage_from_encoding (dict_
get_encoding (d)
);
+ codepage = sys_get_codepage_from_encoding (dict_
encoding
);
if (codepage == 0)
{
if (codepage == 0)
{
- /* Default to "7-bit ASCII" if the codepage number is unknown, because
+ /* The codepage is unknown. Choose a default.
+
+ For an EBCDIC-compatible encoding, use the value for EBCDIC.
+
+ For an ASCII-compatible encoding, default to "7-bit ASCII", because
many files use this codepage number regardless of their actual
many files use this codepage number regardless of their actual
- encoding. */
- codepage = 2;
+ encoding.
+ */
+ if (is_encoding_ascii_compatible (dict_encoding))
+ codepage = 2;
+ else if (is_encoding_ebcdic_compatible (dict_encoding))
+ codepage = 1;
}
/* Write record. */
}
/* Write record. */
@@
-1238,7
+1263,7
@@
put_cmp_string (struct sfm_writer *w, const void *data, size_t size)
assert (w->data_cnt < 8);
assert (size <= 8);
assert (w->data_cnt < 8);
assert (size <= 8);
- memset (w->data[w->data_cnt],
' '
, 8);
+ memset (w->data[w->data_cnt],
w->space
, 8);
memcpy (w->data[w->data_cnt], data, size);
w->data_cnt++;
}
memcpy (w->data[w->data_cnt], data, size);
w->data_cnt++;
}
@@
-1300,7
+1325,7
@@
write_string (struct sfm_writer *w, const char *string, size_t width)
size_t pad_bytes = width - data_bytes;
write_bytes (w, string, data_bytes);
while (pad_bytes-- > 0)
size_t pad_bytes = width - data_bytes;
write_bytes (w, string, data_bytes);
while (pad_bytes-- > 0)
- putc (
' '
, w->file);
+ putc (
w->space
, w->file);
}
/* Recodes null-terminated UTF-8 encoded STRING into ENCODING, and writes the
}
/* Recodes null-terminated UTF-8 encoded STRING into ENCODING, and writes the
@@
-1361,5
+1386,5
@@
static void
write_spaces (struct sfm_writer *w, size_t n)
{
while (n-- > 0)
write_spaces (struct sfm_writer *w, size_t n)
{
while (n-- > 0)
- putc (
' '
, w->file);
+ putc (
w->space
, w->file);
}
}