source: josm/trunk/tools/japicc/modules/Internals/Logging.pm@ 13595

Last change on this file since 13595 was 13595, checked in by Don-vip, 6 years ago

tools update: Groovy 2.4.15, PMD 6.2.0, JAPICC 2.4

File size: 2.3 KB
Line 
1###########################################################################
2# A module for logging
3#
4# Copyright (C) 2016-2018 Andrey Ponomarenko's ABI Laboratory
5#
6# Written by Andrey Ponomarenko
7#
8# This library is free software; you can redistribute it and/or
9# modify it under the terms of the GNU Lesser General Public
10# License as published by the Free Software Foundation; either
11# version 2.1 of the License, or (at your option) any later version.
12#
13# This library is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public
19# License along with this library; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21# MA 02110-1301 USA.
22###########################################################################
23use strict;
24
25my %DEBUG_DIR;
26
27my %ERROR_CODE = (
28 # Compatible verdict
29 "Compatible"=>0,
30 "Success"=>0,
31 # Incompatible verdict
32 "Incompatible"=>1,
33 # Undifferentiated error code
34 "Error"=>2,
35 # System command is not found
36 "Not_Found"=>3,
37 # Cannot access input files
38 "Access_Error"=>4,
39 # Invalid input API dump
40 "Invalid_Dump"=>7,
41 # Incompatible version of API dump
42 "Dump_Version"=>8,
43 # Cannot find a module
44 "Module_Error"=>9
45);
46
47sub exitStatus($$)
48{
49 my ($Code, $Msg) = @_;
50 print STDERR "ERROR: ". $Msg."\n";
51 if(my $Orig = $In::Opt{"OrigDir"}) {
52 chdir($Orig);
53 }
54 exit($ERROR_CODE{$Code});
55}
56
57sub getErrorCode($) {
58 return $ERROR_CODE{$_[0]};
59}
60
61sub printMsg($$)
62{
63 my ($Type, $Msg) = @_;
64 if($Type!~/\AINFO/) {
65 $Msg = $Type.": ".$Msg;
66 }
67 if($Type!~/_C\Z/) {
68 $Msg .= "\n";
69 }
70 if($Type eq "ERROR") {
71 print STDERR $Msg;
72 }
73 else {
74 print $Msg;
75 }
76}
77
78sub initLogging($)
79{
80 my $LVer = $_[0];
81 if($In::Opt{"Debug"})
82 { # debug directory
83 $DEBUG_DIR{$LVer} = "debug/".$In::Opt{"TargetLib"}."/".$In::Desc{$LVer}{"Version"};
84
85 if(-d $DEBUG_DIR{$LVer}) {
86 rmtree($DEBUG_DIR{$LVer});
87 }
88 }
89}
90
91sub getDebugDir($) {
92 return $DEBUG_DIR{$_[0]};
93}
94
95return 1;
Note: See TracBrowser for help on using the repository browser.