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
33 def escapeString( input ):
34 output
= input.replace('"','\\"')
35 output
= output
.replace("\\<","\\\\<")
36 output
= output
.replace('\t',"")
39 # Parse error descriptions from a file which is the content
41 # The file must be formatted as:
45 # Blank lines are allowed and errors do not have to have a
47 # Returns a list of ErrorDef objects.
48 def parseErrorDescriptions( file_contents
, isWinError
, transformErrorFunction
):
51 for line
in file_contents
:
52 if line
== None or line
== '\t' or line
== "" or line
== '\n':
54 content
= line
.strip().split(None,1)
55 # start new error definition ?
56 if line
.startswith("0x"):
58 newError
.err_code
= int(content
[0],0)
59 # escape the usual suspects
61 newError
.err_string
= escapeString(content
[1])
62 newError
.linenum
= count
63 newError
.isWinError
= isWinError
64 errors
.append(newError
)
69 if err
.err_define
== None:
70 err
.err_define
= transformErrorFunction(content
[0])
73 desc
= escapeString(line
.strip())
75 if err
.err_string
== "":
78 err
.err_string
= err
.err_string
+ " " + desc
80 print("parsed %d lines generated %d error definitions"%(count
,len(errors
)))