diff options
author | phantom <phantom@FreeBSD.org> | 2003-06-26 11:01:03 +0000 |
---|---|---|
committer | phantom <phantom@FreeBSD.org> | 2003-06-26 11:01:03 +0000 |
commit | 5d0b1c27887c7c917f04d4414d1253999ff2e4d1 (patch) | |
tree | 2805075462b2407d4acd4fa055cac5a835f0d66f /usr.bin | |
parent | cd4974c7348424a7f4d7337db3b49ee377be4b47 (diff) | |
download | FreeBSD-src-5d0b1c27887c7c917f04d4414d1253999ff2e4d1.zip FreeBSD-src-5d0b1c27887c7c917f04d4414d1253999ff2e4d1.tar.gz |
Add support of '-m' option to show charmaps (or correctly to say list of
available codesets)
Modify manpages appropriatelly
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/locale/locale.1 | 15 | ||||
-rw-r--r-- | usr.bin/locale/locale.c | 52 |
2 files changed, 54 insertions, 13 deletions
diff --git a/usr.bin/locale/locale.1 b/usr.bin/locale/locale.1 index 418298d..4122610 100644 --- a/usr.bin/locale/locale.1 +++ b/usr.bin/locale/locale.1 @@ -65,15 +65,15 @@ will respect .Ev PATH_LOCALE environment variable, and use it instead of system default locale directory. -.\" .It Fl m -.\" Write names of all available charmaps. +.It Fl m +Write names of all available charmaps. .It Fl k Write the name and value of the selected keywords. .It Fl c Write the category name for the selected keywords. .El .Sh IMPLEMENTATION DETAILS -Special keyword +Special (FreeBSD specific) keyword .Ar list can be used to retrieve human readable list of available keywrods. .Sh DIAGNOSTICS @@ -84,12 +84,11 @@ utility exits 0 on success, and >0 if an error occurs. Since .Fx does not support -.Em charpmap Ns No s +.Em charmap Ns No s in their .Em POSIX meaning .Nm -ignores -.Fl m -option -(support, but do nothing). +emulates +.Ar m +option via CODESETs listing of all available locales. diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c index b763034..418acd7 100644 --- a/usr.bin/locale/locale.c +++ b/usr.bin/locale/locale.c @@ -49,6 +49,7 @@ /* Local prototypes */ void init_locales_list(void); +void list_charmaps(void); void list_locales(void); const char *lookup_localecat(int); char *kwval_lconv(int); @@ -252,11 +253,8 @@ main(int argc, char *argv[]) /* process '-m' */ if (all_charmaps) { - /* - * XXX: charmaps are not supported by FreeBSD now. It - * need to be implemented as soon as localedef(1) implemented. - */ - exit(1); + list_charmaps(); + exit(0); } /* check for special case '-k list' */ @@ -312,6 +310,50 @@ list_locales(void) } } +/* + * Output information about all available charmaps + * + * XXX this function is doing a task in hackish way, i.e. by scaning + * list of locales, spliting their codeset part and building list of + * them. + */ +void +list_charmaps(void) +{ + size_t i; + char *s, *cs; + StringList *charmaps; + + /* initialize StringList */ + charmaps = sl_init(); + if (charmaps == NULL) + err(1, "could not allocate memory"); + + /* fetch locales list */ + init_locales_list(); + + /* split codesets and build their list */ + for (i = 0; i < locales->sl_cur; i++) { + s = locales->sl_str[i]; + if ((cs = strchr(s, '.')) != NULL) { + cs++; + if (sl_find(charmaps, cs) == NULL) + sl_add(charmaps, cs); + } + } + + /* add US-ASCII, if not yet added */ + if (sl_find(charmaps, "US-ASCII") == NULL) + sl_add(charmaps, "US-ASCII"); + + /* sort the list */ + qsort(charmaps->sl_str, charmaps->sl_cur, sizeof(char *), scmp); + + /* print results */ + for (i = 0; i < charmaps->sl_cur; i++) { + printf("%s\n", charmaps->sl_str[i]); + } +} /* * qsort() helper function |