From 0711efddc70cb5e3fe7f0f7f586df9531c79ccb6 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Sat, 14 May 2022 20:19:16 +0200 Subject: [PATCH 10/12] generate_packets.py: replace custom formatting code in Variant.get_receive() See osdn#44597 Signed-off-by: Alina Lenk --- common/generate_packets.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index b58994cb82..af56b6c8c5 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -1389,13 +1389,6 @@ static char *stats_{self.name}_names[] = {{{names}}}; # function. This is one of the two real functions. So it is rather # complex to create. def get_receive(self): - temp='''%(receive_prototype)s -{ - RECEIVE_PACKET_START(%(packet_name)s, real_packet); - RECEIVE_PACKET_END(real_packet); -} - -''' if self.delta: delta_header='''#ifdef FREECIV_DELTA_PROTOCOL %(name)s_fields fields; @@ -1450,11 +1443,27 @@ static char *stats_{self.name}_names[] = {{{names}}}; else: faddr = "" - for i in range(2): - for k,v in vars().items(): - if type(v)==type(""): - temp=temp.replace("<%s>"%k,v) - return temp%self.get_dict(vars()) + return "".join(( + """\ +%(receive_prototype)s +{ +""", + delta_header, + """\ + RECEIVE_PACKET_START(%(packet_name)s, real_packet); +""", + faddr, + delta_body1, + body1, + log, + body2, + post, + """\ + RECEIVE_PACKET_END(real_packet); +} + +""", + )) % self.get_dict(vars()) # Helper for get_receive() def get_delta_receive_body(self): -- 2.17.1