Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../bin
File: event_rpcgen.py
#! /usr/libexec/platform-python
[0] Fix | Delete
#
[1] Fix | Delete
# Copyright (c) 2005-2007 Niels Provos <provos@citi.umich.edu>
[2] Fix | Delete
# Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
[3] Fix | Delete
# All rights reserved.
[4] Fix | Delete
#
[5] Fix | Delete
# Generates marshaling code based on libevent.
[6] Fix | Delete
[7] Fix | Delete
# TODO:
[8] Fix | Delete
# 1) use optparse to allow the strategy shell to parse options, and
[9] Fix | Delete
# to allow the instantiated factory (for the specific output language)
[10] Fix | Delete
# to parse remaining options
[11] Fix | Delete
# 2) move the globals into a class that manages execution (including the
[12] Fix | Delete
# progress outputs that space stderr at the moment)
[13] Fix | Delete
# 3) emit other languages
[14] Fix | Delete
[15] Fix | Delete
import sys
[16] Fix | Delete
import re
[17] Fix | Delete
[18] Fix | Delete
_NAME = "event_rpcgen.py"
[19] Fix | Delete
_VERSION = "0.1"
[20] Fix | Delete
[21] Fix | Delete
# Globals
[22] Fix | Delete
line_count = 0
[23] Fix | Delete
[24] Fix | Delete
white = re.compile(r'\s+')
[25] Fix | Delete
cppcomment = re.compile(r'\/\/.*$')
[26] Fix | Delete
nonident = re.compile(r'[^a-zA-Z0-9_]')
[27] Fix | Delete
structref = re.compile(r'^struct\[([a-zA-Z_][a-zA-Z0-9_]*)\]$')
[28] Fix | Delete
structdef = re.compile(r'^struct +[a-zA-Z_][a-zA-Z0-9_]* *{$')
[29] Fix | Delete
[30] Fix | Delete
headerdirect = []
[31] Fix | Delete
cppdirect = []
[32] Fix | Delete
[33] Fix | Delete
QUIETLY = 0
[34] Fix | Delete
[35] Fix | Delete
def declare(s):
[36] Fix | Delete
if not QUIETLY:
[37] Fix | Delete
print(s)
[38] Fix | Delete
[39] Fix | Delete
def TranslateList(mylist, mydict):
[40] Fix | Delete
return [x % mydict for x in mylist]
[41] Fix | Delete
[42] Fix | Delete
# Exception class for parse errors
[43] Fix | Delete
class RpcGenError(Exception):
[44] Fix | Delete
def __init__(self, why):
[45] Fix | Delete
self.why = why
[46] Fix | Delete
def __str__(self):
[47] Fix | Delete
return str(self.why)
[48] Fix | Delete
[49] Fix | Delete
# Holds everything that makes a struct
[50] Fix | Delete
class Struct:
[51] Fix | Delete
def __init__(self, name):
[52] Fix | Delete
self._name = name
[53] Fix | Delete
self._entries = []
[54] Fix | Delete
self._tags = {}
[55] Fix | Delete
declare(' Created struct: %s' % name)
[56] Fix | Delete
[57] Fix | Delete
def AddEntry(self, entry):
[58] Fix | Delete
if entry.Tag() in self._tags:
[59] Fix | Delete
raise RpcGenError(
[60] Fix | Delete
'Entry "%s" duplicates tag number %d from "%s" '
[61] Fix | Delete
'around line %d' % (entry.Name(), entry.Tag(),
[62] Fix | Delete
self._tags[entry.Tag()], line_count))
[63] Fix | Delete
self._entries.append(entry)
[64] Fix | Delete
self._tags[entry.Tag()] = entry.Name()
[65] Fix | Delete
declare(' Added entry: %s' % entry.Name())
[66] Fix | Delete
[67] Fix | Delete
def Name(self):
[68] Fix | Delete
return self._name
[69] Fix | Delete
[70] Fix | Delete
def EntryTagName(self, entry):
[71] Fix | Delete
"""Creates the name inside an enumeration for distinguishing data
[72] Fix | Delete
types."""
[73] Fix | Delete
name = "%s_%s" % (self._name, entry.Name())
[74] Fix | Delete
return name.upper()
[75] Fix | Delete
[76] Fix | Delete
def PrintIndented(self, file, ident, code):
[77] Fix | Delete
"""Takes an array, add indentation to each entry and prints it."""
[78] Fix | Delete
for entry in code:
[79] Fix | Delete
file.write('%s%s\n' % (ident, entry))
[80] Fix | Delete
[81] Fix | Delete
class StructCCode(Struct):
[82] Fix | Delete
""" Knows how to generate C code for a struct """
[83] Fix | Delete
[84] Fix | Delete
def __init__(self, name):
[85] Fix | Delete
Struct.__init__(self, name)
[86] Fix | Delete
[87] Fix | Delete
def PrintTags(self, file):
[88] Fix | Delete
"""Prints the tag definitions for a structure."""
[89] Fix | Delete
file.write('/* Tag definition for %s */\n' % self._name)
[90] Fix | Delete
file.write('enum %s_ {\n' % self._name.lower())
[91] Fix | Delete
for entry in self._entries:
[92] Fix | Delete
file.write(' %s=%d,\n' % (self.EntryTagName(entry), entry.Tag()))
[93] Fix | Delete
file.write(' %s_MAX_TAGS\n' % (self._name.upper()))
[94] Fix | Delete
file.write('};\n\n')
[95] Fix | Delete
[96] Fix | Delete
def PrintForwardDeclaration(self, file):
[97] Fix | Delete
file.write('struct %s;\n' % self._name)
[98] Fix | Delete
[99] Fix | Delete
def PrintDeclaration(self, file):
[100] Fix | Delete
file.write('/* Structure declaration for %s */\n' % self._name)
[101] Fix | Delete
file.write('struct %s_access_ {\n' % self._name)
[102] Fix | Delete
for entry in self._entries:
[103] Fix | Delete
dcl = entry.AssignDeclaration('(*%s_assign)' % entry.Name())
[104] Fix | Delete
dcl.extend(
[105] Fix | Delete
entry.GetDeclaration('(*%s_get)' % entry.Name()))
[106] Fix | Delete
if entry.Array():
[107] Fix | Delete
dcl.extend(
[108] Fix | Delete
entry.AddDeclaration('(*%s_add)' % entry.Name()))
[109] Fix | Delete
self.PrintIndented(file, ' ', dcl)
[110] Fix | Delete
file.write('};\n\n')
[111] Fix | Delete
[112] Fix | Delete
file.write('struct %s {\n' % self._name)
[113] Fix | Delete
file.write(' struct %s_access_ *base;\n\n' % self._name)
[114] Fix | Delete
for entry in self._entries:
[115] Fix | Delete
dcl = entry.Declaration()
[116] Fix | Delete
self.PrintIndented(file, ' ', dcl)
[117] Fix | Delete
file.write('\n')
[118] Fix | Delete
for entry in self._entries:
[119] Fix | Delete
file.write(' ev_uint8_t %s_set;\n' % entry.Name())
[120] Fix | Delete
file.write('};\n\n')
[121] Fix | Delete
[122] Fix | Delete
file.write("""struct %(name)s *%(name)s_new(void);
[123] Fix | Delete
struct %(name)s *%(name)s_new_with_arg(void *);
[124] Fix | Delete
void %(name)s_free(struct %(name)s *);
[125] Fix | Delete
void %(name)s_clear(struct %(name)s *);
[126] Fix | Delete
void %(name)s_marshal(struct evbuffer *, const struct %(name)s *);
[127] Fix | Delete
int %(name)s_unmarshal(struct %(name)s *, struct evbuffer *);
[128] Fix | Delete
int %(name)s_complete(struct %(name)s *);
[129] Fix | Delete
void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
[130] Fix | Delete
const struct %(name)s *);
[131] Fix | Delete
int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
[132] Fix | Delete
struct %(name)s *);\n""" % { 'name' : self._name })
[133] Fix | Delete
[134] Fix | Delete
[135] Fix | Delete
# Write a setting function of every variable
[136] Fix | Delete
for entry in self._entries:
[137] Fix | Delete
self.PrintIndented(file, '', entry.AssignDeclaration(
[138] Fix | Delete
entry.AssignFuncName()))
[139] Fix | Delete
self.PrintIndented(file, '', entry.GetDeclaration(
[140] Fix | Delete
entry.GetFuncName()))
[141] Fix | Delete
if entry.Array():
[142] Fix | Delete
self.PrintIndented(file, '', entry.AddDeclaration(
[143] Fix | Delete
entry.AddFuncName()))
[144] Fix | Delete
[145] Fix | Delete
file.write('/* --- %s done --- */\n\n' % self._name)
[146] Fix | Delete
[147] Fix | Delete
def PrintCode(self, file):
[148] Fix | Delete
file.write(('/*\n'
[149] Fix | Delete
' * Implementation of %s\n'
[150] Fix | Delete
' */\n\n') % self._name)
[151] Fix | Delete
[152] Fix | Delete
file.write('static struct %(name)s_access_ %(name)s_base__ = {\n' % \
[153] Fix | Delete
{ 'name' : self._name })
[154] Fix | Delete
for entry in self._entries:
[155] Fix | Delete
self.PrintIndented(file, ' ', entry.CodeBase())
[156] Fix | Delete
file.write('};\n\n')
[157] Fix | Delete
[158] Fix | Delete
# Creation
[159] Fix | Delete
file.write((
[160] Fix | Delete
'struct %(name)s *\n'
[161] Fix | Delete
'%(name)s_new(void)\n'
[162] Fix | Delete
'{\n'
[163] Fix | Delete
' return %(name)s_new_with_arg(NULL);\n'
[164] Fix | Delete
'}\n'
[165] Fix | Delete
'\n'
[166] Fix | Delete
'struct %(name)s *\n'
[167] Fix | Delete
'%(name)s_new_with_arg(void *unused)\n'
[168] Fix | Delete
'{\n'
[169] Fix | Delete
' struct %(name)s *tmp;\n'
[170] Fix | Delete
' if ((tmp = malloc(sizeof(struct %(name)s))) == NULL) {\n'
[171] Fix | Delete
' event_warn("%%s: malloc", __func__);\n'
[172] Fix | Delete
' return (NULL);\n'
[173] Fix | Delete
' }\n'
[174] Fix | Delete
' tmp->base = &%(name)s_base__;\n\n') % { 'name' : self._name })
[175] Fix | Delete
[176] Fix | Delete
for entry in self._entries:
[177] Fix | Delete
self.PrintIndented(file, ' ', entry.CodeInitialize('tmp'))
[178] Fix | Delete
file.write(' tmp->%s_set = 0;\n\n' % entry.Name())
[179] Fix | Delete
[180] Fix | Delete
file.write((
[181] Fix | Delete
' return (tmp);\n'
[182] Fix | Delete
'}\n\n'))
[183] Fix | Delete
[184] Fix | Delete
# Adding
[185] Fix | Delete
for entry in self._entries:
[186] Fix | Delete
if entry.Array():
[187] Fix | Delete
self.PrintIndented(file, '', entry.CodeAdd())
[188] Fix | Delete
file.write('\n')
[189] Fix | Delete
[190] Fix | Delete
# Assigning
[191] Fix | Delete
for entry in self._entries:
[192] Fix | Delete
self.PrintIndented(file, '', entry.CodeAssign())
[193] Fix | Delete
file.write('\n')
[194] Fix | Delete
[195] Fix | Delete
# Getting
[196] Fix | Delete
for entry in self._entries:
[197] Fix | Delete
self.PrintIndented(file, '', entry.CodeGet())
[198] Fix | Delete
file.write('\n')
[199] Fix | Delete
[200] Fix | Delete
# Clearing
[201] Fix | Delete
file.write(( 'void\n'
[202] Fix | Delete
'%(name)s_clear(struct %(name)s *tmp)\n'
[203] Fix | Delete
'{'
[204] Fix | Delete
'\n') % { 'name' : self._name })
[205] Fix | Delete
for entry in self._entries:
[206] Fix | Delete
self.PrintIndented(file, ' ', entry.CodeClear('tmp'))
[207] Fix | Delete
[208] Fix | Delete
file.write('}\n\n')
[209] Fix | Delete
[210] Fix | Delete
# Freeing
[211] Fix | Delete
file.write(( 'void\n'
[212] Fix | Delete
'%(name)s_free(struct %(name)s *tmp)\n'
[213] Fix | Delete
'{'
[214] Fix | Delete
'\n') % { 'name' : self._name })
[215] Fix | Delete
[216] Fix | Delete
for entry in self._entries:
[217] Fix | Delete
self.PrintIndented(file, ' ', entry.CodeFree('tmp'))
[218] Fix | Delete
[219] Fix | Delete
file.write((' free(tmp);\n'
[220] Fix | Delete
'}\n\n'))
[221] Fix | Delete
[222] Fix | Delete
# Marshaling
[223] Fix | Delete
file.write(('void\n'
[224] Fix | Delete
'%(name)s_marshal(struct evbuffer *evbuf, '
[225] Fix | Delete
'const struct %(name)s *tmp)'
[226] Fix | Delete
'{\n') % { 'name' : self._name })
[227] Fix | Delete
for entry in self._entries:
[228] Fix | Delete
indent = ' '
[229] Fix | Delete
# Optional entries do not have to be set
[230] Fix | Delete
if entry.Optional():
[231] Fix | Delete
indent += ' '
[232] Fix | Delete
file.write(' if (tmp->%s_set) {\n' % entry.Name())
[233] Fix | Delete
self.PrintIndented(
[234] Fix | Delete
file, indent,
[235] Fix | Delete
entry.CodeMarshal('evbuf', self.EntryTagName(entry),
[236] Fix | Delete
entry.GetVarName('tmp'),
[237] Fix | Delete
entry.GetVarLen('tmp')))
[238] Fix | Delete
if entry.Optional():
[239] Fix | Delete
file.write(' }\n')
[240] Fix | Delete
[241] Fix | Delete
file.write('}\n\n')
[242] Fix | Delete
[243] Fix | Delete
# Unmarshaling
[244] Fix | Delete
file.write(('int\n'
[245] Fix | Delete
'%(name)s_unmarshal(struct %(name)s *tmp, '
[246] Fix | Delete
' struct evbuffer *evbuf)\n'
[247] Fix | Delete
'{\n'
[248] Fix | Delete
' ev_uint32_t tag;\n'
[249] Fix | Delete
' while (evbuffer_get_length(evbuf) > 0) {\n'
[250] Fix | Delete
' if (evtag_peek(evbuf, &tag) == -1)\n'
[251] Fix | Delete
' return (-1);\n'
[252] Fix | Delete
' switch (tag) {\n'
[253] Fix | Delete
'\n') % { 'name' : self._name })
[254] Fix | Delete
for entry in self._entries:
[255] Fix | Delete
file.write(' case %s:\n' % self.EntryTagName(entry))
[256] Fix | Delete
if not entry.Array():
[257] Fix | Delete
file.write((
[258] Fix | Delete
' if (tmp->%s_set)\n'
[259] Fix | Delete
' return (-1);'
[260] Fix | Delete
'\n') % (entry.Name()))
[261] Fix | Delete
[262] Fix | Delete
self.PrintIndented(
[263] Fix | Delete
file, ' ',
[264] Fix | Delete
entry.CodeUnmarshal('evbuf',
[265] Fix | Delete
self.EntryTagName(entry),
[266] Fix | Delete
entry.GetVarName('tmp'),
[267] Fix | Delete
entry.GetVarLen('tmp')))
[268] Fix | Delete
[269] Fix | Delete
file.write(( ' tmp->%s_set = 1;\n' % entry.Name() +
[270] Fix | Delete
' break;\n' ))
[271] Fix | Delete
file.write(( ' default:\n'
[272] Fix | Delete
' return -1;\n'
[273] Fix | Delete
' }\n'
[274] Fix | Delete
' }\n\n' ))
[275] Fix | Delete
# Check if it was decoded completely
[276] Fix | Delete
file.write(( ' if (%(name)s_complete(tmp) == -1)\n'
[277] Fix | Delete
' return (-1);'
[278] Fix | Delete
'\n') % { 'name' : self._name })
[279] Fix | Delete
[280] Fix | Delete
# Successfully decoded
[281] Fix | Delete
file.write(( ' return (0);\n'
[282] Fix | Delete
'}\n\n'))
[283] Fix | Delete
[284] Fix | Delete
# Checking if a structure has all the required data
[285] Fix | Delete
file.write((
[286] Fix | Delete
'int\n'
[287] Fix | Delete
'%(name)s_complete(struct %(name)s *msg)\n'
[288] Fix | Delete
'{\n' ) % { 'name' : self._name })
[289] Fix | Delete
for entry in self._entries:
[290] Fix | Delete
if not entry.Optional():
[291] Fix | Delete
code = [
[292] Fix | Delete
'if (!msg->%(name)s_set)',
[293] Fix | Delete
' return (-1);' ]
[294] Fix | Delete
code = TranslateList(code, entry.GetTranslation())
[295] Fix | Delete
self.PrintIndented(
[296] Fix | Delete
file, ' ', code)
[297] Fix | Delete
[298] Fix | Delete
self.PrintIndented(
[299] Fix | Delete
file, ' ',
[300] Fix | Delete
entry.CodeComplete('msg', entry.GetVarName('msg')))
[301] Fix | Delete
file.write((
[302] Fix | Delete
' return (0);\n'
[303] Fix | Delete
'}\n\n' ))
[304] Fix | Delete
[305] Fix | Delete
# Complete message unmarshaling
[306] Fix | Delete
file.write((
[307] Fix | Delete
'int\n'
[308] Fix | Delete
'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, '
[309] Fix | Delete
'ev_uint32_t need_tag, struct %(name)s *msg)\n'
[310] Fix | Delete
'{\n'
[311] Fix | Delete
' ev_uint32_t tag;\n'
[312] Fix | Delete
' int res = -1;\n'
[313] Fix | Delete
'\n'
[314] Fix | Delete
' struct evbuffer *tmp = evbuffer_new();\n'
[315] Fix | Delete
'\n'
[316] Fix | Delete
' if (evtag_unmarshal(evbuf, &tag, tmp) == -1'
[317] Fix | Delete
' || tag != need_tag)\n'
[318] Fix | Delete
' goto error;\n'
[319] Fix | Delete
'\n'
[320] Fix | Delete
' if (%(name)s_unmarshal(msg, tmp) == -1)\n'
[321] Fix | Delete
' goto error;\n'
[322] Fix | Delete
'\n'
[323] Fix | Delete
' res = 0;\n'
[324] Fix | Delete
'\n'
[325] Fix | Delete
' error:\n'
[326] Fix | Delete
' evbuffer_free(tmp);\n'
[327] Fix | Delete
' return (res);\n'
[328] Fix | Delete
'}\n\n' ) % { 'name' : self._name })
[329] Fix | Delete
[330] Fix | Delete
# Complete message marshaling
[331] Fix | Delete
file.write((
[332] Fix | Delete
'void\n'
[333] Fix | Delete
'evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag, '
[334] Fix | Delete
'const struct %(name)s *msg)\n'
[335] Fix | Delete
'{\n'
[336] Fix | Delete
' struct evbuffer *buf_ = evbuffer_new();\n'
[337] Fix | Delete
' assert(buf_ != NULL);\n'
[338] Fix | Delete
' %(name)s_marshal(buf_, msg);\n'
[339] Fix | Delete
' evtag_marshal_buffer(evbuf, tag, buf_);\n '
[340] Fix | Delete
' evbuffer_free(buf_);\n'
[341] Fix | Delete
'}\n\n' ) % { 'name' : self._name })
[342] Fix | Delete
[343] Fix | Delete
class Entry:
[344] Fix | Delete
def __init__(self, type, name, tag):
[345] Fix | Delete
self._type = type
[346] Fix | Delete
self._name = name
[347] Fix | Delete
self._tag = int(tag)
[348] Fix | Delete
self._ctype = type
[349] Fix | Delete
self._optional = 0
[350] Fix | Delete
self._can_be_array = 0
[351] Fix | Delete
self._array = 0
[352] Fix | Delete
self._line_count = -1
[353] Fix | Delete
self._struct = None
[354] Fix | Delete
self._refname = None
[355] Fix | Delete
[356] Fix | Delete
self._optpointer = True
[357] Fix | Delete
self._optaddarg = True
[358] Fix | Delete
[359] Fix | Delete
def GetInitializer(self):
[360] Fix | Delete
assert 0, "Entry does not provide initializer"
[361] Fix | Delete
[362] Fix | Delete
def SetStruct(self, struct):
[363] Fix | Delete
self._struct = struct
[364] Fix | Delete
[365] Fix | Delete
def LineCount(self):
[366] Fix | Delete
assert self._line_count != -1
[367] Fix | Delete
return self._line_count
[368] Fix | Delete
[369] Fix | Delete
def SetLineCount(self, number):
[370] Fix | Delete
self._line_count = number
[371] Fix | Delete
[372] Fix | Delete
def Array(self):
[373] Fix | Delete
return self._array
[374] Fix | Delete
[375] Fix | Delete
def Optional(self):
[376] Fix | Delete
return self._optional
[377] Fix | Delete
[378] Fix | Delete
def Tag(self):
[379] Fix | Delete
return self._tag
[380] Fix | Delete
[381] Fix | Delete
def Name(self):
[382] Fix | Delete
return self._name
[383] Fix | Delete
[384] Fix | Delete
def Type(self):
[385] Fix | Delete
return self._type
[386] Fix | Delete
[387] Fix | Delete
def MakeArray(self, yes=1):
[388] Fix | Delete
self._array = yes
[389] Fix | Delete
[390] Fix | Delete
def MakeOptional(self):
[391] Fix | Delete
self._optional = 1
[392] Fix | Delete
[393] Fix | Delete
def Verify(self):
[394] Fix | Delete
if self.Array() and not self._can_be_array:
[395] Fix | Delete
raise RpcGenError(
[396] Fix | Delete
'Entry "%s" cannot be created as an array '
[397] Fix | Delete
'around line %d' % (self._name, self.LineCount()))
[398] Fix | Delete
if not self._struct:
[399] Fix | Delete
raise RpcGenError(
[400] Fix | Delete
'Entry "%s" does not know which struct it belongs to '
[401] Fix | Delete
'around line %d' % (self._name, self.LineCount()))
[402] Fix | Delete
if self._optional and self._array:
[403] Fix | Delete
raise RpcGenError(
[404] Fix | Delete
'Entry "%s" has illegal combination of optional and array '
[405] Fix | Delete
'around line %d' % (self._name, self.LineCount()))
[406] Fix | Delete
[407] Fix | Delete
def GetTranslation(self, extradict = {}):
[408] Fix | Delete
mapping = {
[409] Fix | Delete
"parent_name" : self._struct.Name(),
[410] Fix | Delete
"name" : self._name,
[411] Fix | Delete
"ctype" : self._ctype,
[412] Fix | Delete
"refname" : self._refname,
[413] Fix | Delete
"optpointer" : self._optpointer and "*" or "",
[414] Fix | Delete
"optreference" : self._optpointer and "&" or "",
[415] Fix | Delete
"optaddarg" :
[416] Fix | Delete
self._optaddarg and ", const %s value" % self._ctype or ""
[417] Fix | Delete
}
[418] Fix | Delete
for (k, v) in list(extradict.items()):
[419] Fix | Delete
mapping[k] = v
[420] Fix | Delete
[421] Fix | Delete
return mapping
[422] Fix | Delete
[423] Fix | Delete
def GetVarName(self, var):
[424] Fix | Delete
return '%(var)s->%(name)s_data' % self.GetTranslation({ 'var' : var })
[425] Fix | Delete
[426] Fix | Delete
def GetVarLen(self, var):
[427] Fix | Delete
return 'sizeof(%s)' % self._ctype
[428] Fix | Delete
[429] Fix | Delete
def GetFuncName(self):
[430] Fix | Delete
return '%s_%s_get' % (self._struct.Name(), self._name)
[431] Fix | Delete
[432] Fix | Delete
def GetDeclaration(self, funcname):
[433] Fix | Delete
code = [ 'int %s(struct %s *, %s *);' % (
[434] Fix | Delete
funcname, self._struct.Name(), self._ctype ) ]
[435] Fix | Delete
return code
[436] Fix | Delete
[437] Fix | Delete
def CodeGet(self):
[438] Fix | Delete
code = (
[439] Fix | Delete
'int',
[440] Fix | Delete
'%(parent_name)s_%(name)s_get(struct %(parent_name)s *msg, '
[441] Fix | Delete
'%(ctype)s *value)',
[442] Fix | Delete
'{',
[443] Fix | Delete
' if (msg->%(name)s_set != 1)',
[444] Fix | Delete
' return (-1);',
[445] Fix | Delete
' *value = msg->%(name)s_data;',
[446] Fix | Delete
' return (0);',
[447] Fix | Delete
'}' )
[448] Fix | Delete
code = '\n'.join(code)
[449] Fix | Delete
code = code % self.GetTranslation()
[450] Fix | Delete
return code.split('\n')
[451] Fix | Delete
[452] Fix | Delete
def AssignFuncName(self):
[453] Fix | Delete
return '%s_%s_assign' % (self._struct.Name(), self._name)
[454] Fix | Delete
[455] Fix | Delete
def AddFuncName(self):
[456] Fix | Delete
return '%s_%s_add' % (self._struct.Name(), self._name)
[457] Fix | Delete
[458] Fix | Delete
def AssignDeclaration(self, funcname):
[459] Fix | Delete
code = [ 'int %s(struct %s *, const %s);' % (
[460] Fix | Delete
funcname, self._struct.Name(), self._ctype ) ]
[461] Fix | Delete
return code
[462] Fix | Delete
[463] Fix | Delete
def CodeAssign(self):
[464] Fix | Delete
code = [ 'int',
[465] Fix | Delete
'%(parent_name)s_%(name)s_assign(struct %(parent_name)s *msg,'
[466] Fix | Delete
' const %(ctype)s value)',
[467] Fix | Delete
'{',
[468] Fix | Delete
' msg->%(name)s_set = 1;',
[469] Fix | Delete
' msg->%(name)s_data = value;',
[470] Fix | Delete
' return (0);',
[471] Fix | Delete
'}' ]
[472] Fix | Delete
code = '\n'.join(code)
[473] Fix | Delete
code = code % self.GetTranslation()
[474] Fix | Delete
return code.split('\n')
[475] Fix | Delete
[476] Fix | Delete
def CodeClear(self, structname):
[477] Fix | Delete
code = [ '%s->%s_set = 0;' % (structname, self.Name()) ]
[478] Fix | Delete
[479] Fix | Delete
return code
[480] Fix | Delete
[481] Fix | Delete
def CodeComplete(self, structname, var_name):
[482] Fix | Delete
return []
[483] Fix | Delete
[484] Fix | Delete
def CodeFree(self, name):
[485] Fix | Delete
return []
[486] Fix | Delete
[487] Fix | Delete
def CodeBase(self):
[488] Fix | Delete
code = [
[489] Fix | Delete
'%(parent_name)s_%(name)s_assign,',
[490] Fix | Delete
'%(parent_name)s_%(name)s_get,'
[491] Fix | Delete
]
[492] Fix | Delete
if self.Array():
[493] Fix | Delete
code.append('%(parent_name)s_%(name)s_add,')
[494] Fix | Delete
[495] Fix | Delete
code = '\n'.join(code)
[496] Fix | Delete
code = code % self.GetTranslation()
[497] Fix | Delete
return code.split('\n')
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function