Ticket #13828: 0002-Fix-style-in-setlocale.patch

File 0002-Fix-style-in-setlocale.patch, 4.1 KB (added by KeyboardFire, 6 years ago)
  • src/bin/setlocale.cpp

    From 9078ef09c3365b7dd1420cf09ea2c041d64cc689 Mon Sep 17 00:00:00 2001
    From: KeyboardFire <andy@keyboardfire.com>
    Date: Sun, 3 Dec 2017 10:01:06 -0600
    Subject: [PATCH 2/4] Fix style in setlocale
    
    Small edits such that it better fits the Haiku style guide.
    ---
     src/bin/setlocale.cpp | 84 ++++++++++++++++++++++++---------------------------
     1 file changed, 40 insertions(+), 44 deletions(-)
    
    diff --git a/src/bin/setlocale.cpp b/src/bin/setlocale.cpp
    index 3b21ef4955..d143337324 100644
    a b  
    99#include <stdio.h>
    1010#include <stdlib.h>
    1111#include <string.h>
     12
    1213#include <Font.h>
    13 #include <String.h>
    1414#include <Locale.h>
    1515#include <LocaleRoster.h>
    1616#include <MutableLocaleRoster.h>
     17#include <String.h>
     18
    1719using BPrivate::MutableLocaleRoster;
    1820
    1921bool matches(const char* a, const char* b)
    bool matches(const char* a, const char* b)  
    2830
    2931int main(int argc, char **argv)
    3032{
    31     const char* queryCode = NULL,
    32         *queryCountry = NULL,
    33         *queryScript = NULL,
    34         *queryVariant = NULL;
     33    const char* queryCode = NULL;
     34    const char* queryCountry = NULL;
     35    const char* queryScript = NULL;
     36    const char* queryVariant = NULL;
    3537    bool list = false, err = false;
    3638
    3739    // parse command line
    int main(int argc, char **argv)  
    5961            // anything more than two arguments
    6062            if (queryCode == NULL)
    6163                queryCode = argv[i];
     64            else if (queryCountry == NULL)
     65                queryCountry = argv[i];
    6266            else {
    63                 if (queryCountry == NULL)
    64                     queryCountry = argv[i];
    65                 else {
    66                     err = true;
    67                     break;
    68                 }
     67                err = true;
     68                break;
    6969            }
     70
    7071        }
    7172    }
    7273
    7374    // check for proper command line, requiring exactly one of list or query
    7475    if (err || ((queryCode == NULL) ^ list)) {
    7576        fprintf(stderr,
    76                 "usage:\n"
    77                 "  %s -l|--list\n"
    78                 "  %s language [country] [-s script] [-v variant]\n",
    79                 argv[0], argv[0]);
     77            "Usage:\n"
     78            "  setlocale -l|--list\n"
     79            "  setlocale language [country] [-s script] [-v variant]\n");
    8080        return 1;
    8181    }
    8282
    int main(int argc, char **argv)  
    9191            // extract all the relevant information about the language
    9292            BString name;
    9393            language->GetNativeName(name);
    94             const char* code = language->Code(),
    95                 *country = language->CountryCode(),
    96                 *script = language->ScriptCode(),
    97                 *variant = language->Variant();
     94            const char* code = language->Code();
     95            const char* country = language->CountryCode();
     96            const char* script = language->ScriptCode();
     97            const char* variant = language->Variant();
    9898
    9999            // if we're listing, print the information
    100             if (list) {
     100            if (list)
    101101                printf("%s\t%s\t%s\t%s\t%s\n",
    102                         code,
    103                         country ? country : "",
    104                         script ? script : "",
    105                         variant ? variant : "",
    106                         name.String());
    107             } else {
    108                 // check to see if this is the desired locale
    109                 if (!strcasecmp(code, queryCode)
    110                         && matches(country, queryCountry)
    111                         && matches(script, queryScript)
    112                         && matches(variant, queryVariant)) {
    113                     // found a match! set the new locale
    114                     BMessage preferred;
    115                     preferred.AddString("language", id);
    116                     MutableLocaleRoster::Default()->
    117                         SetPreferredLanguages(&preferred);
    118                     printf("locale successfully set to %s\n", name.String());
    119                     delete language;
    120                     return 0;
    121                 }
     102                    code,
     103                    country ? country : "",
     104                    script ? script : "",
     105                    variant ? variant : "",
     106                    name.String());
     107            else if (!strcasecmp(code, queryCode)
     108                && matches(country, queryCountry)
     109                && matches(script, queryScript)
     110                && matches(variant, queryVariant)) {
     111                // found a match! set the new locale
     112                BMessage preferred;
     113                preferred.AddString("language", id);
     114                MutableLocaleRoster::Default()->
     115                    SetPreferredLanguages(&preferred);
     116                printf("locale successfully set to %s\n", name.String());
     117                delete language;
     118                return 0;
    122119            }
    123120
    124121            delete language;
    125         } else {
    126             fprintf(stderr, "failed to get BLanguage for %s\n", id);
    127         }
     122        } else
     123            fprintf(stderr, "Failed to get BLanguage for %s\n", id);
    128124    }
    129125
    130126    if (list)
    131127        return 0;
    132128    else {
    133         fprintf(stderr, "locale not found\n");
     129        fprintf(stderr, "Locale not found\n");
    134130        return 1;
    135131    }
    136132}