Yuri Chornoivan contributed some typo fixes
[pspp] / src / data / pc+-file-reader.c
index d9904ef430ea289c798b7d05fc6a31fb9e0ba486..8e9cb94df79cff44bf79ca25a7e85ac59cfac753 100644 (file)
@@ -190,11 +190,10 @@ static bool parse_variable_records (struct pcp_reader *, struct dictionary *,
 static struct any_reader *
 pcp_open (struct file_handle *fh)
 {
-  struct pcp_reader *r;
   struct stat s;
 
   /* Create and initialize reader. */
-  r = xzalloc (sizeof *r);
+  struct pcp_reader *r = XZALLOC (struct pcp_reader);
   r->any_reader.klass = &pcp_file_reader_class;
   r->pool = pool_create ();
   pool_register (r->pool, free, r);
@@ -404,7 +403,7 @@ find_and_delete_var (struct dictionary *dict, const char *name)
     dict_delete_var (dict, var);
 }
 
-/* Decodes the dictionary read from R, saving it into into *DICT.  Character
+/* Decodes the dictionary read from R, saving it into *DICT.  Character
    strings in R are decoded using ENCODING, or an encoding obtained from R if
    ENCODING is null, or the locale encoding if R specifies no encoding.
 
@@ -811,7 +810,7 @@ parse_header (struct pcp_reader *r, const struct pcp_main_header *header,
   info->integer_format = INTEGER_LSB_FIRST;
   info->float_format = FLOAT_IEEE_DOUBLE_LE;
   info->compression = r->compressed ? ANY_COMP_SIMPLE : ANY_COMP_NONE;
-  info->case_cnt = r->n_cases;
+  info->n_cases = r->n_cases;
 
   /* Convert file label to UTF-8 and put it into DICT. */
   label = recode_and_trim_string (r->pool, dict_encoding, header->file_label);
@@ -900,8 +899,7 @@ parse_variable_records (struct pcp_reader *r, struct dictionary *dict,
           if (var_is_numeric (var))
             value.f = parse_float (rec->val_labs[i].value);
           else
-            memcpy (value_str_rw (&value, rec->width),
-                    rec->val_labs[i].value, rec->width);
+            memcpy (value.s, rec->val_labs[i].value, rec->width);
 
           utf8_label = recode_string ("UTF-8", dict_encoding,
                                       rec->val_labs[i].label, -1);
@@ -967,8 +965,7 @@ pcp_file_casereader_read (struct casereader *reader, void *r_)
       if (var->width == 0)
         retval = read_case_number (r, &v->f);
       else
-        retval = read_case_string (r, value_str_rw (v, var->width),
-                                   var->width);
+        retval = read_case_string (r, v->s, var->width);
 
       if (retval != 1)
         {
@@ -1161,12 +1158,13 @@ pcp_msg (struct pcp_reader *r, off_t offset,
     ds_put_format (&text, _("`%s': "), fh_get_file_name (r->fh));
   ds_put_vformat (&text, format, args);
 
-  struct msg m = {
+  struct msg *m = xmalloc (sizeof *m);
+  *m = (struct msg) {
     .category = msg_class_to_category (class),
     .severity = msg_class_to_severity (class),
-    .text = ds_cstr (&text),
+    .text = ds_steal_cstr (&text),
   };
-  msg_emit (&m);
+  msg_emit (m);
 }
 
 /* Displays a warning for offset OFFSET in the file. */
@@ -1202,11 +1200,11 @@ pcp_error (struct pcp_reader *r, off_t offset, const char *format, ...)
    an error. */
 static inline int
 read_bytes_internal (struct pcp_reader *r, bool eof_is_ok,
-                     void *buf, size_t byte_cnt)
+                     void *buf, size_t n_bytes)
 {
-  size_t bytes_read = fread (buf, 1, byte_cnt, r->file);
+  size_t bytes_read = fread (buf, 1, n_bytes, r->file);
   r->pos += bytes_read;
-  if (bytes_read == byte_cnt)
+  if (bytes_read == n_bytes)
     return 1;
   else if (ferror (r->file))
     {
@@ -1226,9 +1224,9 @@ read_bytes_internal (struct pcp_reader *r, bool eof_is_ok,
    Returns true if successful.
    Returns false upon I/O error or if end-of-file is encountered. */
 static bool
-read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt)
+read_bytes (struct pcp_reader *r, void *buf, size_t n_bytes)
 {
-  return read_bytes_internal (r, false, buf, byte_cnt) == 1;
+  return read_bytes_internal (r, false, buf, n_bytes) == 1;
 }
 
 /* Reads BYTE_CNT bytes into BUF.
@@ -1236,9 +1234,9 @@ read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt)
    Returns 0 if an immediate end-of-file is encountered.
    Returns -1 if an I/O error or a partial read occurs. */
 static int
-try_read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt)
+try_read_bytes (struct pcp_reader *r, void *buf, size_t n_bytes)
 {
-  return read_bytes_internal (r, true, buf, byte_cnt);
+  return read_bytes_internal (r, true, buf, n_bytes);
 }
 
 /* Reads a 16-bit signed integer from R and stores its value in host format in