projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor
[pspp]
/
src
/
data
/
vector.c
diff --git
a/src/data/vector.c
b/src/data/vector.c
index 5da797c0a0678fdf6abb3fc1683be6e502ea0a1b..c88d236df6c942057425baa7227cbf23ee02a49f 100644
(file)
--- a/
src/data/vector.c
+++ b/
src/data/vector.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 201
1
Free Software Foundation, Inc.
+ Copyright (C) 2006, 201
0, 2011, 2012
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-21,7
+21,9
@@
#include <stdlib.h>
#include "data/dictionary.h"
#include <stdlib.h>
#include "data/dictionary.h"
+#include "data/identifier.h"
#include "libpspp/assertion.h"
#include "libpspp/assertion.h"
+#include "libpspp/i18n.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
@@
-31,7
+33,7
@@
struct vector
{
char *name; /* Name. */
struct variable **vars; /* Set of variables. */
{
char *name; /* Name. */
struct variable **vars; /* Set of variables. */
- size_t
var_cnt;
/* Number of variables. */
+ size_t
n_vars;
/* Number of variables. */
};
/* Checks that all the variables in VECTOR have consistent
};
/* Checks that all the variables in VECTOR have consistent
@@
-42,25
+44,24
@@
check_widths (const struct vector *vector)
int width = var_get_width (vector->vars[0]);
size_t i;
int width = var_get_width (vector->vars[0]);
size_t i;
- for (i = 1; i < vector->
var_cnt
; i++)
+ for (i = 1; i < vector->
n_vars
; i++)
assert (width == var_get_width (vector->vars[i]));
}
assert (width == var_get_width (vector->vars[i]));
}
-/* Creates and returns a new vector with the given NAME
- that contains the
VAR_CNT
variables in VARS.
+/* Creates and returns a new vector with the given
UTF-8 encoded
NAME
+ that contains the
N_VARS
variables in VARS.
All variables in VARS must have the same type and width. */
struct vector *
All variables in VARS must have the same type and width. */
struct vector *
-vector_create (const char *name,
- struct variable **vars, size_t var_cnt)
+vector_create (const char *name, struct variable **vars, size_t n_vars)
{
struct vector *vector = xmalloc (sizeof *vector);
{
struct vector *vector = xmalloc (sizeof *vector);
- assert (var_cnt > 0);
- assert (var_is_plausible_name (name, false));
- vector->name = xstrdup (name);
+ assert (n_vars > 0);
+ assert (id_is_plausible (name, false));
- vector->vars = xmemdup (vars, var_cnt * sizeof *vector->vars);
- vector->var_cnt = var_cnt;
+ vector->name = xstrdup (name);
+ vector->vars = xmemdup (vars, n_vars * sizeof *vector->vars);
+ vector->n_vars = n_vars;
check_widths (vector);
return vector;
check_widths (vector);
return vector;
@@
-80,10
+81,9
@@
vector_clone (const struct vector *old,
size_t i;
new->name = xstrdup (old->name);
size_t i;
new->name = xstrdup (old->name);
-
- new->vars = xnmalloc (old->var_cnt, sizeof *new->vars);
- new->var_cnt = old->var_cnt;
- for (i = 0; i < new->var_cnt; i++)
+ new->vars = xnmalloc (old->n_vars, sizeof *new->vars);
+ new->n_vars = old->n_vars;
+ for (i = 0; i < new->n_vars; i++)
{
assert (dict_contains_var (old_dict, old->vars[i]));
new->vars[i] = dict_get_var (new_dict,
{
assert (dict_contains_var (old_dict, old->vars[i]));
new->vars[i] = dict_get_var (new_dict,
@@
-103,7
+103,7
@@
vector_destroy (struct vector *vector)
free (vector);
}
free (vector);
}
-/* Returns VECTOR's name. */
+/* Returns VECTOR's name
, as a UTF-8 encoded string
. */
const char *
vector_get_name (const struct vector *vector)
{
const char *
vector_get_name (const struct vector *vector)
{
@@
-120,15
+120,15
@@
enum val_type vector_get_type (const struct vector *vector)
struct variable *
vector_get_var (const struct vector *vector, size_t index)
{
struct variable *
vector_get_var (const struct vector *vector, size_t index)
{
- assert (index < vector->
var_cnt
);
+ assert (index < vector->
n_vars
);
return vector->vars[index];
}
/* Returns the number of variables in VECTOR. */
size_t
return vector->vars[index];
}
/* Returns the number of variables in VECTOR. */
size_t
-vector_get_
var_cnt
(const struct vector *vector)
+vector_get_
n_vars
(const struct vector *vector)
{
{
- return vector->
var_cnt
;
+ return vector->
n_vars
;
}
/* Compares two pointers to vectors represented by A and B and
}
/* Compares two pointers to vectors represented by A and B and
@@
-141,6
+141,6
@@
compare_vector_ptrs_by_name (const void *a_, const void *b_)
struct vector *a = *pa;
struct vector *b = *pb;
struct vector *a = *pa;
struct vector *b = *pb;
- return strcasecmp (a->name, b->name);
+ return
utf8_
strcasecmp (a->name, b->name);
}
}