1# Remove almost all of the $ FreeBSD $ tags in the tree. 2# 3# Copyright (c) 2023, Warner Losh 4# SPDX-License-Identifier: BSD-2-Clause 5# 6# Needs p5-File-Lib package 7# Caveat Emptor 8# 9use strict; 10use warnings; 11use File::Find; 12 13sub skip_list 14{ 15 my $fn = $_[0]; 16 17 if ($fn =~ m=^./contrib/=) { 18 return 1; 19 } 20 if ($fn =~ m=^./sys/contrib/=) { 21 return 1; 22 } 23 if ($fn =~ m=^./cddl/contrib/=) { 24 return 1; 25 } 26 if ($fn =~ m=^./crypto/=) { 27 return 1; 28 } 29 if ($fn =~ m=^./.git/=) { 30 return 1; 31 } 32 if ($fn =~ m=~$=) { 33 return 1; 34 } 35 return 0; 36} 37 38my $pretty; 39my $pattern; 40my $repl; 41my $count; 42 43sub do_one 44{ 45 $pretty = $_[0]; 46 $pattern = $_[1]; 47 $repl = ""; 48 $repl = $_[2] if defined($_[2]); 49 $count = 0; 50 51 sub findfiles 52 { 53 return unless -f; 54 my $fn="$File::Find::name"; 55 return if skip_list($fn); 56 open my $fh, '<', $_ or die "Can't open $fn: $!\n"; 57 local $/; 58 my $file = <$fh>; 59 close $fh; 60 my $len = length($file); 61 62 $file =~ s=$pattern=$repl=gm; 63 my $len2 = length($file); 64 return if $len2 == $len; 65 print "$pretty: $fn\n"; 66 open my $fhw, '>', $_ or die "Can't write $fn: $!\n"; 67 print $fhw $file; 68 close $fhw; 69 $count++; 70 } 71 72 $count = 0; 73 find({ wanted => \&findfiles, }, './sys'); 74 if ($count > 0) { 75 print "Changed $pretty\n"; 76 system("git commit -a -m'sys: Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/'"); 77 } 78 $count = 0; 79 find({ wanted => \&findfiles, }, '.'); 80 if ($count > 0) { 81 print "Changed $pretty\n"; 82 system("git commit -a -m'Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/'"); 83 } 84} 85 86# Note: Do two line before one line 87do_one("sound driver version", 'SND_DECLARE_FILE\("\$FreeBSD\$"\);', 'SND_DECLARE_FILE("");'); 88do_one("one-line m4 tag", '^dnl\s*\$FreeBSD\$.*$\n'); 89do_one("two-line .h pattern", '^\s*\*\n \*\s+\$FreeBSD\$$\n'); 90do_one("one-line .h pattern", '^\s*\*+\s*\$FreeBSD\$.*$\n'); 91do_one("one-line .c comment pattern", '^/[*/]\s*\$FreeBSD\$.*\n'); 92do_one("two-line .c pattern", '^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n'); 93do_one("one-line .c pattern", '^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n'); 94do_one("alt two-line .c pattern", '^\s*__RCSID\("\$FreeBSD\$"\);\n\n'); 95do_one("alt one-line .c pattern", '^\s*__RCSID\("\$FreeBSD\$"\);\n'); 96do_one("one-line .S pattern", '^\s\.(asciz|ident)\s+\"\$FreeBSD\$\".*\n'); 97do_one("one-line sh pattern", '^\s*#[#!]?\s*\$FreeBSD\$.*$\n'); 98do_one("two-line nroff pattern", '^\.\\\\"\n\.\\\\"\s*\$FreeBSD\$$\n'); 99do_one("one-line nroff pattern", '^\.\\\\"\s*\$FreeBSD\$$\n'); 100do_one("one-line bare tag", '^\s*\$FreeBSD\$$\n'); 101do_one("one-line catalog", '^\s*\$\s*\$FreeBSD\$$\n'); 102do_one("two-line lua tag", '^--\n--\s*\$FreeBSD\$.*$\n'); 103do_one("one-line lua tag", '^--\s*\$FreeBSD\$.*$\n'); 104do_one("one-line ps tag", '^%\s*RCSID:\s*\$FreeBSD\$.*$\n'); 105do_one("one-line forth tag", '^\\\\[\s*]*\$FreeBSD\$.*$\n'); 106do_one("one-line xdr pattern", '^\s*%\s*__FBSDID\("\$FreeBSD\$"\);?\s*\n'); 107exit; 108