Move locale support to "src/main.c"

This commit is contained in:
Alex Kotov 2021-11-21 07:03:19 +05:00
parent d35c4c0844
commit bc7eff3c4f
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 37 additions and 8 deletions

View File

@ -10,7 +10,6 @@
#include "unit.h"
#include "util.h"
#include <locale.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -268,20 +267,20 @@ static void (*handler[LASTEvent])(XEvent*) = {
#include "config.h"
/****************************
* function implementations *
****************************/
/************************************
* Private function implementations *
************************************/
#include "dwm/handlers.c"
#include "dwm/layouts.c"
#include "dwm/xerror.c"
/***********************************
* Public function implementations *
***********************************/
int dwm_main()
{
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) {
fputs("warning: no locale support\n", stderr);
}
if (!(dpy = XOpenDisplay(NULL))) {
die("polytreewm: cannot open display");
}
@ -306,6 +305,15 @@ int dwm_main()
return EXIT_SUCCESS;
}
bool dwm_has_locale_support()
{
return XSupportsLocale();
}
/************************************
* Private function implementations *
************************************/
int applysizehints(
Client *c,
ClientGeometry client_geometry,

View File

@ -1,6 +1,9 @@
#ifndef _DWM_H
#define _DWM_H
#include <stdbool.h>
int dwm_main();
bool dwm_has_locale_support();
#endif // _DWM_H

View File

@ -2,6 +2,7 @@
#include "dwm.h"
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@ -18,6 +19,10 @@ int main(int argc, char *argv[])
die("usage: polytreewm [-v]");
}
if (!setlocale(LC_CTYPE, "") || !dwm_has_locale_support()) {
warning("no locale support");
}
return dwm_main(argc, argv);
}
@ -45,3 +50,15 @@ void die_perror(const char *const fmt, ...)
exit(EXIT_FAILURE);
}
void warning(const char *const fmt, ...)
{
fputs("WARN: ", stderr);
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputc('\n', stderr);
}

View File

@ -3,5 +3,6 @@
void die(const char *fmt, ...);
void die_perror(const char *fmt, ...);
void warning(const char *fmt, ...);
#endif // _MAIN_H