# HG changeset patch # User Carlo de Falco # Date 1343116714 -7200 # Node ID c0f9e57ca7322fbb35cbf3a8b432454bb6389d7d # Parent 74c7265c057afcc2975d40753fa114c539de5823 [mq]: base64 diff --git a/build-aux/bootstrap.conf b/build-aux/bootstrap.conf --- a/build-aux/bootstrap.conf +++ b/build-aux/bootstrap.conf @@ -18,6 +18,7 @@ # gnulib modules used by this package. gnulib_modules=" + base64 c-strcase copysign copysignf @@ -60,7 +61,6 @@ signal sigprocmask sleep - sleep stat stdint stdio diff --git a/src/DLD-FUNCTIONS/base64.cc b/src/DLD-FUNCTIONS/base64.cc new file mode 100644 --- /dev/null +++ b/src/DLD-FUNCTIONS/base64.cc @@ -0,0 +1,71 @@ +// base64_encode and base64_decode, encode/decode a double array to/from a base64 string +/* + +Copyright (C) 2012 Carlo de Falco + +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 +. + +*/ + +// Author: Carlo de Falco + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "defun-dld.h" +#include "error.h" + +#include + +DEFUN_DLD (base64_encode, args, nargout, + "-*- texinfo -*-\n\ address@hidden {Loadable Function} address@hidden =} base64_encode (@var{x})\n\ +Encode a double matrix or array @var{x} into the base64 format string @var{s}.\n\ address@hidden address@hidden deftypefn") +{ + octave_value_list retval; + + int nargin = args.length (); + if (nargin != 1) + print_usage (); + else + { + Array in = args(0).array_value (); + if (! error_state) + { + char* inc = (char*) in.fortran_vec (); + size_t inlen = in.numel () * sizeof (double) / sizeof (char); + + char* out; + + size_t outlen = base64_encode_alloc (inc, inlen, &out); + if (out == NULL && outlen == 0 && inlen != 0) + error ("base64_encode: Input array too large."); + if (out == NULL) + error ("base64_encode: Memory allocation error."); + + std::string s (out); + retval(0) = octave_value (s); + } + } + return retval; +} + diff --git a/src/DLD-FUNCTIONS/module-files b/src/DLD-FUNCTIONS/module-files --- a/src/DLD-FUNCTIONS/module-files +++ b/src/DLD-FUNCTIONS/module-files @@ -14,6 +14,7 @@ __voronoi__.cc|$(QHULL_CPPFLAGS)|$(QHULL_LDFLAGS)|$(QHULL_LIBS) amd.cc|$(SPARSE_XCPPFLAGS)|$(SPARSE_XLDFLAGS)|$(SPARSE_XLIBS) balance.cc +base64.cc besselj.cc betainc.cc bsxfun.cc