changeset 984:c416f2979087

Perl utility for parsing a *.ref file, adding data from specified loc files.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 15 Jun 2010 03:01:25 +0000
parents 9aacd5dab11b
children 720ae6af90c5
files old/mapref.pl
diffstat 1 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/old/mapref.pl	Tue Jun 15 03:01:25 2010 +0000
@@ -0,0 +1,85 @@
+#!/usr/bin/perl -w
+use strict;
+
+# Settings and defaults
+my $prog_name = "mapref";
+my $prog_version = "0.1";
+my $prog_file = $0;
+
+my $opt_verbosity = 1;
+my %opt_locfiles = ();
+
+###
+### Print out help if no arguments given
+###
+my $opt_reffile = shift or die(
+"$prog_name v$prog_version - Generate complete LOC file from references
+Developed by Matti Hamalainen (Ggr \@ bat), <ccr\@tnsp.org>
+(C) Copyright 2010 Tecnic Software productions (TNSP)
+
+Usage: $prog_file <reffile> [locfile #1 ...] [options]
+
+ -v                Be more verbose
+");
+
+while (my $opt = shift) {
+  if ($opt eq "-v") {
+    $opt_verbosity++;
+  } else {
+    die("Loc file '$opt' already given.\n") if defined($opt_locfiles{$opt});
+    $opt_locfiles{$opt} = 1;
+  }
+}
+
+die("No loc files given.\n") unless (scalar(keys %opt_locfiles) > 0);
+
+
+###
+### Read loc files
+### 
+my %locfiles = ();
+foreach my $filename (keys %opt_locfiles) {
+  open(INFILE, "<", $filename) or die("Could not open loc-file '$filename'.\n");
+  while (defined(my $line = <INFILE>)) {
+    chomp($line);
+    if ($line =~ /^(#|\s*$)/) {
+      # Ignore empty lines and comments
+    } elsif ($line =~ /^\s*(\d+)\s*;\s*(\d+)\s*;\s*(\d\S*)\s*;\s*([^;]+);(.*)/) {
+      my ($flags, $namestr, $rest) = ($3,$4,$5);
+      my @names = split(/\s*\|\s*/, $namestr);
+      my $key = lc($names[0]);
+      if (substr($key,0,1) eq "\@") { $key = substr($key, 1); }
+      if ($flags !~ /C/) {
+        $locfiles{$key}{"flags"} = $flags;
+        $locfiles{$key}{"name"} = $namestr;
+        $locfiles{$key}{"rest"} = $rest;
+      }
+    }
+  }
+}
+
+
+###
+### Process reference file
+###
+open(INFILE, "<", $opt_reffile) or die("Could not open loc-file '$opt_reffile'.\n");
+my $nline = 0;
+while (defined(my $line = <INFILE>)) {
+  $nline++;
+  chomp($line);
+  if ($line =~ /^(#|\s*$)/) {
+    print "$line\n";
+  } elsif ($line =~ /^\s*(\d+)\s*;\s*(\d+)\s*;\s*(\d\S*)\s*;([^;]+);(.*)/) {
+    my ($xc, $yc, $flags, $namestr, $rest) = ($1,$2,$3,$4,$5);
+    if (substr($namestr,0,1) eq "\@") {
+      my $key = lc(substr($namestr, 1));
+      if (defined($locfiles{$key})) {
+        print "$xc\t; $yc\t; $flags\t;".$locfiles{$key}{"name"}.";".$locfiles{$key}{"rest"}."\n";
+      } else {
+        print "# Location key '$key' on line #$nline not defined!\n";
+      }
+    } else {
+      print "$line\n";
+    }
+  }
+}