Support regex definition for virtual corpora

Change-Id: Iecf55d050f02b019c2591f100cd4d45cb90488a7
diff --git a/script/cosmasvc2koralquery b/script/cosmasvc2koralquery
index c0b3ed2..a95605f 100755
--- a/script/cosmasvc2koralquery
+++ b/script/cosmasvc2koralquery
@@ -2,7 +2,9 @@
 use strict;
 use warnings;
 use KorAP::Def;
+use KorAP::DefList;
 use lib 'lib';
+use Getopt::Long;
 
 # 2020-05-20
 #   Preliminary support for C2 def-files.
@@ -12,25 +14,47 @@
 #   Add KorAP::Def.
 
 our $VERSION = 0.2;
-
 our @ARGV;
 
-unless (@ARGV) {
-  print <<'HELP';
-Convert a line-separated list of corpus sigles, doc sigles or
-text sigles into a virtual corpus query.
+my $cmd = shift @ARGV;
 
-  $ perl list2vc.pl my_vc.txt | gzip -vc > my_vc.jsonld.gz
-  $ cat my_vc.txt | perl list2vc.pl - | gzip -vc > my_vc.jsonld.gz
+
+my $input;
+
+GetOptions (
+  "input|i=s" => \$input
+)
+or die("Error in command line arguments\n");
+
+if ($cmd ne 'def' && $cmd ne 'list') {
+  print <<'HELP';
+Convert a list of C2 VC definitions or a single definition into
+KoralQuery VCs.
+
+  $ perl cosmasvc2koralquery def my_vc.txt | gzip -vc > my_vc.jsonld.gz
+  $ cat my_vc.txt | perl cosmasvc2koralquery def - | gzip -vc > my_vc.jsonld.gz
+
+Commands: def, list
 
 HELP
-exit 0;
+exit 1;
 };
 
+
+# Process a list
+if ($cmd eq 'list') {
+  KorAP::DefList->new($input || $ARGV[0])->parse;
+  exit(0);
+};
+
+# Parse a single def
 my $def_parser;
 if ($ARGV[0] eq '-') {
   $def_parser = KorAP::Def->new(\*STDIN);
 }
+elsif ($input) {
+  $def_parser = KorAP::Def->new($input);
+}
 else {
   $def_parser = KorAP::Def->new($ARGV[0]);
 };