Alt-CWB-ambs
view release on metacpan or search on metacpan
script/cwb-regedit view on Meta::CPAN
foreach my $i ("", 1 .. $recursion) {
foreach my $ext ("", map {"_$_"} @xmlatt) {
push @expanded, "$base$ext$i";
}
}
}
else {
push @expanded, $spec;
}
}
@atts = @expanded;
}
my @invalid = grep {not /^[a-z_][a-z0-9_-]*$/} @atts;
die "Error in :add :$type command: invalid attribute name(s) [@invalid]. Aborted.\n"
if @invalid;
print "Adding $type-attributes: @atts\n";
foreach my $a (@atts) {
my $exist = $reg->attribute($a);
if ($exist) {
die "Error: attribute '$a' already declared as $exist-attribute. Aborted.\n"
unless $exist eq $type;
print "[$type-attribute '$a' already declared]\n";
}
$reg->add_attribute($a, $type);
}
}
## list attributes of specified type
sub list_attributes {
my $type = shift;
my @atts = $reg->list_attributes($type);
print "@atts\n";
}
## check whether next token looks like a command (without removing it)
sub is_command {
return( @ARGV and $ARGV[0] =~ /^:/ );
}
## match next token as command (without removing it) and return normalised name ("" if not a command)
sub match_command {
my $cmd = (@_) ? shift : $ARGV[0];
my $norm = "";
for ($cmd) {
last unless defined $cmd;
$norm = ":info" if /^:info$/i;
$norm = ":id" if /^:id$/i;
$norm = ":home" if /^:h(ome)?$/i;
$norm = ":name" if /^:n(ame)?$/i;
$norm = ":ifile" if /^:ifile$/i;
$norm = ":prop" if /^:pr(op)?$/i;
$norm = ":add" if /^:add$/i;
$norm = lc($cmd) if /^:[psa]$/i;
$norm = ":del" if /^:d(el(ete)?)?$/i;
$norm = ":list" if /^:l(ist)?$/i;
}
return $norm;
}
## get a command block from the command line (command plus any number of non-command arguments)
## result is stored in global variables $COMMAND and @ARGS; returns FALSE at end of input
sub get_block {
$COMMAND = "";
@ARGS = ();
return 0
unless @ARGV > 0;
die "Syntax error: expected command, got '$ARGV[0]'\n"
unless is_command();
$COMMAND = match_command();
die "Syntax error: unknown command '$ARGV[0]'\n"
unless $COMMAND;
shift @ARGV;
# collect command arguments (if any)
while (@ARGV and not is_command()) {
push @ARGS, shift @ARGV;
}
return 1;
}
__END__
=head1 NAME
cwb-regedit - A simple command-line editor for CWB registry files
=head1 SYNOPSIS
cwb-regedit [options] (CORPUS | <filename>) <command> [<command> ...]
Options:
-r <dir>, --registry=<dir> use registry directory <dir> [system default]
-h, --help display usage summary
Commands:
:info
print basic information about the registry entry
(:id | :home | :name | :ifile) [<value>]
print or set corpus ID (:id), data directory (:home),
descriptive name (:name) or info file path (:ifile)
:prop <property> [<value>]
query or set corpus property
:list (:p | :s | :a)
list declared attributes of specified type
:add (:p | :s | :a) <names>
add positional, structural or alignment attributes
:del <names>
delete attributes of any type
Command names are case-insensitive, and some intuitive abbreviations and variations
are allowed (but only the forms listed above are guaranteed to work).
=head1 DESCRIPTION
B<cwb-regedit> is a simple command-line editor for CWB registry files in B<canonical format>.
It allows you to display and modify header information, corpus properties and attribute declarations.
For more complex editing tasks (such as adding descriptive comments), use the functionality
provided by the B<CWB> module (see L<CWB/"REGISTRY FILE EDITING"> manpage).
( run in 1.011 second using v1.01-cache-2.11-cpan-ceb78f64989 )