Ben Pfaff [Sun, 24 Apr 2011 03:15:18 +0000 (20:15 -0700)]
sys-file-writer: Fix encoding of several string fields.
PSPP keeps most string data in the dictionary in UTF-8. The system
file writer needs to recode this data into the correct encoding, but
in several cases it failed to do so. This fixes the problem.
Thanks to Mindaugas for reporting the problem and to John Darrington
for help diagnosing it.
Ben Pfaff [Sun, 24 Apr 2011 05:10:20 +0000 (22:10 -0700)]
sys-file-reader: Take string encoding into account for text records.
The 'encoding' member of struct sfm_reader was not filled in anywhere,
so it was always NULL, which meant that the recode operation in
open_text_record() was a no-op.
Ben Pfaff [Sun, 24 Apr 2011 04:40:48 +0000 (21:40 -0700)]
dictionary: Make dict_create() take the new dictionary's encoding.
There are several places in the PSPP tree that create dictionaries,
but few of them actually set an encoding. This causes most
dictionaries to be in the default encoding, which is often not
correct.
By making dict_create() take the encoding as a parameter we force
the caller to think about the encoding issue up-front.
Ben Pfaff [Sat, 23 Apr 2011 19:01:35 +0000 (12:01 -0700)]
dictionary: Set encoding early when cloning a dictionary.
Many operations that involve the names of variables and other entities
in a dictionary depend on the dictionary's encoding, so it is
potentially important to have the encoding set properly when adding
other entities to the dictionary.
Ben Pfaff [Sat, 23 Apr 2011 18:59:49 +0000 (11:59 -0700)]
short-names: Consider character encoding when making short names.
Variable names and short names are always in UTF-8, but the length of
short names needs to be limited to 8 bytes in the dictionary encoding,
not in UTF-8. This commit fixes that problem.
Ben Pfaff [Sun, 24 Apr 2011 04:59:38 +0000 (21:59 -0700)]
dissect-sysfile: Don't omit the last in a series of text tokens.
Otherwise dissect-sysfile would not print the last long string
variable name written by sys-file-writer, because it did not include
a separator byte after the last record. (This was obvious running
dissect-sysfile on a system file with only one variable.)
Ben Pfaff [Sat, 23 Apr 2011 05:29:19 +0000 (22:29 -0700)]
ascii: Print syntax in output single-spaced.
When SET PRINTBACK=ON was in effect, the ASCII output driver would
put a blank line between successive lines of syntax, because each line
was output separately. This commit fixes that, by causing the output
core to combine successive syntax output items into a single item that
contains multiple lines of text. This was essentially what the HTML
output driver was doing anyhow, so putting this into the core also
allows removing the corresponding logic from the HTML driver.
Ben Pfaff [Sat, 23 Apr 2011 05:10:04 +0000 (22:10 -0700)]
ascii: Don't print command names in output.
This seems to be closer to what users expect.
I think that having the command names in output was being confused
by users with SET PRINTBACK=ON (see e.g. bug #31561) even though I
really just added that so that there are clear titles for the output
that goes with each procedure. This change should help, I think.
It might make sense to make drivers only print the titles of
procedures that have other output, but this commit doesn't do that.
Ben Pfaff [Sat, 23 Apr 2011 03:21:57 +0000 (20:21 -0700)]
ascii: Add support for multibyte characters.
This commit modifies render.at, changing hyphens to non-breaking
hyphens. This change is only to ensure that the output for the tests
in render.at are the same afterward. Without these changes, these
tests wrap these tables differently, because they break after the
hyphens; before, only spaces were considered valid breakpoints.
Ben Pfaff [Sat, 16 Apr 2011 18:20:59 +0000 (11:20 -0700)]
gui: Fix crash in executor when inline data is missing.
Without this commit, typing "DATA LIST /x 1." into an otherwise empty
syntax window and executing it caused a crash because the lexer was
being accessed after it was destroyed. This commit averts the crash.
Ben Pfaff [Sat, 16 Apr 2011 05:49:00 +0000 (22:49 -0700)]
table-casereader: Put space between columns.
When table_casereaders are pasted together next to each other, there
should normally be a little bit of space between neighboring columns,
instead of having them directly abutting. This makes the output of
LIST, for example, much more readable.
Without this commit, LIST output for three variables named x, y, and
z, all with F1.0 format, looks something like this:
Ben Pfaff [Sat, 16 Apr 2011 05:26:43 +0000 (22:26 -0700)]
render: Fix rendering of TAL_GAP rules.
A rule that is set to TAL_GAP is supposed to have the same width or
height as a rule of type TAL_1, but without drawing the line. That
is, it is supposed to be a small blank space between rows or columns.
Unfortunately, TAL_GAP was not implemented properly in the rendering
code. It was treated just like TAL_0, which meant that it was ignored
and no gap appeared.
This commit implements TAL_GAP, fixing the problem.
Ben Pfaff [Sat, 16 Apr 2011 03:16:02 +0000 (20:16 -0700)]
configure: Invoke AM_GNU_GETTEXT by hand.
The Gnulib "gettext" module does not invoke AM_GNU_GETTEXT, because
gnulib-tool uses "sed" to filter it out. So we must invoke it
ourselves.
John Darrington narrowed the problem down to the commit b54a5702b6
"Fix up build following dropping ulc-width-linebreaks module" that
started using the gettext Gnulib module.
Ben Pfaff [Tue, 12 Apr 2011 13:48:08 +0000 (06:48 -0700)]
value-parser: Make parse_value() accept variable's print format also.
Previously commands such as VALUE LABELS required numeric values to
be given as plain numbers, but this makes it difficult to add
meaningful value labels for variables with date and time formats.
This commit allows values for this command and a few others to be
given in a variable's print format instead.
Ben Pfaff [Tue, 12 Apr 2011 13:45:33 +0000 (06:45 -0700)]
DISPLAY: Display values for value labels using the variable's format.
Until now, the values in value labels have been displayed as plain
numbers, but this makes the values for variables with date and time
formats unreadable. Changing them to use the variable's own format
makes them easier to read.
Ben Pfaff [Tue, 12 Apr 2011 13:43:04 +0000 (06:43 -0700)]
tab: Make tab_value() take a variable instead of a dictionary.
It seems far more likely that callers will have the variable handy
than the dictionary. Also, when the variable is used the format can
be optional since tab_value() can get it from the variable's print
format.
Ben Pfaff [Sun, 10 Apr 2011 16:52:31 +0000 (09:52 -0700)]
gui: psppire-var-view: Change "<unset>" to null string.
Commit 0cb2b9c42 caused NULL variables to be displayed as "<unset>".
This commit changes that to the empty string, which doesn't require
translation and is equally clear.
Suggested by John Darrington <john@darrington.wattle.id.au>.
Ben Pfaff [Sat, 9 Apr 2011 23:53:26 +0000 (16:53 -0700)]
gui: Fix crash in Paired T-Test dialog on selecting first variable.
When a variable is moved into the list of selected variables in the
Paired T-Test dialog, that row of the treeview has one nonnull
variable and one null variable. Calling var_get_name(NULL) causes a
segfault.
I'm not certain that this is the correct fix, but it fixes the
segfault. The missing variable is now shown as <unset> until a second
variable is moved into the treeview.
Ben Pfaff [Sat, 9 Apr 2011 23:50:44 +0000 (16:50 -0700)]
gui: Fix Glib warnings for dialogs in realize and configure callbacks.
The GtkBuilder documentation says:
Prior to 2.20, GtkBuilder was setting the "name" property of
constructed widgets to the "id" attribute. In GTK+ 2.20 or newer,
you have to use gtk_buildable_get_name() instead of
gtk_widget_get_name() to obtain the "id", or set the "name"
property in your UI definition.
This commit fixes the problem by switching from using the "name"
property to calling gtk_buildable_get_name().
Ben Pfaff [Fri, 8 Apr 2011 04:49:13 +0000 (21:49 -0700)]
tests: Only check MODE=360 when EBCDIC is supported.
Jeremy Lavergne <jeremy@lavergne.gotdns.org> reported that these tests
fail on Mac OS X. testsuite.log showed that Mac OS X did not support
the EBCDIC-US encoding, so this OS cannot support these tests.
Ben Pfaff [Fri, 8 Apr 2011 04:05:31 +0000 (21:05 -0700)]
gui: widget-io: Fix cleanup code in widget_printf(), widget_scanf().
The 'arg' member of arguments and the 'dir' member of char_directives
are only allocated from malloc() if there are more than fit in the
arrays that are included inside their respective structures, so they
must only be freed when that internal structure is not used.
Also, these arrays are allocated with malloc() and so must be freed
with free(), not g_free().
Thanks to Benoit Flippen <anagogue@gmail.com> for reporting the
problem.
Ben Pfaff [Wed, 23 Mar 2011 05:10:49 +0000 (22:10 -0700)]
cairo: Correctly render table during scrolling.
Commit 845d4b4f3f (cairo: Draw table titles in xr_rendering_draw()
too) started rendering table titles in the GUI but forgot to
compensate for this in the call to render_page_draw_region(), so
scrolling caused visible damage.
Bug #31569. Reported-by: John Darrington <john@darrington.wattle.id.au>
Ben Pfaff [Wed, 23 Mar 2011 04:20:04 +0000 (21:20 -0700)]
i18n: Only close valid iconv converters in i18n_done().
iconv_open() returns (iconv_t) -1 to indicate an error. We shouldn't
pass this to iconv_Close().
Reported-by: Jeremy Lavergne <jeremy@lavergne.gotdns.org>.
John Darrington suggested that this was probably the problem, and
Jeremy confirmed it with valgrind.
Ben Pfaff [Wed, 23 Mar 2011 03:55:55 +0000 (20:55 -0700)]
str: Make ss_alloc_substring_pool() null-terminate its output.
It's inconsistent that ss_alloc_substring() null-terminates its output
but ss_alloc_substring_pool() does not. This caught us out in
recode_substring_pool(), which used ss_alloc_substring_pool() in a
fallback case where create_iconv() failed and expected the result to
be null-terminated.
Reported-by: Jeremy Lavergne <jeremy@lavergne.gotdns.org>
Ben Pfaff [Mon, 21 Mar 2011 04:03:15 +0000 (21:03 -0700)]
Fix up build following dropping ulc-width-linebreaks module.
Commit b5cebf00d5e "Smake: Remove module"
unexpectedly broke the build, because ulc-width-linebreaks had several
indirect dependencies that PSPP actually used but were not in the
list of Gnulib modules in Smake. This fixes the problem.
The oddest consequence fixed by this commit has to do with
build-aux/config.rpath. AM_GNU_GETTEXT requires this file, which is
supplied by only a few Gnulib modules: havelib, gettext, and
threadlib. ulc-width-linebreaks depended indirectly on havelib, but
PSPP did not otherwise depend on any of these modules. It seemed that
the best fix was simply to use the Gnulib gettext module, which is
what this commit does.
Ben Pfaff [Sun, 20 Mar 2011 18:39:55 +0000 (11:39 -0700)]
Change terminology from "active file" to "active dataset".
I plan to introduce the concept of multiple datasets. One of these is
active at any given time, and the others are inactive. Each one is
similar to what has been called the "active file" until now. Thus, it
is natural to rename the "active file" to the "active dataset". I
guess that this greater uniformity of terminology will cause less
user confusion.
Ben Pfaff [Sun, 20 Mar 2011 00:05:47 +0000 (17:05 -0700)]
lexer: Reimplement for better testability and internationalization.
This commit reimplements PSPP lexical analysis from the ground up.
From a PSPP user's perspective, this should make PSPP more reliable
and make it easier to work with syntax files in non-ASCII encodings.
See the changes to NEWS for more details.
From a developer's perspective, the most visible change may be that
strings within tokens are now always encoded in UTF-8, regardless of
the syntax file's encoding. Many of the changes in this commit are
due to this, especially those to functions that check for valid
identifiers: an identifier in UTF-8 is not necessarily the same length
when encoded in the dictionary's encoding, but limits on identifier
length must be enforced in the dictionary's encoding (otherwise it
might not be possible to write out a valid system file, since the
identifier might not fit in the fixed length fields in such files).
Another important change is that, whereas before some special syntax
had to be handled by the parser providing feedback to the lexer, now
increasing the sophistication of the lexer has enabled all PSPP syntax
to be analyzed into tokens. This permitted some other improvements:
- An arbitrary number of tokens of lookahead, up to the end of the
current command, is now supported using lex_next_token() and
related functions.
- Before, some command implementations had a special attribute that
meant that the top-level PSPP command parser would not consume the
final token of the command name (because that token was not
followed by tokenizable syntax). This is no longer necessary and
has been removed.
- Before, each command implementation was responsible for ensuring
that valid command syntax was not followed by trailing garbage,
often by calling lex_end_of_command() as the last step of parsing.
This is no longer necessary; the main command parser will ensure
this for itself.
Ben Pfaff [Sat, 19 Mar 2011 23:30:55 +0000 (16:30 -0700)]
segment: New library for low-level phase of lexical syntax analysis.
This library provides for a low-level part of lexical analysis for
PSPP syntax, which I call "segmentation". Segmentation accepts a
stream of UTF-8 bytes as input. It outputs a label (a segment type)
for each byte or contiguous sequence of bytes in the input.
The following commit will implement the high-level phase of lexical
analysis, called "scanning", that converts a sequence of segments into
PSPP tokens.
Ben Pfaff [Tue, 7 Dec 2010 04:50:04 +0000 (20:50 -0800)]
hash-functions: New function hash_case_bytes().
This is useful for hashing an arbitrary byte sequence case-insensitively.
Obviously most uses would be better off working with Unicode but we aren't
there yet.
Ben Pfaff [Sun, 6 Feb 2011 05:10:10 +0000 (21:10 -0800)]
sys-file-reader: Refactor to clean up character encoding support.
The system file format is unusual in that it does not record the encoding
used by character strings at the beginning or at any fixed place in the
file. Instead, it can be recorded practically anywhere in the file. It
never precedes all of the actual character strings in the file, which makes
it impossible to interpret those strings completely and correctly until it
is encountered.
Until now, the system file reader has dealt with this situation by
stuffing uninterpreted character strings into data structures until the
encoding is known, then at that point fetching out the character strings,
reencoding them, and stuffing them back into the data structures. This
does work, but it has the disadvantage that all of the PSPP data
structures have to tolerate character strings with unknown encoding. In
some cases this seems like an ugly situation. For example, arbitrary
variable names have to be supported, even though the syntax for variable
names is circumscribed by the language, because the syntax rules for
variable names cannot be completely and correctly applied to a string that
is in an unknown encoding.
This commit fixes that problem by adopting a new way to read system files.
Each record in the system file dictionary is essentially slurped into
memory as a chunk, then the character encoding is extracted from it, then
the rest of the dictionary is interpreted based on that encoding. The
actual implementation is a little more intricate because the format of
system file records is somewhat non-uniform.
Ben Pfaff [Sat, 12 Mar 2011 06:10:54 +0000 (22:10 -0800)]
FREQUENCIES: Fix percentiles calculation.
The condition for using a variate directly instead of interpolating was
just wrong. It would interpolate in cases where it clearly should not,
which produced incorrect results in many cases.
Thanks to Fabio Bordignon <bordignon@demos.it> for reporting the problem
and supplying a simple test case.
Ben Pfaff [Fri, 11 Mar 2011 06:53:17 +0000 (22:53 -0800)]
T-TEST: Fix use-after-free with TEMPORARY and independent samples.
When TEMPORARY is in effect, proc_commit() destroys the temporary
dictionary. This means that any procedure that does not somehow disable
temporary transformations and refers to a variable following proc_commit()
has a use-after-free error.
T-TEST has two different bugs of this type. First, the loop that destroys
group statistics refers to destroyed variables. This commit fixes this
problem by instead using variable aux data destructors to destroy group
statistics.
Second, when there is an independent variable, destroying its values
requires knowing the variable's width. This commit fixes this problem by
destroying the values before calling proc_commit().
The AUTORECODE, DESCRIPTIVES, RANK, and REGRESSION procedures appear to
have similar issues (not fixed by this commit).
Reported by Jeremy Lavergne <jeremy@lavergne.gotdns.org>.
Ben Pfaff [Fri, 25 Feb 2011 05:31:44 +0000 (21:31 -0800)]
README.Git: Update to newer commit.
This is the Gnulib commit I'm testing against locally. It should fix the
problem that showed up in the nightly build, in which the dtoastr module
was missing.
Ben Pfaff [Sat, 19 Feb 2011 20:55:54 +0000 (12:55 -0800)]
data-out: Optimize and fix some bad assumptions.
Until now, data_out_pool() and its wrapper function data_out() have always
done at least two memory allocations: one to fill in the initial version
of the result and another to recode it to UTF-8. However, recoding to
UTF-8 is usually unnecessary, because most output formats always produce
output in UTF-8 anyway. Only binary formats and the string A format ever
produce data in other encodings, so this commit drops recoding entirely
except for those cases. Binary formats are a particularly special case:
usually it doesn't make any sense to use these formats for text output,
but this commit does its best to translate the binary output bytes into
valid UTF-8, at least up to the first null byte.
This commit also finishes fixing up display widths.
The closely related data_out_legacy() function, which only has one user
in three also needed some work. It was badly named, so I renamed it to
data_out_recode(). It made the bad assumption that the data passed in
was encoded in ASCII (written C_ENCODING). It also made the bad
assumption that the number of bytes output would be exactly the format's
width. This rewrite fixes these problems.
Ben Pfaff [Sat, 19 Feb 2011 05:55:18 +0000 (21:55 -0800)]
format: Count prefix and suffix width in terms of display columns.
Until now, the prefixes and suffixes for custom currency formats
(CCA, etc.) have been considered to occupy one display column per
byte. This is fine for prefixes and suffixes like "$" or "%", but
falls down badly with U+00A5 (¥) or U+20AC (€), which occupy two
or three bytes, respectively, in UTF-8, while occupying only a
single display column.
This commit fixes the problem. It doesn't add a test yet because
there are still some higher-level issues, but that will come in
a later commit when those remaining issues are resolved.