123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- my $nroff2cd = "0.1";
- sub single {
- my ($f)=@_;
- open(F, "<:crlf", "$f") ||
- return 1;
- my $line;
- my $title;
- my $section;
- my $source;
- my @seealso;
- my @desc;
- my $header;
- my $quote = 0;
- while(<F>) {
- $line++;
- my $d = $_;
- if($_ =~ /^.\\\"/) {
-
- next;
- }
- if(!$header) {
- if($d =~ /.so (.*)/) {
-
- my $f = $1;
-
- $f =~ s/(.*?\/)//;
- close(F);
- open(F, "<:crlf", "$f") || return 1;
- }
- if($d =~ /^\.TH ([^ ]*) (\d) \"(.*?)\" ([^ \n]*)/) {
-
- $title = $1;
- $section = $2;
-
- $source = $4;
-
- $source =~ s/[\"\'](.*)[\"\']\z/$1/;
- $header = 1;
- print <<HEAD
- ---
- c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- SPDX-License-Identifier: curl
- Title: $title
- Section: $section
- Source: $source
- HEAD
- ;
- }
- next;
- }
- if($quote) {
- if($d =~ /^\.SH/) {
-
- $quote = 0;
- push @desc, "~~~\n";
- }
- elsif($d =~ /^\.fi/) {
-
- $quote = 0;
- push @desc, "~~~\n";
- next;
- }
- else {
-
- $d =~ s/\\\\/\\/g;
- push @desc, $d;
- next;
- }
- }
- if($d =~ /^\.SH (.*)/) {
- my $word = $1;
-
- $word =~ s/[\"\'](.*)[\"\']\z/$1/;
- if($word eq "SEE ALSO") {
-
- next;
- }
- push @desc, "\n# $word\n\n";
- }
- elsif($d =~ /^\.(RS|RE)/) {
-
- }
- elsif($d =~ /^\.IP (.*)/) {
- my $word = $1;
-
- $word =~ s/[\"\'](.*)[\"\']\z/$1/;
- push @desc, "\n## $word\n\n";
- }
- elsif($d =~ /^\.IP/) {
-
- }
- elsif($d =~ /^\.BR (.*)/) {
-
- my $word = $1;
-
- $word =~ s/,\z//;
- for my $s (split(/,/, $word)) {
-
- $s =~ s/\"//g;
-
- $s =~ s/^ +//g;
- push @seealso, $s;
- }
- }
- elsif($d =~ /^\.I (.*)/) {
- push @desc, "*$1*\n";
- }
- elsif($d =~ /^\.B (.*)/) {
- push @desc, "**$1**\n";
- }
- elsif($d =~ /^\.nf/) {
- push @desc, "~~~c\n";
- $quote = 1;
- }
- else {
-
- $d =~ s/\\fB(.*?)\\fP/**$1**/g;
-
-
- $d =~ s/\\fI(curl.*?\(3\))\\fP/$1/ig;
-
- $d =~ s/\\fI(.*?)\\fP/*$1*/g;
-
- $d =~ s/\\fI/*/g;
-
- $d =~ s/\\fB/**/g;
-
- $d =~ s/\\&//g;
-
- $d =~ s/\\//g;
-
- $d =~ s/\(aq/'/g;
-
- $d =~ s/\(dq/\"/g;
- push @desc, $d;
- }
- }
- close(F);
- print "See-also:\n";
- for my $s (sort @seealso) {
- print " - $s\n" if($s);
- }
- print "---\n";
- print @desc;
- return !$header;
- }
- exit single($ARGV[0]);
|