diff -ruN newt-0.51.0/button.c newt-0.50.39/button.c --- newt-0.51.0/button.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/button.c Tue Jan 23 15:27:38 2001 @@ -30,7 +30,6 @@ static newtComponent createButton(int left, int row, const char * text, int compact) { newtComponent co; struct button * bu; - int width = wstrlen(text,-1); co = malloc(sizeof(*co)); bu = malloc(sizeof(struct button)); @@ -42,10 +41,10 @@ if (bu->compact) { co->height = 1; - co->width = width + 3; + co->width = strlen(text) + 3; } else { co->height = 4; - co->width = width + 5; + co->width = strlen(text) + 5; } co->top = row; diff -ruN newt-0.51.0/checkbox.c newt-0.50.39/checkbox.c --- newt-0.51.0/checkbox.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/checkbox.c Tue Jan 23 15:27:38 2001 @@ -117,7 +117,7 @@ co->callback = NULL; co->height = 1; - co->width = wstrlen(text, -1) + 4; + co->width = strlen(text) + 4; co->top = top; co->left = left; co->takesFocus = 1; diff -ruN newt-0.51.0/checkboxtree.c newt-0.50.39/checkboxtree.c --- newt-0.51.0/checkboxtree.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/checkboxtree.c Fri Jul 6 07:42:00 2001 @@ -169,7 +169,7 @@ int flags, int * indexes) { struct items * curList, * newNode, * item; struct items ** listPtr = NULL; - int i, index, numIndexes, width; + int i, index, numIndexes; struct CheckboxTree * ct = co->data; numIndexes = 0; @@ -243,10 +243,9 @@ item->depth = numIndexes - 1; i = 4 + (3 * item->depth); - width = wstrlen(text, -1); - if ((ct->userHasSetWidth == 0) && ((width + i + ct->sbAdjust) > co->width)) { - updateWidth(co, ct, width + i); + if ((ct->userHasSetWidth == 0) && ((strlen(text) + i + ct->sbAdjust) > co->width)) { + updateWidth(co, ct, strlen(text) + i); } return 0; @@ -696,7 +695,7 @@ { struct CheckboxTree * ct; struct items * item; - int i, width; + int i; if (!co) return; ct = co->data; @@ -708,9 +707,8 @@ i = 4 + (3 * item->depth); - width = wstrlen(text, -1); - if ((ct->userHasSetWidth == 0) && ((width + i + ct->sbAdjust) > co->width)) { - updateWidth(co, ct, width + i); + if ((ct->userHasSetWidth == 0) && ((strlen(text) + i + ct->sbAdjust) > co->width)) { + updateWidth(co, ct, strlen(text) + i); } ctDraw(co); diff -ruN newt-0.51.0/dialogboxes.c newt-0.50.39/dialogboxes.c --- newt-0.51.0/dialogboxes.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/dialogboxes.c Tue Jan 23 15:27:38 2001 @@ -8,7 +8,6 @@ #include "dialogboxes.h" #include "newt.h" -#include "newt_pr.h" #include "popt.h" /* globals -- ick */ @@ -194,10 +193,10 @@ } else itemInfo[numItems].text = ""; - if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth) - maxTextWidth = wstrlen(itemInfo[numItems].text,-1); - if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth) - maxTagWidth = wstrlen(itemInfo[numItems].tag,-1); + if (strlen(itemInfo[numItems].text) > (unsigned int)maxTextWidth) + maxTextWidth = strlen(itemInfo[numItems].text); + if (strlen(itemInfo[numItems].tag) > (unsigned int)maxTagWidth) + maxTagWidth = strlen(itemInfo[numItems].tag); numItems++; } @@ -288,8 +287,8 @@ else cbStates[numBoxes] = ' '; - if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth) - maxWidth = wstrlen(cbInfo[numBoxes].tag,-1); + if (strlen(cbInfo[numBoxes].tag) > (unsigned int)maxWidth) + maxWidth = strlen(cbInfo[numBoxes].tag); numBoxes++; } diff -ruN newt-0.51.0/entry.c newt-0.50.39/entry.c --- newt-0.51.0/entry.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/entry.c Tue Jun 11 22:11:11 2002 @@ -90,8 +90,8 @@ else co->takesFocus = 0; - if (initialValue && wstrlen(initialValue,-1) > (unsigned int)width) { - en->bufAlloced = wstrlen(initialValue,-1) + 1; + if (initialValue && strlen(initialValue) > (unsigned int)width) { + en->bufAlloced = strlen(initialValue) + 1; } en->buf = malloc(en->bufAlloced); en->resultPtr = resultPtr; diff -ruN newt-0.51.0/grid.c newt-0.50.39/grid.c --- newt-0.51.0/grid.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/grid.c Tue Jun 11 22:11:11 2002 @@ -245,13 +245,12 @@ } void newtGridWrappedWindow(newtGrid grid, char * title) { - int w, width, height, offset = 0; + int width, height, offset = 0; newtGridGetSize(grid, &width, &height); - w = wstrlen(title,-1); - if (width < w + 2) { - offset = ((w + 2) - width) / 2; - width = w + 2; + if (width < strlen(title) + 2) { + offset = ((strlen(title) + 2) - width) / 2; + width = strlen(title) + 2; } newtCenteredWindow(width + 2, height + 2, title); newtGridPlace(grid, 1 + offset, 1); diff -ruN newt-0.51.0/label.c newt-0.50.39/label.c --- newt-0.51.0/label.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/label.c Tue Jan 23 15:27:38 2001 @@ -32,7 +32,7 @@ co->ops = &labelOps; co->height = 1; - co->width = wstrlen(text, -1); + co->width = strlen(text); co->top = top; co->left = left; co->takesFocus = 0; @@ -55,7 +55,7 @@ free(la->text); la->text = strdup(text); la->length = newLength; - co->width = wstrlen(text,-1); + co->width = newLength; } labelDraw(co); diff -ruN newt-0.51.0/listbox.c newt-0.50.39/listbox.c --- newt-0.51.0/listbox.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/listbox.c Tue Jun 11 21:35:25 2002 @@ -297,8 +297,8 @@ free(item->text); item->text = strdup(text); } - if (li->userHasSetWidth == 0 && wstrlen(text,-1) > li->curWidth) { - updateWidth(co, li, wstrlen(text,-1)); + if (li->userHasSetWidth == 0 && strlen(text) > li->curWidth) { + updateWidth(co, li, strlen(text)); } if (num >= li->startShowItem && num <= li->startShowItem + co->height) @@ -329,8 +329,8 @@ item = li->boxItems = malloc(sizeof(struct items)); } - if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth)) - updateWidth(co, li, wstrlen(text,-1)); + if (!li->userHasSetWidth && text && (strlen(text) > li->curWidth)) + updateWidth(co, li, strlen(text)); item->text = strdup(text); item->data = data; item->next = NULL; item->isSelected = 0; @@ -369,8 +369,8 @@ item->next = NULL; } - if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth)) - updateWidth(co, li, wstrlen(text,-1)); + if (!li->userHasSetWidth && text && (strlen(text) > li->curWidth)) + updateWidth(co, li, strlen(text)); item->text = strdup(text?text:"(null)"); item->data = data; item->isSelected = 0; @@ -417,7 +417,7 @@ if (!li->userHasSetWidth) { widest = 0; for (item = li->boxItems; item != NULL; item = item->next) - if ((t = wstrlen(item->text,-1)) > widest) widest = t; + if ((t = strlen(item->text)) > widest) widest = t; } if (li->currItem >= num) diff -ruN newt-0.51.0/newt.c newt-0.50.39/newt.c --- newt-0.51.0/newt.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/newt.c Tue Jun 25 13:40:41 2002 @@ -9,7 +9,6 @@ #include #include #include -#include #ifdef HAVE_ALLOCA_H #include @@ -146,29 +145,6 @@ return -1; } -int wstrlen(const char *str, int len) { - mbstate_t ps; - wchar_t tmp; - int nchars = 0; - - if (!str) return 0; - if (!len) return 0; - if (len < 0) len = strlen(str); - memset(&ps,0,sizeof(mbstate_t)); - while (len > 0) { - int x,y; - - x = mbrtowc(&tmp,str,len,&ps); - if (x >0) { - len -= x; - y = wcwidth(tmp); - if (y>0) - nchars+=y; - } else break; - } - return nchars; -} - void newtFlushInput(void) { while (SLang_input_pending(0)) { SLang_getkey(); @@ -453,7 +429,7 @@ SLsmg_draw_box(top - 1, left - 1, height + 2, width + 2); if (currentWindow->title) { - i = wstrlen(currentWindow->title,-1) + 4; + i = strlen(currentWindow->title) + 4; i = ((width - i) / 2) + left; SLsmg_gotorc(top - 1, i); SLsmg_set_char_set(1); diff -ruN newt-0.51.0/newt_pr.h newt-0.50.39/newt_pr.h --- newt-0.51.0/newt_pr.h Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/newt_pr.h Tue Apr 3 08:57:47 2001 @@ -80,6 +80,4 @@ struct eventResult newtDefaultEventHandler(newtComponent c, struct event ev); -int wstrlen(const char *str, int len); - #endif /* H_NEWT_PR */ diff -ruN newt-0.51.0/textbox.c newt-0.50.39/textbox.c --- newt-0.51.0/textbox.c Fri Aug 16 05:13:40 2002 +++ newt-0.50.39/textbox.c Tue Oct 30 10:18:29 2001 @@ -1,10 +1,7 @@ - #include #include #include #include -#include -#include #include "newt.h" #include "newt_pr.h" @@ -154,6 +147,8 @@ return buf; } +#define iseuckanji(c) (0xa1 <= (unsigned char)(c&0xff) && (unsigned char)(c&0xff) <= 0xfe) + static void doReflow(const char * text, char ** resultPtr, int width, int * badness, int * heightPtr) { char * result = NULL; @@ -161,79 +156,73 @@ int i; int howbad = 0; int height = 0; - wchar_t tmp; - mbstate_t ps; + int kanji = 0; if (resultPtr) { /* XXX I think this will work */ result = malloc(strlen(text) + (strlen(text) / width) + 2); *result = '\0'; } - - memset(&ps,0,sizeof(mbstate_t)); + while (*text) { + kanji = 0; end = strchr(text, '\n'); if (!end) end = text + strlen(text); while (*text && text <= end) { - int len; - - len = wstrlen(text, end - text); - if (len < width) { + if (end - text < width) { if (result) { strncat(result, text, end - text); strcat(result, "\n"); height++; } - if (len < (width / 2)) { -#ifdef DEBUG_WRAP - fprintf(stderr,"adding %d\n",((width / 2) - (len)) / 2); -#endif - howbad += ((width / 2) - (len)) / 2; - } + if (end - text < (width / 2)) + howbad += ((width / 2) - (end - text)) / 2; text = end; if (*text) text++; } else { - char *spcptr = NULL; - int spc =0,w2, x; - chptr = text; - w2 = 0; - for (i = 0; i < width - 1;) { - if ((x=mbrtowc(&tmp,chptr,end-chptr,&ps))<=0) - break; - if (spc && !iswspace(tmp)) - spc = 0; - else if (!spc && iswspace(tmp)) { - spc = 1; - spcptr = chptr; - w2 = i; - } - chptr += x; - x = wcwidth(tmp); - if (x>0) - i+=x; + kanji = 0; + for ( i = 0; i < width - 1; i++ ) { + if ( !iseuckanji(*chptr)) { + kanji = 0; + } else if ( kanji == 1 ) { + kanji = 2; + } else { + kanji = 1; + } + chptr++; + } + if (kanji == 0) { + while (chptr > text && !isspace(*chptr)) chptr--; + while (chptr > text && isspace(*chptr)) chptr--; + chptr++; } - howbad += width - w2 + 1; -#ifdef DEBUG_WRAP - fprintf(stderr,"adding %d\n",width - w2 + 1, chptr); -#endif - if (spcptr) chptr = spcptr; + + if (chptr-text == 1 && !isspace(*chptr)) + chptr = text + width - 1; + + if (chptr > text) + howbad += width - (chptr - text) + 1; if (result) { + if (kanji == 1) { + strncat(result, text, chptr - text + 1 ); + chptr++; + kanji = 0; + } else { strncat(result, text, chptr - text ); + } strcat(result, "\n"); height++; } - text = chptr; - while (1) { - if ((x=mbrtowc(&tmp,text,end-text,NULL))<=0) - break; - if (!iswspace(tmp)) break; - text += x; - } + if (isspace(*chptr)) + text = chptr + 1; + else + text = chptr; + while (isspace(*text)) text++; } } } @@ -241,9 +230,6 @@ if (badness) *badness = howbad; if (resultPtr) *resultPtr = result; if (heightPtr) *heightPtr = height; -#ifdef DEBUG_WRAP - fprintf(stderr, "width %d, badness %d, height %d\n",width, howbad, height); -#endif } char * newtReflowText(char * text, int width, int flexDown, int flexUp, @@ -325,12 +311,12 @@ static void addLine(newtComponent co, const char * s, int len) { struct textbox * tb = co->data; - while (wstrlen(s,len) > tb->textWidth) { - len--; - } - tb->lines[tb->numLines] = malloc(len + 1); + if (len > tb->textWidth) len = tb->textWidth; + + tb->lines[tb->numLines] = malloc(tb->textWidth + 1); + memset(tb->lines[tb->numLines], ' ', tb->textWidth); memcpy(tb->lines[tb->numLines], s, len); - tb->lines[tb->numLines++][len] = '\0'; + tb->lines[tb->numLines++][tb->textWidth] = '\0'; } static void textboxDraw(newtComponent c) {