changelog shortlog tags changeset files revisions annotate raw

src/DLD-FUNCTIONS/md5sum.cc

changeset 10289: 4b124317dc38
parent:40dfc0c99116
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (31 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1/*
2
3Copyright (C) 2007, 2009 David Bateman
4
5
6This file is part of Octave.
7
8Octave is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License as published by the
10Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
12
13Octave is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with Octave; see the file COPYING. If not, see
20<http://www.gnu.org/licenses/>.
21
22*/
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <string>
29#include <vector>
30
31#include "defun-dld.h"
32#include "file-stat.h"
33#include "file-ops.h"
34#include "gripes.h"
35#include "load-path.h"
36#include "oct-env.h"
37#include "oct-md5.h"
38
39DEFUN_DLD (md5sum, args, ,
40 "-*- texinfo -*-\n\
41@deftypefn {Loadable Function} {} md5sum (@var{file})\n\
42@deftypefnx {Loadable Function} {} md5sum (@var{str}, @var{opt})\n\
43Calculates the MD5 sum of the file @var{file}. If the second parameter\n\
44@var{opt} exists and is true, then calculate the MD5 sum of the\n\
45string @var{str}.\n\
46@end deftypefn")
47{
48 octave_value retval;
49 int nargin = args.length ();
50
51 if (nargin != 1 && nargin != 2)
52 print_usage();
53 else
54 {
55 bool have_str = false;
56 std::string str = args(0).string_value();
57
58 if (nargin == 2)
59 have_str = args(1).bool_value();
60
61 if (!error_state)
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
72 = octave_env::make_absolute (load_path::find_file (str));
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 }
85 }
86
87 return retval;
88}