| 1 | --- buffer.c.orig |
| 2 | +++ buffer.c |
| 3 | @@ -1,9 +1,9 @@ |
| 4 | -/*********************/ |
| 5 | -/* buffer.c */ |
| 6 | -/* for Par 1.52 */ |
| 7 | -/* Copyright 2001 by */ |
| 8 | -/* Adam M. Costello */ |
| 9 | -/*********************/ |
| 10 | +/***********************/ |
| 11 | +/* buffer.c */ |
| 12 | +/* for Par 1.52-i18n.3 */ |
| 13 | +/* Copyright 2001 by */ |
| 14 | +/* Adam M. Costello */ |
| 15 | +/***********************/ |
| 16 | |
| 17 | /* This is ANSI C code (C89). */ |
| 18 | |
| 19 | @@ -18,6 +18,7 @@ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | +#include <wchar.h> |
| 24 | |
| 25 | #undef NULL |
| 26 | #define NULL ((void *) 0) |
| 27 | @@ -60,7 +61,7 @@ |
| 28 | blk = malloc(sizeof (block)); |
| 29 | items = malloc(maxhere * itemsize); |
| 30 | if (!buf || !blk || !items) { |
| 31 | - strcpy(errmsg,outofmem); |
| 32 | + wcscpy(errmsg,outofmem); |
| 33 | goto nberror; |
| 34 | } |
| 35 | |
| 36 | @@ -127,7 +128,7 @@ |
| 37 | new = malloc(sizeof (block)); |
| 38 | items = malloc(maxhere * itemsize); |
| 39 | if (!new || !items) { |
| 40 | - strcpy(errmsg,outofmem); |
| 41 | + wcscpy(errmsg,outofmem); |
| 42 | goto aierror; |
| 43 | } |
| 44 | blk->next = new; |
| 45 | @@ -174,7 +175,7 @@ |
| 46 | |
| 47 | r = malloc(n * itemsize); |
| 48 | if (!r) { |
| 49 | - strcpy(errmsg,outofmem); |
| 50 | + wcscpy(errmsg,outofmem); |
| 51 | return NULL; |
| 52 | } |
| 53 | |
| 54 | --- buffer.h.orig |
| 55 | +++ buffer.h |
| 56 | @@ -1,9 +1,9 @@ |
| 57 | -/*********************/ |
| 58 | -/* buffer.h */ |
| 59 | -/* for Par 1.52 */ |
| 60 | -/* Copyright 2001 by */ |
| 61 | -/* Adam M. Costello */ |
| 62 | -/*********************/ |
| 63 | +/***********************/ |
| 64 | +/* buffer.h */ |
| 65 | +/* for Par 1.52-i18n.3 */ |
| 66 | +/* Copyright 2001 by */ |
| 67 | +/* Adam M. Costello */ |
| 68 | +/***********************/ |
| 69 | |
| 70 | /* This is ANSI C code (C89). */ |
| 71 | |
| 72 | --- charset.c.orig |
| 73 | +++ charset.c |
| 74 | @@ -1,9 +1,11 @@ |
| 75 | -/*********************/ |
| 76 | -/* charset.c */ |
| 77 | -/* for Par 1.52 */ |
| 78 | -/* Copyright 2001 by */ |
| 79 | -/* Adam M. Costello */ |
| 80 | -/*********************/ |
| 81 | +/***********************/ |
| 82 | +/* charset.c */ |
| 83 | +/* for Par 1.52-i18n.3 */ |
| 84 | +/* Copyright 2001 by */ |
| 85 | +/* Adam M. Costello */ |
| 86 | +/* Modified by */ |
| 87 | +/* Jérôme Pouiller */ |
| 88 | +/***********************/ |
| 89 | |
| 90 | /* This is ANSI C code (C89). */ |
| 91 | |
| 92 | @@ -22,6 +24,8 @@ |
| 93 | #include <stdio.h> |
| 94 | #include <stdlib.h> |
| 95 | #include <string.h> |
| 96 | +#include <wchar.h> |
| 97 | +#include <wctype.h> |
| 98 | |
| 99 | #undef NULL |
| 100 | #define NULL ((void *) 0) |
| 101 | @@ -39,8 +43,8 @@ |
| 102 | typedef unsigned char csflag_t; |
| 103 | |
| 104 | struct charset { |
| 105 | - char *inlist; /* Characters in inlist are in the set. */ |
| 106 | - char *outlist; /* Characters in outlist are not in the set. */ |
| 107 | + wchar_t *inlist; /* Characters in inlist are in the set. */ |
| 108 | + wchar_t *outlist; /* Characters in outlist are not in the set. */ |
| 109 | /* inlist and outlist must have no common characters. */ |
| 110 | /* inlist and outlist may be NULL, which acts like "". */ |
| 111 | csflag_t flags; /* Characters in neither list are in the set if they */ |
| 112 | @@ -56,25 +60,25 @@ |
| 113 | CS_NUL = 8; /* Includes the NUL character. */ |
| 114 | |
| 115 | |
| 116 | -static int appearsin(char c, const char *str) |
| 117 | +static int appearsin(wchar_t c, const wchar_t *str) |
| 118 | |
| 119 | /* Returns 0 if c is '\0' or str is NULL or c */ |
| 120 | /* does not appear in *str. Otherwise returns 1. */ |
| 121 | { |
| 122 | - return c && str && strchr(str,c); |
| 123 | + return c && str && wcschr(str,c); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | -static int hexdigtoint(char c) |
| 128 | +static int hexdigtoint(wchar_t c) |
| 129 | |
| 130 | /* Returns the value represented by the hexadecimal */ |
| 131 | /* digit c, or -1 if c is not a hexadecimal digit. */ |
| 132 | { |
| 133 | - const char *p, * const hexdigits = "0123456789ABCDEFabcdef"; |
| 134 | + const wchar_t *p, * const hexdigits = L"0123456789ABCDEFabcdef"; |
| 135 | int n; |
| 136 | |
| 137 | if (!c) return -1; |
| 138 | - p = strchr(hexdigits, *(unsigned char *)&c); |
| 139 | + p = wcschr(hexdigits, c); |
| 140 | if (!p) return -1; |
| 141 | n = p - hexdigits; |
| 142 | if (n >= 16) n -= 6; |
| 143 | @@ -91,35 +95,46 @@ |
| 144 | { |
| 145 | charset *cset = NULL; |
| 146 | buffer *cbuf = NULL; |
| 147 | - const char *p, * const singleescapes = "_sbqQx"; |
| 148 | + const wchar_t *p, * const singleescapes = L"_sbqQx"; |
| 149 | int hex1, hex2; |
| 150 | - char ch; |
| 151 | + wchar_t ch; |
| 152 | + wchar_t *wstr; |
| 153 | |
| 154 | + wstr = (wchar_t *) malloc((strlen(str) + 1) * sizeof(wchar_t)); |
| 155 | + if (!wstr) { |
| 156 | + wcscpy(errmsg,outofmem); |
| 157 | + goto pcserror; |
| 158 | + } |
| 159 | + if ((size_t)(-1) == mbstowcs(wstr, str, strlen(str) + 1)) { |
| 160 | + wcscpy(errmsg,mbserror); |
| 161 | + goto pcserror; |
| 162 | + } |
| 163 | cset = malloc(sizeof (charset)); |
| 164 | if (!cset) { |
| 165 | - strcpy(errmsg,outofmem); |
| 166 | + wcscpy(errmsg,outofmem); |
| 167 | goto pcserror; |
| 168 | } |
| 169 | cset->inlist = cset->outlist = NULL; |
| 170 | cset->flags = 0; |
| 171 | |
| 172 | - cbuf = newbuffer(sizeof (char), errmsg); |
| 173 | + cbuf = newbuffer(sizeof (wchar_t), errmsg); |
| 174 | if (*errmsg) goto pcserror; |
| 175 | |
| 176 | - for (p = str; *p; ++p) |
| 177 | - if (*p == '_') { |
| 178 | + for (p = wstr; *p; ++p) |
| 179 | + if (*p == L'_') { |
| 180 | ++p; |
| 181 | if (appearsin(*p, singleescapes)) { |
| 182 | - if (*p == '_') ch = '_' ; |
| 183 | - else if (*p == 's') ch = ' ' ; |
| 184 | - else if (*p == 'b') ch = '\\'; |
| 185 | - else if (*p == 'q') ch = '\''; |
| 186 | - else if (*p == 'Q') ch = '\"'; |
| 187 | + if (*p == L'_') ch = L'_' ; |
| 188 | + else if (*p == L's') ch = L' ' ; |
| 189 | + else if (*p == L'b') ch = L'\\'; |
| 190 | + else if (*p == L'q') ch = L'\''; |
| 191 | + else if (*p == L'Q') ch = L'\"'; |
| 192 | else /* *p == 'x' */ { |
| 193 | + /* FIXME _x metacharacter should allow wide characters input.*/ |
| 194 | hex1 = hexdigtoint(p[1]); |
| 195 | hex2 = hexdigtoint(p[2]); |
| 196 | if (hex1 < 0 || hex2 < 0) goto pcsbadstr; |
| 197 | - *(unsigned char *)&ch = 16 * hex1 + hex2; |
| 198 | + ch = 16 * hex1 + hex2; |
| 199 | p += 2; |
| 200 | } |
| 201 | if (!ch) |
| 202 | @@ -130,14 +145,14 @@ |
| 203 | } |
| 204 | } |
| 205 | else { |
| 206 | - if (*p == 'A') cset->flags |= CS_UCASE; |
| 207 | - else if (*p == 'a') cset->flags |= CS_LCASE; |
| 208 | - else if (*p == '0') cset->flags |= CS_DIGIT; |
| 209 | + if (*p == L'A') cset->flags |= CS_UCASE; |
| 210 | + else if (*p == L'a') cset->flags |= CS_LCASE; |
| 211 | + else if (*p == L'0') cset->flags |= CS_DIGIT; |
| 212 | else goto pcsbadstr; |
| 213 | } |
| 214 | } |
| 215 | else { |
| 216 | - additem(cbuf,p,errmsg); |
| 217 | + additem(cbuf, p,errmsg); |
| 218 | if (*errmsg) goto pcserror; |
| 219 | } |
| 220 | ch = '\0'; |
| 221 | @@ -149,11 +164,12 @@ |
| 222 | pcscleanup: |
| 223 | |
| 224 | if (cbuf) freebuffer(cbuf); |
| 225 | + if (wstr) free(wstr); |
| 226 | return cset; |
| 227 | |
| 228 | pcsbadstr: |
| 229 | |
| 230 | - sprintf(errmsg, "Bad charset syntax: %.*s\n", errmsg_size - 22, str); |
| 231 | + swprintf(errmsg, errmsg_size, L"Bad charset syntax: %.*s\n", errmsg_size - 22, str); |
| 232 | |
| 233 | pcserror: |
| 234 | |
| 235 | @@ -171,14 +187,14 @@ |
| 236 | } |
| 237 | |
| 238 | |
| 239 | -int csmember(char c, const charset *cset) |
| 240 | +int csmember(wchar_t c, const charset *cset) |
| 241 | { |
| 242 | return |
| 243 | appearsin(c, cset->inlist) || |
| 244 | ( !appearsin(c, cset->outlist) && |
| 245 | - ( (cset->flags & CS_LCASE && islower(*(unsigned char *)&c)) || |
| 246 | - (cset->flags & CS_UCASE && isupper(*(unsigned char *)&c)) || |
| 247 | - (cset->flags & CS_DIGIT && isdigit(*(unsigned char *)&c)) || |
| 248 | + ( (cset->flags & CS_LCASE && iswlower(*(wint_t *)&c)) || |
| 249 | + (cset->flags & CS_UCASE && iswupper(*(wint_t *)&c)) || |
| 250 | + (cset->flags & CS_DIGIT && iswdigit(*(wint_t *)&c)) || |
| 251 | (cset->flags & CS_NUL && !c ) ) ); |
| 252 | } |
| 253 | |
| 254 | @@ -191,16 +207,16 @@ |
| 255 | { |
| 256 | charset *csu; |
| 257 | buffer *inbuf = NULL, *outbuf = NULL; |
| 258 | - char *lists[4], **list, *p, nullchar = '\0'; |
| 259 | + wchar_t *lists[4], **list, *p, nullchar = L'\0'; |
| 260 | |
| 261 | csu = malloc(sizeof (charset)); |
| 262 | if (!csu) { |
| 263 | - strcpy(errmsg,outofmem); |
| 264 | + wcscpy(errmsg,outofmem); |
| 265 | goto csuderror; |
| 266 | } |
| 267 | - inbuf = newbuffer(sizeof (char), errmsg); |
| 268 | + inbuf = newbuffer(sizeof (wchar_t), errmsg); |
| 269 | if (*errmsg) goto csuderror; |
| 270 | - outbuf = newbuffer(sizeof (char), errmsg); |
| 271 | + outbuf = newbuffer(sizeof (wchar_t), errmsg); |
| 272 | if (*errmsg) goto csuderror; |
| 273 | csu->inlist = csu->outlist = NULL; |
| 274 | csu->flags = u ? cset1->flags | cset2->flags |
| 275 | --- charset.h.orig |
| 276 | +++ charset.h |
| 277 | @@ -1,9 +1,11 @@ |
| 278 | -/*********************/ |
| 279 | -/* charset.h */ |
| 280 | -/* for Par 1.52 */ |
| 281 | -/* Copyright 2001 by */ |
| 282 | -/* Adam M. Costello */ |
| 283 | -/*********************/ |
| 284 | +/***********************/ |
| 285 | +/* charset.h */ |
| 286 | +/* for Par 1.52-i18n.3 */ |
| 287 | +/* Copyright 2001 by */ |
| 288 | +/* Adam M. Costello */ |
| 289 | +/* Modified by */ |
| 290 | +/* Jérôme Pouiller */ |
| 291 | +/***********************/ |
| 292 | |
| 293 | /* This is ANSI C code (C89). */ |
| 294 | |
| 295 | @@ -11,7 +13,7 @@ |
| 296 | /* Note: Those functions declared here which do not use errmsg */ |
| 297 | /* always succeed, provided that they are passed valid arguments. */ |
| 298 | |
| 299 | - |
| 300 | +#include <wchar.h> |
| 301 | #include "errmsg.h" |
| 302 | |
| 303 | |
| 304 | @@ -30,7 +32,7 @@ |
| 305 | /* *cset. cset may not be used after this call. */ |
| 306 | |
| 307 | |
| 308 | -int csmember(char c, const charset *cset); |
| 309 | +int csmember(wchar_t c, const charset *cset); |
| 310 | |
| 311 | /* csmember(c,cset) returns 1 if c is a member of *cset, 0 otherwise. */ |
| 312 | |
| 313 | --- errmsg.c.orig |
| 314 | +++ errmsg.c |
| 315 | @@ -1,9 +1,11 @@ |
| 316 | -/*********************/ |
| 317 | -/* errmsg.c */ |
| 318 | -/* for Par 1.52 */ |
| 319 | -/* Copyright 2001 by */ |
| 320 | -/* Adam M. Costello */ |
| 321 | -/*********************/ |
| 322 | +/***********************/ |
| 323 | +/* errmsg.c */ |
| 324 | +/* for Par 1.52-i18n.3 */ |
| 325 | +/* Copyright 2001 by */ |
| 326 | +/* Adam M. Costello */ |
| 327 | +/* Modified by */ |
| 328 | +/* Jérôme Pouiller */ |
| 329 | +/***********************/ |
| 330 | |
| 331 | /* This is ANSI C code (C89). */ |
| 332 | |
| 333 | @@ -11,8 +13,11 @@ |
| 334 | #include "errmsg.h" /* Makes sure we're consistent with the declarations. */ |
| 335 | |
| 336 | |
| 337 | -const char * const outofmem = |
| 338 | - "Out of memory.\n"; |
| 339 | +const wchar_t * const outofmem = |
| 340 | + L"Out of memory.\n"; |
| 341 | |
| 342 | -const char * const impossibility = |
| 343 | - "Impossibility #%d has occurred. Please report it.\n"; |
| 344 | +const wchar_t * const mbserror = |
| 345 | + L"Error in input multibyte string.\n"; |
| 346 | + |
| 347 | +const wchar_t * const impossibility = |
| 348 | + L"Impossibility #%d has occurred. Please report it.\n"; |
| 349 | --- errmsg.h.orig |
| 350 | +++ errmsg.h |
| 351 | @@ -1,9 +1,11 @@ |
| 352 | -/*********************/ |
| 353 | -/* errmsg.h */ |
| 354 | -/* for Par 1.52 */ |
| 355 | -/* Copyright 2001 by */ |
| 356 | -/* Adam M. Costello */ |
| 357 | -/*********************/ |
| 358 | +/***********************/ |
| 359 | +/* errmsg.h */ |
| 360 | +/* for Par 1.52-i18n.3 */ |
| 361 | +/* Copyright 2001 by */ |
| 362 | +/* Adam M. Costello */ |
| 363 | +/* Modified by */ |
| 364 | +/* Jérôme Pouiller */ |
| 365 | +/***********************/ |
| 366 | |
| 367 | /* This is ANSI C code (C89). */ |
| 368 | |
| 369 | @@ -11,7 +13,7 @@ |
| 370 | #ifndef ERRMSG_H |
| 371 | #define ERRMSG_H |
| 372 | |
| 373 | - |
| 374 | +#include <wchar.h> |
| 375 | #define errmsg_size 163 |
| 376 | |
| 377 | /* This is the maximum number of characters that will */ |
| 378 | @@ -20,7 +22,7 @@ |
| 379 | /* versions of this header file. */ |
| 380 | |
| 381 | |
| 382 | -typedef char errmsg_t[errmsg_size]; |
| 383 | +typedef wchar_t errmsg_t[errmsg_size]; |
| 384 | |
| 385 | /* Any function which takes the argument errmsg_t errmsg must, before */ |
| 386 | /* returning, either set errmsg[0] to '\0' (indicating success), or */ |
| 387 | @@ -28,10 +30,13 @@ |
| 388 | /* being careful not to overrun the space. */ |
| 389 | |
| 390 | |
| 391 | -extern const char * const outofmem; |
| 392 | +extern const wchar_t * const outofmem; |
| 393 | /* "Out of memory.\n" */ |
| 394 | |
| 395 | -extern const char * const impossibility; |
| 396 | +extern const wchar_t * const mbserror; |
| 397 | + /* "Error in input multibyte string.\n" */ |
| 398 | + |
| 399 | +extern const wchar_t * const impossibility; |
| 400 | /* "Impossibility #%d has occurred. Please report it.\n" */ |
| 401 | |
| 402 | |
| 403 | --- par.1.orig |
| 404 | +++ par.1 |
| 405 | @@ -1,6 +1,6 @@ |
| 406 | .\"********************* |
| 407 | .\"* par.1 * |
| 408 | -.\"* for Par 1.52 * |
| 409 | +.\"* for Par 1.52 i18n * |
| 410 | .\"* Copyright 2001 by * |
| 411 | .\"* Adam M. Costello * |
| 412 | .\"********************* |
| 413 | --- par.c.orig |
| 414 | +++ par.c |
| 415 | @@ -1,9 +1,11 @@ |
| 416 | -/*********************/ |
| 417 | -/* par.c */ |
| 418 | -/* for Par 1.52 */ |
| 419 | -/* Copyright 2001 by */ |
| 420 | -/* Adam M. Costello */ |
| 421 | -/*********************/ |
| 422 | +/***********************/ |
| 423 | +/* par.c */ |
| 424 | +/* for Par 1.52-i18n.3 */ |
| 425 | +/* Copyright 2001 by */ |
| 426 | +/* Adam M. Costello */ |
| 427 | +/* Modified by */ |
| 428 | +/* Jérôme Pouiller */ |
| 429 | +/***********************/ |
| 430 | |
| 431 | /* This is ANSI C code (C89). */ |
| 432 | |
| 433 | @@ -17,6 +19,7 @@ |
| 434 | #include <stdio.h> |
| 435 | #include <stdlib.h> |
| 436 | #include <string.h> |
| 437 | +#include <wchar.h> |
| 438 | |
| 439 | #undef NULL |
| 440 | #define NULL ((void *) 0) |
| 441 | @@ -126,7 +129,7 @@ |
| 442 | /* line, or the fallback prelen and suflen */ |
| 443 | /* of the IP containing a non-bodiless line. */ |
| 444 | lflag_t flags; /* Boolean properties (see below). */ |
| 445 | - char rc; /* The repeated character of a bodiless line. */ |
| 446 | + wchar_t rc; /* The repeated character of a bodiless line. */ |
| 447 | } lineprop; |
| 448 | |
| 449 | /* Flags for marking boolean properties: */ |
| 450 | @@ -277,12 +280,12 @@ |
| 451 | |
| 452 | badarg: |
| 453 | |
| 454 | - sprintf(errmsg, "Bad argument: %.*s\n", errmsg_size - 16, savearg); |
| 455 | + swprintf(errmsg, errmsg_size,L"Bad argument: %.*s\n", errmsg_size - 16, savearg); |
| 456 | *phelp = 1; |
| 457 | } |
| 458 | |
| 459 | |
| 460 | -static char **readlines( |
| 461 | +static wchar_t **readlines( |
| 462 | lineprop **pprops, const charset *protectchars, |
| 463 | const charset *quotechars, int Tab, int invis, int quote, errmsg_t errmsg |
| 464 | ) |
| 465 | @@ -303,8 +306,10 @@ |
| 466 | { |
| 467 | buffer *cbuf = NULL, *lbuf = NULL, *lpbuf = NULL; |
| 468 | int c, empty, blank, firstline, qsonly, oldqsonly = 0, vlnlen, i; |
| 469 | - char ch, *ln = NULL, nullchar = '\0', *nullline = NULL, *qpend, |
| 470 | - *oldln = NULL, *oldqpend = NULL, *p, *op, *vln = NULL, **lines = NULL; |
| 471 | + char ch, *ln = NULL, *qpend, *oldln = NULL, |
| 472 | + *oldqpend = NULL, *p, *op; |
| 473 | + wchar_t nullchar = L'\0'; |
| 474 | + wchar_t *nullline = NULL, *vln = NULL, **lines = NULL; |
| 475 | lineprop vprop = { 0, 0, 0, '\0' }, iprop = { 0, 0, 0, '\0' }; |
| 476 | |
| 477 | /* oldqsonly, oldln, and oldquend don't really need to be initialized. */ |
| 478 | @@ -318,7 +323,7 @@ |
| 479 | |
| 480 | cbuf = newbuffer(sizeof (char), errmsg); |
| 481 | if (*errmsg) goto rlcleanup; |
| 482 | - lbuf = newbuffer(sizeof (char *), errmsg); |
| 483 | + lbuf = newbuffer(sizeof (wchar_t *), errmsg); |
| 484 | if (*errmsg) goto rlcleanup; |
| 485 | lpbuf = newbuffer(sizeof (lineprop), errmsg); |
| 486 | if (*errmsg) goto rlcleanup; |
| 487 | @@ -339,7 +344,7 @@ |
| 488 | if (quote) { |
| 489 | for (qpend = ln; *qpend && csmember(*qpend, quotechars); ++qpend); |
| 490 | for (p = qpend; *p == ' ' || csmember(*p, quotechars); ++p); |
| 491 | - qsonly = *p == '\0'; |
| 492 | + qsonly = (*p == '\0'); |
| 493 | while (qpend > ln && qpend[-1] == ' ') --qpend; |
| 494 | if (!firstline) { |
| 495 | for (p = ln, op = oldln; |
| 496 | @@ -358,13 +363,13 @@ |
| 497 | } |
| 498 | else { |
| 499 | vlnlen = p - ln; |
| 500 | - vln = malloc((vlnlen + 1) * sizeof (char)); |
| 501 | + vln = malloc((vlnlen + 1) * sizeof (wchar_t)); |
| 502 | if (!vln) { |
| 503 | - strcpy(errmsg,outofmem); |
| 504 | + wcscpy(errmsg,outofmem); |
| 505 | goto rlcleanup; |
| 506 | } |
| 507 | - strncpy(vln,ln,vlnlen); |
| 508 | - vln[vlnlen] = '\0'; |
| 509 | + mbstowcs(vln,ln,vlnlen + 1); |
| 510 | + vln[vlnlen] = L'\0'; |
| 511 | additem(lbuf, &vln, errmsg); |
| 512 | if (*errmsg) goto rlcleanup; |
| 513 | additem(lpbuf, invis ? &iprop : &vprop, errmsg); |
| 514 | @@ -373,13 +378,27 @@ |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | + if (oldln != NULL) { |
| 519 | + free(oldln); |
| 520 | + oldln = NULL; |
| 521 | + } |
| 522 | oldln = ln; |
| 523 | oldqpend = qpend; |
| 524 | oldqsonly = qsonly; |
| 525 | } |
| 526 | - additem(lbuf, &ln, errmsg); |
| 527 | + vln = malloc((strlen(ln) + 1) * sizeof (wchar_t)); |
| 528 | + if (!vln) { |
| 529 | + wcscpy(errmsg, outofmem); |
| 530 | + goto rlcleanup; |
| 531 | + } |
| 532 | + mbstowcs(vln,ln,strlen(ln) + 1); |
| 533 | + if (oldln == NULL) { |
| 534 | + free(ln); |
| 535 | + ln = NULL; |
| 536 | + } |
| 537 | + additem(lbuf, &vln, errmsg); |
| 538 | if (*errmsg) goto rlcleanup; |
| 539 | - ln = NULL; |
| 540 | + vln = NULL; |
| 541 | additem(lpbuf, &vprop, errmsg); |
| 542 | if (*errmsg) goto rlcleanup; |
| 543 | clearbuffer(cbuf); |
| 544 | @@ -407,7 +426,8 @@ |
| 545 | if (isspace(c) && isascii(c)) ch = ' '; |
| 546 | else blank = 0; |
| 547 | additem(cbuf, &ch, errmsg); |
| 548 | - if (*errmsg) goto rlcleanup; |
| 549 | + if (*errmsg) |
| 550 | + goto rlcleanup; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | @@ -416,9 +436,17 @@ |
| 555 | if (*errmsg) goto rlcleanup; |
| 556 | ln = copyitems(cbuf,errmsg); |
| 557 | if (*errmsg) goto rlcleanup; |
| 558 | - additem(lbuf, &ln, errmsg); |
| 559 | - if (*errmsg) goto rlcleanup; |
| 560 | + vln = malloc((strlen(ln) + 1) * sizeof (wchar_t)); |
| 561 | + if (!vln) { |
| 562 | + wcscpy(errmsg, outofmem); |
| 563 | + goto rlcleanup; |
| 564 | + } |
| 565 | + mbstowcs(vln,ln,strlen(ln) + 1); |
| 566 | + free(ln); |
| 567 | ln = NULL; |
| 568 | + additem(lbuf, &vln, errmsg); |
| 569 | + if (*errmsg) goto rlcleanup; |
| 570 | + vln = NULL; |
| 571 | additem(lpbuf, &vprop, errmsg); |
| 572 | if (*errmsg) goto rlcleanup; |
| 573 | } |
| 574 | @@ -450,7 +478,7 @@ |
| 575 | |
| 576 | |
| 577 | static void compresuflen( |
| 578 | - const char * const *lines, const char * const *endline, |
| 579 | + const wchar_t * const *lines, const wchar_t * const *endline, |
| 580 | const charset *bodychars, int body, int pre, int suf, int *ppre, int *psuf |
| 581 | ) |
| 582 | /* lines is an array of strings, up to but not including endline. */ |
| 583 | @@ -458,7 +486,7 @@ |
| 584 | /* lines in lines. Assumes that they have already been determined */ |
| 585 | /* to be at least pre and suf. endline must not equal lines. */ |
| 586 | { |
| 587 | - const char *start, *end, *knownstart, * const *line, *p1, *p2, *knownend, |
| 588 | + const wchar_t *start, *end, *knownstart, * const *line, *p1, *p2, *knownend, |
| 589 | *knownstart2; |
| 590 | |
| 591 | start = *lines; |
| 592 | @@ -475,7 +503,7 @@ |
| 593 | } |
| 594 | if (body) |
| 595 | for (p1 = end; p1 > knownstart; ) |
| 596 | - if (*--p1 != ' ') { |
| 597 | + if (*--p1 != L' ') { |
| 598 | if (csmember(*p1, bodychars)) |
| 599 | end = p1; |
| 600 | else |
| 601 | @@ -502,18 +530,18 @@ |
| 602 | } |
| 603 | if (body) { |
| 604 | for (p1 = start; |
| 605 | - start < knownend && (*start == ' ' || csmember(*start, bodychars)); |
| 606 | + start < knownend && (*start == L' ' || csmember(*start, bodychars)); |
| 607 | ++start); |
| 608 | - if (start > p1 && start[-1] == ' ') --start; |
| 609 | + if (start > p1 && start[-1] == L' ') --start; |
| 610 | } |
| 611 | else |
| 612 | - while (end - start >= 2 && *start == ' ' && start[1] == ' ') ++start; |
| 613 | + while (end - start >= 2 && *start == L' ' && start[1] == L' ') ++start; |
| 614 | *psuf = end - start; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | static void delimit( |
| 619 | - const char * const *lines, const char * const *endline, |
| 620 | + const wchar_t * const *lines, const wchar_t * const *endline, |
| 621 | const charset *bodychars, int repeat, int body, int div, |
| 622 | int pre, int suf, lineprop *props |
| 623 | ) |
| 624 | @@ -524,8 +552,8 @@ |
| 625 | /* and comsuflen of the lines in lines have already been */ |
| 626 | /* determined to be at least pre and suf, respectively. */ |
| 627 | { |
| 628 | - const char * const *line, *end, *p, * const *nextline; |
| 629 | - char rc; |
| 630 | + const wchar_t * const *line, *end, *p, * const *nextline; |
| 631 | + wchar_t rc; |
| 632 | lineprop *prop, *nextprop; |
| 633 | int anybodiless = 0, status; |
| 634 | |
| 635 | @@ -546,8 +574,8 @@ |
| 636 | for (end = *line; *end; ++end); |
| 637 | end -= suf; |
| 638 | p = *line + pre; |
| 639 | - rc = p < end ? *p : ' '; |
| 640 | - if (rc != ' ' && (!repeat || end - p < repeat)) |
| 641 | + rc = p < end ? *p : L' '; |
| 642 | + if (rc != L' ' && (!repeat || end - p < repeat)) |
| 643 | prop->flags &= ~L_BODILESS; |
| 644 | else |
| 645 | while (p < end) { |
| 646 | @@ -590,9 +618,9 @@ |
| 647 | } |
| 648 | |
| 649 | line = lines, prop = props; |
| 650 | - status = ((*lines)[pre] == ' '); |
| 651 | + status = ((*lines)[pre] == L' '); |
| 652 | do { |
| 653 | - if (((*line)[pre] == ' ') == status) |
| 654 | + if (((*line)[pre] == L' ') == status) |
| 655 | prop->flags |= L_FIRST; |
| 656 | ++line, ++prop; |
| 657 | } while (line < endline); |
| 658 | @@ -600,14 +628,14 @@ |
| 659 | |
| 660 | |
| 661 | static void marksuperf( |
| 662 | - const char * const * lines, const char * const * endline, lineprop *props |
| 663 | + const wchar_t * const * lines, const wchar_t * const * endline, lineprop *props |
| 664 | ) |
| 665 | /* lines points to the first line of a segment, and endline to one */ |
| 666 | /* line beyond the last line in the segment. Sets L_SUPERF bits in */ |
| 667 | /* the flags fields of the props array whenever the corresponding */ |
| 668 | /* line is superfluous. L_BODILESS bits must already be set. */ |
| 669 | { |
| 670 | - const char * const *line, *p; |
| 671 | + const wchar_t * const *line, *p; |
| 672 | lineprop *prop, *mprop, dummy; |
| 673 | int inbody, num, mnum; |
| 674 | |
| 675 | @@ -620,7 +648,7 @@ |
| 676 | for (line = lines, prop = props; line < endline; ++line, ++prop) |
| 677 | if (isvacant(prop)) { |
| 678 | for (num = 0, p = *line; *p; ++p) |
| 679 | - if (*p != ' ') ++num; |
| 680 | + if (*p != L' ') ++num; |
| 681 | if (inbody || num < mnum) |
| 682 | mnum = num, mprop = prop; |
| 683 | inbody = 0; |
| 684 | @@ -632,7 +660,7 @@ |
| 685 | |
| 686 | |
| 687 | static void setaffixes( |
| 688 | - const char * const *inlines, const char * const *endline, |
| 689 | + const wchar_t * const *inlines, const wchar_t * const *endline, |
| 690 | const lineprop *props, const charset *bodychars, |
| 691 | const charset *quotechars, int hang, int body, int quote, |
| 692 | int *pafp, int *pfs, int *pprefix, int *psuffix |
| 693 | @@ -645,7 +673,7 @@ |
| 694 | /* default value as specified in "par.doc". */ |
| 695 | { |
| 696 | int numin, pre, suf; |
| 697 | - const char *p; |
| 698 | + const wchar_t *p; |
| 699 | |
| 700 | numin = endline - inlines; |
| 701 | |
| 702 | @@ -667,11 +695,11 @@ |
| 703 | } |
| 704 | |
| 705 | |
| 706 | -static void freelines(char **lines) |
| 707 | +static void freelines(wchar_t **lines) |
| 708 | /* Frees the elements of lines, and lines itself. */ |
| 709 | /* lines is a NULL-terminated array of strings. */ |
| 710 | { |
| 711 | - char **line; |
| 712 | + wchar_t **line; |
| 713 | |
| 714 | for (line = lines; *line; ++line) |
| 715 | free(*line); |
| 716 | @@ -679,18 +707,21 @@ |
| 717 | free(lines); |
| 718 | } |
| 719 | |
| 720 | - |
| 721 | int main(int argc, const char * const *argv) |
| 722 | { |
| 723 | int help = 0, version = 0, hang = 0, prefix = -1, repeat = 0, suffix = -1, |
| 724 | Tab = 1, width = 72, body = 0, cap = 0, div = 0, Err = 0, expel = 0, |
| 725 | fit = 0, guess = 0, invis = 0, just = 0, last = 0, quote = 0, Report = 0, |
| 726 | touch = -1; |
| 727 | - int prefixbak, suffixbak, c, sawnonblank, oweblank, n, i, afp, fs; |
| 728 | + int prefixbak, suffixbak, sawnonblank, oweblank, n, i, afp, fs; |
| 729 | charset *bodychars = NULL, *protectchars = NULL, *quotechars = NULL; |
| 730 | - char *parinit = NULL, *arg, **inlines = NULL, **endline, **firstline, *end, |
| 731 | - **nextline, **outlines = NULL, **line, ch; |
| 732 | - const char *env, * const whitechars = " \f\n\r\t\v"; |
| 733 | + char ch; |
| 734 | + wint_t c; |
| 735 | + char *arg, *parinit = NULL; |
| 736 | + wchar_t *end, **nextline, **inlines = NULL, **endline, **firstline, |
| 737 | + **outlines = NULL, **line; |
| 738 | + const char *env; |
| 739 | + const char * const whitechars = " \f\n\r\t\v"; |
| 740 | errmsg_t errmsg = { '\0' }; |
| 741 | lineprop *props = NULL, *firstprop, *nextprop; |
| 742 | FILE *errout; |
| 743 | @@ -729,7 +760,7 @@ |
| 744 | if (env) { |
| 745 | parinit = malloc((strlen(env) + 1) * sizeof (char)); |
| 746 | if (!parinit) { |
| 747 | - strcpy(errmsg,outofmem); |
| 748 | + wcscpy(errmsg,outofmem); |
| 749 | goto parcleanup; |
| 750 | } |
| 751 | strcpy(parinit,env); |
| 752 | @@ -757,7 +788,7 @@ |
| 753 | } |
| 754 | |
| 755 | if (Tab == 0) { |
| 756 | - strcpy(errmsg, "<Tab> must not be 0.\n"); |
| 757 | + wcscpy(errmsg, L"<Tab> must not be 0.\n"); |
| 758 | goto parcleanup; |
| 759 | } |
| 760 | |
| 761 | @@ -765,8 +796,7 @@ |
| 762 | prefixbak = prefix; |
| 763 | suffixbak = suffix; |
| 764 | |
| 765 | -/* Main loop: */ |
| 766 | - |
| 767 | + /* Main loop: */ |
| 768 | for (sawnonblank = oweblank = 0; ; ) { |
| 769 | for (;;) { |
| 770 | c = getchar(); |
| 771 | @@ -779,7 +809,7 @@ |
| 772 | if (csmember(ch, protectchars)) { |
| 773 | sawnonblank = 1; |
| 774 | if (oweblank) { |
| 775 | - puts(""); |
| 776 | + fputwc('\n', stdout); |
| 777 | oweblank = 0; |
| 778 | } |
| 779 | while (ch != '\n') { |
| 780 | @@ -798,8 +828,7 @@ |
| 781 | inlines = |
| 782 | readlines(&props, protectchars, quotechars, Tab, invis, quote, errmsg); |
| 783 | if (*errmsg) goto parcleanup; |
| 784 | - |
| 785 | - for (endline = inlines; *endline; ++endline); |
| 786 | + for (endline = inlines; *endline; ++endline) ; |
| 787 | if (endline == inlines) { |
| 788 | free(inlines); |
| 789 | inlines = NULL; |
| 790 | @@ -808,19 +837,20 @@ |
| 791 | |
| 792 | sawnonblank = 1; |
| 793 | if (oweblank) { |
| 794 | - puts(""); |
| 795 | + fputwc('\n', stdout); |
| 796 | oweblank = 0; |
| 797 | } |
| 798 | |
| 799 | - delimit((const char * const *) inlines, |
| 800 | - (const char * const *) endline, |
| 801 | + delimit((const wchar_t * const *) inlines, |
| 802 | + (const wchar_t * const *) endline, |
| 803 | bodychars, repeat, body, div, 0, 0, props); |
| 804 | |
| 805 | if (expel) |
| 806 | - marksuperf((const char * const *) inlines, |
| 807 | - (const char * const *) endline, props); |
| 808 | + marksuperf((const wchar_t * const *) inlines, |
| 809 | + (const wchar_t * const *) endline, props); |
| 810 | |
| 811 | firstline = inlines, firstprop = props; |
| 812 | + |
| 813 | do { |
| 814 | if (isbodiless(firstprop)) { |
| 815 | if (!isinvis(firstprop) && !(expel && issuperf(firstprop))) { |
| 816 | @@ -828,18 +858,18 @@ |
| 817 | if (!repeat || (firstprop->rc == ' ' && !firstprop->s)) { |
| 818 | while (end > *firstline && end[-1] == ' ') --end; |
| 819 | *end = '\0'; |
| 820 | - puts(*firstline); |
| 821 | + fwprintf(stdout, L"%ls\n", *firstline); |
| 822 | } |
| 823 | else { |
| 824 | n = width - firstprop->p - firstprop->s; |
| 825 | if (n < 0) { |
| 826 | - sprintf(errmsg,impossibility,5); |
| 827 | + swprintf(errmsg,errmsg_size,impossibility,5); |
| 828 | goto parcleanup; |
| 829 | } |
| 830 | - printf("%.*s", firstprop->p, *firstline); |
| 831 | + fwprintf(stdout, L"%.*ls", firstprop->p, *firstline); |
| 832 | for (i = n; i; --i) |
| 833 | - putchar(*(unsigned char *)&firstprop->rc); |
| 834 | - puts(end - firstprop->s); |
| 835 | + fputwc(firstprop->rc, stdout); |
| 836 | + fwprintf(stdout, L"%ls\n", end - firstprop->s); |
| 837 | } |
| 838 | } |
| 839 | ++firstline, ++firstprop; |
| 840 | @@ -851,26 +881,24 @@ |
| 841 | ++nextline, ++nextprop); |
| 842 | |
| 843 | prefix = prefixbak, suffix = suffixbak; |
| 844 | - setaffixes((const char * const *) firstline, |
| 845 | - (const char * const *) nextline, firstprop, bodychars, |
| 846 | + setaffixes((const wchar_t * const *) firstline, |
| 847 | + (const wchar_t * const *) nextline, firstprop, bodychars, |
| 848 | quotechars, hang, body, quote, &afp, &fs, &prefix, &suffix); |
| 849 | if (width <= prefix + suffix) { |
| 850 | - sprintf(errmsg, |
| 851 | - "<width> (%d) <= <prefix> (%d) + <suffix> (%d)\n", |
| 852 | + swprintf(errmsg,errmsg_size, |
| 853 | + L"<width> (%d) <= <prefix> (%d) + <suffix> (%d)\n", |
| 854 | width, prefix, suffix); |
| 855 | goto parcleanup; |
| 856 | } |
| 857 | |
| 858 | outlines = |
| 859 | - reformat((const char * const *) firstline, |
| 860 | - (const char * const *) nextline, |
| 861 | + reformat((const wchar_t * const *) firstline, |
| 862 | + (const wchar_t * const *) nextline, |
| 863 | afp, fs, hang, prefix, suffix, width, cap, |
| 864 | fit, guess, just, last, Report, touch, errmsg); |
| 865 | if (*errmsg) goto parcleanup; |
| 866 | - |
| 867 | for (line = outlines; *line; ++line) |
| 868 | - puts(*line); |
| 869 | - |
| 870 | + fwprintf(stdout, L"%ls\n", *line); |
| 871 | freelines(outlines); |
| 872 | outlines = NULL; |
| 873 | |
| 874 | @@ -895,8 +923,12 @@ |
| 875 | if (outlines) freelines(outlines); |
| 876 | |
| 877 | errout = Err ? stderr : stdout; |
| 878 | - if (*errmsg) fprintf(errout, "par error:\n%.*s", errmsg_size, errmsg); |
| 879 | - if (version) fputs("par 1.52\n",errout); |
| 880 | + if (*errmsg) fwprintf(errout, L"par error:\n%.*ls", errmsg_size, errmsg); |
| 881 | +#ifdef NOWIDTH |
| 882 | + if (version) fputws(L"par 1.52-i18n.3 (without wcwidth() support)\n",errout); |
| 883 | +#else |
| 884 | + if (version) fputws(L"par 1.52-i18n.3\n",errout); |
| 885 | +#endif |
| 886 | if (help) fputs(usagemsg,errout); |
| 887 | |
| 888 | return *errmsg ? EXIT_FAILURE : EXIT_SUCCESS; |
| 889 | --- par.doc.orig |
| 890 | +++ par.doc |
| 891 | @@ -1,6 +1,6 @@ |
| 892 | ********************* |
| 893 | * par.doc * |
| 894 | - * for Par 1.52 * |
| 895 | + * for Par 1.52 i18n * |
| 896 | * Copyright 2001 by * |
| 897 | * Adam M. Costello * |
| 898 | ********************* |
| 899 | --- reformat.c.orig |
| 900 | +++ reformat.c |
| 901 | @@ -1,9 +1,11 @@ |
| 902 | -/*********************/ |
| 903 | -/* reformat.c */ |
| 904 | -/* for Par 1.52 */ |
| 905 | -/* Copyright 2001 by */ |
| 906 | -/* Adam M. Costello */ |
| 907 | -/*********************/ |
| 908 | +/***********************/ |
| 909 | +/* reformat.c */ |
| 910 | +/* for Par 1.52-i18n.3 */ |
| 911 | +/* Copyright 2001 by */ |
| 912 | +/* Adam M. Costello */ |
| 913 | +/* Modified by */ |
| 914 | +/* Jérôme Pouiller */ |
| 915 | +/***********************/ |
| 916 | |
| 917 | /* This is ANSI C code (C89). */ |
| 918 | |
| 919 | @@ -16,6 +18,7 @@ |
| 920 | #include <stdio.h> |
| 921 | #include <stdlib.h> |
| 922 | #include <string.h> |
| 923 | +#include <wctype.h> |
| 924 | |
| 925 | #undef NULL |
| 926 | #define NULL ((void *) 0) |
| 927 | @@ -33,14 +36,15 @@ |
| 928 | typedef unsigned char wflag_t; |
| 929 | |
| 930 | typedef struct word { |
| 931 | - const char *chrs; /* Pointer to the characters in the word */ |
| 932 | + const wchar_t *chrs; /* Pointer to the characters in the word */ |
| 933 | /* (NOT terminated by '\0'). */ |
| 934 | struct word *prev, /* Pointer to previous word. */ |
| 935 | *next, /* Pointer to next word. */ |
| 936 | /* Supposing this word were the first... */ |
| 937 | *nextline; /* Pointer to first word in next line. */ |
| 938 | int score, /* Value of the objective function. */ |
| 939 | - length; /* Length of this word. */ |
| 940 | + length, /* Length (in widechar) of this word. */ |
| 941 | + width; /* Visual width of this word. */ |
| 942 | wflag_t flags; /* Notable properties of this word. */ |
| 943 | } word; |
| 944 | |
| 945 | @@ -57,17 +61,36 @@ |
| 946 | #define iscurious(w) (((w)->flags & 2) != 0) |
| 947 | #define iscapital(w) (((w)->flags & 4) != 0) |
| 948 | |
| 949 | +static int getWidth(const wchar_t *beg, const wchar_t *end) |
| 950 | +/* Compute (visual) width of a word. This function is aware */ |
| 951 | +/* about double-width characters used in oriental langages. */ |
| 952 | +{ |
| 953 | + int ret, tmp; |
| 954 | + |
| 955 | + for (ret = 0; beg != end; beg++) { |
| 956 | +#ifdef NOWIDTH |
| 957 | + tmp = 1; |
| 958 | +#else |
| 959 | + tmp = wcwidth(*beg); |
| 960 | +#endif |
| 961 | + if (tmp < 0) |
| 962 | + tmp = 0; |
| 963 | + ret += tmp; |
| 964 | + } |
| 965 | + |
| 966 | + return ret; |
| 967 | +} |
| 968 | |
| 969 | static int checkcapital(word *w) |
| 970 | /* Returns 1 if *w is capitalized according to the definition */ |
| 971 | /* in par.doc (assuming <cap> is 0), or 0 if not. */ |
| 972 | { |
| 973 | - const char *p, *end; |
| 974 | + const wchar_t *p, *end; |
| 975 | |
| 976 | for (p = w->chrs, end = p + w->length; |
| 977 | - p < end && !isalnum(*(unsigned char *)p); |
| 978 | + p < end && !iswalnum(*p); |
| 979 | ++p); |
| 980 | - return p < end && !islower(*(unsigned char *)p); |
| 981 | + return p < end && !iswlower(*p); |
| 982 | } |
| 983 | |
| 984 | |
| 985 | @@ -75,19 +98,19 @@ |
| 986 | /* Returns 1 if *w is curious according to */ |
| 987 | /* the definition in par.doc, or 0 if not. */ |
| 988 | { |
| 989 | - const char *start, *p; |
| 990 | - char ch; |
| 991 | + const wchar_t *start, *p; |
| 992 | + wchar_t ch; |
| 993 | |
| 994 | for (start = w->chrs, p = start + w->length; p > start; --p) { |
| 995 | ch = p[-1]; |
| 996 | - if (isalnum(*(unsigned char *)&ch)) return 0; |
| 997 | - if (ch == '.' || ch == '?' || ch == '!' || ch == ':') break; |
| 998 | + if (iswalnum(*(wchar_t *)&ch)) return 0; |
| 999 | + if (ch == L'.' || ch == L'?' || ch == L'!' || ch == L':') break; |
| 1000 | } |
| 1001 | |
| 1002 | if (p <= start + 1) return 0; |
| 1003 | |
| 1004 | --p; |
| 1005 | - do if (isalnum(*(unsigned char *)--p)) return 1; |
| 1006 | + do if (iswalnum(*(wchar_t *)--p)) return 1; |
| 1007 | while (p > start); |
| 1008 | |
| 1009 | return 0; |
| 1010 | @@ -95,31 +118,32 @@ |
| 1011 | |
| 1012 | |
| 1013 | static int simplebreaks(word *head, word *tail, int L, int last) |
| 1014 | - |
| 1015 | -/* Chooses line breaks in a list of words which maximize the length of the */ |
| 1016 | -/* shortest line. L is the maximum line length. The last line counts as a */ |
| 1017 | -/* line only if last is non-zero. _head must point to a dummy word, and tail */ |
| 1018 | -/* must point to the last word, whose next field must be NULL. Returns the */ |
| 1019 | -/* length of the shortest line on success, -1 if there is a word of length */ |
| 1020 | -/* greater than L, or L if there are no lines. */ |
| 1021 | +/* Chooses line breaks in a list of words which maximize */ |
| 1022 | +/* the length of the shortest line. L is the maximum line */ |
| 1023 | +/* length. The last line counts as a line only if last is */ |
| 1024 | +/* non-zero. _head must point to a dummy word, and tail */ |
| 1025 | +/* must point to the last word, whose next field must be */ |
| 1026 | +/* NULL. Returns the length of the shortest line on */ |
| 1027 | +/* success, -1 if there is a word of length greater than L, */ |
| 1028 | +/* or L if there are no lines. */ |
| 1029 | { |
| 1030 | word *w1, *w2; |
| 1031 | int linelen, score; |
| 1032 | |
| 1033 | if (!head->next) return L; |
| 1034 | |
| 1035 | - for (w1 = tail, linelen = w1->length; |
| 1036 | + for (w1 = tail, linelen = w1->width; |
| 1037 | w1 != head && linelen <= L; |
| 1038 | - linelen += isshifted(w1), w1 = w1->prev, linelen += 1 + w1->length) { |
| 1039 | + linelen += isshifted(w1), w1 = w1->prev, linelen += 1 + w1->width) { |
| 1040 | w1->score = last ? linelen : L; |
| 1041 | w1->nextline = NULL; |
| 1042 | } |
| 1043 | |
| 1044 | for ( ; w1 != head; w1 = w1->prev) { |
| 1045 | w1->score = -1; |
| 1046 | - for (linelen = w1->length, w2 = w1->next; |
| 1047 | + for (linelen = w1->width, w2 = w1->next; |
| 1048 | linelen <= L; |
| 1049 | - linelen += 1 + isshifted(w2) + w2->length, w2 = w2->next) { |
| 1050 | + linelen += 1 + isshifted(w2) + w2->width, w2 = w2->next) { |
| 1051 | score = w2->score; |
| 1052 | if (linelen < score) score = linelen; |
| 1053 | if (score >= w1->score) { |
| 1054 | @@ -168,7 +192,7 @@ |
| 1055 | |
| 1056 | shortest = simplebreaks(head,tail,target,last); |
| 1057 | if (shortest < 0) { |
| 1058 | - sprintf(errmsg,impossibility,1); |
| 1059 | + swprintf(errmsg,errmsg_size,impossibility,1); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | @@ -178,9 +202,9 @@ |
| 1064 | w1 = tail; |
| 1065 | do { |
| 1066 | w1->score = -1; |
| 1067 | - for (linelen = w1->length, w2 = w1->next; |
| 1068 | + for (linelen = w1->width, w2 = w1->next; |
| 1069 | linelen <= target; |
| 1070 | - linelen += 1 + isshifted(w2) + w2->length, w2 = w2->next) { |
| 1071 | + linelen += 1 + isshifted(w2) + w2->width, w2 = w2->next) { |
| 1072 | extra = target - linelen; |
| 1073 | minlen = shortest; |
| 1074 | if (w2) |
| 1075 | @@ -202,7 +226,7 @@ |
| 1076 | } while (w1 != head); |
| 1077 | |
| 1078 | if (head->next->score < 0) |
| 1079 | - sprintf(errmsg,impossibility,2); |
| 1080 | + swprintf(errmsg,errmsg_size,impossibility,2); |
| 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | @@ -225,9 +249,9 @@ |
| 1085 | w1 = tail; |
| 1086 | do { |
| 1087 | w1->score = L; |
| 1088 | - for (numgaps = 0, extra = L - w1->length, w2 = w1->next; |
| 1089 | + for (numgaps = 0, extra = L - w1->width, w2 = w1->next; |
| 1090 | extra >= 0; |
| 1091 | - ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next) { |
| 1092 | + ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next) { |
| 1093 | gap = numgaps ? (extra + numgaps - 1) / numgaps : L; |
| 1094 | if (w2) |
| 1095 | score = w2->score; |
| 1096 | @@ -247,7 +271,7 @@ |
| 1097 | |
| 1098 | maxgap = head->next->score; |
| 1099 | if (maxgap >= L) { |
| 1100 | - strcpy(errmsg, "Cannot justify.\n"); |
| 1101 | + wcscpy(errmsg, L"Cannot justify.\n"); |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | @@ -257,9 +281,9 @@ |
| 1106 | w1 = tail; |
| 1107 | do { |
| 1108 | w1->score = -1; |
| 1109 | - for (numgaps = 0, extra = L - w1->length, w2 = w1->next; |
| 1110 | + for (numgaps = 0, extra = L - w1->width, w2 = w1->next; |
| 1111 | extra >= 0; |
| 1112 | - ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next) { |
| 1113 | + ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next) { |
| 1114 | gap = numgaps ? (extra + numgaps - 1) / numgaps : L; |
| 1115 | if (w2) |
| 1116 | score = w2->score; |
| 1117 | @@ -288,40 +312,39 @@ |
| 1118 | } while (w1 != head); |
| 1119 | |
| 1120 | if (head->next->score < 0) |
| 1121 | - sprintf(errmsg,impossibility,3); |
| 1122 | + swprintf(errmsg,errmsg_size,impossibility,3); |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | -char **reformat( |
| 1127 | - const char * const *inlines, const char * const *endline, int afp, int fs, |
| 1128 | +wchar_t **reformat( |
| 1129 | + const wchar_t * const *inlines, const wchar_t * const *endline, int afp, int fs, |
| 1130 | int hang, int prefix, int suffix, int width, int cap, int fit, int guess, |
| 1131 | int just, int last, int Report, int touch, errmsg_t errmsg |
| 1132 | ) |
| 1133 | { |
| 1134 | int numin, affix, L, onfirstword = 1, linelen, numout, numgaps, extra, phase; |
| 1135 | - const char * const *line, **suffixes = NULL, **suf, *end, *p1, *p2; |
| 1136 | - char *q1, *q2, **outlines = NULL; |
| 1137 | + const wchar_t * const *line, **suffixes = NULL, **suf, *end, *p1, *p2; |
| 1138 | + wchar_t *q1, *q2, **outlines = NULL; |
| 1139 | word dummy, *head, *tail, *w1, *w2; |
| 1140 | buffer *pbuf = NULL; |
| 1141 | |
| 1142 | /* Initialization: */ |
| 1143 | - |
| 1144 | *errmsg = '\0'; |
| 1145 | dummy.next = dummy.prev = NULL; |
| 1146 | dummy.flags = 0; |
| 1147 | head = tail = &dummy; |
| 1148 | numin = endline - inlines; |
| 1149 | if (numin <= 0) { |
| 1150 | - sprintf(errmsg,impossibility,4); |
| 1151 | + swprintf(errmsg,errmsg_size,impossibility,4); |
| 1152 | goto rfcleanup; |
| 1153 | } |
| 1154 | numgaps = extra = 0; /* unnecessary, but quiets compiler warnings */ |
| 1155 | |
| 1156 | /* Allocate space for pointers to the suffixes: */ |
| 1157 | |
| 1158 | - suffixes = malloc(numin * sizeof (const char *)); |
| 1159 | + suffixes = malloc(numin * sizeof (const wchar_t *)); |
| 1160 | if (!suffixes) { |
| 1161 | - strcpy(errmsg,outofmem); |
| 1162 | + wcscpy(errmsg,outofmem); |
| 1163 | goto rfcleanup; |
| 1164 | } |
| 1165 | |
| 1166 | @@ -334,8 +357,8 @@ |
| 1167 | do { |
| 1168 | for (end = *line; *end; ++end); |
| 1169 | if (end - *line < affix) { |
| 1170 | - sprintf(errmsg, |
| 1171 | - "Line %d shorter than <prefix> + <suffix> = %d + %d = %d\n", |
| 1172 | + swprintf(errmsg,errmsg_size, |
| 1173 | + L"Line %d shorter than <prefix> + <suffix> = %d + %d = %d\n", |
| 1174 | (int)(line - inlines + 1), prefix, suffix, affix); |
| 1175 | goto rfcleanup; |
| 1176 | } |
| 1177 | @@ -343,17 +366,17 @@ |
| 1178 | *suf = end; |
| 1179 | p1 = *line + prefix; |
| 1180 | for (;;) { |
| 1181 | - while (p1 < end && *p1 == ' ') ++p1; |
| 1182 | + while (p1 < end && *p1 == L' ') ++p1; |
| 1183 | if (p1 == end) break; |
| 1184 | p2 = p1; |
| 1185 | if (onfirstword) { |
| 1186 | p1 = *line + prefix; |
| 1187 | onfirstword = 0; |
| 1188 | } |
| 1189 | - while (p2 < end && *p2 != ' ') ++p2; |
| 1190 | + while (p2 < end && *p2 != L' ') ++p2; |
| 1191 | w1 = malloc(sizeof (word)); |
| 1192 | if (!w1) { |
| 1193 | - strcpy(errmsg,outofmem); |
| 1194 | + wcscpy(errmsg,outofmem); |
| 1195 | goto rfcleanup; |
| 1196 | } |
| 1197 | w1->next = NULL; |
| 1198 | @@ -361,6 +384,7 @@ |
| 1199 | tail = tail->next = w1; |
| 1200 | w1->chrs = p1; |
| 1201 | w1->length = p2 - p1; |
| 1202 | + w1->width = getWidth(p1, p2); |
| 1203 | w1->flags = 0; |
| 1204 | p1 = p2; |
| 1205 | } |
| 1206 | @@ -377,6 +401,7 @@ |
| 1207 | if (iscurious(w1)) { |
| 1208 | if (w1->chrs[w1->length] && w1->chrs + w1->length + 1 == w2->chrs) { |
| 1209 | w2->length += w1->length + 1; |
| 1210 | + w2->width += w1->width + 1; |
| 1211 | w2->chrs = w1->chrs; |
| 1212 | w2->prev = w1->prev; |
| 1213 | w2->prev->next = w2; |
| 1214 | @@ -397,20 +422,20 @@ |
| 1215 | |
| 1216 | if (Report) |
| 1217 | for (w2 = head->next; w2; w2 = w2->next) { |
| 1218 | - if (w2->length > L) { |
| 1219 | - linelen = w2->length; |
| 1220 | + if (w2->width > L) { |
| 1221 | + linelen = w2->width; |
| 1222 | if (linelen > errmsg_size - 17) |
| 1223 | linelen = errmsg_size - 17; |
| 1224 | - sprintf(errmsg, "Word too long: %.*s\n", linelen, w2->chrs); |
| 1225 | + swprintf(errmsg,errmsg_size, L"Word too long: %.*ls\n", linelen, w2->chrs); |
| 1226 | goto rfcleanup; |
| 1227 | } |
| 1228 | } |
| 1229 | else |
| 1230 | for (w2 = head->next; w2; w2 = w2->next) |
| 1231 | - while (w2->length > L) { |
| 1232 | + while (w2->width > L) { |
| 1233 | w1 = malloc(sizeof (word)); |
| 1234 | if (!w1) { |
| 1235 | - strcpy(errmsg,outofmem); |
| 1236 | + wcscpy(errmsg,outofmem); |
| 1237 | goto rfcleanup; |
| 1238 | } |
| 1239 | w1->next = w2; |
| 1240 | @@ -420,7 +445,9 @@ |
| 1241 | w1->chrs = w2->chrs; |
| 1242 | w2->chrs += L; |
| 1243 | w1->length = L; |
| 1244 | + w1->width = getWidth(w1->chrs, w1->chrs + L); |
| 1245 | w2->length -= L; |
| 1246 | + w2->width -= w1->width; |
| 1247 | w1->flags = 0; |
| 1248 | if (iscapital(w2)) { |
| 1249 | w1->flags |= W_CAPITAL; |
| 1250 | @@ -444,9 +471,9 @@ |
| 1251 | L = 0; |
| 1252 | w1 = head->next; |
| 1253 | while (w1) { |
| 1254 | - for (linelen = w1->length, w2 = w1->next; |
| 1255 | + for (linelen = w1->width, w2 = w1->next; |
| 1256 | w2 != w1->nextline; |
| 1257 | - linelen += 1 + isshifted(w2) + w2->length, w2 = w2->next); |
| 1258 | + linelen += 1 + isshifted(w2) + w2->width, w2 = w2->next); |
| 1259 | if (linelen > L) L = linelen; |
| 1260 | w1 = w2; |
| 1261 | } |
| 1262 | @@ -454,67 +481,67 @@ |
| 1263 | |
| 1264 | /* Construct the lines: */ |
| 1265 | |
| 1266 | - pbuf = newbuffer(sizeof (char *), errmsg); |
| 1267 | + pbuf = newbuffer(sizeof (wchar_t *), errmsg); |
| 1268 | if (*errmsg) goto rfcleanup; |
| 1269 | |
| 1270 | numout = 0; |
| 1271 | w1 = head->next; |
| 1272 | while (numout < hang || w1) { |
| 1273 | if (w1) |
| 1274 | - for (w2 = w1->next, numgaps = 0, extra = L - w1->length; |
| 1275 | + for (w2 = w1->next, numgaps = 0, extra = L - w1->width; |
| 1276 | w2 != w1->nextline; |
| 1277 | - ++numgaps, extra -= 1 + isshifted(w2) + w2->length, w2 = w2->next); |
| 1278 | + ++numgaps, extra -= 1 + isshifted(w2) + w2->width, w2 = w2->next); |
| 1279 | linelen = suffix || (just && (w2 || last)) ? |
| 1280 | L + affix : |
| 1281 | w1 ? prefix + L - extra : prefix; |
| 1282 | - q1 = malloc((linelen + 1) * sizeof (char)); |
| 1283 | + q1 = malloc((linelen + 1) * sizeof (wchar_t)); |
| 1284 | if (!q1) { |
| 1285 | - strcpy(errmsg,outofmem); |
| 1286 | + wcscpy(errmsg,outofmem); |
| 1287 | goto rfcleanup; |
| 1288 | } |
| 1289 | additem(pbuf, &q1, errmsg); |
| 1290 | if (*errmsg) goto rfcleanup; |
| 1291 | ++numout; |
| 1292 | q2 = q1 + prefix; |
| 1293 | - if (numout <= numin) memcpy(q1, inlines[numout - 1], prefix); |
| 1294 | - else if (numin > hang ) memcpy(q1, endline[-1], prefix); |
| 1295 | + if (numout <= numin) memcpy(q1, inlines[numout - 1], prefix * sizeof(wchar_t)); |
| 1296 | + else if (numin > hang ) memcpy(q1, endline[-1], prefix * sizeof(wchar_t)); |
| 1297 | else { |
| 1298 | if (afp > prefix) afp = prefix; |
| 1299 | - memcpy(q1, endline[-1], afp); |
| 1300 | + memcpy(q1, endline[-1], afp * sizeof(wchar_t)); |
| 1301 | q1 += afp; |
| 1302 | - while (q1 < q2) *q1++ = ' '; |
| 1303 | + while (q1 < q2) *q1++ = L' '; |
| 1304 | } |
| 1305 | q1 = q2; |
| 1306 | if (w1) { |
| 1307 | phase = numgaps / 2; |
| 1308 | for (w2 = w1; ; ) { |
| 1309 | - memcpy(q1, w2->chrs, w2->length); |
| 1310 | + memcpy(q1, w2->chrs, w2->length * sizeof(wchar_t)); |
| 1311 | q1 += w2->length; |
| 1312 | w2 = w2->next; |
| 1313 | if (w2 == w1->nextline) break; |
| 1314 | - *q1++ = ' '; |
| 1315 | + *q1++ = L' '; |
| 1316 | if (just && (w1->nextline || last)) { |
| 1317 | phase += extra; |
| 1318 | while (phase >= numgaps) { |
| 1319 | - *q1++ = ' '; |
| 1320 | + *q1++ = L' '; |
| 1321 | phase -= numgaps; |
| 1322 | } |
| 1323 | } |
| 1324 | - if (isshifted(w2)) *q1++ = ' '; |
| 1325 | + if (isshifted(w2)) *q1++ = L' '; |
| 1326 | } |
| 1327 | } |
| 1328 | q2 += linelen - affix; |
| 1329 | - while (q1 < q2) *q1++ = ' '; |
| 1330 | + while (q1 < q2) *q1++ = L' '; |
| 1331 | q2 = q1 + suffix; |
| 1332 | - if (numout <= numin) memcpy(q1, suffixes[numout - 1], suffix); |
| 1333 | - else if (numin > hang ) memcpy(q1, suffixes[numin - 1], suffix); |
| 1334 | + if (numout <= numin) memcpy(q1, suffixes[numout - 1], suffix * sizeof(wchar_t)); |
| 1335 | + else if (numin > hang ) memcpy(q1, suffixes[numin - 1], suffix * sizeof(wchar_t)); |
| 1336 | else { |
| 1337 | if (fs > suffix) fs = suffix; |
| 1338 | - memcpy(q1, suffixes[numin - 1], fs); |
| 1339 | + memcpy(q1, suffixes[numin - 1], fs * sizeof(wchar_t)); |
| 1340 | q1 += fs; |
| 1341 | - while(q1 < q2) *q1++ = ' '; |
| 1342 | + while(q1 < q2) *q1++ = L' '; |
| 1343 | } |
| 1344 | - *q2 = '\0'; |
| 1345 | + *q2 = L'\0'; |
| 1346 | if (w1) w1 = w1->nextline; |
| 1347 | } |
| 1348 | |
| 1349 | @@ -543,5 +570,6 @@ |
| 1350 | freebuffer(pbuf); |
| 1351 | } |
| 1352 | |
| 1353 | + |
| 1354 | return outlines; |
| 1355 | } |
| 1356 | --- reformat.h.orig |
| 1357 | +++ reformat.h |
| 1358 | @@ -1,18 +1,20 @@ |
| 1359 | -/*********************/ |
| 1360 | -/* reformat.h */ |
| 1361 | -/* for Par 1.52 */ |
| 1362 | -/* Copyright 2001 by */ |
| 1363 | -/* Adam M. Costello */ |
| 1364 | -/*********************/ |
| 1365 | +/***********************/ |
| 1366 | +/* reformat.h */ |
| 1367 | +/* for Par 1.52-i18n.3 */ |
| 1368 | +/* Copyright 2001 by */ |
| 1369 | +/* Adam M. Costello */ |
| 1370 | +/* Modified by */ |
| 1371 | +/* Jérôme Pouiller */ |
| 1372 | +/***********************/ |
| 1373 | |
| 1374 | /* This is ANSI C code (C89). */ |
| 1375 | |
| 1376 | |
| 1377 | #include "errmsg.h" |
| 1378 | +#include <wchar.h> |
| 1379 | |
| 1380 | - |
| 1381 | -char **reformat( |
| 1382 | - const char * const *inlines, const char * const *endline, int afp, int fs, |
| 1383 | +wchar_t **reformat( |
| 1384 | + const wchar_t * const *inlines, const wchar_t * const *endline, int afp, int fs, |
| 1385 | int hang, int prefix, int suffix, int width, int cap, int fit, int guess, |
| 1386 | int just, int last, int Report, int touch, errmsg_t errmsg |
| 1387 | ); |
| 1388 | --- releasenotes.orig |
| 1389 | +++ releasenotes |
| 1390 | @@ -1,12 +1,23 @@ |
| 1391 | - ********************* |
| 1392 | - * releasenotes * |
| 1393 | - * for Par 1.52 * |
| 1394 | - * Copyright 2001 by * |
| 1395 | - * Adam M. Costello * |
| 1396 | - ********************* |
| 1397 | + *********************** |
| 1398 | + * releasenotes * |
| 1399 | + * for Par 1.52-i18n.3 * |
| 1400 | + * Copyright 2001 by * |
| 1401 | + * Adam M. Costello * |
| 1402 | + * Modified by * |
| 1403 | + * Jérôme Pouiller * |
| 1404 | + *********************** |
| 1405 | |
| 1406 | |
| 1407 | Each entry below describes changes since the previous version. |
| 1408 | +Par 1.52-i18n.3 released 2006-Oct-03 |
| 1409 | + Fix bug with option 'g' |
| 1410 | + |
| 1411 | +Par 1.52-i18n.2 released 2006-Aug-03 |
| 1412 | + Fix bug debian #310495. |
| 1413 | + |
| 1414 | +Par 1.52-i18n.1 released 2006-Jun-22 |
| 1415 | + Changed char in wchar_t. Allow support of multibytes characters. |
| 1416 | + Added support for double-width characters. |
| 1417 | |
| 1418 | Par 1.52 released 2001-Apr-29 |
| 1419 | Fixed a portability problem regarding unsigned char versus char. |