Mercurial > hg > octave-jordi
annotate src/DLD-FUNCTIONS/md5sum.cc @ 10250:2d47356a7a1a
use gnulib getcwd module
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 03:07:06 -0500 |
parents | 40dfc0c99116 |
children | 89f4d7e294cc |
rev | line source |
---|---|
6375 | 1 /* |
2 | |
9245 | 3 Copyright (C) 2007, 2009 David Bateman |
6375 | 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 | |
10039
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
25 #include <config.h> |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
26 #endif |
1e306aa51d6c
Include config.h before another header file.
Thomas Treichl
parents:
9245
diff
changeset
|
27 |
6375 | 28 #include <string> |
29 #include <vector> | |
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) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
59 have_str = args(1).bool_value(); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
60 |
6375 | 61 if (!error_state) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
62 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
63 if (have_str) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
64 retval = oct_md5 (str); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
65 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
66 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
67 file_stat fs (str); |
6383 | 68 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
69 if (! fs.exists ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
70 { |
10250 | 71 std::string tmp |
72 = octave_env::make_absolute (load_path::find_file (str)); | |
6383 | 73 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
74 if (! tmp.empty ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
75 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
76 warning_with_id ("Octave:md5sum-file-in-path", |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
77 "md5sum: file found in load path"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
78 str = tmp; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
79 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
80 } |
6383 | 81 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
82 retval = oct_md5_file (str); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
83 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10039
diff
changeset
|
84 } |
6375 | 85 } |
86 | |
87 return retval; | |
88 } |