summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris West (Faux) <git@goeswhere.com>2013-01-13 12:35:25 +0000
committerChris West (Faux) <git@goeswhere.com>2013-01-13 12:42:28 +0000
commitc4f5f370acb48aa60bc8c6f54407648089e60942 (patch)
treef1ef6f8c82bf0bdae6df02397b6c8098e833fbd0
parentfdd86924e5f22669603dc9524e33583d5173f01f (diff)
use the locale's thousand seperator, if available
-rw-r--r--src/main.c1
-rw-r--r--src/util.c14
-rw-r--r--src/util.h3
3 files changed, 17 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 71b7546..109f2a1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -246,6 +246,7 @@ static void init_nc() {
/* main program */
int main(int argc, char **argv) {
setlocale(LC_ALL, "");
+ read_locale();
argv_parse(argc, argv);
if(dir_ui == 2)
diff --git a/src/util.c b/src/util.c
index 5da9db5..137d16d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -28,9 +28,11 @@
#include <string.h>
#include <stdlib.h>
#include <ncurses.h>
+#include <locale.h>
int winrows, wincols;
int subwinr, subwinc;
+char thou_sep;
char *cropstr(const char *from, int s) {
@@ -88,7 +90,7 @@ char *fullsize(int64_t from) {
while(i--) {
dat[j++] = tmp[i];
if(i != 0 && i%3 == 0)
- dat[j++] = '.';
+ dat[j++] = thou_sep;
}
dat[j] = '\0';
@@ -96,6 +98,16 @@ char *fullsize(int64_t from) {
}
+void read_locale() {
+ char *locale_thou_sep = localeconv()->thousands_sep;
+ if (locale_thou_sep && 1 == strlen(locale_thou_sep)) {
+ thou_sep = locale_thou_sep[0];
+ } else {
+ thou_sep = '.';
+ }
+}
+
+
int ncresize(int minrows, int mincols) {
int ch;
diff --git a/src/util.h b/src/util.h
index 933bf97..d3b417f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -71,6 +71,9 @@ char *formatsize(int64_t );
/* int2string with thousand separators */
char *fullsize(int64_t);
+/* read locale information from the environment */
+void read_locale();
+
/* recursively free()s a directory tree */
void freedir(struct dir *);