Skip to content

Commit

Permalink
handle BOM in --list-file, found by chris0e3, #502
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed Aug 23, 2020
1 parent 7095c26 commit 6b6e2bc
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 30 deletions.
37 changes: 22 additions & 15 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -12115,25 +12115,32 @@ sub read_list_file { # {{{1
# reads filenames from a STDIN pipe if $file == "-"

print "-> read_list_file($file)\n" if $opt_v > 2;
my $IN;
my @entry = ();

if ($file eq "-") {
# read from a STDIN pipe
my $IN;
open($IN, $file);
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
}
$IN->close;
} else {
$IN = IO::File->new($file, 'r');
# $IN = IO::File->new($file, 'r:utf8');
}
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
my @entry = ();
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
# read from an actual file
foreach my $line (read_file($file)) {
next if $line =~ /^\s*$/ or $line =~ /^\s*#/;
$line =~ s/\cM$//; # DOS to Unix
chomp $line;
push @entry, $line;
}
}
$IN->close;

print "<- read_list_file\n" if $opt_v > 2;
return @entry;
Expand Down
7 changes: 7 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ my @Tests = (
'ref' => '../tests/outputs/issues/513/results.yaml',
},

{
'name' => '--list-file BOM #502',
'cd' => '../tests/inputs/issues/502',
'args' => '--list-file FileCounter20200715140433.txt',
'ref' => '../tests/outputs/issues/502/results.yaml',
},

);

# Create test input for issue #132 which needs data not in the git repo.
Expand Down
37 changes: 22 additions & 15 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -13782,25 +13782,32 @@ sub read_list_file { # {{{1
# reads filenames from a STDIN pipe if $file == "-"

print "-> read_list_file($file)\n" if $opt_v > 2;
my $IN;
my @entry = ();

if ($file eq "-") {
# read from a STDIN pipe
my $IN;
open($IN, $file);
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
}
$IN->close;
} else {
$IN = IO::File->new($file, 'r');
# $IN = IO::File->new($file, 'r:utf8');
}
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
my @entry = ();
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
# read from an actual file
foreach my $line (read_file($file)) {
next if $line =~ /^\s*$/ or $line =~ /^\s*#/;
$line =~ s/\cM$//; # DOS to Unix
chomp $line;
push @entry, $line;
}
}
$IN->close;

print "<- read_list_file\n" if $opt_v > 2;
return @entry;
Expand Down
1 change: 1 addition & 0 deletions tests/inputs/issues/502/FileCounter20200715140433.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Điếm LOC/P_EDI_Book.sql
83 changes: 83 additions & 0 deletions tests/inputs/issues/502/Điếm LOC/P_EDI_Book.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
USE
GO
/****** Object: StoredProcedure [dbo].[P_EDI_Book] Script Date: 2020/05/22 11:41:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--=================================================

---------------------------------------------------
--
---------------------------------------------------

-- <下り>
--
,@ext_day int = -5 --2017-02-28 更新
-- ,@ext_day int = -1 --2016-08-17 更新
,@ext_time datetime = '00:00:00'

AS
--=================================================
-- 開始
--=================================================
SP_MAIN:
SET NOCOUNT ON

--=============================================
-- なんとなく共通処理
--=============================================

-- 必要なローカル変数定義
Declare @tran_ct int -- トランザクションカウント

Declare @FETCH_STATUS int -- @@FETCH_STATUSワーク

--=================================================
-- パラメタチェック
--=================================================

Declare @a_tax_rate_type char(1) -- 税端数処理区分
-- ▼▼▼ 2013/11/21 add
Declare @a_tonets_v_up_flag char(1) -- トーハンTONET=V上り実装フラグ
Declare @a_tonets_v_dw_flag char(1) -- トーハンTONET=V下り実装フラグ
-- ▲▲▲ 2013/11/21 add

--=================================================
-- 共通処理
--=================================================

-- 下り用処理カウンタ
Declare @count_all int -- 処理対象


-- サーバ名・データベース名セット
Declare @server_name varchar(100)

End

-- ▼▼▼ 2013/11/21 add
-- 上り在庫変動処理(TONETS-V:T1)
If @edi_type = '56U' Begin

End
-- ▲▲▲ 2013/11/21 add

-- 【上り未登録商品マスタ(エコール)】上り未登録商品マスタのクライアント処理 -- 2014/01/20 add
If @edi_type = '60U' Begin

-- ▼▼▼ 2014/01/28 add
-- 【JEUGIA基幹連動】上り売上処理
If @edi_type = '62U' Begin

-- ▲▲▲ 2014/01/28 add

--

--=================================================
-- SP終了
--=================================================


21 changes: 21 additions & 0 deletions tests/outputs/issues/502/results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.87
elapsed_seconds : 0.00855422019958496
n_files : 1
n_lines : 83
files_per_second : 116.90136291424
lines_per_second : 9702.81312188188
report_file : ../../../outputs/issues/502/results.yaml
'SQL' :
nFiles: 1
blank: 24
comment: 36
code: 23
SUM:
blank: 24
comment: 36
code: 23
nFiles: 1

0 comments on commit 6b6e2bc

Please sign in to comment.