/usr/bin/stag-autoschema is in libdata-stag-perl 0.14-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #!/usr/bin/perl -w
# POD docs at bottom of file
use strict;
use Carp;
use Data::Stag qw(:all);
use Getopt::Long;
my $parser = "";
my $handler = "sxpr";
my $mapf;
my $tosql;
my $toxml;
my $toperl;
my $debug;
my $help;
my $name;
my $defs;
my $dtd;
GetOptions(
"help|h"=>\$help,
"parser|format|p=s" => \$parser,
"handler|writer|w=s" => \$handler,
"xml"=>\$toxml,
"perl"=>\$toperl,
"debug"=>\$debug,
"name|n=s"=>\$name,
"defs"=>\$defs,
"dtd"=>\$dtd,
);
if ($help) {
system("perldoc $0");
exit 0;
}
$dtd = 1 if $handler eq 'dtd';
#my @hdr = ();
#if ($name) {
# push(@hdr, (name=>$name));
#}
my @files = @ARGV;
my $tree = Data::Stag->new(null=>[]);
foreach my $fn (@files) {
my $curr_tree =
Data::Stag->parse($fn,
$parser);
$tree->name($curr_tree->name);
$tree->addkid($_) foreach $curr_tree->subnodes;
}
my $s = $tree->autoschema;
if ($defs) {
my @sdefs = ();
my %u = ();
$s->iterate(sub {
my $stag = shift;
my $n = $stag->name;
$n =~ s/[\+\?\*]$//;
return if $u{$n};
$u{$n}=1;
push(@sdefs, ($n=>''));
return;
});
$s = Data::Stag->unflatten(schemadefs=>[@sdefs]);
} else {
$s->iterate(sub {
my $stag = shift;
my $d = $stag->data;
if (!ref $d) {
$stag->data($d =~ /INT/ ? "i" : "s");
}
});
}
# my $top =
# Data::Stag->unflatten(schema=>[
# @hdr,
# ]);
# $top->set_nesting($s->data);
if ($dtd) {
print $s->dtd;
} else {
print $s->generate(-fmt=>$handler);
}
__END__
=head1 NAME
stag-autoschema - writes the implicit stag-schema for a stag file
=head1 SYNOPSIS
stag-autoschema -w sxpr sample-data.xml
stag-autoschema -dtd sample-data.xml
=head1 DESCRIPTION
Takes a stag compatible file (xml, sxpr, itext), or a file in any
format plus a parser, and writes out the implicit underlying stag-schema
stag-schema should look relatively self-explanatory.
Here is an example stag-schema, shown in sxpr syntax:
(db
(person*
(name "s"
(address+
(address_type "s")
(street "s")
(street2? "s")
(city "s")
(zip? "s")))))
The database db contains zero or more persons, each person has a
mandatory name and at least one address.
The cardinality mnemonics are as follows:
=over
=item +
1 or more
=item ?
0 or one
=item *Z<>
0 or more
=back
The default cardinality is 1
=head1 ARGUMENTS
=over
=item -p|parser FORMAT
FORMAT is one of xml, sxpr or itext, or the name of a perl module
xml assumed as default
=item -dtd
exports schema as DTD
=item -w|writer FORMAT
FORMAT is one of xml, sxpr or itext, or the name of a perl module, OR DTD
The default is sxpr
note that stag schemas exported as xml will be invalid xml, due to the
use of symbols *, +, ? in the node names
=back
=head1 LIMITATIONS
not event based - memory usage becomes exhorbitant on large files;
prepare a small sample beforehand
=cut
|