-
Notifications
You must be signed in to change notification settings - Fork 0
/
riscos-prminxml
executable file
·1312 lines (1180 loc) · 38.1 KB
/
riscos-prminxml
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
##
# PRMinXML generation tool.
#
# This tool is intended to build documentation using the PRMinXML
# stylesheets.
#
# This script should be a perl 5.0 tool which can be used under
# RISC OS or POSIX systems.
#
# At the present time it has not been tested under RISC OS.
#
# Requires:
# Native xsltproc (when processing individual files)
# Native xmllint (when linting individual files)
# Native make (when generating multiple indexed files)
#
my $riscos = ($^O eq '') || ($^O eq 'riscos');
my $script = "$0";
my $scriptdir = $script;
my $resourcedir;
my $dirsep = $riscos ? '.' : '/';
my $extsep = $riscos ? '/' : '.';
my $envvar;
if ($riscos)
{
if (! ($scriptdir =~ s/\.[^\.]+$//))
{
$scriptdir = "@";
}
$resourcedir = "$scriptdir${dirsep}riscos-prminxml-resources";
if (!-d $resourcedir) {
# May have been installed into the XMLCatalog resource
if (-d '<XMLCatalog$Dir>.gerph') {
$resourcedir = '<XMLCatalog$Dir>';
}
}
$envvar_catalog = 'XML$CatalogFiles';
}
else
{
if (! ($scriptdir =~ s/\/[^\/]+$//))
{
$scriptdir = ".";
}
$resourcedir = "$scriptdir${dirsep}riscos-prminxml-resources";
$envvar_catalog = 'XML_CATALOG_FILES';
}
if (!-d $resourcedir)
{
# Not yet installed
$resourcedir = "$scriptdir${dirsep}catalog";
}
my $toolname = 'riscos-prminxml';
my $version = 'VERSION';
my $debug = 0;
my $lint = 0;
my $format = 'html5';
my $outputdir = undef;
my $outputfile = undef;
my $tool = 'xsltproc';
my $toollint = 'xmllint';
my $catalog_base = 'http://gerph.org/dtd';
my $catalog_version = '103';
my $logdir = undef;
my $logfile = undef;
my $index = undef;
my $params = {};
my $unique = $$ || time();
my $tempbase;
if ($riscos)
{
if (defined $ENV{'Wimp$ScrapDir'})
{
$tempbase = "<Wimp\$ScrapDir>.prmxml-$unique";
}
else
{
$tempbase = "\$.prmxml-$unique";
}
}
else
{
$tempbase = "/tmp/prminxml-$unique";
}
# Extensions to use for each format
my %extensions = (
'html' => 'html',
'html5' => 'html',
'html+xml' => 'html',
'html5+xml' => 'html',
'header' => 'h',
'command' => 'txt',
'stronghelp' => undef,
'index' => undef, # Special value
'lint' => undef, # Special value
'skeleton' => undef, # Special value
);
my @valid_formats = (
'header',
'command',
'stronghelp',
'html',
'html5',
);
my $arg;
while ($arg = shift)
{
#print "Arg = $arg\n";
if ($arg =~ /^-(-?)([a-zA-Z\-]+)/)
{
my ($double, $arg) = ($1, $2);
my @args = ();
if ($double)
{
# Long options are given by name.
push @args, $arg;
}
else
{
# Single character arguments are broken up.
push @args, split //, $arg;
}
for $arg (@args)
{
if ($arg eq 'help' or $arg eq 'h')
{
help();
exit(0);
}
elsif ($arg eq 'help-indexed')
{
help_indexed();
exit(0);
}
elsif ($arg eq 'help-params')
{
help_params();
exit(0);
}
elsif ($arg eq 'version' or $arg eq 'V')
{
version();
exit(0);
}
elsif ($arg eq 'catalog' or $arg eq 'C')
{
$catalog_version = shift;
}
elsif ($arg eq 'debug' or $arg eq 'd')
{
$debug = 1;
}
elsif ($arg eq 'help-tag')
{
$helptag = shift;
help_tag($helptag);
exit(0);
}
elsif ($arg eq 'lint')
{
$lint = 1;
}
elsif ($arg eq 'format' or $arg eq 'f')
{
$format = shift;
if (! exists $extensions{$format})
{
die "Format '$format' is not known\n";
}
}
elsif ($arg eq 'logdir' or $arg eq 'L')
{
$logdir = shift;
}
elsif ($arg eq 'logfile' or $arg eq 'l')
{
$logfile = shift;
}
elsif ($arg eq 'outputdir' or $arg eq 'O')
{
$outputdir = shift;
}
elsif ($arg eq 'output' or $arg eq 'o')
{
my $output = shift;
# Convenience; if they give us a directory, we just use that
if (-d $output)
{
$outputdir = $output;
}
else
{
$outputfile = $output;
}
}
elsif ($arg eq 'param' or $arg eq 'p')
{
my $param = shift;
my ($name, $value) = ($param =~ /^([a-zA-Z\-]+)=(.*)$/);
if (!$name)
{
die "Parameter should be given in the form '<name>=<value>'\n";
}
$params{$name} = $value;
}
}
}
else
{
#print "Push back $arg\n";
print ""; # Some bug in the perl interpreter causes the unshift to be ignored without this?!
unshift @ARGV, $arg;
last;
}
}
# See if we can read what the input files are.
my @inputs = ();
my $f;
while ($f = shift)
{
#print "Arg: Bare filename $f\n";
my $nf = native_filename($f);
if (!$nf)
{
# FIXME: Should we allow non-local file resources? (eg http resources?)
die "Input '$f' is not a file\n";
}
push @inputs, $nf;
}
if ($format eq 'skeleton')
{
if (!defined $outputfile)
{
die "No output file defined for skeleton\n";
}
if (-f $outputfile)
{
die "Skeleton output file '$outputfile' already exists - refusing to overwrite\n";
}
$skeleton = "$resourcedir${dirsep}gerph${dirsep}skeleton${extsep}xml";
copyfile($skeleton, $outputfile, 'skeleton source', 'skeleton output');
print "Created $outputfile\n";
print "To create HTML from this, use:\n";
my $newfile = replaceext($outputfile, "html");
print " $toolname -f html5 -o $newfile $outputfile\n";
if ($riscos)
{
# Ensure that the skeleton XML file is given an appropriate type.
system "Settype $outputfile F80";
}
exit 0;
}
if (scalar(@inputs) == 0)
{
die "No input files supplied\n";
}
if (scalar(@inputs) > 1 && defined($outputfile))
{
die "Cannot process multiple outputs to a single output file\n";
}
if (defined $logdir)
{
my $nlogdir = native_filename($logdir, 'd');
if (!$nlogdir)
{
die "Log directory '$logdir' does not exist\n";
}
$logdir = $nlogdir;
}
if (defined $outputdir)
{
my $noutput = native_filename($outputdir, 'd');
if (!$noutput)
{
die "Output directory '$outputdir' does not exist\n";
}
$outputdir = $noutput;
}
my $rc = 0;
if ($format eq 'index')
{
# Special case for the 'index' format - we take a index.xml file and we build everything
# described in it and give it a common structure.
if (scalar(@inputs) != 1)
{
die "For 'index' format, only a single file, the index${extsep}xml file, should be supplied\n";
}
if (defined $outputdir)
{
die "For 'index' format, the output directory should be supplied in the index${extsep}xml file\n";
}
if (!defined $logdir)
{
die "For 'index' format, a log directory must be supplied\n";
}
my $indexxml = $inputs[0];
my $step = 1;
# Build the makefile
print "Building makefile\n";
my $makefile = "$tempbase-Makefile";
# FIXME: Should we use the makefile-ro for RISC OS? Does that work any more?
my $xslt = "$catalog_base/$catalog_version/prmindex-makefile.xsl";
my $cmd = "$tool";
$cmd .= " -stringparam index-xml \"$indexxml\"";
$cmd .= " $xslt \"$indexxml\" > \"$makefile\"";
runcommand($cmd) && die "Unable to generate makefile with: $cmd\n";
#print("Made makefile: $makefile\n");
#<STDIN>;
# Clean
print "Cleaning target\n";
$cmd = "make -f \"$makefile\" clean > \"$logdir${dirsep}$step-clean${extsep}log\"";
$cmd .= " 2>&1" if (!$riscos);
runcommand($cmd) && die "Unable to clean directories with: $cmd\n";
$step += 1;
# Build
print "Building documentation\n";
my $logfile;
$logfile = "$logdir${dirsep}$step-build${extsep}log";
build_with_log("make -f \"$makefile\"", $logfile, "build documentation");
$step += 1;
if ($lint)
{
# Validate
print "Validating source\n";
$logfile = "$logdir${dirsep}$step-validate${extsep}log";
build_with_log("make -f \"$makefile\" validate", $logfile, "validate documentation", 1);
$step += 1;
# Report on the validity errors
if (check_lint_log($logfile) && $lint)
{
$rc = 1;
}
}
unlink "$makefile";
}
else
{
if (!defined $outputdir)
{
if ($riscos)
{ $outputdir = '@'; }
else
{ $outputdir = '.'; }
}
my $copy_xml = 0;
if ($format =~ s/\+xml$//)
{
$copy_xml = 1;
}
for $input (@inputs) {
my $xslt = "$catalog_base/$catalog_version/prm-$format.xsl";
my $out;
my $cmd;
if (defined($outputfile))
{
$out = $outputfile;
if ($riscos)
{
if ($outputfile !~ /[:\$@%\\]/)
{
$out = "$outputdir.$outputfile";
}
}
else
{
if ($outputfile !~ /^\//)
{
$out = "$outputdir/$outputfile";
}
}
}
else
{
my $leaf = leafname($input);
$leaf = replaceext($leaf, $extensions{$format});
$out = "$outputdir${dirsep}$leaf";
}
print "Processing $input -> $out\n";
my $logtail = '';
my $log;
if ($logfile or $logdir)
{
# They want a log file writing out.
if ($logfile)
{
$log = $logdir ? "$logdir${dirsep}$logfile" : "$logfile";
# They wanted just one log file.
open(OUT, ">> $log") || die "Cannot access log file '$log': $!\n";
print OUT "--- $input -> $output ---\n";
close OUT;
}
else
{
# They gave a log directory, so we want to create one file per input
my $leaf = leafname($input);
$leaf = replaceext($leaf, 'log');
$log = "$logdir${dirsep}$leaf";
}
if ($riscos)
{
$logtail = " > $log";
}
else
{
$logtail = " > \"$log\" 2>&1";
}
}
if ($lint)
{
# They requested linting first; so we need to check the file
my $native = $riscos ? '--native' : '';
$cmd = "$toollint $native --noout --valid \"$input\"";
if ($riscos)
{
$cmd .= " > $tempbase";
}
else
{
$cmd .= " > \"$tempbase\" 2>&1";
}
my $cmdrc = runcommand($cmd);
if ($cmdrc != 0)
{
# Any lint failure, when requested, is an overall failure
$rc = 1;
print " Linting failed with rc=".($cmdrc>>8)."\n";
}
# Copy the file to any log we have
open(IN, "< $tempbase") || die "Cannot read temporary log file '$tempbase': $!\n";
if ($log)
{
# If they specified a log, then everything should go to the log
open(OUT, ">> $log") || die "Cannot update log file '$log': $!\n";;
while (<IN>)
{
print OUT;
}
close(OUT)
}
else
{
# No log supplied, so we should write to the display
while (<IN>)
{
print;
}
}
close(IN);
# Report on the validity errors
if (check_lint_log($tempbase, $input))
{
# There were failures, so that means we return a failure from this command
$rc = 1;
}
}
if ($format eq 'lint')
{
my $native = $riscos ? '--native' : '';
$cmd = "$toollint $native --noout --valid \"$input\"";
}
else
{
my $native = $riscos ? '--native' : '';
my $cliparams = join(' ', map { "--stringparam $_ \"$params{$_}\"" } sort keys %params);
$cmd = "$tool $native $cliparams --output \"$out\" $xslt \"$input\"";
}
$cmd .= $logtail;
my $cmdrc = runcommand($cmd);
if ($cmdrc != 0)
{
# Any type of failure means that we'll return a failure.
$rc = 1;
print "Failed to process document\n";
}
else
{
# Success, so see copy the XML, if we need to.
if ($copy_xml)
{
my $outxml = replaceext($out, 'xml');
print " Copying -> $outxml\n";
copyfile($input, $outxml);
}
}
}
}
# If we get to here, we'll clear away the file.
unlink($tempbase);
exit($rc);
##
# Return the directory name of a file.
sub dirname
{
my ($f) = @_;
if ($riscos)
{ $f =~ s/\.[^\.]+$//; }
else
{ $f =~ s/\/[^\/]+$//; }
return $f;
}
##
# Return the leafname of a file.
sub leafname
{
my ($f) = @_;
if ($riscos)
{ $f =~ s/^.*\.([^\.]+)$/$1/; }
else
{ $f =~ s/^.*\/([^\/]+)$/$1/; }
return $f;
}
##
# Replace extension with a new one
sub replaceext
{
my ($f, $ext) = @_;
if ($riscos)
{
if (! $ext)
{ $f =~ s/(^|\.)([^\.]+)\/[^\.]+$/$1$2/; }
else
{ $f =~ s/(^|\.)([^\.]+)\/[^\.]+$/$1$2\/$ext/; }
}
else
{
if (! $ext)
{ $f =~ s/(^|\/)([^\/]+)\.[^\/]+$/$1$2/; }
else
{ $f =~ s/(^|\/)([^\/]+)\.[^\/]+$/$1$2.$ext/; }
}
return $f;
}
##
# Copy a file to a new location.
sub copyfile
{
my ($src, $dst, $srcname, $dstname) = @_;
open(IN, "< $src") || die "Cannot read $srcname file '$src': $!\n";
open(OUT, "> $dst") || die "Cannot write to $dstname file '$dst': $!\n";
while (<IN>)
{
print OUT;
}
close(OUT);
close(IN);
}
##
# Expand a RISC OS variable on non-RISC OS system.
sub expand_variable
{
my ($var) = @_;
my $uvar = $var;
$uvar = uc $uvar;
$uvar =~ tr/$/_/;
if (defined $ENV{$uvar})
{
return $ENV{$uvar};
}
return "<$var>";
}
##
# Convert a filename supplied into a native format.
sub native_filename
{
my ($f, $type) = @_;
$type ||= 'f';
if (($type eq 'f' && -f $f) ||
($type eq 'd' && -d $f))
{
# Already a native filename; that's fine.
return $f;
}
if (!$riscos)
{
# We're not on RISC OS.
my $rof = $f;
# Let's see if we can swap the convention to native style
$rof =~ tr!./!/.!;
# And replace any variable expansions.
$rof =~ s/<([A-Za-z0-9_\$]+)>/expand_variable($1)/ge;
if (($type eq 'f' && -f $rof) ||
($type eq 'd' && -d $rof))
{
# Just swapping the directory and extensions around appeared to work
return $rof;
}
if ($rof =~ m!/xml$!)
{
# It ends in /xml so it could have been given a filetype.
if (($type eq 'f' && -f "$rof,f80") ||
($type eq 'd' && -d "$rof,f80"))
{
# Gotcha
return "$rof,f80";
}
}
}
else
{
# We're on RISC OS, we might have been given a unix style filename.
# FIXME: Not implemented.
}
return undef;
}
##
# Run a command and return the return code (in perl format)
sub runcommand
{
my ($cmd) = @_;
my $oldenv = $ENV{$envvar_catalog};
# Use the catalog files that we supplied.
my $need_restore = 0;
my $tmpsymlink = undef;
my $catalog = "${resourcedir}${dirsep}root${extsep}xml";
if (-f "$catalog") {
# Only use the resource catalog if one is present; otherwise we'll fall back to the
# system catalogs or fetching from the network if possible.
$need_restore = 1;
$ENV{$envvar_catalog} = $catalog;
if ($catalog =~ / / && !$riscos)
{
# The catalog directory contains a space. This would make it impossible for us to reference the
# XML catalog because the files used would be inaccessible due to the spaces in the path.
# However, we can get around this. We can create a temporary symlink which points to the resources
# directory. This would then allow us to use /that/ as the path, which had no spaces in.
$tmpsymlink = "$tempbase-res";
symlink "$resourcedir", "$tmpsymlink";
$ENV{$envvar_catalog} = "${tmpsymlink}${dirsep}root${extsep}xml";
print "Replaced catalog with ${tmpsymlink}${dirsep}root${extsep}xml\n" if ($debug);
}
}
else
{
print "WARNING: Falling back to system catalog / network resources as catalog not available ('$catalog' does not exist)\n";
}
print "Command: $cmd\n" if ($debug);
my $rc = system "$cmd";
print "RC is $rc\n" if ($debug);
# Restore the old environment variable on RISC OS
if ($need_restore) {
if (defined $oldenv) {
$ENV{$envvar_catalog} = $oldenv;
}
else {
delete $ENV{$envvar_catalog};
}
}
if ($tmpsymlink)
{
unlink $tmpsymlink;
}
return $rc;
}
##
# Build using a command, with a log which we report on failure.
#
# Note: Will die if there is a failure.
#
# @param $cmd The command to run
# @param $logfile Where the logfile should go
# @param $type The build type, as a readable string
# @param $always_print Always output the logs
sub build_with_log
{
my ($cmd, $logfile, $type, $always_print) = @_;
$cmd = "$cmd > \"$logfile\"";
$cmd .= " 2>&1" if (!$riscos);
my $rc = runcommand($cmd);
if ($rc || $always_print)
{
if ($rc) {
print "Failed to $type; log follows:\n";
}
else {
print " Log for $type:\n";
}
if (! open(LOG, "< $logfile"))
{
print "ERROR: Cannot read log '$logfile': $!\n";
}
else
{
while (<LOG>)
{
if (/^Processing|xsltproc/)
{
# This is a heading block.
print " $_";
}
else
{
print " $_";
}
}
}
}
if ($rc)
{
die "Unable to $type with: $cmd\n";
}
}
##
# Check a log containing lint information.
#
# @param $logfile The file holding the lint information
# @param $infile The initial file we are parsing, or undef if none
#
# @return: Number of failures seen
sub check_lint_log
{
my ($logfile, $infile) = @_;
open(LOG, "< $logfile") || die "Could not read validation log file '$logfile': $!\n";
my $onefile = defined($infile);
my $nfails = 0;
my %badfiles;
while (<LOG>)
{
if (/^xmllint.* (\S*)\n?$/)
{
my $cmd = $_;
$infile = $1;
}
if (/validity error/)
{
$nfails++;
$badfiles{$infile} = ($badfiles{$infile} || 0) + 1;
}
}
close(LOG);
if ($nfails > 0)
{
print " Validation failures: $nfails\n";
if (!$onefile)
{
print " Failure breakdown:\n";
for $file (sort(keys %badfiles))
{
printf " %4i : %s\n", $badfiles{$file}, $file;
}
}
}
return $nfails;
}
##
# Print version messages.
sub version
{
print "$toolname $version\n";
}
##
# Print help message for a specific tag (or which ones are supported).
sub help_tag
{
my ($helptag) = @_;
my $dochelp;
$dochelp = "$resourcedir${dirsep}docs${dirsep}PRMinXML${extsep}txt";
open(IN, "< $dochelp") || die "Cannot find documentation file '$dochelp': $!\n";
if (!$helptag)
{
print("Supported tags (with attributes, and child elements):\n");
}
my $show_element = 0;
my $current_tag = undef;
my $current_attributes = undef;
my $current_children = undef;
my $last = "\n";
while (<IN>)
{
my $line = $_;
if ($last eq "\n" && $_ eq "\n")
{
$show_element = 0;
}
elsif (/^Element: +(.*)\n/)
{
# We've found an element
my $tag = $1;
my $namespace = undef;
if ($tag =~ s/ \(namespace: (.*)\)//)
{
$namespace = $1;
}
if ($tag eq $helptag)
{
$show_element = 1;
print;
}
elsif (!$helptag)
{
# We're showing all elements
$current_tag = $tag;
$current_attributes = '<none>';
$current_children = '<none>';
}
}
elsif (/^Attributes: +(.*)\n/)
{
if ($show_element) {
print;
}
elsif (!$helptag)
{
$current_attributes = $1;
}
}
elsif (/^Children: +(.*)\n/)
{
if ($show_element) {
print;
}
elsif (!$helptag)
{
$current_children = $1;
}
}
elsif (/^ *\n/)
{
if ($show_element) {
print;
}
elsif (!$helptag && $current_tag)
{
my $attr = join(', ', map { "\@$_" } split(/, */, $current_attributes));
$attr =~ s/@<none>/<none>/;
printf " %-24s %s\n", $current_tag, $attr;
if (!$current_children)
{
$current_children = '<none>';
}
#if ($current_children ne '<none>') {
printf " %24s %s\n", '', $current_children;
#}
$current_tag = undef;
}
}
else
{
if ($show_element) {
print;
}
}
$last = $line;
}
close(IN);
}
##
# Print help messages.
sub help
{
print "$toolname $version - converts structured documentation to presentation formats\n";
print "Syntax: $toolname <options> <input-files>\n";
my $formats = join ', ', sort keys %extensions;
print <<EOM;
Options:
--help, -h This help message
--help-indexed Help on creating indexed collections of documents
--help-params Help on parameters for stylesheets
--help-tag [<tag>]
Print help for a specific tag (or list the supported tags)
--version, -V Show version of this tool
--catalog <version>, -C <version>
Select the version of the transforms to use (default $catalog_version)
--debug, -d Enable debug
--lint Lint files as well as formatting them
--format <format>, -f <format>
Format to render into ($formats)
--logfile <file>, -l <file>
Log file to write to
--logdir <dir>, -L <dir>
Log directory (for writing multiple files)
--output <file>, -o <file>
Output file (or directory) to write to
--outputdir <dir>, -O <dir>
Output directory to use
--param <name>=<value>, -p <name>=<value>
Supply parameters to the stylesheet for the render format.
The 'skeleton' format outputs a skeleton document containing examples of some
of the structures used in the PRM-in-XML format:
$toolname -f skeleton -o skel${extsep}xml
The 'html' format is the most common. Usually you would use a command like
(the '-f html' is actually the default, but is used for completeness):
$toolname -f html -O outputdir mydocs${extsep}xml
The 'html+xml' format is exactly the same but copies the XML file alongside
the HTML:
$toolname -f html+xml -O outputdir mydocs${extsep}xml
The 'html5' format is similar to the 'html' format, but uses HTML 5 semantic
elements and CSS to render documents:
$toolname -f html5 -O outputdir mydocs${extsep}xml
The 'header' format outputs a C header file for the constants from the file:
$toolname -f header -O outputdir mydocs${extsep}xml
The 'command' format outputs a command line help file suitable for passing
through VTranslate:
$toolname -f command -O outputdir mydocs${extsep}xml
The 'stronghelp' format outputs a skeleton StrongHelp directory structure:
$toolname -f stronghelp -O outputdir mydocs${extsep}xml
The 'lint' format just checks that the files supplied follow the DTD defined for
the files. Whilst the HTML might be generated adequately, it is very useful
to stick to the intended definition of the format to ensure that it will
work with future iterations of the conversion.
$toolname -f lint mydocs${extsep}xml
Linting can be used as a check in addition to any of the other formatting
operations by specifying the --lint option.
The 'index' format is more complex; it can take a 'index${extsep}xml' file which
describes many documents to be included in the structured output documentation:
$toolname -f index index${extsep}xml