Changes in / [0eaa488:feabce2]
- Files:
-
- 3 added
- 1 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.in
r864ed35 r864ed35 26 26 keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \ 27 27 aim.c buddy.c buddylist.c timer.c style.c errqueue.c \ 28 zbuddylist.c muxevents.c popexec.c obarray.c select.c 28 zbuddylist.c muxevents.c popexec.c obarray.c select.c wcwidth.c \ 29 glib_compat.c 29 30 OWL_SRC = owl.c 30 31 TESTER_SRC = tester.c -
aim.c
re3e6cff re3e6cff 948 948 949 949 if (modname) { 950 if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {950 if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) { 951 951 /* perror("memrequest: malloc"); */ 952 952 return -1; … … 954 954 sprintf(filename, "%s/%s.ocm", priv->aimbinarypath, modname); 955 955 } else { 956 if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {956 if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) { 957 957 /* perror("memrequest: malloc"); */ 958 958 return -1; … … 964 964 if (!modname) { 965 965 /* perror("memrequest: stat"); */ 966 free(filename);966 owl_free(filename); 967 967 return -1; 968 968 } … … 986 986 int i; 987 987 988 free(filename); /* not needed */988 owl_free(filename); /* not needed */ 989 989 owl_function_error("getaimdata memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname); 990 990 i = 8; … … 993 993 } 994 994 995 if (!(buf = malloc(i))) {995 if (!(buf = owl_malloc(i))) { 996 996 return -1; 997 997 } … … 1017 1017 *buflenret = i; 1018 1018 } else { 1019 if (!(buf = malloc(len))) {1020 free(filename);1019 if (!(buf = owl_malloc(len))) { 1020 owl_free(filename); 1021 1021 return -1; 1022 1022 } … … 1024 1024 if (!(f = fopen(filename, "r"))) { 1025 1025 /* perror("memrequest: fopen"); */ 1026 free(filename);1027 free(buf);1026 owl_free(filename); 1027 owl_free(buf); 1028 1028 return -1; 1029 1029 } 1030 1030 1031 free(filename);1031 owl_free(filename); 1032 1032 1033 1033 if (fseek(f, offset, SEEK_SET) == -1) { 1034 1034 /* perror("memrequest: fseek"); */ 1035 1035 fclose(f); 1036 free(buf);1036 owl_free(buf); 1037 1037 return -1; 1038 1038 } … … 1041 1041 /* perror("memrequest: fread"); */ 1042 1042 fclose(f); 1043 free(buf);1043 owl_free(buf); 1044 1044 return -1; 1045 1045 } … … 1076 1076 if (priv->aimbinarypath && (getaimdata(sess, &buf, &buflen, offset, len, modname) == 0)) { 1077 1077 aim_sendmemblock(sess, fr->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); 1078 free(buf);1078 owl_free(buf); 1079 1079 } else { 1080 1080 owl_function_debugmsg("faimtest_memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", priv->aimbinarypath, modname); … … 1342 1342 int z; 1343 1343 1344 newbuf = malloc(i+1);1344 newbuf = owl_malloc(i+1); 1345 1345 for (z = 0; z < i; z++) 1346 1346 newbuf[z] = (z % 10)+0x30; 1347 1347 newbuf[i] = '\0'; 1348 1348 /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_ACK | AIM_IMFLAGS_AWAY, newbuf); */ 1349 free(newbuf);1349 owl_free(newbuf); 1350 1350 } 1351 1351 } else if (strstr(tmpstr, "seticqstatus")) { -
cmd.c
r6922edd r34509d5 74 74 owl_cmd *cmd; 75 75 76 tmpbuff= strdup(cmdbuff);76 tmpbuff=owl_strdup(cmdbuff); 77 77 argv=owl_parseline(tmpbuff, &argc); 78 78 if (argc < 0) { -
config.h.in
r03cf6b9 re23eb2b 22 22 #undef HAVE_LIBCOM_ERR 23 23 24 /* Define to 1 if you have the `curses' library (-lcurses). */25 #undef HAVE_LIBCURSES26 27 24 /* Define to 1 if you have the `des425' library (-ldes425). */ 28 25 #undef HAVE_LIBDES425 … … 39 36 /* Define to 1 if you have the `krb5' library (-lkrb5). */ 40 37 #undef HAVE_LIBKRB5 41 42 /* Define to 1 if you have the `ncurses' library (-lncurses). */43 #undef HAVE_LIBNCURSES44 38 45 39 /* Define to 1 if you have the `ncursesw' library (-lncursesw). */ -
editwin.c
raf1920fd r2d4ff14 143 143 e->buffy=0; 144 144 owl_editwin_overwrite_string(e, text); 145 owl_editwin_overwrite_char(e, '\0'); 145 146 e->lock=strlen(text); 146 147 /* if (text[e->lock-1]=='\n') e->lock--; */ 147 e->buffx=x;148 e->buffy=y;149 owl_editwin_adjust_for_locktext(e);148 /* e->buffx=x; */ 149 /* e->buffy=y; */ 150 _owl_editwin_set_xy_by_index(e, e->lock); 150 151 owl_editwin_redisplay(e, 0); 151 152 } … … 255 256 256 257 /* start at topline */ 257 ptr1 =e->buff;258 for (i =0; i<e->topline; i++) {259 ptr2 =strchr(ptr1, '\n');258 ptr1 = e->buff; 259 for (i = 0; i < e->topline; i++) { 260 ptr2 = strchr(ptr1, '\n'); 260 261 if (!ptr2) { 261 262 /* we're already on the last line */ 262 263 break; 263 264 } 264 ptr1 =ptr2+1;265 ptr1 = ptr2 + 1; 265 266 } 266 267 /* ptr1 now stores the starting point */ 267 268 268 269 /* find the ending point and store it in ptr3 */ 269 ptr2 =ptr1;270 ptr3 =ptr1;271 for (i =0; i<e->winlines; i++) {272 ptr3 =strchr(ptr2, '\n');270 ptr2 = ptr1; 271 ptr3 = ptr1; 272 for (i = 0; i < e->winlines; i++) { 273 ptr3 = strchr(ptr2, '\n'); 273 274 if (!ptr3) { 274 275 /* we've hit the last line */ 275 276 /* print everything to the end */ 276 ptr3 =e->buff+e->bufflen-1;277 ptr3 = e->buff + e->bufflen - 1; 277 278 ptr3--; 278 279 break; 279 280 } 280 ptr2 =ptr3+1;281 } 282 ptr3 +=2;283 284 buff =owl_malloc(ptr3-ptr1+50);285 strncpy(buff, ptr1, ptr3 -ptr1);286 buff[ptr3 -ptr1]='\0';287 if (e->echochar =='\0') {281 ptr2 = ptr3 + 1; 282 } 283 ptr3 += 2; 284 285 buff = owl_malloc(ptr3 - ptr1 + 50); 286 strncpy(buff, ptr1, ptr3 - ptr1); 287 buff[ptr3 - ptr1] = '\0'; 288 if (e->echochar == '\0') { 288 289 waddstr(e->curswin, buff); 289 290 } else { 290 291 /* translate to echochar, *except* for the locktext */ 291 292 int len; 292 int dolocklen=e->lock-(ptr1-e->buff); 293 294 for (i=0; i<dolocklen; i++) { 295 waddch(e->curswin, buff[i]); 296 } 297 len=strlen(buff); 298 for (i=0; i<len-dolocklen; i++) { 293 int dolocklen = e->lock - (ptr1 - e->buff); 294 char *locktext; 295 char tmp = e->buff[dolocklen]; 296 297 e->buff[dolocklen] = '\0'; 298 locktext = owl_strdup(e->buff); 299 e->buff[dolocklen] = tmp; 300 301 waddstr(e->curswin, locktext); 302 303 len = strlen(buff); 304 for (i = 0; i < len-dolocklen; i++) { 299 305 waddch(e->curswin, e->echochar); 300 306 } 301 307 } 302 wmove(e->curswin, e->buffy-e->topline, e->buffx );308 wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e)); 303 309 wnoutrefresh(e->curswin); 304 if (update ==1) {310 if (update == 1) { 305 311 doupdate(); 306 312 } 307 313 owl_free(buff); 314 } 315 316 /* Remove n bytes at cursor. */ 317 void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/ 318 { 319 int i = _owl_editwin_get_index_from_xy(e) + n; 320 for (; i < e->bufflen; i++) { 321 e->buff[i-n] = e->buff[i]; 322 } 323 324 e->bufflen -= n; 325 e->buff[e->bufflen] = '\0'; 326 } 327 328 /* Insert n bytes at cursor.*/ 329 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/ 330 { 331 int i, z; 332 333 if ((e->bufflen + n) > (e->allocated - 5)) { 334 _owl_editwin_addspace(e); 335 } 336 337 e->bufflen += n; 338 e->buff[e->bufflen] = '\0'; 339 340 z = _owl_editwin_get_index_from_xy(e); 341 for (i = e->bufflen - 1; i > z; i--) { 342 e->buff[i] = e->buff[i - n]; 343 } 308 344 } 309 345 … … 315 351 int _owl_editwin_linewrap_word(owl_editwin *e) 316 352 { 317 int i, z; 318 319 z=_owl_editwin_get_index_from_xy(e); 320 /* move back and line wrap the previous word */ 321 for (i=z-1; ; i--) { 322 /* move back until you find a space or hit the beginning of the line */ 323 if (e->buff[i]==' ') { 324 /* replace the space with a newline */ 325 e->buff[i]='\n'; 326 e->buffy++; 327 e->buffx=z-i-1; 328 /* were we on the last line */ 329 return(0); 330 } else if (e->buff[i]=='\n' || i<=e->lock) { 331 /* we hit the begginning of the line or the buffer, we cannot 332 * wrap. 333 */ 334 return(-1); 335 } 336 } 353 int x, y; 354 int i; 355 char *ptr1, *start; 356 gunichar c; 357 358 /* saving values */ 359 x = e->buffx; 360 y = e->buffy; 361 start = e->buff + e->lock; 362 363 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 364 ptr1 = g_utf8_find_prev_char(start, ptr1); 365 366 while (ptr1) { 367 c = g_utf8_get_char(ptr1); 368 if (owl_util_can_break_after(c)) { 369 if (c != ' ') { 370 i = ptr1 - e->buff; 371 _owl_editwin_set_xy_by_index(e, i); 372 _owl_editwin_insert_bytes(e, 1); 373 /* _owl_editwin_insert_bytes may move e->buff. */ 374 ptr1 = e->buff + i; 375 } 376 *ptr1 = '\n'; 377 return 0; 378 } 379 else if (c == '\n') { 380 return 0; 381 } 382 ptr1 = g_utf8_find_prev_char(start, ptr1); 383 } 384 return -1; 337 385 } 338 386 … … 340 388 * characters over) 341 389 */ 342 void owl_editwin_insert_char(owl_editwin *e, char c) 343 { 344 345 int z, i, ret; 390 void owl_editwin_insert_char(owl_editwin *e, gunichar c) 391 { 392 int z, i, ret, len; 393 char tmp[6]; 394 memset(tmp, '\0', 6); 346 395 347 396 /* \r is \n */ 348 if (c =='\r') {349 c ='\n';350 } 351 352 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {397 if (c == '\r') { 398 c = '\n'; 399 } 400 401 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 353 402 /* perhaps later this will change some state that allows the string 354 403 to be read */ … … 356 405 } 357 406 407 g_unichar_to_utf8(c, tmp); 408 len = strlen(tmp); 409 358 410 /* make sure there is enough memory for the new text */ 359 if ((e->bufflen +1) > (e->allocated-5)) {411 if ((e->bufflen + len) > (e->allocated - 5)) { 360 412 _owl_editwin_addspace(e); 361 413 } 362 414 363 415 /* get the insertion point */ 364 z =_owl_editwin_get_index_from_xy(e);416 z = _owl_editwin_get_index_from_xy(e); 365 417 366 418 /* If we're going to insert at the last column do word wrapping, unless it's a \n */ 367 if ((e->buffx +1==e->wrapcol) && (c!='\n')) {368 ret =_owl_editwin_linewrap_word(e);369 if (ret ==-1) {419 if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) { 420 ret = _owl_editwin_linewrap_word(e); 421 if (ret == -1) { 370 422 /* we couldn't wrap, insert a hard newline instead */ 371 423 owl_editwin_insert_char(e, '\n'); … … 373 425 } 374 426 375 z=_owl_editwin_get_index_from_xy(e);376 427 /* shift all the other characters right */ 377 for (i=e->bufflen; i>z; i--) { 378 e->buff[i]=e->buff[i-1]; 379 } 380 381 /* insert the new one */ 382 e->buff[z]=c; 428 if (z != e->bufflen) { 429 _owl_editwin_insert_bytes(e, len); 430 } 431 432 /* insert the new character */ 433 for(i = 0; i < len; i++) { 434 e->buff[z + i] = tmp[i]; 435 } 383 436 384 437 /* housekeeping */ 385 e->bufflen ++;386 e->buff[e->bufflen] ='\0';387 438 e->bufflen += len; 439 e->buff[e->bufflen] = '\0'; 440 388 441 /* advance the cursor */ 389 if (c=='\n') { 390 e->buffx=0; 391 e->buffy++; 392 } else { 393 e->buffx++; 394 } 442 z += len; 443 _owl_editwin_set_xy_by_index(e, z); 395 444 } 396 445 397 446 /* overwrite the character at the current point with 'c' */ 398 void owl_editwin_overwrite_char(owl_editwin *e, char c) 399 { 400 int z; 401 447 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c) 448 { 449 int z, oldlen, newlen, i; 450 char tmp[6]; 451 memset(tmp, '\0', 6); 452 402 453 /* \r is \n */ 403 if (c =='\r') {404 c ='\n';405 } 406 407 if (c =='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {454 if (c == '\r') { 455 c = '\n'; 456 } 457 458 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 408 459 /* perhaps later this will change some state that allows the string 409 460 to be read */ … … 411 462 } 412 463 413 z=_owl_editwin_get_index_from_xy(e); 414 415 /* only if we are at the end of the buffer do we create new space */ 416 if (z==e->bufflen) { 417 if ((e->bufflen+1) > (e->allocated-5)) { 464 g_unichar_to_utf8(c, tmp); 465 newlen = strlen(tmp); 466 467 z = _owl_editwin_get_index_from_xy(e); 468 { 469 char *t = g_utf8_find_next_char(e->buff + z, NULL); 470 oldlen = (t ? (t - (e->buff + z)) : 0); 471 } 472 473 /* only if we are at the end of the buffer do we create new space here */ 474 if (z == e->bufflen) { 475 if ((e->bufflen+newlen) > (e->allocated-5)) { 418 476 _owl_editwin_addspace(e); 419 477 } 420 478 } 421 422 e->buff[z]=c; 423 424 /* housekeeping if we are at the end of the buffer */ 425 if (z==e->bufflen) { 426 e->bufflen++; 427 e->buff[e->bufflen]='\0'; 428 } 429 479 /* if not at the end of the buffer, adjust based in char size difference. */ 480 else if (oldlen > newlen) { 481 _owl_editwin_remove_bytes(e, oldlen-newlen); 482 } 483 else /* oldlen < newlen */ { 484 _owl_editwin_insert_bytes(e, newlen-oldlen); 485 } 486 /* Overwrite the old char*/ 487 for (i = 0; i < newlen; i++) { 488 e->buff[z+i] = tmp[i]; 489 } 490 491 /* housekeeping */ 492 if (z == e->bufflen) { 493 e->bufflen += newlen; 494 e->buff[e->bufflen] = '\0'; 495 } 496 430 497 /* advance the cursor */ 431 if (c=='\n') { 432 e->buffx=0; 433 e->buffy++; 434 } else { 435 e->buffx++; 436 } 437 498 z += newlen; 499 _owl_editwin_set_xy_by_index(e, z); 438 500 } 439 501 … … 443 505 void owl_editwin_delete_char(owl_editwin *e) 444 506 { 445 int z, i; 446 447 if (e->bufflen==0) return; 507 int z; 508 char *p1, *p2; 509 gunichar c; 510 511 if (e->bufflen == 0) return; 448 512 449 513 /* get the deletion point */ 450 z=_owl_editwin_get_index_from_xy(e); 451 452 if (z==e->bufflen) return; 453 454 for (i=z; i<e->bufflen; i++) { 455 e->buff[i]=e->buff[i+1]; 456 } 457 e->bufflen--; 458 e->buff[e->bufflen]='\0'; 514 z = _owl_editwin_get_index_from_xy(e); 515 516 if (z == e->bufflen) return; 517 518 p1 = e->buff + z; 519 p2 = g_utf8_next_char(p1); 520 c = g_utf8_get_char(p2); 521 while (g_unichar_ismark(c)) { 522 p2 = g_utf8_next_char(p2); 523 c = g_utf8_get_char(p2); 524 } 525 _owl_editwin_remove_bytes(e, p2-p1); 459 526 } 460 527 … … 467 534 { 468 535 int z; 469 char tmp;470 471 if (e->bufflen ==0) return;536 char *p1, *p2, *p3, *tmp; 537 538 if (e->bufflen == 0) return; 472 539 473 540 /* get the cursor point */ 474 z =_owl_editwin_get_index_from_xy(e);475 476 if (z ==e->bufflen) {541 z = _owl_editwin_get_index_from_xy(e); 542 543 if (z == e->bufflen) { 477 544 /* point is after last character */ 478 545 z--; 479 546 } 480 547 481 if (z -1 < e->lock) {548 if (z - 1 < e->lock) { 482 549 /* point is at beginning of buffer, do nothing */ 483 550 return; 484 551 } 485 552 486 tmp=e->buff[z]; 487 e->buff[z]=e->buff[z-1]; 488 e->buff[z-1]=tmp; 489 owl_editwin_key_right(e); 553 /* Transpose two utf-8 unicode glyphs. */ 554 p1 = e->buff + z; 555 556 p2 = g_utf8_find_next_char(p1, NULL); 557 while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) { 558 p2 = g_utf8_find_next_char(p2, NULL); 559 } 560 if (p2 == NULL) return; 561 562 p3 = g_utf8_find_prev_char(e->buff, p1); 563 while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) { 564 p3 = g_utf8_find_prev_char(p3, NULL); 565 } 566 if (p3 == NULL) return; 567 568 tmp = owl_malloc(p2 - p3 + 5); 569 *tmp = '\0'; 570 strncat(tmp, p1, p2 - p1); 571 strncat(tmp, p3, p1 - p3); 572 strncpy(p3, tmp, p2 - p3); 573 owl_free(tmp); 574 _owl_editwin_set_xy_by_index(e, p3 - e->buff); 490 575 } 491 576 … … 495 580 void owl_editwin_insert_string(owl_editwin *e, char *string) 496 581 { 497 int i, j; 498 499 j=strlen(string); 500 for (i=0; i<j; i++) { 501 owl_editwin_insert_char(e, string[i]); 582 char *p; 583 gunichar c; 584 if (!g_utf8_validate(string, -1, NULL)) { 585 owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); 586 return; 587 } 588 p = string; 589 c = g_utf8_get_char(p); 590 while (c) { 591 _owl_editwin_process_char(e, c); 592 p = g_utf8_next_char(p); 593 c = g_utf8_get_char(p); 502 594 } 503 595 } … … 509 601 void owl_editwin_overwrite_string(owl_editwin *e, char *string) 510 602 { 511 int i, j; 512 513 j=strlen(string); 514 for (i=0; i<j; i++) { 515 owl_editwin_overwrite_char(e, string[i]); 603 char *p; 604 gunichar c; 605 606 if (!g_utf8_validate(string, -1, NULL)) { 607 owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string."); 608 return; 609 } 610 p = string; 611 c = g_utf8_get_char(p); 612 while (c) { 613 owl_editwin_overwrite_char(e, c); 614 p = g_utf8_next_char(p); 615 c = g_utf8_get_char(p); 516 616 } 517 617 } … … 524 624 int i; 525 625 char *ptr1, *ptr2; 526 527 if (e->bufflen==0) return(0); 626 gunichar c; 627 628 if (e->bufflen == 0) return(0); 528 629 529 630 /* first go to the yth line */ 530 ptr1 =e->buff;531 for (i =0; i<e->buffy; i++) {532 ptr2= strchr(ptr1, '\n');631 ptr1 = e->buff; 632 for (i = 0; i < e->buffy; i++) { 633 ptr2= strchr(ptr1, '\n'); 533 634 if (!ptr2) { 534 635 /* we're already on the last line */ 535 636 break; 536 637 } 537 ptr1=ptr2+1; 538 } 539 540 /* now go to the xth character */ 541 ptr2=strchr(ptr1, '\n'); 542 if (!ptr2) { 543 ptr2=e->buff+e->bufflen; 544 } 545 546 if ((ptr2-ptr1) < e->buffx) { 547 ptr1=ptr2-1; 548 } else { 549 ptr1+=e->buffx; 550 } 551 552 /* printf("DEBUG: index is %i\r\n", ptr1-e->buff); */ 553 return(ptr1-e->buff); 554 } 638 ptr1 = ptr2 + 1; 639 } 640 641 /* now go to the xth cell */ 642 ptr2 = ptr1; 643 i = 0; 644 while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) { 645 c = g_utf8_get_char(ptr2); 646 i += (c == '\n' ? 1 : mk_wcwidth(c)); 647 ptr2 = g_utf8_next_char(ptr2); 648 } 649 while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) { 650 ptr2 = g_utf8_next_char(ptr2); 651 } 652 if (ptr2 == NULL) return e->bufflen; 653 return(ptr2 - e->buff); 654 } 655 656 /* We assume x,y are not set to point to a mid-char */ 657 gunichar _owl_editwin_get_char_at_xy(owl_editwin *e) 658 { 659 return g_utf8_get_char(e->buff + _owl_editwin_get_index_from_xy(e)); 660 } 661 555 662 556 663 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 557 664 { 558 int z, i; 559 560 z=_owl_editwin_get_index_from_xy(e); 561 if (index>z) { 562 for (i=0; i<index-z; i++) { 563 owl_editwin_key_right(e); 564 } 565 } else if (index<z) { 566 for (i=0; i<z-index; i++) { 567 owl_editwin_key_left(e); 568 } 569 } 665 char *ptr1, *ptr2, *target; 666 gunichar c; 667 668 e->buffx = 0; 669 e->buffy = 0; 670 671 ptr1 = e->buff; 672 target = ptr1 + index; 673 /* target sanitizing */ 674 if ((target[0] & 0x80) && (~target[0] & 0x40)) { 675 /* middle of a utf-8 character, back up to previous character. */ 676 target = g_utf8_find_prev_char(e->buff, target); 677 } 678 c = g_utf8_get_char(target); 679 while (g_unichar_ismark(c) && target > e->buff) { 680 /* Adjust the target off of combining characters and the like. */ 681 target = g_utf8_find_prev_char(e->buff, target); 682 c = g_utf8_get_char(target); 683 } 684 /* If we start with a mark, something is wrong.*/ 685 if (g_unichar_ismark(c)) return; 686 687 /* Now our target should be acceptable. */ 688 ptr2 = strchr(ptr1, '\n'); 689 while (ptr2 != NULL && ptr2 < target) { 690 e->buffy++; 691 ptr1 = ptr2 + 1; 692 ptr2 = strchr(ptr1, '\n'); 693 } 694 ptr2 = ptr1; 695 while (ptr2 != NULL && ptr2 < target) { 696 c = g_utf8_get_char(ptr2); 697 e->buffx += mk_wcwidth(c); 698 ptr2 = g_utf8_next_char(ptr2); 699 } 700 } 701 702 int _owl_editwin_cursor_adjustment(owl_editwin *e) 703 { 704 char *ptr1, *ptr2; 705 gunichar c; 706 int x, i; 707 708 /* Find line */ 709 ptr1 = e->buff; 710 ptr2 = strchr(ptr1, '\n'); 711 for (i = 0; ptr2 != NULL && i < e->buffy; i++) { 712 ptr1 = ptr2 + 1; 713 ptr2 = strchr(ptr1, '\n'); 714 } 715 ptr2 = ptr1; 716 717 /* Find char */ 718 x = 0; 719 while (ptr2 != NULL && x < e->buffx) { 720 if (*ptr2 == '\n') return 0; 721 c = g_utf8_get_char(ptr2); 722 x += mk_wcwidth(c); 723 ptr2 = g_utf8_next_char(ptr2); 724 } 725 726 /* calculate x offset */ 727 return x - e->buffx; 570 728 } 571 729 … … 574 732 /* if we happen to have the cursor over locked text 575 733 * move it to be out of the locktext region */ 576 if (_owl_editwin_get_index_from_xy(e) <e->lock) {734 if (_owl_editwin_get_index_from_xy(e) < e->lock) { 577 735 _owl_editwin_set_xy_by_index(e, e->lock); 578 736 } … … 594 752 { 595 753 if (e->buffy > 0) e->buffy--; 596 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {597 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);754 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 755 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 598 756 } 599 757 … … 612 770 613 771 /* if we're past the last character move back */ 614 if (e->buffx >= owl_editwin_get_numc hars_on_line(e, e->buffy)) {615 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);772 if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) { 773 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 616 774 } 617 775 … … 627 785 void owl_editwin_key_left(owl_editwin *e) 628 786 { 629 /* move left if we can, and maybe up a line */ 630 if (e->buffx>0) { 631 e->buffx--; 632 } else if (e->buffy>0) { 633 e->buffy--; 634 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 635 } 636 637 /* do we need to scroll up? */ 638 if (e->buffy-e->topline < 0) { 639 e->topline-=e->winlines/2; 787 int i; 788 char * p; 789 i = _owl_editwin_get_index_from_xy(e); 790 p = e->buff + i; 791 p = g_utf8_find_prev_char(e->buff, p); 792 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 793 p = g_utf8_find_prev_char(e->buff, p); 794 } 795 if (p == NULL) p = e->buff; 796 _owl_editwin_set_xy_by_index(e, p - e->buff); 797 798 if (e->buffy - e->topline < 0) { 799 e->topline -= e->winlines / 2; 640 800 } 641 801 … … 647 807 { 648 808 int i; 649 650 /* move right if we can, and skip down a line if needed */ 651 i=owl_editwin_get_numchars_on_line(e, e->buffy); 652 if (e->buffx < i) { 653 e->buffx++; 654 /* } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { */ 655 } else if (_owl_editwin_get_index_from_xy(e) < e->bufflen) { 656 if (e->style==OWL_EDITWIN_STYLE_MULTILINE) { 657 e->buffx=0; 658 e->buffy++; 659 } 809 char * p; 810 i = _owl_editwin_get_index_from_xy(e); 811 p = e->buff + i; 812 p = g_utf8_find_next_char(p, NULL); 813 while (p && g_unichar_ismark(g_utf8_get_char(p))) { 814 p = g_utf8_find_next_char(p, NULL); 815 } 816 if (p == NULL) { 817 _owl_editwin_set_xy_by_index(e, e->bufflen); 818 } 819 else { 820 _owl_editwin_set_xy_by_index(e, p - e->buff); 660 821 } 661 822 662 823 /* do we need to scroll down? */ 663 if (e->buffy -e->topline >= e->winlines) {664 e->topline +=e->winlines/2;824 if (e->buffy - e->topline >= e->winlines) { 825 e->topline += e->winlines / 2; 665 826 } 666 827 } … … 669 830 { 670 831 int i, x; 832 gunichar c = '\0'; 671 833 672 834 /* if we're starting on a space, find the first non-space */ … … 681 843 } 682 844 683 /* find the next space, newline or end of line and go there, if 684 already at the end of the line, continue on to the next */ 685 i=owl_editwin_get_numchars_on_line(e, e->buffy); 845 /* find the next space, newline or end of line and go 846 there, if already at the end of the line, continue on to the next */ 847 i=owl_editwin_get_numcells_on_line(e, e->buffy); 848 c = _owl_editwin_get_char_at_xy(e); 686 849 if (e->buffx < i) { 687 850 /* move right till end of line */ 688 851 while (e->buffx < i) { 689 e->buffx++; 690 if (e->buff[_owl_editwin_get_index_from_xy(e)]==' ') return; 852 owl_editwin_key_right(e); 853 c = _owl_editwin_get_char_at_xy(e); 854 if (c == ' ') return; 691 855 if (e->buffx == i) return; 692 856 } … … 694 858 /* try to move down */ 695 859 if (e->style==OWL_EDITWIN_STYLE_MULTILINE) { 696 if (e->buffy+1 < 860 if (e->buffy+1 < owl_editwin_get_numlines(e)) { 697 861 e->buffx=0; 698 862 e->buffy++; … … 707 871 void owl_editwin_move_to_previousword(owl_editwin *e) 708 872 { 709 int i, x; 873 int i; 874 gunichar c; 875 char *ptr1, *ptr2; 710 876 711 877 /* are we already at the beginning of the word? */ 712 i=_owl_editwin_get_index_from_xy(e); 713 if ( (e->buff[i]!=' ' && e->buff[i]!='\n' && e->buff[i]!='\0') && 714 (e->buff[i-1]==' ' || e->buff[i-1]=='\n') ) { 878 c = _owl_editwin_get_char_at_xy(e); 879 i = _owl_editwin_get_index_from_xy(e); 880 ptr1 = e->buff + i; 881 if (*ptr1 != ' ' && *ptr1 != '\n' && *ptr1 != '\0' ) { 882 ptr1 = g_utf8_find_prev_char(e->buff, ptr1); 883 c = g_utf8_get_char(ptr1); 884 if (c == ' ' || c == '\n') { 885 owl_editwin_key_left(e); 886 } 887 } 888 889 /* are we starting on a space character? */ 890 i = _owl_editwin_get_index_from_xy(e); 891 while (i > e->lock && (e->buff[i] == ' ' || e->buff[i] == '\n' || e->buff[i] == '\0')) { 892 /* find the first non-space */ 893 owl_editwin_key_left(e); 894 i = _owl_editwin_get_index_from_xy(e); 895 } 896 897 /* find the last non-space */ 898 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 899 while (ptr1 >= e->buff + e->lock) { 900 ptr2 = g_utf8_find_prev_char(e->buff, ptr1); 901 if (!ptr2) break; 902 903 c = g_utf8_get_char(ptr2); 904 if (c == ' ' || c == '\n'){ 905 break; 906 } 715 907 owl_editwin_key_left(e); 716 } 717 718 /* are we starting on a space character? */ 719 i=_owl_editwin_get_index_from_xy(e); 720 if (e->buff[i]==' ' || e->buff[i]=='\n' || e->buff[i]=='\0') { 721 /* find the first non-space */ 722 for (x=i; x>=e->lock; x--) { 723 if (e->buff[x]!=' ' && e->buff[x]!='\n' && e->buff[x]!='\0') { 724 _owl_editwin_set_xy_by_index(e, x); 725 break; 726 } 727 } 728 } 729 730 /* find the last non-space */ 731 i=_owl_editwin_get_index_from_xy(e); 732 for (x=i; x>=e->lock; x--) { 733 if (e->buff[x-1]==' ' || e->buff[x-1]=='\n') { 734 _owl_editwin_set_xy_by_index(e, x); 735 break; 736 } 737 } 738 _owl_editwin_set_xy_by_index(e, x); 908 ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 909 } 739 910 } 740 911 … … 742 913 void owl_editwin_delete_nextword(owl_editwin *e) 743 914 { 744 int z; 915 char *ptr1, *start; 916 gunichar c; 745 917 746 918 if (e->bufflen==0) return; 747 919 748 /* if we start out on a space character then gobble all the spaces 749 up first */ 750 while (1) { 751 z=_owl_editwin_get_index_from_xy(e); 752 if (e->buff[z]==' ' || e->buff[z]=='\n') { 753 owl_editwin_delete_char(e); 754 } else { 755 break; 756 } 757 } 758 759 /* then nuke the next word */ 760 while (1) { 761 z=_owl_editwin_get_index_from_xy(e); 762 /* z == e->bufflen check added to prevent a hang I (nelhage) have 763 seen repeatedly while using owl. I'm not sure precisely what 764 conditions lead to it. */ 765 if (z == e->bufflen 766 || e->buff[z+1]==' ' || e->buff[z+1]=='\n' || e->buff[z+1]=='\0') break; 767 owl_editwin_delete_char(e); 768 } 769 owl_editwin_delete_char(e); 920 start = ptr1 = e->buff + _owl_editwin_get_index_from_xy(e); 921 /* if we start out on a space character then jump past all the 922 spaces up first */ 923 while (*ptr1 == ' ' || *ptr1 == '\n') { 924 ++ptr1; 925 } 926 927 /* then jump past the next word */ 928 929 while (ptr1 && ptr1 - e->buff < e->bufflen) { 930 c = g_utf8_get_char(ptr1); 931 if (c == ' ' || c == '\n' || c == '\0') break; 932 ptr1 = g_utf8_find_next_char(ptr1, NULL); 933 } 934 935 if (ptr1) { /* We broke on a space, */ 936 ptr1 = g_utf8_find_next_char(ptr1, NULL); 937 if (ptr1) { /* and there's a character after it, */ 938 /* nuke everything back to our starting point. */ 939 _owl_editwin_remove_bytes(e, ptr1 - start); 940 return; 941 } 942 } 943 944 /* If we get here, we ran out of string, drop what's left. */ 945 *start = '\0'; 946 e->bufflen = start - e->buff; 770 947 } 771 948 … … 773 950 { 774 951 /* go backwards to the last non-space character, then delete chars */ 775 int i,startpos, endpos;952 int startpos, endpos; 776 953 777 954 startpos = _owl_editwin_get_index_from_xy(e); 778 955 owl_editwin_move_to_previousword(e); 779 956 endpos = _owl_editwin_get_index_from_xy(e); 780 for (i=0; i<startpos-endpos; i++) { 781 owl_editwin_delete_char(e); 782 } 957 _owl_editwin_remove_bytes(e, startpos-endpos); 783 958 } 784 959 … … 787 962 int i; 788 963 789 if (owl_editwin_get_numchars_on_line(e, e->buffy) >e->buffx) {964 if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) { 790 965 /* normal line */ 791 966 i=_owl_editwin_get_index_from_xy(e); … … 808 983 void owl_editwin_move_to_line_end(owl_editwin *e) 809 984 { 810 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);985 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 811 986 } 812 987 … … 821 996 /* go to last char */ 822 997 e->buffy=owl_editwin_get_numlines(e)-1; 823 e->buffx=owl_editwin_get_numc hars_on_line(e, e->buffy);998 e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy); 824 999 owl_editwin_key_right(e); 825 1000 … … 861 1036 /* main loop */ 862 1037 while (1) { 863 i =_owl_editwin_get_index_from_xy(e);1038 i = _owl_editwin_get_index_from_xy(e); 864 1039 865 1040 /* bail if we hit the end of the buffer */ 866 if (i >=e->bufflen) break;1041 if (i >= e->bufflen || e->buff[i] == '\0') break; 867 1042 868 1043 /* bail if we hit the end of the paragraph */ 869 if (e->buff[i] =='\n' && e->buff[i+1]=='\n') break;1044 if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break; 870 1045 871 1046 /* if we've travelled too far, linewrap */ 872 1047 if ((e->buffx) >= e->fillcol) { 1048 int len = e->bufflen; 873 1049 _owl_editwin_linewrap_word(e); 1050 /* we may have added a character. */ 1051 if (i < save) save += e->bufflen - len; 1052 _owl_editwin_set_xy_by_index(e, i); 874 1053 } 875 1054 876 1055 /* did we hit the end of a line too soon? */ 877 i=_owl_editwin_get_index_from_xy(e); 878 if (e->buff[i]=='\n' && e->buffx<e->fillcol-1) { 1056 /* asedeno: Here we replace a newline with a space. We may want to 1057 consider removing the space if the characters to either side 1058 are CJK ideograms.*/ 1059 i = _owl_editwin_get_index_from_xy(e); 1060 if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) { 879 1061 /* ********* we need to make sure we don't pull in a word that's too long ***********/ 880 1062 e->buff[i]=' '; 881 1063 } 882 1064 883 1065 /* fix spacing */ 884 i =_owl_editwin_get_index_from_xy(e);885 if (e->buff[i] ==' ' && e->buff[i+1]==' ') {886 if (e->buff[i-1] =='.' || e->buff[i-1]=='!' || e->buff[i-1]=='?') {1066 i = _owl_editwin_get_index_from_xy(e); 1067 if (e->buff[i] == ' ' && e->buff[i+1] == ' ') { 1068 if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') { 887 1069 owl_editwin_key_right(e); 888 1070 } else { 889 1071 owl_editwin_delete_char(e); 890 /* if we did this ahead of the save point, adjust it */ 891 if (i<save) save--; 1072 /* if we did this ahead of the save point, adjust it. Changing 1073 by one is fine here because we're only removing an ASCII 1074 space. */ 1075 if (i < save) save--; 892 1076 } 893 1077 } else { 894 1078 owl_editwin_key_right(e); 895 1079 } 896 897 1080 } 898 1081 … … 915 1098 int owl_editwin_check_dotsend(owl_editwin *e) 916 1099 { 917 int i; 1100 char *p, *p_n, *p_p; 1101 gunichar c; 918 1102 919 1103 if (!e->dotsend) return(0); 920 for (i=e->bufflen-1; i>0; i--) { 921 if (e->buff[i] == '.' 922 && (e->buff[i-1] == '\n' || e->buff[i-1] == '\r') 923 && (e->buff[i+1] == '\n' || e->buff[i+1] == '\r')) { 924 e->bufflen = i; 925 e->buff[i] = '\0'; 1104 1105 p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen); 1106 p_n = g_utf8_find_next_char(p, NULL); 1107 p_p = g_utf8_find_prev_char(e->buff, p); 1108 c = g_utf8_get_char(p); 1109 while (p != NULL) { 1110 if (*p == '.' 1111 && p_p != NULL && (*p_p == '\n' || *p_p == '\r') 1112 && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) { 1113 e->bufflen = p - e->buff; 1114 e->buff[e->bufflen] = '\0'; 926 1115 return(1); 927 1116 } 928 if (!isspace((int) e->buff[i])) { 929 return(0); 930 } 1117 if (c != '\0' && !g_unichar_isspace(c)) return(0); 1118 p_n = p; 1119 p = p_p; 1120 c = g_utf8_get_char(p); 1121 p_p = g_utf8_find_prev_char(e->buff, p); 931 1122 } 932 1123 return(0); 933 1124 } 934 1125 935 void owl_editwin_post_process_char(owl_editwin *e, int j)1126 void owl_editwin_post_process_char(owl_editwin *e, owl_input j) 936 1127 { 937 1128 /* check if we need to scroll down */ … … 939 1130 e->topline+=e->winlines/2; 940 1131 } 941 if ((j ==13 || j==10) && owl_editwin_check_dotsend(e)) {1132 if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) { 942 1133 owl_command_editmulti_done(e); 943 1134 return; … … 946 1137 } 947 1138 948 void owl_editwin_process_char(owl_editwin *e, int j) 949 { 950 if (j == ERR) return; 951 if (j>127 || ((j<32) && (j!=10) && (j!=13))) { 952 return; 953 } else { 1139 void _owl_editwin_process_char(owl_editwin *e, gunichar j) 1140 { 1141 if (!(g_unichar_iscntrl(j) && (j != 10) && (j != 13))) { 954 1142 owl_editwin_insert_char(e, j); 1143 } 1144 } 1145 1146 1147 void owl_editwin_process_char(owl_editwin *e, owl_input j) 1148 { 1149 if (j.ch == ERR) return; 1150 /* Ignore ncurses control characters. */ 1151 if (j.ch < 0x100) { 1152 _owl_editwin_process_char(e, j.uch); 955 1153 } 956 1154 } … … 979 1177 } 980 1178 981 /* now go to the xth character */ 982 ptr2=strchr(ptr1, '\n'); 983 if (!ptr2) { 984 return(e->buff + e->bufflen - ptr1); 985 } 986 return(ptr2-ptr1); /* don't count the newline for now */ 1179 /* now count characters */ 1180 i = 0; 1181 ptr2 = ptr1; 1182 while (ptr2 - e->buff < e->bufflen 1183 && *ptr2 != '\n') { 1184 ++i; 1185 ptr2 = g_utf8_next_char(ptr2); 1186 } 1187 return i; 1188 } 1189 1190 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line) 1191 { 1192 int i; 1193 char *ptr1, *ptr2; 1194 gunichar c; 1195 1196 if (e->bufflen==0) return(0); 1197 1198 /* first go to the yth line */ 1199 ptr1=e->buff; 1200 for (i=0; i<line; i++) { 1201 ptr2=strchr(ptr1, '\n'); 1202 if (!ptr2) { 1203 /* we're already on the last line */ 1204 return(0); 1205 } 1206 ptr1=ptr2+1; 1207 } 1208 1209 /* now count cells */ 1210 i = 0; 1211 ptr2 = ptr1; 1212 while (ptr2 - e->buff < e->bufflen 1213 && *ptr2 != '\n') { 1214 c = g_utf8_get_char(ptr2); 1215 i += mk_wcwidth(c); 1216 ptr2 = g_utf8_next_char(ptr2); 1217 } 1218 return i; 987 1219 } 988 1220 -
fmtext.c
r005fc22 r6f6330b 8 8 void owl_fmtext_init_null(owl_fmtext *f) 9 9 { 10 f->textlen=0; 11 f->bufflen=5; 12 f->textbuff=owl_malloc(5); 13 f->fmbuff=owl_malloc(5); 14 f->fgcolorbuff=owl_malloc(5 * sizeof(short)); 15 f->bgcolorbuff=owl_malloc(5 * sizeof(short)); 16 f->textbuff[0]=0; 17 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 18 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 19 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 10 f->textlen = 0; 11 f->bufflen = 5; 12 f->textbuff = owl_malloc(5); 13 f->textbuff[0] = 0; 14 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 15 f->default_fgcolor = OWL_COLOR_DEFAULT; 16 f->default_bgcolor = OWL_COLOR_DEFAULT; 20 17 } 21 18 … … 24 21 void owl_fmtext_clear(owl_fmtext *f) 25 22 { 26 f->textlen = 0; 27 f->textbuff[0] = 0; 28 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 29 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 30 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 31 } 32 33 /* Internal function. Set the attribute 'attr' from index 'first' to 34 * index 'last' 35 */ 36 void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last) 37 { 38 int i; 39 for (i=first; i<=last; i++) { 40 f->fmbuff[i]=(unsigned char) attr; 41 } 42 } 43 44 /* Internal function. Add the attribute 'attr' to the existing 45 * attributes from index 'first' to index 'last' 46 */ 47 void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) 48 { 49 int i; 50 for (i=first; i<=last; i++) { 51 f->fmbuff[i]|=(unsigned char) attr; 52 } 53 } 54 55 /* Internal function. Set the color to be 'color' from index 'first' 56 * to index 'last 57 */ 58 void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last) 59 { 60 int i; 61 for (i=first; i<=last; i++) { 62 f->fgcolorbuff[i]=(short)color; 63 } 64 } 65 66 void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last) 67 { 68 int i; 69 for (i=first; i<=last; i++) { 70 f->bgcolorbuff[i]=(short)color; 71 } 23 f->textlen = 0; 24 f->textbuff[0] = 0; 25 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 26 f->default_fgcolor = OWL_COLOR_DEFAULT; 27 f->default_bgcolor = OWL_COLOR_DEFAULT; 72 28 } 73 29 … … 75 31 { 76 32 if(newlen + 1 > f->bufflen) { 77 f->textbuff=owl_realloc(f->textbuff, newlen+1); 78 f->fmbuff=owl_realloc(f->fmbuff, newlen+1); 79 f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short)); 80 f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short)); 33 f->textbuff = owl_realloc(f->textbuff, newlen + 1); 81 34 f->bufflen = newlen+1; 82 35 } 83 36 } 84 37 38 int owl_fmtext_is_format_char(gunichar c) 39 { 40 if ((c & ~OWL_FMTEXT_UC_ATTR_MASK) == OWL_FMTEXT_UC_ATTR) return 1; 41 if ((c & ~(OWL_FMTEXT_UC_ALLCOLOR_MASK)) == OWL_FMTEXT_UC_COLOR_BASE) return 1; 42 return 0; 43 } 85 44 /* append text to the end of 'f' with attribute 'attr' and color 86 45 * 'color' 87 46 */ 88 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor) 89 { 90 int newlen; 91 newlen=strlen(f->textbuff)+strlen(text); 47 void owl_fmtext_append_attr(owl_fmtext *f, char *text, char attr, short fgcolor, short bgcolor) 48 { 49 char attrbuff[6]; 50 int newlen, a = 0, fg = 0, bg = 0; 51 52 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 53 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 54 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 55 56 /* Plane-16 characters in UTF-8 are 4 bytes long. */ 57 newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg)); 92 58 _owl_fmtext_realloc(f, newlen); 59 60 /* Set attributes */ 61 if (a) { 62 memset(attrbuff,0,6); 63 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff); 64 strcat(f->textbuff, attrbuff); 65 } 66 if (fg) { 67 memset(attrbuff,0,6); 68 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff); 69 strcat(f->textbuff, attrbuff); 70 } 71 if (bg) { 72 memset(attrbuff,0,6); 73 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff); 74 strcat(f->textbuff, attrbuff); 75 } 93 76 94 77 strcat(f->textbuff, text); 95 _owl_fmtext_set_attr(f, attr, f->textlen, newlen); 96 _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen); 97 _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen); 78 79 /* Reset attributes */ 80 if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT); 81 if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT); 82 if (a) strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE); 98 83 f->textlen=newlen; 99 84 } … … 129 114 } 130 115 131 /* Add the attribute 'attr' to alltext in 'f' */132 void owl_fmtext_addattr(owl_fmtext *f, intattr)116 /* Add the attribute 'attr' to the default atts for the text in 'f' */ 117 void owl_fmtext_addattr(owl_fmtext *f, char attr) 133 118 { 134 119 /* add the attribute to all text */ 135 int i, j; 136 137 j=f->textlen; 138 for (i=0; i<j; i++) { 139 f->fmbuff[i] |= attr; 140 } 141 } 142 143 /* Anywhere the color is NOT ALREDY SET, set the color to 'color'. 144 * Other colors are left unchanged 120 f->default_attrs |= attr; 121 } 122 123 /* Set the default foreground color for this fmtext to 'color'. 124 * Only affects text that is colored default. 145 125 */ 146 126 void owl_fmtext_colorize(owl_fmtext *f, int color) 147 127 { 148 /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 149 int i, j; 150 151 j=f->textlen; 152 for(i=0; i<j; i++) { 153 if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color; 154 } 155 } 156 128 f->default_fgcolor = color; 129 } 130 131 /* Set the default foreground color for this fmtext to 'color'. 132 * Only affects text that is colored default. 133 */ 157 134 void owl_fmtext_colorizebg(owl_fmtext *f, int color) 158 135 { 159 /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 160 int i, j; 161 162 j=f->textlen; 163 for(i=0; i<j; i++) { 164 if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color; 165 } 166 } 136 f->default_bgcolor = color; 137 } 138 139 /* Internal function. Parse attrbute character. */ 140 void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 141 { 142 if ((c & OWL_FMTEXT_UC_ATTR) == OWL_FMTEXT_UC_ATTR) { 143 *attr = c & OWL_FMTEXT_UC_ATTR_MASK; 144 } 145 else if ((c & OWL_FMTEXT_UC_COLOR_BASE) == OWL_FMTEXT_UC_COLOR_BASE) { 146 if ((c & OWL_FMTEXT_UC_BGCOLOR) == OWL_FMTEXT_UC_BGCOLOR) { 147 *bgcolor = (c == OWL_FMTEXT_UC_BGDEFAULT 148 ? OWL_COLOR_DEFAULT 149 : c & OWL_FMTEXT_UC_COLOR_MASK); 150 } 151 else if ((c & OWL_FMTEXT_UC_FGCOLOR) == OWL_FMTEXT_UC_FGCOLOR) { 152 *fgcolor = (c == OWL_FMTEXT_UC_FGDEFAULT 153 ? OWL_COLOR_DEFAULT 154 : c & OWL_FMTEXT_UC_COLOR_MASK); 155 } 156 } 157 } 158 159 /* Internal function. Scan for attribute characters. */ 160 void _owl_fmtext_scan_attributes(owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 161 { 162 char *p; 163 p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8); 164 while (p && p < f->textbuff + start) { 165 _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor); 166 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 167 } 168 } 167 169 168 170 /* Internal function. Append text from 'in' between index 'start' and 169 171 * 'stop' to the end of 'f' 170 172 */ 171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) 172 { 173 int newlen, i; 174 175 newlen=strlen(f->textbuff)+(stop-start+1); 173 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/ 174 { 175 char attrbuff[6]; 176 int newlen, a = 0, fg = 0, bg = 0; 177 char attr = 0; 178 short fgcolor = OWL_COLOR_DEFAULT; 179 short bgcolor = OWL_COLOR_DEFAULT; 180 181 _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor); 182 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 183 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 184 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 185 186 /* We will reset to defaults after appending the text. We may need 187 to set initial attributes. */ 188 newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12; 176 189 _owl_fmtext_realloc(f, newlen); 177 190 191 if (a) { 192 memset(attrbuff,0,6); 193 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff); 194 strcat(f->textbuff, attrbuff); 195 } 196 if (fg) { 197 memset(attrbuff,0,6); 198 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff); 199 strcat(f->textbuff, attrbuff); 200 } 201 if (bg) { 202 memset(attrbuff,0,6); 203 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff); 204 strcat(f->textbuff, attrbuff); 205 } 206 178 207 strncat(f->textbuff, in->textbuff+start, stop-start+1); 208 209 /* Reset attributes */ 210 strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT); 211 strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT); 212 strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE); 213 179 214 f->textbuff[newlen]='\0'; 180 for (i=start; i<=stop; i++) {181 f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];182 f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];183 f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];184 }185 215 f->textlen=newlen; 186 216 } … … 207 237 char *owl_fmtext_print_plain(owl_fmtext *f) 208 238 { 209 return(owl_strdup(f->textbuff)); 239 return owl_strip_format_chars(f->textbuff); 240 } 241 242 void _owl_fmtext_wattrset(WINDOW *w, int attrs) /*noproto*/ 243 { 244 wattrset(w, A_NORMAL); 245 if (attrs & OWL_FMTEXT_ATTR_BOLD) wattron(w, A_BOLD); 246 if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE); 247 if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE); 248 } 249 250 void _owl_fmtext_update_colorpair(short fg, short bg, short *pair) /*noproto*/ 251 { 252 if (owl_global_get_hascolors(&g)) { 253 *pair = owl_fmtext_get_colorpair(fg, bg); 254 } 255 } 256 257 void _owl_fmtext_wcolor_set(WINDOW *w, short pair) /*noproto*/ 258 { 259 if (owl_global_get_hascolors(&g)) { 260 wcolor_set(w,pair,NULL); 261 } 210 262 } 211 263 … … 213 265 * must already be initiatlized with curses 214 266 */ 215 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 216 { 217 char *tmpbuff; 218 int position, trans1, trans2, trans3, len, lastsame; 219 267 void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/ 268 { 269 /* char *tmpbuff; */ 270 /* int position, trans1, trans2, trans3, len, lastsame; */ 271 char *s, *p; 272 char attr; 273 short fg, bg, pair; 274 int search_results, search_len; 275 220 276 if (w==NULL) { 221 277 owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr."); … … 223 279 } 224 280 225 tmpbuff=owl_malloc(f->textlen+10); 226 227 position=0; 228 len=f->textlen; 229 while (position<=len) { 230 /* find the last char with the current format and color */ 231 trans1=owl_util_find_trans(f->fmbuff+position, len-position); 232 trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position); 233 trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position); 234 235 lastsame = (trans1 < trans2) ? trans1 : trans2; 236 lastsame = (lastsame < trans3) ? lastsame : trans3; 237 lastsame += position; 238 239 /* set the format */ 240 wattrset(w, A_NORMAL); 241 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_BOLD) { 242 wattron(w, A_BOLD); 243 } 244 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_REVERSE) { 245 wattron(w, A_REVERSE); 246 } 247 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_UNDERLINE) { 248 wattron(w, A_UNDERLINE); 249 } 250 251 /* set the color */ 252 /* warning, this is sort of a hack */ 253 if (owl_global_get_hascolors(&g)) { 254 short fg, bg, pair; 255 fg = f->fgcolorbuff[position]; 256 bg = f->bgcolorbuff[position]; 257 258 pair = owl_fmtext_get_colorpair(fg, bg); 259 if (pair != -1) { 260 wcolor_set(w,pair,NULL); 261 } 262 } 263 264 /* add the text */ 265 strncpy(tmpbuff, f->textbuff + position, lastsame-position+1); 266 tmpbuff[lastsame-position+1]='\0'; 267 waddstr(w, tmpbuff); 268 269 position=lastsame+1; 270 } 271 owl_free(tmpbuff); 272 } 273 281 search_results = (do_search 282 ? owl_fmtext_search(f, owl_global_get_search_string(&g)) 283 : 0); 284 search_len = (search_results 285 ? strlen(owl_global_get_search_string(&g)) 286 : 0); 287 s = f->textbuff; 288 /* Set default attributes. */ 289 attr = f->default_attrs; 290 fg = f->default_fgcolor; 291 bg = f->default_bgcolor; 292 _owl_fmtext_wattrset(w, attr); 293 _owl_fmtext_update_colorpair(fg, bg, &pair); 294 _owl_fmtext_wcolor_set(w, pair); 295 296 /* Find next possible format character. */ 297 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 298 while(p) { 299 if (owl_fmtext_is_format_char(g_utf8_get_char(p))) { 300 /* Deal with all text from last insert to here. */ 301 char tmp; 302 303 tmp = p[0]; 304 p[0] = '\0'; 305 if (search_results) { 306 /* Search is active, so highlight search results. */ 307 char tmp2, *ss; 308 ss = stristr(s, owl_global_get_search_string(&g)); 309 while (ss) { 310 /* Found search string, highlight it. */ 311 312 tmp2 = ss[0]; 313 ss[0] = '\0'; 314 waddstr(w, s); 315 ss[0] = tmp2; 316 317 _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE); 318 _owl_fmtext_wcolor_set(w, pair); 319 320 tmp2 = ss[search_len]; 321 ss[search_len] = '\0'; 322 waddstr(w, ss); 323 ss[search_len] = tmp2; 324 325 _owl_fmtext_wattrset(w, attr); 326 _owl_fmtext_wcolor_set(w, pair); 327 328 s = ss + search_len; 329 ss = stristr(s, owl_global_get_search_string(&g)); 330 } 331 } 332 /* Deal with remaining part of string. */ 333 waddstr(w, s); 334 p[0] = tmp; 335 336 /* Deal with new attributes. Initialize to defaults, then 337 process all consecutive formatting characters. */ 338 attr = f->default_attrs; 339 fg = f->default_fgcolor; 340 bg = f->default_bgcolor; 341 while (p && owl_fmtext_is_format_char(g_utf8_get_char(p))) { 342 _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg); 343 p = g_utf8_next_char(p); 344 } 345 _owl_fmtext_wattrset(w, attr | f->default_attrs); 346 if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor; 347 if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor; 348 _owl_fmtext_update_colorpair(fg, bg, &pair); 349 _owl_fmtext_wcolor_set(w, pair); 350 351 /* Advance to next non-formatting character. */ 352 s = p; 353 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 354 } 355 else { 356 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 357 } 358 } 359 if (s) { 360 waddstr(w, s); 361 } 362 } 363 364 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 365 { 366 _owl_fmtext_curs_waddstr(f, w, owl_global_is_search_active(&g)); 367 } 368 369 void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w) 370 { 371 _owl_fmtext_curs_waddstr(f, w, 0); 372 } 274 373 275 374 /* start with line 'aline' (where the first line is 0) and print … … 282 381 283 382 /* find the starting line */ 284 ptr1=in->textbuff; 285 if (aline!=0) { 286 for (i=0; i<aline; i++) { 287 ptr1=strchr(ptr1, '\n'); 288 if (!ptr1) return(-1); 289 ptr1++; 290 } 291 } 383 ptr1 = in->textbuff; 384 for (i = 0; i < aline; i++) { 385 ptr1 = strchr(ptr1, '\n'); 386 if (!ptr1) return(-1); 387 ptr1++; 388 } 389 292 390 /* ptr1 now holds the starting point */ 293 391 392 /* copy the default attributes */ 393 out->default_attrs = in->default_attrs; 394 out->default_fgcolor = in->default_fgcolor; 395 out->default_bgcolor = in->default_bgcolor; 396 294 397 /* copy in the next 'lines' lines */ 295 if (lines <1) return(-1);296 297 for (i =0; i<lines; i++) {298 offset =ptr1-in->textbuff;299 ptr2 =strchr(ptr1, '\n');398 if (lines < 1) return(-1); 399 400 for (i = 0; i < lines; i++) { 401 offset = ptr1 - in->textbuff; 402 ptr2 = strchr(ptr1, '\n'); 300 403 if (!ptr2) { 301 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) -1);404 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1); 302 405 return(-1); 303 406 } 304 _owl_fmtext_append_fmtext(out, in, offset, (ptr2 -ptr1)+offset);305 ptr1 =ptr2+1;407 _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset); 408 ptr1 = ptr2 + 1; 306 409 } 307 410 return(0); … … 311 414 * ends at 'bcol' or sooner. The first column is number 0. The new 312 415 * message is placed in 'out'. The message is * expected to end in a 313 * new line for now 416 * new line for now. NOTE: This needs to be modified to deal with 417 * backing up if we find a SPACING COMBINING MARK at the end of a 418 * line. If that happens, we should back up to the last non-mark 419 * character and stop there. 314 420 */ 315 421 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out) 316 422 { 317 char *ptr1, *ptr2, *last; 318 int len, offset; 423 char *ptr_s, *ptr_e, *ptr_c, *last; 424 int col, st, padding, chwidth; 425 426 /* copy the default attributes */ 427 out->default_attrs = in->default_attrs; 428 out->default_fgcolor = in->default_fgcolor; 429 out->default_bgcolor = in->default_bgcolor; 319 430 320 431 last=in->textbuff+in->textlen-1; 321 ptr 1=in->textbuff;322 while (ptr 1<=last) {323 ptr 2=strchr(ptr1, '\n');324 if (!ptr 2) {432 ptr_s=in->textbuff; 433 while (ptr_s <= last) { 434 ptr_e=strchr(ptr_s, '\n'); 435 if (!ptr_e) { 325 436 /* but this shouldn't happen if we end in a \n */ 326 437 break; 327 438 } 328 439 329 if (ptr 2==ptr1) {440 if (ptr_e == ptr_s) { 330 441 owl_fmtext_append_normal(out, "\n"); 331 ptr1++;442 ++ptr_s; 332 443 continue; 333 444 } 334 445 335 /* we need to check that we won't run over here */ 336 len=bcol-acol; 337 if (len > (ptr2-(ptr1+acol))) { 338 /* the whole line fits with room to spare, don't take a full 'len' */ 339 len=ptr2-(ptr1+acol); 340 } 341 if (len>last-ptr1) { 342 /* the whole rest of the text fits with room to spare, adjust for it */ 343 len-=(last-ptr1); 344 } 345 if (len<=0) { 346 /* saftey check */ 446 col = 0; 447 st = 0; 448 padding = 0; 449 chwidth = 0; 450 ptr_c = ptr_s; 451 while(ptr_c < ptr_e) { 452 gunichar c = g_utf8_get_char(ptr_c); 453 if (!owl_fmtext_is_format_char(c)) { 454 chwidth = mk_wcwidth(c); 455 if (col + chwidth > bcol) break; 456 457 if (col >= acol) { 458 if (st == 0) { 459 ptr_s = ptr_c; 460 padding = col - acol; 461 ++st; 462 } 463 } 464 col += chwidth; 465 chwidth = 0; 466 } 467 ptr_c = g_utf8_next_char(ptr_c); 468 } 469 if (st) { 470 /* lead padding */ 471 owl_fmtext_append_spaces(out, padding); 472 if (ptr_c == ptr_e) { 473 /* We made it to the newline. */ 474 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 475 } 476 else { 477 if (chwidth > 1) { 478 /* Last char is wide, truncate. */ 479 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); 480 owl_fmtext_append_normal(out, "\n"); 481 } 482 else { 483 /* Last char fits perfectly, leave alone.*/ 484 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 485 } 486 } 487 } 488 else { 347 489 owl_fmtext_append_normal(out, "\n"); 348 ptr1=ptr2+1; 349 continue; 350 } 351 352 offset=ptr1-in->textbuff; 353 _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len); 354 355 ptr1=ptr2+1; 490 } 491 ptr_s = g_utf8_next_char(ptr_e); 356 492 } 357 493 } … … 381 517 382 518 /* set the charater at 'index' to be 'char'. If index is out of 383 * bounds don't do anything */ 384 void owl_fmtext_set_char(owl_fmtext *f, int index, int ch) 519 * bounds don't do anything. If c or char at index is not ASCII, don't 520 * do anything because it's not UTF-8 safe. */ 521 void owl_fmtext_set_char(owl_fmtext *f, int index, char ch) 385 522 { 386 523 if ((index < 0) || (index > f->textlen-1)) return; 524 /* NOT ASCII*/ 525 if (f->textbuff[index] & 0x80 || ch & 0x80) return; 387 526 f->textbuff[index]=ch; 388 527 } … … 401 540 dst->bufflen=mallocsize; 402 541 dst->textbuff=owl_malloc(mallocsize); 403 dst->fmbuff=owl_malloc(mallocsize);404 dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));405 dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));406 542 memcpy(dst->textbuff, src->textbuff, src->textlen+1); 407 memcpy(dst->fmbuff, src->fmbuff, src->textlen); 408 memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short)); 409 memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short)); 410 } 411 412 /* highlight all instances of "string". Return the number of 413 * instances found. This is a case insensitive search. 414 */ 415 int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) 416 { 417 418 int found, len; 419 char *ptr1, *ptr2; 420 421 len=strlen(string); 422 found=0; 423 ptr1=f->textbuff; 424 while (ptr1-f->textbuff <= f->textlen) { 425 ptr2=stristr(ptr1, string); 426 if (!ptr2) return(found); 427 428 found++; 429 _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE, 430 ptr2 - f->textbuff, 431 ptr2 - f->textbuff + len - 1); 432 433 ptr1=ptr2+len; 434 } 435 return(found); 543 dst->default_attrs = src->default_attrs; 544 dst->default_fgcolor = src->default_fgcolor; 545 dst->default_bgcolor = src->default_bgcolor; 436 546 } 437 547 … … 441 551 int owl_fmtext_search(owl_fmtext *f, char *string) 442 552 { 443 444 553 if (stristr(f->textbuff, string)) return(1); 445 554 return(0); … … 682 791 { 683 792 if (f->textbuff) owl_free(f->textbuff); 684 if (f->fmbuff) owl_free(f->fmbuff);685 if (f->fgcolorbuff) owl_free(f->fgcolorbuff);686 if (f->bgcolorbuff) owl_free(f->bgcolorbuff);687 793 } 688 794 -
functions.c
rcdd3959 rcdd3959 1606 1606 sprintf(buff, " Field %i : ", i+1); 1607 1607 1608 ptr=owl_zephyr_get_field (n, i+1);1608 ptr=owl_zephyr_get_field_as_utf8(n, i+1); 1609 1609 len=strlen(ptr); 1610 1610 if (len<30) { … … 2187 2187 void owl_function_start_command(char *line) 2188 2188 { 2189 int i, j;2190 2189 owl_editwin *tw; 2191 2190 … … 2198 2197 owl_global_set_needrefresh(&g); 2199 2198 2200 j=strlen(line); 2201 for (i=0; i<j; i++) { 2202 owl_editwin_process_char(tw, line[i]); 2203 } 2199 owl_editwin_insert_string(tw, line); 2204 2200 owl_editwin_redisplay(tw, 0); 2205 2201 … … 2599 2595 } 2600 2596 /* downcase it */ 2601 downstr(filtname); 2597 { 2598 char *temp = g_utf8_strdown(filtname, -1); 2599 if (temp) { 2600 owl_free(filtname); 2601 filtname = temp; 2602 } 2603 } 2602 2604 /* turn spaces, single quotes, and double quotes into dots */ 2603 2605 owl_text_tr(filtname, ' ', '.'); … … 3024 3026 char *quoted; 3025 3027 3026 buff= malloc(strlen(class)+strlen(inst)+strlen(recip)+100);3028 buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100); 3027 3029 strcpy(buff, "class"); 3028 3030 if (!strcmp(class, "*")) { … … 3328 3330 if (ret==0) { 3329 3331 for (x=0; x<numlocs; x++) { 3330 line= malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);3332 line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100); 3331 3333 tmp=short_zuser(user); 3332 3334 sprintf(line, " %-10.10s %-24.24s %-12.12s %20.20s\n", … … 3371 3373 owl_view *v; 3372 3374 FILE *file; 3375 char *plaintext; 3373 3376 3374 3377 v=owl_global_get_current_view(&g); … … 3393 3396 for (i=0; i<j; i++) { 3394 3397 m=owl_view_get_element(v, i); 3395 fputs(owl_message_get_text(m), file); 3398 plaintext = owl_strip_format_chars(owl_message_get_text(m)); 3399 if (plaintext) { 3400 fputs(plaintext, file); 3401 owl_free(plaintext); 3402 } 3396 3403 } 3397 3404 fclose(file); … … 3434 3441 _exit(127); 3435 3442 } 3436 parsed= realloc(parsed, sizeof(*parsed) * (myargc+1));3443 parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1)); 3437 3444 parsed[myargc] = NULL; 3438 3445 -
global.c
r8aa83ea3 r8aa83ea3 557 557 len+=strlen(argv[i])+5; 558 558 } 559 g->startupargs= malloc(len+5);559 g->startupargs=owl_malloc(len+5); 560 560 561 561 strcpy(g->startupargs, ""); -
keymap.c
rcf83b7a r428834d 5 5 6 6 /* returns 0 on success */ 7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)( int), void (*prealways_fn)(int), void (*postalways_fn)(int))7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input)) 8 8 { 9 9 if (!name || !desc) return(-1); … … 151 151 } 152 152 153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)( int), void (*prealways_fn)(int), void (*postalways_fn)(int))153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input)) 154 154 { 155 155 owl_keymap *km; … … 202 202 /* processes a keypress. returns 0 if the keypress was handled, 203 203 * 1 if not handled, -1 on error, and -2 if j==ERR. */ 204 int owl_keyhandler_process(owl_keyhandler *kh, int j)204 int owl_keyhandler_process(owl_keyhandler *kh, owl_input j) 205 205 { 206 206 owl_keymap *km; … … 214 214 215 215 /* temporarily disallow C-`/C-SPACE until we fix associated bugs */ 216 if (j ==ERR || j==0) {216 if (j.ch == ERR || j.ch == 0) { 217 217 return(-1); 218 218 } … … 224 224 225 225 /* deal with ESC prefixing */ 226 if (!kh->in_esc && j ==27) {226 if (!kh->in_esc && j.ch == 27) { 227 227 kh->in_esc = 1; 228 228 return(0); 229 229 } 230 230 if (kh->in_esc) { 231 j = OWL_META(j);231 j.ch = OWL_META(j.ch); 232 232 kh->in_esc = 0; 233 233 } 234 234 235 kh->kpstack[++(kh->kpstackpos)] = j ;235 kh->kpstack[++(kh->kpstackpos)] = j.ch; 236 236 if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) { 237 237 owl_keyhandler_reset(kh); … … 260 260 } else if (match == 2) { /* exact match */ 261 261 /* owl_function_debugmsg("processkey: found exact match in %s", km->name); */ 262 owl_keybinding_execute(kb, j );262 owl_keybinding_execute(kb, j.ch); 263 263 owl_keyhandler_reset(kh); 264 264 if (km->postalways_fn) { -
keypress.c
r948b942 r428834d 148 148 } 149 149 if (!*kb) { 150 if (j &OWL_META(0)) {150 if (j & OWL_META(0)) { 151 151 strcat(kb, "M-"); 152 152 j &= ~OWL_META(0); … … 163 163 strcat(kb, kb2); 164 164 } 165 165 166 } 166 167 if (!*kb) { -
keys.c
r3004c9f r3004c9f 302 302 /****************************************************************/ 303 303 304 void owl_keys_recwin_prealways( int j) {304 void owl_keys_recwin_prealways(owl_input j) { 305 305 /* Clear the message line on subsequent key presses */ 306 306 owl_function_makemsg(""); 307 307 } 308 308 309 void owl_keys_editwin_default( int j) {309 void owl_keys_editwin_default(owl_input j) { 310 310 owl_editwin *e; 311 311 if (NULL != (e=owl_global_get_typwin(&g))) { 312 owl_editwin_process_char(e, j);312 owl_editwin_process_char(e, j); 313 313 } 314 314 } 315 315 316 void owl_keys_editwin_postalways( int j) {316 void owl_keys_editwin_postalways(owl_input j) { 317 317 owl_editwin *e; 318 318 if (NULL != (e=owl_global_get_typwin(&g))) { 319 319 owl_editwin_post_process_char(e, j); 320 } 320 } 321 321 owl_global_set_needrefresh(&g); 322 322 } 323 323 324 void owl_keys_popless_postalways( int j) {324 void owl_keys_popless_postalways(owl_input j) { 325 325 owl_viewwin *v = owl_global_get_viewwin(&g); 326 326 owl_popwin *pw = owl_global_get_popwin(&g); … … 331 331 } 332 332 333 void owl_keys_default_invalid( int j) {334 if (j ==ERR) return;335 if (j ==410) return;333 void owl_keys_default_invalid(owl_input j) { 334 if (j.ch==ERR) return; 335 if (j.ch==410) return; 336 336 owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g)); 337 337 } -
logging.c
raf1920fd raf1920fd 155 155 to = owl_sprintf("jabber:%s", owl_message_get_recipient(m)); 156 156 } else if (owl_message_is_type_aim(m)) { 157 char *temp2; 157 158 temp = owl_aim_normalize_screenname(owl_message_get_recipient(m)); 158 downstr(temp); 159 to = owl_sprintf("aim:%s", temp); 159 temp2 = g_utf8_strdown(temp,-1); 160 to = owl_sprintf("aim:%s", temp2); 161 owl_free(temp2); 160 162 owl_free(temp); 161 163 } else { … … 267 269 } else if (owl_message_is_type_aim(m)) { 268 270 /* we do not yet handle chat rooms */ 269 char *normalto ;270 normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));271 downstr(normalto);271 char *normalto, *temp; 272 temp = owl_aim_normalize_screenname(owl_message_get_sender(m)); 273 normalto = g_utf8_strdown(temp, -1); 272 274 from=frombuff=owl_sprintf("aim:%s", normalto); 273 275 owl_free(normalto); 276 owl_free(temp); 274 277 } else if (owl_message_is_type_loopback(m)) { 275 278 from=frombuff=owl_strdup("loopback"); … … 290 293 291 294 ch=frombuff[0]; 292 if (! isalnum(ch)) from="weird";295 if (!g_ascii_isalnum(ch)) from="weird"; 293 296 294 297 for (i=0; i<len; i++) { … … 299 302 300 303 if (!personal) { 301 if (strcmp(from, "weird")) downstr(from); 304 if (strcmp(from, "weird")) { 305 char* temp = g_utf8_strdown(frombuff, -1); 306 if (temp) { 307 owl_free(frombuff); 308 from = frombuff = temp; 309 } 310 } 302 311 } 303 312 -
message.c
r18108b1e r18108b1e 79 79 owl_list_append_element(&(m->attributes), pair); 80 80 } 81 owl_pair_set_value(pair, owl_ strdup(attrvalue));81 owl_pair_set_value(pair, owl_validate_or_convert(attrvalue)); 82 82 } 83 83 … … 493 493 { 494 494 if(m->zwriteline) owl_free(m->zwriteline); 495 m->zwriteline= strdup(line);495 m->zwriteline=owl_strdup(line); 496 496 } 497 497 … … 535 535 owl_fmtext_init_null(&b); 536 536 537 owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline +1, &a);537 owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a); 538 538 owl_fmtext_truncate_cols(&a, acol, bcol, &b); 539 if (fgcolor!=OWL_COLOR_DEFAULT) { 540 owl_fmtext_colorize(&b, fgcolor); 541 } 542 if (bgcolor!=OWL_COLOR_DEFAULT) { 543 owl_fmtext_colorizebg(&b, bgcolor); 544 } 545 546 if (owl_global_is_search_active(&g)) { 547 owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g)); 548 } 549 539 owl_fmtext_colorize(&b, fgcolor); 540 owl_fmtext_colorizebg(&b, bgcolor); 541 550 542 owl_fmtext_curs_waddstr(&b, win); 551 543 … … 892 884 } 893 885 894 m->zwriteline= strdup("");886 m->zwriteline=owl_strdup(""); 895 887 896 888 /* save the hostname */ … … 974 966 } 975 967 976 m->zwriteline= strdup("");968 m->zwriteline=owl_strdup(""); 977 969 978 970 owl_message_set_body(m, "<uninitialized>"); -
owl.c
r52f8dd6 r52f8dd6 49 49 #include <termios.h> 50 50 #include <sys/stat.h> 51 #include <locale.h> 51 52 #include "owl.h" 52 53 … … 60 61 int stderr_replace(void); 61 62 #endif 63 64 #define STDIN 0 62 65 63 66 static const char fileIdent[] = "$Id$"; … … 85 88 int newstderr; 86 89 #endif 90 91 if (!GLIB_CHECK_VERSION (2, 12, 0)) 92 g_error ("GLib version 2.12.0 or above is needed."); 87 93 88 94 argcsave=argc; … … 93 99 debug=0; 94 100 initialsubs=1; 101 102 setlocale(LC_ALL, ""); 103 95 104 if (argc>0) { 96 105 argv++; … … 210 219 { 211 220 owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); 212 d->fd = fileno(stdin);221 d->fd = STDIN; 213 222 d->cfunc = &owl_process_input; 214 223 d->pfunc = NULL; … … 520 529 owl_function_set_cursor(sepwin); 521 530 } 522 owl_function_debugmsg("owl.c -- doupdate()");523 531 doupdate(); 524 532 owl_global_set_noneedrefresh(&g); 525 533 } 526 527 /* Handle all keypresses. If no key has been pressed, sleep for a528 * little bit, but otherwise do not. This lets input be grabbed529 * as quickly as possbile */530 534 531 535 /* select on FDs we know about. */ … … 664 668 void owl_process_input() 665 669 { 666 int ret, j; 670 int ret; 671 owl_input j; 667 672 owl_popwin *pw; 668 673 owl_editwin *tw; 669 674 WINDOW *typwin; 675 676 typwin = owl_global_get_curs_typwin(&g); 670 677 while (1) { 671 j = wgetch(owl_global_get_curs_typwin(&g));672 if (j == ERR) return;673 678 j.ch = wgetch(typwin); 679 if (j.ch == ERR) return; 680 674 681 owl_global_set_lastinputtime(&g, time(NULL)); 675 682 pw=owl_global_get_popwin(&g); 676 683 tw=owl_global_get_typwin(&g); 684 685 j.uch = '\0'; 686 if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) { 687 /* This is a curses control character. */ 688 } 689 else if (j.ch > 0x7f && j.ch < 0xfe) { 690 /* Pull in a full utf-8 character. */ 691 int bytes, i; 692 char utf8buf[7]; 693 memset(utf8buf, '\0', 7); 694 695 utf8buf[0] = j.ch; 696 697 if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2; 698 else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3; 699 else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4; 700 else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5; 701 else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6; 702 else bytes = 1; 703 704 for (i = 1; i < bytes; i++) { 705 int tmp = wgetch(typwin); 706 /* If what we got was not a byte, or not a continuation byte */ 707 if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) { 708 /* ill-formed UTF-8 code unit subsequence, put back the 709 char we just got. */ 710 ungetch(tmp); 711 j.ch = ERR; 712 break; 713 } 714 utf8buf[i] = tmp; 715 } 716 717 if (j.ch != ERR) { 718 if (g_utf8_validate(utf8buf, -1, NULL)) { 719 j.uch = g_utf8_get_char(utf8buf); 720 } 721 else { 722 j.ch = ERR; 723 } 724 } 725 } 726 else if (j.ch <= 0x7f) { 727 j.uch = j.ch; 728 } 677 729 730 owl_global_set_lastinputtime(&g, time(NULL)); 678 731 /* find and activate the current keymap. 679 732 * TODO: this should really get fixed by activating … … 685 738 owl_function_activate_keymap("popless"); 686 739 } else if (owl_global_is_typwin_active(&g) 687 && owl_editwin_get_style(tw) ==OWL_EDITWIN_STYLE_ONELINE) {740 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) { 688 741 /* 689 742 owl_context_set_editline(owl_global_get_context(&g), tw); … … 691 744 */ 692 745 } else if (owl_global_is_typwin_active(&g) 693 && owl_editwin_get_style(tw) ==OWL_EDITWIN_STYLE_MULTILINE) {746 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) { 694 747 owl_context_set_editmulti(owl_global_get_context(&g), tw); 695 748 owl_function_activate_keymap("editmulti"); … … 700 753 /* now actually handle the keypress */ 701 754 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 702 if (ret != 0 && ret !=1) {755 if (ret!=0 && ret!=1) { 703 756 owl_function_makemsg("Unable to handle keypress"); 704 757 } -
owl.h
r120291c r120291c 52 52 #include <termios.h> 53 53 #include <libfaim/aim.h> 54 #include <wchar.h> 54 55 #include "config.h" 56 #include "glib.h" 55 57 #ifdef HAVE_LIBZEPHYR 56 58 #include <zephyr/zephyr.h> … … 101 103 #define OWL_FMTEXT_ATTR_REVERSE 2 102 104 #define OWL_FMTEXT_ATTR_UNDERLINE 4 105 106 #define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/ 107 #define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 ) 108 #define OWL_FMTEXT_UC_ATTR_MASK 0x7 109 #define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 ) 110 #define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE 111 #define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 ) 112 #define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100 113 #define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) 114 #define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) 115 #define OWL_FMTEXT_UC_COLOR_MASK 0xFF 116 #define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200) 117 #define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4' 118 119 #define OWL_FMTEXT_UTF8_ATTR_NONE "\xf4\x80\xa0\x80" 120 #define OWL_FMTEXT_UTF8_FGDEFAULT "\xf4\x80\x94\x80" 121 #define OWL_FMTEXT_UTF8_BGDEFAULT "\xf4\x80\x9C\x80" 103 122 104 123 #define OWL_COLOR_BLACK 0 … … 210 229 #endif 211 230 212 #define OWL_META(key) ((key)|0 200)231 #define OWL_META(key) ((key)|010000) 213 232 /* OWL_CTRL is definied in kepress.c */ 214 233 … … 250 269 } owl_variable; 251 270 271 typedef struct _owl_input { 272 int ch; 273 gunichar uch; 274 } owl_input; 275 252 276 typedef struct _owl_fmtext { 253 277 int textlen; 254 278 int bufflen; 255 279 char *textbuff; 256 char *fmbuff;257 short *fgcolorbuff;258 short *bgcolorbuff;280 char default_attrs; 281 short default_fgcolor; 282 short default_bgcolor; 259 283 } owl_fmtext; 260 284 … … 486 510 owl_list bindings; /* key bindings */ 487 511 struct _owl_keymap *submap; /* submap */ 488 void (*default_fn)( int j); /* default action (takes a keypress) */489 void (*prealways_fn)( intj); /* always called before a keypress is received */490 void (*postalways_fn)( intj); /* always called after keypress is processed */512 void (*default_fn)(owl_input j); /* default action (takes a keypress) */ 513 void (*prealways_fn)(owl_input j); /* always called before a keypress is received */ 514 void (*postalways_fn)(owl_input j); /* always called after keypress is processed */ 491 515 } owl_keymap; 492 516 -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
rb72a352 rb72a352 26 26 use Getopt::Long; 27 27 Getopt::Long::Configure(qw(no_getopt_compat prefix_pattern=-|--)); 28 29 use utf8; 28 30 29 31 our $VERSION = 0.1; … … 378 380 $vars{jlogin_havepass} = 1; 379 381 $conn->removeConnection($jidStr); 380 BarnOwl::start_password( 382 BarnOwl::start_password("Password for $jidStr: ", \&do_login ); 381 383 return ""; 382 384 } … … 487 489 } 488 490 else { 489 491 $to = shift @ARGV; 490 492 } 491 493 … … 531 533 $cmd .= " -t $jwrite_thread" if $jwrite_thread; 532 534 $cmd .= " -s $jwrite_subject" if $jwrite_subject; 533 BarnOwl::start_edit_win( $cmd, \&process_owl_jwrite ); 535 536 BarnOwl::start_edit_win($cmd, \&process_owl_jwrite ); 534 537 } 535 538 -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
r6b580b0 r6b580b0 1 1 use warnings; 2 2 use strict; 3 use utf8; 3 4 4 5 =head1 NAME -
perl/modules/Jabber/lib/Net/XMPP/Debug.pm
rc2bed55 rb7b2a76 189 189 { 190 190 $self->{HANDLE}->autoflush(1); 191 binmode $self->{HANDLE}, ":utf8"; 191 192 $Net::XMPP::Debug::HANDLES{$args{file}} = $self->{HANDLE}; 192 193 } -
perl/modules/Jabber/lib/Net/XMPP/Message.pm
rc2bed55 r8574801 135 135 $Mess->SetMessage(TO=>"bob\@jabber.org", 136 136 Subject=>"Lunch", 137 Bo Dy=>"Let's do lunch!");137 Body=>"Let's do lunch!"); 138 138 $Mess->SetMessage(to=>"bob\@jabber.org", 139 139 from=>"jabber.org", -
perl/modules/Jabber/lib/XML/Stream.pm
r5073972 ra8d5a39 1659 1659 { 1660 1660 $self->debug(3,"Send: can_write"); 1661 1661 1662 1662 $self->{SENDSTRING} = Encode::encode_utf8(join("",@_)); 1663 1663 -
perlconfig.c
rb67ab6b rb67ab6b 55 55 j=owl_zephyr_get_num_fields(owl_message_get_notice(m)); 56 56 for (i=0; i<j; i++) { 57 ptr=owl_zephyr_get_field (owl_message_get_notice(m), i+1);57 ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1); 58 58 av_push(av_zfields, newSVpvn(ptr, strlen(ptr))); 59 59 owl_free(ptr); … … 434 434 PUSHMARK(SP); 435 435 for(i=0;i<argc;i++) { 436 XPUSHs(sv_2mortal(newSVpv(argv[i], 0))); 436 SV *tmp = newSVpv(argv[i], 0); 437 SvUTF8_on(tmp); 438 XPUSHs(sv_2mortal(tmp)); 437 439 } 438 440 PUTBACK; … … 473 475 { 474 476 SV *cb = (SV*)(e->cbdata); 477 SV *text; 475 478 unsigned int n_a; 476 479 dSP; … … 479 482 owl_function_error("Perl callback is NULL!"); 480 483 } 484 text = newSVpv(owl_editwin_get_text(e), 0); 485 SvUTF8_on(text); 481 486 482 487 ENTER; … … 484 489 485 490 PUSHMARK(SP); 486 XPUSHs(sv_2mortal( newSVpv(owl_editwin_get_text(e), 0)));491 XPUSHs(sv_2mortal(text)); 487 492 PUTBACK; 488 493 -
text.c
r3bcf125 r3bcf125 50 50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol) 51 51 { 52 char *ptr 1, *ptr2, *tmpbuff, *last;53 int len;54 52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last; 53 int col, cnt, padding; 54 55 55 tmpbuff=owl_malloc(strlen(in)+20); 56 56 57 57 strcpy(tmpbuff, ""); 58 58 last=in+strlen(in)-1; 59 ptr 1=in;60 while (ptr 1<last) {61 ptr 2=strchr(ptr1, '\n');62 if (!ptr 2) {59 ptr_s=in; 60 while (ptr_s<last) { 61 ptr_e=strchr(ptr_s, '\n'); 62 if (!ptr_e) { 63 63 /* but this shouldn't happen if we end in a \n */ 64 64 break; 65 65 } 66 66 67 if (ptr 2==ptr1) {67 if (ptr_e==ptr_s) { 68 68 strcat(tmpbuff, "\n"); 69 ptr1++; 70 continue; 71 } 72 69 ptr_s++; 70 continue; 71 } 72 73 col = 0; 74 cnt = 0; 75 padding = 0; 76 ptr_c = ptr_s; 77 while(col < bcol && ptr_c < ptr_e) { 78 gunichar c = g_utf8_get_char(ptr_c); 79 if (col + mk_wcwidth(c) > bcol) break; 80 col += mk_wcwidth(c); 81 ptr_c = g_utf8_next_char(ptr_c); 82 if (col >= acol) { 83 if (cnt == 0) { 84 ptr_s = ptr_c; 85 padding = col - acol; 86 } 87 ++cnt; 88 } 89 } 90 if (cnt) { 91 while(padding-- > 0) { 92 strcat(tmpbuff, " "); 93 } 94 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1); 95 } 96 strcat(tmpbuff, "\n"); 97 ptr_s = ptr_e + 1; 98 #if 0 73 99 /* we need to check that we won't run over here */ 74 if ( (ptr 2-ptr1) < (bcol-acol) ) {75 len=ptr 2-(ptr1+acol);100 if ( (ptr_e-ptr_s) < (bcol-acol) ) { 101 len=ptr_e-(ptr_s+acol); 76 102 } else { 77 103 len=bcol-acol; 78 104 } 79 if ((ptr 1+len)>=last) {80 len-=last-(ptr 1+len);81 } 82 83 strncat(tmpbuff, ptr 1+acol, len);105 if ((ptr_s+len)>=last) { 106 len-=last-(ptr_s+len); 107 } 108 109 strncat(tmpbuff, ptr_s+acol, len); 84 110 strcat(tmpbuff, "\n"); 85 111 86 ptr1=ptr2+1; 112 ptr_s=ptr_e+1; 113 #endif 87 114 } 88 115 strcpy(out, tmpbuff); … … 275 302 char *stristr(char *a, char *b) 276 303 { 277 char *x, *y, *ret; 278 279 if ((x=owl_strdup(a))==NULL) return(NULL); 280 if ((y=owl_strdup(b))==NULL) return(NULL); 281 downstr(x); 282 downstr(y); 283 ret=strstr(x, y); 284 if (ret==NULL) { 285 owl_free(x); 286 owl_free(y); 287 return(NULL); 288 } 289 ret=ret-x+a; 290 owl_free(x); 291 owl_free(y); 304 char *x, *y; 305 char *ret = NULL; 306 if ((x = g_utf8_casefold(a, -1)) != NULL) { 307 if ((y = g_utf8_casefold(b, -1)) != NULL) { 308 ret = strstr(x, y); 309 if (ret != NULL) { 310 ret = ret - x + a; 311 } 312 g_free(y); 313 } 314 g_free(x); 315 } 292 316 return(ret); 293 317 } … … 296 320 int only_whitespace(char *s) 297 321 { 298 int i; 299 for (i=0; s[i]; i++) { 300 if (!isspace((int) s[i])) return(0); 322 if (g_utf8_validate(s,-1,NULL)) { 323 char *p; 324 for(p = s; p[0]; p=g_utf8_next_char(p)) { 325 if (!g_unichar_isspace(g_utf8_get_char(p))) return 0; 326 } 327 } 328 else { 329 int i; 330 for (i=0; s[i]; i++) { 331 if (!isspace((int) s[i])) return(0); 332 } 301 333 } 302 334 return(1); … … 327 359 tolen = strlen(to); 328 360 fromlen = strlen(from); 329 out = malloc(outlen);361 out = owl_malloc(outlen); 330 362 331 363 while (in[inpos]) { -
util.c
raf1920fd raf1920fd 399 399 } 400 400 401 /* downcase the string 'foo' */402 void downstr(char *foo)403 {404 int i;405 for (i=0; foo[i]!='\0'; i++) {406 foo[i]=tolower(foo[i]);407 }408 }409 410 401 /* Caller must free response. 411 402 * Takes in strings which are space-separated lists of tokens … … 446 437 void *owl_malloc(size_t size) 447 438 { 448 return( malloc(size));439 return(g_malloc(size)); 449 440 } 450 441 451 442 void owl_free(void *ptr) 452 443 { 453 free(ptr);444 g_free(ptr); 454 445 } 455 446 456 447 char *owl_strdup(const char *s1) 457 448 { 458 return( strdup(s1));449 return(g_strdup(s1)); 459 450 } 460 451 461 452 void *owl_realloc(void *ptr, size_t size) 462 453 { 463 return( realloc(ptr, size));454 return(g_realloc(ptr, size)); 464 455 } 465 456 466 457 /* allocates memory and returns the string or null. 467 458 * caller must free the string. 468 * from Linux sprintf man page.469 459 */ 470 460 char *owl_sprintf(const char *fmt, ...) 471 461 { 472 int n, size = 100;473 char *p;474 462 va_list ap; 475 if ((p = owl_malloc (size)) == NULL) return (NULL); 476 while (1) { 477 /* Try to print in the allocated space. */ 478 va_start(ap, fmt); 479 n = vsnprintf (p, size, fmt, ap); 480 va_end(ap); 481 /* If that worked, return the string. */ 482 if (n > -1 && n < size) 483 return p; 484 /* Else try again with more space. */ 485 if (n > -1) /* glibc 2.1 */ 486 size = n+1; /* precisely what is needed */ 487 else /* glibc 2.0 */ 488 size *= 2; /* twice the old size */ 489 if ((p = owl_realloc (p, size)) == NULL) 490 return NULL; 491 } 492 } 463 char *ret = NULL; 464 va_start(ap, fmt); 465 ret = g_strdup_vprintf(fmt, ap); 466 va_end(ap); 467 return ret; 468 } 469 493 470 494 471 /* Return the owl color associated with the named color. Return -1 … … 776 753 } 777 754 778 char * owl_get_datadir() { 779 char * datadir = getenv("BARNOWL_DATA_DIR"); 780 if(datadir != NULL) 781 return strchr(datadir, '=') + 1; 782 return DATADIR; 755 char * owl_get_datadir() 756 { 757 char * datadir = getenv("BARNOWL_DATA_DIR"); 758 if(datadir != NULL) 759 return strchr(datadir, '=') + 1; 760 return DATADIR; 761 } 762 763 /* Strips format characters from a valid utf-8 string. Returns the 764 empty string if 'in' does not validate. */ 765 char * owl_strip_format_chars(char *in) 766 { 767 char *r; 768 if (g_utf8_validate(in, -1, NULL)) { 769 char *s, *p; 770 r = owl_malloc(strlen(in)+1); 771 r[0] = '\0'; 772 s = in; 773 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 774 while(p) { 775 /* If it's a format character, copy up to it, and skip all 776 immediately following format characters. */ 777 if (owl_fmtext_is_format_char(g_utf8_get_char(p))) { 778 strncat(r, s, p-s); 779 p = g_utf8_next_char(p); 780 while (p && owl_fmtext_is_format_char(g_utf8_get_char(p))) { 781 p = g_utf8_next_char(p); 782 } 783 s = p; 784 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 785 } 786 else { 787 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 788 } 789 } 790 if (s) strcat(r,s); 791 } 792 else { 793 r = owl_strdup(""); 794 } 795 return r; 796 } 797 798 /* If in is not UTF-8, convert from ISO-8859-1. We may want to allow 799 * the caller to specify an alternative in the future. We also strip 800 * out characters in Unicode Plane 16, as we use that plane internally 801 * for formatting. 802 */ 803 char * owl_validate_or_convert(char *in) 804 { 805 if (g_utf8_validate(in, -1, NULL)) { 806 return owl_strip_format_chars(in); 807 } 808 else { 809 return g_convert(in, -1, 810 "UTF-8", "ISO-8859-1", 811 NULL, NULL, NULL); 812 } 813 } 814 /* Attempts to convert 'in' to ISO-8859-1. Returns that if possible, 815 else returns UTF-8. 816 */ 817 char * owl_get_iso_8859_1_if_possible(char *in) 818 { 819 char *out; 820 if (g_utf8_validate(in, -1, NULL)) { 821 out = g_convert(in, -1, 822 "ISO-8859-1", "UTF-8", 823 NULL, NULL, NULL); 824 if (!out) { 825 out = owl_strdup(in); 826 } 827 } 828 else { 829 out = owl_strdup(""); 830 } 831 return out; 832 } 833 834 /* This is based on _extract() and _isCJ() from perl's Text::WrapI18N */ 835 int owl_util_can_break_after(gunichar c) 836 { 837 838 if (c == ' ') return 1; 839 if (c >= 0x3000 && c <= 0x312f) { 840 /* CJK punctuations, Hiragana, Katakana, Bopomofo */ 841 if (c == 0x300a || c == 0x300c || c == 0x300e || 842 c == 0x3010 || c == 0x3014 || c == 0x3016 || 843 c == 0x3018 || c == 0x301a) 844 return 0; 845 return 1; 846 } 847 if (c >= 0x31a0 && c <= 0x31bf) {return 1;} /* Bopomofo */ 848 if (c >= 0x31f0 && c <= 0x31ff) {return 1;} /* Katakana extension */ 849 if (c >= 0x3400 && c <= 0x9fff) {return 1;} /* Han Ideogram */ 850 if (c >= 0xf900 && c <= 0xfaff) {return 1;} /* Han Ideogram */ 851 if (c >= 0x20000 && c <= 0x2ffff) {return 1;} /* Han Ideogram */ 852 return 0; 783 853 } 784 854 -
viewwin.c
r8721756 r47519e1b 73 73 owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2); 74 74 75 owl_fmtext_curs_waddstr (&fm2, v->curswin);75 owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin); 76 76 77 77 /* print the message at the bottom */ -
zcrypt.c
r9ceee9d r34509d5 385 385 386 386 /* Build a space-separated string from argv from elements between start * 387 * and end - 1. malloc()'s the returned string. */387 * and end - 1. owl_malloc()'s the returned string. */ 388 388 char *BuildArgString(char **argv, int start, int end) { 389 389 int len = 1; … … 397 397 398 398 /* Allocate memory */ 399 result = (char *) malloc(len);399 result = (char *)owl_malloc(len); 400 400 if (result) { 401 401 /* Build the string */ … … 482 482 /* Prepare result to be returned */ 483 483 char *temp = keyfile; 484 keyfile = (char *) malloc(strlen(temp) + 1);484 keyfile = (char *)owl_malloc(strlen(temp) + 1); 485 485 if (keyfile) { 486 486 strcpy(keyfile, temp); … … 611 611 } 612 612 use_buffer = TRUE; 613 if ((inptr = inbuff = (char *) malloc(MAX_RESULT)) == NULL) {613 if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) { 614 614 printf("Memory allocation error\n"); 615 615 return FALSE; … … 639 639 printf("Could not run zwrite\n"); 640 640 if (freein && inbuff) { 641 free(inbuff);641 owl_free(inbuff); 642 642 } 643 643 return(FALSE); … … 685 685 686 686 /* Free the input buffer, if necessary */ 687 if (freein && inbuff) free(inbuff);687 if (freein && inbuff) owl_free(inbuff); 688 688 689 689 return(!error); -
zephyr.c
r9c7a701 r5577606 353 353 return(owl_strdup("")); 354 354 } 355 356 char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j) 357 { 358 int i, count, save; 359 360 /* If there's no message here, just run along now */ 361 if (n->z_message_len == 0) 362 return(owl_strdup("")); 363 364 count=save=0; 365 for (i = 0; i < n->z_message_len; i++) { 366 if (n->z_message[i]=='\0') { 367 count++; 368 if (count == j) { 369 /* just found the end of the field we're looking for */ 370 return(owl_validate_or_convert(n->z_message + save)); 371 } else { 372 save = i + 1; 373 } 374 } 375 } 376 /* catch the last field, which might not be null terminated */ 377 if (count == j - 1) { 378 char *tmp, *out; 379 tmp = owl_malloc(n->z_message_len-save+5); 380 memcpy(tmp, n->z_message+save, n->z_message_len-save); 381 tmp[n->z_message_len-save]='\0'; 382 out = owl_validate_or_convert(tmp); 383 owl_free(tmp); 384 return out; 385 } 386 387 return(owl_strdup("")); 388 } 355 389 #else 356 390 char *owl_zephyr_get_field(void *n, int j) 357 391 { 358 392 return(owl_strdup("")); 393 } 394 char *owl_zephyr_get_field_as_utf8(void *n, int j) 395 { 396 return owl_zephyr_get_field(n, j); 359 397 } 360 398 #endif -
zwrite.c
r1fe100c r7b1d048 44 44 break; 45 45 } 46 z->class=owl_ strdup(myargv[1]);46 z->class=owl_get_iso_8859_1_if_possible(myargv[1]); 47 47 myargv+=2; 48 48 myargc-=2; … … 52 52 break; 53 53 } 54 z->inst=owl_ strdup(myargv[1]);54 z->inst=owl_get_iso_8859_1_if_possible(myargv[1]); 55 55 myargv+=2; 56 56 myargc-=2; … … 60 60 break; 61 61 } 62 z->realm=owl_ strdup(myargv[1]);62 z->realm=owl_get_iso_8859_1_if_possible(myargv[1]); 63 63 myargv+=2; 64 64 myargc-=2; … … 68 68 break; 69 69 } 70 z->zsig=owl_ strdup(myargv[1]);70 z->zsig=owl_get_iso_8859_1_if_possible(myargv[1]); 71 71 myargv+=2; 72 72 myargc-=2; … … 76 76 break; 77 77 } 78 z->opcode=owl_ strdup(myargv[1]);78 z->opcode=owl_get_iso_8859_1_if_possible(myargv[1]); 79 79 myargv+=2; 80 80 myargc-=2; … … 93 93 myargv++; 94 94 myargc--; 95 z->message=owl_ strdup("");95 z->message=owl_get_iso_8859_1_if_possible(""); 96 96 while (myargc) { 97 z->message= realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);97 z->message=owl_realloc(z->message, strlen(z->message)+strlen(myargv[0])+5); 98 98 strcat(z->message, myargv[0]); 99 99 strcat(z->message, " "); … … 113 113 } else { 114 114 /* anything unattached is a recipient */ 115 owl_list_append_element(&(z->recips), strdup(myargv[0]));115 owl_list_append_element(&(z->recips), owl_get_iso_8859_1_if_possible(myargv[0])); 116 116 myargv++; 117 117 myargc--; … … 146 146 147 147 if (zsigowlvar && *zsigowlvar) { 148 z->zsig=owl_ strdup(zsigowlvar);148 z->zsig=owl_get_iso_8859_1_if_possible(zsigowlvar); 149 149 } else if (zsigproc && *zsigproc) { 150 150 FILE *file; … … 161 161 if (!file) { 162 162 if (zsigzvar && *zsigzvar) { 163 z->zsig=owl_ strdup(zsigzvar);163 z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar); 164 164 } 165 165 } else { … … 175 175 } 176 176 } else if (zsigzvar) { 177 z->zsig=owl_ strdup(zsigzvar);177 z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar); 178 178 } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) { 179 z->zsig= strdup(pw->pw_gecos);179 z->zsig=owl_get_iso_8859_1_if_possible(pw->pw_gecos); 180 180 ptr=strchr(z->zsig, ','); 181 181 if (ptr) { … … 218 218 int i, j; 219 219 char toline[LINE]; 220 char *tmp = NULL; 220 221 221 222 if (z->message) owl_free(z->message); … … 231 232 } 232 233 } 233 z->message=owl_sprintf("%s\n%s", toline, msg); 234 tmp = owl_get_iso_8859_1_if_possible(msg); 235 z->message=owl_sprintf("%s\n%s", toline, tmp); 234 236 } else { 235 z->message=owl_strdup(msg); 236 } 237 z->message=owl_get_iso_8859_1_if_possible(msg); 238 } 239 if (tmp) owl_free(tmp); 237 240 } 238 241 … … 305 308 { 306 309 if (z->opcode) owl_free(z->opcode); 307 z->opcode=owl_ strdup(opcode);310 z->opcode=owl_get_iso_8859_1_if_possible(opcode); 308 311 } 309 312
Note: See TracChangeset
for help on using the changeset viewer.