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