This file is indexed.

/usr/share/perl5/Language/INTERCAL/Rcfile.pm is in clc-intercal 1:1.0~4pre1.-94.-2-4.

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
package Language::INTERCAL::Rcfile;

# Configuration files for sick and intercalc

# 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/Rcfile.pm 1.-94.-2") =~ /\s(\S+)$/;

use Carp;
use File::Spec::Functions;
use Language::INTERCAL::Exporter '1.-94.-2';
use Language::INTERCAL::GenericIO '1.-94.-2';

my %rcdefs = (
    'WRITE' => [ \&_rc_array, [], 'Character sets used for guessing' ],
    'UNDERSTAND' => [ \&_rc_understand, [], 'Suffix to parser mapping' ],
    'UNDERSTAND ANYWHERE' => [ \&_rc_anywhere, [], undef ],
    'SPEAK' => [ \&_rc_array, [], 'Default user interfaces' ],
    'PRODUCE' => [ \&_rc_scalar, '', 'Default compiler back end' ],
);

my %programs = (
    INTERNET      => 'INTERNET defaults',
    INTERCALC     => "Calculator's defaults",
);

sub new {
    @_ == 1 or croak "Usage: new Language::INTERCAL::Rcfile";
    my ($class) = @_;
    my %data = ();
    for my $k (keys %rcdefs) {
	$data{$k} = ref $rcdefs{$k}[1] ? [] : '';
    }
    my @include =
	grep { -d $_ }
	     map { catdir($_, qw(Language INTERCAL Include)) }
		 @INC;
    # TODO - make the following portable (is there such a thing?)
    my @home = ();
    if ($ENV{HOME}) {
	@home = (homedir => $ENV{HOME});
    } else {
	my $name = getlogin;
	if (! $name || ! getpwnam($name)) {
	    $name = getpwuid($<);
	}
	if ($name && getpwnam($name)) {
	    @home = (homedir => (getpwnam($name))[7]);
	}
    }
    bless {
	options => {
	    rcfile => [],
	    include => \@include,
	    nouserrc => 0,
	},
	userinc => 0,
	rccmd => [],
	data => \%data,
	prog => {},
	@home,
    }, $class;
}

sub setoption {
    @_ == 3 or croak "Usage: RCFILE->setoption(NAME, VALUE)";
    my ($rc, $name, $value) = @_;
    exists $rc->{options}{$name}
	or die "Unknown option $name\n";
    if (ref $rc->{options}{$name}) {
	if ($name eq 'include') {
	    my $userinc = $rc->{userinc}++;
	    splice(@{$rc->{options}{$name}}, $userinc, 0, $value);
	} else {
	    push @{$rc->{options}{$name}}, $value;
	}
    } else {
	$rc->{options}{$name} = $value;
    }
    $rc;
}

sub getoption {
    @_ == 2 or croak "Usage: RCFILE->getoption(NAME)";
    my ($rc, $name) = @_;
    exists $rc->{options}{$name}
	or die "Unknown option $name\n";
    $rc->{options}{$name};
}

sub getitem {
    @_ == 2 or croak "Usage: RCFILE->getitem(NAME)";
    my ($rc, $name) = @_;
    exists $rc->{data}{$name}
	or die "Unknown item $name\n";
    ref $rc->{data}{$name} or return $rc->{data}{$name};
    @{$rc->{data}{$name}};
}

sub putitem {
    @_ == 3 or croak "Usage: RCFILE->putitem(NAME, VALUE)";
    my ($rc, $name, $value) = @_;
    exists $rc->{data}{$name}
	or die "Unknown item $name\n";
    if (ref $rc->{data}{$name}) {
	ref $value && UNIVERSAL::isa($value, 'ARRAY')
	    or die "Value for $name should be an array\n";
    } else {
	ref $value
	    and die "Value for $name should be a scalar\n";
    }
    $rc->{data}{$name} = $value;
    $rc;
}

sub program_options {
    @_ == 2 or croak "Usage: RCFILE->program_options(PROGRAM)";
    my ($rc, $program) = @_;
    $program = uc($program);
    exists $rc->{prog}{$program} or return ();
    %{$rc->{prog}{$program}};
}

sub program_setoptions {
    @_ == 3 or croak "Usage: RCFILE->program_setoptions(PROGRAM, OPTIONS)";
    my ($rc, $program, $options) = @_;
    ref $options && UNIVERSAL::isa($options, 'HASH')
	or die "Options should be a HASH reference\n";
    $program = uc($program);
    $rc->{prog}{$program} = $options;
    $rc;
}

sub _rc_array {
    my ($rc, $mode, $ln, $file) = @_;
    die "Missing value for $mode\n" if $ln eq '';
    push @{$rc->{data}{$mode}}, $ln;
}

sub _rc_scalar {
    my ($rc, $mode, $ln, $file) = @_;
    die "Missing value for $mode\n" if $ln eq '';
    $rc->{data}{$mode} = $ln;
}

sub _rc_understand {
    my ($rc, $mode, $ln, $file) = @_;
    my $suffix;
    if ($ln =~ s/^(['"])(.*?)\1\s*//) {
	$suffix = $2;
    } elsif ($ln =~ s/^(\S+)\s*//) {
	$suffix = $1;
    } else {
	die "$file\: Invalid $mode\: missing SUFFIX\n";
    }
    if ($ln =~ s/^ANYWHERE\s*//i) {
	$mode .= ' ANYWHERE';
	$ln = $suffix . ' ' . $ln;
	return &{$rcdefs{$mode}[0]}($rc, $mode, $ln, $file);
    }
    $ln =~ s/^AS\s*//i or die "$file\: Invalid $mode\: missing AS\n";
    my $name;
    if ($ln =~ s/^(['"])(.*?)\1\s*//) {
	$name = $2;
    } elsif ($ln =~ s/^(\w+)\s*//) {
	$name = $1;
    } else {
	die "$file\: Invalid $mode\: missing NAME\n";
    }
    my %map = ( '' => [] );
    while ($ln ne '') {
	if ($ln =~ s/^WITH\s*//i) {
	    while (1) {
		my $maybe = '';
		$maybe = $1 if $ln =~ s/^(\?)//;
		my $preload;
		if ($ln =~ s/^(['"])(.*?)\1\s*//) {
		    $preload = $2;
		} elsif ($ln =~ s/^(\w+)\s*//) {
		    $preload = $1;
		} else {
		    die "$file\: Invalid $mode\: missing PRELOAD\n";
		}
		push @{$map{''}}, $maybe . $preload;
		$ln =~ s/^\+\s*// or last;
	    }
	    next;
	}
	if ($ln =~ s/^DISCARDING\s*//) {
	    my $option;
	    if ($ln =~ s/^(['"])(.*?)\1\s*//) {
		$option = $2;
	    } elsif ($ln =~ s/^(\S+)\s*//) {
		$option = $1;
	    } else {
		die "$file\: Invalid $mode\: missing DISCARDING\n";
	    }
	    $map{$option} = [[], ''];
	    next;
	}
	die "$file\: Invalid $mode\: $ln\n";
    }
    if ($suffix =~ s/^\.\.([^\.]+)\.//) {
	# special item used for program configuration - this avoids changing
	# the syntax of .sickrc again
	$rc->{prog}{uc $1}{$suffix} = [$name, \%map];
    } else {
	push @{$rc->{data}{$mode}}, [$suffix, $name, \%map];
    }
}

sub _rc_anywhere {
    my ($rc, $mode, $ln, $file) = @_;
    my $suffix;
    if ($ln =~ s/^(['"])(.*?)\1\s*//) {
	$suffix = $2;
    } elsif ($ln =~ s/^(\S+)\s*//) {
	$suffix = $1;
    } else {
	die "$file\: Invalid $mode\: missing SUFFIX\n";
    }
    $ln =~ s/^AS\s*//i or die "$file\: Invalid $mode\: missing AS\n";
    my $name;
    if ($ln =~ s/^(['"])(.*?)\1\s*//) {
	$name = $2;
    } elsif ($ln =~ s/^(\w+)\s*//) {
	$name = $1;
    } else {
	die "$file\: Invalid $mode\: missing NAME\n";
    }
    $ln =~ s/^WITH\s*//i or die "$file\: Invalid $mode\: missing WITH\n";
    my @preload = ();
    while (1) {
	my $maybe = '';
	$maybe = $1 if $ln =~ s/^(\?)//;
	my $preload;
	if ($ln =~ s/^(['"])(.*?)\1\s*//) {
	    $preload = $2;
	} elsif ($ln =~ s/^(\S+)\s*//) {
	    $preload = $1;
	} else {
	    die "$file\: Invalid $mode\: missing PRELOAD\n";
	}
	push @preload, $maybe . $preload;
	$ln =~ s/^\+\s*// or last;
    }
    die "$file\: Invalid $mode\: extra data at end ($ln)\n"
	if $ln ne '';
    push @{$rc->{data}{$mode}}, [$suffix, \@preload, $name];
}

sub load {
    @_ == 1 or croak "Usage: RCFILE->load";
    my ($rc) = @_;
    unless (@{$rc->{options}{rcfile}}) {
	my @home = exists $rc->{homedir} ? ($rc->{homedir}) : ();
	my $u = $rc->{options}{nouserrc};
	$rc->{options}{rcfile} = [
	    map {canonpath($_)}
		grep { -f $_ }
		     map { catfile($_, "system.sickrc"),
			   ($u ? () : catfile($_, ".sickrc")),
			 }
			 (@{$rc->{options}{include}}, @home, '.')
	];
	$rc->{options}{rcfile} = [$rc->{options}{rcfile}[0]]
	    if $u && @{$rc->{options}{rcfile}} > 1;
    }
    for my $rcfile (@{$rc->{options}{rcfile}}) {
	my $fh = Language::INTERCAL::GenericIO->new('FILE', 'w', $rcfile)
	    or die "$rcfile: $!\n";
	my $mode = undef;
	my $text = '';
	my $mln = '';
	my $no = 0;
	while ('' ne (my $ln = $fh->write_text())) {
	    chomp $ln;
	    $ln =~ s/^\s*//;
	    $no++;
	    next if $ln eq '';
	    my $rn = "$rcfile\:$no";
	    if ($ln =~ s/^(?:DO|PLEASE)\s*NOTE\s*//i) {
		&{$rcdefs{$mode}[0]}($rc, $mode, $text, $mln)
		    if defined $mode && $mode ne '';
		$mode = '';
	    } elsif ($ln =~ s/^I\s*DO\s*N[O']T\s*(\S+)//i) {
		&{$rcdefs{$mode}[0]}($rc, $mode, $text, $mln)
		    if defined $mode && $mode ne '';
		$mode = uc($1);
		die "No such action \"$1\": $rn\n"
		    unless exists $rcdefs{$mode};
		die "Invalid declaration \"$_\": $rn\n"
		    unless ref $rc->{data}{$mode};
		$rc->{data}{$mode} = [];
		$mode = undef;
	    } elsif ($ln =~ s/^I\s*CAN\s*(\S+)\s*//i) {
		&{$rcdefs{$mode}[0]}($rc, $mode, $text, $mln)
		    if defined $mode && $mode ne '';
		$mode = uc($1);
		exists $rcdefs{$mode}
		    or die "No such action \"$1\": $rn\n";
		$text = $ln;
		$mln = $rn;
	    } elsif (defined $mode) {
		$text .= ' ' . $ln;
	    } else {
		die "Syntax error: $rn\n";
	    }
	}
	&{$rcdefs{$mode}[0]}($rc, $mode, $text, $mln)
	    if defined $mode && $mode ne '';
    }
    $rc;
}

sub save {
    @_ == 1 || @_ == 2 or croak "Usage: RCFILE->save [(TO)]";
    my ($rc, $to) = @_;
    if (! defined $to) {
	$to = catfile($rc->{homedir}, ".sickrc"),
    }
    my $tmp = $to . '.tmp';
    open(RC, '>', $tmp) or die "$tmp: $!\n";
    print RC "PLEASE NOTE: This file was automatically generated while saving settings\n\n"
	or die "$tmp: $!\n";
    for my $data (sort keys %{$rc->{data}}) {
	print RC "PLEASE NOTE: $rcdefs{$data}[2]\n" or die "$tmp: $!\n"
	    if defined $rcdefs{$data}[2];
	if (ref $rc->{data}{$data}) {
	    print RC "I DON'T $data\n" or die "$tmp: $!\n"
		if defined $rcdefs{$data}[2];
	    for my $value (@{$rc->{data}{$data}}) {
		if ($data eq 'UNDERSTAND') {
		    my ($suffix, $name, $map) = @$value;
		    $value = "$suffix\n\tAS \"$name\"";
		    my @w = map {
			if (/\s/) {
			    if (/"/) {
				"'$_'";
			    } else {
				"\"$_\"";
			    }
			} else {
			    $_;
			}
		    } @{$map->{''}};
		    $value .= "\n\tWITH " . join(' + ', @w);
		    $value .= "\n\tDISCARDING " . join(' + ', sort grep { /./ } keys %$map)
			if keys %$map > 1;
		} elsif ($data eq 'UNDERSTAND ANYWHERE') {
		    my ($suffix, $preload, $name) = @$value;
		    $value = "$suffix\n\tAS \"$name\"";
		    if (@$preload) {
			my @p = map {
			    if (/\s/) {
				if (/"/) {
				    "'$_'";
				} else {
				    "\"$_\"";
				}
			    } else {
				$_;
			    }
			} @$preload;
			$value .= "\n\tWITH " . join(' ', @p);
		    }
		} elsif ($data =~ /\s/) {
		    if ($data =~ /"/) {
			$data = "'$data'";
		    } else {
			$data = "\"$data\"";
		    }
		}
		print RC "I CAN $data $value\n" or die "$tmp: $!\n";
	    }
	} else {
	    print RC "I CAN $data $rc->{data}{$data}\n" or die "$tmp: $!\n";
	}
	print RC "\n" or die "$tmp: $!\n";
    }
    for my $data (sort keys %{$rc->{prog}}) {
	my $def = $programs{uc $data} || "Defaults for \L$data";
	print RC "PLEASE NOTE: $def\n" or die "$tmp: $!\n";
	for my $key (sort keys %{$rc->{prog}{$data}}) {
	    my ($value, $map) = @{$rc->{prog}{$data}{$key}};
	    my $withr = $map->{''};
	    my $with = $withr && @$withr ? join(' ', ' WITH', map { "\"$_\"" } @$withr) : '';
	    print RC "I CAN UNDERSTAND \"$data.$key\" AS \"$value\"$with\n" or die "$tmp: $!\n";
	}
	print RC "\n" or die "$tmp: $!\n";
    }
    close RC or die "$tmp: $!\n";
    my $old = $to . '~';
    unlink($old);
    rename($to, $old);
    rename($tmp, $to) or die "rename($tmp, $to): $!\n";
    $rc;
}

sub run {
    @_ == 2 or croak "Usage: RCFILE->run(UI)";
    my ($rc, $ui) = @_;
    for my $cmdline (@{$rc->{rccmd}}) {
	$ui->do($cmdline);
    }
    $rc;
}

1;