comparison libinterp/corefcn/file-io.cc @ 21633:dcf8922b724b

Deprecate printf, puts, and scanf. Make fputs a M-file. * libinterp/corefcn/file-io.cc: extracted printf, puts, and scanf to M-files. * scripts/deprecated/printf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/puts.m: new function, equivalent to version file-io.cc. * scripts/deprecated/scanf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/module.mk: added printf, puts, and scanf. * scripts/io/fputs.m: new function, equivalent to version file-io.cc. * scripts/io/module.mk: added fputs. * doc/interpreter/io.txi: adapted documentation to current implementation. * NEWS: announced changes. * doc/interpreter/basics.txi: replaced printf by fprintf. * doc/interpreter/stmt.txi: replaced printf by fprintf. * doc/interpreter/var.txi: replaced printf by fprintf. * doc/refcard/refcard.tex: removed printf and scanf. * examples/code/@FIRfilter/display.m: replaced printf by fprintf. * examples/code/@polynomial/display.m: replaced printf by fprintf. * scripts/@ftp/display.m: replaced printf by fprintf. * scripts/general/inputParser.m: replaced printf by fprintf. * scripts/general/methods.m: replaced printf by fprintf. * scripts/general/profexplore.m: replaced printf by fprintf. * scripts/general/profshow.m: replaced printf by fprintf. * scripts/help/help.m: replaced puts by fputs and printf by fprintf. * scripts/help/lookfor.m: replaced puts by fputs and printf by fprintf. * scripts/help/which.m: replaced printf by fprintf. * scripts/image/imformats.m: replaced printf by fprintf. * scripts/io/beep.m: replaced puts by fputs. * scripts/io/textread.m: replaced printf by fprintf. * scripts/java/javaclasspath.m: replaced printf by fprintf. * scripts/java/javamem.m: replaced printf by fprintf. * scripts/miscellaneous/dir.m: replaced printf by fprintf. * scripts/miscellaneous/dos.m: replaced printf by fprintf. * scripts/miscellaneous/fact.m: replaced printf by fprintf. * scripts/miscellaneous/info.m: replaced printf by fprintf. * scripts/miscellaneous/license.m: replaced printf by fprintf. * scripts/miscellaneous/ls.m: replaced puts by fputs. * scripts/miscellaneous/menu.m: replaced printf by fprintf. * scripts/miscellaneous/mkoctfile.m: replaced printf by fprintf. * scripts/miscellaneous/private/display_info_file.m: * scripts/miscellaneous/unix.m: replaced printf by fprintf. * scripts/miscellaneous/ver.m: replaced printf by fprintf. * scripts/miscellaneous/what.m: replaced printf by fprintf. * scripts/ode/ode23.m: replaced printf by fprintf. * scripts/ode/ode45.m: replaced printf by fprintf. * scripts/optimization/fminbnd.m: replaced printf by fprintf. * scripts/optimization/optimset.m: replaced puts by fputs and printf by fprintf. * scripts/optimization/sqp.m: replaced printf by fprintf. * scripts/pkg/pkg.m: replaced printf by fprintf. * scripts/pkg/private/describe.m: replaced printf by fprintf. * scripts/pkg/private/install.m: replaced printf by fprintf. * scripts/pkg/private/installed_packages.m: replaced printf by fprintf. * scripts/pkg/private/list_forge_packages.m: replaced puts by fputs and printf by fprintf. * scripts/pkg/private/rebuild.m: replaced printf by fprintf. * scripts/plot/util/__gnuplot_drawnow__.m: replaced puts by fputs and printf by fprintf. * scripts/signal/stft.m: replaced printf by fprintf. * scripts/sparse/bicg.m: replaced printf by fprintf. * scripts/sparse/bicgstab.m: replaced printf by fprintf. * scripts/sparse/cgs.m: replaced printf by fprintf. * scripts/sparse/pcg.m: replaced printf by fprintf. * scripts/sparse/pcr.m: replaced printf by fprintf. * scripts/sparse/qmr.m: replaced printf by fprintf. * scripts/statistics/models/logistic_regression.m: replaced printf by fprintf. * scripts/statistics/tests/anova.m: replaced printf by fprintf. * scripts/statistics/tests/bartlett_test.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_homogeneity.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_independence.m: replaced printf by fprintf. * scripts/statistics/tests/cor_test.m: replaced printf by fprintf. * scripts/statistics/tests/f_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kruskal_wallis_test.m: replaced printf by fprintf. * scripts/statistics/tests/manova.m: replaced printf by fprintf. * scripts/statistics/tests/mcnemar_test.m: replaced printf by fprintf. * scripts/statistics/tests/prop_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/run_test.m: replaced printf by fprintf. * scripts/statistics/tests/sign_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/u_test.m: replaced printf by fprintf. * scripts/statistics/tests/var_test.m: replaced printf by fprintf. * scripts/statistics/tests/welch_test.m: replaced printf by fprintf. * scripts/statistics/tests/wilcoxon_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test_2.m: replaced printf by fprintf. * scripts/strings/strtok.m: replaced printf by fprintf. * scripts/testfun/__run_test_suite__.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/demo.m: replaced printf by fprintf. * scripts/testfun/example.m: replaced printf by fprintf. * scripts/testfun/private/compare_plot_demos.m: replaced printf by fprintf. * scripts/testfun/rundemos.m: replaced printf by fprintf. * scripts/testfun/runtests.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/speed.m: replaced printf by fprintf. * scripts/testfun/test.m: replaced printf by fprintf. * scripts/time/calendar.m: replaced puts by fputs and printf by fprintf. * test/io.tst: replaced printf by fprintf.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Wed, 20 Apr 2016 17:53:10 +0200
parents 3cadca91e390
children 96518f623c91
comparison
equal deleted inserted replaced
21632:e3c44a120a8c 21633:dcf8922b724b
778 The optional output returns the number of bytes written to the file.\n\ 778 The optional output returns the number of bytes written to the file.\n\
779 \n\ 779 \n\
780 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ 780 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
781 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ 781 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
782 expanded even when the template string is defined with single quotes.\n\ 782 expanded even when the template string is defined with single quotes.\n\
783 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen}\n\ 783 @seealso{fputs, fdisp, fwrite, fscanf, sprintf, fopen}\n\
784 @end deftypefn") 784 @end deftypefn")
785 { 785 {
786 static std::string who = "fprintf"; 786 static std::string who = "fprintf";
787 787
788 int nargin = args.length (); 788 int nargin = args.length ();
820 820
821 if (nargout > 0) 821 if (nargout > 0)
822 return ovl (result); 822 return ovl (result);
823 else 823 else
824 return ovl (); 824 return ovl ();
825 }
826
827 DEFUN (printf, args, nargout,
828 "-*- texinfo -*-\n\
829 @deftypefn {} {} printf (@var{template}, @dots{})\n\
830 Print optional arguments under the control of the template string\n\
831 @var{template} to the stream @code{stdout} and return the number of\n\
832 characters printed.\n\
833 @ifclear OCTAVE_MANUAL\n\
834 \n\
835 See the Formatted Output section of the GNU Octave manual for a\n\
836 complete description of the syntax of the template string.\n\
837 @end ifclear\n\
838 \n\
839 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
840 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
841 expanded even when the template string is defined with single quotes.\n\
842 @seealso{fprintf, sprintf, scanf}\n\
843 @end deftypefn")
844 {
845 static std::string who = "printf";
846
847 int nargin = args.length ();
848
849 if (nargin == 0)
850 print_usage ();
851
852 int result;
853
854 if (! args(0).is_string ())
855 error ("%s: format TEMPLATE must be a string", who.c_str ());
856
857 octave_value_list tmp_args;
858
859 if (nargin > 1)
860 {
861 tmp_args.resize (nargin-1, octave_value ());
862
863 for (int i = 1; i < nargin; i++)
864 tmp_args(i-1) = args(i);
865 }
866
867 result = stdout_stream.printf (args(0), tmp_args, who);
868
869 if (nargout > 0)
870 return ovl (result);
871 else
872 return ovl ();
873 }
874
875 DEFUN (fputs, args, ,
876 "-*- texinfo -*-\n\
877 @deftypefn {} {} fputs (@var{fid}, @var{string})\n\
878 @deftypefnx {} {@var{status} =} fputs (@var{fid}, @var{string})\n\
879 Write the string @var{string} to the file with file descriptor @var{fid}.\n\
880 \n\
881 The string is written to the file with no additional formatting. Use\n\
882 @code{fdisp} instead to automatically append a newline character appropriate\n\
883 for the local machine.\n\
884 \n\
885 Return a non-negative number on success or EOF on error.\n\
886 @seealso{fdisp, fprintf, fwrite, fopen}\n\
887 @end deftypefn")
888 {
889 static std::string who = "fputs";
890
891 if (args.length () != 2)
892 print_usage ();
893
894 octave_stream os = octave_stream_list::lookup (args(0), who);
895
896 return ovl (os.puts (args(1), who));
897 }
898
899 DEFUN (puts, args, ,
900 "-*- texinfo -*-\n\
901 @deftypefn {} {} puts (@var{string})\n\
902 @deftypefnx {} {@var{status} =} puts (@var{string})\n\
903 Write a string to the standard output with no formatting.\n\
904 \n\
905 The string is written verbatim to the standard output. Use @code{disp} to\n\
906 automatically append a newline character appropriate for the local machine.\n\
907 \n\
908 Return a non-negative number on success and EOF on error.\n\
909 @seealso{fputs, disp}\n\
910 @end deftypefn")
911 {
912 static std::string who = "puts";
913
914 if (args.length () != 1)
915 print_usage ();
916
917 return ovl (stdout_stream.puts (args(0), who));
918 } 825 }
919 826
920 DEFUN (sprintf, args, , 827 DEFUN (sprintf, args, ,
921 "-*- texinfo -*-\n\ 828 "-*- texinfo -*-\n\
922 @deftypefn {} {} sprintf (@var{template}, @dots{})\n\ 829 @deftypefn {} {} sprintf (@var{template}, @dots{})\n\
928 string, automatically sized to hold all of the items converted.\n\ 835 string, automatically sized to hold all of the items converted.\n\
929 \n\ 836 \n\
930 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ 837 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
931 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ 838 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
932 expanded even when the template string is defined with single quotes.\n\ 839 expanded even when the template string is defined with single quotes.\n\
933 @seealso{printf, fprintf, sscanf}\n\ 840 @seealso{fprintf, sscanf}\n\
934 @end deftypefn") 841 @end deftypefn")
935 { 842 {
936 static std::string who = "sprintf"; 843 static std::string who = "sprintf";
937 844
938 int nargin = args.length (); 845 int nargin = args.length ();
1025 @ifclear OCTAVE_MANUAL\n\ 932 @ifclear OCTAVE_MANUAL\n\
1026 \n\ 933 \n\
1027 See the Formatted Input section of the GNU Octave manual for a\n\ 934 See the Formatted Input section of the GNU Octave manual for a\n\
1028 complete description of the syntax of the template string.\n\ 935 complete description of the syntax of the template string.\n\
1029 @end ifclear\n\ 936 @end ifclear\n\
1030 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen}\n\ 937 @seealso{fgets, fgetl, fread, sscanf, fopen}\n\
1031 @end deftypefn") 938 @end deftypefn")
1032 { 939 {
1033 static std::string who = "fscanf"; 940 static std::string who = "fscanf";
1034 941
1035 int nargin = args.length (); 942 int nargin = args.length ();
1088 string @var{string} instead of from a stream.\n\ 995 string @var{string} instead of from a stream.\n\
1089 \n\ 996 \n\
1090 Reaching the end of the string is treated as an end-of-file condition. In\n\ 997 Reaching the end of the string is treated as an end-of-file condition. In\n\
1091 addition to the values returned by @code{fscanf}, the index of the next\n\ 998 addition to the values returned by @code{fscanf}, the index of the next\n\
1092 character to be read is returned in @var{pos}.\n\ 999 character to be read is returned in @var{pos}.\n\
1093 @seealso{fscanf, scanf, sprintf}\n\ 1000 @seealso{fscanf, sprintf}\n\
1094 @end deftypefn") 1001 @end deftypefn")
1095 { 1002 {
1096 static std::string who = "sscanf"; 1003 static std::string who = "sscanf";
1097 1004
1098 int nargin = args.length (); 1005 int nargin = args.length ();
1134 retval = ovl (tmp, count, errmsg, 1041 retval = ovl (tmp, count, errmsg,
1135 (os.eof () ? data.length () : os.tell ()) + 1); 1042 (os.eof () ? data.length () : os.tell ()) + 1);
1136 } 1043 }
1137 1044
1138 return retval; 1045 return retval;
1139 }
1140
1141 DEFUN (scanf, args, nargout,
1142 "-*- texinfo -*-\n\
1143 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\
1144 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\
1145 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\
1146 \n\
1147 It is currently not useful to call @code{scanf} in interactive programs.\n\
1148 @seealso{fscanf, sscanf, printf}\n\
1149 @end deftypefn")
1150 {
1151 int nargin = args.length ();
1152
1153 octave_value_list tmp_args (nargin+1, octave_value ());
1154
1155 tmp_args (0) = 0.0;
1156 for (int i = 0; i < nargin; i++)
1157 tmp_args(i+1) = args(i);
1158
1159 return Ffscanf (tmp_args, nargout);
1160 } 1046 }
1161 1047
1162 static octave_value_list 1048 static octave_value_list
1163 textscan_internal (const std::string& who, const octave_value_list& args) 1049 textscan_internal (const std::string& who, const octave_value_list& args)
1164 { 1050 {