Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include <string>
00029 #include <vector>
00030
00031 #include "defun-dld.h"
00032 #include "file-stat.h"
00033 #include "file-ops.h"
00034 #include "gripes.h"
00035 #include "load-path.h"
00036 #include "oct-env.h"
00037 #include "oct-md5.h"
00038
00039 DEFUN_DLD (md5sum, args, ,
00040 "-*- texinfo -*-\n\
00041 @deftypefn {Loadable Function} {} md5sum (@var{file})\n\
00042 @deftypefnx {Loadable Function} {} md5sum (@var{str}, @var{opt})\n\
00043 Calculate the MD5 sum of the file @var{file}. If the second parameter\n\
00044 @var{opt} exists and is true, then calculate the MD5 sum of the\n\
00045 string @var{str}.\n\
00046 @end deftypefn")
00047 {
00048 octave_value retval;
00049 int nargin = args.length ();
00050
00051 if (nargin != 1 && nargin != 2)
00052 print_usage();
00053 else
00054 {
00055 bool have_str = false;
00056 std::string str = args(0).string_value();
00057
00058 if (nargin == 2)
00059 have_str = args(1).bool_value();
00060
00061 if (!error_state)
00062 {
00063 if (have_str)
00064 retval = oct_md5 (str);
00065 else
00066 {
00067 file_stat fs (str);
00068
00069 if (! fs.exists ())
00070 {
00071 std::string tmp
00072 = octave_env::make_absolute (load_path::find_file (str));
00073
00074 if (! tmp.empty ())
00075 {
00076 warning_with_id ("Octave:md5sum-file-in-path",
00077 "md5sum: file found in load path");
00078 str = tmp;
00079 }
00080 }
00081
00082 retval = oct_md5_file (str);
00083 }
00084 }
00085 }
00086
00087 return retval;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101