Mercurial > octave-nkf
comparison src/load-save.cc @ 5369:4bbde94b5cf8
[project @ 2005-05-23 23:39:28 by jwe]
author | jwe |
---|---|
date | Mon, 23 May 2005 23:39:28 +0000 |
parents | 05adf9de7657 |
children | 1eb29d3bed2b |
comparison
equal
deleted
inserted
replaced
5368:720dc7f7a75e | 5369:4bbde94b5cf8 |
---|---|
105 // The format string for the comment line at the top of text-format | 105 // The format string for the comment line at the top of text-format |
106 // save files. Passed to strftime. Should begin with `#' and contain | 106 // save files. Passed to strftime. Should begin with `#' and contain |
107 // no newline characters. | 107 // no newline characters. |
108 static std::string Vsave_header_format_string; | 108 static std::string Vsave_header_format_string; |
109 | 109 |
110 static void | |
111 gripe_file_open (const std::string& fcn, const std::string& file) | |
112 { | |
113 if (fcn == "load") | |
114 error ("%s: unable to open input file `%s'", fcn.c_str (), file.c_str ()); | |
115 else if (fcn == "save") | |
116 error ("%s: unable to open output file `%s'", fcn.c_str (), file.c_str ()); | |
117 else | |
118 error ("%s: unable to open file `%s'", fcn.c_str (), file.c_str ()); | |
119 } | |
120 | |
110 // XXX FIXME XXX -- shouldn't this be implemented in terms of other | 121 // XXX FIXME XXX -- shouldn't this be implemented in terms of other |
111 // functions that are already available? | 122 // functions that are already available? |
112 | 123 |
113 // Install a variable with name NAME and the value specified TC in the | 124 // Install a variable with name NAME and the value specified TC in the |
114 // symbol table. If FORCE is TRUE, replace any existing definition | 125 // symbol table. If FORCE is TRUE, replace any existing definition |
283 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) | 294 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) |
284 swap = ! oct_mach_info::words_big_endian (); | 295 swap = ! oct_mach_info::words_big_endian (); |
285 else | 296 else |
286 { | 297 { |
287 if (! quiet) | 298 if (! quiet) |
288 error ("load: can't read binary file"); | 299 error ("load: unable to read read binary file"); |
289 return -1; | 300 return -1; |
290 } | 301 } |
291 | 302 |
292 char tmp = 0; | 303 char tmp = 0; |
293 is.read (X_CAST (char *, &tmp), 1); | 304 is.read (X_CAST (char *, &tmp), 1); |
416 } | 427 } |
417 | 428 |
418 #endif | 429 #endif |
419 } | 430 } |
420 else | 431 else |
421 error ("load: couldn't open input file `%s'", orig_fname.c_str ()); | 432 gripe_file_open ("load", orig_fname); |
422 | 433 |
423 return retval; | 434 return retval; |
424 } | 435 } |
425 | 436 |
426 octave_value | 437 octave_value |
798 std::ifstream file_mat_exist (fname.c_str ()); | 809 std::ifstream file_mat_exist (fname.c_str ()); |
799 if (file_mat_exist) | 810 if (file_mat_exist) |
800 file_mat_exist.close (); | 811 file_mat_exist.close (); |
801 else | 812 else |
802 { | 813 { |
803 error ("load: nonexistent file: `%s'", orig_fname.c_str ()); | 814 gripe_file_open ("load", orig_fname); |
804 return retval; | 815 return retval; |
805 } | 816 } |
806 } | 817 } |
807 | 818 |
808 if (format == LS_UNKNOWN) | 819 if (format == LS_UNKNOWN) |
822 argv, i, argc, nargout); | 833 argv, i, argc, nargout); |
823 | 834 |
824 hdf5_file.close (); | 835 hdf5_file.close (); |
825 } | 836 } |
826 else | 837 else |
827 error ("load: couldn't open input file `%s'", | 838 gripe_file_open ("load", orig_fname); |
828 orig_fname.c_str ()); | |
829 } | 839 } |
830 else | 840 else |
831 #endif /* HAVE_HDF5 */ | 841 #endif /* HAVE_HDF5 */ |
832 // don't insert any statements here; the "else" above has to | 842 // don't insert any statements here; the "else" above has to |
833 // go with the "if" below!!!!! | 843 // go with the "if" below!!!!! |
876 argv, i, argc, nargout); | 886 argv, i, argc, nargout); |
877 | 887 |
878 file.close (); | 888 file.close (); |
879 } | 889 } |
880 else | 890 else |
881 error ("load: couldn't open input file `%s'", | 891 gripe_file_open ("load", orig_fname); |
882 orig_fname.c_str ()); | |
883 } | 892 } |
884 else | 893 else |
885 #endif | 894 #endif |
886 { | 895 { |
887 std::ifstream file (fname.c_str (), mode); | 896 std::ifstream file (fname.c_str (), mode); |
911 argv, i, argc, nargout); | 920 argv, i, argc, nargout); |
912 | 921 |
913 file.close (); | 922 file.close (); |
914 } | 923 } |
915 else | 924 else |
916 error ("load: couldn't open input file `%s'", | 925 error ("load: unable open input file `%s'", |
917 orig_fname.c_str ()); | 926 orig_fname.c_str ()); |
918 } | 927 } |
919 } | 928 } |
920 } | 929 } |
921 | 930 |
1657 | 1666 |
1658 hdf5_file.close (); | 1667 hdf5_file.close (); |
1659 } | 1668 } |
1660 else | 1669 else |
1661 { | 1670 { |
1662 error ("save: couldn't open output file `%s'", fname.c_str ()); | 1671 gripe_file_open ("save", fname); |
1663 return retval; | 1672 return retval; |
1664 } | 1673 } |
1665 } | 1674 } |
1666 else | 1675 else |
1667 #endif /* HAVE_HDF5 */ | 1676 #endif /* HAVE_HDF5 */ |
1684 | 1693 |
1685 file.close (); | 1694 file.close (); |
1686 } | 1695 } |
1687 else | 1696 else |
1688 { | 1697 { |
1689 error ("save: couldn't open output file `%s'", | 1698 gripe_file_open ("save", fname); |
1690 fname.c_str ()); | |
1691 return retval; | 1699 return retval; |
1692 } | 1700 } |
1693 } | 1701 } |
1694 else | 1702 else |
1695 #endif | 1703 #endif |
1707 | 1715 |
1708 file.close (); | 1716 file.close (); |
1709 } | 1717 } |
1710 else | 1718 else |
1711 { | 1719 { |
1712 error ("save: couldn't open output file `%s'", | 1720 gripe_file_open ("save", fname); |
1713 fname.c_str ()); | |
1714 return retval; | 1721 return retval; |
1715 } | 1722 } |
1716 } | 1723 } |
1717 } | 1724 } |
1718 } | 1725 } |