Dylibs isdylib.m

From Octave
Jump to: navigation, search

An m-file function used in support of creating a MacOS X App bundle.

## Copyright (C) 2012 Ben Abbott
## 
## This program 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.
## 
## This program 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 {Function File} result = dylibs_isdylib (@var{filename})
## Determines if the filename qualifies as a dynamically loaded library.
## The @var{result} is @var{true} for dylib-files, oct-files, and mex-files.
## The result is @var{false} for all other files.
##
## This function isn't sophisticated. It only examines the file extension.
## @seealso {dylibs__find, dylibs_get_deps, dylibs_fix}
## @end deftypefn
 
## Author: Ben Abbott <bpabbott@mac.com>
## Created: 2012-06-29
 
function result = dylibs_isdylib (cstr)
  persistent flip=@(str)str(end:-1:1)
  if (ischar (cstr))
    cstr = {cstr};
  endif
  suffix = {".dylib", ".oct", ".mex"};
  result = false (size (cstr));
  for n = 1:numel(suffix)
    fun = @(str) strncmp (cellfun (flip, str, "UniformOutput", false),
                          flip (suffix{n}), numel (suffix{n}));
    result = result | fun  (cstr);
  endfor
endfunction