init_lang(): take struct notcurses, not verbose flag #888

pull/907/head
nick black 4 years ago committed by Nick Black
parent bcff36ac77
commit a64433afe2

@ -445,7 +445,7 @@ ncdirect* ncdirect_init(const char* termtype, FILE* outfp){
ret->fgdefault = ret->bgdefault = true; ret->fgdefault = ret->bgdefault = true;
ret->fgrgb = ret->bgrgb = 0; ret->fgrgb = ret->bgrgb = 0;
ncdirect_styles_set(ret, 0); ncdirect_styles_set(ret, 0);
init_lang(false); init_lang(nullptr);
const char* encoding = nl_langinfo(CODESET); const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){ if(encoding && strcmp(encoding, "UTF-8") == 0){
ret->utf8 = true; ret->utf8 = true;

@ -314,7 +314,7 @@ typedef struct notcurses {
void sigwinch_handler(int signo); void sigwinch_handler(int signo);
void init_lang(int verbose); void init_lang(struct notcurses* nc); // nc may be NULL, only used for logging
int terminfostr(char** gseq, const char* name); int terminfostr(char** gseq, const char* name);
int interrogate_terminfo(tinfo* ti); int interrogate_terminfo(tinfo* ti);

@ -774,24 +774,22 @@ init_banner(const notcurses* nc){
// practice is for the client code to have called setlocale() themselves, and // practice is for the client code to have called setlocale() themselves, and
// set the NCOPTION_INHIBIT_SETLOCALE flag. if that flag is set, we take the // set the NCOPTION_INHIBIT_SETLOCALE flag. if that flag is set, we take the
// locale as we get it. // locale as we get it.
void init_lang(int verbose){ void init_lang(struct notcurses* nc){
const char* locale = setlocale(LC_ALL, ""); const char* locale = setlocale(LC_ALL, "");
if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){ if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){
const char* lang = getenv("LANG"); const char* lang = getenv("LANG");
if(lang){ if(lang){
// if LANG was explicitly set to C/POSIX, roll with it // if LANG was explicitly set to C/POSIX, roll with it
if(strcmp(locale, "C") && strcmp(locale, "POSIX")){ if(strcmp(locale, "C") && strcmp(locale, "POSIX")){
if(verbose){
if(!locale){ // otherwise, generate diagnostic if(!locale){ // otherwise, generate diagnostic
fprintf(stderr, "Couldn't set locale based off LANG %s\n", lang); logerror(nc, "Couldn't set locale based off LANG %s\n", lang);
}else{ }else{
fprintf(stderr, "Set %s locale from LANG; client should call setlocale(2)!\n", loginfo(nc, "Set %s locale from LANG; client should call setlocale(2)!\n",
lang ? lang : "???"); lang ? lang : "???");
} }
} }
} }else{
}else if(verbose){ logwarn(nc, "No LANG environment variable was set, ick :/\n");
fprintf(stderr, "No LANG environment variable was set, ick :/\n");
} }
} }
} }
@ -842,7 +840,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
} }
ret->loglevel = opts->loglevel; ret->loglevel = opts->loglevel;
if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){ if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){
init_lang(true); init_lang(ret);
} }
const char* encoding = nl_langinfo(CODESET); const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){ if(encoding && strcmp(encoding, "UTF-8") == 0){

Loading…
Cancel
Save