CREDITS: Add yaml output option and make indentation consistent

This commit is contained in:
Matan Bareket 2019-10-08 20:23:31 -04:00
parent 3f1ff3eaea
commit c1697cd177

View File

@ -7,7 +7,8 @@
# - The gui/credits.h header file
# - The Credits.rtf file used by the Mac OS X port
# - The credits.xml file, part of the DocBook manual
# - Finally, credits.xml, for use on the website (different format than the DocBook one)
# - The credits.xml, for use on the website (different format than the DocBook one)
# - The credits.yaml, alternative version for use on the website
#
# Initial version written by Fingolfin in December 2004.
#
@ -27,6 +28,13 @@ my $max_name_width;
# in terms of 'sections'.
my $section_level = 0;
# Variables used for yaml output
my $person_started = 0;
my $group_started = 0;
my $group_indent = "";
my $paragraph_started = 0;
my $indent = "";
# Count how many sections there have been on this level already
my @section_count = ( 0, 0, 0 );
@ -37,11 +45,12 @@ if ($#ARGV >= 0) {
$mode = "XML-DOC" if ($ARGV[0] eq "--xml-docbook"); # credits.xml (DocBook)
$mode = "RTF" if ($ARGV[0] eq "--rtf"); # Credits.rtf (Mac OS X About box)
$mode = "STRONGHELP" if ($ARGV[0] eq "--stronghelp"); # AUTHORS (RISC OS StrongHelp manual)
$mode = "YAML" if ($ARGV[0] eq "--yaml"); # YAML (Simple format)
}
if ($mode eq "") {
print STDERR "Usage: $0 [--text | --xml-website | --cpp | --xml-docbook | --rtf | --stronghelp]\n";
print STDERR " Just pass --text / --xml-website / --cpp / --xml-docbook / --rtf / --stronghelp as parameter, and credits.pl\n";
print STDERR "Usage: $0 [--text | --xml-website | --cpp | --xml-docbook | --rtf | --stronghelp | --yaml]\n";
print STDERR " Just pass --text / --xml-website / --cpp / --xml-docbook / --rtf / --stronghelp / --yaml as parameter, and credits.pl\n";
print STDERR " will print out the corresponding version of the credits to stdout.\n";
exit 1;
}
@ -250,6 +259,9 @@ sub begin_credits {
print "<?xml version='1.0'?>\n";
print "<!-- This file was generated by credits.pl. Do not edit by hand! -->\n";
print "<credits>\n";
} elsif ($mode eq "YAML") {
print "# This file was generated by credits.pl. Do not edit by hand!\n";
print "credits:\n";
} elsif ($mode eq "STRONGHELP") {
print "ScummVM - AUTHORS\n";
print "# This file was generated by credits.pl. Do not edit by hand!\n";
@ -348,14 +360,31 @@ sub begin_section {
#print "\t\t\t<group>" . $title . "</group>\n";
#print "\t\t\t\t<name>" . $title . "</name>\n";
}
} elsif ($mode eq "YAML") {
my $key = "section:\n";
$indent = " " . (" " x $section_level);
if ($section_level eq 1) {
$key = "subsection:\n";
}
if ($section_level < 2) {
if (@section_count[$section_level] eq 0) {
print $indent . $key;
}
print $indent . "-\n";
print $indent . " title: \"" . $title . "\"\n";
if ($anchor) {
print $indent . " anchor: \"" . $anchor . "\"\n";
}
}
} elsif ($mode eq "STRONGHELP") {
$title = html_entities_to_iso8859_1($title);
print "#fH" . ($section_level + 1) . ":" . $title."\n";
}
# Implicit start of person list on section level 2
if ($section_level >= 2) {
begin_persons($title);
begin_persons($title, 1);
}
@section_count[$section_level]++;
$section_level++;
@ -364,10 +393,13 @@ sub begin_section {
sub end_section {
$section_level--;
$paragraph_started = 0;
$group_started = 0;
# Implicit end of person list on section level 2
if ($section_level >= 2) {
end_persons();
$group_started = 1;
}
if ($mode eq "TEXT") {
@ -391,10 +423,21 @@ sub end_section {
sub begin_persons {
my $title = shift;
my $level = shift;
if ($mode eq "XML-WEB") {
print "\t\t\t<group>\n";
print "\t\t\t\t<name>" . $title . "</name>\n";
#print "\t\t\t\t<persons>\n";
} elsif ($mode eq "YAML") {
$group_indent = $level eq 1 ? " " : " " . (" " x $section_level);
if ($group_started == 0) {
print $group_indent . "group:\n";
$group_started = 1;
}
print $group_indent . "-\n";
print $group_indent . " name: \"" . $title . "\"\n";
}
}
@ -408,6 +451,8 @@ sub end_persons {
print "\t\t\t</group>\n";
} elsif ($mode eq "STRONGHELP") {
print "\n";
} elsif ($mode eq "YAML") {
$person_started = 0;
}
}
@ -482,6 +527,18 @@ sub add_person {
print "\t\t\t\t\t<alias>" . $nick . "</alias>\n";
print "\t\t\t\t\t<description>" . $desc . "</description>\n";
print "\t\t\t\t</person>\n";
} elsif ($mode eq "YAML") {
$indent = $group_indent . " ";
if ($person_started eq 0) {
print $indent . "person:\n";
$person_started = 1;
}
print $indent . "-\n";
$name = "???" if $name eq "";
print $indent . " name: \"" . $name . "\"\n";
print $indent . " alias: \"" . $nick . "\"\n";
print $indent . " description: \"" . $desc . "\"\n";
} elsif ($mode eq "STRONGHELP") {
my $min_name_width = length $desc > 0 ? $max_name_width : 0;
$name = $nick if $name eq "";
@ -519,6 +576,13 @@ sub add_paragraph {
print " <row><entry namest='start' nameend='job'> </entry></row>\n\n";
} elsif ($mode eq "XML-WEB") {
print "\t\t<paragraph>" . $text . "</paragraph>\n";
} elsif ($mode eq "YAML") {
$indent = " " . (" " x $section_level);
if ($paragraph_started eq 0) {
print $indent . "paragraph:\n";
$paragraph_started = 1;
}
print $indent . "- \"" . $text . "\"\n";
} elsif ($mode eq "STRONGHELP") {
$text = html_entities_to_iso8859_1($text);
print "#Wrap On\n";