master
1#!/usr/bin/env perl
2# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3#
4# SPDX-License-Identifier: curl
6# Output all the C comments and double-quoted strings in the given source
7# files. All other contents should be blanked out. Output the text at the same
8# horizontal position as in the original file.
9#
10# Ignores strings for the preprocessor.
11#
12## States
13#
14# 0 - default, initial state
15# 1 - there was a slash
16# 2 - quoted string
17# 3 - // comment
18# 4 - /* comment
19# 5 - asterisk found within a /* comment
20# 6 - #include line
21# 7 - backslash in a string
22# 8 - backslash in plain code
23# 9 - single quote in plain code
24#
25## Flags
26#
27# 1 - include preprocessor line, ignore strings
29sub scanline {
30 my ($col, $state, $flags, $l) = @_;
31 my $line;
33 if($state == 3) {
34 # // ended on the prev line, go back to init
35 $state = 0;
36 }
38 if(($state == 0) && ($l =~ /^ *\# *include/)) {
39 # preprocessor include line
40 $flags |= 1;
41 }
42 else {
43 # not preprocessor
44 $flags &= ~1;
45 }
47 my @c = split(//, $l);
49 # state machine this line
50 for my $c (@c) {
51 if($state == 1) {
52 # we had a slash
53 if($c eq "/") {
54 # // confirmed, the rest of the line is a comment
55 $line .= "//";
56 $state = 3;
57 }
58 elsif($c eq "*") {
59 # /* confirmed
60 $state = 4;
61 $line .= "/*";
62 }
63 else {
64 # back to normal
65 $line .= " ";
66 $state = 0;
67 }
68 }
69 elsif($state == 2) {
70 # a string
71 if($c eq "\\") {
72 $line .= "\\";
73 $state = 7;
74 }
75 elsif($c eq "\"") {
76 # end of the string
77 $line .= "\"";
78 $state = 0;
79 }
80 else {
81 $line .= $c;
82 }
83 }
84 elsif($state == 3) {
85 # a // comment
86 $line .= $c;
87 }
88 elsif($state == 4) {
89 # an ongoing /* comment
90 if($c eq "*") {
91 # could a comment close
92 $state = 5;
93 }
94 else {
95 $line .= $c;
96 }
97 }
98 elsif($state == 5) {
99 if($c eq "/") {
100 # a /* */ comment ended here */
101 $line .= "*/";
102 $state = 0;
103 }
104 else {
105 # the /* comment continues
106 $line .= "*$c";
107 $state = 4;
108 }
109 }
110 elsif($state == 7) {
111 # the prev was a backslash in a string
112 $line .= $c;
113 # switch back to normal string
114 $state = 2;
115 }
116 elsif($state == 8) {
117 # the prev was a backslash in code
118 if($c eq "\n") {
119 $line .= $c;
120 }
121 else {
122 #$line .= " ";
123 }
124 # switch back to plain code
125 $state = 0;
126 }
127 elsif($state == 9) {
128 # the prev was a single quote in code
129 if($c eq "\n") {
130 $line .= $c;
131 # switch back to plain code
132 $state = 0;
133 }
134 elsif($c eq "\\") {
135 # a backslash followed the quote
136 $line .= " ";
137 $state = 8;
138 }
139 else {
140 # switch back to plain code
141 $state = 0;
142 }
143 }
144 else {
145 if($c eq "\\") {
146 # got a backslash
147 $line .= " ";
148 $state = 8
149 }
150 elsif($c eq "\'") {
151 # got a single quote
152 $line .= " ";
153 $state = 9
154 }
155 if($c eq "/") {
156 $state = 1; # got a slash
157 }
158 elsif(($c eq "\"") && !($flags & 1)) {
159 # start of a string, not within a preprocessor line
160 $line .= "\"";
161 $state = 2;
162 }
163 elsif($c eq "\n") {
164 $line .= "\n";
165 }
166 else {
167 $line .= " ";
168 }
169 }
170 }
171 # strip trailing space
172 $line =~ s/( +)\n/\n/;
173 return $state, $flags, $line;
174}
176sub strip {
177 my ($f) = @_;
178 my $state = 0;
179 my $flags = 0;
180 open(F, "<$f") || die "can't open $f";
181 while(<F>) {
182 my $l = $_;
183 ($state, $flags, $line) = scanline(0, $state, $flags, $l);
184 print "$line";
185 }
186 close(F);
187}
189for my $f (@ARGV) {
190 strip($f);
191}
Diagnostics4 git calls · 229 ms
CallStatusSizeTime0229 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=2 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=223 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 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
fetch2001.3 KiB223 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1282 git.response.cache=MISS git.response.duration_ms=223 git.fetch.wants=f8c30cf0f9745b0bc5384969c4b7e5430f4ec556 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=1282 git.pkt.payload.max=1261 git.sideband.band1.bytes=1260 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
- a5e1257c2b107fd8
- Request
- f02bda04…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format