Mercurial > hg > octave-nkf
comparison src/pr-output.cc @ 1755:3a9462b655f1
[project @ 1996-01-22 04:47:22 by jwe]
author | jwe |
---|---|
date | Mon, 22 Jan 1996 04:47:22 +0000 |
parents | a02f140ed897 |
children | bc7ae9be3378 |
comparison
equal
deleted
inserted
replaced
1754:5f1938919fdc | 1755:3a9462b655f1 |
---|---|
36 | 36 |
37 #include "CMatrix.h" | 37 #include "CMatrix.h" |
38 #include "Range.h" | 38 #include "Range.h" |
39 #include "dMatrix.h" | 39 #include "dMatrix.h" |
40 #include "oct-cmplx.h" | 40 #include "oct-cmplx.h" |
41 #include "str-vec.h" | |
41 | 42 |
42 #include "defun.h" | 43 #include "defun.h" |
43 #include "error.h" | 44 #include "error.h" |
44 #include "help.h" | 45 #include "help.h" |
45 #include "mappers.h" | 46 #include "mappers.h" |
47 #include "oct-obj.h" | |
46 #include "pager.h" | 48 #include "pager.h" |
47 #include "pr-output.h" | 49 #include "pr-output.h" |
50 #include "pt-const.h" | |
48 #include "sysdep.h" | 51 #include "sysdep.h" |
49 #include "pt-const.h" | |
50 #include "oct-obj.h" | |
51 #include "user-prefs.h" | 52 #include "user-prefs.h" |
52 #include "utils.h" | 53 #include "utils.h" |
53 #include "variables.h" | 54 #include "variables.h" |
54 | 55 |
55 // Current format string for real numbers and the real part of complex | 56 // Current format string for real numbers and the real part of complex |
1516 if (pr_as_read_syntax && nstr > 1) | 1517 if (pr_as_read_syntax && nstr > 1) |
1517 os << "[ "; | 1518 os << "[ "; |
1518 | 1519 |
1519 for (int i = 0; i < nstr; i++) | 1520 for (int i = 0; i < nstr; i++) |
1520 { | 1521 { |
1521 string tstr = chm.row_as_string (i); | 1522 string row = chm.row_as_string (i); |
1522 const char *row = tstr.c_str (); | |
1523 | 1523 |
1524 if (pr_as_read_syntax) | 1524 if (pr_as_read_syntax) |
1525 { | 1525 { |
1526 char *tmp = undo_string_escapes (row); | 1526 os << "\"" << undo_string_escapes (row) << "\""; |
1527 | |
1528 os << "\"" << tmp << "\""; | |
1529 | |
1530 delete [] tmp; | |
1531 | 1527 |
1532 if (i < nstr - 1) | 1528 if (i < nstr - 1) |
1533 os << "; "; | 1529 os << "; "; |
1534 } | 1530 } |
1535 else | 1531 else |
1536 os << row << "\n"; | 1532 os << row << "\n"; |
1537 | |
1538 delete [] row; | |
1539 } | 1533 } |
1540 | 1534 |
1541 if (pr_as_read_syntax && nstr > 1) | 1535 if (pr_as_read_syntax && nstr > 1) |
1542 os << " ]"; | 1536 os << " ]"; |
1543 } | 1537 } |
1584 | 1578 |
1585 tmp = new tree_constant ((double) fw); | 1579 tmp = new tree_constant ((double) fw); |
1586 bind_builtin_variable ("output_max_field_width", tmp); | 1580 bind_builtin_variable ("output_max_field_width", tmp); |
1587 } | 1581 } |
1588 | 1582 |
1589 void | 1583 static void |
1590 set_format_style (int argc, char **argv) | 1584 set_format_style (int argc, const string_vector& argv) |
1591 { | 1585 { |
1592 if (--argc > 0) | 1586 int idx = 1; |
1593 { | 1587 string arg = argv[idx++]; |
1594 argv++; | 1588 |
1595 if (*argv[0]) | 1589 if (argc > 1) |
1596 { | 1590 { |
1597 if (strcmp (*argv, "short") == 0) | 1591 if (arg == "short") |
1592 { | |
1593 if (--argc > 0) | |
1598 { | 1594 { |
1599 if (--argc > 0) | 1595 arg = argv[idx++]; |
1596 | |
1597 if (arg == "e") | |
1600 { | 1598 { |
1601 argv++; | 1599 init_format_state (); |
1602 if (strcmp (*argv, "e") == 0) | 1600 print_e = 1; |
1603 { | 1601 } |
1604 init_format_state (); | 1602 else if (arg == "E") |
1605 print_e = 1; | 1603 { |
1606 } | 1604 init_format_state (); |
1607 else if (strcmp (*argv, "E") == 0) | 1605 print_e = 1; |
1608 { | 1606 print_big_e = 1; |
1609 init_format_state (); | |
1610 print_e = 1; | |
1611 print_big_e = 1; | |
1612 } | |
1613 else | |
1614 { | |
1615 error ("format: unrecognized option `short %s'", *argv); | |
1616 return; | |
1617 } | |
1618 } | 1607 } |
1619 else | 1608 else |
1620 init_format_state (); | 1609 { |
1621 | 1610 error ("format: unrecognized option `short %s'", |
1622 set_output_prec_and_fw (3, 8); | 1611 arg.c_str ()); |
1612 return; | |
1613 } | |
1623 } | 1614 } |
1624 else if (strcmp (*argv, "long") == 0) | 1615 else |
1616 init_format_state (); | |
1617 | |
1618 set_output_prec_and_fw (3, 8); | |
1619 } | |
1620 else if (arg == "long") | |
1621 { | |
1622 if (--argc > 0) | |
1625 { | 1623 { |
1626 if (--argc > 0) | 1624 arg = argv[idx++]; |
1625 | |
1626 if (arg == "e") | |
1627 { | 1627 { |
1628 argv++; | 1628 init_format_state (); |
1629 if (strcmp (*argv, "e") == 0) | 1629 print_e = 1; |
1630 { | 1630 } |
1631 init_format_state (); | 1631 else if (arg == "E") |
1632 print_e = 1; | 1632 { |
1633 } | 1633 init_format_state (); |
1634 else if (strcmp (*argv, "E") == 0) | 1634 print_e = 1; |
1635 { | 1635 print_big_e = 1; |
1636 init_format_state (); | |
1637 print_e = 1; | |
1638 print_big_e = 1; | |
1639 } | |
1640 else | |
1641 { | |
1642 error ("format: unrecognized option `long %s'", *argv); | |
1643 return; | |
1644 } | |
1645 } | 1636 } |
1646 else | 1637 else |
1647 init_format_state (); | 1638 { |
1648 | 1639 error ("format: unrecognized option `long %s'", |
1649 set_output_prec_and_fw (15, 24); | 1640 arg.c_str ()); |
1650 } | 1641 return; |
1651 else if (strcmp (*argv, "hex") == 0) | 1642 } |
1652 { | |
1653 init_format_state (); | |
1654 hex_format = 1; | |
1655 } | |
1656 else if (strcmp (*argv, "native-hex") == 0) | |
1657 { | |
1658 init_format_state (); | |
1659 hex_format = 2; | |
1660 } | |
1661 else if (strcmp (*argv, "bit") == 0) | |
1662 { | |
1663 init_format_state (); | |
1664 bit_format = 1; | |
1665 } | |
1666 else if (strcmp (*argv, "native-bit") == 0) | |
1667 { | |
1668 init_format_state (); | |
1669 bit_format = 2; | |
1670 } | |
1671 else if (strcmp (*argv, "+") == 0 || strcmp (*argv, "plus") == 0) | |
1672 { | |
1673 init_format_state (); | |
1674 plus_format = 1; | |
1675 } | |
1676 else if (strcmp (*argv, "bank") == 0) | |
1677 { | |
1678 init_format_state (); | |
1679 bank_format = 1; | |
1680 } | |
1681 else if (strcmp (*argv, "free") == 0) | |
1682 { | |
1683 init_format_state (); | |
1684 free_format = 1; | |
1685 } | |
1686 else if (strcmp (*argv, "none") == 0) | |
1687 { | |
1688 init_format_state (); | |
1689 free_format = 1; | |
1690 } | |
1691 else if (strcmp (*argv, "compact") == 0) | |
1692 { | |
1693 compact_format = 1; | |
1694 } | |
1695 else if (strcmp (*argv, "loose") == 0) | |
1696 { | |
1697 compact_format = 0; | |
1698 } | 1643 } |
1699 else | 1644 else |
1700 error ("format: unrecognized format state `%s'", *argv); | 1645 init_format_state (); |
1701 } | 1646 |
1702 else | 1647 set_output_prec_and_fw (15, 24); |
1703 usage ("format [format_state]"); | 1648 } |
1649 else if (arg == "hex") | |
1650 { | |
1651 init_format_state (); | |
1652 hex_format = 1; | |
1653 } | |
1654 else if (arg == "native-hex") | |
1655 { | |
1656 init_format_state (); | |
1657 hex_format = 2; | |
1658 } | |
1659 else if (arg == "bit") | |
1660 { | |
1661 init_format_state (); | |
1662 bit_format = 1; | |
1663 } | |
1664 else if (arg == "native-bit") | |
1665 { | |
1666 init_format_state (); | |
1667 bit_format = 2; | |
1668 } | |
1669 else if (arg == "+" || arg == "plus") | |
1670 { | |
1671 init_format_state (); | |
1672 plus_format = 1; | |
1673 } | |
1674 else if (arg == "bank") | |
1675 { | |
1676 init_format_state (); | |
1677 bank_format = 1; | |
1678 } | |
1679 else if (arg == "free") | |
1680 { | |
1681 init_format_state (); | |
1682 free_format = 1; | |
1683 } | |
1684 else if (arg == "none") | |
1685 { | |
1686 init_format_state (); | |
1687 free_format = 1; | |
1688 } | |
1689 else if (arg == "compact") | |
1690 { | |
1691 compact_format = 1; | |
1692 } | |
1693 else if (arg == "loose") | |
1694 { | |
1695 compact_format = 0; | |
1696 } | |
1697 else | |
1698 error ("format: unrecognized format state `%s'", arg.c_str ()); | |
1704 } | 1699 } |
1705 else | 1700 else |
1706 { | 1701 { |
1707 init_format_state (); | 1702 init_format_state (); |
1708 set_output_prec_and_fw (5, 10); | 1703 set_output_prec_and_fw (5, 10); |
1714 \n\ | 1709 \n\ |
1715 set output formatting style") | 1710 set output formatting style") |
1716 { | 1711 { |
1717 Octave_object retval; | 1712 Octave_object retval; |
1718 | 1713 |
1719 DEFINE_ARGV("format"); | 1714 int argc = args.length () + 1; |
1715 | |
1716 string_vector argv = make_argv (args, "format"); | |
1717 | |
1718 if (error_state) | |
1719 return retval; | |
1720 | 1720 |
1721 set_format_style (argc, argv); | 1721 set_format_style (argc, argv); |
1722 | |
1723 DELETE_ARGV; | |
1724 | 1722 |
1725 return retval; | 1723 return retval; |
1726 } | 1724 } |
1727 | 1725 |
1728 /* | 1726 /* |