X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-private.c;h=9114f54e2fda289a4c3a60a962434845c8aec48b;hb=18e998adf231aef51c477bd26d60c65334d19436;hp=2a2979f92a8db7c10c477f150de952b57be9deff;hpb=37273a2e5b058a1907bc7b4b5bf666c64e0afdbb;p=pspp diff --git a/src/data/sys-file-private.c b/src/data/sys-file-private.c index 2a2979f92a..9114f54e2f 100644 --- a/src/data/sys-file-private.c +++ b/src/data/sys-file-private.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2009, 2010 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 @@ -16,15 +16,17 @@ #include -#include +#include "data/sys-file-private.h" -#include -#include -#include -#include +#include "data/dictionary.h" +#include "data/value.h" +#include "data/variable.h" +#include "libpspp/assertion.h" +#include "libpspp/misc.h" -#include "minmax.h" -#include "xalloc.h" +#include "gl/c-strcase.h" +#include "gl/minmax.h" +#include "gl/xalloc.h" /* Number of bytes really stored in each segment of a very long string variable. */ @@ -228,7 +230,8 @@ sfm_dictionary_to_sfm_vars (const struct dictionary *dict, if (used_bytes != 0) { sv = &(*sfm_vars)[(*sfm_var_cnt)++]; - sv->width = width == 0 ? 0 : used_bytes; + sv->var_width = width; + sv->segment_width = width == 0 ? 0 : used_bytes; sv->case_index = var_get_case_index (dv); sv->offset = sfm_segment_offset (width, j); sv->padding = padding; @@ -236,15 +239,44 @@ sfm_dictionary_to_sfm_vars (const struct dictionary *dict, else { /* Segment is all padding. Just add it to the - previous segment. (Otherwise we'd have an - ambiguity whether ->width of 0 indicates a - numeric variable or an all-padding segment.) */ + previous segment. */ sv = &(*sfm_vars)[*sfm_var_cnt - 1]; sv->padding += padding; } - assert ((sv->width + sv->padding) % 8 == 0); + assert ((sv->segment_width + sv->padding) % 8 == 0); } } return segment_cnt; } + +/* Given the name of an encoding, returns the codepage number to use in the + 'character_code' member of the machine integer info record for writing a + system file. */ +int +sys_get_codepage_from_encoding (const char *name) +{ + const struct sys_encoding *e; + + for (e = sys_codepage_name_to_number; e->name != NULL; e++) + if (!c_strcasecmp (name, e->name)) + return e->number; + + return 0; +} + +/* Given a codepage number from the 'character_code' member of the machine + integer info record in a system file, returns a corresponding encoding name. + Most encodings have multiple aliases; the one returned is the one that would + be used in the character encoding record. */ +const char * +sys_get_encoding_from_codepage (int codepage) +{ + const struct sys_encoding *e; + + for (e = sys_codepage_number_to_name; e->name != NULL; e++) + if (codepage == e->number) + return e->name; + + return NULL; +}