Mercurial > hg > octave-nkf
comparison src/oct-stream.cc @ 3633:2e6a41bc8fed
[project @ 2000-03-23 09:32:36 by jwe]
author | jwe |
---|---|
date | Thu, 23 Mar 2000 09:32:36 +0000 |
parents | 58e52fbee1dd |
children | 68b993aa2020 |
comparison
equal
deleted
inserted
replaced
3632:95d7c4b2b2e8 | 3633:2e6a41bc8fed |
---|---|
23 #ifdef HAVE_CONFIG_H | 23 #ifdef HAVE_CONFIG_H |
24 #include <config.h> | 24 #include <config.h> |
25 #endif | 25 #endif |
26 | 26 |
27 #include <cassert> | 27 #include <cassert> |
28 #include <cstdarg> | |
28 #include <cstring> | 29 #include <cstring> |
29 | 30 |
30 #include <iomanip> | 31 #include <iomanip> |
31 #include <strstream> | 32 #include <strstream> |
32 #include <fstream> | 33 #include <fstream> |
40 #include "error.h" | 41 #include "error.h" |
41 #include "input.h" | 42 #include "input.h" |
42 #include "oct-stream.h" | 43 #include "oct-stream.h" |
43 #include "oct-obj.h" | 44 #include "oct-obj.h" |
44 #include "utils.h" | 45 #include "utils.h" |
46 | |
47 static istream& | |
48 octave_scan (istream& is, const char *fmt, ...) | |
49 { | |
50 #if defined (__GNUG__) | |
51 | |
52 va_list args; | |
53 va_start (args, fmt); | |
54 | |
55 is.vscan (fmt, args); | |
56 | |
57 va_end (args); | |
58 | |
59 #endif | |
60 | |
61 return is; | |
62 } | |
45 | 63 |
46 // Possible values for conv_err: | 64 // Possible values for conv_err: |
47 // | 65 // |
48 // 1 : not a real scalar | 66 // 1 : not a real scalar |
49 // 2 : value is NaN | 67 // 2 : value is NaN |
1010 void | 1028 void |
1011 do_scanf_conv (std::istream& is, const char *fmt, T valptr, Matrix& mval, | 1029 do_scanf_conv (std::istream& is, const char *fmt, T valptr, Matrix& mval, |
1012 double *data, int& idx, int& conversion_count, int nr, | 1030 double *data, int& idx, int& conversion_count, int nr, |
1013 int max_size, bool discard) | 1031 int max_size, bool discard) |
1014 { | 1032 { |
1015 is.scan (fmt, valptr); | 1033 octave_scan (is, fmt, valptr); |
1016 | 1034 |
1017 if (is) | 1035 if (is) |
1018 { | 1036 { |
1019 if (idx == max_size && ! discard) | 1037 if (idx == max_size && ! discard) |
1020 { | 1038 { |
1124 { \ | 1142 { \ |
1125 if (width) \ | 1143 if (width) \ |
1126 { \ | 1144 { \ |
1127 tmp = new char [width+1]; \ | 1145 tmp = new char [width+1]; \ |
1128 \ | 1146 \ |
1129 is.scan (fmt, tmp); \ | 1147 octave_scan (is, fmt, tmp); \ |
1130 \ | 1148 \ |
1131 tmp[width] = '\0'; \ | 1149 tmp[width] = '\0'; \ |
1132 } \ | 1150 } \ |
1133 else \ | 1151 else \ |
1134 { \ | 1152 { \ |
1165 { \ | 1183 { \ |
1166 if (width) \ | 1184 if (width) \ |
1167 { \ | 1185 { \ |
1168 tmp = new char[width+1]; \ | 1186 tmp = new char[width+1]; \ |
1169 \ | 1187 \ |
1170 is.scan (fmt, tmp); \ | 1188 octave_scan (is, fmt, tmp); \ |
1171 \ | 1189 \ |
1172 tmp[width] = '\0'; \ | 1190 tmp[width] = '\0'; \ |
1173 } \ | 1191 } \ |
1174 else \ | 1192 else \ |
1175 { \ | 1193 { \ |
1379 | 1397 |
1380 case '%': | 1398 case '%': |
1381 { | 1399 { |
1382 int dummy; | 1400 int dummy; |
1383 | 1401 |
1384 is.scan (fmt, &dummy); | 1402 octave_scan (is, fmt, &dummy); |
1385 } | 1403 } |
1386 break; | 1404 break; |
1387 | 1405 |
1388 case 'd': case 'i': case 'o': case 'u': case 'x': | 1406 case 'd': case 'i': case 'o': case 'u': case 'x': |
1389 { | 1407 { |
1579 | 1597 |
1580 if (elt) | 1598 if (elt) |
1581 { | 1599 { |
1582 is.clear (); | 1600 is.clear (); |
1583 | 1601 |
1584 is.scan (elt->text); | 1602 octave_scan (is, elt->text); |
1585 | 1603 |
1586 if (! is) | 1604 if (! is) |
1587 { | 1605 { |
1588 // If it looks like we have a matching failure, then | 1606 // If it looks like we have a matching failure, then |
1589 // reset the failbit in the stream state. | 1607 // reset the failbit in the stream state. |
1663 | 1681 |
1664 case '%': | 1682 case '%': |
1665 { | 1683 { |
1666 int dummy; | 1684 int dummy; |
1667 | 1685 |
1668 if (! is.scan (fmt, &dummy)) | 1686 if (! octave_scan (is, fmt, &dummy)) |
1669 quit = true; | 1687 quit = true; |
1670 } | 1688 } |
1671 break; | 1689 break; |
1672 | 1690 |
1673 case 'd': case 'i': case 'o': case 'u': case 'x': | 1691 case 'd': case 'i': case 'o': case 'u': case 'x': |
1674 { | 1692 { |
1675 int tmp; | 1693 int tmp; |
1676 | 1694 |
1677 if (is.scan (fmt, &tmp)) | 1695 if (octave_scan (is, fmt, &tmp)) |
1678 { | 1696 { |
1679 if (! discard) | 1697 if (! discard) |
1680 retval = static_cast<double> (tmp); | 1698 retval = static_cast<double> (tmp); |
1681 } | 1699 } |
1682 else | 1700 else |
1686 | 1704 |
1687 case 'e': case 'f': case 'g': | 1705 case 'e': case 'f': case 'g': |
1688 { | 1706 { |
1689 double tmp; | 1707 double tmp; |
1690 | 1708 |
1691 if (is.scan (fmt, &tmp)) | 1709 if (octave_scan (is, fmt, &tmp)) |
1692 { | 1710 { |
1693 if (! discard) | 1711 if (! discard) |
1694 retval = tmp; | 1712 retval = tmp; |
1695 } | 1713 } |
1696 else | 1714 else |
1798 | 1816 |
1799 if (elt) | 1817 if (elt) |
1800 { | 1818 { |
1801 is.clear (); | 1819 is.clear (); |
1802 | 1820 |
1803 is.scan (elt->text); | 1821 octave_scan (is, elt->text); |
1804 | 1822 |
1805 if (! is) | 1823 if (! is) |
1806 { | 1824 { |
1807 error ("fscanf: read error"); | 1825 error ("fscanf: read error"); |
1808 | 1826 |