- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <data/value-labels.h>
#include <data/variable.h>
#include <libpspp/compiler.h>
#include <data/value-labels.h>
#include <data/variable.h>
#include <libpspp/compiler.h>
/* portable_to_local[PORTABLE] translates the given portable
character into the local character set. */
/* portable_to_local[PORTABLE] translates the given portable
character into the local character set. */
jmp_buf bail_out; /* longjmp() target for error handling. */
struct file_handle *fh; /* File handle. */
jmp_buf bail_out; /* longjmp() target for error handling. */
struct file_handle *fh; /* File handle. */
FILE *file; /* File stream. */
int line_length; /* Number of characters so far on this line. */
char cc; /* Current character. */
char *trans; /* 256-byte character set translation table. */
int var_cnt; /* Number of variables. */
int weight_index; /* 0-based index of weight variable, or -1. */
FILE *file; /* File stream. */
int line_length; /* Number of characters so far on this line. */
char cc; /* Current character. */
char *trans; /* 256-byte character set translation table. */
int var_cnt; /* Number of variables. */
int weight_index; /* 0-based index of weight variable, or -1. */
/* Create and initialize reader. */
pool = pool_create ();
r = pool_alloc (pool, sizeof *r);
r->pool = pool;
/* Create and initialize reader. */
pool = pool_create ();
r = pool_alloc (pool, sizeof *r);
r->pool = pool;
- /* Check that file open succeeded. */
+ /* Lock file. */
+ /* TRANSLATORS: this fragment will be interpolated into
+ messages in fh_lock() that identify types of files. */
+ r->lock = fh_lock (fh, FH_REF_FILE, N_("portable file"), FH_ACC_READ, false);
+ if (r->lock == NULL)
+ goto error;
+
+ /* Open file. */
+ r->file = fn_open (fh_get_file_name (r->fh), "rb");
- r->value_cnt = dict_get_next_value_idx (*dict);
- return casereader_create_sequential (NULL, r->value_cnt, CASENUMBER_MAX,
+ r->proto = caseproto_ref_pool (dict_get_proto (*dict), r->pool);
+ return casereader_create_sequential (NULL, r->proto, CASENUMBER_MAX,
- static char empty_string[] = "";
- char *date, *time, *product, *author, *subproduct;
+ static const char empty_string[] = "";
+ char *date, *time;
+ const char *product, *author, *subproduct;
r->var_cnt = read_int (r);
if (r->var_cnt <= 0)
error (r, _("Invalid number of variables %d."), r->var_cnt);
r->var_cnt = read_int (r);
if (r->var_cnt <= 0)
error (r, _("Invalid number of variables %d."), r->var_cnt);
- char try_name[LONG_NAME_LEN + 1];
- sprintf (try_name, "%.*s_%d", LONG_NAME_LEN - 6, name, i);
+ char try_name[VAR_NAME_LEN + 1];
+ sprintf (try_name, "%.*s_%d", VAR_NAME_LEN - 6, name, i);
- buf_copy_str_rpad (v.s, 8, string);
+ buf_copy_str_rpad (value_str_rw (v, 8), 8, string, ' ');
- if (!var_is_long_string (var))
- var_replace_value_label (var, &val, label);
- }
+ value_destroy (&val, var_get_width (v[0]));
-/* Reads one case from portable file R into C. */
-static bool
-por_file_casereader_read (struct casereader *reader, void *r_, struct ccase *c)
+/* Reads and returns one case from portable file R. Returns a
+ null pointer on failure. */
+static struct ccase *
+por_file_casereader_read (struct casereader *reader, void *r_)
- buf_copy_str_rpad (case_data_rw_idx (c, idx)->s, width, string);
+ buf_copy_str_rpad (case_str_rw_idx (c, idx), width, string, ' ');
{
por_file_casereader_read,
por_file_casereader_destroy,
{
por_file_casereader_read,
por_file_casereader_destroy,