Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ Pek (pek)
Perl (ack, al, cpanfile, makefile.pl, perl, ph, plh, plx, pm, psgi, rexfile, pl, p6)
Pest (pest)
PHP (aw, ctp, phakefile, php, php3, php4, php5, php_cs, php_cs.dist, phps, phpt, phtml)
PHP/Pascal/Fortran/Pawn/BitBake (inc)
PHP/Pascal/Fortran/Pawn/BitBake/Assembly (inc)
Pig Latin (pig)
Pkl (pkl)
PL/I (pl1)
Expand Down Expand Up @@ -1452,7 +1452,7 @@ These file extensions map to multiple languages:
* `fnc` files could be Oracle PL or SQL
* `for` files could be Fortran 77 or Forth
* `fs` files could be F# or Forth
* `inc` files could be PHP, Pascal or BitBake
* `inc` files could be PHP, Pascal, Fortran, Pawn, BitBake or Assembly
* `itk` files could be Tcl or Tk
* `jl` files could be Lisp or Julia
* `lit` files could be PL or M
Expand Down
1 change: 1 addition & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ my @Tests = (
'../tests/inputs/hanoi.inc ' .
'../tests/inputs/pascal.inc ' .
'../tests/inputs/test1.inc ' .
'../tests/inputs/assembly.inc ' .
'../tests/inputs/Pascal.p ' .
'../tests/inputs/queue.p ',
},
Expand Down
51 changes: 33 additions & 18 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ my %Extension_Collision = (
'Pascal/Pawn' => [ 'p' ] ,
'Pascal/Puppet' => [ 'pp' ] ,
'Perl/Prolog' => [ 'pl', 'PL' ] ,
'PHP/Pascal/Fortran/Pawn/BitBake' => [ 'inc' ] ,
'PHP/Pascal/Fortran/Pawn/BitBake/Assembly' => [ 'inc' ] ,
'Raku/Prolog' => [ 'p6', 'P6' ] ,
'XML-Qt-GTK/Glade' => [ 'ui' ] ,
'TypeScript/Qt Linguist' => [ 'ts' ] ,
Expand Down Expand Up @@ -6866,17 +6866,17 @@ sub classify_file { # {{{1
'failure in matlab_or_objective_C($full_file)';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'PHP/Pascal/Fortran/Pawn/BitBake') {
my $lang_F_or_P_or_P_or_B = "";
php_pascal_fortran_pawn_bitbake($full_file ,
} elsif ($Language_by_Extension{$extension} eq 'PHP/Pascal/Fortran/Pawn/BitBake/Assembly') {
my $lang_F_or_P_or_P_or_B_or_A = "";
php_pascal_fortran_pawn_bitbake_assembly($full_file ,
$rh_Err ,
$raa_errors,
\$lang_F_or_P_or_P_or_B);
if ($lang_F_or_P_or_P_or_B) {
return $lang_F_or_P_or_P_or_B;
} else { # an error happened in php_pascal_fortran_pawn_bitbake()
\$lang_F_or_P_or_P_or_B_or_A);
if ($lang_F_or_P_or_P_or_B_or_A) {
return $lang_F_or_P_or_P_or_B_or_A;
} else { # an error happened in php_pascal_fortran_pawn_bitbake_assembly()
$rh_ignored->{$full_file} =
'failure in php_pascal_fortran_pawn_bitbake($full_file)';
'failure in php_pascal_fortran_pawn_bitbake_assembly($full_file)';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Puppet') {
Expand Down Expand Up @@ -9184,7 +9184,7 @@ sub set_constants { # {{{1
'ig' => 'Modula3' ,
'il' => 'SKILL/.NET IL' ,
'ils' => 'SKILL++' ,
'inc' => 'PHP/Pascal/Fortran/Pawn/BitBake' ,
'inc' => 'PHP/Pascal/Fortran/Pawn/BitBake/Assembly' ,
'ino' => 'Arduino Sketch' ,
'ipf' => 'Igor Pro' ,
#'pde' => 'Arduino Sketch' , # pre 1.0
Expand Down Expand Up @@ -10963,7 +10963,7 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'PHP/Pascal/Fortran/Pawn/BitBake' => [ [ 'die' , ], ], # never called
'PHP/Pascal/Fortran/Pawn/BitBake/Assembly' => [ [ 'die' , ], ], # never called
'Mako' => [
[ 'remove_matches' , '##.*$' ],
],
Expand Down Expand Up @@ -12479,7 +12479,7 @@ sub set_constants { # {{{1
'Fortran 77/Forth' => 1.00,
'Lisp/Julia' => 1.00,
'Lisp/OpenCL' => 1.00,
'PHP/Pascal/Fortran/Pawn/Bitbake' => 1.00,
'PHP/Pascal/Fortran/Pawn/Bitbake/Assembly' => 1.00,
'Pascal/Puppet' => 1.00,
'Perl/Prolog' => 1.00,
'Raku/Prolog' => 1.00,
Expand Down Expand Up @@ -12753,8 +12753,8 @@ printf "END LOOP obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $obje
if $opt_v > 2;

} # 1}}}
sub php_pascal_fortran_pawn_bitbake { # {{{1
# Decide if code is Fortran, PHP, Pascal, Pawn
sub php_pascal_fortran_pawn_bitbake_assembly { # {{{1
# Decide if code is Fortran, PHP, Pascal, Pawn, Assembly
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
Expand Down Expand Up @@ -12788,6 +12788,10 @@ sub php_pascal_fortran_pawn_bitbake { # {{{1
# some lines start with include, require, inherit statements
# contains .=, =., ?=, ??= operators
# contains :... = assignments
#
# Assembly:
# lines may start with: org/.org, section/.section, segment, %include/.include/include, macro/.macro/%macro/.endm/%endmacro (some nasm/fasm/gas/masm directives)
# lines may start with: mov, push, pop, add, jmp, call, ret (common assembly instructions)

${$rs_language} = "";
my $IN = open_file('<', $file, 1);
Expand All @@ -12804,6 +12808,7 @@ sub php_pascal_fortran_pawn_bitbake { # {{{1
my $pascal_points = 0;
my $pawn_points = 0;
my $bitbake_points = 0;
my $assembly_points = 0;
while (<$IN>) {
if (/^\s*<\?php/i) {
$php_points += 100;
Expand Down Expand Up @@ -12836,7 +12841,13 @@ sub php_pascal_fortran_pawn_bitbake { # {{{1
} elsif (/^\@/ or /^\s*(Float:|bool:)/) {
$pawn_points += 1e+20;
last;
}
} elsif (/^\s*(\%include|\.include|include)\b/i or
/^\s*(segment|section|\.section)\b/i or
/^\s*(macro|\.macro|\%macro|\%endmacro|\.endm)\b/i or
/^\s*(\.org|org)\b/i) {
$assembly_points += 100;
last;
}
if (/^\s*(integer|real|complex|double|character|logical|public|private).*?::/i or
/^\s*(allocatable|dimension)/i or
/^\s*(end\s+)?(interface|type|function|module)\b/i) {
Expand All @@ -12853,14 +12864,18 @@ sub php_pascal_fortran_pawn_bitbake { # {{{1
if (/^[A-Z0-9_:-]+:[A-Za-z0-9_-]+\s*=/) {
++$bitbake_points;
}
if (/^\s*(mov|push|pop|add|jmp|call|ret)\b/i) {
++$assembly_points;
}
}
$IN->close;

my %points = ( 'Fortran' => $fortran_points ,
'PHP' => $php_points ,
'Pascal' => $pascal_points ,
'Pawn' => $pawn_points ,
'BitBake' => $bitbake_points , );
'BitBake' => $bitbake_points ,
'Assembly' => $assembly_points , );

${$rs_language} = (sort { $points{$b} <=> $points{$a} or $a cmp $b } keys %points)[0];
if (${$rs_language} eq 'Fortran') {
Expand All @@ -12871,8 +12886,8 @@ sub php_pascal_fortran_pawn_bitbake { # {{{1
}
}

print "<- php_pascal_fortran_pawn_bitbake($file: fortran=$fortran_points, php=$php_points, ",
"pascal=$pascal_points, pawn=$pawn_points, bitbake=$bitbake_points) => ${$rs_language}\n"
print "<- php_pascal_fortran_pawn_bitbake_assembly($file: fortran=$fortran_points, php=$php_points, ",
"pascal=$pascal_points, pawn=$pawn_points, bitbake=$bitbake_points, assembly=$assembly_points) => ${$rs_language}\n"
if $opt_v > 2;

} # 1}}}
Expand Down
22 changes: 22 additions & 0 deletions tests/inputs/assembly.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; simple Flat Assembler macros

SYS_EXIT = 60
SYS_WRITE = 1

EXIT_CODE = 255

SYS_STDOUT = 1

macro PRINT str_address, len {
mov rax, SYS_WRITE
mov rdi, SYS_STDOUT
mov rsi, str_address
mov rdx, len
syscall
}

macro EXIT {
mov rax, SYS_EXIT
mov rdi, EXIT_CODE
syscall
}
27 changes: 16 additions & 11 deletions tests/outputs/pawn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 2.01
elapsed_seconds : 0.00428891181945801
n_files : 6
n_lines : 165
files_per_second : 1398.9562510423
lines_per_second : 38471.2969036634
report_file : ../outputs/pawn.yaml
cloc_version : 2.11
elapsed_seconds : 0.00733709335327148
n_files : 7
n_lines : 187
files_per_second : 954.056281276402
lines_per_second : 25486.9320855267
report_file : tests/outputs/pawn.yaml
'Pawn' :
nFiles: 2
blank: 16
Expand All @@ -19,6 +19,11 @@ header :
blank: 4
comment: 4
code: 20
'Assembly' :
nFiles: 1
blank: 5
comment: 1
code: 16
'Pascal' :
nFiles: 2
blank: 2
Expand All @@ -30,7 +35,7 @@ header :
comment: 7
code: 11
SUM:
blank: 27
comment: 29
code: 109
nFiles: 6
blank: 32
comment: 30
code: 125
nFiles: 7