File: convert-in-file

package info (click to toggle)
xemacs21-packages 2009.02.17.dfsg.2-4
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 116,276 kB
  • ctags: 89,333
  • sloc: lisp: 1,232,060; ansic: 16,570; java: 13,514; xml: 6,477; sh: 4,617; makefile: 4,022; asm: 3,007; perl: 840; cpp: 500; ruby: 257; csh: 96; haskell: 93; awk: 49; python: 47
file content (48 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

BEGIN { unshift @INC, '.' }

my $vf = shift(@ARGV);

require "$vf";

my $input_file = shift(@ARGV);
my $clean = 0;

if($input_file eq "CLEAN") {
  $clean = 1;
  $input_file = shift(@ARGV);
}

if($#ARGV != -1) {
  print STDERR "Too many arguments for file $input_file (@ARGV ($#ARGV))... Exiting...\n";
  exit 1;
}

my $output_file = $input_file;

foreach (keys %{$reps}) {
  $output_file =~ s/\@$_\@/$$reps{$_}/gi;
}
$output_file =~ s/\.in$//;


if($clean) {
  print STDERR "Removing file $output_file\n";
  system("rm", "-f", $output_file);
}
else {
  print STDERR "Converting from $input_file to $output_file\n";
  open(IN, $input_file);
  open(OUT, "> $output_file");
  while(<IN>) {
    foreach $key (keys %{$reps}) {
      s/\@$key\@/$$reps{$key}/gi;
    }
    print OUT $_;
  }
  close(OUT);
  close(IN);
}