par-1.52-i18n.4.patch - pkgsrc-localpatches - leot's pkgsrc LOCALPATCHES
 (HTM) hg clone https://bitbucket.org/iamleot/pkgsrc-localpatches
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       par-1.52-i18n.4.patch
       ---
            1 $NetBSD$
            2 
            3 Downloaded from:
            4 
            5  <http://sysmic.org/dl/par/par-1.52-i18n.4.patch>
            6 
            7 ...and only adjusted for the `---' and `+++' parts.
            8 
            9 diff -ur par-1.52.orig/buffer.c par-1.52-i18n.4/buffer.c
           10 --- buffer.c.orig       2001-03-09 00:51:11.000000000 +0100
           11 +++ buffer.c    2009-05-29 21:09:45.000000000 +0200
           12 @@ -1,9 +1,11 @@
           13 -/*********************/
           14 -/* buffer.c          */
           15 -/* for Par 1.52      */
           16 -/* Copyright 2001 by */
           17 -/* Adam M. Costello  */
           18 -/*********************/
           19 +/***********************/
           20 +/* buffer.c            */
           21 +/* for Par 1.52-i18n.4 */
           22 +/* Copyright 2001 by   */
           23 +/* Adam M. Costello    */
           24 +/* Modified by         */
           25 +/* Jérôme Pouiller     */
           26 +/***********************/
           27  
           28  /* This is ANSI C code (C89). */
           29  
           30 @@ -18,6 +20,7 @@
           31  
           32  #include <stdlib.h>
           33  #include <string.h>
           34 +#include <wchar.h>
           35  
           36  #undef NULL
           37  #define NULL ((void *) 0)
           38 @@ -60,7 +63,7 @@
           39    blk = malloc(sizeof (block));
           40    items = malloc(maxhere * itemsize);
           41    if (!buf || !blk || !items) {
           42 -    strcpy(errmsg,outofmem);
           43 +    wcscpy(errmsg,outofmem);
           44      goto nberror;
           45    }
           46  
           47 @@ -127,7 +130,7 @@
           48        new = malloc(sizeof (block));
           49        items = malloc(maxhere * itemsize);
           50        if (!new || !items) {
           51 -        strcpy(errmsg,outofmem);
           52 +        wcscpy(errmsg,outofmem);
           53          goto aierror;
           54        }
           55        blk->next = new;
           56 @@ -174,7 +177,7 @@
           57  
           58    r = malloc(n * itemsize);
           59    if (!r) {
           60 -    strcpy(errmsg,outofmem);
           61 +    wcscpy(errmsg,outofmem);
           62      return NULL;
           63    }
           64  
           65 diff -ur par-1.52.orig/buffer.h par-1.52-i18n.4/buffer.h
           66 --- buffer.h.orig       2001-03-09 00:51:25.000000000 +0100
           67 +++ buffer.h    2009-05-29 21:12:39.000000000 +0200
           68 @@ -1,9 +1,11 @@
           69 -/*********************/
           70 -/* buffer.h          */
           71 -/* for Par 1.52      */
           72 -/* Copyright 2001 by */
           73 -/* Adam M. Costello  */
           74 -/*********************/
           75 +/***********************/
           76 +/* buffer.h            */
           77 +/* for Par 1.52-i18n.4 */
           78 +/* Copyright 2001 by   */
           79 +/* Adam M. Costello    */
           80 +/* Modified by         */
           81 +/* Jérôme Pouiller     */
           82 +/***********************/
           83  
           84  /* This is ANSI C code (C89). */
           85  
           86 diff -ur par-1.52.orig/charset.c par-1.52-i18n.4/charset.c
           87 --- charset.c.orig      2001-04-02 23:51:48.000000000 +0200
           88 +++ charset.c   2009-05-29 21:09:23.000000000 +0200
           89 @@ -1,9 +1,11 @@
           90 -/*********************/
           91 -/* charset.c         */
           92 -/* for Par 1.52      */
           93 -/* Copyright 2001 by */
           94 -/* Adam M. Costello  */
           95 -/*********************/
           96 +/***********************/
           97 +/* charset.c           */
           98 +/* for Par 1.52-i18n.4 */
           99 +/* Copyright 2001 by   */
          100 +/* Adam M. Costello    */
          101 +/* Modified by         */
          102 +/* Jérôme Pouiller     */
          103 +/***********************/
          104  
          105  /* This is ANSI C code (C89). */
          106  
          107 @@ -18,8 +20,9 @@
          108                        /* prototypes.  Also includes "errmsg.h". */
          109  #include "buffer.h"   /* Also includes <stddef.h>.              */
          110  
          111 -#include <ctype.h>
          112  #include <stdio.h>
          113 +#include <wchar.h>
          114 +#include <wctype.h>
          115  #include <stdlib.h>
          116  #include <string.h>
          117  
          118 @@ -39,8 +42,8 @@
          119  typedef unsigned char csflag_t;
          120  
          121  struct charset {
          122 -  char *inlist;    /* Characters in inlist are in the set.                */
          123 -  char *outlist;   /* Characters in outlist are not in the set.           */
          124 +  wchar_t *inlist;    /* Characters in inlist are in the set.                */
          125 +  wchar_t *outlist;   /* Characters in outlist are not in the set.           */
          126                     /* inlist and outlist must have no common characters.  */
          127                     /* inlist and outlist may be NULL, which acts like "". */
          128    csflag_t flags;  /* Characters in neither list are in the set if they   */
          129 @@ -56,25 +59,25 @@
          130                        CS_NUL   = 8;  /* Includes the NUL character.      */
          131  
          132  
          133 -static int appearsin(char c, const char *str)
          134 +static int appearsin(wchar_t c, const wchar_t *str)
          135  
          136  /* Returns 0 if c is '\0' or str is NULL or c     */
          137  /* does not appear in *str.  Otherwise returns 1. */
          138  {
          139 -  return c && str && strchr(str,c);
          140 +  return c && str && wcschr(str,c);
          141  }
          142  
          143  
          144 -static int hexdigtoint(char c)
          145 +static int hexdigtoint(wchar_t c)
          146  
          147  /* Returns the value represented by the hexadecimal */
          148  /* digit c, or -1 if c is not a hexadecimal digit.  */
          149  {
          150 -  const char *p, * const hexdigits = "0123456789ABCDEFabcdef";
          151 +  const wchar_t *p, * const hexdigits = L"0123456789ABCDEFabcdef";
          152    int n;
          153  
          154    if (!c) return -1;
          155 -  p = strchr(hexdigits, *(unsigned char *)&c);
          156 +  p = wcschr(hexdigits, c);
          157    if (!p) return -1;
          158    n = p - hexdigits;
          159    if (n >= 16) n -= 6;
          160 @@ -87,39 +90,40 @@
          161  }
          162  
          163  
          164 -charset *parsecharset(const char *str, errmsg_t errmsg)
          165 +charset *parsecharset(const wchar_t *str, errmsg_t errmsg)
          166  {
          167    charset *cset = NULL;
          168    buffer *cbuf = NULL;
          169 -  const char *p, * const singleescapes = "_sbqQx";
          170 +  const wchar_t *p, * const singleescapes = L"_sbqQx";
          171    int hex1, hex2;
          172 -  char ch;
          173 -
          174 +  wchar_t ch;
          175 +      
          176    cset = malloc(sizeof (charset));
          177    if (!cset) {
          178 -    strcpy(errmsg,outofmem);
          179 +    wcscpy(errmsg,outofmem);
          180      goto pcserror;
          181    }
          182    cset->inlist = cset->outlist = NULL;
          183    cset->flags = 0;
          184  
          185 -  cbuf = newbuffer(sizeof (char), errmsg);
          186 +  cbuf = newbuffer(sizeof (wchar_t), errmsg);
          187    if (*errmsg) goto pcserror;
          188  
          189    for (p = str;  *p;  ++p)
          190 -    if (*p == '_') {
          191 +    if (*p == L'_') {
          192        ++p;
          193        if (appearsin(*p, singleescapes)) {
          194 -        if      (*p == '_') ch = '_' ;
          195 -        else if (*p == 's') ch = ' ' ;
          196 -        else if (*p == 'b') ch = '\\';
          197 -        else if (*p == 'q') ch = '\'';
          198 -        else if (*p == 'Q') ch = '\"';
          199 +        if      (*p == L'_') ch = L'_' ;
          200 +        else if (*p == L's') ch = L' ' ;
          201 +        else if (*p == L'b') ch = L'\\';
          202 +        else if (*p == L'q') ch = L'\'';
          203 +        else if (*p == L'Q') ch = L'\"';
          204          else /*  *p == 'x'  */ {
          205 +          /* FIXME _x metacharacter should allow wide characters input.*/
          206            hex1 = hexdigtoint(p[1]);
          207            hex2 = hexdigtoint(p[2]);
          208            if (hex1 < 0  ||  hex2 < 0) goto pcsbadstr;
          209 -          *(unsigned char *)&ch = 16 * hex1 + hex2;
          210 +          ch = 16 * hex1 + hex2;
          211            p += 2;
          212          }
          213          if (!ch)
          214 @@ -130,14 +134,14 @@
          215          }
          216        }
          217        else {
          218 -        if      (*p == 'A') cset->flags |= CS_UCASE;
          219 -        else if (*p == 'a') cset->flags |= CS_LCASE;
          220 -        else if (*p == '0') cset->flags |= CS_DIGIT;
          221 +        if      (*p == L'A') cset->flags |= CS_UCASE;
          222 +        else if (*p == L'a') cset->flags |= CS_LCASE;
          223 +        else if (*p == L'0') cset->flags |= CS_DIGIT;
          224          else goto pcsbadstr;
          225        }
          226      }
          227      else {
          228 -      additem(cbuf,p,errmsg);
          229 +      additem(cbuf, p,errmsg);
          230        if (*errmsg) goto pcserror;
          231      }
          232    ch = '\0';
          233 @@ -149,11 +153,12 @@
          234  pcscleanup:
          235  
          236    if (cbuf) freebuffer(cbuf);
          237 +  //if (wstr) free(wstr);
          238    return cset;
          239  
          240  pcsbadstr:
          241  
          242 -  sprintf(errmsg, "Bad charset syntax: %.*s\n", errmsg_size - 22, str);
          243 +  swprintf(errmsg, errmsg_size, L"Bad charset syntax: %.*s\n", errmsg_size - 22, str);
          244  
          245  pcserror:
          246  
          247 @@ -171,14 +176,14 @@
          248  }
          249  
          250  
          251 -int csmember(char c, const charset *cset)
          252 +int csmember(wchar_t c, const charset *cset)
          253  {
          254    return
          255      appearsin(c, cset->inlist) ||
          256      ( !appearsin(c, cset->outlist) &&
          257 -      ( (cset->flags & CS_LCASE && islower(*(unsigned char *)&c)) ||
          258 -        (cset->flags & CS_UCASE && isupper(*(unsigned char *)&c)) ||
          259 -        (cset->flags & CS_DIGIT && isdigit(*(unsigned char *)&c)) ||
          260 +        ( (cset->flags & CS_LCASE && iswlower(*(wint_t *)&c)) ||
          261 +          (cset->flags & CS_UCASE && iswupper(*(wint_t *)&c)) ||
          262 +          (cset->flags & CS_DIGIT && iswdigit(*(wint_t *)&c)) ||
          263          (cset->flags & CS_NUL   && !c                           )   ) );
          264  }
          265  
          266 @@ -191,16 +196,16 @@
          267  {
          268    charset *csu;
          269    buffer *inbuf = NULL, *outbuf = NULL;
          270 -  char *lists[4], **list, *p, nullchar = '\0';
          271 +  wchar_t *lists[4], **list, *p, nullchar = L'\0';
          272  
          273    csu = malloc(sizeof (charset));
          274    if (!csu) {
          275 -    strcpy(errmsg,outofmem);
          276 +    wcscpy(errmsg,outofmem);
          277      goto csuderror;
          278    }
          279 -  inbuf = newbuffer(sizeof (char), errmsg);
          280 +  inbuf = newbuffer(sizeof (wchar_t), errmsg);
          281    if (*errmsg) goto csuderror;
          282 -  outbuf = newbuffer(sizeof (char), errmsg);
          283 +  outbuf = newbuffer(sizeof (wchar_t), errmsg);
          284    if (*errmsg) goto csuderror;
          285    csu->inlist = csu->outlist = NULL;
          286    csu->flags =  u  ?  cset1->flags |  cset2->flags
          287 diff -ur par-1.52.orig/charset.h par-1.52-i18n.4/charset.h
          288 --- charset.h.orig      2001-03-09 01:50:35.000000000 +0100
          289 +++ charset.h   2009-05-29 21:12:21.000000000 +0200
          290 @@ -1,9 +1,11 @@
          291 -/*********************/
          292 -/* charset.h         */
          293 -/* for Par 1.52      */
          294 -/* Copyright 2001 by */
          295 -/* Adam M. Costello  */
          296 -/*********************/
          297 +/***********************/
          298 +/* charset.h           */
          299 +/* for Par 1.52-i18n.4 */
          300 +/* Copyright 2001 by   */
          301 +/* Adam M. Costello    */
          302 +/* Modified by         */
          303 +/* Jérôme Pouiller     */
          304 +/***********************/
          305  
          306  /* This is ANSI C code (C89). */
          307  
          308 @@ -11,14 +13,14 @@
          309  /* Note: Those functions declared here which do not use errmsg    */
          310  /* always succeed, provided that they are passed valid arguments. */
          311  
          312 -
          313 +#include <wchar.h>
          314  #include "errmsg.h"
          315  
          316  
          317  typedef struct charset charset;
          318  
          319  
          320 -charset *parsecharset(const char *str, errmsg_t errmsg);
          321 +charset *parsecharset(const wchar_t *str, errmsg_t errmsg);
          322  
          323    /* parsecharset(str,errmsg) returns the set of characters defined by */
          324    /* str using charset syntax (see par.doc).  Returns NULL on failure. */
          325 @@ -30,7 +32,7 @@
          326    /* *cset.  cset may not be used after this call.      */
          327  
          328  
          329 -int csmember(char c, const charset *cset);
          330 +int csmember(wchar_t c, const charset *cset);
          331  
          332    /* csmember(c,cset) returns 1 if c is a member of *cset, 0 otherwise. */
          333  
          334 diff -ur par-1.52.orig/errmsg.c par-1.52-i18n.4/errmsg.c
          335 --- errmsg.c.orig       2001-03-09 01:50:46.000000000 +0100
          336 +++ errmsg.c    2009-05-29 21:11:43.000000000 +0200
          337 @@ -1,9 +1,11 @@
          338 -/*********************/
          339 -/* errmsg.c          */
          340 -/* for Par 1.52      */
          341 -/* Copyright 2001 by */
          342 -/* Adam M. Costello  */
          343 -/*********************/
          344 +/***********************/
          345 +/* errmsg.c            */
          346 +/* for Par 1.52-i18n.4 */
          347 +/* Copyright 2001 by   */
          348 +/* Adam M. Costello    */
          349 +/* Modified by         */
          350 +/* Jérôme Pouiller     */
          351 +/***********************/
          352  
          353  /* This is ANSI C code (C89). */
          354  
          355 @@ -11,8 +13,11 @@
          356  #include "errmsg.h"  /* Makes sure we're consistent with the declarations. */
          357  
          358  
          359 -const char * const outofmem =
          360 -  "Out of memory.\n";
          361 +const wchar_t * const outofmem =
          362 +  L"Out of memory.\n";
          363  
          364 -const char * const impossibility =
          365 -  "Impossibility #%d has occurred.  Please report it.\n";
          366 +const wchar_t * const mbserror =
          367 +  L"Error in input multibyte string.\n";
          368 +
          369 +const wchar_t * const impossibility =
          370 +  L"Impossibility #%d has occurred.  Please report it.\n";
          371 diff -ur par-1.52.orig/errmsg.h par-1.52-i18n.4/errmsg.h
          372 --- errmsg.h.orig       2001-03-09 01:50:56.000000000 +0100
          373 +++ errmsg.h    2009-05-29 21:12:10.000000000 +0200
          374 @@ -1,9 +1,11 @@
          375 -/*********************/
          376 -/* errmsg.h          */
          377 -/* for Par 1.52      */
          378 -/* Copyright 2001 by */
          379 -/* Adam M. Costello  */
          380 -/*********************/
          381 +/***********************/
          382 +/* errmsg.h            */
          383 +/* for Par 1.52-i18n.4 */
          384 +/* Copyright 2001 by   */
          385 +/* Adam M. Costello    */
          386 +/* Modified by         */
          387 +/* Jérôme Pouiller     */
          388 +/***********************/
          389  
          390  /* This is ANSI C code (C89). */
          391  
          392 @@ -11,7 +13,7 @@
          393  #ifndef ERRMSG_H
          394  #define ERRMSG_H
          395  
          396 -
          397 +#include <wchar.h>
          398  #define errmsg_size 163
          399  
          400  /* This is the maximum number of characters that will  */
          401 @@ -20,7 +22,7 @@
          402  /* versions of this header file.                       */
          403  
          404  
          405 -typedef char errmsg_t[errmsg_size];
          406 +typedef wchar_t errmsg_t[errmsg_size];
          407  
          408  /* Any function which takes the argument errmsg_t errmsg must, before */
          409  /* returning, either set errmsg[0] to '\0' (indicating success), or   */
          410 @@ -28,10 +30,13 @@
          411  /* being careful not to overrun the space.                            */
          412  
          413  
          414 -extern const char * const outofmem;
          415 +extern const wchar_t * const outofmem;
          416    /* "Out of memory.\n" */
          417  
          418 -extern const char * const impossibility;
          419 +extern const wchar_t * const mbserror;
          420 +  /* "Error in input multibyte string.\n" */
          421 +  
          422 +extern const wchar_t * const impossibility;
          423    /* "Impossibility #%d has occurred.  Please report it.\n" */
          424  
          425  
          426 diff -ur par-1.52.orig/par.1 par-1.52-i18n.4/par.1
          427 --- par.1.orig  2001-04-29 23:16:22.000000000 +0200
          428 +++ par.1       2009-05-06 14:54:22.000000000 +0200
          429 @@ -1,6 +1,6 @@
          430  .\"*********************
          431  .\"* par.1             *
          432 -.\"* for Par 1.52      *
          433 +.\"* for Par 1.52 i18n *
          434  .\"* Copyright 2001 by *
          435  .\"* Adam M. Costello  *
          436  .\"*********************
          437 diff -ur par-1.52.orig/par.c par-1.52-i18n.4/par.c
          438 --- par.c.orig  2001-04-02 06:25:57.000000000 +0200
          439 +++ par.c       2009-05-29 21:13:35.000000000 +0200
          440 @@ -1,9 +1,11 @@
          441 -/*********************/
          442 -/* par.c             */
          443 -/* for Par 1.52      */
          444 -/* Copyright 2001 by */
          445 -/* Adam M. Costello  */
          446 -/*********************/
          447 +/***********************/
          448 +/* par.c               */
          449 +/* for Par 1.52-i18n.4 */
          450 +/* Copyright 2001 by   */
          451 +/* Adam M. Costello    */
          452 +/* Modified by         */
          453 +/* Jérôme Pouiller     */
          454 +/***********************/
          455  
          456  /* This is ANSI C code (C89). */
          457  
          458 @@ -12,11 +14,14 @@
          459  #include "buffer.h"    /* Also includes <stddef.h>. */
          460  #include "reformat.h"
          461  
          462 -#include <ctype.h>
          463 +#include <langinfo.h>
          464 +#include <wchar.h>
          465 +#include <wctype.h>
          466  #include <locale.h>
          467  #include <stdio.h>
          468  #include <stdlib.h>
          469  #include <string.h>
          470 +#include <errno.h>
          471  
          472  #undef NULL
          473  #define NULL ((void *) 0)
          474 @@ -25,56 +30,6 @@
          475  #define free(ptr)
          476  #endif
          477  
          478 -
          479 -/*===
          480 -
          481 -Regarding char and unsigned char:  ANSI C is a nightmare in this
          482 -respect.  Some functions, like puts(), strchr(), and getenv(), use char
          483 -or char*, so they work well with character constants like 'a', which
          484 -are char, and with argv, which is char**.  But several other functions,
          485 -like getchar(), putchar(), and isdigit(), use unsigned char (converted
          486 -to/from int).  Therefore innocent-looking code can be wrong, for
          487 -example:
          488 -
          489 -    int c = getchar();
          490 -    if (c == 'a') ...
          491 -
          492 -This is wrong because 'a' is char (converted to int) and could be
          493 -negative, but getchar() returns unsigned char (converted to int), so c
          494 -is always nonnegative or EOF.  For similar reasons, it is wrong to pass
          495 -a char to a function that expects an unsigned char:
          496 -
          497 -    putchar('\n');
          498 -    if (isdigit(argv[1][0])) ...
          499 -
          500 -Inevitably, we need to convert between char and unsigned char.  This can
          501 -be done by integral conversion (casting or assigning a char to unsigned
          502 -char or vice versa), or by aliasing (converting a pointer to char to
          503 -a pointer to unsigned char (or vice versa) and then dereferencing
          504 -it).  ANSI C requires that integral conversion alters the bits when the
          505 -unsigned value is not representable in the signed type and the signed
          506 -type does not use two's complement representation.  Aliasing, on the
          507 -other hand, preserves the bits.  Although the C standard is not at all
          508 -clear about which sort of conversion is appropriate for making the
          509 -standard library functions interoperate, I think preserving the bits
          510 -is what is needed.  Under that assumption, here are some examples of
          511 -correct code:
          512 -
          513 -    int c = getchar();
          514 -    char ch;
          515 -
          516 -    if (c != EOF) {
          517 -      *(unsigned char *)&ch = c;
          518 -      if (ch == 'a') ...
          519 -      if (isdigit(c)) ...
          520 -    }
          521 -
          522 -    char *s = ...
          523 -    if (isdigit(*(unsigned char *)s)) ...
          524 -
          525 -===*/
          526 -
          527 -
          528  static const char * const usagemsg =
          529  "\n"
          530  "Options for par:\n"
          531 @@ -126,7 +81,7 @@
          532                    /* line, or the fallback prelen and suflen       */
          533                    /* of the IP containing a non-bodiless line.     */
          534    lflag_t flags;  /* Boolean properties (see below).               */
          535 -  char rc;        /* The repeated character of a bodiless line.    */
          536 +  wchar_t rc;     /* The repeated character of a bodiless line.    */
          537  } lineprop;
          538  
          539  /* Flags for marking boolean properties: */
          540 @@ -143,14 +98,14 @@
          541  #define   isvacant(prop) (isbodiless(prop) && (prop)->rc == ' ')
          542  
          543  
          544 -static int digtoint(char c)
          545 +static int digtoint(wchar_t c)
          546  
          547  /* Returns the value represented by the digit c, or -1 if c is not a digit. */
          548  {
          549 -  const char *p, * const digits = "0123456789";
          550 +  const wchar_t *p, * const digits = L"0123456789";
          551  
          552    if (!c) return -1;
          553 -  p = strchr(digits,c);
          554 +  p = wcschr(digits,c);
          555    return  p  ?  p - digits  :  -1;
          556  
          557    /* We can't simply return c - '0' because this is ANSI C code,  */
          558 @@ -161,7 +116,7 @@
          559  }
          560  
          561  
          562 -static int strtoudec(const char *s, int *pn)
          563 +static int strtoudec(const wchar_t *s, int *pn)
          564  
          565  /* Converts the longest prefix of string s consisting of decimal   */
          566  /* digits to an integer, which is stored in *pn.  Normally returns */
          567 @@ -187,7 +142,7 @@
          568  
          569  
          570  static void parsearg(
          571 -  const char *arg, int *phelp, int *pversion, charset *bodychars, charset
          572 +  const wchar_t *arg, int *phelp, int *pversion, charset *bodychars, charset
          573    *protectchars, charset *quotechars, int *phang, int *pprefix, int *prepeat,
          574    int *psuffix, int *pTab, int *pwidth, int *pbody, int *pcap, int *pdiv, int
          575    *pErr, int *pexpel, int *pfit, int *pguess, int *pinvis, int *pjust, int
          576 @@ -197,78 +152,78 @@
          577  /* by the other pointers as appropriate.  *phelp and *pversion are boolean  */
          578  /* flags indicating whether the help and version options were supplied.     */
          579  {
          580 -  const char *savearg = arg;
          581 +  const wchar_t *savearg = arg;
          582    charset *chars, *change;
          583 -  char oc;
          584 +  wchar_t oc;
          585    int n;
          586  
          587    *errmsg = '\0';
          588 +  
          589 +  if (*arg == L'-') ++arg;
          590  
          591 -  if (*arg == '-') ++arg;
          592 -
          593 -  if (!strcmp(arg, "help")) {
          594 +  if (!wcscmp(arg, L"help")) {
          595      *phelp = 1;
          596      return;
          597    }
          598  
          599 -  if (!strcmp(arg, "version")) {
          600 +  if (!wcscmp(arg, L"version")) {
          601      *pversion = 1;
          602      return;
          603    }
          604  
          605 -  if (*arg == 'B' || *arg == 'P' || *arg == 'Q' ) {
          606 -    chars =  *arg == 'B'  ?  bodychars    :
          607 -             *arg == 'P'  ?  protectchars :
          608 -          /* *arg == 'Q' */  quotechars   ;
          609 +  if (*arg == L'B' || *arg == L'P' || *arg == L'Q' ) {
          610 +    chars =  *arg == L'B'  ?  bodychars    :
          611 +             *arg == L'P'  ?  protectchars :
          612 +          /* *arg == L'Q' */  quotechars   ;
          613      ++arg;
          614 -    if (*arg != '='  &&  *arg != '+'  &&  *arg != '-') goto badarg;
          615 +    if (*arg != L'='  &&  *arg != L'+'  &&  *arg != L'-') goto badarg;
          616      change = parsecharset(arg + 1, errmsg);
          617      if (change) {
          618 -      if      (*arg == '=')   csswap(chars,change);
          619 -      else if (*arg == '+')   csadd(chars,change,errmsg);
          620 -      else  /* *arg == '-' */ csremove(chars,change,errmsg);
          621 +      if      (*arg == L'=')   csswap(chars,change);
          622 +      else if (*arg == L'+')   csadd(chars,change,errmsg);
          623 +      else  /* *arg == L'-' */ csremove(chars,change,errmsg);
          624        freecharset(change);
          625      }
          626      return;
          627    }
          628  
          629 -  if (isdigit(*(unsigned char *)arg)) {
          630 +  if (iswdigit(*arg)) {
          631      if (!strtoudec(arg, &n)) goto badarg;
          632      if (n <= 8) *pprefix = n;
          633      else *pwidth = n;
          634    }
          635  
          636    for (;;) {
          637 -    while (isdigit(*(unsigned char *)arg)) ++arg;
          638 +    while (iswdigit(*arg)) ++arg;
          639      oc = *arg;
          640      if (!oc) break;
          641      n = -1;
          642      if (!strtoudec(++arg, &n)) goto badarg;
          643 -    if (   oc == 'h' || oc == 'p' || oc == 'r'
          644 -        || oc == 's' || oc == 'T' || oc == 'w') {
          645 -      if      (oc == 'h')   *phang   =  n >= 0 ? n :  1;
          646 -      else if (oc == 'p')   *pprefix =  n;
          647 -      else if (oc == 'r')   *prepeat =  n >= 0 ? n :  3;
          648 -      else if (oc == 's')   *psuffix =  n;
          649 -      else if (oc == 'T')   *pTab    =  n >= 0 ? n :  8;
          650 -      else  /* oc == 'w' */ *pwidth  =  n >= 0 ? n : 79;
          651 +    if (   oc == L'h' || oc == L'p' || oc == L'r'
          652 +        || oc == L's' || oc == L'T' || oc == L'w') {
          653 +      if      (oc == L'h')   *phang   =  n >= 0 ? n :  1;
          654 +      else if (oc == L'p')   *pprefix =  n;
          655 +      else if (oc == L'r')   *prepeat =  n >= 0 ? n :  3;
          656 +      else if (oc == L's')   *psuffix =  n;
          657 +      else if (oc == L'T')   *pTab    =  n >= 0 ? n :  8;
          658 +      else  /* oc == L'w' */ *pwidth  =  n >= 0 ? n : 79;
          659      }
          660      else {
          661        if (n < 0) n = 1;
          662        if (n > 1) goto badarg;
          663 -      if      (oc == 'b') *pbody   = n;
          664 -      else if (oc == 'c') *pcap    = n;
          665 -      else if (oc == 'd') *pdiv    = n;
          666 -      else if (oc == 'E') *pErr    = n;
          667 -      else if (oc == 'e') *pexpel  = n;
          668 -      else if (oc == 'f') *pfit    = n;
          669 -      else if (oc == 'g') *pguess  = n;
          670 -      else if (oc == 'i') *pinvis  = n;
          671 -      else if (oc == 'j') *pjust   = n;
          672 -      else if (oc == 'l') *plast   = n;
          673 -      else if (oc == 'q') *pquote  = n;
          674 -      else if (oc == 'R') *pReport = n;
          675 -      else if (oc == 't') *ptouch  = n;
          676 +      if      (oc == L'b') *pbody   = n;
          677 +      else if (oc == L'c') *pcap    = n;
          678 +      else if (oc == L'd') *pdiv    = n;
          679 +      else if (oc == L'E') *pErr    = n;
          680 +      else if (oc == L'e') *pexpel  = n;
          681 +      else if (oc == L'f') *pfit    = n;
          682 +      else if (oc == L'g') *pguess  = n;
          683 +      else if (oc == L'i') *pinvis  = n;
          684 +      else if (oc == L'j') *pjust   = n;
          685 +      else if (oc == L'l') *plast   = n;
          686 +      else if (oc == L'q') *pquote  = n;
          687 +      else if (oc == L'R') *pReport = n;
          688 +      else if (oc == L't') *ptouch  = n;
          689        else goto badarg;
          690      }
          691    }
          692 @@ -277,12 +232,12 @@
          693  
          694  badarg:
          695  
          696 -  sprintf(errmsg, "Bad argument: %.*s\n", errmsg_size - 16, savearg);
          697 +  swprintf(errmsg, errmsg_size, L"Bad argument: %.*s\n", errmsg_size - 16, savearg);
          698    *phelp = 1;
          699  }
          700  
          701  
          702 -static char **readlines(
          703 +static wchar_t **readlines(
          704    lineprop **pprops, const charset *protectchars,
          705    const charset *quotechars, int Tab, int invis, int quote, errmsg_t errmsg
          706  )
          707 @@ -302,9 +257,10 @@
          708  /* it's not NULL.  On failure, returns NULL and sets *pprops to NULL.   */
          709  {
          710    buffer *cbuf = NULL, *lbuf = NULL, *lpbuf = NULL;
          711 -  int c, empty, blank, firstline, qsonly, oldqsonly = 0, vlnlen, i;
          712 -  char ch, *ln = NULL, nullchar = '\0', *nullline = NULL, *qpend,
          713 -       *oldln = NULL, *oldqpend = NULL, *p, *op, *vln = NULL, **lines = NULL;
          714 +  wint_t c;
          715 +  int empty, blank, firstline, qsonly, oldqsonly = 0, vlnlen, i;
          716 +  wchar_t *ln = NULL, nullchar = L'\0', *nullline = NULL, *qpend, 
          717 +    *oldln = NULL, *oldqpend = NULL, *p, *op, *vln = NULL, **lines = NULL;
          718    lineprop vprop = { 0, 0, 0, '\0' }, iprop = { 0, 0, 0, '\0' };
          719  
          720    /* oldqsonly, oldln, and oldquend don't really need to be initialized.   */
          721 @@ -316,20 +272,25 @@
          722  
          723    *pprops = NULL;
          724  
          725 -  cbuf = newbuffer(sizeof (char), errmsg);
          726 +  cbuf = newbuffer(sizeof (wchar_t), errmsg);
          727    if (*errmsg) goto rlcleanup;
          728 -  lbuf = newbuffer(sizeof (char *), errmsg);
          729 +  lbuf = newbuffer(sizeof (wchar_t *), errmsg);
          730    if (*errmsg) goto rlcleanup;
          731    lpbuf = newbuffer(sizeof (lineprop), errmsg);
          732    if (*errmsg) goto rlcleanup;
          733  
          734    for (empty = blank = firstline = 1;  ;  ) {
          735 -    c = getchar();
          736 -    if (c == EOF) break;
          737 -    *(unsigned char *)&ch = c;
          738 -    if (ch == '\n') {
          739 +    c = getwchar();
          740 +    if (c == WEOF) {
          741 +      if (errno == EILSEQ) {
          742 +       wcscpy(errmsg, L"Invalid multibyte sequence in input\n");
          743 +       goto rlcleanup;
          744 +      }
          745 +      break;
          746 +    }
          747 +    if (c == L'\n') {
          748        if (blank) {
          749 -        ungetc(c,stdin);
          750 +        ungetwc(c,stdin);
          751          break;
          752        }
          753        additem(cbuf, &nullchar, errmsg);
          754 @@ -338,9 +299,9 @@
          755        if (*errmsg) goto rlcleanup;
          756        if (quote) {
          757          for (qpend = ln;  *qpend && csmember(*qpend, quotechars);  ++qpend);
          758 -        for (p = qpend;  *p == ' ' || csmember(*p, quotechars);  ++p);
          759 -        qsonly =  *p == '\0';
          760 -        while (qpend > ln && qpend[-1] == ' ') --qpend;
          761 +        for (p = qpend;  *p == L' ' || csmember(*p, quotechars);  ++p);
          762 +        qsonly =  (*p == L'\0');
          763 +        while (qpend > ln && qpend[-1] == L' ') --qpend;
          764          if (!firstline) {
          765            for (p = ln, op = oldln;
          766                 p < qpend && op < oldqpend && *p == *op;
          767 @@ -348,23 +309,23 @@
          768            if (!(p == qpend && op == oldqpend)) {
          769              if (!invis && (oldqsonly || qsonly)) {
          770                if (oldqsonly) {
          771 -                *op = '\0';
          772 +                *op = L'\0';
          773                  oldqpend = op;
          774                }
          775                if (qsonly) {
          776 -                *p = '\0';
          777 +                *p = L'\0';
          778                  qpend = p;
          779                }
          780              }
          781              else {
          782                vlnlen = p - ln;
          783 -              vln = malloc((vlnlen + 1) * sizeof (char));
          784 +              vln = malloc((vlnlen + 1) * sizeof (wchar_t));
          785                if (!vln) {
          786 -                strcpy(errmsg,outofmem);
          787 +                wcscpy(errmsg,outofmem);
          788                  goto rlcleanup;
          789                }
          790 -              strncpy(vln,ln,vlnlen);
          791 -              vln[vlnlen] = '\0';
          792 +              wcsncpy(vln, ln, vlnlen);
          793 +              vln[vlnlen] = L'\0';
          794                additem(lbuf, &vln, errmsg);
          795                if (*errmsg) goto rlcleanup;
          796                additem(lpbuf,  invis ? &iprop : &vprop,  errmsg);
          797 @@ -388,28 +349,31 @@
          798      }
          799      else {
          800        if (empty) {
          801 -        if (csmember(ch, protectchars)) {
          802 -          ungetc(c,stdin);
          803 +        if (csmember(c, protectchars)) {
          804 +          ungetwc(c,stdin);
          805            break;
          806          }
          807          empty = 0;
          808        }
          809 -      if (!ch) continue;
          810 -      if (ch == '\t') {
          811 -        ch = ' ';
          812 +      if (!c) continue;
          813 +      if (c == L'\t') {
          814 +        c = L' ';
          815          for (i = Tab - numitems(cbuf) % Tab;  i > 0;  --i) {
          816 -          additem(cbuf, &ch, errmsg);
          817 +          additem(cbuf, &c, errmsg);
          818            if (*errmsg) goto rlcleanup;
          819          }
          820          continue;
          821        }
          822 -      if (isspace(c)) ch = ' ';
          823 -      else blank = 0;
          824 -      additem(cbuf, &ch, errmsg);
          825 -      if (*errmsg) goto rlcleanup;
          826 +      if (iswspace(c)) 
          827 +        c = L' ';
          828 +      else 
          829 +        blank = 0;
          830 +      additem(cbuf, &c, errmsg);
          831 +      if (*errmsg) 
          832 +        goto rlcleanup;
          833      }
          834    }
          835 -
          836 +  
          837    if (!blank) {
          838      additem(cbuf, &nullchar, errmsg);
          839      if (*errmsg) goto rlcleanup;
          840 @@ -449,7 +413,7 @@
          841  
          842  
          843  static void compresuflen(
          844 -  const char * const *lines, const char * const *endline,
          845 +  const wchar_t * const *lines, const wchar_t * const *endline,
          846    const charset *bodychars, int body, int pre, int suf, int *ppre, int *psuf
          847  )
          848  /* lines is an array of strings, up to but not including endline.  */
          849 @@ -457,9 +421,9 @@
          850  /* lines in lines.  Assumes that they have already been determined */
          851  /* to be at least pre and suf.  endline must not equal lines.      */
          852  {
          853 -  const char *start, *end, *knownstart, * const *line, *p1, *p2, *knownend,
          854 +  const wchar_t *start, *end, *knownstart, * const *line, *p1, *p2, *knownend,
          855               *knownstart2;
          856 -
          857 +           
          858    start = *lines;
          859    end = knownstart = start + pre;
          860    if (body)
          861 @@ -474,7 +438,7 @@
          862    }
          863    if (body)
          864      for (p1 = end;  p1 > knownstart;  )
          865 -      if (*--p1 != ' ') {
          866 +      if (*--p1 != L' ') {
          867          if (csmember(*p1, bodychars))
          868            end = p1;
          869          else
          870 @@ -501,18 +465,18 @@
          871    }
          872    if (body) {
          873      for (p1 = start;
          874 -         start < knownend && (*start == ' ' || csmember(*start, bodychars));
          875 +         start < knownend && (*start == L' ' || csmember(*start, bodychars));
          876           ++start);
          877 -    if (start > p1 && start[-1] == ' ') --start;
          878 +    if (start > p1 && start[-1] == L' ') --start;
          879    }
          880    else
          881 -    while (end - start >= 2 && *start == ' ' && start[1] == ' ') ++start;
          882 +    while (end - start >= 2 && *start == L' ' && start[1] == L' ') ++start;
          883    *psuf = end - start;
          884  }
          885  
          886  
          887  static void delimit(
          888 -  const char * const *lines, const char * const *endline,
          889 +  const wchar_t * const *lines, const wchar_t * const *endline,
          890    const charset *bodychars, int repeat, int body, int div,
          891    int pre, int suf, lineprop *props
          892  )
          893 @@ -523,8 +487,8 @@
          894  /* and comsuflen of the lines in lines have already been     */
          895  /* determined to be at least pre and suf, respectively.      */
          896  {
          897 -  const char * const *line, *end, *p, * const *nextline;
          898 -  char rc;
          899 +  const wchar_t * const *line, *end, *p, * const *nextline;
          900 +  wchar_t rc;
          901    lineprop *prop, *nextprop;
          902    int anybodiless = 0, status;
          903  
          904 @@ -545,8 +509,8 @@
          905      for (end = *line;  *end;  ++end);
          906      end -= suf;
          907      p = *line + pre;
          908 -    rc =  p < end  ?  *p  :  ' ';
          909 -    if (rc != ' ' && (!repeat || end - p < repeat))
          910 +    rc =  p < end  ?  *p  :  L' ';
          911 +    if (rc != L' ' && (!repeat || end - p < repeat))
          912        prop->flags &= ~L_BODILESS;
          913      else
          914        while (p < end) {
          915 @@ -589,9 +553,9 @@
          916    }
          917  
          918    line = lines, prop = props;
          919 -  status = ((*lines)[pre] == ' ');
          920 +  status = ((*lines)[pre] == L' ');
          921    do {
          922 -    if (((*line)[pre] == ' ') == status)
          923 +    if (((*line)[pre] == L' ') == status)
          924        prop->flags |= L_FIRST;
          925      ++line, ++prop;
          926    } while (line < endline);
          927 @@ -599,14 +563,14 @@
          928  
          929  
          930  static void marksuperf(
          931 -  const char * const * lines, const char * const * endline, lineprop *props
          932 +  const wchar_t * const * lines, const wchar_t * const * endline, lineprop *props
          933  )
          934  /* lines points to the first line of a segment, and endline to one  */
          935  /* line beyond the last line in the segment.  Sets L_SUPERF bits in */
          936  /* the flags fields of the props array whenever the corresponding   */
          937  /* line is superfluous.  L_BODILESS bits must already be set.       */
          938  {
          939 -  const char * const *line, *p;
          940 +  const wchar_t * const *line, *p;
          941    lineprop *prop, *mprop, dummy;
          942    int inbody, num, mnum;
          943  
          944 @@ -619,7 +583,7 @@
          945    for (line = lines, prop = props;  line < endline;  ++line, ++prop)
          946      if (isvacant(prop)) {
          947        for (num = 0, p = *line;  *p;  ++p)
          948 -        if (*p != ' ') ++num;
          949 +        if (*p != L' ') ++num;
          950        if (inbody || num < mnum)
          951          mnum = num, mprop = prop;
          952        inbody = 0;
          953 @@ -631,7 +595,7 @@
          954  
          955  
          956  static void setaffixes(
          957 -  const char * const *inlines, const char * const *endline,
          958 +  const wchar_t * const *inlines, const wchar_t * const *endline,
          959    const lineprop *props, const charset *bodychars,
          960    const charset *quotechars, int hang, int body, int quote,
          961    int *pafp, int *pfs, int *pprefix, int *psuffix
          962 @@ -644,7 +608,7 @@
          963  /* default value as specified in "par.doc".                            */
          964  {
          965    int numin, pre, suf;
          966 -  const char *p;
          967 +  const wchar_t *p;
          968  
          969    numin = endline - inlines;
          970  
          971 @@ -666,11 +630,11 @@
          972  }
          973  
          974  
          975 -static void freelines(char **lines)
          976 +static void freelines(wchar_t **lines)
          977  /* Frees the elements of lines, and lines itself. */
          978  /* lines is a NULL-terminated array of strings.   */
          979  {
          980 -  char **line;
          981 +  wchar_t **line;
          982  
          983    for (line = lines;  *line;  ++line)
          984      free(*line);
          985 @@ -678,68 +642,116 @@
          986    free(lines);
          987  }
          988  
          989 -
          990  int main(int argc, const char * const *argv)
          991  {
          992    int help = 0, version = 0, hang = 0, prefix = -1, repeat = 0, suffix = -1,
          993        Tab = 1, width = 72, body = 0, cap = 0, div = 0, Err = 0, expel = 0,
          994        fit = 0, guess = 0, invis = 0, just = 0, last = 0, quote = 0, Report = 0,
          995        touch = -1;
          996 -  int prefixbak, suffixbak, c, sawnonblank, oweblank, n, i, afp, fs;
          997 +  int prefixbak, suffixbak, sawnonblank, oweblank, n, i, afp, fs;
          998    charset *bodychars = NULL, *protectchars = NULL, *quotechars = NULL;
          999 -  char *parinit = NULL, *arg, **inlines = NULL, **endline, **firstline, *end,
         1000 -       **nextline, **outlines = NULL, **line, ch;
         1001 -  const char *env, * const whitechars = " \f\n\r\t\v";
         1002 +  wint_t c;
         1003 +  wchar_t *state;
         1004 +  wchar_t *parinit = NULL, *arg, **inlines = NULL, **endline, **firstline, *end,
         1005 +    **nextline, **outlines = NULL, **line;
         1006 +  const char *env;
         1007 +  wchar_t *wenv = NULL;
         1008 +  const wchar_t * const whitechars = L" \f\n\r\t\v";
         1009    errmsg_t errmsg = { '\0' };
         1010    lineprop *props = NULL, *firstprop, *nextprop;
         1011    FILE *errout;
         1012 +  char *langinfo;
         1013  
         1014  /* Set the current locale from the environment: */
         1015  
         1016    setlocale(LC_ALL,"");
         1017 +  langinfo = nl_langinfo(CODESET);
         1018 +  if (!strcmp(langinfo, "ANSI_X3.4-1968")) {
         1019 +    // We would like to fallback in an 8 bits encoding, but it is not easily possible.
         1020 +    //setlocale(LC_CTYPE, "C");
         1021 +    //langinfo = nl_langinfo(CODESET);
         1022 +    fwprintf( Err ? stderr : stdout, 
         1023 +        L"Warning: Locale seems not configured\n");
         1024 +  }
         1025  
         1026  /* Process environment variables: */
         1027  
         1028    env = getenv("PARBODY");
         1029    if (!env) env = "";
         1030 -  bodychars = parsecharset(env,errmsg);
         1031 +  wenv = malloc((strlen(env) + 1) * sizeof (wchar_t));
         1032 +  if (!wenv) {
         1033 +    wcscpy(errmsg,outofmem);
         1034 +    goto parcleanup;
         1035 +  }
         1036 +  if (0 > mbstowcs(wenv,env, strlen(env) + 1)) {
         1037 +    wcscpy(errmsg, L"Invalid multibyte sequence in PARBODY\n");
         1038 +    goto parcleanup;
         1039 +  }
         1040 +  bodychars = parsecharset(wenv,errmsg);
         1041    if (*errmsg) {
         1042      help = 1;
         1043      goto parcleanup;
         1044    }
         1045 +  free(wenv);
         1046 +  wenv = NULL;
         1047  
         1048    env = getenv("PARPROTECT");
         1049    if (!env) env = "";
         1050 -  protectchars = parsecharset(env,errmsg);
         1051 +  wenv = malloc((strlen(env) + 1) * sizeof (wchar_t));
         1052 +  if (!wenv) {
         1053 +    wcscpy(errmsg,outofmem);
         1054 +    goto parcleanup;
         1055 +  }
         1056 +  if (0 > mbstowcs(wenv,env, strlen(env) + 1)) {
         1057 +    wcscpy(errmsg, L"Invalid multibyte sequence in PARPROTECT\n");
         1058 +    goto parcleanup;
         1059 +  }
         1060 +  protectchars = parsecharset(wenv,errmsg);
         1061    if (*errmsg) {
         1062      help = 1;
         1063      goto parcleanup;
         1064    }
         1065 +  free(wenv);
         1066 +  wenv = NULL;
         1067  
         1068    env = getenv("PARQUOTE");
         1069    if (!env) env = "> ";
         1070 -  quotechars = parsecharset(env,errmsg);
         1071 +  wenv = malloc((strlen(env) + 1) * sizeof (wchar_t));
         1072 +  if (!wenv) {
         1073 +    wcscpy(errmsg,outofmem);
         1074 +    goto parcleanup;
         1075 +  }
         1076 +  if (0 > mbstowcs(wenv,env, strlen(env) + 1)) {
         1077 +    wcscpy(errmsg, L"Invalid multibyte sequence in PARQUOTE\n");
         1078 +    goto parcleanup;
         1079 +  }
         1080 +  quotechars = parsecharset(wenv,errmsg);
         1081    if (*errmsg) {
         1082      help = 1;
         1083      goto parcleanup;
         1084    }
         1085 +  free(wenv);
         1086 +  wenv = NULL;
         1087  
         1088    env = getenv("PARINIT");
         1089    if (env) {
         1090 -    parinit = malloc((strlen(env) + 1) * sizeof (char));
         1091 +    parinit = malloc((strlen(env) + 1) * sizeof (wchar_t));
         1092      if (!parinit) {
         1093 -      strcpy(errmsg,outofmem);
         1094 +      wcscpy(errmsg,outofmem);
         1095        goto parcleanup;
         1096      }
         1097 -    strcpy(parinit,env);
         1098 -    arg = strtok(parinit,whitechars);
         1099 +    if (0 > mbstowcs(parinit,env, strlen(env) + 1)) {
         1100 +      wcscpy(errmsg, L"Invalid multibyte sequence in PARINIT\n");
         1101 +      goto parcleanup;
         1102 +    }    
         1103 +    arg = wcstok(parinit, whitechars, &state);
         1104      while (arg) {
         1105        parsearg(arg, &help, &version, bodychars, protectchars,
         1106                 quotechars, &hang, &prefix, &repeat, &suffix, &Tab,
         1107                 &width, &body, &cap, &div, &Err, &expel, &fit, &guess,
         1108                 &invis, &just, &last, &quote, &Report, &touch, errmsg );
         1109        if (*errmsg || help || version) goto parcleanup;
         1110 -      arg = strtok(NULL,whitechars);
         1111 +      arg = wcstok(NULL, whitechars, &state);
         1112      }
         1113      free(parinit);
         1114      parinit = NULL;
         1115 @@ -748,57 +760,71 @@
         1116  /* Process command line arguments: */
         1117  
         1118    while (*++argv) {
         1119 -    parsearg(*argv, &help, &version, bodychars, protectchars,
         1120 +    arg = malloc((strlen(*argv) + 1) * sizeof (wchar_t));
         1121 +    if (0 > mbstowcs(arg, *argv, strlen(*argv) + 1)) {
         1122 +      wcscpy(errmsg, L"Invalid multibyte sequence in argument\n");
         1123 +      goto parcleanup;
         1124 +    }
         1125 +    parsearg(arg, &help, &version, bodychars, protectchars,
         1126               quotechars, &hang, &prefix, &repeat, &suffix, &Tab,
         1127               &width, &body, &cap, &div, &Err, &expel, &fit, &guess,
         1128               &invis, &just, &last, &quote, &Report, &touch, errmsg );
         1129 +    free(arg);
         1130      if (*errmsg || help || version) goto parcleanup;
         1131    }
         1132  
         1133    if (Tab == 0) {
         1134 -    strcpy(errmsg, "<Tab> must not be 0.\n");
         1135 +    wcscpy(errmsg, L"<Tab> must not be 0.\n");
         1136      goto parcleanup;
         1137    }
         1138  
         1139    if (touch < 0) touch = fit || last;
         1140    prefixbak = prefix;
         1141    suffixbak = suffix;
         1142 -
         1143 -/* Main loop: */
         1144 -
         1145 +  
         1146 +  /* Main loop: */
         1147    for (sawnonblank = oweblank = 0;  ;  ) {
         1148      for (;;) {
         1149 -      c = getchar();
         1150 -      if (c == EOF) break;
         1151 -      *(unsigned char *)&ch = c;
         1152 -      if (expel && ch == '\n') {
         1153 +      c = getwchar();
         1154 +      if (c == WEOF) {
         1155 +        if (errno == EILSEQ) {
         1156 +          wcscpy(errmsg, L"Invalid multibyte sequence in input\n");
         1157 +          goto parcleanup;
         1158 +        }
         1159 +        break;
         1160 +      }
         1161 +      if (expel && c == L'\n') {
         1162          oweblank = sawnonblank;
         1163          continue;
         1164        }
         1165 -      if (csmember(ch, protectchars)) {
         1166 +      if (csmember(c, protectchars)) {
         1167          sawnonblank = 1;
         1168          if (oweblank) {
         1169 -          puts("");
         1170 +          fputwc(L'\n', stdout);
         1171            oweblank = 0;
         1172          }
         1173 -        while (ch != '\n') {
         1174 -          putchar(c);
         1175 -          c = getchar();
         1176 -          if (c == EOF) break;
         1177 -          *(unsigned char *)&ch = c;
         1178 +        while (c != L'\n') {
         1179 +          putwchar(c);
         1180 +          c = getwchar();
         1181 +          if (c == WEOF) {
         1182 +            if (errno == EILSEQ) {
         1183 +              wcscpy(errmsg, L"Invalid multibyte sequence in input\n");
         1184 +              goto parcleanup;
         1185 +            }
         1186 +            break;
         1187 +          }
         1188          }
         1189        }
         1190 -      if (ch != '\n') break;  /* subsumes the case that c == EOF */
         1191 -      putchar(c);
         1192 +      if (c != L'\n') break;  /* subsumes the case that c == EOF */
         1193 +      putwchar(c);
         1194      }
         1195 -    if (c == EOF) break;
         1196 -    ungetc(c,stdin);
         1197 +    if (c == WEOF) break;
         1198 +    ungetwc(c,stdin);
         1199  
         1200      inlines =
         1201        readlines(&props, protectchars, quotechars, Tab, invis, quote, errmsg);
         1202      if (*errmsg) goto parcleanup;
         1203 -
         1204 -    for (endline = inlines;  *endline;  ++endline);
         1205 +    for (endline = inlines;  *endline;  ++endline) ;
         1206      if (endline == inlines) {
         1207        free(inlines);
         1208        inlines = NULL;
         1209 @@ -807,38 +833,39 @@
         1210  
         1211      sawnonblank = 1;
         1212      if (oweblank) {
         1213 -      puts("");
         1214 +      fputwc(L'\n', stdout);
         1215        oweblank = 0;
         1216      }
         1217  
         1218 -    delimit((const char * const *) inlines,
         1219 -            (const char * const *) endline,
         1220 +    delimit((const wchar_t * const *) inlines,
         1221 +            (const wchar_t * const *) endline,
         1222              bodychars, repeat, body, div, 0, 0, props);
         1223  
         1224      if (expel)
         1225 -      marksuperf((const char * const *) inlines,
         1226 -                 (const char * const *) endline, props);
         1227 +      marksuperf((const wchar_t * const *) inlines,
         1228 +                 (const wchar_t * const *) endline, props);
         1229  
         1230      firstline = inlines, firstprop = props;
         1231 +
         1232      do {
         1233        if (isbodiless(firstprop)) {
         1234          if (!isinvis(firstprop) && !(expel && issuperf(firstprop))) {
         1235            for (end = *firstline;  *end;  ++end);
         1236 -          if (!repeat || (firstprop->rc == ' ' && !firstprop->s)) {
         1237 -            while (end > *firstline && end[-1] == ' ') --end;
         1238 -            *end = '\0';
         1239 -            puts(*firstline);
         1240 +          if (!repeat || (firstprop->rc == L' ' && !firstprop->s)) {
         1241 +            while (end > *firstline && end[-1] == L' ') --end;
         1242 +            *end = L'\0';
         1243 +            fwprintf(stdout, L"%ls\n", *firstline);
         1244            }
         1245            else {
         1246              n = width - firstprop->p - firstprop->s;
         1247              if (n < 0) {
         1248 -              sprintf(errmsg,impossibility,5);
         1249 +              swprintf(errmsg,errmsg_size,impossibility,5);
         1250                goto parcleanup;
         1251              }
         1252 -            printf("%.*s", firstprop->p, *firstline);
         1253 +            fwprintf(stdout, L"%.*ls", firstprop->p, *firstline);
         1254              for (i = n;  i;  --i)
         1255 -              putchar(*(unsigned char *)&firstprop->rc);
         1256 -            puts(end - firstprop->s);
         1257 +              fputwc(firstprop->rc, stdout);
         1258 +            fwprintf(stdout, L"%ls\n", end - firstprop->s);
         1259            }
         1260          }
         1261          ++firstline, ++firstprop;
         1262 @@ -848,28 +875,26 @@
         1263        for (nextline = firstline + 1, nextprop = firstprop + 1;
         1264             nextline < endline && !isbodiless(nextprop) && !isfirst(nextprop);
         1265             ++nextline, ++nextprop);
         1266 -
         1267 +      
         1268        prefix = prefixbak, suffix = suffixbak;
         1269 -      setaffixes((const char * const *) firstline,
         1270 -                 (const char * const *) nextline, firstprop, bodychars,
         1271 +      setaffixes((const wchar_t * const *) firstline,
         1272 +                 (const wchar_t * const *) nextline, firstprop, bodychars,
         1273                   quotechars, hang, body, quote, &afp, &fs, &prefix, &suffix);
         1274        if (width <= prefix + suffix) {
         1275 -        sprintf(errmsg,
         1276 -                "<width> (%d) <= <prefix> (%d) + <suffix> (%d)\n",
         1277 +        swprintf(errmsg,errmsg_size,
         1278 +                L"<width> (%d) <= <prefix> (%d) + <suffix> (%d)\n",
         1279                  width, prefix, suffix);
         1280          goto parcleanup;
         1281        }
         1282  
         1283        outlines =
         1284 -        reformat((const char * const *) firstline,
         1285 -                 (const char * const *) nextline,
         1286 +        reformat((const wchar_t * const *) firstline,
         1287 +                 (const wchar_t * const *) nextline,
         1288                   afp, fs, hang, prefix, suffix, width, cap,
         1289                   fit, guess, just, last, Report, touch, errmsg);
         1290        if (*errmsg) goto parcleanup;
         1291 -
         1292        for (line = outlines;  *line;  ++line)
         1293 -        puts(*line);
         1294 -
         1295 +        fwprintf(stdout, L"%ls\n", *line);
         1296        freelines(outlines);
         1297        outlines = NULL;
         1298  
         1299 @@ -884,7 +909,7 @@
         1300    }
         1301  
         1302  parcleanup:
         1303 -
         1304 +  if (wenv) free(wenv);
         1305    if (bodychars) freecharset(bodychars);
         1306    if (protectchars) freecharset(protectchars);
         1307    if (quotechars) freecharset(quotechars);
         1308 @@ -892,10 +917,14 @@
         1309    if (inlines) freelines(inlines);
         1310    if (props) free(props);
         1311    if (outlines) freelines(outlines);
         1312  
         1313    errout = Err ? stderr : stdout;
         1314 -  if (*errmsg) fprintf(errout, "par error:\n%.*s", errmsg_size, errmsg);
         1315 -  if (version) fputs("par 1.52\n",errout);
         1316 +  if (*errmsg) fwprintf(errout, L"par error:\n%.*ls", errmsg_size, errmsg);
         1317 +#ifdef NOWIDTH
         1318 +  if (version) fputws(L"par 1.52-i18n.4 (without wcwidth() support)\n",errout);
         1319 +#else
         1320 +  if (version) fputws(L"par 1.52-i18n.4\n",errout);
         1321 +#endif
         1322    if (help)    fputs(usagemsg,errout);
         1323  
         1324    return *errmsg ? EXIT_FAILURE : EXIT_SUCCESS;
         1325 diff -ur par-1.52.orig/par.doc par-1.52-i18n.4/par.doc
         1326 --- par.doc.orig        2001-04-29 23:17:28.000000000 +0200
         1327 +++ par.doc     2009-05-06 14:54:22.000000000 +0200
         1328 @@ -1,6 +1,6 @@
         1329    *********************
         1330    * par.doc           *
         1331 -  * for Par 1.52      *
         1332 +  * for Par 1.52 i18n *
         1333    * Copyright 2001 by *
         1334    * Adam M. Costello  *
         1335    *********************
         1336 diff -ur par-1.52.orig/protoMakefile par-1.52-i18n.4/protoMakefile
         1337 --- protoMakefile.orig  2001-03-09 01:53:25.000000000 +0100
         1338 +++ protoMakefile       2009-05-06 18:00:20.000000000 +0200
         1339 @@ -47,7 +47,7 @@
         1340  # Example (for Solaris 2.x with SPARCompiler C):
         1341  # CC = cc -c -O -s -Xc -DDONTFREE
         1342  
         1343 -CC = cc -c
         1344 +CC = cc -std=c99 -c
         1345  
         1346  # Define LINK1 and LINK2 so that the command
         1347  #
         1348 diff -ur par-1.52.orig/reformat.c par-1.52-i18n.4/reformat.c
         1349 --- reformat.c.orig     2001-03-22 05:17:15.000000000 +0100
         1350 +++ reformat.c  2009-05-29 21:09:56.000000000 +0200
         1351 @@ -1,9 +1,11 @@
         1352 -/*********************/
         1353 -/* reformat.c        */
         1354 -/* for Par 1.52      */
         1355 -/* Copyright 2001 by */
         1356 -/* Adam M. Costello  */
         1357 -/*********************/
         1358 +/***********************/
         1359 +/* reformat.c          */
         1360 +/* for Par 1.52-i18n.4 */
         1361 +/* Copyright 2001 by   */
         1362 +/* Adam M. Costello    */
         1363 +/* Modified by         */
         1364 +/* Jérôme Pouiller     */
         1365 +/***********************/
         1366  
         1367  /* This is ANSI C code (C89). */
         1368  
         1369 @@ -16,6 +18,7 @@
         1370  #include <stdio.h>
         1371  #include <stdlib.h>
         1372  #include <string.h>
         1373 +#include <wctype.h>
         1374  
         1375  #undef NULL
         1376  #define NULL ((void *) 0)
         1377 @@ -33,14 +36,15 @@
         1378  typedef unsigned char wflag_t;
         1379  
         1380  typedef struct word {
         1381 -  const char *chrs;       /* Pointer to the characters in the word */
         1382 +  const wchar_t *chrs;    /* Pointer to the characters in the word */
         1383                            /* (NOT terminated by '\0').             */
         1384    struct word *prev,      /* Pointer to previous word.             */
         1385                *next,      /* Pointer to next word.                 */
         1386                            /* Supposing this word were the first... */
         1387                *nextline;  /*   Pointer to first word in next line. */
         1388    int score,              /*   Value of the objective function.    */
         1389 -      length;             /* Length of this word.                  */
         1390 +      length,             /* Length (in widechar) of this word.    */
         1391 +      width;              /* Visual width of this word.            */
         1392    wflag_t flags;          /* Notable properties of this word.      */
         1393  } word;
         1394  
         1395 @@ -57,17 +61,39 @@
         1396  #define iscurious(w) (((w)->flags & 2) != 0)
         1397  #define iscapital(w) (((w)->flags & 4) != 0)
         1398  
         1399 +static int getWidth(const wchar_t *beg, const wchar_t *end)
         1400 +/* Compute (visual) width of a  word. This function is aware */
         1401 +/* about double-width characters used in oriental langages.  */
         1402 +{
         1403 +  int ret, tmp;
         1404 +  
         1405 +  for (ret = 0; beg != end; beg++) {
         1406 +#ifdef NOWIDTH
         1407 +    tmp = 1;
         1408 +#else
         1409 +    tmp = wcwidth(*beg);
         1410 +#endif
         1411 +    // BUG: It is not really easy to handle case of zero width characters.
         1412 +    // If we don't do this, size mallloc for q1 will be less than real 
         1413 +    // size and program will segfault. So I prefer to have a bug than a segfault.
         1414 +    if (tmp <= 0)
         1415 +      tmp = 1;
         1416 +    ret += tmp;
         1417 +  }
         1418 +  
         1419 +  return ret;
         1420 +}
         1421  
         1422  static int checkcapital(word *w)
         1423  /* Returns 1 if *w is capitalized according to the definition */
         1424  /* in par.doc (assuming <cap> is 0), or 0 if not.             */
         1425  {
         1426 -  const char *p, *end;
         1427 +  const wchar_t *p, *end;
         1428  
         1429    for (p = w->chrs, end = p + w->length;
         1430 -       p < end && !isalnum(*(unsigned char *)p);
         1431 +       p < end && !iswalnum(*p);
         1432         ++p);
         1433 -  return p < end && !islower(*(unsigned char *)p);
         1434 +  return p < end && !iswlower(*p);
         1435  }
         1436  
         1437  
         1438 @@ -75,19 +101,19 @@
         1439  /* Returns 1 if *w is curious according to */
         1440  /* the definition in par.doc, or 0 if not. */
         1441  {
         1442 -  const char *start, *p;
         1443 -  char ch;
         1444 +  const wchar_t *start, *p;
         1445 +  wchar_t ch;
         1446  
         1447    for (start = w->chrs, p = start + w->length;  p > start;  --p) {
         1448      ch = p[-1];
         1449 -    if (isalnum(*(unsigned char *)&ch)) return 0;
         1450 -    if (ch == '.' || ch == '?' || ch == '!' || ch == ':') break;
         1451 +    if (iswalnum(*(wchar_t *)&ch)) return 0;
         1452 +    if (ch == L'.' || ch == L'?' || ch == L'!' || ch == L':') break;
         1453    }
         1454  
         1455    if (p <= start + 1) return 0;
         1456  
         1457    --p;
         1458 -  do if (isalnum(*(unsigned char *)--p)) return 1;
         1459 +  do if (iswalnum(*(wchar_t *)--p)) return 1;
         1460    while (p > start);
         1461  
         1462    return 0;
         1463 @@ -95,31 +121,32 @@
         1464  
         1465  
         1466  static int simplebreaks(word *head, word *tail, int L, int last)
         1467 -
         1468 -/* Chooses line breaks in a list of words which maximize the length of the   */
         1469 -/* shortest line.  L is the maximum line length.  The last line counts as a  */
         1470 -/* line only if last is non-zero. _head must point to a dummy word, and tail */
         1471 -/* must point to the last word, whose next field must be NULL.  Returns the  */
         1472 -/* length of the shortest line on success, -1 if there is a word of length   */
         1473 -/* greater than L, or L if there are no lines.                               */
         1474 +/* Chooses line  breaks in a  list of words  which maximize */
         1475 +/* the length of  the shortest line. L is  the maximum line */
         1476 +/* length. The last  line counts as a line only  if last is */
         1477 +/* non-zero. _head  must point  to a  dummy word,  and tail */
         1478 +/* must point  to the last  word, whose next field  must be */
         1479 +/* NULL.  Returns  the  length  of  the  shortest  line  on */
         1480 +/* success, -1 if there is a word of length greater than L, */
         1481 +/* or L if there are no lines.                              */
         1482  {
         1483    word *w1, *w2;
         1484    int linelen, score;
         1485  
         1486    if (!head->next) return L;
         1487  
         1488 -  for (w1 = tail, linelen = w1->length;
         1489 +  for (w1 = tail, linelen = w1->width;
         1490         w1 != head && linelen <= L;
         1491 -       linelen += isshifted(w1), w1 = w1->prev, linelen += 1 + w1->length) {
         1492 +       linelen += isshifted(w1), w1 = w1->prev, linelen += 1 + w1->width) {
         1493      w1->score = last ? linelen : L;
         1494      w1->nextline = NULL;
         1495    }
         1496  
         1497    for ( ;  w1 != head;  w1 = w1->prev) {
         1498      w1->score = -1;
         1499 -    for (linelen = w1->length,  w2 = w1->next;
         1500 +    for (linelen = w1->width,  w2 = w1->next;
         1501           linelen <= L;
         1502 -         linelen += 1 + isshifted(w2) + w2->length,  w2 = w2->next) {
         1503 +         linelen += 1 + isshifted(w2) + w2->width,  w2 = w2->next) {
         1504        score = w2->score;
         1505        if (linelen < score) score = linelen;
         1506        if (score >= w1->score) {
         1507 @@ -168,7 +195,7 @@
         1508  
         1509    shortest = simplebreaks(head,tail,target,last);
         1510    if (shortest < 0) {
         1511 -    sprintf(errmsg,impossibility,1);
         1512 +    swprintf(errmsg,errmsg_size,impossibility,1);
         1513      return;
         1514    }
         1515  
         1516 @@ -178,9 +205,9 @@
         1517    w1 = tail;
         1518    do {
         1519      w1->score = -1;
         1520 -    for (linelen = w1->length,  w2 = w1->next;
         1521 +    for (linelen = w1->width,  w2 = w1->next;
         1522           linelen <= target;
         1523 -         linelen += 1 + isshifted(w2) + w2->length,  w2 = w2->next) {
         1524 +         linelen += 1 + isshifted(w2) + w2->width,  w2 = w2->next) {
         1525        extra = target - linelen;
         1526        minlen = shortest;
         1527        if (w2)
         1528 @@ -202,7 +229,7 @@
         1529    } while (w1 != head);
         1530  
         1531    if (head->next->score < 0)
         1532 -    sprintf(errmsg,impossibility,2);
         1533 +    swprintf(errmsg,errmsg_size,impossibility,2);
         1534  }
         1535  
         1536  
         1537 @@ -225,9 +252,9 @@
         1538    w1 = tail;
         1539    do {
         1540      w1->score = L;
         1541 -    for (numgaps = 0, extra = L - w1->length, w2 = w1->next;
         1542 +    for (numgaps = 0, extra = L - w1->width, w2 = w1->next;
         1543           extra >= 0;
         1544 -         ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next) {
         1545 +         ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next) {
         1546        gap = numgaps ? (extra + numgaps - 1) / numgaps : L;
         1547        if (w2)
         1548          score = w2->score;
         1549 @@ -247,7 +274,7 @@
         1550  
         1551    maxgap = head->next->score;
         1552    if (maxgap >= L) {
         1553 -    strcpy(errmsg, "Cannot justify.\n");
         1554 +    wcscpy(errmsg, L"Cannot justify.\n");
         1555      return;
         1556    }
         1557  
         1558 @@ -257,9 +284,9 @@
         1559    w1 = tail;
         1560    do {
         1561      w1->score = -1;
         1562 -    for (numgaps = 0, extra = L - w1->length, w2 = w1->next;
         1563 +    for (numgaps = 0, extra = L - w1->width, w2 = w1->next;
         1564           extra >= 0;
         1565 -         ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next) {
         1566 +         ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next) {
         1567        gap = numgaps ? (extra + numgaps - 1) / numgaps : L;
         1568        if (w2)
         1569          score = w2->score;
         1570 @@ -288,40 +315,39 @@
         1571    } while (w1 != head);
         1572  
         1573    if (head->next->score < 0)
         1574 -    sprintf(errmsg,impossibility,3);
         1575 +    swprintf(errmsg,errmsg_size,impossibility,3);
         1576  }
         1577  
         1578  
         1579 -char **reformat(
         1580 -  const char * const *inlines, const char * const *endline, int afp, int fs,
         1581 +wchar_t **reformat(
         1582 +  const wchar_t * const *inlines, const wchar_t * const *endline, int afp, int fs,
         1583    int hang, int prefix, int suffix, int width, int cap, int fit, int guess,
         1584    int just, int last, int Report, int touch, errmsg_t errmsg
         1585  )
         1586  {
         1587    int numin, affix, L, onfirstword = 1, linelen, numout, numgaps, extra, phase;
         1588 -  const char * const *line, **suffixes = NULL, **suf, *end, *p1, *p2;
         1589 -  char *q1, *q2, **outlines = NULL;
         1590 +  const wchar_t * const *line, **suffixes = NULL, **suf, *end, *p1, *p2;
         1591 +  wchar_t *q1, *q2, **outlines = NULL;
         1592    word dummy, *head, *tail, *w1, *w2;
         1593    buffer *pbuf = NULL;
         1594  
         1595  /* Initialization: */
         1596 -
         1597    *errmsg = '\0';
         1598    dummy.next = dummy.prev = NULL;
         1599    dummy.flags = 0;
         1600    head = tail = &dummy;
         1601    numin = endline - inlines;
         1602    if (numin <= 0) {
         1603 -    sprintf(errmsg,impossibility,4);
         1604 +    swprintf(errmsg,errmsg_size,impossibility,4);
         1605      goto rfcleanup;
         1606    }
         1607    numgaps = extra = 0;  /* unnecessary, but quiets compiler warnings */
         1608  
         1609  /* Allocate space for pointers to the suffixes: */
         1610  
         1611 -  suffixes = malloc(numin * sizeof (const char *));
         1612 +  suffixes = malloc(numin * sizeof (const wchar_t *));
         1613    if (!suffixes) {
         1614 -    strcpy(errmsg,outofmem);
         1615 +    wcscpy(errmsg,outofmem);
         1616      goto rfcleanup;
         1617    }
         1618  
         1619 @@ -334,8 +360,8 @@
         1620    do {
         1621      for (end = *line;  *end;  ++end);
         1622      if (end - *line < affix) {
         1623 -      sprintf(errmsg,
         1624 -              "Line %d shorter than <prefix> + <suffix> = %d + %d = %d\n",
         1625 +      swprintf(errmsg,errmsg_size,
         1626 +              L"Line %d shorter than <prefix> + <suffix> = %d + %d = %d\n",
         1627                line - inlines + 1, prefix, suffix, affix);
         1628        goto rfcleanup;
         1629      }
         1630 @@ -343,17 +369,17 @@
         1631      *suf = end;
         1632      p1 = *line + prefix;
         1633      for (;;) {
         1634 -      while (p1 < end && *p1 == ' ') ++p1;
         1635 +      while (p1 < end && *p1 == L' ') ++p1;
         1636        if (p1 == end) break;
         1637        p2 = p1;
         1638        if (onfirstword) {
         1639          p1 = *line + prefix;
         1640          onfirstword = 0;
         1641        }
         1642 -      while (p2 < end && *p2 != ' ') ++p2;
         1643 +      while (p2 < end && *p2 != L' ') ++p2;
         1644        w1 = malloc(sizeof (word));
         1645        if (!w1) {
         1646 -        strcpy(errmsg,outofmem);
         1647 +        wcscpy(errmsg,outofmem);
         1648          goto rfcleanup;
         1649        }
         1650        w1->next = NULL;
         1651 @@ -361,6 +387,7 @@
         1652        tail = tail->next = w1;
         1653        w1->chrs = p1;
         1654        w1->length = p2 - p1;
         1655 +      w1->width = getWidth(p1, p2);
         1656        w1->flags = 0;
         1657        p1 = p2;
         1658      }
         1659 @@ -377,6 +404,7 @@
         1660          if (iscurious(w1)) {
         1661            if (w1->chrs[w1->length] && w1->chrs + w1->length + 1 == w2->chrs) {
         1662              w2->length += w1->length + 1;
         1663 +            w2->width += w1->width + 1;
         1664              w2->chrs = w1->chrs;
         1665              w2->prev = w1->prev;
         1666              w2->prev->next = w2;
         1667 @@ -397,20 +425,20 @@
         1668  
         1669    if (Report)
         1670      for (w2 = head->next;  w2;  w2 = w2->next) {
         1671 -      if (w2->length > L) {
         1672 -        linelen = w2->length;
         1673 +      if (w2->width > L) {
         1674 +        linelen = w2->width;
         1675          if (linelen > errmsg_size - 17)
         1676            linelen = errmsg_size - 17;
         1677 -        sprintf(errmsg, "Word too long: %.*s\n", linelen, w2->chrs);
         1678 +        swprintf(errmsg,errmsg_size, L"Word too long: %.*ls\n", linelen, w2->chrs);
         1679          goto rfcleanup;
         1680        }
         1681      }
         1682    else
         1683      for (w2 = head->next;  w2;  w2 = w2->next)
         1684 -      while (w2->length > L) {
         1685 +      while (w2->width > L) {
         1686          w1 = malloc(sizeof (word));
         1687          if (!w1) {
         1688 -          strcpy(errmsg,outofmem);
         1689 +          wcscpy(errmsg,outofmem);
         1690            goto rfcleanup;
         1691          }
         1692          w1->next = w2;
         1693 @@ -420,7 +448,9 @@
         1694          w1->chrs = w2->chrs;
         1695          w2->chrs += L;
         1696          w1->length = L;
         1697 +        w1->width = getWidth(w1->chrs, w1->chrs + L);
         1698          w2->length -= L;
         1699 +        w2->width -= w1->width;
         1700          w1->flags = 0;
         1701          if (iscapital(w2)) {
         1702            w1->flags |= W_CAPITAL;
         1703 @@ -444,9 +474,9 @@
         1704      L = 0;
         1705      w1 = head->next;
         1706      while (w1) {
         1707 -      for (linelen = w1->length, w2 = w1->next;
         1708 +      for (linelen = w1->width, w2 = w1->next;
         1709             w2 != w1->nextline;
         1710 -           linelen += 1 + isshifted(w2) + w2->length, w2 = w2->next);
         1711 +           linelen += 1 + isshifted(w2) + w2->width, w2 = w2->next);
         1712        if (linelen > L) L = linelen;
         1713        w1 = w2;
         1714      }
         1715 @@ -454,67 +484,67 @@
         1716  
         1717  /* Construct the lines: */
         1718  
         1719 -  pbuf = newbuffer(sizeof (char *), errmsg);
         1720 +  pbuf = newbuffer(sizeof (wchar_t *), errmsg);
         1721    if (*errmsg) goto rfcleanup;
         1722  
         1723    numout = 0;
         1724    w1 = head->next;
         1725    while (numout < hang || w1) {
         1726      if (w1)
         1727 -      for (w2 = w1->next, numgaps = 0, extra = L - w1->length;
         1728 +      for (w2 = w1->next, numgaps = 0, extra = L - w1->width;
         1729             w2 != w1->nextline;
         1730 -           ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next);
         1731 +           ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next);
         1732      linelen = suffix || (just && (w2 || last)) ?
         1733                  L + affix :
         1734                  w1 ? prefix + L - extra : prefix;
         1735 -    q1 = malloc((linelen + 1) * sizeof (char));
         1736 +    q1 = malloc((linelen + 1) * sizeof (wchar_t));
         1737      if (!q1) {
         1738 -      strcpy(errmsg,outofmem);
         1739 +      wcscpy(errmsg,outofmem);
         1740        goto rfcleanup;
         1741      }
         1742      additem(pbuf, &q1, errmsg);
         1743      if (*errmsg) goto rfcleanup;
         1744      ++numout;
         1745      q2 = q1 + prefix;
         1746 -    if      (numout <= numin) memcpy(q1, inlines[numout - 1], prefix);
         1747 -    else if (numin  >  hang ) memcpy(q1, endline[-1],         prefix);
         1748 +    if      (numout <= numin) memcpy(q1, inlines[numout - 1], prefix * sizeof(wchar_t));
         1749 +    else if (numin  >  hang ) memcpy(q1, endline[-1],         prefix * sizeof(wchar_t));
         1750      else {
         1751        if (afp > prefix) afp = prefix;
         1752 -      memcpy(q1, endline[-1], afp);
         1753 +      memcpy(q1, endline[-1], afp * sizeof(wchar_t));
         1754        q1 += afp;
         1755 -      while (q1 < q2) *q1++ = ' ';
         1756 +      while (q1 < q2) *q1++ = L' ';
         1757      }
         1758      q1 = q2;
         1759      if (w1) {
         1760        phase = numgaps / 2;
         1761        for (w2 = w1;  ;  ) {
         1762 -        memcpy(q1, w2->chrs, w2->length);
         1763 +        memcpy(q1, w2->chrs, w2->length * sizeof(wchar_t));
         1764          q1 += w2->length;
         1765          w2 = w2->next;
         1766          if (w2 == w1->nextline) break;
         1767 -        *q1++ = ' ';
         1768 +        *q1++ = L' ';
         1769          if (just && (w1->nextline || last)) {
         1770            phase += extra;
         1771            while (phase >= numgaps) {
         1772 -            *q1++ = ' ';
         1773 +            *q1++ = L' ';
         1774              phase -= numgaps;
         1775            }
         1776          }
         1777 -        if (isshifted(w2)) *q1++ = ' ';
         1778 +        if (isshifted(w2)) *q1++ = L' ';
         1779        }
         1780      }
         1781      q2 += linelen - affix;
         1782 -    while (q1 < q2) *q1++ = ' ';
         1783 +    while (q1 < q2) *q1++ = L' ';
         1784      q2 = q1 + suffix;
         1785 -    if      (numout <= numin) memcpy(q1, suffixes[numout - 1], suffix);
         1786 -    else if (numin  >  hang ) memcpy(q1, suffixes[numin  - 1], suffix);
         1787 +    if      (numout <= numin) memcpy(q1, suffixes[numout - 1], suffix * sizeof(wchar_t));
         1788 +    else if (numin  >  hang ) memcpy(q1, suffixes[numin  - 1], suffix * sizeof(wchar_t));
         1789      else {
         1790        if (fs > suffix) fs = suffix;
         1791 -      memcpy(q1, suffixes[numin - 1], fs);
         1792 +      memcpy(q1, suffixes[numin - 1], fs * sizeof(wchar_t));
         1793        q1 += fs;
         1794 -      while(q1 < q2) *q1++ = ' ';
         1795 +      while(q1 < q2) *q1++ = L' ';
         1796      }
         1797 -    *q2 = '\0';
         1798 +    *q2 = L'\0';
         1799      if (w1) w1 = w1->nextline;
         1800    }
         1801  
         1802 @@ -543,5 +573,6 @@
         1803      freebuffer(pbuf);
         1804    }
         1805  
         1806 +  
         1807    return outlines;
         1808  }
         1809 diff -ur par-1.52.orig/reformat.h par-1.52-i18n.4/reformat.h
         1810 --- reformat.h.orig     2001-03-09 01:53:43.000000000 +0100
         1811 +++ reformat.h  2009-05-29 21:12:57.000000000 +0200
         1812 @@ -1,18 +1,20 @@
         1813 -/*********************/
         1814 -/* reformat.h        */
         1815 -/* for Par 1.52      */
         1816 -/* Copyright 2001 by */
         1817 -/* Adam M. Costello  */
         1818 -/*********************/
         1819 +/***********************/
         1820 +/* reformat.h          */
         1821 +/* for Par 1.52-i18n.4 */
         1822 +/* Copyright 2001 by   */
         1823 +/* Adam M. Costello    */
         1824 +/* Modified by         */
         1825 +/* Jérôme Pouiller     */
         1826 +/***********************/
         1827  
         1828  /* This is ANSI C code (C89). */
         1829  
         1830  
         1831  #include "errmsg.h"
         1832 +#include <wchar.h>
         1833  
         1834 -
         1835 -char **reformat(
         1836 -  const char * const *inlines, const char * const *endline, int afp, int fs,
         1837 +wchar_t **reformat(
         1838 +  const wchar_t * const *inlines, const wchar_t * const *endline, int afp, int fs,
         1839    int hang, int prefix, int suffix, int width, int cap, int fit, int guess,
         1840    int just, int last, int Report, int touch, errmsg_t errmsg
         1841  );
         1842 diff -ur par-1.52.orig/releasenotes par-1.52-i18n.4/releasenotes
         1843 --- releasenotes.orig   2001-04-29 23:12:05.000000000 +0200
         1844 +++ releasenotes        2009-05-29 21:02:37.000000000 +0200
         1845 @@ -1,12 +1,28 @@
         1846 -  *********************
         1847 -  * releasenotes      *
         1848 -  * for Par 1.52      *
         1849 -  * Copyright 2001 by *
         1850 -  * Adam M. Costello  *
         1851 -  *********************
         1852 +  ***********************
         1853 +  * releasenotes        *
         1854 +  * for Par 1.52-i18n.4 *
         1855 +  * Copyright 2001 by   *
         1856 +  * Adam M. Costello    *
         1857 +  * Modified by         *
         1858 +  * Jérôme Pouiller     *
         1859 +  ***********************
         1860  
         1861  
         1862  Each entry below describes changes since the previous version.
         1863 +Par 1.52-i18n.4 released 2009-May-05
         1864 +    Change nearly all char in wchar_t remove nightmare of unsigned char vs signed char
         1865 +    Fix bugs with option 'q'
         1866 +    Fix bugs with '\n'
         1867 +
         1868 +Par 1.52-i18n.3 released 2006-Oct-03
         1869 +    Fix bug with option 'g'
         1870 +
         1871 +Par 1.52-i18n.2 released 2006-Aug-03
         1872 +    Fix bug debian #310495.
         1873 +
         1874 +Par 1.52-i18n.1 released 2006-Jun-22
         1875 +    Changed char in wchar_t. Allow support of multibytes characters.
         1876 +    Added support for double-width characters.
         1877  
         1878  Par 1.52 released 2001-Apr-29
         1879      Fixed a portability problem regarding unsigned char versus char.