This file is indexed.

/usr/share/octave/site/m/libsbml5/installSBML.m is in libsbml5-octave 5.12.0+dfsg-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
function installSBML(varargin)
% Installs the MATLAB language interface for libSBML.
%
% This script assumes that the libsbml matlab binding executables files already
% exist; either because the user has built them using buildSBML (only
% in the src release) or the binding is being installed from an installer.
%
% Currently prebuilt executables are only available in the windows installers
% of libSBML.
%
% For Linux or Mac users this means that you need to build libsbml and then
% run the buildSBML script.


% Filename    : installSBML.m
% Description : install matlab binding
% Author(s)   : SBML Team <sbml-team@caltech.edu>
% Organization: EMBL-EBI
% 
% This file is part of libSBML.  Please visit http://sbml.org for more
% information about SBML, and the latest version of libSBML.
%
% Copyright (C) 2013-2014 jointly by the following organizations:
%     1. California Institute of Technology, Pasadena, CA, USA
%     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
%     3. University of Heidelberg, Heidelberg, Germany
%
% Copyright (C) 2009-2013 jointly by the following organizations: 
%     1. California Institute of Technology, Pasadena, CA, USA
%     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
%  
% Copyright (C) 2006-2008 by the California Institute of Technology,
%     Pasadena, CA, USA 
%  
% Copyright (C) 2002-2005 jointly by the following organizations: 
%     1. California Institute of Technology, Pasadena, CA, USA
%     2. Japan Science and Technology Agency, Japan
% 
% This library is free software; you can redistribute it and/or modify it
% under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation.  A copy of the license agreement is provided
% in the file named "LICENSE.txt" included with this software distribution
% and also available online as http://sbml.org/software/libsbml/license.html
%

% =========================================================================
% Main loop.
% =========================================================================

% look at input arguments

  [verbose, directory] = checkInputArguments(varargin);
      
  myDisp({'Installing the libSBML interface.'},  verbose);

 [matlab_octave]  = check_system(verbose);
 
 [functioning, located] = checkForExecutables(matlab_octave, directory, verbose);
 
 if (functioning == 0)
   if (located == 0)
     % we didnt find executables where we first looked
     % try again with a different directory
     if (isWindows() == 0)
       if (strcmp(directory, '/usr/local/lib') == 0)
         directory = '/usr/local/lib';
         functioning = checkForExecutables(matlab_octave, directory, verbose);
       end;
     else
       if (strcmp(directory, pwd) == 0)
         directory = pwd;
         functioning = checkForExecutables(matlab_octave, directory, verbose);
       end;
     end;
   else
     % we found executables but they did not work
     error('%s%s%s\n%s%s', ...
       'Executables were located at ', directory, ' but failed to execute', ...
       'Please contact the libSBML team libsbml-team@caltech.edu ', ...
       'for further assistance');
   end;
 end;

 if (functioning == 1)
   myDisp({'Installation successful'}, verbose);
 end;
end
  
  
  
% =========================================================================
% Helper functions
% =========================================================================

% check any input arguments
%--------------------------------------------------------------------------
function [verbose, directory] = checkInputArguments(input)

  numArgs = length(input);
  
  if (numArgs > 2)
    reportInputArgumentError('Too many arguments to installSBML');
  end;
  
  if (numArgs == 0)
    verbose = 1;
    if (isWindows() == 1)
      directory = pwd;
    else
      directory = '/usr/local/lib';
    end;
  elseif (numArgs == 1)
    directory = input{1};
    verbose = 1;
  else
    directory = input{1};
    verbose = input{2};
  end;
 
  if (verbose ~= 0 && verbose ~= 1)
    reportInputArgumentError('Incorrect value for verbose flag');
  end;
  
  if (ischar(directory) ~= 1)
    reportInputArgumentError('Directory value should be a string');
  elseif(exist(directory, 'dir') ~= 7)
    reportInputArgumentError('Directory value should be a directory');
  end;

end
% display error message relating to input arguments
%---------------------------------------------------
function reportInputArgumentError(message)

    error('%s\n%s\n\t%s%s\n\t%s%s\n\t\t%s', message, ...
      'Arguments are optional but if present:', ...
      'the first should be a string representing the directory containing ', ...
      'the executables', 'the second should be a flag (0 or 1) indicating ', ...
      'whether messages should be displayed ', ...
      '0 - no messages; 1 - display messages');
end
      


% display error messages iff verbose = 1
%-----------------------------------------
function myDisp(message, verbose)

  outputStr = '';

  if (verbose == 1)
    for i=1:length(message)
      outputStr = sprintf('%s\n%s', outputStr, message{i});
    end;
  end;
 
  disp(outputStr);
end

%
%
% Is this windows
% Mac OS X 10.7 Lion returns true for a call to ispc()
% since we were using that to distinguish between windows and macs we need
% to catch this
% ------------------------------------------------------------------------
function y = isWindows()

  y = 1;
  
  if isunix()
    y = 0;
    return;
  end;
  
  if ismac()
    y = 0;
    return;
  end;
  
  if ~ispc()
    error('\n%s\n%s\n', ...
      'Unable to determine the type of operating system in use.', ...
      'Please contact libsbml-team@caltech.edu to help resolve this problem.');
  end;
end   

% 
% Assess our computing environment.
% -------------------------------------------------------------------------
function [matlab_octave] = check_system(verbose)
 message{1} = '* Doing preliminary checks of runtime environment ...';

  if (strcmp(isoctave(), '0'))
    matlab_octave = 'MATLAB';
    message{2} = '  - This appears to be MATLAB and not Octave.';
  else
    matlab_octave = 'Octave';
    message{2} = '  - This appears to be Octave and not MATLAB.';
  end;
  
  myDisp(message, verbose);
end

%
% check for executables and that they are right ones
% -------------------------------------------------------------------------
function [success, located] = checkForExecutables(matlab_octave, directory, verbose)  
  message{1} = 'Checking for executables in ';
  message{2} = sprintf('\t%s', directory);
  
  transFile = strcat('TranslateSBML.', mexext());
  outFile = strcat('OutputSBML.', mexext());
  
  thisDirTFile = fullfile(pwd(), transFile);
  thisDirOFile = fullfile(pwd(), outFile);

  success = 0;
  located = 0;
  
  if strcmpi(matlab_octave, 'matlab')
    if (~(exist([directory, filesep, transFile], 'file') ~= 0 ...
        && exist([directory, filesep, outFile], 'file') ~= 0))
      located = 0;
    else 
      located = 1;
    end;
  else
    % octave is much more picky about whether the files exist
  	% it wants to find the libraries at the same time
  	% exist throws an exception if it cannot find them
    if (~(myExist(directory, transFile) ~= 0 ...
        && myExist(directory, outFile) ~= 0))
      located = 0;
    else 
      located = 1;
    end;
  end;

  if (located == 1)
    % we have found the executables where the user says but 
    % need to check that there are not other files on the path
    t = which(transFile);
    o = which(outFile);
      
    % exclude the current dir
    currentT = strcmp(t, thisDirTFile);
    currentO = strcmp(t, thisDirOFile);
    found = 0;
    if (currentT == 1 && currentO == 1)
      t_found = 0;
      if (isempty(t) == 0 && strcmp(t, [directory, filesep, transFile]) == 0)
        found = 1;
        t_found = 1;
      elseif (isempty(o) == 0 && strcmp(o, [directory, filesep, outFile]) == 0)
        found = 1;
      end;
    end;
    if (found == 1)  
      if (t_found == 1)
        pathDir = t;
      else
        pathDir = o;
      end;
      error('%s\n%s\n%s', 'Other libsbml executables found on the path at:', ... 
        pathDir, ...
      'Please uninstall these before attempting to install again');
    end;
  end;


  if (located == 1)
    message{3} = 'Executables found';
  else
    message{3} = 'Executables not found';
  end;

  
  myDisp(message, verbose);
  
  if (located == 1)
    % we have found the executables
    % add the directory to the matlab path
    added = addDir(directory, verbose);
    
    % if addDir returns 0 this may be that the user does not have
    % permission to add to the path
    if (added == 0)
      error('%s%s%s%s\n%s%s', ...
        'The directory containing the executables could not ', ...
        'be added to the ', matlab_octave, ' path', ... 
        'You may need to run in administrator mode or contact your ', ...
        'network manager if running from a network');
    elseif (added == 1)
      % to test the actual files we need to be in the directory
      % if we happen to be in the src tree where the .m helps files
      % exist these will get picked up first by the function calls
      % according to mathworks the only way to avoid this is to cd to the 
      % right dir 
      currentDir = pwd();
      cd(directory);
      success = doesItRun(matlab_octave, verbose, currentDir);
      cd (currentDir);
    end;
    
    % at this point if success = 0 it means there was an error running
    % the files - take the directory out of the path
    if (success == 0 && added == 1)
      removeDir(directory, verbose);
    end;
  end;
end

% test the installation
% -------------------------------------------------------------------------
function success = doesItRun(matlab_octave, verbose, dirForTest)
    
  success = 1;
  
  message{1} = 'Attempting to execute functions';
  myDisp(message, verbose);
    
  testFile = fullfile(dirForTest, 'test.xml');
  
  if strcmpi(matlab_octave, 'matlab')
    try
      M = TranslateSBML(testFile);
      message{1} = 'TranslateSBML successful';
    catch ME
      success = 0;
      message{1} = sprintf('%s\n%s', 'TranslateSBML failed', ME.message);
    end;
  else
    try
      M = TranslateSBML(testFile);
      message{1} = 'TranslateSBML successful';
    catch
      success = 0;
      message{1} = 'TranslateSBML failed';
    end;
  end;

  if strcmpi(matlab_octave, 'matlab')
    outFile = [tempdir, filesep, 'test-out.xml'];
  else
    if isWindows()
      outFile = [tempdir, 'temp', filesep, 'test-out.xml'];
    else
      outFile = [tempdir, 'test-out.xml'];
    end;
  end;
      
  if (success == 1)
    if strcmpi(matlab_octave, 'matlab')
      try
        if (verbose == 1)
          OutputSBML(M, outFile);
        else
          OutputSBML(M, outFile, verbose, verbose);
        end;
        message{2} = 'OutputSBML successful';
      catch ME
        success = 0;
        message{2} = sprintf('%s\n%s', 'OutputSBML failed', ME.message);
      end;
    else
      try
        if (verbose == 1)
          OutputSBML(M, outFile);
        else
          OutputSBML(M, outFile, verbose, verbose);
        end;
        message{2} = 'OutputSBML successful';
      catch
        success = 0;
        message{2} = 'OutputSBML failed';
      end;
    end;
  end;
  
  myDisp(message, verbose);
end
 
% add directory to the matlab path
% -------------------------------------------------------------------------
function added = addDir(name, verbose)

  added = 0;
  addpath(name);
  if (savepath ~= 0)
    message{1} = sprintf('Adding %s to path ...\nFailed', name);
  else
    message{1} = sprintf('Adding %s to path ...\nSuccess', name);
    added = 1;
  end;
  
  myDisp(message, verbose);
end
  
% remove directory to the matlab path
% -------------------------------------------------------------------------
function added = removeDir(name, verbose)

  added = 0;
  rmpath(name);
  if (savepath ~= 0)
    message{1} = sprintf('Removing %s from path ...\nFailed', name);
  else
    message{1} = sprintf('Removing %s from path ...\nSuccess', name);
    added = 1;
  end;
  
  myDisp(message, verbose);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function found = myExist(directory, filename)


found = 0;
dirnames = dir(directory);
i = 1;
while (found == 0 && i <= length(dirnames))
  if (dirnames(i).isdir == 0)
	  found = strcmp(dirnames(i).name, filename);
	end;
	i = i+1;
end;
  
end