Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/md5sum.cc @ 9064:7c02ec148a3c
Check grammar on all .cc files
Same check as previously done on .m files
Attempt to enforce some conformity in documentation text for rules
such as two spaces after a period, commas around latin abbreviations, etc.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sat, 28 Mar 2009 13:57:22 -0700 |
parents | 93c65f2a5668 |
children | 16f53d29049f |
rev | line source |
---|---|
6375 | 1 /* |
2 | |
3 Copyright (C) 2007 David Bateman | |
4 | |
5 | |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
6375 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
6375 | 21 |
22 */ | |
23 | |
24 #include <string> | |
25 #include <vector> | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include "config.h" | |
29 #endif | |
30 | |
31 #include "defun-dld.h" | |
6383 | 32 #include "file-stat.h" |
33 #include "file-ops.h" | |
34 #include "gripes.h" | |
35 #include "load-path.h" | |
36 #include "oct-env.h" | |
6375 | 37 #include "oct-md5.h" |
38 | |
6383 | 39 DEFUN_DLD (md5sum, args, , |
6375 | 40 "-*- texinfo -*-\n\ |
6383 | 41 @deftypefn {Loadable Function} {} md5sum (@var{file})\n\ |
42 @deftypefnx {Loadable Function} {} md5sum (@var{str}, @var{opt})\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
7016
diff
changeset
|
43 Calculates the MD5 sum of the file @var{file}. If the second parameter\n\ |
6383 | 44 @var{opt} exists and is true, then calculate the MD5 sum of the\n\ |
45 string @var{str}.\n\ | |
6375 | 46 @end deftypefn") |
47 { | |
48 octave_value retval; | |
49 int nargin = args.length (); | |
50 | |
6383 | 51 if (nargin != 1 && nargin != 2) |
6375 | 52 print_usage(); |
53 else | |
54 { | |
6383 | 55 bool have_str = false; |
6375 | 56 std::string str = args(0).string_value(); |
57 | |
6383 | 58 if (nargin == 2) |
59 have_str = args(1).bool_value(); | |
60 | |
6375 | 61 if (!error_state) |
6383 | 62 { |
63 if (have_str) | |
64 retval = oct_md5 (str); | |
65 else | |
66 { | |
67 file_stat fs (str); | |
68 | |
69 if (! fs.exists ()) | |
70 { | |
71 std::string tmp = octave_env::make_absolute | |
72 (load_path::find_file (str), octave_env::getcwd ()); | |
73 | |
74 if (! tmp.empty ()) | |
75 { | |
76 warning_with_id ("Octave:md5sum-file-in-path", | |
77 "md5sum: file found in load path"); | |
78 str = tmp; | |
79 } | |
80 } | |
81 | |
82 retval = oct_md5_file (str); | |
83 } | |
84 } | |
6375 | 85 } |
86 | |
87 return retval; | |
88 } |