X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fdata%2Fvariable.c;h=64e4b3f0cd9cbeb46e1315a6ee122de4834b9b51;hb=b64685d06f8db1aff292ec409abe25f8a483d775;hp=3c170c842c943fddd2039d8932543fb1849eebee;hpb=985c40f2a83588b25f0e6fe7f7d82863c5d34d43;p=pspp-builds.git diff --git a/src/data/variable.c b/src/data/variable.c index 3c170c84..64e4b3f0 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -131,6 +131,7 @@ hash_value(const union value *v, int width) bool var_is_valid_name (const char *name, bool issue_error) { + bool plausible; size_t length, i; assert (name != NULL); @@ -139,7 +140,7 @@ var_is_valid_name (const char *name, bool issue_error) CHARACTERS */ length = strlen (name); - bool plausible = var_is_plausible_name(name, issue_error); + plausible = var_is_plausible_name(name, issue_error); if ( ! plausible ) return false; @@ -349,3 +350,36 @@ dict_class_to_name (enum dict_class dict_class) abort (); } } + +/* Return the number of bytes used when writing case_data for a variable + of WIDTH */ +int +width_to_bytes(int width) +{ + const int chunks = width / EFFECTIVE_LONG_STRING_LENGTH ; + const int remainder = width - (chunks * EFFECTIVE_LONG_STRING_LENGTH) ; + int bytes, mod8; + + assert (width >= 0); + + if ( width == 0 ) + return MAX_SHORT_STRING ; + + if ( width <= MAX_LONG_STRING) + return MAX_SHORT_STRING * DIV_RND_UP(width, MAX_SHORT_STRING); + + + bytes = remainder + (chunks * (MAX_LONG_STRING + 1) ); + + /* Round up to the nearest 8 */ + mod8 = bytes % MAX_SHORT_STRING; + + if ( mod8 ) + bytes += MAX_SHORT_STRING - mod8; + + assert( bytes % MAX_SHORT_STRING == 0 ); + + return bytes; +} + +