From: Ben Pfaff Date: Mon, 8 Sep 2014 06:02:03 +0000 (-0700) Subject: str: Make str_format_26adic() able to use lowercase. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=d6fb2728eb8a99e89165c45d8e5d4a482114d3a0 str: Make str_format_26adic() able to use lowercase. The output engine will use lowercase for footnote markers. --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 79952b5814..4eaaefae18 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014 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 @@ -907,7 +907,7 @@ make_hinted_name (const struct dictionary *dict, const char *hint) char *name; suffix[0] = '_'; - if (!str_format_26adic (i + 1, &suffix[1], sizeof suffix - 1)) + if (!str_format_26adic (i + 1, true, &suffix[1], sizeof suffix - 1)) NOT_REACHED (); name = utf8_encoding_concat (root, suffix, dict->encoding, 64); diff --git a/src/data/short-names.c b/src/data/short-names.c index aa157bae1b..ea8df782b4 100644 --- a/src/data/short-names.c +++ b/src/data/short-names.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010, 2011, 2014 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 @@ -62,7 +62,7 @@ assign_short_name (struct variable *v, size_t i, else { suffix[0] = '_'; - str_format_26adic (trial, &suffix[1], sizeof suffix - 1); + str_format_26adic (trial, true, &suffix[1], sizeof suffix - 1); } /* Set name. */ diff --git a/src/libpspp/str.c b/src/libpspp/str.c index d7c71b11f5..3fa2fbe9a7 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2014 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 @@ -257,9 +257,10 @@ str_lowercase (char *s) } /* Converts NUMBER into a string in 26-adic notation in BUFFER, - which has room for SIZE bytes. Returns true if successful, - false if NUMBER, plus a trailing null, is too large to fit in - the available space. + which has room for SIZE bytes. Uses uppercase if UPPERCASE is + true, otherwise lowercase, Returns true if successful, false + if NUMBER, plus a trailing null, is too large to fit in the + available space. 26-adic notation is "spreadsheet column numbering": 1 = A, 2 = B, 3 = C, ... 26 = Z, 27 = AA, 28 = AB, 29 = AC, ... @@ -271,15 +272,18 @@ str_lowercase (char *s) For more information, see http://en.wikipedia.org/wiki/Bijective_numeration. */ bool -str_format_26adic (unsigned long int number, char buffer[], size_t size) +str_format_26adic (unsigned long int number, bool uppercase, + char buffer[], size_t size) { + const char *alphabet + = uppercase ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "abcdefghijklmnopqrstuvwxyz"; size_t length = 0; while (number-- > 0) { if (length >= size) goto overflow; - buffer[length++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[number % 26]; + buffer[length++] = alphabet[number % 26]; number /= 26; } diff --git a/src/libpspp/str.h b/src/libpspp/str.h index 306bd8ba89..dd41ede819 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2014 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 @@ -47,7 +47,8 @@ void str_copy_buf_trunc (char *, size_t, const char *, size_t); void str_uppercase (char *); void str_lowercase (char *); -bool str_format_26adic (unsigned long int number, char buffer[], size_t); +bool str_format_26adic (unsigned long int number, bool uppercase, + char buffer[], size_t); void *mempset (void *, int, size_t); diff --git a/tests/libpspp/str-test.c b/tests/libpspp/str-test.c index c341d887b8..36d5415744 100644 --- a/tests/libpspp/str-test.c +++ b/tests/libpspp/str-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008, 2010 Free Software Foundation, Inc. + Copyright (C) 2008, 2010, 2014 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 @@ -34,7 +34,7 @@ static void check_26adic (unsigned long int number, const char *expected_string) { char string[8]; - str_format_26adic (number, string, sizeof string); + str_format_26adic (number, true, string, sizeof string); if (strcmp (string, expected_string)) { printf ("base-26 of %lu: expected \"%s\", got \"%s\"\n", diff --git a/tests/libpspp/stringi-map-test.c b/tests/libpspp/stringi-map-test.c index 3ae027fb36..20b8ce5c2c 100644 --- a/tests/libpspp/stringi-map-test.c +++ b/tests/libpspp/stringi-map-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 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 @@ -145,7 +145,7 @@ get_string (int idx) if (*s == NULL) { *s = xmalloc (16); - str_format_26adic (idx + 1, *s, 16); + str_format_26adic (idx + 1, true, *s, 16); } return *s; } diff --git a/tests/libpspp/stringi-set-test.c b/tests/libpspp/stringi-set-test.c index daf7b2fa6d..2bcc760780 100644 --- a/tests/libpspp/stringi-set-test.c +++ b/tests/libpspp/stringi-set-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 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 @@ -133,7 +133,7 @@ make_string (int value) if (*s == NULL) { *s = xmalloc (16); - str_format_26adic (value + 1, *s, 16); + str_format_26adic (value + 1, true, *s, 16); } return *s; }