diff --git a/smatch_data/db/init_constraints.pl b/smatch_data/db/init_constraints.pl index e2bc8685..857934b6 100755 --- a/smatch_data/db/init_constraints.pl +++ b/smatch_data/db/init_constraints.pl @@ -50,26 +50,30 @@ ($$) return; } - open(FILE, "$dir/$project.constraints"); - while () { - s/\n//; - $db->do("insert or ignore into constraints (str) values ('$_')"); + if (open(FILE, "$dir/$project.constraints")) + { + while () { + s/\n//; + $db->do("insert or ignore into constraints (str) values ('$_')"); + } + close(FILE); } - close(FILE); - - open(FILE, "$dir/$project.constraints_required"); - while () { - my $limit; - my $dummy; - - ($dummy, $dummy, $limit) = split(/,/); - $limit =~ s/^ +//; - $limit =~ s/\n//; - try { - $db->do("insert or ignore into constraints (str) values ('$limit')"); - } catch {} + + if (open(FILE, "$dir/$project.constraints_required")) + { + while () { + my $limit; + my $dummy; + + ($dummy, $dummy, $limit) = split(/,/); + $limit =~ s/^ +//; + $limit =~ s/\n//; + try { + $db->do("insert or ignore into constraints (str) values ('$limit')"); + } catch {} + } + close(FILE); } - close(FILE); $db->commit(); } diff --git a/smatch_data/db/init_constraints_required.pl b/smatch_data/db/init_constraints_required.pl index 15ce19b2..d6d296e2 100755 --- a/smatch_data/db/init_constraints_required.pl +++ b/smatch_data/db/init_constraints_required.pl @@ -38,15 +38,17 @@ ($$) return; } - open(FILE, "$dir/$project.constraints_required"); - while () { - ($data, $op, $limit) = split(/,/); - $op =~ s/ //g; - $limit =~ s/^ +//; - $limit =~ s/\n//; - $db->do("insert into constraints_required values (?, ?, ?);", undef, $data, $op, $limit); + if(open(FILE, "$dir/$project.constraints_required")) + { + while () { + ($data, $op, $limit) = split(/,/); + $op =~ s/ //g; + $limit =~ s/^ +//; + $limit =~ s/\n//; + $db->do("insert into constraints_required values (?, ?, ?);", undef, $data, $op, $limit); + } + close(FILE); } - close(FILE); $db->commit(); } diff --git a/smatch_data/db/insert_manual_states.pl b/smatch_data/db/insert_manual_states.pl index c6682702..452fef5c 100755 --- a/smatch_data/db/insert_manual_states.pl +++ b/smatch_data/db/insert_manual_states.pl @@ -64,38 +64,40 @@ ($$$$$$$) my ($ret, $insert, $file, $func, $type, $param, $key, $value); -open(FILE, "<$insertions"); -while () { - - if ($_ =~ /^\s*#/) { - next; - } +if (open(FILE, "<$insertions")) +{ + while () { - ($ret, $insert) = split(/\|/, $_); + if ($_ =~ /^\s*#/) { + next; + } - if ($ret =~ /(.+),\W*(.+),\W*"(.*)"/) { - $file = $1; - $func = $2; - $ret = $3; - } elsif ($ret =~ /(.+),\W*"(.*)"/) { - $file = ""; - $func = $1; - $ret = $2; - } else { - next; - } + ($ret, $insert) = split(/\|/, $_); + + if ($ret =~ /(.+),\W*(.+),\W*"(.*)"/) { + $file = $1; + $func = $2; + $ret = $3; + } elsif ($ret =~ /(.+),\W*"(.*)"/) { + $file = ""; + $func = $1; + $ret = $2; + } else { + next; + } - ($type, $param, $key, $value) = split(/,/, $insert); + ($type, $param, $key, $value) = split(/,/, $insert); - $type = int($type); - $param = int($param); - $key =~ s/^["\s]+|["\s]+$//g; - $value =~ s/^["\s]+|["\s]+$//g; - chomp($value); + $type = int($type); + $param = int($param); + $key =~ s/^["\s]+|["\s]+$//g; + $value =~ s/^["\s]+|["\s]+$//g; + chomp($value); - insert_record($file, $func, $ret, $type, $param, $key, $value); + insert_record($file, $func, $ret, $type, $param, $key, $value); + } + close(FILE); } -close(FILE); $db->commit(); $db->disconnect();