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
|
#! /usr/bin/env perl
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# usage: skeleton [--header=PATH ...] API ...
# Using declarations from the given headers, generate a skeleton man page
# for the named APIs.
use 5.012;
use warnings;
use autodie;
use Getopt::Long;
sub slurp
{
my $path = shift;
open(my $fh, "<", $path);
return do { local $/; <$fh> }
}
sub datestamp
{
use POSIX qw/strftime/;
return strftime "%B %d, %Y", localtime;
}
# Extract the function declarations from an ATS header file.
sub parse
{
my $decls = [];
foreach my $header (@_) {
my $defs = slurp($header);
while ($defs =~ m/
tsapi\s+ # Start with 'tsapi'
([^;\(]+) # Capture the followinf return value
\s+(\w+)\s* # Capture the word before the opening parenthesis
\(([^\)]+)\) # Capture the arguments
.*\;/xg) {
chomp $1; chomp $2; chomp $3;
my $d ={ return => $1, name => $2, args => $3 };
$d->{args} =~ s/\n//g;
push @$decls, $d;
}
}
return $decls;
}
# Return a mandoc declaration for the given API name.
sub define
{
my $decls = shift;
my $name = shift;
foreach my $d (@$decls) {
if ($d->{name} eq $name) {
my @args;
my $mdoc;
@args = split(/,\s+/, $d->{args}); # split args at comma boundaries
@args = map { "\"$_\"" } @args; # quote each arg list element
$mdoc =
".Ft \"" . $d->{return} . "\"\n" .
".Fo " . $name . "\n" .
".Fa " . join("\n.Fa ", @args) . "\n" .
".Fc";
$mdoc =~ s/^\s+(.*)\s+$/$1/;
return $mdoc;
}
}
}
my @headers = ();
my $options = GetOptions(
"header=s" => \@headers
);
my $decls = parse(@headers);
#say define($decls, @ARGV);
print <<EOF;
.\\" Licensed to the Apache Software Foundation (ASF) under one .\\"
.\\" or more contributor license agreements. See the NOTICE file .\\"
.\\" distributed with this work for additional information .\\"
.\\" regarding copyright ownership. The ASF licenses this file .\\"
.\\" to you under the Apache License, Version 2.0 (the .\\"
.\\" "License"); you may not use this file except in compliance .\\"
.\\" with the License. You may obtain a copy of the License at .\\"
.\\" .\\"
.\\" http://www.apache.org/licenses/LICENSE-2.0 .\\"
.\\" .\\"
.\\" Unless required by applicable law or agreed to in writing, software .\\"
.\\" distributed under the License is distributed on an "AS IS" BASIS, .\\"
.\\" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. .\\"
.\\" See the License for the specific language governing permissions and .\\"
.Dd @{[ datestamp() ]}
.Dt @{[ $ARGV[0] ]} 3ts TSAPI
.Sh NAME
.Nm @{[ join(",\n.Nm ", @ARGV) ]}
.Nd XXX Api short description
.Sh LIBRARY
Apache Traffic Server plugin API
.Sh SYNOPSIS
.In ts/ts.h
EOF
print @{[ map { define($decls, $_) . "\n" } @ARGV ]};
print <<EOF;
.Sh DESCRIPTION
.Sh RETURN VALUES
.Sh EXAMPLES
.nf
#include <ts/ts.h>
.fi
.Sh SEE ALSO
.Xr TSAPI 3ts
EOF
# vim: set ts=2 sw=2 et :
|