comparison src/oct-stream.cc @ 9952:7cd2e1b372e5

allow scanf to store ASCII NUL values
author John W. Eaton <jwe@octave.org>
date Thu, 10 Dec 2009 01:03:34 -0500
parents 1369f13ae6b2
children 4b270d1540f7
comparison
equal deleted inserted replaced
9951:d64d15e12e6b 9952:7cd2e1b372e5
1553 #define BEGIN_C_CONVERSION() \ 1553 #define BEGIN_C_CONVERSION() \
1554 is.unsetf (std::ios::skipws); \ 1554 is.unsetf (std::ios::skipws); \
1555 \ 1555 \
1556 int width = elt->width ? elt->width : 1; \ 1556 int width = elt->width ? elt->width : 1; \
1557 \ 1557 \
1558 char *tbuf = new char[width + 1]; \ 1558 std::string tmp (width, '\0'); \
1559 \ 1559 \
1560 int c = EOF; \ 1560 int c = EOF; \
1561 int n = 0; \ 1561 int n = 0; \
1562 \ 1562 \
1563 while (is && n < width && (c = is.get ()) != EOF) \ 1563 while (is && n < width && (c = is.get ()) != EOF) \
1564 tbuf[n++] = static_cast<char> (c); \ 1564 tmp[n++] = static_cast<char> (c); \
1565 \
1566 tbuf[n] = '\0'; \
1567 \ 1565 \
1568 if (n > 0 && c == EOF) \ 1566 if (n > 0 && c == EOF) \
1569 is.clear (); \ 1567 is.clear ()
1570 \
1571 std::string tmp = tbuf; \
1572 \
1573 delete [] tbuf
1574 1568
1575 // For a `%s' format, skip initial whitespace and then read until the 1569 // For a `%s' format, skip initial whitespace and then read until the
1576 // next whitespace character or until WIDTH characters have been read. 1570 // next whitespace character or until WIDTH characters have been read.
1577 #define BEGIN_S_CONVERSION() \ 1571 #define BEGIN_S_CONVERSION() \
1578 int width = elt->width; \ 1572 int width = elt->width; \
1581 \ 1575 \
1582 do \ 1576 do \
1583 { \ 1577 { \
1584 if (width) \ 1578 if (width) \
1585 { \ 1579 { \
1586 char *tbuf = new char [width+1]; \ 1580 std::string tmp (width, '\0'); \
1587 \ 1581 \
1588 int c = EOF; \ 1582 int c = EOF; \
1589 \ 1583 \
1590 int n = 0; \ 1584 int n = 0; \
1591 \ 1585 \
1592 while (is && (c = is.get ()) != EOF) \ 1586 while (is && (c = is.get ()) != EOF) \
1593 { \ 1587 { \
1594 if (! isspace (c)) \ 1588 if (! isspace (c)) \
1595 { \ 1589 { \
1596 tbuf[n++] = static_cast<char> (c); \ 1590 tmp[n++] = static_cast<char> (c); \
1597 break; \ 1591 break; \
1598 } \ 1592 } \
1599 } \ 1593 } \
1600 \ 1594 \
1601 while (is && n < width && (c = is.get ()) != EOF) \ 1595 while (is && n < width && (c = is.get ()) != EOF) \
1604 { \ 1598 { \
1605 is.putback (c); \ 1599 is.putback (c); \
1606 break; \ 1600 break; \
1607 } \ 1601 } \
1608 else \ 1602 else \
1609 tbuf[n++] = static_cast<char> (c); \ 1603 tmp[n++] = static_cast<char> (c); \
1610 } \ 1604 } \
1611 \
1612 tbuf[n] = '\0'; \
1613 \ 1605 \
1614 if (n > 0 && c == EOF) \ 1606 if (n > 0 && c == EOF) \
1615 is.clear (); \ 1607 is.clear (); \
1616 \ 1608 \
1617 tmp = tbuf; \ 1609 tmp.resize (n); \
1618 \
1619 delete [] tbuf; \
1620 } \ 1610 } \
1621 else \ 1611 else \
1622 { \ 1612 { \
1623 is >> std::ws >> tmp; \ 1613 is >> std::ws >> tmp; \
1624 } \ 1614 } \
1678 \ 1668 \
1679 if (! discard) \ 1669 if (! discard) \
1680 { \ 1670 { \
1681 conversion_count++; \ 1671 conversion_count++; \
1682 \ 1672 \
1683 while (i < width && tmp[i] != '\0') \ 1673 while (i < width) \
1684 { \ 1674 { \
1685 if (data_index == max_size) \ 1675 if (data_index == max_size) \
1686 { \ 1676 { \
1687 max_size *= 2; \ 1677 max_size *= 2; \
1688 \ 1678 \