You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
-#include <config.h>
+#include "config.h"
#include "error.h"
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
+#include "algorithm.h"
#include "alloc.h"
#include "case.h"
#include "command.h"
#include "misc.h"
#include "settings.h"
#include "str.h"
+#include "val.h"
#include "var.h"
#include "vfm.h"
+
/* List of variable names. */
struct varname
{
struct varname *next;
- char name[9];
+ char name[SHORT_NAME_LEN + 1];
};
/* Represents a FLIP input program. */
for (i = 0; i < flip->var_cnt; i++)
if (flip->var[i] == flip->new_names)
{
- memmove (&flip->var[i], &flip->var[i + 1], sizeof *flip->var * (flip->var_cnt - i - 1));
+ remove_element (flip->var, flip->var_cnt, sizeof *flip->var, i);
flip->var_cnt--;
break;
}
static int
make_new_var (char name[])
{
+ char *cp;
+
+ /* Trim trailing spaces. */
+ cp = strchr (name, '\0');
+ while (cp > name && isspace ((unsigned char) cp[-1]))
+ *--cp = '\0';
+
/* Fix invalid characters. */
- {
- char *cp;
-
- for (cp = name; *cp && !isspace (*cp); cp++)
+ for (cp = name; *cp && cp < name + SHORT_NAME_LEN; cp++)
+ if (cp == name)
{
- *cp = toupper ((unsigned char) *cp);
- if (!isalpha (*cp) && *cp != '@' && *cp != '#'
- && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_'
- && !isdigit (*cp))))
- {
- if (cp == name)
- *cp = 'V'; /* _ not valid in first position. */
- else
- *cp = '_';
- }
+ if (!CHAR_IS_ID1 (*cp) || *cp == '$')
+ *cp = 'V';
}
- *cp = 0;
- }
+ else
+ {
+ if (!CHAR_IS_IDN (*cp))
+ *cp = '_';
+ }
+ *cp = '\0';
+ st_uppercase (name);
if (dict_create_var (default_dict, name, 0))
return 1;
/* Add numeric extensions until acceptable. */
{
- int len = (int) strlen (name);
- char n[9];
+ const int len = (int) strlen (name);
+ char n[SHORT_NAME_LEN + 1];
int i;
for (i = 1; i < 10000000; i++)
for (i = 0; i < flip->case_cnt; i++)
{
struct variable *v;
- char s[9];
+ char s[SHORT_NAME_LEN + 1];
sprintf (s, "VAR%03d", i);
v = dict_create_var_assert (default_dict, s, 0);
/* Write variable names as first case. */
for (i = 0; i < flip->var_cnt; i++)
- st_bare_pad_copy (info->output_buf[i].s, flip->var[i]->name, 8);
+ st_bare_pad_copy (info->output_buf[i].s, flip->var[i]->name, MAX_SHORT_STRING);
if (fwrite (info->output_buf, sizeof *info->output_buf,
flip->var_cnt, flip->file) != (size_t) flip->var_cnt)
msg (FE, _("Error writing FLIP file: %s."), strerror (errno));
{
char name[INT_DIGITS + 2];
sprintf (name, "V%d", (int) f);
- strncpy (v->name, name, 8);
- name[8] = 0;
+ st_trim_copy (v->name, name, sizeof v->name);
}
}
else
{
- int width = min (flip->new_names->width, 8);
+ int width = min (flip->new_names->width, MAX_SHORT_STRING);
memcpy (v->name, case_str (c, flip->idx_to_fv[flip->new_names->index]),
width);
v->name[width] = 0;