/usr/share/octave/packages/3.2/io-1.0.14/parse_sp_range.m is in octave-io 1.0.14-2.
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 | ## Copyright (C) 2009 Philip Nienhuis <pr.nienhuis at users.sf.net>
##
## 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 2 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/>.
## Parse a string representing a range of cells for a spreadsheet
## into nr of rows and nr of columns and also extract top left
## cell address + top row + left column. Some error checks are implemented.
## Author: Philip Nienhuis
## Created: 2009-06-20
## Latest update 2010-01-13
function [topleft, nrows, ncols, toprow, lcol] = parse_sp_range (range_org)
range = deblank (toupper (range_org));
range_error = 0; nrows = 0; ncols = 0;
# Basic checks
if (index (range, ':') == 0)
if (isempty (range))
range_error = 0;
leftcol = 'A';
rightcol = 'A';
else
# Only upperleft cell given, just complete range to 1x1
# (needed for some routines)
range = [range ":" range];
endif
endif
# Split up both sides of the range
[topleft, lowerright] = strtok (range, ':');
# Get toprow and clean up left column
[st, en] = regexp (topleft, '\d+');
toprow = str2num (topleft(st:en));
leftcol = deblank (topleft(1:st-1));
[st, en1] = regexp( leftcol,'\s+');
if (isempty (en1))
en1=0;
endif
[st, en2] = regexp (leftcol,'\D+');
leftcol = leftcol(en1+1:en2);
# Get bottom row and clean up right column
[st, en] = regexp (lowerright,'\d+');
bottomrow = str2num (lowerright(st:en));
rightcol = deblank (lowerright(2:st-1));
[st, en1] = regexp (rightcol,'\s+');
if (isempty (en1))
en1=0;
endif
[st, en2] = regexp (rightcol,'\D+');
rightcol = rightcol(en1+1:en2);
# Check nr. of rows
nrows = bottomrow - toprow + 1;
if (nrows < 1)
range_error = 1;
endif
if (range_error == 0)
# Get left column nr.
[st, en] = regexp (leftcol, '\D+');
lcol = (leftcol(st:st) - 'A' + 1);
while (++st <= en)
lcol = lcol * 26 + (leftcol(st:st) - 'A' + 1);
endwhile
# Get right column nr.
[st, en] = regexp (rightcol, '\D+');
rcol = (rightcol(st:st) - 'A' + 1);
while (++st <= en)
rcol = rcol * 26 + (rightcol(st:st) - 'A' + 1);
endwhile
# Check
ncols = rcol - lcol + 1;
if (ncols < 1)
range_error = 1;
endif
endif
if (range_error > 0)
ncols = 0; nrows = 0;
error ("Spreadsheet range error! ");
endif
endfunction
|