File: convert-in-file

package info (click to toggle)
xemacs21 21.4.24-12
  • links: PTS
  • area: main
  • in suites: sid
  • size: 34,212 kB
  • sloc: ansic: 243,882; lisp: 94,071; cpp: 5,726; sh: 4,406; perl: 1,096; cs: 775; makefile: 765; python: 279; asm: 248; lex: 119; yacc: 95; sed: 22; csh: 9
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);
}