Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added include-yang #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions doc/oxtradoc/oxtradoc.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
# the line (minus the '@') is not translated.
# '!! include-figure <filename>' includes the file, and makes
# it's content a figure.
# '!! include-yang <filename>' includes the YANG module in file, and makes
# it's content a figure, and adds a proper <CODE ...> instruction.
# (requires pyang in the path)
# '-' at the beginning of the line marks a symbol list item.
# '_' at the beginning of the line marks an empty list item.
# '+' at the beginning of the line marks a numbered list item.
Expand Down Expand Up @@ -296,7 +299,7 @@ sub first_pass {
last;
}

# Handles include-figure, table, and row
# Handles include-figure, include-yang, table, and row
if (/^!!\s*(\S+)/) {
$tag = $1;
$tag =~ s/-/_/g;
Expand Down Expand Up @@ -560,7 +563,7 @@ sub section {

sub start_picture {
suspend_digress();
print "\t<figure>\n\t <artwork><![CDATA[\n";
print " <figure>\n <artwork><![CDATA[\n";
check_line_length($line, $file, $lnum) unless $do_digress;
print $indent_digress, untabify($line), "\n";
}
Expand Down Expand Up @@ -635,7 +638,7 @@ sub picture {
}

sub end_picture {
print "\t ]]></artwork>\n\t</figure>\n";
print " ]]></artwork>\n </figure>\n";
resume_digress();
}

Expand All @@ -646,27 +649,27 @@ sub start_code {

print "\n<t>", $indent_digress, untabify($line), "</t>\n";
} else {
print "\t<figure>\n\t <artwork><![CDATA[\n";
print " <figure>\n <artwork><![CDATA[\n";
print $indent_digress, untabify($line), "\n";
$art = 1;
}
}

sub end_code {
print "\t ]]></artwork>\n\t</figure>\n" if $art;
print " ]]></artwork>\n </figure>\n" if $art;
resume_digress();
$art = 0;
}

sub start_xml {
suspend_digress();
print "\t<figure>\n\t <artwork><![CDATA[\n";
print " <figure>\n <artwork><![CDATA[\n";
print $indent_digress, untabify($line), "\n";
$art = 1;
}

sub end_xml {
print "\t ]]></artwork>\n\t</figure>\n";
print " ]]></artwork>\n </figure>\n";
resume_digress();
$art = 0;
}
Expand Down Expand Up @@ -753,7 +756,7 @@ sub nlist {
}

if ($type eq "hanging") {
print "\t<t hangText=\"", esc($content), "\">\n";
print " <t hangText=\"", esc($content), "\">\n";
} else {
print " " x $ndepth, "<t>\n", esc($content), "\n";
}
Expand All @@ -773,11 +776,11 @@ sub end_nlist {

sub start_abstract {
print " <abstract>\n" unless &prev_tag() eq "abstract";
print "\t<t>\n", esc($line), "\n";
print " <t>\n", esc($line), "\n";
}

sub end_abstract {
print "\t</t>\n";
print " </t>\n";
print "</abstract>\n" unless &next_tag() eq "abstract";
}

Expand Down Expand Up @@ -855,7 +858,7 @@ sub include_figure {
print "<t>&lt;CODE BEGINS> file \"${extract_to}\"</t>\n";
}

print "\t<figure>\n\t <artwork><![CDATA[\n";
print " <figure>\n <artwork><![CDATA[\n";
open(FD, $file) || die "could not open file: $file";
while (<FD>) {
$lnum += 1;
Expand All @@ -871,13 +874,38 @@ sub include_figure {
}
}
close FD;
print "\t ]]></artwork>\n\t</figure>\n";
print " ]]></artwork>\n </figure>\n";
if ($extract_to) {
print "<t>&lt;CODE ENDS></t>\n";
}
resume_digress();
}

sub include_yang {
my $prefix;
return if $phase eq "end";

my ($file) = ($line =~ /^!!\s*include-yang (\S+)/);

my $cmd = "pyang -f name --name-print-revision ${file}";
my $extract_to = `${cmd} || echo 1` || die "error invoking: ${cmd}";
$extract_to =~ s/\s+$//;
!($extract_to eq "1") || die "error invoking: ${cmd}";

suspend_digress();
print "<t>&lt;CODE BEGINS> file \"${extract_to}.yang\"</t>\n";
print " <figure>\n <artwork><![CDATA[\n";
open(FD, $file) || die "could not open file: $file";
while (<FD>) {
$line = untabify($_);
print $indent_digress, $prefix, $line;
}
close FD;
print " ]]></artwork>\n </figure>\n";
print "<t>&lt;CODE ENDS></t>\n";
resume_digress();
}

sub list_sections {
return if $phase eq "end";

Expand Down Expand Up @@ -994,11 +1022,11 @@ sub question {
return if /^$/;

if (/^\? /) {
print "\t </c>\n\t</texttable>\n" if $in_question;
print " </c>\n </texttable>\n" if $in_question;

print "\t<?rfc compact=\"yes\"?>\n\t<texttable>\n",
print " <?rfc compact=\"yes\"?>\n <texttable>\n",
"<ttcol align='left' width='60em'>Open Question</ttcol>\n";
print "\t <c>\n";
print " <c>\n";
s/^\?\s+//;
}

Expand All @@ -1007,7 +1035,7 @@ sub question {
}

sub end_question {
print "\t </c>\n\t</texttable>\n\t<?rfc compact=\"no\"?>\n";
print " </c>\n </texttable>\n <?rfc compact=\"no\"?>\n";
$in_question = 0;
}

Expand Down Expand Up @@ -1045,9 +1073,9 @@ print "<?rfc private=\"$doc{private}\"?>\n" if $doc{private};
EOF

print_authors($doc);
print "\t<date/>\n";
print " <date/>\n";
foreach $k (@{$doc{keyword}}) {
print "\t<keyword>", $k, "</keyword>\n";
print " <keyword>", $k, "</keyword>\n";
}
}

Expand Down