[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nmh-commits] nmh ./ChangeLog sbr/fmt_scan.c
From: |
Josh Bressers |
Subject: |
[Nmh-commits] nmh ./ChangeLog sbr/fmt_scan.c |
Date: |
Sun, 15 Jan 2006 02:29:39 +0000 |
CVSROOT: /sources/nmh
Module name: nmh
Branch:
Changes by: Josh Bressers <address@hidden> 06/01/15 02:29:38
Modified files:
. : ChangeLog
sbr : fmt_scan.c
Log message:
* sbr/fmt_scan.c: Turn the PUTSF macro into a function capable of
handling
multi column characters.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/ChangeLog.diff?tr1=1.222&tr2=1.223&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/sbr/fmt_scan.c.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
Patches:
Index: nmh/ChangeLog
diff -u nmh/ChangeLog:1.222 nmh/ChangeLog:1.223
--- nmh/ChangeLog:1.222 Sat Jan 7 15:22:19 2006
+++ nmh/ChangeLog Sun Jan 15 02:29:38 2006
@@ -1,3 +1,8 @@
+2006-01-14 Josh Bressers <address@hidden>
+
+ * sbr/fmt_scan.c: Turn the PUTSF macro into a function capable of
+ handling multi column characters.
+
2006-01-07 Josh Bressers <address@hidden>
* Remove sbr/strerror.c -- strerror(3) is defined in C89.
Index: nmh/sbr/fmt_scan.c
diff -u nmh/sbr/fmt_scan.c:1.16 nmh/sbr/fmt_scan.c:1.17
--- nmh/sbr/fmt_scan.c:1.16 Sun Nov 6 21:54:40 2005
+++ nmh/sbr/fmt_scan.c Sun Jan 15 02:29:38 2006
@@ -2,7 +2,7 @@
/*
* fmt_scan.c -- format string interpretation
*
- * $Id: fmt_scan.c,v 1.16 2005/11/06 21:54:40 pm215 Exp $
+ * $Id: fmt_scan.c,v 1.17 2006/01/15 02:29:38 bress Exp $
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
@@ -108,40 +108,35 @@
cp += c;\
}
-#ifdef LOCALE
-#define PUTSF(cp, str, wid, fill) {\
- ljust = 0;\
- if ((i = (wid)) < 0) {\
- i = -i;\
- ljust++;\
- }\
- if ((sp = (str))) {\
- if (ljust) {\
- c = strlen(sp);\
- if (c > i)\
- sp += c - i;\
- else {\
- while( --i >= c && cp < ep)\
- *cp++ = fill;\
- i++;\
- }\
- } else {\
- while ((c = (unsigned char) *sp) && (iscntrl(c) ||
isspace(c)))\
- sp++;\
- }\
- while ((c = (unsigned char) *sp++) && --i >= 0 && cp <
ep)\
- if (!iscntrl(c) && !isspace(c)) \
- *cp++ = c;\
- else {\
- while ((c = (unsigned char) *sp) &&
(iscntrl(c) || isspace(c)))\
- sp++;\
- *cp++ = ' ';\
- }\
- }\
- if (!ljust)\
- while( --i >= 0 && cp < ep)\
- *cp++ = fill;\
- }
+char * PUTSF(char *cp, char *str, unsigned int wid, char fill) {
+
+ unsigned int i, j;
+ unsigned int char_len;
+ unsigned int term_len = 0;
+ wchar_t wide_char;
+
+ for (i = 0 ; i < wid && i < strlen(str) && term_len < wid; ) {
+ char_len = mblen(str + i, strlen(str + i));
+ if (char_len <= 0) {
+ continue;
+ }
+ mbtowc(&wide_char, str + i, strlen(str + i));
+ term_len += wcwidth(wide_char);
+
+ for (j = 0 ; j < char_len ; j++) {
+ *(cp + i) = *(str + i);
+ i++;
+ }
+ }
+
+ if (term_len < wid) {
+ for (j = term_len ; j <= wid ; j++) {
+ *(cp + i++) = fill;
+ }
+ }
+
+ return cp + i;
+}
#define PUTS(cp, str) {\
if ((sp = (str))) {\
@@ -158,59 +153,6 @@
}\
}
-#else /* LOCALE */
-#define PUTSF(cp, str, wid, fill) {\
- ljust = 0;\
- if ((i = (wid)) < 0) {\
- i = -i;\
- ljust++;\
- }\
- if (sp = (str)) {\
- if (ljust) {\
- c = strlen(sp);\
- if (c > i)\
- sp += c - i;\
- else {\
- while( --i >= c && cp < ep)\
- *cp++ = fill;\
- i++;\
- }\
- } else {\
- while ((c = *sp) && c <= 32)\
- sp++;\
- }\
- while ((c = *sp++) && --i >= 0 && cp < ep)\
- if (c > 32) \
- *cp++ = c;\
- else {\
- while ((c = *sp) && c <= 32)\
- sp++;\
- *cp++ = ' ';\
- }\
- }\
- if (!ljust)\
- while( --i >= 0 && cp < ep)\
- *cp++ = fill;\
- }
-
-#define PUTS(cp, str) {\
- if (sp = (str)) {\
- while ((c = *sp) && c <= 32)\
- sp++;\
- while( (c = *sp++) && cp < ep)\
- if ( c > 32 ) \
- *cp++ = c;\
- else {\
- while ( (c = *sp) && c <= 32 )\
- sp++;\
- *cp++ = ' ';\
- }\
- }\
- }
-
-#endif /* LOCALE */
-
-
static char *lmonth[] = { "January", "February","March", "April",
"May", "June", "July", "August",
"September","October", "November","December" };
@@ -293,7 +235,7 @@
PUTS (cp, fmt->f_comp->c_text);
break;
case FT_COMPF:
- PUTSF (cp, fmt->f_comp->c_text, fmt->f_width, fmt->f_fill);
+ cp = PUTSF(cp, fmt->f_comp->c_text, fmt->f_width, fmt->f_fill);
break;
case FT_LIT:
@@ -319,7 +261,7 @@
PUTS (cp, str);
break;
case FT_STRF:
- PUTSF (cp, str, fmt->f_width, fmt->f_fill);
+ cp =PUTSF (cp, str, fmt->f_width, fmt->f_fill);
break;
case FT_STRFW:
adios (NULL, "internal error (FT_STRFW)");
- [Nmh-commits] nmh ./ChangeLog sbr/fmt_scan.c,
Josh Bressers <=