aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c72
1 files changed, 47 insertions, 25 deletions
diff --git a/main.c b/main.c
index a6ec1cb7..15741012 100644
--- a/main.c
+++ b/main.c
@@ -258,7 +258,7 @@ main(int argc, char *const *argv)
break;
case 't':
- tll_push_back(overrides, xstrjoin("term=", optarg, 0));
+ tll_push_back(overrides, xstrjoin("term=", optarg));
break;
case 'L':
@@ -266,11 +266,11 @@ main(int argc, char *const *argv)
break;
case 'T':
- tll_push_back(overrides, xstrjoin("title=", optarg, 0));
+ tll_push_back(overrides, xstrjoin("title=", optarg));
break;
case 'a':
- tll_push_back(overrides, xstrjoin("app-id=", optarg, 0));
+ tll_push_back(overrides, xstrjoin("app-id=", optarg));
break;
case 'D': {
@@ -284,7 +284,7 @@ main(int argc, char *const *argv)
}
case 'f': {
- char *font_override = xstrjoin("font=", optarg, 0);
+ char *font_override = xstrjoin("font=", optarg);
tll_push_back(overrides, font_override);
break;
}
@@ -425,19 +425,19 @@ main(int argc, char *const *argv)
* that does not exist on this system, then the above call may return
* NULL. We should just continue with the fallback method below.
*/
- LOG_WARN("setlocale() failed");
- locale = "C";
+ LOG_ERR("setlocale() failed. The most common cause is that the "
+ "configured locale is not available, or has been misspelled");
}
- LOG_INFO("locale: %s", locale);
+ LOG_INFO("locale: %s", locale != NULL ? locale : "<invalid>");
- bool bad_locale = !locale_is_utf8();
+ bool bad_locale = locale == NULL || !locale_is_utf8();
if (bad_locale) {
static const char fallback_locales[][12] = {
"C.UTF-8",
"en_US.UTF-8",
};
- char *saved_locale = xstrdup(locale);
+ char *saved_locale = locale != NULL ? xstrdup(locale) : NULL;
/*
* Try to force an UTF-8 locale. If we succeed, launch the
@@ -448,13 +448,23 @@ main(int argc, char *const *argv)
const char *const fallback_locale = fallback_locales[i];
if (setlocale(LC_CTYPE, fallback_locale) != NULL) {
- LOG_WARN("'%s' is not a UTF-8 locale, using '%s' instead",
- saved_locale, fallback_locale);
+ if (saved_locale != NULL) {
+ LOG_WARN(
+ "'%s' is not a UTF-8 locale, falling back to '%s'",
+ saved_locale, fallback_locale);
- user_notification_add_fmt(
- &user_notifications, USER_NOTIFICATION_WARNING,
- "'%s' is not a UTF-8 locale, using '%s' instead",
- saved_locale, fallback_locale);
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_WARNING,
+ "'%s' is not a UTF-8 locale, falling back to '%s'",
+ saved_locale, fallback_locale);
+
+ } else {
+ LOG_WARN(
+ "invalid locale, falling back to '%s'", fallback_locale);
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_WARNING,
+ "invalid locale, falling back to '%s'", fallback_locale);
+ }
bad_locale = false;
break;
@@ -462,14 +472,22 @@ main(int argc, char *const *argv)
}
if (bad_locale) {
- LOG_ERR(
- "'%s' is not a UTF-8 locale, and failed to find a fallback",
- saved_locale);
+ if (saved_locale != NULL) {
+ LOG_ERR(
+ "'%s' is not a UTF-8 locale, and failed to find a fallback",
+ saved_locale);
+
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_ERROR,
+ "'%s' is not a UTF-8 locale, and failed to find a fallback",
+ saved_locale);
+ } else {
+ LOG_ERR("invalid locale, and failed to find a fallback");
- user_notification_add_fmt(
- &user_notifications, USER_NOTIFICATION_ERROR,
- "'%s' is not a UTF-8 locale, and failed to find a fallback",
- saved_locale);
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_ERROR,
+ "invalid locale, and failed to find a fallback");
+ }
}
free(saved_locale);
}
@@ -658,15 +676,19 @@ out:
UNITTEST
{
- char *s = xstrjoin("foo", "bar", 0);
+ char *s = xstrjoin("foo", "bar");
xassert(streq(s, "foobar"));
free(s);
- s = xstrjoin("foo", "bar", ' ');
+ s = xstrjoin3("foo", " ", "bar");
xassert(streq(s, "foo bar"));
free(s);
- s = xstrjoin("foo", "bar", ',');
+ s = xstrjoin3("foo", ",", "bar");
xassert(streq(s, "foo,bar"));
free(s);
+
+ s = xstrjoin3("foo", "bar", "baz");
+ xassert(streq(s, "foobarbaz"));
+ free(s);
}