9360576759367dcb47cfa3bd6fab9100964a0a7d
[pspp-builds.git] / doc / dev / concepts.texi
1 @node Basic Concepts
2 @chapter Basic Concepts
3
4 This chapter introduces basic data structures and other concepts
5 needed for developing in PSPP.
6
7 @menu
8 * Values::
9 * Input and Output Formats::
10 * User-Missing Values::
11 * Value Labels::
12 * Variables::
13 * Dictionaries::
14 * Coding Conventions::
15 * Cases::
16 * Data Sets::
17 * Pools::
18 @end menu
19
20 @node Values
21 @section Values
22
23 @cindex value
24 The unit of data in PSPP is a @dfn{value}.
25
26 @cindex width
27 @cindex string value
28 @cindex numeric value
29 @cindex MAX_STRING
30 Values are classified by @dfn{type} and @dfn{width}.  The
31 type of a value is either @dfn{numeric} or @dfn{string} (sometimes
32 called alphanumeric).  The width of a string value ranges from 1 to
33 @code{MAX_STRING} bytes.  The width of a numeric value is artificially
34 defined to be 0; thus, the type of a value can be inferred from its
35 width.
36
37 Some support is provided for working with value types and widths, in
38 @file{data/val-type.h}:
39
40 @deftypefn Macro int MAX_STRING
41 Maximum width of a string value, in bytes, currently 32,767.
42 @end deftypefn
43
44 @deftypefun bool val_type_is_valid (enum val_type @var{val_type})
45 Returns true if @var{val_type} is a valid value type, that is,
46 either @code{VAL_NUMERIC} or @code{VAL_STRING}.  Useful for
47 assertions.
48 @end deftypefun
49
50 @deftypefun {enum val_type} val_type_from_width (int @var{width})
51 Returns @code{VAL_NUMERIC} if @var{width} is 0 and thus represents the
52 width of a numeric value, otherwise @code{VAL_STRING} to indicate that
53 @var{width} is the width of a string value.
54 @end deftypefun
55
56 The following subsections describe how values of each type are
57 represented.
58
59 @menu
60 * Numeric Values::
61 * String Values::
62 * Runtime Typed Values::
63 @end menu
64
65 @node Numeric Values
66 @subsection Numeric Values
67
68 A value known to be numeric at compile time is represented as a
69 @code{double}.  PSPP provides three values of @code{double} for
70 special purposes, defined in @file{data/val-type.h}:
71
72 @deftypefn Macro double SYSMIS
73 The @dfn{system-missing value}, used to represent a datum whose true
74 value is unknown, such as a survey question that was not answered by
75 the respondent, or undefined, such as the result of division by zero.
76 PSPP propagates the system-missing value through calculations and
77 compensates for missing values in statistical analyses.  @xref{Missing
78 Observations,,,pspp, PSPP Users Guide}, for a PSPP user's view of
79 missing values.
80
81 PSPP currently defines @code{SYSMIS} as @code{-DBL_MAX}, that is, the
82 greatest finite negative value of @code{double}.  It is best not to
83 depend on this definition, because PSPP may transition to using an
84 IEEE NaN (not a number) instead at some point in the future.
85 @end deftypefn
86
87 @deftypefn Macro double LOWEST
88 @deftypefnx Macro double HIGHEST
89 The greatest finite negative (except for @code{SYSMIS}) and positive
90 values of @code{double}, respectively.  These values do not ordinarily
91 appear in user data files.  Instead, they are used to implement
92 endpoints of open-ended ranges that are occasionally permitted in PSPP
93 syntax, e.g.@: @code{5 THRU HI} as a range of missing values
94 (@pxref{MISSING VALUES,,,pspp, PSPP Users Guide}).
95 @end deftypefn
96
97 @node String Values
98 @subsection String Values
99
100 A value known at compile time to have string type is represented as an
101 array of @code{char}.  String values do not necessarily represent
102 readable text strings and may contain arbitrary 8-bit data, including
103 null bytes, control codes, and bytes with the high bit set.  Thus,
104 string values are not null-terminated strings, but rather opaque
105 arrays of bytes.
106
107 @code{SYSMIS}, @code{LOWEST}, and @code{HIGHEST} have no equivalents
108 as string values.  Usually, PSPP fills an unknown or undefined string
109 values with spaces, but PSPP does not treat such a string as a special
110 case when it processes it later.
111
112 @cindex MAX_STRING
113 @code{MAX_STRING}, the maximum length of a string value, is defined in
114 @file{data/val-type.h}.
115
116 @node Runtime Typed Values
117 @subsection Runtime Typed Values
118
119 When a value's type is only known at runtime, it is often represented
120 as a @union{value}, defined in @file{data/value.h}.  A @union{value}
121 does not identify the type or width of the data it contains.  Code
122 that works with @union{values}s must therefore have external knowledge
123 of its content, often through the type and width of a
124 @struct{variable} (@pxref{Variables}).
125
126 @union{value} has one member that clients are permitted to access
127 directly, a @code{double} named @samp{f} that stores the content of a
128 numeric @union{value}.  It has other members that store the content of
129 string @union{value}, but client code should use accessor functions
130 instead of referring to these directly.
131
132 PSPP provides some functions for working with @union{value}s.  The
133 most useful are described below.  To use these functions, recall that
134 a numeric value has a width of 0.
135
136 @deftypefun void value_init (union value *@var{value}, int @var{width})
137 Initializes @var{value} as a value of the given @var{width}.  After
138 initialization, the data in @var{value} are indeterminate; the caller
139 is responsible for storing initial data in it.
140 @end deftypefun
141
142 @deftypefun void value_destroy (union value *@var{value}, int @var{width})
143 Frees auxiliary storage associated with @var{value}, which must have
144 the given @var{width}.
145 @end deftypefun
146
147 @deftypefun bool value_needs_init (int @var{width})
148 For some widths, @func{value_init} and @func{value_destroy} do not
149 actually do anything, because no additional storage is needed beyond
150 the size of @union{value}.  This function returns true if @var{width}
151 is such a width, which case there is no actual need to call those
152 functions.  This can be a useful optimization if a large number of
153 @union{value}s of such a width are to be initialized or destroyed.
154
155 This function returns false if @func{value_init} and
156 @func{value_destroy} are actually required for the given @var{width}.
157 @end deftypefun
158
159 @deftypefun double value_num (const union value *@var{value})
160 Returns the numeric value in @var{value}, which must have been
161 initialized as a numeric value.  Equivalent to @code{@var{value}->f}.
162 @end deftypefun
163
164 @deftypefun {const char *} value_str (const union value *@var{value}, int @var{width})
165 @deftypefunx {char *} value_str_rw (union value *@var{value}, int @var{width})
166 Returns the string value in @var{value}, which must have been
167 initialized with positive width @var{width}.  The string returned is
168 not null-terminated.  Only @var{width} bytes of returned data may be
169 accessed.
170
171 The two different functions exist only for @code{const}-correctness.
172 Otherwise they are identical.
173
174 It is important that @var{width} be the correct value that was passed
175 to @func{value_init}.  Passing a smaller or larger value (e.g.@:
176 because that number of bytes will be accessed) will not always work
177 and should be avoided.
178 @end deftypefun
179
180 @deftypefun void value_copy (union value *@var{dst}, @
181                              const union value *@var{src}, @
182                              int @var{width})
183 Copies the contents of @union{value} @var{src} to @var{dst}.  Both
184 @var{dst} and @var{src} must have been initialized with the specified
185 @var{width}.
186 @end deftypefun
187
188 @deftypefun void value_set_missing (union value *@var{value}, int @var{width})
189 Sets @var{value} to @code{SYSMIS} if it is numeric or to all spaces if
190 it is alphanumeric, according to @var{width}.  @var{value} must have
191 been initialized with the specified @var{width}.
192 @end deftypefun
193
194 @anchor{value_is_resizable}
195 @deftypefun bool value_is_resizable (const union value *@var{value}, int @var{old_width}, int @var{new_width})
196 Determines whether @var{value}, which must have been initialized with
197 the specified @var{old_width}, may be resized to @var{new_width}.
198 Resizing is possible if the following criteria are met.  First,
199 @var{old_width} and @var{new_width} must be both numeric or both
200 string widths.  Second, if @var{new_width} is a short string width and
201 less than @var{old_width}, resizing is allowed only if bytes
202 @var{new_width} through @var{old_width} in @var{value} contain only
203 spaces.
204
205 These rules are part of those used by @func{mv_is_resizable} and
206 @func{val_labs_can_set_width}.
207 @end deftypefun
208
209 @deftypefun void value_resize (union value *@var{value}, int @var{old_width}, int @var{new_width})
210 Resizes @var{value} from @var{old_width} to @var{new_width}, which
211 must be allowed by the rules stated above.  @var{value} must have been
212 initialized with the specified @var{old_width} before calling this
213 function.  After resizing, @var{value} has width @var{new_width}.
214
215 If @var{new_width} is greater than @var{old_width}, @var{value} will
216 be padded on the right with spaces to the new width.  If
217 @var{new_width} is less than @var{old_width}, the rightmost bytes of
218 @var{value} are truncated.
219 @end deftypefun
220
221 @deftypefun bool value_equal (const union value *@var{a}, const union value *@var{b}, int @var{width})
222 Compares of @var{a} and @var{b}, which must both have width
223 @var{width}.  Returns true if their contents are the same, false if
224 they differ.
225 @end deftypefun
226
227 @deftypefun int value_compare_3way (const union value *@var{a}, const union value *@var{b}, int @var{width})
228 Compares of @var{a} and @var{b}, which must both have width
229 @var{width}.  Returns -1 if @var{a} is less than @var{b}, 0 if they
230 are equal, or 1 if @var{a} is greater than @var{b}.
231
232 Numeric values are compared numerically, with @code{SYSMIS} comparing
233 less than any real number.  String values are compared
234 lexicographically byte-by-byte.
235 @end deftypefun
236
237 @deftypefun size_t value_hash (const union value *@var{value}, int @var{width}, unsigned int @var{basis})
238 Computes and returns a hash of @var{value}, which must have the
239 specified @var{width}.  The value in @var{basis} is folded into the
240 hash.
241 @end deftypefun
242
243 @node Input and Output Formats
244 @section Input and Output Formats
245
246 Input and output formats specify how to convert data fields to and
247 from data values (@pxref{Input and Output Formats,,,pspp, PSPP Users
248 Guide}).  PSPP uses @struct{fmt_spec} to represent input and output
249 formats.
250
251 Function prototypes and other declarations related to formats are in
252 the @file{<data/format.h>} header.
253
254 @deftp {Structure} {struct fmt_spec}
255 An input or output format, with the following members:
256
257 @table @code
258 @item enum fmt_type type
259 The format type (see below).
260
261 @item int w
262 Field width, in bytes.  The width of numeric fields is always between
263 1 and 40 bytes, and the width of string fields is always between 1 and
264 65534 bytes.  However, many individual types of formats place stricter
265 limits on field width (see @ref{fmt_max_input_width},
266 @ref{fmt_max_output_width}).
267
268 @item int d
269 Number of decimal places, in character positions.  For format types
270 that do not allow decimal places to be specified, this value must be
271 0.  Format types that do allow decimal places have type-specific and
272 often width-specific restrictions on @code{d} (see
273 @ref{fmt_max_input_decimals}, @ref{fmt_max_output_decimals}).
274 @end table
275 @end deftp
276
277 @deftp {Enumeration} {enum fmt_type}
278 An enumerated type representing an input or output format type.  Each
279 PSPP input and output format has a corresponding enumeration constant
280 prefixed by @samp{FMT}: @code{FMT_F}, @code{FMT_COMMA},
281 @code{FMT_DOT}, and so on.
282 @end deftp
283
284 The following sections describe functions for manipulating formats and
285 the data in fields represented by formats.
286
287 @menu
288 * Constructing and Verifying Formats::
289 * Format Utility Functions::
290 * Obtaining Properties of Format Types::
291 * Numeric Formatting Styles::
292 * Formatted Data Input and Output::
293 @end menu
294
295 @node Constructing and Verifying Formats
296 @subsection Constructing and Verifying Formats
297
298 These functions construct @struct{fmt_spec}s and verify that they are
299 valid.
300
301
302
303 @deftypefun {struct fmt_spec} fmt_for_input (enum fmt_type @var{type}, int @var{w}, int @var{d})
304 @deftypefunx {struct fmt_spec} fmt_for_output (enum fmt_type @var{type}, int @var{w}, int @var{d})
305 Constructs a @struct{fmt_spec} with the given @var{type}, @var{w}, and
306 @var{d}, asserts that the result is a valid input (or output) format,
307 and returns it.
308 @end deftypefun
309
310 @anchor{fmt_for_output_from_input}
311 @deftypefun {struct fmt_spec} fmt_for_output_from_input (const struct fmt_spec *@var{input})
312 Given @var{input}, which must be a valid input format, returns the
313 equivalent output format.  @xref{Input and Output Formats,,,pspp, PSPP
314 Users Guide}, for the rules for converting input formats into output
315 formats.
316 @end deftypefun
317
318 @deftypefun {struct fmt_spec} fmt_default_for_width (int @var{width})
319 Returns the default output format for a variable of the given
320 @var{width}.  For a numeric variable, this is F8.2 format; for a
321 string variable, it is the A format of the given @var{width}.
322 @end deftypefun
323
324 The following functions check whether a @struct{fmt_spec} is valid for
325 various uses and return true if so, false otherwise.  When any of them
326 returns false, it also outputs an explanatory error message using
327 @func{msg}.  To suppress error output, enclose a call to one of these
328 functions by a @func{msg_disable}/@func{msg_enable} pair.
329
330 @deftypefun bool fmt_check (const struct fmt_spec *@var{format}, bool @var{for_input})
331 @deftypefunx bool fmt_check_input (const struct fmt_spec *@var{format})
332 @deftypefunx bool fmt_check_output (const struct fmt_spec *@var{format})
333 Checks whether @var{format} is a valid input format (for
334 @func{fmt_check_input}, or @func{fmt_check} if @var{for_input}) or
335 output format (for @func{fmt_check_output}, or @func{fmt_check} if not
336 @var{for_input}).
337 @end deftypefun
338
339 @deftypefun bool fmt_check_type_compat (const struct fmt_spec *@var{format}, enum val_type @var{type})
340 Checks whether @var{format} matches the value type @var{type}, that
341 is, if @var{type} is @code{VAL_NUMERIC} and @var{format} is a numeric
342 format or @var{type} is @code{VAL_STRING} and @var{format} is a string
343 format.
344 @end deftypefun
345
346 @deftypefun bool fmt_check_width_compat (const struct fmt_spec *@var{format}, int @var{width})
347 Checks whether @var{format} may be used as an output format for a
348 value of the given @var{width}.
349
350 @func{fmt_var_width}, described in
351 the following section, can be also be used to determine the value
352 width needed by a format.
353 @end deftypefun
354
355 @node Format Utility Functions
356 @subsection Format Utility Functions
357
358 These functions work with @struct{fmt_spec}s.
359
360 @deftypefun int fmt_var_width (const struct fmt_spec *@var{format})
361 Returns the width for values associated with @var{format}.  If
362 @var{format} is a numeric format, the width is 0; if @var{format} is
363 an A format, then the width @code{@var{format}->w}; otherwise,
364 @var{format} is an AHEX format and its width is @code{@var{format}->w
365 / 2}.
366 @end deftypefun
367
368 @deftypefun char *fmt_to_string (const struct fmt_spec *@var{format}, char @var{s}[FMT_STRING_LEN_MAX + 1])
369 Converts @var{format} to a human-readable format specifier in @var{s}
370 and returns @var{s}.  @var{format} need not be a valid input or output
371 format specifier, e.g.@: it is allowed to have an excess width or
372 decimal places.  In particular, if @var{format} has decimals, they are
373 included in the output string, even if @var{format}'s type does not
374 allow decimals, to allow accurately presenting incorrect formats to
375 the user.
376 @end deftypefun
377
378 @deftypefun bool fmt_equal (const struct fmt_spec *@var{a}, const struct fmt_spec *@var{b})
379 Compares @var{a} and @var{b} memberwise and returns true if they are
380 identical, false otherwise.  @var{format} need not be a valid input or
381 output format specifier.
382 @end deftypefun
383
384 @deftypefun void fmt_resize (struct fmt_spec *@var{fmt}, int @var{width})
385 Sets the width of @var{fmt} to a valid format for a  @union{value} of size @var{width}.
386 @end deftypefun
387
388 @node Obtaining Properties of Format Types
389 @subsection Obtaining Properties of Format Types
390
391 These functions work with @enum{fmt_type}s instead of the higher-level
392 @struct{fmt_spec}s.  Their primary purpose is to report properties of
393 each possible format type, which in turn allows clients to abstract
394 away many of the details of the very heterogeneous requirements of
395 each format type.
396
397 The first group of functions works with format type names.
398
399 @deftypefun const char *fmt_name (enum fmt_type @var{type})
400 Returns the name for the given @var{type}, e.g.@: @code{"COMMA"} for
401 @code{FMT_COMMA}.
402 @end deftypefun
403
404 @deftypefun bool fmt_from_name (const char *@var{name}, enum fmt_type *@var{type})
405 Tries to find the @enum{fmt_type} associated with @var{name}.  If
406 successful, sets @code{*@var{type}} to the type and returns true;
407 otherwise, returns false without modifying @code{*@var{type}}.
408 @end deftypefun
409
410 The functions below query basic limits on width and decimal places for
411 each kind of format.
412
413 @deftypefun bool fmt_takes_decimals (enum fmt_type @var{type})
414 Returns true if a format of the given @var{type} is allowed to have a
415 nonzero number of decimal places (the @code{d} member of
416 @struct{fmt_spec}), false if not.
417 @end deftypefun
418
419 @anchor{fmt_min_input_width}
420 @anchor{fmt_max_input_width}
421 @anchor{fmt_min_output_width}
422 @anchor{fmt_max_output_width}
423 @deftypefun int fmt_min_input_width (enum fmt_type @var{type})
424 @deftypefunx int fmt_max_input_width (enum fmt_type @var{type})
425 @deftypefunx int fmt_min_output_width (enum fmt_type @var{type})
426 @deftypefunx int fmt_max_output_width (enum fmt_type @var{type})
427 Returns the minimum or maximum width (the @code{w} member of
428 @struct{fmt_spec}) allowed for an input or output format of the
429 specified @var{type}.
430 @end deftypefun
431
432 @anchor{fmt_max_input_decimals}
433 @anchor{fmt_max_output_decimals}
434 @deftypefun int fmt_max_input_decimals (enum fmt_type @var{type}, int @var{width})
435 @deftypefunx int fmt_max_output_decimals (enum fmt_type @var{type}, int @var{width})
436 Returns the maximum number of decimal places allowed for an input or
437 output format, respectively, of the given @var{type} and @var{width}.
438 Returns 0 if the specified @var{type} does not allow any decimal
439 places or if @var{width} is too narrow to allow decimal places.
440 @end deftypefun
441
442 @deftypefun int fmt_step_width (enum fmt_type @var{type})
443 Returns the ``width step'' for a @struct{fmt_spec} of the given
444 @var{type}.  A @struct{fmt_spec}'s width must be a multiple of its
445 type's width step.  Most format types have a width step of 1, so that
446 their formats' widths may be any integer within the valid range, but
447 hexadecimal numeric formats and AHEX string formats have a width step
448 of 2.
449 @end deftypefun
450
451 These functions allow clients to broadly determine how each kind of
452 input or output format behaves.
453
454 @deftypefun bool fmt_is_string (enum fmt_type @var{type})
455 @deftypefunx bool fmt_is_numeric (enum fmt_type @var{type})
456 Returns true if @var{type} is a format for numeric or string values,
457 respectively, false otherwise.
458 @end deftypefun
459
460 @deftypefun enum fmt_category fmt_get_category (enum fmt_type @var{type})
461 Returns the category within which @var{type} falls.
462
463 @deftp {Enumeration} {enum fmt_category}
464 A group of format types.  Format type categories correspond to the
465 input and output categories described in the PSPP user documentation
466 (@pxref{Input and Output Formats,,,pspp, PSPP Users Guide}).
467
468 Each format is in exactly one category.  The categories have bitwise
469 disjoint values to make it easy to test whether a format type is in
470 one of multiple categories, e.g.@:
471
472 @example
473 if (fmt_get_category (type) & (FMT_CAT_DATE | FMT_CAT_TIME))
474   @{
475     /* @dots{}@r{@code{type} is a date or time format}@dots{} */
476   @}
477 @end example
478
479 The format categories are:
480 @table @code
481 @item FMT_CAT_BASIC
482 Basic numeric formats.
483
484 @item FMT_CAT_CUSTOM
485 Custom currency formats.
486
487 @item FMT_CAT_LEGACY
488 Legacy numeric formats.
489
490 @item FMT_CAT_BINARY
491 Binary formats.
492
493 @item FMT_CAT_HEXADECIMAL
494 Hexadecimal formats.
495
496 @item FMT_CAT_DATE
497 Date formats.
498
499 @item FMT_CAT_TIME
500 Time formats.
501
502 @item FMT_CAT_DATE_COMPONENT
503 Date component formats.
504
505 @item FMT_CAT_STRING
506 String formats.
507 @end table
508 @end deftp
509 @end deftypefun
510
511 The PSPP input and output routines use the following pair of functions
512 to convert @enum{fmt_type}s to and from the separate set of codes used
513 in system and portable files:
514
515 @deftypefun int fmt_to_io (enum fmt_type @var{type})
516 Returns the format code used in system and portable files that
517 corresponds to @var{type}.
518 @end deftypefun
519
520 @deftypefun bool fmt_from_io (int @var{io}, enum fmt_type *@var{type})
521 Converts @var{io}, a format code used in system and portable files,
522 into a @enum{fmt_type} in @code{*@var{type}}.  Returns true if
523 successful, false if @var{io} is not valid.
524 @end deftypefun
525
526 These functions reflect the relationship between input and output
527 formats.
528
529 @deftypefun enum fmt_type fmt_input_to_output (enum fmt_type @var{type})
530 Returns the output format type that is used by default by DATA LIST
531 and other input procedures when @var{type} is specified as an input
532 format.  The conversion from input format to output format is more
533 complicated than simply changing the format.
534 @xref{fmt_for_output_from_input}, for a function that performs the
535 entire conversion.
536 @end deftypefun
537
538 @deftypefun bool fmt_usable_for_input (enum fmt_type @var{type})
539 Returns true if @var{type} may be used as an input format type, false
540 otherwise.  The custom currency formats, in particular, may be used
541 for output but not for input.
542
543 All format types are valid for output.
544 @end deftypefun
545
546 The final group of format type property functions obtain
547 human-readable templates that illustrate the formats graphically.
548
549 @deftypefun const char *fmt_date_template (enum fmt_type @var{type})
550 Returns a formatting template for @var{type}, which must be a date or
551 time format type.  These formats are used by @func{data_in} and
552 @func{data_out} to guide parsing and formatting date and time data.
553 @end deftypefun
554
555 @deftypefun char *fmt_dollar_template (const struct fmt_spec *@var{format})
556 Returns a string of the form @code{$#,###.##} according to
557 @var{format}, which must be of type @code{FMT_DOLLAR}.  The caller
558 must free the string with @code{free}.
559 @end deftypefun
560
561 @node Numeric Formatting Styles
562 @subsection Numeric Formatting Styles
563
564 Each of the basic numeric formats (F, E, COMMA, DOT, DOLLAR, PCT) and
565 custom currency formats (CCA, CCB, CCC, CCD, CCE) has an associated
566 numeric formatting style, represented by @struct{fmt_number_style}.
567 Input and output conversion of formats that have numeric styles is
568 determined mainly by the style, although the formatting rules have
569 special cases that are not represented within the style.
570
571 @deftp {Structure} {struct fmt_number_style}
572 A structure type with the following members:
573
574 @table @code
575 @item struct substring neg_prefix
576 @itemx struct substring prefix
577 @itemx struct substring suffix
578 @itemx struct substring neg_suffix
579 A set of strings used a prefix to negative numbers, a prefix to every
580 number, a suffix to every number, and a suffix to negative numbers,
581 respectively.  Each of these strings is no more than
582 @code{FMT_STYLE_AFFIX_MAX} bytes (currently 16) bytes in length.
583 These strings must be freed with @func{ss_dealloc} when no longer
584 needed.
585
586 @item decimal
587 The character used as a decimal point.  It must be either @samp{.} or
588 @samp{,}.
589
590 @item grouping
591 The character used for grouping digits to the left of the decimal
592 point.  It may be @samp{.} or @samp{,}, in which case it must not be
593 equal to @code{decimal}, or it may be set to 0 to disable grouping.
594 @end table
595 @end deftp
596
597 The following functions are provided for working with numeric
598 formatting styles.
599
600 @deftypefun void fmt_number_style_init (struct fmt_number_style *@var{style})
601 Initialises a @struct{fmt_number_style} with all of the
602 prefixes and suffixes set to the empty string, @samp{.} as the decimal
603 point character, and grouping disables.
604 @end deftypefun
605
606
607 @deftypefun void fmt_number_style_destroy (struct fmt_number_style *@var{style})
608 Destroys @var{style}, freeing its storage.
609 @end deftypefun
610
611 @deftypefun {struct fmt_number_style}    *fmt_create (void)
612 A function which creates an array of all the styles used by pspp, and 
613 calls fmt_number_style_init on each of them.
614 @end deftypefun
615
616 @deftypefun void fmt_done (struct fmt_number_style *@var{styles})
617 A wrapper function which takes an array of @struct{fmt_number_style}, calls
618 fmt_number_style_destroy on each of them, and then frees the array.
619 @end deftypefun
620
621
622
623 @deftypefun int fmt_affix_width (const struct fmt_number_style *@var{style})
624 Returns the total length of @var{style}'s @code{prefix} and @code{suffix}.
625 @end deftypefun
626
627 @deftypefun int fmt_neg_affix_width (const struct fmt_number_style *@var{style})
628 Returns the total length of @var{style}'s @code{neg_prefix} and
629 @code{neg_suffix}.
630 @end deftypefun
631
632 PSPP maintains a global set of number styles for each of the basic
633 numeric formats and custom currency formats.  The following functions
634 work with these global styles:
635
636 @deftypefun {const struct fmt_number_style *} fmt_get_style (enum fmt_type @var{type})
637 Returns the numeric style for the given format @var{type}.
638 @end deftypefun
639
640 @deftypefun void fmt_check_style (const struct fmt_number_style *@var{style})
641 Asserts that style is self consistent.
642 @end deftypefun
643
644
645 @deftypefun {const char *} fmt_name (enum fmt_type @var{type})
646 Returns the name of the given format @var{type}.
647 @end deftypefun
648
649
650
651 @node Formatted Data Input and Output
652 @subsection Formatted Data Input and Output
653
654 These functions provide the ability to convert data fields into
655 @union{value}s and vice versa.
656
657 @deftypefun bool data_in (struct substring @var{input}, enum legacy_encoding @var{legacy_encoding}, enum fmt_type @var{type}, int @var{implied_decimals}, int @var{first_column}, union value *@var{output}, int @var{width})
658 Parses @var{input} as a field containing data in the given format
659 @var{type}.  The resulting value is stored in @var{output}, which the
660 caller must have initialized with the given @var{width}.  For
661 consistency, @var{width} must be 0 if
662 @var{type} is a numeric format type and greater than 0 if @var{type}
663 is a string format type.
664
665 Ordinarily @var{legacy_encoding} should be @code{LEGACY_NATIVE},
666 indicating that @var{input} is encoded in the character set
667 conventionally used on the host machine.  It may be set to
668 @code{LEGACY_EBCDIC} to cause @var{input} to be re-encoded from EBCDIC
669 during data parsing.
670
671 If @var{input} is the empty string (with length 0), @var{output} is
672 set to the value set on SET BLANKS (@pxref{SET BLANKS,,,pspp, PSPP
673 Users Guide}) for a numeric value, or to all spaces for a string
674 value.  This applies regardless of the usual parsing requirements for
675 @var{type}.
676
677 If @var{implied_decimals} is greater than zero, then the numeric
678 result is shifted right by @var{implied_decimals} decimal places if
679 @var{input} does not contain a decimal point character or an exponent.
680 Only certain numeric format types support implied decimal places; for
681 string formats and other numeric formats, @var{implied_decimals} has
682 no effect.  DATA LIST FIXED is the primary user of this feature
683 (@pxref{DATA LIST FIXED,,,pspp, PSPP Users Guide}).  Other callers
684 should generally specify 0 for @var{implied_decimals}, to disable this
685 feature.
686
687 When @var{input} contains invalid input data, @func{data_in} outputs a
688 message using @func{msg}.
689 @c (@pxref{msg}).
690 If @var{first_column} is
691 nonzero, it is included in any such error message as the 1-based
692 column number of the start of the field.  The last column in the field
693 is calculated as @math{@var{first_column} + @var{input} - 1}.  To
694 suppress error output, enclose the call to @func{data_in} by calls to
695 @func{msg_disable} and @func{msg_enable}.
696
697 This function returns true on success, false if a message was output
698 (even if suppressed).  Overflow and underflow provoke warnings but are
699 not propagated to the caller as errors.
700
701 This function is declared in @file{data/data-in.h}.
702 @end deftypefun
703
704 @deftypefun void data_out (const union value *@var{input}, const struct fmt_spec *@var{format}, char *@var{output})
705 @deftypefunx void data_out_legacy (const union value *@var{input}, enum legacy_encoding @var{legacy_encoding}, const struct fmt_spec *@var{format}, char *@var{output})
706 Converts the data pointed to by @var{input} into a data field in
707 @var{output} according to output format specifier @var{format}, which
708 must be a valid output format.  Exactly @code{@var{format}->w} bytes
709 are written to @var{output}.  The width of @var{input} is also
710 inferred from @var{format} using an algorithm equivalent to
711 @func{fmt_var_width}.
712
713 If @func{data_out} is called, or @func{data_out_legacy} is called with
714 @var{legacy_encoding} set to @code{LEGACY_NATIVE}, @var{output} will
715 be encoded in the character set conventionally used on the host
716 machine.  If @var{legacy_encoding} is set to @code{LEGACY_EBCDIC},
717 @var{output} will be re-encoded from EBCDIC during data output.
718
719 When @var{input} contains data that cannot be represented in the given
720 @var{format}, @func{data_out} may output a message using @func{msg},
721 @c (@pxref{msg}),
722 although the current implementation does not
723 consistently do so.  To suppress error output, enclose the call to
724 @func{data_out} by calls to @func{msg_disable} and @func{msg_enable}.
725
726 This function is declared in @file{data/data-out.h}.
727 @end deftypefun
728
729 @node User-Missing Values
730 @section User-Missing Values
731
732 In addition to the system-missing value for numeric values, each
733 variable has a set of user-missing values (@pxref{MISSING
734 VALUES,,,pspp, PSPP Users Guide}).  A set of user-missing values is
735 represented by @struct{missing_values}.
736
737 It is rarely necessary to interact directly with a
738 @struct{missing_values} object.  Instead, the most common operation,
739 querying whether a particular value is a missing value for a given
740 variable, is most conveniently executed through functions on
741 @struct{variable}.  @xref{Variable Missing Values}, for details.
742
743 A @struct{missing_values} is essentially a set of @union{value}s that
744 have a common value width (@pxref{Values}).  For a set of
745 missing values associated with a variable (the common case), the set's
746 width is the same as the variable's width.  The contents of a set of
747 missing values is subject to some restrictions.  Regardless of width,
748 a set of missing values is allowed to be empty.  Otherwise, its
749 possible contents depend on its width:
750
751 @table @asis
752 @item 0 (numeric values)
753 Up to three discrete numeric values, or a range of numeric values
754 (which includes both ends of the range), or a range plus one discrete
755 numeric value.
756
757 @item 1@dots{}@t{MAX_SHORT_STRING} - 1 (short string values)
758 Up to three discrete string values (with the same width as the set).
759
760 @item @t{MAX_SHORT_STRING}@dots{}@t{MAX_STRING} (long string values)
761 Always empty.
762 @end table
763
764 These somewhat arbitrary restrictions are the same as those imposed by
765 SPSS.  In PSPP we could easily eliminate these restrictions, but doing
766 so would also require us to extend the system file format in an
767 incompatible way, which we consider a bad tradeoff.
768
769 Function prototypes and other declarations related to missing values
770 are declared in @file{data/missing-values.h}.
771
772 @deftp {Structure} {struct missing_values}
773 Opaque type that represents a set of missing values.
774 @end deftp
775
776 The most often useful functions for missing values are those for
777 testing whether a given value is missing, described in the following
778 section.  Several other functions for creating, inspecting, and
779 modifying @struct{missing_values} objects are described afterward, but
780 these functions are much more rarely useful.  No function for
781 destroying a @struct{missing_values} is provided, because
782 @struct{missing_values} does not contain any pointers or other
783 references to resources that need deallocation.
784
785 @menu
786 * Testing for Missing Values::
787 * Initializing User-Missing Value Sets::
788 * Changing User-Missing Value Set Width::
789 * Inspecting User-Missing Value Sets::
790 * Modifying User-Missing Value Sets::
791 @end menu
792
793 @node Testing for Missing Values
794 @subsection Testing for Missing Values
795
796 The most often useful functions for missing values are those for
797 testing whether a given value is missing, described here.  However,
798 using one of the corresponding missing value testing functions for
799 variables can be even easier (@pxref{Variable Missing Values}).
800
801 @deftypefun bool mv_is_value_missing (const struct missing_values *@var{mv}, const union value *@var{value}, enum mv_class @var{class})
802 @deftypefunx bool mv_is_num_missing (const struct missing_values *@var{mv}, double @var{value}, enum mv_class @var{class})
803 @deftypefunx bool mv_is_str_missing (const struct missing_values *@var{mv}, const char @var{value}[], enum mv_class @var{class})
804 Tests whether @var{value} is in one of the categories of missing
805 values given by @var{class}.  Returns true if so, false otherwise.
806
807 @var{mv} determines the width of @var{value} and provides the set of
808 user-missing values to test.
809
810 The only difference among these functions in the form in which
811 @var{value} is provided, so you may use whichever function is most
812 convenient.
813
814 The @var{class} argument determines the exact kinds of missing values
815 that the functions test for:
816
817 @deftp Enumeration {enum mv_class}
818 @table @t
819 @item MV_USER
820 Returns true if @var{value} is in the set of user-missing values given
821 by @var{mv}.
822
823 @item MV_SYSTEM
824 Returns true if @var{value} is system-missing.  (If @var{mv}
825 represents a set of string values, then @var{value} is never
826 system-missing.)
827
828 @item MV_ANY
829 @itemx MV_USER | MV_SYSTEM
830 Returns true if @var{value} is user-missing or system-missing.
831
832 @item MV_NONE
833 Always returns false, that is, @var{value} is never considered
834 missing.
835 @end table
836 @end deftp
837 @end deftypefun
838
839 @node Initializing User-Missing Value Sets
840 @subsection Initializing User-Missing Value Sets
841
842 @deftypefun void mv_init (struct missing_values *@var{mv}, int @var{width})
843 Initializes @var{mv} as a set of user-missing values.  The set is
844 initially empty.  Any values added to it must have the specified
845 @var{width}.
846 @end deftypefun
847
848 @deftypefun void mv_copy (struct missing_values *@var{mv}, const struct missing_values *@var{old})
849 Initializes @var{mv} as a copy of the existing set of user-missing
850 values @var{old}.
851 @end deftypefun
852
853 @deftypefun void mv_clear (struct missing_values *@var{mv})
854 Empties the user-missing value set @var{mv}, retaining its existing
855 width.
856 @end deftypefun
857
858 @node Changing User-Missing Value Set Width
859 @subsection Changing User-Missing Value Set Width
860
861 A few PSPP language constructs copy sets of user-missing values from
862 one variable to another.  When the source and target variables have
863 the same width, this is simple.  But when the target variable's width
864 might be different from the source variable's, it takes a little more
865 work.  The functions described here can help.
866
867 In fact, it is usually unnecessary to call these functions directly.
868 Most of the time @func{var_set_missing_values}, which uses
869 @func{mv_resize} internally to resize the new set of missing values to
870 the required width, may be used instead.
871 @xref{var_set_missing_values}, for more information.
872
873 @deftypefun bool mv_is_resizable (const struct missing_values *@var{mv}, int @var{new_width})
874 Tests whether @var{mv}'s width may be changed to @var{new_width} using
875 @func{mv_resize}.  Returns true if it is allowed, false otherwise.
876
877 If @var{new_width} is a long string width, @var{mv} may be resized
878 only if it is empty.  Otherwise, if @var{mv} contains any missing
879 values, then it may be resized only if each missing value may be
880 resized, as determined by @func{value_is_resizable}
881 (@pxref{value_is_resizable}).
882 @end deftypefun
883
884 @anchor{mv_resize}
885 @deftypefun void mv_resize (struct missing_values *@var{mv}, int @var{width})
886 Changes @var{mv}'s width to @var{width}.  @var{mv} and @var{width}
887 must satisfy the constraints explained above.
888
889 When a string missing value set's width is increased, each
890 user-missing value is padded on the right with spaces to the new
891 width.
892 @end deftypefun
893
894 @node Inspecting User-Missing Value Sets
895 @subsection Inspecting User-Missing Value Sets
896
897 These functions inspect the properties and contents of
898 @struct{missing_values} objects.
899
900 The first set of functions inspects the discrete values that numeric
901 and short string sets of user-missing values may contain:
902
903 @deftypefun bool mv_is_empty (const struct missing_values *@var{mv})
904 Returns true if @var{mv} contains no user-missing values, false if it
905 contains at least one user-missing value (either a discrete value or a
906 numeric range).
907 @end deftypefun
908
909 @deftypefun int mv_get_width (const struct missing_values *@var{mv})
910 Returns the width of the user-missing values that @var{mv} represents.
911 @end deftypefun
912
913 @deftypefun int mv_n_values (const struct missing_values *@var{mv})
914 Returns the number of discrete user-missing values included in
915 @var{mv}.  The return value will be between 0 and 3.  For sets of
916 numeric user-missing values that include a range, the return value
917 will be 0 or 1.
918 @end deftypefun
919
920 @deftypefun bool mv_has_value (const struct missing_values *@var{mv})
921 Returns true if @var{mv} has at least one discrete user-missing
922 values, that is, if @func{mv_n_values} would return nonzero for
923 @var{mv}.
924 @end deftypefun
925
926 @deftypefun void mv_get_value (const struct missing_values *@var{mv}, union value *@var{value}, int @var{index})
927 Copies the discrete user-missing value in @var{mv} with the given
928 @var{index} into @var{value}.  The index must be less than the number
929 of discrete user-missing values in @var{mv}, as reported by
930 @func{mv_n_values}.
931 @end deftypefun
932
933 The second set of functions inspects the single range of values that
934 numeric sets of user-missing values may contain:
935
936 @deftypefun bool mv_has_range (const struct missing_values *@var{mv})
937 Returns true if @var{mv} includes a range, false otherwise.
938 @end deftypefun
939
940 @deftypefun void mv_get_range (const struct missing_values *@var{mv}, double *@var{low}, double *@var{high})
941 Stores the low endpoint of @var{mv}'s range in @code{*@var{low}} and
942 the high endpoint of the range in @code{*@var{high}}.  @var{mv} must
943 include a range.
944 @end deftypefun
945
946 @node Modifying User-Missing Value Sets
947 @subsection Modifying User-Missing Value Sets
948
949 These functions modify the contents of @struct{missing_values}
950 objects.
951
952 The first set of functions applies to all sets of user-missing values:
953
954 @deftypefun bool mv_add_value (struct missing_values *@var{mv}, const union value *@var{value})
955 @deftypefunx bool mv_add_str (struct missing_values *@var{mv}, const char @var{value}[])
956 @deftypefunx bool mv_add_num (struct missing_values *@var{mv}, double @var{value})
957 Attempts to add the given discrete @var{value} to set of user-missing
958 values @var{mv}.  @var{value} must have the same width as @var{mv}.
959 Returns true if @var{value} was successfully added, false if the set
960 could not accept any more discrete values.  (Always returns false if
961 @var{mv} is a set of long string user-missing values.)
962
963 These functions are equivalent, except for the form in which
964 @var{value} is provided, so you may use whichever function is most
965 convenient.
966 @end deftypefun
967
968 @deftypefun void mv_pop_value (struct missing_values *@var{mv}, union value *@var{value})
969 Removes a discrete value from @var{mv} (which must contain at least
970 one discrete value) and stores it in @var{value}.
971 @end deftypefun
972
973 @deftypefun void mv_replace_value (struct missing_values *@var{mv}, const union value *@var{value}, int @var{index})
974 Replaces the discrete value with the given @var{index} in @var{mv}
975 (which must contain at least @var{index} + 1 discrete values) with
976 @var{value}.
977 @end deftypefun
978
979 The second set of functions applies only to numeric sets of
980 user-missing values:
981
982 @deftypefun bool mv_add_range (struct missing_values *@var{mv}, double @var{low}, double @var{high})
983 Attempts to add a numeric range covering @var{low}@dots{}@var{high}
984 (inclusive on both ends) to @var{mv}, which must be a numeric set of
985 user-missing values.  Returns true if the range is successful added,
986 false on failure.  Fails if @var{mv} already contains a range, or if
987 @var{mv} contains more than one discrete value, or if @var{low} >
988 @var{high}.
989 @end deftypefun
990
991 @deftypefun void mv_pop_range (struct missing_values *@var{mv}, double *@var{low}, double *@var{high})
992 Given @var{mv}, which must be a numeric set of user-missing values
993 that contains a range, removes that range from @var{mv} and stores its
994 low endpoint in @code{*@var{low}} and its high endpoint in
995 @code{*@var{high}}.
996 @end deftypefun
997
998 @node Value Labels
999 @section Value Labels
1000
1001 Each variable has a set of value labels (@pxref{VALUE LABELS,,,pspp,
1002 PSPP Users Guide}), represented as @struct{val_labs}.  A
1003 @struct{val_labs} is essentially a map from @union{value}s to strings.
1004 All of the values in a set of value labels have the same width, which
1005 for a set of value labels owned by a variable (the common case) is the
1006 same as its variable.
1007
1008 Numeric and short string sets of value labels may contain any number
1009 of entries.  Long string sets of value labels may not contain any
1010 value labels at all, due to a corresponding restriction in SPSS.  In
1011 PSPP we could easily eliminate this restriction, but doing so would
1012 also require us to extend the system file format in an incompatible
1013 way, which we consider a bad tradeoff.
1014
1015 It is rarely necessary to interact directly with a @struct{val_labs}
1016 object.  Instead, the most common operation, looking up the label for
1017 a value of a given variable, can be conveniently executed through
1018 functions on @struct{variable}.  @xref{Variable Value Labels}, for
1019 details.
1020
1021 Function prototypes and other declarations related to missing values
1022 are declared in @file{data/value-labels.h}.
1023
1024 @deftp {Structure} {struct val_labs}
1025 Opaque type that represents a set of value labels.
1026 @end deftp
1027
1028 The most often useful function for value labels is
1029 @func{val_labs_find}, for looking up the label associated with a
1030 value.
1031
1032 @deftypefun {char *} val_labs_find (const struct val_labs *@var{val_labs}, union value @var{value})
1033 Looks in @var{val_labs} for a label for the given @var{value}.
1034 Returns the label, if one is found, or a null pointer otherwise.
1035 @end deftypefun
1036
1037 Several other functions for working with value labels are described in
1038 the following section, but these are more rarely useful.
1039
1040 @menu
1041 * Value Labels Creation and Destruction::
1042 * Value Labels Properties::
1043 * Value Labels Adding and Removing Labels::
1044 * Value Labels Iteration::
1045 @end menu
1046
1047 @node Value Labels Creation and Destruction
1048 @subsection Creation and Destruction
1049
1050 These functions create and destroy @struct{val_labs} objects.
1051
1052 @deftypefun {struct val_labs *} val_labs_create (int @var{width})
1053 Creates and returns an initially empty set of value labels with the
1054 given @var{width}.
1055 @end deftypefun
1056
1057 @deftypefun {struct val_labs *} val_labs_clone (const struct val_labs *@var{val_labs})
1058 Creates and returns a set of value labels whose width and contents are
1059 the same as those of @var{var_labs}.
1060 @end deftypefun
1061
1062 @deftypefun void val_labs_clear (struct val_labs *@var{var_labs})
1063 Deletes all value labels from @var{var_labs}.
1064 @end deftypefun
1065
1066 @deftypefun void val_labs_destroy (struct val_labs *@var{var_labs})
1067 Destroys @var{var_labs}, which must not be referenced again.
1068 @end deftypefun
1069
1070 @node Value Labels Properties
1071 @subsection Value Labels Properties
1072
1073 These functions inspect and manipulate basic properties of
1074 @struct{val_labs} objects.
1075
1076 @deftypefun size_t val_labs_count (const struct val_labs *@var{val_labs})
1077 Returns the number of value labels in @var{val_labs}.
1078 @end deftypefun
1079
1080 @deftypefun bool val_labs_can_set_width (const struct val_labs *@var{val_labs}, int @var{new_width})
1081 Tests whether @var{val_labs}'s width may be changed to @var{new_width}
1082 using @func{val_labs_set_width}.  Returns true if it is allowed, false
1083 otherwise.
1084
1085 A set of value labels may be resized to a given width only if each
1086 value in it may be resized to that width, as determined by
1087 @func{value_is_resizable} (@pxref{value_is_resizable}).
1088 @end deftypefun
1089
1090 @deftypefun void val_labs_set_width (struct val_labs *@var{val_labs}, int @var{new_width})
1091 Changes the width of @var{val_labs}'s values to @var{new_width}, which
1092 must be a valid new width as determined by
1093 @func{val_labs_can_set_width}.
1094
1095 If @var{new_width} is a long string width, this function deletes all
1096 value labels from @var{val_labs}.
1097 @end deftypefun
1098
1099 @node Value Labels Adding and Removing Labels
1100 @subsection Adding and Removing Labels
1101
1102 These functions add and remove value labels from a @struct{val_labs}
1103 object.  These functions apply only to numeric and short string sets
1104 of value labels.  They have no effect on long string sets of value
1105 labels, since these sets are always empty.
1106
1107 @deftypefun bool val_labs_add (struct val_labs *@var{val_labs}, union value @var{value}, const char *@var{label})
1108 Adds @var{label} to in @var{var_labs} as a label for @var{value},
1109 which must have the same width as the set of value labels.  Returns
1110 true if successful, false if @var{value} already has a label or if
1111 @var{val_labs} has long string width.
1112 @end deftypefun
1113
1114 @deftypefun void val_labs_replace (struct val_labs *@var{val_labs}, union value @var{value}, const char *@var{label})
1115 Adds @var{label} to in @var{var_labs} as a label for @var{value},
1116 which must have the same width as the set of value labels.  If
1117 @var{value} already has a label in @var{var_labs}, it is replaced.
1118 Has no effect if @var{var_labs} has long string width.
1119 @end deftypefun
1120
1121 @deftypefun bool val_labs_remove (struct val_labs *@var{val_labs}, union value @var{value})
1122 Removes from @var{val_labs} any label for @var{value}, which must have
1123 the same width as the set of value labels.  Returns true if a label
1124 was removed, false otherwise.
1125 @end deftypefun
1126
1127 @node Value Labels Iteration
1128 @subsection Iterating through Value Labels
1129
1130 These functions allow iteration through the set of value labels
1131 represented by a @struct{val_labs} object.  They may be used in the
1132 context of a @code{for} loop:
1133
1134 @example
1135 struct val_labs val_labs;
1136 const struct val_lab *vl;
1137
1138 @dots{}
1139
1140 for (vl = val_labs_first (val_labs); vl != NULL;
1141      vl = val_labs_next (val_labs, vl))
1142   @{
1143     @dots{}@r{do something with @code{vl}}@dots{}
1144   @}
1145 @end example
1146
1147 Value labels should not be added or deleted from a @struct{val_labs}
1148 as it is undergoing iteration.
1149
1150 @deftypefun {const struct val_lab *} val_labs_first (const struct val_labs *@var{val_labs})
1151 Returns the first value label in @var{var_labs}, if it contains at
1152 least one value label, or a null pointer if it does not contain any
1153 value labels.
1154 @end deftypefun
1155
1156 @deftypefun {const struct val_lab *} val_labs_next (const struct val_labs *@var{val_labs}, const struct val_labs_iterator **@var{vl})
1157 Returns the value label in @var{var_labs} following @var{vl}, if
1158 @var{vl} is not the last value label in @var{val_labs}, or a null
1159 pointer if there are no value labels following @var{vl}.
1160 @end deftypefun
1161
1162 @deftypefun {const struct val_lab **} val_labs_sorted (const struct val_labs *@var{val_labs})
1163 Allocates and returns an array of pointers to value labels, which are
1164 sorted in increasing order by value.  The array has
1165 @code{val_labs_count (@var{val_labs})} elements.  The caller is
1166 responsible for freeing the array with @func{free} (but must not free
1167 any of the @struct{val_lab} elements that the array points to).
1168 @end deftypefun
1169
1170 The iteration functions above work with pointers to @struct{val_lab}
1171 which is an opaque data structure that users of @struct{val_labs} must
1172 not modify or free directly.  The following functions work with
1173 objects of this type:
1174
1175 @deftypefun {const union value *} val_lab_get_value (const struct val_lab *@var{vl})
1176 Returns the value of value label @var{vl}.  The caller must not modify
1177 or free the returned value.  (To achieve a similar result, remove the
1178 value label with @func{val_labs_remove}, then add the new value with
1179 @func{val_labs_add}.)
1180
1181 The width of the returned value cannot be determined directly from
1182 @var{vl}.  It may be obtained by calling @func{val_labs_get_width} on
1183 the @struct{val_labs} that @var{vl} is in.
1184 @end deftypefun
1185
1186 @deftypefun {const char *} val_lab_get_label (const struct val_lab *@var{vl})
1187 Returns the label in @var{vl} as a null-terminated string.  The caller
1188 must not modify or free the returned string.  (Use
1189 @func{val_labs_replace} to change a value label.)
1190 @end deftypefun
1191
1192 @node Variables
1193 @section Variables
1194
1195 A PSPP variable is represented by @struct{variable}, an opaque type
1196 declared in @file{data/variable.h} along with related declarations.
1197 @xref{Variables,,,pspp, PSPP Users Guide}, for a description of PSPP
1198 variables from a user perspective.
1199
1200 PSPP is unusual among computer languages in that, by itself, a PSPP
1201 variable does not have a value.  Instead, a variable in PSPP takes on
1202 a value only in the context of a case, which supplies one value for
1203 each variable in a set of variables (@pxref{Cases}).  The set of
1204 variables in a case, in turn, are ordinarily part of a dictionary
1205 (@pxref{Dictionaries}).
1206
1207 Every variable has several attributes, most of which correspond
1208 directly to one of the variable attributes visible to PSPP users
1209 (@pxref{Attributes,,,pspp, PSPP Users Guide}).
1210
1211 The following sections describe variable-related functions and macros.
1212
1213 @menu
1214 * Variable Name::
1215 * Variable Type and Width::
1216 * Variable Missing Values::
1217 * Variable Value Labels::
1218 * Variable Print and Write Formats::
1219 * Variable Labels::
1220 * Variable GUI Attributes::
1221 * Variable Leave Status::
1222 * Dictionary Class::
1223 * Variable Creation and Destruction::
1224 * Variable Short Names::
1225 * Variable Relationships::
1226 * Variable Auxiliary Data::
1227 * Variable Categorical Values::
1228 @end menu
1229
1230 @node Variable Name
1231 @subsection Variable Name
1232
1233 A variable name is a string between 1 and @code{VAR_NAME_LEN} bytes
1234 long that satisfies the rules for PSPP identifiers
1235 (@pxref{Tokens,,,pspp, PSPP Users Guide}).  Variable names are
1236 mixed-case and treated case-insensitively.
1237
1238 @deftypefn Macro int VAR_NAME_LEN
1239 Maximum length of a variable name, in bytes, currently 64.
1240 @end deftypefn
1241
1242 Only one commonly useful function relates to variable names:
1243
1244 @deftypefun {const char *} var_get_name (const struct variable *@var{var})
1245 Returns @var{var}'s variable name as a C string.
1246 @end deftypefun
1247
1248 A few other functions are much more rarely used.  Some of these
1249 functions are used internally by the dictionary implementation:
1250
1251 @anchor{var_set_name}
1252 @deftypefun {void} var_set_name (struct variable *@var{var}, const char *@var{new_name})
1253 Changes the name of @var{var} to @var{new_name}, which must be a
1254 ``plausible'' name as defined below.
1255
1256 This function cannot be applied to a variable that is part of a
1257 dictionary.  Use @func{dict_rename_var} instead (@pxref{Dictionary
1258 Renaming Variables}).
1259 @end deftypefun
1260
1261 @anchor{var_is_plausible_name}
1262 @deftypefun {bool} var_is_valid_name (const char *@var{name}, bool @var{issue_error})
1263 @deftypefunx {bool} var_is_plausible_name (const char *@var{name}, bool @var{issue_error})
1264 Tests @var{name} for validity or ``plausibility.''  Returns true if
1265 the name is acceptable, false otherwise.  If the name is not
1266 acceptable and @var{issue_error} is true, also issues an error message
1267 explaining the violation.
1268
1269 A valid name is one that fully satisfies all of the requirements for
1270 variable names (@pxref{Tokens,,,pspp, PSPP Users Guide}).  A
1271 ``plausible'' name is simply a string whose length is in the valid
1272 range and that is not a reserved word.  PSPP accepts plausible but
1273 invalid names as variable names in some contexts where the character
1274 encoding scheme is ambiguous, as when reading variable names from
1275 system files.
1276 @end deftypefun
1277
1278 @deftypefun {enum dict_class} var_get_dict_class (const struct variable *@var{var})
1279 Returns the dictionary class of @var{var}'s name (@pxref{Dictionary
1280 Class}).
1281 @end deftypefun
1282
1283 @node Variable Type and Width
1284 @subsection Variable Type and Width
1285
1286 A variable's type and width are the type and width of its values
1287 (@pxref{Values}).
1288
1289 @deftypefun {enum val_type} var_get_type (const struct variable *@var{var})
1290 Returns the type of variable @var{var}.
1291 @end deftypefun
1292
1293 @deftypefun int var_get_width (const struct variable *@var{var})
1294 Returns the width of variable @var{var}.
1295 @end deftypefun
1296
1297 @deftypefun void var_set_width (struct variable *@var{var}, int @var{width})
1298 Sets the width of variable @var{var} to @var{width}.  The width of a
1299 variable should not normally be changed after the variable is created,
1300 so this function is rarely used.  This function cannot be applied to a
1301 variable that is part of a dictionary.
1302 @end deftypefun
1303
1304 @deftypefun bool var_is_numeric (const struct variable *@var{var})
1305 Returns true if @var{var} is a numeric variable, false otherwise.
1306 @end deftypefun
1307
1308 @deftypefun bool var_is_alpha (const struct variable *@var{var})
1309 Returns true if @var{var} is an alphanumeric (string) variable, false
1310 otherwise.
1311 @end deftypefun
1312
1313 @deftypefun bool var_is_short_string (const struct variable *@var{var})
1314 Returns true if @var{var} is a string variable of width
1315 @code{MAX_SHORT_STRING} or less, false otherwise.
1316 @end deftypefun
1317
1318 @deftypefun bool var_is_long_string (const struct variable *@var{var})
1319 Returns true if @var{var} is a string variable of width greater than
1320 @code{MAX_SHORT_STRING}, false otherwise.
1321 @end deftypefun
1322
1323 @node Variable Missing Values
1324 @subsection Variable Missing Values
1325
1326 A numeric or short string variable may have a set of user-missing
1327 values (@pxref{MISSING VALUES,,,pspp, PSPP Users Guide}), represented
1328 as a @struct{missing_values} (@pxref{User-Missing Values}).
1329
1330 The most frequent operation on a variable's missing values is to query
1331 whether a value is user- or system-missing:
1332
1333 @deftypefun bool var_is_value_missing (const struct variable *@var{var}, const union value *@var{value}, enum mv_class @var{class})
1334 @deftypefunx bool var_is_num_missing (const struct variable *@var{var}, double @var{value}, enum mv_class @var{class})
1335 @deftypefunx bool var_is_str_missing (const struct variable *@var{var}, const char @var{value}[], enum mv_class @var{class})
1336 Tests whether @var{value} is a missing value of the given @var{class}
1337 for variable @var{var} and returns true if so, false otherwise.
1338 @func{var_is_num_missing} may only be applied to numeric variables;
1339 @func{var_is_str_missing} may only be applied to string variables.
1340 @var{value} must have been initialized with the same width as
1341 @var{var}.
1342
1343 @code{var_is_@var{type}_missing (@var{var}, @var{value}, @var{class})}
1344 is equivalent to @code{mv_is_@var{type}_missing
1345 (var_get_missing_values (@var{var}), @var{value}, @var{class})}.
1346 @end deftypefun
1347
1348 In addition, a few functions are provided to work more directly with a
1349 variable's @struct{missing_values}:
1350
1351 @deftypefun {const struct missing_values *} var_get_missing_values (const struct variable *@var{var})
1352 Returns the @struct{missing_values} associated with @var{var}.  The
1353 caller must not modify the returned structure.  The return value is
1354 always non-null.
1355 @end deftypefun
1356
1357 @anchor{var_set_missing_values}
1358 @deftypefun {void} var_set_missing_values (struct variable *@var{var}, const struct missing_values *@var{miss})
1359 Changes @var{var}'s missing values to a copy of @var{miss}, or if
1360 @var{miss} is a null pointer, clears @var{var}'s missing values.  If
1361 @var{miss} is non-null, it must have the same width as @var{var} or be
1362 resizable to @var{var}'s width (@pxref{mv_resize}).  The caller
1363 retains ownership of @var{miss}.
1364 @end deftypefun
1365
1366 @deftypefun void var_clear_missing_values (struct variable *@var{var})
1367 Clears @var{var}'s missing values.  Equivalent to
1368 @code{var_set_missing_values (@var{var}, NULL)}.
1369 @end deftypefun
1370
1371 @deftypefun bool var_has_missing_values (const struct variable *@var{var})
1372 Returns true if @var{var} has any missing values, false if it has
1373 none.  Equivalent to @code{mv_is_empty (var_get_missing_values (@var{var}))}.
1374 @end deftypefun
1375
1376 @node Variable Value Labels
1377 @subsection Variable Value Labels
1378
1379 A numeric or short string variable may have a set of value labels
1380 (@pxref{VALUE LABELS,,,pspp, PSPP Users Guide}), represented as a
1381 @struct{val_labs} (@pxref{Value Labels}).  The most commonly useful
1382 functions for value labels return the value label associated with a
1383 value:
1384
1385 @deftypefun {const char *} var_lookup_value_label (const struct variable *@var{var}, const union value *@var{value})
1386 Looks for a label for @var{value} in @var{var}'s set of value labels.
1387 @var{value} must have the same width as @var{var}.  Returns the label
1388 if one exists, otherwise a null pointer.
1389 @end deftypefun
1390
1391 @deftypefun void var_append_value_name (const struct variable *@var{var}, const union value *@var{value}, struct string *@var{str})
1392 Looks for a label for @var{value} in @var{var}'s set of value labels.
1393 @var{value} must have the same width as @var{var}.
1394 If a label exists, it will be appended to the string pointed to by @var{str}.
1395 Otherwise, it formats @var{value}
1396 using @var{var}'s print format (@pxref{Input and Output Formats}) 
1397 and appends the formatted string.
1398 @end deftypefun
1399
1400 The underlying @struct{val_labs} structure may also be accessed
1401 directly using the functions described below.
1402
1403 @deftypefun bool var_has_value_labels (const struct variable *@var{var})
1404 Returns true if @var{var} has at least one value label, false
1405 otherwise.
1406 @end deftypefun
1407
1408 @deftypefun {const struct val_labs *} var_get_value_labels (const struct variable *@var{var})
1409 Returns the @struct{val_labs} associated with @var{var}.  If @var{var}
1410 has no value labels, then the return value may or may not be a null
1411 pointer.
1412
1413 The variable retains ownership of the returned @struct{val_labs},
1414 which the caller must not attempt to modify.
1415 @end deftypefun
1416
1417 @deftypefun void var_set_value_labels (struct variable *@var{var}, const struct val_labs *@var{val_labs})
1418 Replaces @var{var}'s value labels by a copy of @var{val_labs}.  The
1419 caller retains ownership of @var{val_labs}.  If @var{val_labs} is a
1420 null pointer, then @var{var}'s value labels, if any, are deleted.
1421 @end deftypefun
1422
1423 @deftypefun void var_clear_value_labels (struct variable *@var{var})
1424 Deletes @var{var}'s value labels.  Equivalent to
1425 @code{var_set_value_labels (@var{var}, NULL)}.
1426 @end deftypefun
1427
1428 A final group of functions offers shorthands for operations that would
1429 otherwise require getting the value labels from a variable, copying
1430 them, modifying them, and then setting the modified value labels into
1431 the variable (making a second copy):
1432
1433 @deftypefun bool var_add_value_label (struct variable *@var{var}, const union value *@var{value}, const char *@var{label})
1434 Attempts to add a copy of @var{label} as a label for @var{value} for
1435 the given @var{var}.  @var{value} must have the same width as
1436 @var{var}.  If @var{value} already has a label, then the old
1437 label is retained.  Returns true if a label is added, false if there
1438 was an existing label for @var{value} or if @var{var} is a long string
1439 variable.  Either way, the caller retains ownership of @var{value} and
1440 @var{label}.
1441 @end deftypefun
1442
1443 @deftypefun void var_replace_value_label (struct variable *@var{var}, const union value *@var{value}, const char *@var{label})
1444 Attempts to add a copy of @var{label} as a label for @var{value} for
1445 the given @var{var}.  @var{value} must have the same width as
1446 @var{var}.  If @var{value} already has a label, then
1447 @var{label} replaces the old label.  Either way, the caller retains
1448 ownership of @var{value} and @var{label}.
1449
1450 If @var{var} is a long string variable, this function has no effect.
1451 @end deftypefun
1452
1453 @node Variable Print and Write Formats
1454 @subsection Variable Print and Write Formats
1455
1456 Each variable has an associated pair of output formats, called its
1457 @dfn{print format} and @dfn{write format}.  @xref{Input and Output
1458 Formats,,,pspp, PSPP Users Guide}, for an introduction to formats.
1459 @xref{Input and Output Formats}, for a developer's description of
1460 format representation.
1461
1462 The print format is used to convert a variable's data values to
1463 strings for human-readable output.  The write format is used similarly
1464 for machine-readable output, primarily by the WRITE transformation
1465 (@pxref{WRITE,,,pspp, PSPP Users Guide}).  Most often a variable's
1466 print and write formats are the same.
1467
1468 A newly created variable by default has format F8.2 if it is numeric
1469 or an A format with the same width as the variable if it is string.
1470 Many creators of variables override these defaults.
1471
1472 Both the print format and write format are output formats.  Input
1473 formats are not part of @struct{variable}.  Instead, input programs
1474 and transformations keep track of variable input formats themselves.
1475
1476 The following functions work with variable print and write formats.
1477
1478 @deftypefun {const struct fmt_spec *} var_get_print_format (const struct variable *@var{var})
1479 @deftypefunx {const struct fmt_spec *} var_get_write_format (const struct variable *@var{var})
1480 Returns @var{var}'s print or write format, respectively.
1481 @end deftypefun
1482
1483 @deftypefun void var_set_print_format (struct variable *@var{var}, const struct fmt_spec *@var{format})
1484 @deftypefunx void var_set_write_format (struct variable *@var{var}, const struct fmt_spec *@var{format})
1485 @deftypefunx void var_set_both_formats (struct variable *@var{var}, const struct fmt_spec *@var{format})
1486 Sets @var{var}'s print format, write format, or both formats,
1487 respectively, to a copy of @var{format}.
1488 @end deftypefun
1489
1490 @node Variable Labels
1491 @subsection Variable Labels
1492
1493 A variable label is a string that describes a variable.  Variable
1494 labels may contain spaces and punctuation not allowed in variable
1495 names.  @xref{VARIABLE LABELS,,,pspp, PSPP Users Guide}, for a
1496 user-level description of variable labels.
1497
1498 The most commonly useful functions for variable labels are those to
1499 retrieve a variable's label:
1500
1501 @deftypefun {const char *} var_to_string (const struct variable *@var{var})
1502 Returns @var{var}'s variable label, if it has one, otherwise
1503 @var{var}'s name.  In either case the caller must not attempt to
1504 modify or free the returned string.
1505
1506 This function is useful for user output.
1507 @end deftypefun
1508
1509 @deftypefun {const char *} var_get_label (const struct variable *@var{var})
1510 Returns @var{var}'s variable label, if it has one, or a null pointer
1511 otherwise.
1512 @end deftypefun
1513
1514 A few other variable label functions are also provided:
1515
1516 @deftypefun void var_set_label (struct variable *@var{var}, const char *@var{label})
1517 Sets @var{var}'s variable label to a copy of @var{label}, or removes
1518 any label from @var{var} if @var{label} is a null pointer or contains
1519 only spaces.  Leading and trailing spaces are removed from the
1520 variable label and its remaining content is truncated at 255 bytes.
1521 @end deftypefun
1522
1523 @deftypefun void var_clear_label (struct variable *@var{var})
1524 Removes any variable label from @var{var}.
1525 @end deftypefun
1526
1527 @deftypefun bool var_has_label (const struct variable *@var{var})
1528 Returns true if @var{var} has a variable label, false otherwise.
1529 @end deftypefun
1530
1531 @node Variable GUI Attributes
1532 @subsection GUI Attributes
1533
1534 These functions and types access and set attributes that are mainly
1535 used by graphical user interfaces.  Their values are also stored in
1536 and retrieved from system files (but not portable files).
1537
1538 The first group of functions relate to the measurement level of
1539 numeric data.  New variables are assigned a nominal level of
1540 measurement by default.
1541
1542 @deftp {Enumeration} {enum measure}
1543 Measurement level.  Available values are:
1544
1545 @table @code
1546 @item MEASURE_NOMINAL
1547 Numeric data values are arbitrary.  Arithmetic operations and
1548 numerical comparisons of such data are not meaningful.
1549
1550 @item MEASURE_ORDINAL
1551 Numeric data values indicate progression along a rank order.
1552 Arbitrary arithmetic operations such as addition are not meaningful on
1553 such data, but inequality comparisons (less, greater, etc.) have
1554 straightforward interpretations.
1555
1556 @item MEASURE_SCALE
1557 Ratios, sums, etc. of numeric data values have meaningful
1558 interpretations.
1559 @end table
1560
1561 PSPP does not have a separate category for interval data, which would
1562 naturally fall between the ordinal and scale measurement levels.
1563 @end deftp
1564
1565 @deftypefun bool measure_is_valid (enum measure @var{measure})
1566 Returns true if @var{measure} is a valid level of measurement, that
1567 is, if it is one of the @code{enum measure} constants listed above,
1568 and false otherwise.
1569 @end deftypefun
1570
1571 @deftypefun enum measure var_get_measure (const struct variable *@var{var})
1572 @deftypefunx void var_set_measure (struct variable *@var{var}, enum measure @var{measure})
1573 Gets or sets @var{var}'s measurement level.
1574 @end deftypefun
1575
1576 The following set of functions relates to the width of on-screen
1577 columns used for displaying variable data in a graphical user
1578 interface environment.  The unit of measurement is the width of a
1579 character.  For proportionally spaced fonts, this is based on the
1580 average width of a character.
1581
1582 @deftypefun int var_get_display_width (const struct variable *@var{var})
1583 @deftypefunx void var_set_display_width (struct variable *@var{var}, int @var{display_width})
1584 Gets or sets @var{var}'s display width.
1585 @end deftypefun
1586
1587 @anchor{var_default_display_width}
1588 @deftypefun int var_default_display_width (int @var{width})
1589 Returns the default display width for a variable with the given
1590 @var{width}.  The default width of a numeric variable is 8.  The
1591 default width of a string variable is @var{width} or 32, whichever is
1592 less.
1593 @end deftypefun
1594
1595 The final group of functions work with the justification of data when
1596 it is displayed in on-screen columns.  New variables are by default
1597 right-justified.
1598
1599 @deftp {Enumeration} {enum alignment}
1600 Text justification.  Possible values are @code{ALIGN_LEFT},
1601 @code{ALIGN_RIGHT}, and @code{ALIGN_CENTRE}.
1602 @end deftp
1603
1604 @deftypefun bool alignment_is_valid (enum alignment @var{alignment})
1605 Returns true if @var{alignment} is a valid alignment, that is, if it
1606 is one of the @code{enum alignment} constants listed above, and false
1607 otherwise.
1608 @end deftypefun
1609
1610 @deftypefun enum alignment var_get_alignment (const struct variable *@var{var})
1611 @deftypefunx void var_set_alignment (struct variable *@var{var}, enum alignment @var{alignment})
1612 Gets or sets @var{var}'s alignment.
1613 @end deftypefun
1614
1615 @node Variable Leave Status
1616 @subsection Variable Leave Status
1617
1618 Commonly, most or all data in a case come from an input file, read
1619 with a command such as DATA LIST or GET, but data can also be
1620 generated with transformations such as COMPUTE.  In the latter case
1621 the question of a datum's ``initial value'' can arise.  For example,
1622 the value of a piece of generated data can recursively depend on its
1623 own value:
1624 @example
1625 COMPUTE X = X + 1.
1626 @end example
1627 Another situation where the initial value of a variable arises is when
1628 its value is not set at all for some cases, e.g.@: below, @code{Y} is
1629 set only for the first 10 cases:
1630 @example
1631 DO IF #CASENUM <= 10.
1632 + COMPUTE Y = 1.
1633 END IF.
1634 @end example
1635
1636 By default, the initial value of a datum in either of these situations
1637 is the system-missing value for numeric values and spaces for string
1638 values.  This means that, above, X would be system-missing and that Y
1639 would be 1 for the first 10 cases and system-missing for the
1640 remainder.
1641
1642 PSPP also supports retaining the value of a variable from one case to
1643 another, using the LEAVE command (@pxref{LEAVE,,,pspp, PSPP Users
1644 Guide}).  The initial value of such a variable is 0 if it is numeric
1645 and spaces if it is a string.  If the command @samp{LEAVE X Y} is
1646 appended to the above example, then X would have value 1 in the first
1647 case and increase by 1 in every succeeding case, and Y would have
1648 value 1 for the first 10 cases and 0 for later cases.
1649
1650 The LEAVE command has no effect on data that comes from an input file
1651 or whose values do not depend on a variable's initial value.
1652
1653 The value of scratch variables (@pxref{Scratch Variables,,,pspp, PSPP
1654 Users Guide}) are always left from one case to another.
1655
1656 The following functions work with a variable's leave status.
1657
1658 @deftypefun bool var_get_leave (const struct variable *@var{var})
1659 Returns true if @var{var}'s value is to be retained from case to case,
1660 false if it is reinitialized to system-missing or spaces.
1661 @end deftypefun
1662
1663 @deftypefun void var_set_leave (struct variable *@var{var}, bool @var{leave})
1664 If @var{leave} is true, marks @var{var} to be left from case to case;
1665 if @var{leave} is false, marks @var{var} to be reinitialized for each
1666 case.
1667
1668 If @var{var} is a scratch variable, @var{leave} must be true.
1669 @end deftypefun
1670
1671 @deftypefun bool var_must_leave (const struct variable *@var{var})
1672 Returns true if @var{var} must be left from case to case, that is, if
1673 @var{var} is a scratch variable.
1674 @end deftypefun
1675
1676 @node Dictionary Class
1677 @subsection Dictionary Class
1678
1679 Occasionally it is useful to classify variables into @dfn{dictionary
1680 classes} based on their names.  Dictionary classes are represented by
1681 @enum{dict_class}.  This type and other declarations for dictionary
1682 classes are in the @file{<data/dict-class.h>} header.
1683
1684 @deftp {Enumeration} {enum dict_class}
1685 The dictionary classes are:
1686
1687 @table @code
1688 @item DC_ORDINARY
1689 An ordinary variable, one whose name does not begin with @samp{$} or
1690 @samp{#}.
1691
1692 @item DC_SYSTEM
1693 A system variable, one whose name begins with @samp{$}.  @xref{System
1694 Variables,,,pspp, PSPP Users Guide}.
1695
1696 @item DC_SCRATCH
1697 A scratch variable, one whose name begins with @samp{#}.
1698 @xref{Scratch Variables,,,pspp, PSPP Users Guide}.
1699 @end table
1700
1701 The values for dictionary classes are bitwise disjoint, which allows
1702 them to be used in bit-masks.  An extra enumeration constant
1703 @code{DC_ALL}, whose value is the bitwise-@i{or} of all of the above
1704 constants, is provided to aid in this purpose.
1705 @end deftp
1706
1707 One example use of dictionary classes arises in connection with PSPP
1708 syntax that uses @code{@var{a} TO @var{b}} to name the variables in a
1709 dictionary from @var{a} to @var{b} (@pxref{Sets of Variables,,,pspp,
1710 PSPP Users Guide}).  This syntax requires @var{a} and @var{b} to be in
1711 the same dictionary class.  It limits the variables that it includes
1712 to those in that dictionary class.
1713
1714 The following functions relate to dictionary classes.
1715
1716 @deftypefun {enum dict_class} dict_class_from_id (const char *@var{name})
1717 Returns the ``dictionary class'' for the given variable @var{name}, by
1718 looking at its first letter.
1719 @end deftypefun
1720
1721 @deftypefun {const char *} dict_class_to_name (enum dict_class @var{dict_class})
1722 Returns a name for the given @var{dict_class} as an adjective, e.g.@:
1723 @code{"scratch"}.
1724
1725 This function should probably not be used in new code as it can lead
1726 to difficulties for internationalization.
1727 @end deftypefun
1728
1729 @node Variable Creation and Destruction
1730 @subsection Variable Creation and Destruction
1731
1732 Only rarely should PSPP code create or destroy variables directly.
1733 Ordinarily, variables are created within a dictionary and destroying
1734 by individual deletion from the dictionary or by destroying the entire
1735 dictionary at once.  The functions here enable the exceptional case,
1736 of creation and destruction of variables that are not associated with
1737 any dictionary.  These functions are used internally in the dictionary
1738 implementation.
1739
1740 @anchor{var_create}
1741 @deftypefun {struct variable *} var_create (const char *@var{name}, int @var{width})
1742 Creates and returns a new variable with the given @var{name} and
1743 @var{width}.  The new variable is not part of any dictionary.  Use
1744 @func{dict_create_var}, instead, to create a variable in a dictionary
1745 (@pxref{Dictionary Creating Variables}).
1746
1747 @var{name} should be a valid variable name and must be a ``plausible''
1748 variable name (@pxref{Variable Name}).  @var{width} must be between 0
1749 and @code{MAX_STRING}, inclusive (@pxref{Values}).
1750
1751 The new variable has no user-missing values, value labels, or variable
1752 label.  Numeric variables initially have F8.2 print and write formats,
1753 right-justified display alignment, and scale level of measurement.
1754 String variables are created with A print and write formats,
1755 left-justified display alignment, and nominal level of measurement.
1756 The initial display width is determined by
1757 @func{var_default_display_width} (@pxref{var_default_display_width}).
1758
1759 The new variable initially has no short name (@pxref{Variable Short
1760 Names}) and no auxiliary data (@pxref{Variable Auxiliary Data}).
1761 @end deftypefun
1762
1763 @anchor{var_clone}
1764 @deftypefun {struct variable *} var_clone (const struct variable *@var{old_var})
1765 Creates and returns a new variable with the same attributes as
1766 @var{old_var}, with a few exceptions.  First, the new variable is not
1767 part of any dictionary, regardless of whether @var{old_var} was in a
1768 dictionary.  Use @func{dict_clone_var}, instead, to add a clone of a
1769 variable to a dictionary.
1770
1771 Second, the new variable is not given any short name, even if
1772 @var{old_var} had a short name.  This is because the new variable is
1773 likely to be immediately renamed, in which case the short name would
1774 be incorrect (@pxref{Variable Short Names}).
1775
1776 Finally, @var{old_var}'s auxiliary data, if any, is not copied to the
1777 new variable (@pxref{Variable Auxiliary Data}).
1778 @end deftypefun
1779
1780 @deftypefun {void} var_destroy (struct variable *@var{var})
1781 Destroys @var{var} and frees all associated storage, including its
1782 auxiliary data, if any.  @var{var} must not be part of a dictionary.
1783 To delete a variable from a dictionary and destroy it, use
1784 @func{dict_delete_var} (@pxref{Dictionary Deleting Variables}).
1785 @end deftypefun
1786
1787 @node Variable Short Names
1788 @subsection Variable Short Names
1789
1790 PSPP variable names may be up to 64 (@code{VAR_NAME_LEN}) bytes long.
1791 The system and portable file formats, however, were designed when
1792 variable names were limited to 8 bytes in length.  Since then, the
1793 system file format has been augmented with an extension record that
1794 explains how the 8-byte short names map to full-length names
1795 (@pxref{Long Variable Names Record}), but the short names are still
1796 present.  Thus, the continued presence of the short names is more or
1797 less invisible to PSPP users, but every variable in a system file
1798 still has a short name that must be unique.
1799
1800 PSPP can generate unique short names for variables based on their full
1801 names at the time it creates the data file.  If all variables' full
1802 names are unique in their first 8 bytes, then the short names are
1803 simply prefixes of the full names; otherwise, PSPP changes them so
1804 that they are unique.
1805
1806 By itself this algorithm interoperates well with other software that
1807 can read system files, as long as that software understands the
1808 extension record that maps short names to long names.  When the other
1809 software does not understand the extension record, it can produce
1810 surprising results.  Consider a situation where PSPP reads a system
1811 file that contains two variables named RANKINGSCORE, then the user
1812 adds a new variable named RANKINGSTATUS, then saves the modified data
1813 as a new system file.  A program that does not understand long names
1814 would then see one of these variables under the name RANKINGS---either
1815 one, depending on the algorithm's details---and the other under a
1816 different name.  The effect could be very confusing: by adding a new
1817 and apparently unrelated variable in PSPP, the user effectively
1818 renamed the existing variable.
1819
1820 To counteract this potential problem, every @struct{variable} may have
1821 a short name.  A variable created by the system or portable file
1822 reader receives the short name from that data file.  When a variable
1823 with a short name is written to a system or portable file, that
1824 variable receives priority over other long names whose names begin
1825 with the same 8 bytes but which were not read from a data file under
1826 that short name.
1827
1828 Variables not created by the system or portable file reader have no
1829 short name by default.
1830
1831 A variable with a full name of 8 bytes or less in length has absolute
1832 priority for that name when the variable is written to a system file,
1833 even over a second variable with that assigned short name.
1834
1835 PSPP does not enforce uniqueness of short names, although the short
1836 names read from any given data file will always be unique.  If two
1837 variables with the same short name are written to a single data file,
1838 neither one receives priority.
1839
1840 The following macros and functions relate to short names.
1841
1842 @defmac SHORT_NAME_LEN
1843 Maximum length of a short name, in bytes.  Its value is 8.
1844 @end defmac
1845
1846 @deftypefun {const char *} var_get_short_name (const struct variable *@var{var})
1847 Returns @var{var}'s short name, or a null pointer if @var{var} has not
1848 been assigned a short name.
1849 @end deftypefun
1850
1851 @deftypefun void var_set_short_name (struct variable *@var{var}, const char *@var{short_name})
1852 Sets @var{var}'s short name to @var{short_name}, or removes
1853 @var{var}'s short name if @var{short_name} is a null pointer.  If it
1854 is non-null, then @var{short_name} must be a plausible name for a
1855 variable (@pxref{var_is_plausible_name}).  The name will be truncated
1856 to 8 bytes in length and converted to all-uppercase.
1857 @end deftypefun
1858
1859 @deftypefun void var_clear_short_name (struct variable *@var{var})
1860 Removes @var{var}'s short name.
1861 @end deftypefun
1862
1863 @node Variable Relationships
1864 @subsection Variable Relationships
1865
1866 Variables have close relationships with dictionaries
1867 (@pxref{Dictionaries}) and cases (@pxref{Cases}).  A variable is
1868 usually a member of some dictionary, and a case is often used to store
1869 data for the set of variables in a dictionary.
1870
1871 These functions report on these relationships.  They may be applied
1872 only to variables that are in a dictionary.
1873
1874 @deftypefun size_t var_get_dict_index (const struct variable *@var{var})
1875 Returns @var{var}'s index within its dictionary.  The first variable
1876 in a dictionary has index 0, the next variable index 1, and so on.
1877
1878 The dictionary index can be influenced using dictionary functions such
1879 as dict_reorder_var (@pxref{dict_reorder_var}).
1880 @end deftypefun
1881
1882 @deftypefun size_t var_get_case_index (const struct variable *@var{var})
1883 Returns @var{var}'s index within a case.  The case index is an index
1884 into an array of @union{value} large enough to contain all the data in
1885 the dictionary.
1886
1887 The returned case index can be used to access the value of @var{var}
1888 within a case for its dictionary, as in e.g.@: @code{case_data_idx
1889 (case, var_get_case_index (@var{var}))}, but ordinarily it is more
1890 convenient to use the data access functions that do variable-to-index
1891 translation internally, as in e.g.@: @code{case_data (case,
1892 @var{var})}.
1893 @end deftypefun
1894
1895 @node Variable Auxiliary Data
1896 @subsection Variable Auxiliary Data
1897
1898 Each @struct{variable} can have a single pointer to auxiliary data of
1899 type @code{void *}.  These functions manipulate a variable's auxiliary
1900 data.
1901
1902 Use of auxiliary data is discouraged because of its lack of
1903 flexibility.  Only one client can make use of auxiliary data on a
1904 given variable at any time, even though many clients could usefully
1905 associate data with a variable.
1906
1907 To prevent multiple clients from attempting to use a variable's single
1908 auxiliary data field at the same time, we adopt the convention that
1909 use of auxiliary data in the active file dictionary is restricted to
1910 the currently executing command.  In particular, transformations must
1911 not attach auxiliary data to a variable in the active file in the
1912 expectation that it can be used later when the active file is read and
1913 the transformation is executed.  To help enforce this restriction,
1914 auxiliary data is deleted from all variables in the active file
1915 dictionary after the execution of each PSPP command.
1916
1917 This convention for safe use of auxiliary data applies only to the
1918 active file dictionary.  Rules for other dictionaries may be
1919 established separately.
1920
1921 Auxiliary data should be replaced by a more flexible mechanism at some
1922 point, but no replacement mechanism has been designed or implemented
1923 so far.
1924
1925 The following functions work with variable auxiliary data.
1926
1927 @deftypefun {void *} var_get_aux (const struct variable *@var{var})
1928 Returns @var{var}'s auxiliary data, or a null pointer if none has been
1929 assigned.
1930 @end deftypefun
1931
1932 @deftypefun {void *} var_attach_aux (const struct variable *@var{var}, void *@var{aux}, void (*@var{aux_dtor}) (struct variable *))
1933 Sets @var{var}'s auxiliary data to @var{aux}, which must not be null.
1934 @var{var} must not already have auxiliary data.
1935
1936 Before @var{var}'s auxiliary data is cleared by @code{var_clear_aux},
1937 @var{aux_dtor}, if non-null, will be called with @var{var} as its
1938 argument.  It should free any storage associated with @var{aux}, if
1939 necessary.  @code{var_dtor_free} may be appropriate for use as
1940 @var{aux_dtor}:
1941
1942 @deffn {Function} void var_dtor_free (struct variable *@var{var})
1943 Frees @var{var}'s auxiliary data by calling @code{free}.
1944 @end deffn
1945 @end deftypefun
1946
1947 @deftypefun void var_clear_aux (struct variable *@var{var})
1948 Removes auxiliary data, if any, from @var{var}, first calling the
1949 destructor passed to @code{var_attach_aux}, if one was provided.
1950
1951 Use @code{dict_clear_aux} to remove auxiliary data from every variable
1952 in a dictionary. @c (@pxref{dict_clear_aux}).
1953 @end deftypefun
1954
1955 @deftypefun {void *} var_detach_aux (struct variable *@var{var})
1956 Removes auxiliary data, if any, from @var{var}, and returns it.
1957 Returns a null pointer if @var{var} had no auxiliary data.
1958
1959 Any destructor passed to @code{var_attach_aux} is not called, so the
1960 caller is responsible for freeing storage associated with the returned
1961 auxiliary data.
1962 @end deftypefun
1963
1964 @node Variable Categorical Values
1965 @subsection Variable Categorical Values
1966
1967 Some statistical procedures require a list of all the values that a
1968 categorical variable takes on.  Arranging such a list requires making
1969 a pass through the data, so PSPP caches categorical values in
1970 @struct{variable}.
1971
1972 When variable auxiliary data is revamped to support multiple clients
1973 as described in the previous section, categorical values are an
1974 obvious candidate.  The form in which they are currently supported is
1975 inelegant.
1976
1977 Categorical values are not robust against changes in the data.  That
1978 is, there is currently no way to detect that a transformation has
1979 changed data values, meaning that categorical values lists for the
1980 changed variables must be recomputed.  PSPP is in fact in need of a
1981 general-purpose caching and cache-invalidation mechanism, but none
1982 has yet been designed and built.
1983
1984 The following functions work with cached categorical values.
1985
1986 @deftypefun {struct cat_vals *} var_get_obs_vals (const struct variable *@var{var})
1987 Returns @var{var}'s set of categorical values.  Yields undefined
1988 behavior if @var{var} does not have any categorical values.
1989 @end deftypefun
1990
1991 @deftypefun void var_set_obs_vals (const struct variable *@var{var}, struct cat_vals *@var{cat_vals})
1992 Destroys @var{var}'s categorical values, if any, and replaces them by
1993 @var{cat_vals}, ownership of which is transferred to @var{var}.  If
1994 @var{cat_vals} is a null pointer, then @var{var}'s categorical values
1995 are cleared.
1996 @end deftypefun
1997
1998 @deftypefun bool var_has_obs_vals (const struct variable *@var{var})
1999 Returns true if @var{var} has a set of categorical values, false
2000 otherwise.
2001 @end deftypefun
2002
2003 @node Dictionaries
2004 @section Dictionaries
2005
2006 Each data file in memory or on disk has an associated dictionary,
2007 whose primary purpose is to describe the data in the file.
2008 @xref{Variables,,,pspp, PSPP Users Guide}, for a PSPP user's view of a
2009 dictionary.
2010
2011 A data file stored in a PSPP format, either as a system or portable
2012 file, has a representation of its dictionary embedded in it.  Other
2013 kinds of data files are usually not self-describing enough to
2014 construct a dictionary unassisted, so the dictionaries for these files
2015 must be specified explicitly with PSPP commands such as @cmd{DATA
2016 LIST}.
2017
2018 The most important content of a dictionary is an array of variables,
2019 which must have unique names.  A dictionary also conceptually contains
2020 a mapping from each of its variables to a location within a case
2021 (@pxref{Cases}), although in fact these mappings are stored within
2022 individual variables.
2023
2024 System variables are not members of any dictionary (@pxref{System
2025 Variables,,,pspp, PSPP Users Guide}).
2026
2027 Dictionaries are represented by @struct{dictionary}.  Declarations
2028 related to dictionaries are in the @file{<data/dictionary.h>} header.
2029
2030 The following sections describe functions for use with dictionaries.
2031
2032 @menu
2033 * Dictionary Variable Access::
2034 * Dictionary Creating Variables::
2035 * Dictionary Deleting Variables::
2036 * Dictionary Reordering Variables::
2037 * Dictionary Renaming Variables::
2038 * Dictionary Weight Variable::
2039 * Dictionary Filter Variable::
2040 * Dictionary Case Limit::
2041 * Dictionary Split Variables::
2042 * Dictionary File Label::
2043 * Dictionary Documents::
2044 @end menu
2045
2046 @node Dictionary Variable Access
2047 @subsection Accessing Variables
2048
2049 The most common operations on a dictionary simply retrieve a
2050 @code{struct variable *} of an individual variable based on its name
2051 or position.
2052
2053 @deftypefun {struct variable *} dict_lookup_var (const struct dictionary *@var{dict}, const char *@var{name})
2054 @deftypefunx {struct variable *} dict_lookup_var_assert (const struct dictionary *@var{dict}, const char *@var{name})
2055 Looks up and returns the variable with the given @var{name} within
2056 @var{dict}.  Name lookup is not case-sensitive.
2057
2058 @code{dict_lookup_var} returns a null pointer if @var{dict} does not
2059 contain a variable named @var{name}.  @code{dict_lookup_var_assert}
2060 asserts that such a variable exists.
2061 @end deftypefun
2062
2063 @deftypefun {struct variable *} dict_get_var (const struct dictionary *@var{dict}, size_t @var{position})
2064 Returns the variable at the given @var{position} in @var{dict}.
2065 @var{position} must be less than the number of variables in @var{dict}
2066 (see below).
2067 @end deftypefun
2068
2069 @deftypefun size_t dict_get_var_cnt (const struct dictionary *@var{dict})
2070 Returns the number of variables in @var{dict}.
2071 @end deftypefun
2072
2073 Another pair of functions allows retrieving a number of variables at
2074 once.  These functions are more rarely useful.
2075
2076 @deftypefun void dict_get_vars (const struct dictionary *@var{dict}, const struct variable ***@var{vars}, size_t *@var{cnt}, enum dict_class @var{exclude})
2077 @deftypefunx void dict_get_vars_mutable (const struct dictionary *@var{dict}, struct variable ***@var{vars}, size_t *@var{cnt}, enum dict_class @var{exclude})
2078 Retrieves all of the variables in @var{dict}, in their original order,
2079 except that any variables in the dictionary classes specified
2080 @var{exclude}, if any, are excluded (@pxref{Dictionary Class}).
2081 Pointers to the variables are stored in an array allocated with
2082 @code{malloc}, and a pointer to the first element of this array is
2083 stored in @code{*@var{vars}}.  The caller is responsible for freeing
2084 this memory when it is no longer needed.  The number of variables
2085 retrieved is stored in @code{*@var{cnt}}.
2086
2087 The presence or absence of @code{DC_SYSTEM} in @var{exclude} has no
2088 effect, because dictionaries never include system variables.
2089 @end deftypefun
2090
2091 One additional function is available.  This function is most often
2092 used in assertions, but it is not restricted to such use.
2093
2094 @deftypefun bool dict_contains_var (const struct dictionary *@var{dict}, const struct variable *@var{var})
2095 Tests whether @var{var} is one of the variables in @var{dict}.
2096 Returns true if so, false otherwise.
2097 @end deftypefun
2098
2099 @node Dictionary Creating Variables
2100 @subsection Creating Variables
2101
2102 These functions create a new variable and insert it into a dictionary
2103 in a single step.
2104
2105 There is no provision for inserting an already created variable into a
2106 dictionary.  There is no reason that such a function could not be
2107 written, but so far there has been no need for one.
2108
2109 The names provided to one of these functions should be valid variable
2110 names and must be plausible variable names. @c (@pxref{Variable Names}).
2111
2112 If a variable with the same name already exists in the dictionary, the
2113 non-@code{assert} variants of these functions return a null pointer,
2114 without modifying the dictionary.  The @code{assert} variants, on the
2115 other hand, assert that no duplicate name exists.
2116
2117 A variable may be in only one dictionary at any given time.
2118
2119 @deftypefun {struct variable *} dict_create_var (struct dictionary *@var{dict}, const char *@var{name}, int @var{width})
2120 @deftypefunx {struct variable *} dict_create_var_assert (struct dictionary *@var{dict}, const char *@var{name}, int @var{width})
2121 Creates a new variable with the given @var{name} and @var{width}, as
2122 if through a call to @code{var_create} with those arguments
2123 (@pxref{var_create}), appends the new variable to @var{dict}'s array
2124 of variables, and returns the new variable.
2125 @end deftypefun
2126
2127 @deftypefun {struct variable *} dict_clone_var (struct dictionary *@var{dict}, const struct variable *@var{old_var}, const char *@var{name})
2128 @deftypefunx {struct variable *} dict_clone_var_assert (struct dictionary *@var{dict}, const struct variable *@var{old_var}, const char *@var{name})
2129 Creates a new variable as a clone of @var{var}, inserts the new
2130 variable into @var{dict}, and returns the new variable.  The new
2131 variable is named @var{name}.  Other properties of the new variable
2132 are copied from @var{old_var}, except for those not copied by
2133 @code{var_clone} (@pxref{var_clone}).
2134
2135 @var{var} does not need to be a member of any dictionary.
2136 @end deftypefun
2137
2138 @node Dictionary Deleting Variables
2139 @subsection Deleting Variables
2140
2141 These functions remove variables from a dictionary's array of
2142 variables.  They also destroy the removed variables and free their
2143 associated storage.
2144
2145 Deleting a variable to which there might be external pointers is a bad
2146 idea.  In particular, deleting variables from the active file
2147 dictionary is a risky proposition, because transformations can retain
2148 references to arbitrary variables.  Therefore, no variable should be
2149 deleted from the active file dictionary when any transformations are
2150 active, because those transformations might reference the variable to
2151 be deleted.  The safest time to delete a variable is just after a
2152 procedure has been executed, as done by @cmd{DELETE VARIABLES}.
2153
2154 Deleting a variable automatically removes references to that variable
2155 from elsewhere in the dictionary as a weighting variable, filter
2156 variable, @cmd{SPLIT FILE} variable, or member of a vector.
2157
2158 No functions are provided for removing a variable from a dictionary
2159 without destroying that variable.  As with insertion of an existing
2160 variable, there is no reason that this could not be implemented, but
2161 so far there has been no need.
2162
2163 @deftypefun void dict_delete_var (struct dictionary *@var{dict}, struct variable *@var{var})
2164 Deletes @var{var} from @var{dict}, of which it must be a member.
2165 @end deftypefun
2166
2167 @deftypefun void dict_delete_vars (struct dictionary *@var{dict}, struct variable *const *@var{vars}, size_t @var{count})
2168 Deletes the @var{count} variables in array @var{vars} from @var{dict}.
2169 All of the variables in @var{vars} must be members of @var{dict}.  No
2170 variable may be included in @var{vars} more than once.
2171 @end deftypefun
2172
2173 @deftypefun void dict_delete_consecutive_vars (struct dictionary *@var{dict}, size_t @var{idx}, size_t @var{count})
2174 Deletes the variables in sequential positions
2175 @var{idx}@dots{}@var{idx} + @var{count} (exclusive) from @var{dict},
2176 which must contain at least @var{idx} + @var{count} variables.
2177 @end deftypefun
2178
2179 @deftypefun void dict_delete_scratch_vars (struct dictionary *@var{dict})
2180 Deletes all scratch variables from @var{dict}.
2181 @end deftypefun
2182
2183 @node Dictionary Reordering Variables
2184 @subsection Changing Variable Order
2185
2186 The variables in a dictionary are stored in an array.  These functions
2187 change the order of a dictionary's array of variables without changing
2188 which variables are in the dictionary.
2189
2190 @anchor{dict_reorder_var}
2191 @deftypefun void dict_reorder_var (struct dictionary *@var{dict}, struct variable *@var{var}, size_t @var{new_index})
2192 Moves @var{var}, which must be in @var{dict}, so that it is at
2193 position @var{new_index} in @var{dict}'s array of variables.  Other
2194 variables in @var{dict}, if any, retain their relative positions.
2195 @var{new_index} must be less than the number of variables in
2196 @var{dict}.
2197 @end deftypefun
2198
2199 @deftypefun void dict_reorder_vars (struct dictionary *@var{dict}, struct variable *const *@var{new_order}, size_t @var{count})
2200 Moves the @var{count} variables in @var{new_order} to the beginning of
2201 @var{dict}'s array of variables in the specified order.  Other
2202 variables in @var{dict}, if any, retain their relative positions.
2203
2204 All of the variables in @var{new_order} must be in @var{dict}.  No
2205 duplicates are allowed within @var{new_order}, which means that
2206 @var{count} must be no greater than the number of variables in
2207 @var{dict}.
2208 @end deftypefun
2209
2210 @node Dictionary Renaming Variables
2211 @subsection Renaming Variables
2212
2213 These functions change the names of variables within a dictionary.
2214 The @func{var_set_name} function (@pxref{var_set_name}) cannot be
2215 applied directly to a variable that is in a dictionary, because
2216 @struct{dictionary} contains an index by name that @func{var_set_name}
2217 would not update.  The following functions take care to update the
2218 index as well.  They also ensure that variable renaming does not cause
2219 a dictionary to contain a duplicate variable name.
2220
2221 @deftypefun void dict_rename_var (struct dictionary *@var{dict}, struct variable *@var{var}, const char *@var{new_name})
2222 Changes the name of @var{var}, which must be in @var{dict}, to
2223 @var{new_name}.  A variable named @var{new_name} must not already be
2224 in @var{dict}, unless @var{new_name} is the same as @var{var}'s
2225 current name.
2226 @end deftypefun
2227
2228 @deftypefun bool dict_rename_vars (struct dictionary *@var{dicT}, struct variable **@var{vars}, char **@var{new_names}, size_t @var{count}, char **@var{err_name})
2229 Renames each of the @var{count} variables in @var{vars} to the name in
2230 the corresponding position of @var{new_names}.  If the renaming would
2231 result in a duplicate variable name, returns false and stores one of
2232 the names that would be be duplicated into @code{*@var{err_name}}, if
2233 @var{err_name} is non-null.  Otherwise, the renaming is successful,
2234 and true is returned.
2235 @end deftypefun
2236
2237 @node Dictionary Weight Variable
2238 @subsection Weight Variable
2239
2240 A data set's cases may optionally be weighted by the value of a
2241 numeric variable.  @xref{WEIGHT,,,pspp, PSPP Users Guide}, for a user
2242 view of weight variables.
2243
2244 The weight variable is written to and read from system and portable
2245 files.
2246
2247 The most commonly useful function related to weighting is a
2248 convenience function to retrieve a weighting value from a case.
2249
2250 @deftypefun double dict_get_case_weight (const struct dictionary *@var{dict}, const struct ccase *@var{case}, bool *@var{warn_on_invalid})
2251 Retrieves and returns the value of the weighting variable specified by
2252 @var{dict} from @var{case}.  Returns 1.0 if @var{dict} has no
2253 weighting variable.
2254
2255 Returns 0.0 if @var{c}'s weight value is user- or system-missing,
2256 zero, or negative.  In such a case, if @var{warn_on_invalid} is
2257 non-null and @code{*@var{warn_on_invalid}} is true,
2258 @func{dict_get_case_weight} also issues an error message and sets
2259 @code{*@var{warn_on_invalid}} to false.  To disable error reporting,
2260 pass a null pointer or a pointer to false as @var{warn_on_invalid} or
2261 use a @func{msg_disable}/@func{msg_enable} pair.
2262 @end deftypefun
2263
2264 The dictionary also has a pair of functions for getting and setting
2265 the weight variable.
2266
2267 @deftypefun {struct variable *} dict_get_weight (const struct dictionary *@var{dict})
2268 Returns @var{dict}'s current weighting variable, or a null pointer if
2269 the dictionary does not have a weighting variable.
2270 @end deftypefun
2271
2272 @deftypefun void dict_set_weight (struct dictionary *@var{dict}, struct variable *@var{var})
2273 Sets @var{dict}'s weighting variable to @var{var}.  If @var{var} is
2274 non-null, it must be a numeric variable in @var{dict}.  If @var{var}
2275 is null, then @var{dict}'s weighting variable, if any, is cleared.
2276 @end deftypefun
2277
2278 @node Dictionary Filter Variable
2279 @subsection Filter Variable
2280
2281 When the active file is read by a procedure, cases can be excluded
2282 from analysis based on the values of a @dfn{filter variable}.
2283 @xref{FILTER,,,pspp, PSPP Users Guide}, for a user view of filtering.
2284
2285 These functions store and retrieve the filter variable.  They are
2286 rarely useful, because the data analysis framework automatically
2287 excludes from analysis the cases that should be filtered.
2288
2289 @deftypefun {struct variable *} dict_get_filter (const struct dictionary *@var{dict})
2290 Returns @var{dict}'s current filter variable, or a null pointer if the
2291 dictionary does not have a filter variable.
2292 @end deftypefun
2293
2294 @deftypefun void dict_set_filter (struct dictionary *@var{dict}, struct variable *@var{var})
2295 Sets @var{dict}'s filter variable to @var{var}.  If @var{var} is
2296 non-null, it must be a numeric variable in @var{dict}.  If @var{var}
2297 is null, then @var{dict}'s filter variable, if any, is cleared.
2298 @end deftypefun
2299
2300 @node Dictionary Case Limit
2301 @subsection Case Limit
2302
2303 The limit on cases analyzed by a procedure, set by the @cmd{N OF
2304 CASES} command (@pxref{N OF CASES,,,pspp, PSPP Users Guide}), is
2305 stored as part of the dictionary.  The dictionary does not, on the
2306 other hand, play any role in enforcing the case limit (a job done by
2307 data analysis framework code).
2308
2309 A case limit of 0 means that the number of cases is not limited.
2310
2311 These functions are rarely useful, because the data analysis framework
2312 automatically excludes from analysis any cases beyond the limit.
2313
2314 @deftypefun casenumber dict_get_case_limit (const struct dictionary *@var{dict})
2315 Returns the current case limit for @var{dict}.
2316 @end deftypefun
2317
2318 @deftypefun void dict_set_case_limit (struct dictionary *@var{dict}, casenumber @var{limit})
2319 Sets @var{dict}'s case limit to @var{limit}.
2320 @end deftypefun
2321
2322 @node Dictionary Split Variables
2323 @subsection Split Variables
2324
2325 The user may use the @cmd{SPLIT FILE} command (@pxref{SPLIT
2326 FILE,,,pspp, PSPP Users Guide}) to select a set of variables on which
2327 to split the active file into groups of cases to be analyzed
2328 independently in each statistical procedure.  The set of split
2329 variables is stored as part of the dictionary, although the effect on
2330 data analysis is implemented by each individual statistical procedure.
2331
2332 Split variables may be numeric or short or long string variables.
2333
2334 The most useful functions for split variables are those to retrieve
2335 them.  Even these functions are rarely useful directly: for the
2336 purpose of breaking cases into groups based on the values of the split
2337 variables, it is usually easier to use
2338 @func{casegrouper_create_splits}.
2339
2340 @deftypefun {const struct variable *const *} dict_get_split_vars (const struct dictionary *@var{dict})
2341 Returns a pointer to an array of pointers to split variables.  If and
2342 only if there are no split variables, returns a null pointer.  The
2343 caller must not modify or free the returned array.
2344 @end deftypefun
2345
2346 @deftypefun size_t dict_get_split_cnt (const struct dictionary *@var{dict})
2347 Returns the number of split variables.
2348 @end deftypefun
2349
2350 The following functions are also available for working with split
2351 variables.
2352
2353 @deftypefun void dict_set_split_vars (struct dictionary *@var{dict}, struct variable *const *@var{vars}, size_t @var{cnt})
2354 Sets @var{dict}'s split variables to the @var{cnt} variables in
2355 @var{vars}.  If @var{cnt} is 0, then @var{dict} will not have any
2356 split variables.  The caller retains ownership of @var{vars}.
2357 @end deftypefun
2358
2359 @deftypefun void dict_unset_split_var (struct dictionary *@var{dict}, struct variable *@var{var})
2360 Removes @var{var}, which must be a variable in @var{dict}, from
2361 @var{dict}'s split of split variables.
2362 @end deftypefun
2363
2364 @node Dictionary File Label
2365 @subsection File Label
2366
2367 A dictionary may optionally have an associated string that describes
2368 its contents, called its file label.  The user may set the file label
2369 with the @cmd{FILE LABEL} command (@pxref{FILE LABEL,,,pspp, PSPP
2370 Users Guide}).
2371
2372 These functions set and retrieve the file label.
2373
2374 @deftypefun {const char *} dict_get_label (const struct dictionary *@var{dict})
2375 Returns @var{dict}'s file label.  If @var{dict} does not have a label,
2376 returns a null pointer.
2377 @end deftypefun
2378
2379 @deftypefun void dict_set_label (struct dictionary *@var{dict}, const char *@var{label})
2380 Sets @var{dict}'s label to @var{label}.  If @var{label} is non-null,
2381 then its content, truncated to at most 60 bytes, becomes the new file
2382 label.  If @var{label} is null, then @var{dict}'s label is removed.
2383
2384 The caller retains ownership of @var{label}.
2385 @end deftypefun
2386
2387 @node Dictionary Documents
2388 @subsection Documents
2389
2390 A dictionary may include an arbitrary number of lines of explanatory
2391 text, called the dictionary's documents.  For compatibility, document
2392 lines have a fixed width, and lines that are not exactly this width
2393 are truncated or padded with spaces as necessary to bring them to the
2394 correct width.
2395
2396 PSPP users can use the @cmd{DOCUMENT} (@pxref{DOCUMENT,,,pspp, PSPP
2397 Users Guide}), @cmd{ADD DOCUMENT} (@pxref{ADD DOCUMENT,,,pspp, PSPP
2398 Users Guide}), and @cmd{DROP DOCUMENTS} (@pxref{DROP DOCUMENTS,,,pspp,
2399 PSPP Users Guide}) commands to manipulate documents.
2400
2401 @deftypefn Macro int DOC_LINE_LENGTH
2402 The fixed length of a document line, in bytes, defined to 80.
2403 @end deftypefn
2404
2405 The following functions work with whole sets of documents.  They
2406 accept or return sets of documents formatted as null-terminated
2407 strings that are an exact multiple of @code{DOC_LINE_LENGTH}
2408 bytes in length.
2409
2410 @deftypefun {const char *} dict_get_documents (const struct dictionary *@var{dict})
2411 Returns the documents in @var{dict}, or a null pointer if @var{dict}
2412 has no documents.
2413 @end deftypefun
2414
2415 @deftypefun void dict_set_documents (struct dictionary *@var{dict}, const char *@var{new_documents})
2416 Sets @var{dict}'s documents to @var{new_documents}.  If
2417 @var{new_documents} is a null pointer or an empty string, then
2418 @var{dict}'s documents are cleared.  The caller retains ownership of
2419 @var{new_documents}.
2420 @end deftypefun
2421
2422 @deftypefun void dict_clear_documents (struct dictionary *@var{dict})
2423 Clears the documents from @var{dict}.
2424 @end deftypefun
2425
2426 The following functions work with individual lines in a dictionary's
2427 set of documents.
2428
2429 @deftypefun void dict_add_document_line (struct dictionary *@var{dict}, const char *@var{content})
2430 Appends @var{content} to the documents in @var{dict}.  The text in
2431 @var{content} will be truncated or padded with spaces as necessary to
2432 make it exactly @code{DOC_LINE_LENGTH} bytes long.  The caller retains
2433 ownership of @var{content}.
2434
2435 If @var{content} is over @code{DOC_LINE_LENGTH}, this function also
2436 issues a warning using @func{msg}.  To suppress the warning, enclose a
2437 call to one of this function in a @func{msg_disable}/@func{msg_enable}
2438 pair.
2439 @end deftypefun
2440
2441 @deftypefun size_t dict_get_document_line_cnt (const struct dictionary *@var{dict})
2442 Returns the number of line of documents in @var{dict}.  If the
2443 dictionary contains no documents, returns 0.
2444 @end deftypefun
2445
2446 @deftypefun void dict_get_document_line (const struct dictionary *@var{dict}, size_t @var{idx}, struct string *@var{content})
2447 Replaces the text in @var{content} (which must already have been
2448 initialized by the caller) by the document line in @var{dict} numbered
2449 @var{idx}, which must be less than the number of lines of documents in
2450 @var{dict}.  Any trailing white space in the document line is trimmed,
2451 so that @var{content} will have a length between 0 and
2452 @code{DOC_LINE_LENGTH}.
2453 @end deftypefun
2454
2455 @node Coding Conventions
2456 @section Coding Conventions
2457
2458 Every @file{.c} file should have @samp{#include <config.h>} as its
2459 first non-comment line.  No @file{.h} file should include
2460 @file{config.h}.
2461
2462 This section needs to be finished.
2463
2464 @node Cases
2465 @section Cases
2466
2467 This section needs to be written.
2468
2469 @node Data Sets
2470 @section Data Sets
2471
2472 This section needs to be written.
2473
2474 @node Pools
2475 @section Pools
2476
2477 This section needs to be written.
2478
2479 @c  LocalWords:  bool