2
0

cleancmd.pl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/perl
  2. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  3. #
  4. # SPDX-License-Identifier: curl
  5. #
  6. # Input: a cmdline docs markdown, it gets modfied *in place*
  7. #
  8. # The main purpose is to strip off the leading meta-data part, but also to
  9. # clean up whatever else the spell checker might have a problem with that we
  10. # still deem is fine.
  11. my $header = 1;
  12. while(1) {
  13. # set this if the markdown has no meta-data header to skip
  14. if($ARGV[0] eq "--no-header") {
  15. shift @ARGV;
  16. $header = 0;
  17. }
  18. else {
  19. last;
  20. }
  21. }
  22. my $f = $ARGV[0];
  23. open(F, "<$f") or die;
  24. my $ignore = $header;
  25. my $sepcount = 0;
  26. my @out;
  27. while(<F>) {
  28. if(/^---/ && $header) {
  29. if(++$sepcount == 2) {
  30. $ignore = 0;
  31. }
  32. next;
  33. }
  34. next if($ignore);
  35. # strip out all long command line options
  36. $_ =~ s/--[a-z0-9-]+//g;
  37. # strip out https URLs, we don't want them spellchecked
  38. $_ =~ s!https://[a-z0-9\#_/.-]+!!gi;
  39. push @out, $_;
  40. }
  41. close(F);
  42. if(!$ignore) {
  43. open(O, ">$f") or die;
  44. print O @out;
  45. close(O);
  46. }