|
|
d77ab8 |
--- bsd-finger-0.17/finger/finger.c.widechar 2005-12-15 09:14:18.000000000 +0100
|
|
|
d77ab8 |
+++ bsd-finger-0.17/finger/finger.c 2005-12-15 09:14:18.000000000 +0100
|
|
|
d77ab8 |
@@ -77,6 +77,7 @@
|
|
|
d77ab8 |
#include <getopt.h>
|
|
|
d77ab8 |
#include <signal.h>
|
|
|
d77ab8 |
#include <errno.h>
|
|
|
d77ab8 |
+#include <locale.h>
|
|
|
d77ab8 |
#include "finger.h"
|
|
|
d77ab8 |
#ifdef _USAGI
|
|
|
d77ab8 |
#include "version.h"
|
|
|
d77ab8 |
@@ -211,6 +212,9 @@
|
|
|
d77ab8 |
struct utmp *uptr;
|
|
|
d77ab8 |
char name[UT_NAMESIZE + 1];
|
|
|
d77ab8 |
|
|
|
d77ab8 |
+ if (setlocale (LC_ALL, "") != NULL)
|
|
|
d77ab8 |
+ set_haslocale();
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
name[UT_NAMESIZE] = '\0';
|
|
|
d77ab8 |
|
|
|
d77ab8 |
/*
|
|
|
d77ab8 |
@@ -286,6 +287,9 @@
|
|
|
d77ab8 |
struct utmp *uptr;
|
|
|
d77ab8 |
int dolocal, *used;
|
|
|
d77ab8 |
|
|
|
d77ab8 |
+ if (setlocale (LC_ALL, "") != NULL)
|
|
|
d77ab8 |
+ set_haslocale();
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
used = calloc(argc, sizeof(int));
|
|
|
d77ab8 |
if (!used) {
|
|
|
d77ab8 |
eprintf("finger: out of space.\n");
|
|
|
d77ab8 |
--- bsd-finger-0.17/finger/finger.h.widechar 2005-12-15 09:14:17.000000000 +0100
|
|
|
d77ab8 |
+++ bsd-finger-0.17/finger/finger.h 2005-12-15 09:14:18.000000000 +0100
|
|
|
d77ab8 |
@@ -117,3 +117,7 @@
|
|
|
d77ab8 |
/* terminal inquiries */
|
|
|
d77ab8 |
int is8bit(void);
|
|
|
d77ab8 |
int getscreenwidth(void);
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+/* locale support */
|
|
|
d77ab8 |
+void set_haslocale(void);
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
--- bsd-finger-0.17/finger/display.c.widechar 1999-09-29 00:53:58.000000000 +0200
|
|
|
d77ab8 |
+++ bsd-finger-0.17/finger/display.c 2005-12-15 10:05:40.000000000 +0100
|
|
|
d77ab8 |
@@ -40,8 +40,19 @@
|
|
|
d77ab8 |
#include <stdlib.h>
|
|
|
d77ab8 |
#include <string.h>
|
|
|
d77ab8 |
#include <stdarg.h>
|
|
|
d77ab8 |
+#include <inttypes.h>
|
|
|
d77ab8 |
#include "finger.h"
|
|
|
d77ab8 |
|
|
|
d77ab8 |
+#define HAVE_WCHAR_H 1
|
|
|
d77ab8 |
+#define HAVE_MBRTOWC 1
|
|
|
d77ab8 |
+#define HAVE_WCWIDTH 1
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
|
|
|
d77ab8 |
+#include <wchar.h>
|
|
|
d77ab8 |
+#include <wctype.h>
|
|
|
d77ab8 |
+#include <assert.h>
|
|
|
d77ab8 |
+#endif
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
int
|
|
|
d77ab8 |
getscreenwidth(void)
|
|
|
d77ab8 |
{
|
|
|
d77ab8 |
@@ -147,9 +158,105 @@
|
|
|
d77ab8 |
fxputc(stdout, ch);
|
|
|
d77ab8 |
}
|
|
|
d77ab8 |
|
|
|
d77ab8 |
+static int has_locale = 0;
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+void
|
|
|
d77ab8 |
+set_haslocale (void)
|
|
|
d77ab8 |
+{
|
|
|
d77ab8 |
+ has_locale = 1;
|
|
|
d77ab8 |
+}
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
|
|
|
d77ab8 |
+static int verifymultibyte(const char *buf) {
|
|
|
d77ab8 |
+ mbstate_t state;
|
|
|
d77ab8 |
+ wchar_t nextchar;
|
|
|
d77ab8 |
+ size_t bytesconsumed;
|
|
|
d77ab8 |
+ char *eop, *op;
|
|
|
d77ab8 |
+ (void)memset(&state, 0, sizeof(mbstate_t));
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+ eop = (char *) (buf + strlen(buf));
|
|
|
d77ab8 |
+ op = (char *) buf;
|
|
|
d77ab8 |
+ while (op < eop) {
|
|
|
d77ab8 |
+ bytesconsumed = mbrtowc(&nextchar, op, eop - op, &state);
|
|
|
d77ab8 |
+ if (bytesconsumed == (size_t)(-1) ||
|
|
|
d77ab8 |
+ bytesconsumed == (size_t)(-2)) {
|
|
|
d77ab8 |
+ return 0;
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+ op += bytesconsumed;
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+ return 1;
|
|
|
d77ab8 |
+}
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#define OCTALIFY(n, o) \
|
|
|
d77ab8 |
+ *(n)++ = '\\', \
|
|
|
d77ab8 |
+ *(n)++ = (((uint32_t)*(o) >> 6) & 3) + '0', \
|
|
|
d77ab8 |
+ *(n)++ = (((uint32_t)*(o) >> 3) & 7) + '0', \
|
|
|
d77ab8 |
+ *(n)++ = (((uint32_t)*(o) >> 0) & 7) + '0', \
|
|
|
d77ab8 |
+ (o)++
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#endif
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
static void fxputs(FILE *f, const char *buf) {
|
|
|
d77ab8 |
- int i;
|
|
|
d77ab8 |
- for (i=0; buf[i]; i++) fxputc(f, buf[i]);
|
|
|
d77ab8 |
+ int widechars;
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
|
|
|
d77ab8 |
+ if (has_locale)
|
|
|
d77ab8 |
+ widechars = verifymultibyte (buf);
|
|
|
d77ab8 |
+ else
|
|
|
d77ab8 |
+ widechars = 0;
|
|
|
d77ab8 |
+#else
|
|
|
d77ab8 |
+ widechars = 0;
|
|
|
d77ab8 |
+#endif
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+ /* on 7-bit terminals, without wide-chars support, or string
|
|
|
d77ab8 |
+ * isn't parseable, print char * by char */
|
|
|
d77ab8 |
+ if (!is8bit() || !widechars) {
|
|
|
d77ab8 |
+ unsigned int i;
|
|
|
d77ab8 |
+ char ch;
|
|
|
d77ab8 |
+ for (i = 0; i < strlen (buf); i++) {
|
|
|
d77ab8 |
+ ch = buf[i];
|
|
|
d77ab8 |
+ fxputc(f, ch);
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+ return;
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
|
|
|
d77ab8 |
+ {
|
|
|
d77ab8 |
+ mbstate_t state;
|
|
|
d77ab8 |
+ wchar_t nextchar;
|
|
|
d77ab8 |
+ size_t bytesconsumed;
|
|
|
d77ab8 |
+ char *eop, *op, buffer[256];
|
|
|
d77ab8 |
+ (void)memset(&state, 0, sizeof(mbstate_t));
|
|
|
d77ab8 |
+ char* op1;
|
|
|
d77ab8 |
+ eop = (char *) (buf + strlen(buf));
|
|
|
d77ab8 |
+ op = (char *) buf;
|
|
|
d77ab8 |
+ op1 = op;
|
|
|
d77ab8 |
+ while (op < eop) {
|
|
|
d77ab8 |
+ bytesconsumed = mbrtowc(&nextchar, op,
|
|
|
d77ab8 |
+ eop - op, &state);
|
|
|
d77ab8 |
+ /* This isn't supposed to happen as we verified the
|
|
|
d77ab8 |
+ * string before hand */
|
|
|
d77ab8 |
+ assert(bytesconsumed != (size_t)(-1) && bytesconsumed != (size_t)(-2));
|
|
|
d77ab8 |
+
|
|
|
d77ab8 |
+ if (iswprint(nextchar)) {
|
|
|
d77ab8 |
+ (void)memcpy(buffer, op, bytesconsumed);
|
|
|
d77ab8 |
+ buffer[bytesconsumed] = '\0';
|
|
|
d77ab8 |
+ op += bytesconsumed;
|
|
|
d77ab8 |
+ } else if (bytesconsumed == 1) {
|
|
|
d77ab8 |
+ op++;
|
|
|
d77ab8 |
+ } else {
|
|
|
d77ab8 |
+ char *tmp;
|
|
|
d77ab8 |
+ tmp = buffer;
|
|
|
d77ab8 |
+ buffer[bytesconsumed] = '\0';
|
|
|
d77ab8 |
+ while (bytesconsumed-- > 0) {
|
|
|
d77ab8 |
+ OCTALIFY(tmp, op);
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+ fprintf(f,"%s",op1);
|
|
|
d77ab8 |
+ }
|
|
|
d77ab8 |
+#endif
|
|
|
d77ab8 |
}
|
|
|
d77ab8 |
|
|
|
d77ab8 |
int xprintf(const char *fmt, ...) {
|