view scripts/deprecated/md5sum.m @ 21317:a4faec57f4c8

maint: remove semicolon after %!assert tests to follow Octave conventions. * testfun.txi: Remove semicolons from examples in manual and update remaider of text to reflect changes. * bsxfun.cc, cellfun.cc, data.cc, hash.cc, lu.cc, nproc.cc, rcond.cc, regexp.cc, sparse-xpow.cc, strfns.cc, symtab.cc, time.cc, variables.cc, ov-class.cc, ov-cx-diag.cc, ov-struct.cc, ov.cc, oct-parse.in.yy, pt-mat.cc, CMatrix.cc, oct-inttypes.cc, md5sum.m, blkdiag.m, cell2mat.m, interp1.m, interp2.m, interpft.m, num2str.m, repmat.m, ntsc2rgb.m, expm.m, inputname.m, polyvalm.m, blackman.m, hamming.m, hanning.m, eigs.m, median.m, binopdf.m, strsplit.m, strtok.m, assert.m, example.m, datevec.m, bug-38565.tst, build-sparse-tests.sh, classdef.tst, classes.tst, diag-perm.tst, index.tst, io.tst, logical-index.tst, nest.tst, parser.tst, prefer.tst, struct.tst: maint: remove semicolon after %!assert tests to follow Octave conventions.
author Rik <rik@octave.org>
date Sun, 21 Feb 2016 08:10:36 -0800
parents dba88797f69f
children 6fab85c1538f
line wrap: on
line source

## Copyright (C) 2007-2015 David Bateman
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn  {} {} md5sum (@var{file})
## @deftypefnx {} {} md5sum (@var{str}, @var{opt})
##
## @code{md5sum} is deprecated and will be removed in Octave version 4.6.
## For equivalent functionality replace calls like @code{md5sum (@var{file})}
## with:
##
## @example
## hash (\"md5\", fileread (@var{file}))
## @end example
##
## And calls like @code{md5sum (@var{str}, true)} with:
##
## @example
## hash (\"md5\", fileread (@var{str}))
## @end example
##
## Calculate the MD5 sum of the file @var{file}.
##
## If the second parameter @var{opt} exists and is true, then calculate the MD5
## sum of the string @var{str}.
##
## @seealso{hash, fileread}
## @end deftypefn

function r = md5sum (str, opt)

  persistent warned = false;
  if (! warned)
    warned = true;
    warning ("Octave:deprecated-function",
             "md5sum is obsolete and will be removed from a future version of Octave, please use hash instead");
  endif

  if (nargin == 1)
    r = hash ("md5", fileread (str));
  elseif ((nargin == 2) && isbool (opt) && isscalar (opt) && (opt == true))
    r = hash ("md5", str);
  else
    print_usage ();
  endif

endfunction

%!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a")

%!test
%! tfile = tempname ();
%! fid = fopen (tfile, "wb");
%! fwrite (fid, "abc\0");
%! fclose (fid);
%! assert (md5sum (tfile), "147a664a2ca9410911e61986d3f0d52a");
%! unlink (tfile);

%!error md5sum ();