1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1995 by Sun Microsystems, Inc. 23 * All Rights Reserved. 24 */ 25 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <ctype.h> 30 #include <string.h> 31 #include "kdefs.h" 32 #include <errno.h> 33 #include "ktable.h" 34 #include "nbyte_euc.h" 35 36 extern KCHAR getc_12(); 37 extern KCHAR packtocomp(); 38 39 struct _cv_state { 40 char temp_ibuf[5]; 41 int ibuf_left; 42 int istart, iend; 43 char temp_obuf[1]; 44 int flush_obuf; 45 }; 46 47 int is_SI(char **inbuf, size_t *inbytesleft, struct _cv_state *st); 48 49 static int _johap_to_wansung(unsigned short* wcode, unsigned short code); 50 51 /**** _ I C V _ O P E N ****/ 52 53 void* _icv_open() 54 { 55 _conv_desc* cd = (_conv_desc*)malloc(sizeof(_conv_desc)); 56 57 if (cd == (_conv_desc*)NULL) 58 { 59 errno = ENOMEM; 60 return((void*)-1); 61 } 62 63 cd->cur_stat = 1; 64 cd->hbuf[1] = cd->hbuf[2] = cd->hbuf[3] = cd->hbuf[4] = '\0'; 65 cd->cur_act = 0; 66 67 return((void*)cd); 68 } /* end of int _icv_open(). */ 69 70 71 /**** _ I C V _ C L O S E ****/ 72 73 void _icv_close(_conv_desc* cd) 74 { 75 if (!cd) 76 errno = EBADF; 77 else 78 free((void*)cd); 79 } /* end of void _icv_close(_conv_desc*). */ 80 81 82 /**** _ I C V _ I C O N V ****/ 83 84 size_t _icv_iconv(_conv_desc* cd, char** inbuf, size_t* inbufleft, 85 char** outbuf, size_t* outbufleft) 86 { 87 size_t ret_val = 0; 88 unsigned char* ib; 89 unsigned char* ob; 90 unsigned char* ibtail; 91 unsigned char* obtail; 92 93 if (!cd) 94 { 95 errno = EBADF; 96 return((size_t)-1); 97 } 98 99 if (!inbuf || !(*inbuf)) 100 { 101 cd->cur_stat = 1; 102 cd->hbuf[1] = cd->hbuf[2] = cd->hbuf[3] = cd->hbuf[4] = '\0'; 103 cd->cur_act = 0; 104 return((size_t)0); 105 } 106 107 ib = (unsigned char*)*inbuf; 108 ob = (unsigned char*)*outbuf; 109 ibtail = ib + *inbufleft; 110 obtail = ob + *outbufleft; 111 112 while (ib < ibtail) 113 { 114 int cur_input, action, state; 115 char result; 116 int input_conv(char); 117 unsigned short make_johap_code(int, char*); 118 int _johap_to_wansung(unsigned short*, 119 unsigned short); 120 121 cur_input = input_conv(*ib); 122 action = next_act[cd->cur_stat][cur_input]; 123 state = next_stat[cd->cur_stat][cur_input]; 124 if (action == 4) 125 { 126 if (ob >= obtail) 127 { 128 errno = E2BIG; 129 ret_val = (size_t)-1; 130 break; 131 } 132 *ob++ = *ib; 133 } 134 else if (action >= 5 && action <= 8) 135 cd->hbuf[action - 4] = *ib; 136 else if (action == 9) 137 { 138 ADD_CONVERTED_CODE(0, 0); 139 cd->hbuf[1] = *ib; 140 } 141 else if (action == 10) 142 { 143 ADD_CONVERTED_CODE(0, 0); 144 cd->hbuf[2] = *ib; 145 ADD_CONVERTED_CODE(0, 0); 146 } 147 else if (action == 11 || action == 12) 148 { 149 ADD_CONVERTED_CODE(0, 0); 150 } 151 else if (action == 13) 152 { 153 ADD_CONVERTED_CODE(0, 1); 154 *ob++ = *ib; 155 } 156 else if (action == 14) 157 { 158 register char c1 = cd->hbuf[2], c2 = *ib; 159 160 if (c1 == 'l' && c2 == 'b') /* _|_ && |- */ 161 cd->hbuf[2] = 'm'; 162 else if (c1 == 'l' && c2 == 'c') /* _|_ && H */ 163 cd->hbuf[2] = 'n'; 164 else if (c1 == 'l' && c2 == '|') /* _|_ && | */ 165 cd->hbuf[2] = 'o'; 166 else if (c1 == 's' && c2 == 'f') /* T && -| */ 167 cd->hbuf[2] = 't'; 168 else if (c1 == 's' && c2 == 'g') /* T && -|| */ 169 cd->hbuf[2] = 'u'; 170 else if (c1 == 's' && c2 == '|') /* T && | */ 171 cd->hbuf[2] = 'v'; 172 else if (c1 == 'z' && c2 == '|') /* __ && | */ 173 cd->hbuf[2] = '{'; 174 else 175 cd->hbuf[2] = *ib; /* Just in case. */ 176 } 177 else if (action == 15) 178 { 179 cd->hbuf[2] = *ib; 180 ADD_CONVERTED_CODE(0, 0); 181 } 182 else if (action == 16) 183 { 184 ADD_CONVERTED_CODE(0, 0); 185 } 186 else if (action == 17) 187 { 188 ADD_CONVERTED_CODE(1, 0); 189 cd->hbuf[2] = *ib; 190 } 191 cd->cur_act = action; 192 cd->cur_stat = state; 193 ib++; 194 } 195 196 *inbuf = (char*)ib; 197 *inbufleft = ibtail - ib; 198 *outbuf = (char*)ob; 199 *outbufleft = obtail - ob; 200 201 return(ret_val); 202 } /* end of size_t _icv_iconv(_conv_desc*, char**, size_t*, char**, size_t*).*/ 203 204 205 /**** I N P U T _ C O N V ****/ 206 207 int input_conv(char c) 208 { 209 switch (c) 210 { 211 case 'H': /* dd */ 212 case 'S': /* bb */ 213 case 'Y': /* jj */ 214 return(1); 215 216 case 'A': /* g */ 217 return(2); 218 219 case 'D': /* n */ 220 return(3); 221 222 case 'I': /* r */ 223 return(4); 224 225 case 'R': /* b */ 226 return(5); 227 228 case 'B': /* gg */ 229 case 'G': /* d */ 230 case 'V': /* ss */ 231 case 'W': /* o */ 232 case 'Z': /* ch */ 233 case '[': /* k */ 234 return(6); 235 236 case 'U': /* s */ 237 return(7); 238 239 case 'X': /* j */ 240 return(8); 241 242 case '^': /* h */ 243 return(9); 244 245 case 'Q': /* m */ 246 case ']': /* p */ 247 case '\\': /* t */ 248 return(10); 249 250 case 'k': /* =|| */ 251 case 'd': /* |= */ 252 case 'e': /* |=| */ 253 case 'j': /* =| */ 254 case 'r': /* _||_ */ 255 case 'w': /* TT */ 256 return(11); 257 258 case 'b': /* |- */ 259 case 'c': /* H */ 260 return(12); 261 262 case 'f': /* -| */ 263 case 'g': /* -|| */ 264 return(13); 265 266 case '|': /* | */ 267 return(14); 268 269 case 'l': /* _|_ */ 270 return(15); 271 272 case 's': /* T */ 273 return(16); 274 275 case 'z': /* __ */ 276 return(17); 277 278 case '\016': 279 return(18); 280 281 case '\017': 282 case '\024': 283 return(19); 284 285 default: 286 return(20); 287 } 288 } /* end of int input_conv(char). */ 289 290 291 /**** M A K E _ J O H A P _ C O D E ****/ 292 293 unsigned short make_johap_code(int n, char* temp) 294 { 295 register unsigned short code = 0; 296 char save ='\0'; 297 298 if (n == 1) 299 { 300 if (temp[4] == '\0') 301 { 302 save = temp[3]; 303 temp[3] = '\0'; 304 } 305 else 306 { 307 save = temp[4]; 308 temp[4] = '\0'; 309 } 310 } 311 312 code = (temp[1] >= 'A' && temp[1] <= '^') ? 313 (unsigned short)X32_19[temp[1] - '@'] 314 : (unsigned short)9; 315 code = (code << 5) | (unsigned short)((temp[2] >= 'b' && 316 temp[2] <= '|') ? X32_21[temp[2] - '`'] 317 : 1); 318 code = (code << 5) | (unsigned short)((temp[3] >= 'A' && 319 temp[3] <= '^') ? X32_28[temp[3] - '@'] 320 : 1); 321 322 if (temp[4] >= 'A') 323 { 324 if (temp[3] == 'A' && temp[4] == 'U') /* gs */ 325 code += 2; 326 else if (temp[3] == 'D' && temp[4] == 'X') /* nj */ 327 code++; 328 else if (temp[3] == 'D' && temp[4] == '^') /* nh */ 329 code += 2; 330 else if (temp[3] == 'I' && temp[4] == 'A') /* rg */ 331 code++; 332 else if (temp[3] == 'I' && temp[4] == 'Q') /* rm */ 333 code += 2; 334 else if (temp[3] == 'I' && temp[4] == 'R') /* rb */ 335 code += 3; 336 else if (temp[3] == 'I' && temp[4] == 'U') /* rs */ 337 code += 4; 338 else if (temp[3] == 'I' && temp[4] == '\\') /* rt */ 339 code += 5; 340 else if (temp[3] == 'I' && temp[4] == ']') /* rp */ 341 code += 6; 342 else if (temp[3] == 'I' && temp[4] == '^') /* rh */ 343 code += 7; 344 else if (temp[3] == 'R' && temp[4] == 'U') /* bs */ 345 code++; 346 else if (temp[3] == 'U' && temp[4] == 'U') /* ss */ 347 code++; 348 } 349 350 temp[1] = (n == 1) ? save : '\0'; 351 temp[2] = temp[3] = temp[4] = '\0'; 352 return(code | 0x8000); 353 } /* end of unsigned short make_johap_code(int, char*). */ 354 355 356 /**** _ J O H A P _ T O _ W A N S U N G ****/ 357 358 static int _johap_to_wansung(unsigned short* wcode, unsigned short code) 359 { 360 register unsigned short i; 361 unsigned short ci, v, cf; 362 unsigned short mask, disp; 363 long cfbit; 364 365 *wcode = 0; 366 ci = CHOSUNG(code) - 0x0A; 367 v = JOONGSUNG(code) - ((unsigned short)JOONGSUNG(code) / 4 + 2); 368 cf = JONGSUNG(code); 369 370 if (JOONGSUNG(code) - ((unsigned short)JOONGSUNG(code) / 4 + 2) < 0) 371 *wcode = 0xA4A0 + Y19_32[ci + 1]; 372 else if (CHOSUNG(code) - 0x0A < 0) 373 { 374 if (cf <= 1) 375 *wcode = 0xA4BF + v; 376 else 377 return(FAILED); 378 } 379 else 380 { 381 if (cf < 2) 382 cf = 1; 383 384 cfbit = cmp_bitmap[ci][v]; 385 for (disp = 0, i = 0; i < cf; i++) 386 { 387 if (cfbit & BIT_MASK) 388 disp++; 389 cfbit >>= 1; 390 } 391 if (!(cfbit & BIT_MASK)) 392 return(FAILED); 393 394 *wcode = cmp_srchtbl[ci][v] + disp; 395 mask = cmp_srchtbl[ci][v] & 0xFF; 396 397 *wcode += (((short)(mask + disp) > 0xFE) ? SKIP : 0); 398 } 399 400 return(HANGUL); 401 } /* end of unsigned short _johap_to_wansung(unsigned short, unsigned short, 402 * unsigned short). */ 403 404 void * 405 _cv_open() 406 { 407 struct _cv_state *st; 408 409 if ((st = (struct _cv_state *)malloc(sizeof(struct _cv_state))) == NULL) 410 return ((void *)-1); 411 412 st->ibuf_left = 0; 413 st->istart = 0; 414 st->iend = 0; 415 st->flush_obuf = 0; 416 417 return (st); 418 } 419 420 void 421 _cv_close(st) 422 struct _cv_state *st; 423 { 424 free(st); 425 } 426 427 size_t 428 _cv_enconv(st, inbuf, inbytesleft, outbuf, outbytesleft) 429 struct _cv_state *st; 430 char **inbuf; 431 size_t*inbytesleft; 432 char **outbuf; 433 size_t*outbytesleft; 434 { 435 unsigned short code; 436 437 if (inbuf == NULL || *inbuf == NULL) { /* Reset request. */ 438 st->ibuf_left = 0; 439 st->istart = 0; 440 st->iend = 0; 441 st->flush_obuf = 0; 442 return (0); 443 } 444 445 if (st->flush_obuf) { 446 **outbuf = st->temp_obuf[0]; 447 (*outbuf)++; 448 (*outbytesleft)--; 449 st->flush_obuf = 0; 450 if (*outbytesleft <= 0) { 451 return(*inbytesleft); 452 } 453 } 454 455 while (*inbytesleft > 0 && *outbytesleft > 0) { 456 if (!is_SI(inbuf, inbytesleft, st)) 457 break; 458 459 code = getc_12(inbuf, inbytesleft, st); 460 461 if (code&0x8000) { 462 code = packtocomp(code); 463 **outbuf = code>>8; 464 (*outbuf)++, (*outbytesleft)--; 465 if (*outbytesleft <= 0) { 466 st->flush_obuf = 1; 467 st->temp_obuf[0] = code&0xFF; 468 } else { 469 **outbuf = code&0xFF; 470 (*outbuf)++, (*outbytesleft)--; 471 } 472 } else { 473 **outbuf = code&0xFF; 474 (*outbuf)++, (*outbytesleft)--; 475 } 476 } 477 return (*inbytesleft); 478 } 479 480 int 481 is_SI(inbuf, inbytesleft, st) 482 char **inbuf; 483 size_t *inbytesleft; 484 struct _cv_state *st; 485 { 486 size_t i, x; 487 char *buf; 488 int SO_found = 0, SI_found = 0; 489 490 buf = *inbuf; 491 for (i = *inbytesleft; i > 0; i--) { 492 /* if SO is found */ 493 if (*buf == 0x0e) { 494 SO_found = 1; 495 break; 496 } else 497 buf++; 498 } 499 500 if (SO_found || st->ibuf_left) { 501 while (i > 0) { 502 i--; 503 /* if SI is found */ 504 if (*buf == 0x0f) { 505 SI_found = 1; 506 break; 507 } else 508 buf++; 509 } 510 } 511 512 513 /* if input buffer is not complete, i.e., last SI is not there */ 514 /* NEED to check for size of left buffer vs. temp_ibuf[] size */ 515 if ((SO_found && !SI_found) || (st->ibuf_left && !SI_found)) { 516 st->ibuf_left = 1; 517 x = *inbytesleft; 518 for (i = 0; i < x; i++) { 519 st->temp_ibuf[st->iend] = **inbuf; 520 st->iend++; 521 (*inbuf)++; 522 (*inbytesleft)--; 523 } 524 return(0); 525 } 526 return(1); 527 } 528 529 #ifdef TEST 530 531 /* test case 1 */ 532 char ibuf1[] = {0x0e, 0x57, 0x6c, 0x0f, 0x0e, 0x55, 0x67, 0x0f, 0x0e, 0x5a, 0x62, 0x57, 0x0f}; 533 char obuf1[20]; 534 535 /* test case 2 */ 536 char ibuf2[] = {0x0e, 0x57, 0x6c, 0x0f, 0x0e, 0x55}; 537 char ibuf21[] = {0x67, 0x0f, 0x0e, 0x5a, 0x62, 0x57, 0x0f}; 538 char obuf2[20]; 539 540 /* test case 3 */ 541 char ibuf3[] = {0x0e, 0x57, 0x6c, 0x0f, 0x0e, 0x55, 0x67, 0x0f, 0x0e, 0x5a, 0x62, 0x57, 0x0f}; 542 char obuf3[4]; 543 544 /* test case 3+ */ 545 char obuf31[5]; 546 547 main() 548 { 549 int i; 550 struct _cv_state *st; 551 size_t oleft, ileft; 552 char *ip1 = &ibuf1[0], *op1 = &obuf1[0], 553 *ip2 = &ibuf2[0], *ip21 = &ibuf21[0], *op2 = &obuf2[0], 554 *ip3 = &ibuf3[0], *op3 = &obuf3[0]; 555 556 /****************************** test case 1 *************************/ 557 ileft = sizeof(ibuf1); 558 oleft = sizeof(obuf1); 559 560 st = _cv_open(); 561 562 printf("TEST 1\n INPUT BUFFER: "); 563 for (i = 0; i < ileft ; i++) { 564 printf("%x ", 0xff&ibuf1[i]); 565 } 566 printf("\n"); 567 printf("OUTPUT: return value %d ", 568 _cv_enconv(st, &ip1, &ileft, &op1, &oleft)); 569 printf("ileft %d oleft %d\n", ileft, oleft); 570 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 571 st->ibuf_left); 572 printf("OUTPUT BUFFER: "); 573 for (i = 0; i < (sizeof(obuf1) - oleft) ; i++) { 574 printf("%x ", 0xff&obuf1[i]); 575 } 576 printf("\n\n\n"); 577 _cv_close(st); 578 579 /************************ test case 2 ******************************/ 580 ileft = sizeof(ibuf2); 581 oleft = sizeof(obuf2); 582 583 st = _cv_open(); 584 585 printf("TEST 2\nINPUT BUFFER: "); 586 for (i = 0; i < ileft ; i++) { 587 printf("%x ", 0xff&ibuf2[i]); 588 } 589 printf("\n"); 590 printf("OUTPUT: return value %d ", 591 _cv_enconv(st, &ip2, &ileft, &op2, &oleft)); 592 printf("ileft %d oleft %d\n", ileft, oleft); 593 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 594 st->ibuf_left); 595 printf("OUTPUT BUFFER: "); 596 for (i = 0; i < (sizeof(obuf2) - oleft) ; i++) { 597 printf("%x ", 0xff&obuf2[i]); 598 } 599 printf("\n\n"); 600 601 ileft = sizeof(ibuf21); 602 oleft = sizeof(obuf2); 603 op2 = &obuf2[0]; 604 printf("INPUT BUFFER: "); 605 for (i = 0; i < ileft ; i++) { 606 printf("%x ", 0xff&ibuf21[i]); 607 } 608 printf("\n"); 609 printf("OUTPUT: return value %d ", 610 _cv_enconv(st, &ip21, &ileft, &op2, &oleft)); 611 printf("ileft %d oleft %d\n", ileft, oleft); 612 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 613 st->ibuf_left); 614 printf("OUTPUT BUFFER: "); 615 for (i = 0; i < (sizeof(obuf2) - oleft) ; i++) { 616 printf("%x ", 0xff&obuf2[i]); 617 } 618 printf("\n\n\n"); 619 _cv_close(st); 620 621 /************************ test case 3 ******************************/ 622 ileft = sizeof(ibuf3); 623 oleft = sizeof(obuf3); 624 625 st = _cv_open(); 626 627 printf("TEST 3\nINPUT BUFFER: "); 628 for (i = 0; i < ileft ; i++) { 629 printf("%x ", 0xff&ibuf3[i]); 630 } 631 printf("\n"); 632 printf("OUTPUT: return value %d ", 633 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 634 printf("ileft %d oleft %d\n", ileft, oleft); 635 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 636 st->ibuf_left); 637 printf(" strat_cnt %d end_cnt %d\n", st->istart, 638 st->iend); 639 printf("OUTPUT BUFFER: "); 640 for (i = 0; i < (sizeof(obuf3) - oleft) ; i++) { 641 printf("%x ", 0xff&obuf3[i]); 642 } 643 printf("\n\n"); 644 645 op3 = &obuf3[0]; 646 oleft = sizeof(obuf3); 647 printf("OUTPUT: return value %d ", 648 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 649 printf("ileft %d oleft %d\n", ileft, oleft); 650 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 651 st->ibuf_left); 652 printf(" strat_cnt %d end_cnt %d\n", st->istart, 653 st->iend); 654 printf("OUTPUT BUFFER: "); 655 for (i = 0; i < (sizeof(obuf3) - oleft) ; i++) { 656 printf("%x ", 0xff&obuf3[i]); 657 } 658 printf("\n\n"); 659 660 op3 = &obuf3[0]; 661 oleft = sizeof(obuf3); 662 printf("OUTPUT: return value %d ", 663 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 664 printf("ileft %d oleft %d\n", ileft, oleft); 665 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 666 st->ibuf_left); 667 printf(" strat_cnt %d end_cnt %d\n", st->istart, 668 st->iend); 669 printf("OUTPUT BUFFER: "); 670 for (i = 0; i < (sizeof(obuf3) - oleft) ; i++) { 671 printf("%x ", 0xff&obuf3[i]); 672 } 673 printf("\n\n\n"); 674 _cv_close(st); 675 676 /************************ test case 3+ ******************************/ 677 ip3 = &ibuf3[0]; 678 op3 = &obuf31[0]; 679 ileft = sizeof(ibuf3); 680 oleft = sizeof(obuf31); 681 682 st = _cv_open(); 683 684 printf("TEST 3+\nINPUT BUFFER: "); 685 for (i = 0; i < ileft ; i++) { 686 printf("%x ", 0xff&ibuf3[i]); 687 } 688 printf("\n"); 689 printf("OUTPUT: return value %d ", 690 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 691 printf("ileft %d oleft %d\n", ileft, oleft); 692 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 693 st->ibuf_left); 694 printf(" strat_cnt %d end_cnt %d\n", st->istart, 695 st->iend); 696 printf("OUTPUT BUFFER: "); 697 for (i = 0; i < (sizeof(obuf31) - oleft) ; i++) { 698 printf("%x ", 0xff&obuf31[i]); 699 } 700 printf("\n\n"); 701 702 op3 = &obuf31[0]; 703 oleft = sizeof(obuf31); 704 printf("OUTPUT: return value %d ", 705 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 706 printf("ileft %d oleft %d\n", ileft, oleft); 707 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 708 st->ibuf_left); 709 printf(" strat_cnt %d end_cnt %d\n", st->istart, 710 st->iend); 711 printf("OUTPUT BUFFER: "); 712 for (i = 0; i < (sizeof(obuf31) - oleft) ; i++) { 713 printf("%x ", 0xff&obuf31[i]); 714 } 715 printf("\n\n"); 716 717 op3 = &obuf31[0]; 718 oleft = sizeof(obuf31); 719 printf("OUTPUT: return value %d ", 720 _cv_enconv(st, &ip3, &ileft, &op3, &oleft)); 721 printf("ileft %d oleft %d\n", ileft, oleft); 722 printf(" flush_obuf %d ibuf_left %d\n", st->flush_obuf, 723 st->ibuf_left); 724 printf(" strat_cnt %d end_cnt %d\n", st->istart, 725 st->iend); 726 printf("OUTPUT BUFFER: "); 727 for (i = 0; i < (sizeof(obuf31) - oleft) ; i++) { 728 printf("%x ", 0xff&obuf31[i]); 729 } 730 printf("\n\n\n"); 731 _cv_close(st); 732 } 733 734 /* expected output 735 736 TEST 1 737 INPUT BUFFER: e 57 6c f e 55 67 f e 5a 62 57 f 738 OUTPUT: return value 0 ileft 0 oleft 14 739 flush_obuf 0 ibuf_left 0 740 OUTPUT BUFFER: bf c0 bc bc c3 a2 741 742 743 TEST 2 744 INPUT BUFFER: e 57 6c f e 55 745 OUTPUT: return value 0 ileft 0 oleft 18 746 flush_obuf 0 ibuf_left 1 747 OUTPUT BUFFER: bf c0 748 749 INPUT BUFFER: 67 f e 5a 62 57 f 750 OUTPUT: return value 0 ileft 0 oleft 16 751 flush_obuf 0 ibuf_left 0 752 OUTPUT BUFFER: bc bc c3 a2 753 754 755 TEST 3 756 INPUT BUFFER: e 57 6c f e 55 67 f e 5a 62 57 f 757 OUTPUT: return value 5 ileft 5 oleft 0 758 flush_obuf 0 ibuf_left 0 759 strat_cnt 0 end_cnt 0 760 OUTPUT BUFFER: bf c0 bc bc 761 762 OUTPUT: return value 0 ileft 0 oleft 2 763 flush_obuf 0 ibuf_left 0 764 strat_cnt 0 end_cnt 0 765 OUTPUT BUFFER: c3 a2 766 767 OUTPUT: return value 0 ileft 0 oleft 4 768 flush_obuf 0 ibuf_left 0 769 strat_cnt 0 end_cnt 0 770 OUTPUT BUFFER: 771 772 773 TEST 3+ 774 INPUT BUFFER: e 57 6c f e 55 67 f e 5a 62 57 f 775 OUTPUT: return value 0 ileft 0 oleft 0 776 flush_obuf 1 ibuf_left 0 777 strat_cnt 0 end_cnt 0 778 OUTPUT BUFFER: bf c0 bc bc c3 779 780 OUTPUT: return value 0 ileft 0 oleft 4 781 flush_obuf 0 ibuf_left 0 782 strat_cnt 0 end_cnt 0 783 OUTPUT BUFFER: a2 784 785 OUTPUT: return value 0 ileft 0 oleft 5 786 flush_obuf 0 ibuf_left 0 787 strat_cnt 0 end_cnt 0 788 OUTPUT BUFFER: 789 790 */ 791 792 #endif /* TEST */ 793