4 # Unix SMB/CIFS implementation.
6 # Utility methods for generating error codes from a file.
8 # Copyright (C) Noel Power <noel.power@suse.com> 2014
9 # Copyright (C) Catalyst IT Ltd. 2017
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 self
.err_define
= None
31 self
.isWinError
= False
34 def escapeString( input ):
35 output
= input.replace('"','\\"')
36 output
= output
.replace("\\<","\\\\<")
37 output
= output
.replace('\t',"")
40 # Parse error descriptions from a file which is the content
42 # The file must be formatted as:
46 # Blank lines are allowed and errors do not have to have a
48 # Returns a list of ErrorDef objects.
49 def parseErrorDescriptions( file_contents
, isWinError
, transformErrorFunction
):
52 for line
in file_contents
:
53 if line
is None or line
== '\t' or line
== "" or line
== '\n':
55 content
= line
.strip().split(None,1)
56 # start new error definition ?
59 if line
.startswith("0x"):
61 newError
.err_code
= int(content
[0],0)
62 # escape the usual suspects
64 newError
.err_string
= escapeString(content
[1])
65 newError
.linenum
= count
66 newError
.isWinError
= isWinError
67 errors
.append(newError
)
72 if err
.err_define
is None:
73 err
.err_define
= transformErrorFunction(content
[0])
76 desc
= escapeString(line
.strip())
78 if err
.err_string
== "":
81 err
.err_string
= err
.err_string
+ " " + desc
83 print("parsed %d lines generated %d error definitions"%(count
,len(errors
)))