X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvariable.c;h=64e4b3f0cd9cbeb46e1315a6ee122de4834b9b51;hb=255b128bd64df42632d2a509bd9436f0163539d6;hp=6c1414832b7c992fe5301940a80e33aca794b29d;hpb=573068f2bdcd3f8796e9646668fed910a90f890b;p=pspp-builds.git diff --git a/src/data/variable.c b/src/data/variable.c index 6c141483..64e4b3f0 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -350,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; +} + +