master
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22# SPDX-License-Identifier: curl
23#
24###########################################################################
26=begin comment
28This script converts an nroff file to curldown
30Example: cd2nroff [options] <file.md> > <file.3>
32Note: when converting .nf sections, this tool does not know if the
33section is code or regular quotes. It then assumes and uses ~~~c
34for code.
36=end comment
37=cut
39use strict;
40use warnings;
42my $nroff2cd = "0.1"; # to keep check
44sub single {
45 my ($f) = @_;
46 open(F, "<:crlf", $f) or
47 return 1;
48 my $line;
49 my $title;
50 my $section;
51 my $source;
52 my @seealso;
53 my @desc;
54 my $header; # non-zero when TH is passed
55 my $quote = 0; # quote state
56 while(<F>) {
57 $line++;
58 my $d = $_;
59 if($_ =~ /^.\\\"/) {
60 # a comment we can ignore
61 next;
62 }
63 if(!$header) {
64 if($d =~ /.so (.*)/) {
65 # this is basically an include, so do that
66 my $f = $1;
67 # remove leading directory
68 $f =~ s/(.*?\/)//;
69 close(F);
70 open(F, "<:crlf", $f) or return 1;
71 }
72 if($d =~ /^\.TH ([^ ]*) (\d) \"(.*?)\" ([^ \n]*)/) {
73 # header, this needs to be the first thing after leading comments
74 $title = $1;
75 $section = $2;
76 # date is $3
77 $source = $4;
78 # if there are enclosing quotes around source, remove them
79 $source =~ s/[\"\'](.*)[\"\']\z/$1/;
80 $header = 1;
82 print <<HEAD
83---
84c: Copyright (C) Daniel Stenberg, <daniel\@haxx.se>, et al.
85SPDX-License-Identifier: curl
86Title: $title
87Section: $section
88Source: $source
89HEAD
90 ;
91 }
92 next;
93 }
95 if($quote) {
96 if($d =~ /^\.SH/) {
97 #end of quote without an .fi
98 $quote = 0;
99 push @desc, "~~~\n";
100 }
101 elsif($d =~ /^\.fi/) {
102 #end of quote
103 $quote = 0;
104 push @desc, "~~~\n";
105 next;
106 }
107 else {
108 # double-backslashes converted to single ones
109 $d =~ s/\\\\/\\/g;
110 push @desc, $d;
111 next;
112 }
113 }
114 if($d =~ /^\.SH (.*)/) {
115 my $word = $1;
116 # if there are enclosing quotes, remove them first
117 $word =~ s/[\"\'](.*)[\"\']\z/$1/;
118 if($word eq "SEE ALSO") {
119 # we slurp up this section
120 next;
121 }
122 push @desc, "\n# $word\n\n";
123 }
124 elsif($d =~ /^\.(RS|RE)/) {
125 # ignore these
126 }
127 elsif($d =~ /^\.IP (.*)/) {
128 my $word = $1;
129 # if there are enclosing quotes, remove them first
130 $word =~ s/[\"\'](.*)[\"\']\z/$1/;
131 push @desc, "\n## $word\n\n";
132 }
133 elsif($d =~ /^\.IP/) {
134 # .IP with no text we skip
135 }
136 elsif($d =~ /^\.BR (.*)/) {
137 # only used for SEE ALSO
138 my $word = $1;
139 # remove trailing comma
140 $word =~ s/,\z//;
142 for my $s (split(/,/, $word)) {
143 # remove all double quotes
144 $s =~ s/\"//g;
145 # tream leading whitespace
146 $s =~ s/^ +//g;
147 push @seealso, $s;
148 }
149 }
150 elsif($d =~ /^\.I (.*)/) {
151 push @desc, "*$1*\n";
152 }
153 elsif($d =~ /^\.B (.*)/) {
154 push @desc, "**$1**\n";
155 }
156 elsif($d =~ /^\.nf/) {
157 push @desc, "~~~c\n";
158 $quote = 1;
159 }
160 else {
161 # embolden
162 $d =~ s/\\fB(.*?)\\fP/**$1**/g;
163 # links to "curl.*()" are left bare since cd2nroff handles them
164 # specially
165 $d =~ s/\\fI(curl.*?\(3\))\\fP/$1/ig;
166 # emphasize
167 $d =~ s/\\fI(.*?)\\fP/*$1*/g;
168 # emphasize on a split line
169 $d =~ s/\\fI/*/g;
170 # bold on a split line
171 $d =~ s/\\fB/**/g;
172 # remove backslash amp
173 $d =~ s/\\&//g;
174 # remove backslashes
175 $d =~ s/\\//g;
176 # fix single quotes
177 $d =~ s/\(aq/'/g;
178 # fix double quotes
179 $d =~ s/\(dq/\"/g;
180 push @desc, $d;
181 }
182 }
183 close(F);
185 print "See-also:\n";
186 for my $s (sort @seealso) {
187 print " - $s\n" if($s);
188 }
189 print "---\n";
190 print @desc;
192 return !$header;
193}
195if(@ARGV) {
196 exit single($ARGV[0]);
197}
Diagnostics4 git calls · 224 ms
CallStatusSizeTime0224 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit29 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=192 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=29 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.0 KiB192 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2008 git.response.cache=MISS git.response.duration_ms=192 git.fetch.wants=374b0cbdab58080652230e0f3de8a876e3109314 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2008 git.pkt.payload.max=1987 git.sideband.band1.bytes=1986 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1f6a2ecc6efe9
- Request
- 43c56ad1…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format