comparison src/ccl.c @ 23280:b4656367043f

(CCL_WRITE_CHAR): Don't use bcopy. (ccl_driver): If BUFFER-MAGNIFICATION of the CCL program is 0, cause error if the program is going to output some bytes. When outputing a string to notify an error, check the case that DST_BYTES is zero.
author Kenichi Handa <handa@m17n.org>
date Fri, 18 Sep 1998 13:10:40 +0000
parents 9edc07f08118
children fb38954a02d3
comparison
equal deleted inserted replaced
23279:ca159e828a68 23280:b4656367043f
668 { \ 668 { \
669 unsigned char work[4], *str; \ 669 unsigned char work[4], *str; \
670 int len = CHAR_STRING (ch, work, str); \ 670 int len = CHAR_STRING (ch, work, str); \
671 if (dst + len <= (dst_bytes ? dst_end : src)) \ 671 if (dst + len <= (dst_bytes ? dst_end : src)) \
672 { \ 672 { \
673 bcopy (str, dst, len); \ 673 while (len--) *dst++ = *str++; \
674 dst += len; \
675 } \ 674 } \
676 else \ 675 else \
677 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \ 676 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
678 } \ 677 } \
679 } while (0) 678 } while (0)
748 /* For the moment, we only support depth 256 of stack. */ 747 /* For the moment, we only support depth 256 of stack. */
749 struct ccl_prog_stack ccl_prog_stack_struct[256]; 748 struct ccl_prog_stack ccl_prog_stack_struct[256];
750 749
751 if (ic >= ccl->eof_ic) 750 if (ic >= ccl->eof_ic)
752 ic = CCL_HEADER_MAIN; 751 ic = CCL_HEADER_MAIN;
752
753 if (ccl->buf_magnification ==0) /* We can't produce any bytes. */
754 dst = NULL;
753 755
754 #ifdef CCL_DEBUG 756 #ifdef CCL_DEBUG
755 ccl_backtrace_idx = 0; 757 ccl_backtrace_idx = 0;
756 #endif 758 #endif
757 759
1541 specified and we still have a room to store the message 1543 specified and we still have a room to store the message
1542 there. */ 1544 there. */
1543 char msg[256]; 1545 char msg[256];
1544 int msglen; 1546 int msglen;
1545 1547
1548 if (!dst)
1549 dst = destination;
1550
1546 switch (ccl->status) 1551 switch (ccl->status)
1547 { 1552 {
1548 case CCL_STAT_INVALID_CMD: 1553 case CCL_STAT_INVALID_CMD:
1549 sprintf(msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.", 1554 sprintf(msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
1550 code & 0x1F, code, ic); 1555 code & 0x1F, code, ic);
1552 { 1557 {
1553 int i = ccl_backtrace_idx - 1; 1558 int i = ccl_backtrace_idx - 1;
1554 int j; 1559 int j;
1555 1560
1556 msglen = strlen (msg); 1561 msglen = strlen (msg);
1557 if (dst + msglen <= dst_end) 1562 if (dst + msglen <= (dst_bytes ? dst_end : src))
1558 { 1563 {
1559 bcopy (msg, dst, msglen); 1564 bcopy (msg, dst, msglen);
1560 dst += msglen; 1565 dst += msglen;
1561 } 1566 }
1562 1567
1565 if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1; 1570 if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1;
1566 if (ccl_backtrace_table[i] == 0) 1571 if (ccl_backtrace_table[i] == 0)
1567 break; 1572 break;
1568 sprintf(msg, " %d", ccl_backtrace_table[i]); 1573 sprintf(msg, " %d", ccl_backtrace_table[i]);
1569 msglen = strlen (msg); 1574 msglen = strlen (msg);
1570 if (dst + msglen > dst_end) 1575 if (dst + msglen > (dst_bytes ? dst_end : src))
1571 break; 1576 break;
1572 bcopy (msg, dst, msglen); 1577 bcopy (msg, dst, msglen);
1573 dst += msglen; 1578 dst += msglen;
1574 } 1579 }
1580 goto ccl_finish;
1575 } 1581 }
1576 #endif 1582 #endif
1577 goto ccl_finish; 1583 break;
1578 1584
1579 case CCL_STAT_QUIT: 1585 case CCL_STAT_QUIT:
1580 sprintf(msg, "\nCCL: Quited."); 1586 sprintf(msg, "\nCCL: Quited.");
1581 break; 1587 break;
1582 1588
1583 default: 1589 default:
1584 sprintf(msg, "\nCCL: Unknown error type (%d).", ccl->status); 1590 sprintf(msg, "\nCCL: Unknown error type (%d).", ccl->status);
1585 } 1591 }
1586 1592
1587 msglen = strlen (msg); 1593 msglen = strlen (msg);
1588 if (dst + msglen <= dst_end) 1594 if (dst + msglen <= (dst_bytes ? dst_end : src))
1589 { 1595 {
1590 bcopy (msg, dst, msglen); 1596 bcopy (msg, dst, msglen);
1591 dst += msglen; 1597 dst += msglen;
1592 } 1598 }
1593 } 1599 }
1594 1600
1595 ccl_finish: 1601 ccl_finish:
1596 ccl->ic = ic; 1602 ccl->ic = ic;
1597 if (consumed) *consumed = src - source; 1603 if (consumed) *consumed = src - source;
1598 return dst - destination; 1604 return (dst ? dst - destination : 0);
1599 } 1605 }
1600 1606
1601 /* Setup fields of the structure pointed by CCL appropriately for the 1607 /* Setup fields of the structure pointed by CCL appropriately for the
1602 execution of compiled CCL code in VEC (vector of integer). */ 1608 execution of compiled CCL code in VEC (vector of integer). */
1603 void 1609 void