hoist out init_lang(), call from ncdirect #888

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

@ -445,11 +445,10 @@ ncdirect* ncdirect_init(const char* termtype, FILE* outfp){
ret->fgdefault = ret->bgdefault = true;
ret->fgrgb = ret->bgrgb = 0;
ncdirect_styles_set(ret, 0);
init_lang(false);
const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){
ret->utf8 = true;
}else if(encoding && strcmp(encoding, "ANSI_X3.4-1968") == 0){
ret->utf8 = false;
}
return ret;
}

@ -314,6 +314,7 @@ typedef struct notcurses {
void sigwinch_handler(int signo);
void init_lang(int verbose);
int terminfostr(char** gseq, const char* name);
int interrogate_terminfo(tinfo* ti);

@ -774,15 +774,14 @@ init_banner(const notcurses* nc){
// 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
// locale as we get it.
static void
init_lang(const notcurses_options* opts){
if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){
const char* locale = setlocale(LC_ALL, "");
if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){
const char* lang = getenv("LANG");
if(lang){
// if LANG was explicitly set to C/POSIX, roll with it
if(strcmp(locale, "C") && strcmp(locale, "POSIX")){
void init_lang(int verbose){
const char* locale = setlocale(LC_ALL, "");
if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){
const char* lang = getenv("LANG");
if(lang){
// if LANG was explicitly set to C/POSIX, roll with it
if(strcmp(locale, "C") && strcmp(locale, "POSIX")){
if(verbose){
if(!locale){ // otherwise, generate diagnostic
fprintf(stderr, "Couldn't set locale based off LANG %s\n", lang);
}else{
@ -790,9 +789,9 @@ init_lang(const notcurses_options* opts){
lang ? lang : "???");
}
}
}else{
fprintf(stderr, "No LANG environment variable was set, ick :/\n");
}
}else if(verbose){
fprintf(stderr, "No LANG environment variable was set, ick :/\n");
}
}
}
@ -842,7 +841,9 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
return ret;
}
ret->loglevel = opts->loglevel;
init_lang(opts);
if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){
init_lang(true);
}
const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){
ret->utf8 = true;

Loading…
Cancel
Save