File: check_pseudoMD.pl

package info (click to toggle)
plm 2.6+repack-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 15,000 kB
  • ctags: 6,149
  • sloc: java: 34,456; ansic: 4,070; python: 2,576; xml: 191; perl: 150; makefile: 42; sh: 16
file content (42 lines) | stat: -rwxr-xr-x 1,059 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/perl

use strict;

my @langs = qw,python java scala c,;

my $errorCount = 0;

sub error($) {
    print $_[0];
    $errorCount++;
}

print "Checking for errors about language pseudo-markup ([!python] etc)\n";

foreach my $file (qx(find src -name '*html')) {
    chomp $file;
    
    open my $fh, '<', $file or die "unable to open file '$file' for reading : $!";
    my @arr = <$fh>;
    close $fh;  # close as soon as possible
    
    for my $line (@arr) {
	for my $lang1 (@langs) {
	    error "$file: [$lang1] instead of [!$lang1].\n  $line\n"
	      if ($line =~ /\[$lang1\]/);
	    for my $lang2 (@langs) {
		error "$file: [$lang1|$lang2] instead of [!$lang1|$lang2].\n  $line\n"
		  if ($line =~ /\[$lang1\|$lang2\]/);
		for my $lang3 (@langs) {
		    error "$file: [$lang1|$lang2|$lang3] instead of [!$lang1|$lang2|$lang3].\n  $line\n"
		      if ($line =~ /\[$lang1\|$lang2\|$lang3\]/);
		}
	    }
	}
	error "$file: [!/] instead of [/!].\n  $line" 
	  if ($line =~ m|\[!/\]|);
    }
}

print "$errorCount errors found.\n";
exit $errorCount;