#!/usr/bin/perl # # Usage: arc_tool [list |export |merge ] # use strict; use warnings; my $directive=$ARGV[0] or die("Usage: arc_tool [list|export] \n"); if ($directive eq 'list') { my @tools; open(AST, $ARGV[1]) or die("Error: cannot open file '$ARGV[1]'\n"); while() { my($line) = $_; chomp($line); if ($line =~ m/^console\.ui\.tools\[/) { my($toolname) = $line =~ m/console\.ui\.tools\[(.*)\]\./; push (@tools, $toolname); } } close AST; @tools = sort @tools; my %seen = (); my @uniq = (); foreach my $item (@tools) { push(@uniq, $item) unless $seen{$item}++; } foreach my $a (@uniq) { print "$a\n"; } } elsif ($directive eq 'export') { my $tool = $ARGV[1] or die("Usage: arc_tool export [tool name] [AST file]"); open(AST, $ARGV[2]) or die("Error: cannot open file '$ARGV[2]'\n"); if ("$tool" eq "all") { while() { my($line) = $_; chomp($line); if ($line =~ m/^console\.ui\.tools\[(.*)\]\./) { print "$line\n"; } if ($line =~ m/^console\.ui\.toolsList=(.*)/) { print "$line\n"; } } } else { my $count = 0; while() { my($line) = $_; chomp($line); if ($line =~ m/^console\.ui\.tools\[$tool\]\./) { print "$line\n"; $count++; } } if ($count == 0) { print "Error: no tool found: '$tool'\n"; } } close AST; } else { print "Error: unrecognized argument: '$directive'\n"; }