This file is indexed.

/usr/share/perl5/Language/INTERCAL/Arrays.pm is in clc-intercal 1:1.0~4pre1.-94.-2-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
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
package Language::INTERCAL::Arrays;

# Tails and hybrids; also shark fins

# This file is part of CLC-INTERCAL

# Copyright (c) 2006-2008 Claudio Calvelli, all rights reserved.

# CLC-INTERCAL is copyrighted software. However, permission to use, modify,
# and distribute it is granted provided that the conditions set out in the
# licence agreement are met. See files README and COPYING in the distribution.

use strict;
use vars qw($VERSION $PERVERSION);
($VERSION) = ($PERVERSION = "CLC-INTERCAL/Base INTERCAL/Arrays.pm 1.-94.-2") =~ /\s(\S+)$/;

use Carp;
use Language::INTERCAL::Exporter '1.-94.-2';
use Language::INTERCAL::Splats '1.-94.-2', qw(:SP);
use Language::INTERCAL::Numbers '1.-94.-2';
use Language::INTERCAL::DataItem '1.-94.-2';
use vars qw(@ISA);
@ISA = qw(Language::INTERCAL::DataItem);

sub new {
    @_ or croak
	"Usage: new Language::INTERCAL::Arrays [::TYPE | BITS], SUBSCRIPTS";
    my $class = shift;
    my $bits;
    if ($class->isa('Language::INTERCAL::Arrays::Tail')) {
	@_ == 1 or croak "Usage: new $class SUBSCRIPTS";
	$bits = 16;
    } elsif ($class->isa('Language::INTERCAL::Arrays::Hybrid')) {
	@_ == 1 or croak "Usage: new $class SUBSCRIPTS";
	$bits = 32;
    } else {
	@_ == 2 or croak "Usage: new $class BITS, SUBSCRIPTS";
	my $bits = shift;
	$bits > 32 and croak "Invalid number of BITS";
	$bits = $bits > 16 ? 32 : 16;
	$class .= $bits > 16 ? '::Hybrid' : '::Tail';
    }
    my @subscripts = _make_subscripts(undef, @_);
    bless {
	subscripts => \@subscripts,
	value => {},
	bits => $bits,
	overload => undef,
    }, $class;
}

sub copy {
    @_ == 1 or croak "Usage: ARRAY->copy";
    my ($arr) = @_;
    bless {
	map {
	    my $v = $arr->{$_};
	    if (ref $v) {
		$v = [@$v] if ref $v eq 'ARRAY';
		$v = {%$v} if ref $v eq 'HASH';
	    }
	    ($_, $v);
	} keys %$arr
    }, ref $arr;
}

sub _store {
    @_ == 3 or croak "Usage: ARRAY->store(SUBSCRIPTS, VALUE)";
    my ($arr, $subscripts, $value) = @_;
    my @subscripts = _make_subscripts($arr, $subscripts);
    my $bits = $arr->{bits};
    if (ref $value) {
	UNIVERSAL::isa($value, 'Language::INTERCAL::Numbers')
	    or faint(SP_INVARRAY, 'Not a number');
	$value = $bits > 16 ? $value->twospot : $value->spot;
    } else {
	defined $value && $value =~ /^\d+$/
	    or faint(SP_INVARRAY, 'Not a number');
	$value = new Language::INTERCAL::Numbers $bits, $value;
    }
    my $sv = join(' ', @subscripts);
    if (! exists $arr->{value}{$sv}) {
	$arr->{value}{$sv} =
	    new Language::INTERCAL::Numbers $arr->{bits}, $value;
    } else {
	$arr->{value}{$sv}->assign($value);
    }
    $arr;
}

sub _get {
    @_ == 2 or croak "Usage: ARRAY->get(SUBSCRIPTS)";
    my ($arr, $subscripts) = @_;
    my $place = join(' ', _make_subscripts($arr, $subscripts));
    return $arr->{value}{$place}->value if exists $arr->{value}{$place};
    new Language::INTERCAL::Numbers $arr->bits, 0;
}

sub elements {
    @_ == 1 or croak "Usage: ARRAY->elements";
    my ($arr) = @_;
    return 0 unless @{$arr->{subscripts}};
    my $elems = 1;
    $elems *= $_ for @{$arr->{subscripts}};
    $elems;
}

sub subscripts {
    @_ == 1 or croak "Usage: ARRAY->subscripts";
    my ($arr) = @_;
    return () unless @{$arr->{subscripts}};
    @{$arr->{subscripts}};
}

sub range {
    @_ == 3 or croak "Usage: ARRAY->range(START, LEN)";
    my ($arr, $start, $len) = @_;
    my $el = $arr->elements;
    $start > 0 && $start <= $el
	or faint(SP_SUBSCRIPT, 'range start outside array');
    $start--;
    $len >= 0 && $start + $len <= $el
	or faint(SP_SUBSCRIPT, 'range length outside array');
    my @a = _as_list($arr);
    return (ref $arr)->from_list([splice(@a, $start, $len)]);
}

sub as_string {
    @_ == 1 or croak "Usage: ARRAY->as_string";
    my ($arr) = @_;
    pack('C*', map { $_->number & 0xff } $arr->as_list);
}

sub sparse_list {
    @_ == 1 or croak "Usage: ARRAY->sparse_list";
    my ($arr) = @_;
    return () unless @{$arr->{subscripts}};
    _sparse_list($arr);
}

sub _sparse_list {
    my ($arr, @subs) = @_;
    if (@subs >= @{$arr->{subscripts}}) {
	my $s = join(' ', @subs);
	return [$arr->{value}{$s}, @subs] if exists $arr->{value}{$s};
	return ();
    }
    my $max = $arr->{subscripts}[scalar @subs];
    map { _sparse_list($arr, @subs, $_) } (1..$max);
}

sub as_list {
    @_ == 1 or croak "Usage: ARRAY->as_list";
    my ($arr) = @_;
    return () unless @{$arr->{subscripts}};
    _as_list($arr);
}

sub _as_list {
    my ($arr, @subs) = @_;
    if (@subs >= @{$arr->{subscripts}}) {
	my $s = join(' ', @subs);
	return $arr->{value}{$s} if exists $arr->{value}{$s};
	return new Language::INTERCAL::Numbers $arr->bits, 0;
    }
    my $max = $arr->{subscripts}[scalar @subs];
    map { _as_list($arr, @subs, $_) } (1..$max);
}

sub from_list {
    @_ or croak "Usage: from_list Language::INTERCAL::Arrays " .
		"[::TYPE | BITS], VALUES";
    my $class = shift;
    if ($class->isa('Language::INTERCAL::Arrays::Tail')) {
	@_ == 1 or croak "Usage: from_list $class LIST";
    } elsif ($class->isa('Language::INTERCAL::Arrays::Hybrid')) {
	@_ == 1 or croak "Usage: from_list $class LIST";
    } else {
	@_ == 2 or croak "Usage: from_list $class BITS, LIST";
	my $bits = shift;
	$bits > 32 and croak "Invalid number of BITS";
	$class .= $bits > 16 ? '::Hybrid' : '::Tail';
    }
    my ($values) = @_;
    my $arr = $class->new([@$values ? scalar @$values : ()]);
    for (my $i = 1; $i <= @$values; $i++) {
	$arr->store([$i], $values->[$i - 1]);
    }
    $arr;
}

sub _assign {
    @_ == 2 or croak "Usage: ARRAY->assign(VALUE)";
    my ($arr, $value) = @_;
    my @subscripts = _make_subscripts(undef, $value);
    $arr->{subscripts} = \@subscripts;
    $arr->{value} = {};
    $arr;
}

sub print {
    @_ == 1 or croak "Usage: ARRAY->print";
    my ($arr) = @_;
    my $s = $arr->{subscripts};
    return "[]" unless $s && @$s;
    _print($arr, [], @$s);
}

sub _print {
    my ($arr, $sp, @s) = @_;
    if (@s) {
	my $m = shift @s;
	my @v = map { _print($arr, [@$sp, $_], @s) } (1..$m);
	return '[' . join(', ', @v) . ']';
    } else {
	my $s = join(' ', @$sp);
	return $arr->{value}{$s}->print if exists $arr->{value}{$s};
	return '#0';
    }
}

sub replace {
    @_ == 2 or croak "Usage: ARRAY->replace(LIST)";
    my ($arr, $list) = @_;
    faint(SP_NODIM) unless @{$arr->{subscripts}};
    _replace($arr, $list);
    faint(SP_ARRAY, "Too many elements") if @$list;
    $arr;
}

sub _replace {
    my ($arr, $list, @subs) = @_;
    if (@subs >= @{$arr->{subscripts}}) {
	my $s = join(' ', @subs);
	my $num = @$list ? shift @$list : 0;
	if (exists $arr->{value}{$s}) {
	    $arr->{value}{$s}->assign($num);
	} else {
	    $arr->{value}{$s} =
		Language::INTERCAL::Numbers->new($arr->bits, $num);
	}
	return;
    }
    my $max = $arr->{subscripts}[scalar @subs];
    for (my $s = 1; $s <= $max; $s++) {
	_replace($arr, $list, @subs, $s);
    }
}

# some methods in case arrays are used as numbers or class

sub digits { faint(SP_ISARRAY); }
sub filehandle { faint(SP_NOTCLASS); }
sub number { faint(SP_ISARRAY); }
sub spot { faint(SP_ISARRAY) }
sub twospot { faint(SP_ISARRAY) }

package Language::INTERCAL::Arrays::Tail;

use Carp;
use Language::INTERCAL::Splats '1.-94.-2', qw(:SP);

use vars qw(@ISA);
@ISA = qw(Language::INTERCAL::Arrays);

sub tail {
    @_ == 1 or croak "Usage: ARRAY->tail";
    goto &Language::INTERCAL::Arrays::copy;
}

sub hybrid {
    @_ == 1 or croak "Usage: ARRAY->hybrid";
    my ($arr) = @_;
    my $h = new Language::INTERCAL::Arrays::Hybrid $arr->{subscripts};
    for my $k (keys %{$arr->{value}}) {
	my $v = $arr->{value}{$k};
	$h->{value} = $v->twospot;
    }
    $h;
}

package Language::INTERCAL::Arrays::Hybrid;

use Carp;
use Language::INTERCAL::Splats '1.-94.-2', qw(:SP);

use vars qw(@ISA);
@ISA = qw(Language::INTERCAL::Arrays);

sub tail {
    @_ == 1 or croak "Usage: ARRAY->tail";
    my ($arr) = @_;
    my $t = new Language::INTERCAL::Arrays::Tail $arr->{subscripts};
    for my $k (keys %{$arr->{value}}) {
	my $v = $arr->{value}{$k};
	$t->{value} = $v->spot;
    }
    $t;
}

sub hybrid {
    @_ == 1 or croak "Usage: ARRAY->hybrid";
    goto &Language::INTERCAL::Arrays::copy;
}

1;