From 11b72ea167b4caa5e73f4c802d520053d3cf5136 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Sun, 15 May 2022 01:10:10 +0200 Subject: [PATCH 18/18] generate_packets.py: clean up string formatting for Variant.get_send() helpers See osdn#44606 Signed-off-by: Alina Lenk --- common/generate_packets.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index d539f76e61..41ba37919f 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -1269,7 +1269,7 @@ static char *stats_{self.name}_names[] = {{{names}}}; """.format(diff = diff) delta_header2 = delta_header2 + '''#endif /* FREECIV_DELTA_PROTOCOL */ ''' - body = self.get_delta_send_body(pre2) % self.__dict__ + "\n#ifndef FREECIV_DELTA_PROTOCOL" + body = self.get_delta_send_body(pre2) + "\n#ifndef FREECIV_DELTA_PROTOCOL" else: delta_header="" body="#if 1 /* To match endif */" @@ -1339,20 +1339,20 @@ static char *stats_{self.name}_names[] = {{{names}}}; # Helper for get_send() def get_delta_send_body(self, before_return=""): - intro=''' + intro = """ #ifdef FREECIV_DELTA_PROTOCOL - if (NULL == *hash) { - *hash = genhash_new_full(hash_%(name)s, cmp_%(name)s, + if (NULL == *hash) {{ + *hash = genhash_new_full(hash_{self.name}, cmp_{self.name}, NULL, NULL, NULL, free); - } + }} BV_CLR_ALL(fields); - if (!genhash_lookup(*hash, real_packet, (void **) &old)) { + if (!genhash_lookup(*hash, real_packet, (void **) &old)) {{ old = fc_malloc(sizeof(*old)); *old = *real_packet; genhash_insert(*hash, old, old); memset(old, 0, sizeof(*old)); -''' +""".format(self = self) if self.is_info != "no": intro = intro + ''' different = 1; /* Force to send. */ ''' @@ -1362,11 +1362,15 @@ static char *stats_{self.name}_names[] = {{{names}}}; for i, field in enumerate(self.other_fields): body = body + field.get_cmp_wrapper(i, self) if self.gen_log: - fl=' %(log_macro)s(" no change -> discard");\n' + fl = """\ + {self.log_macro}(" no change -> discard"); +""".format(self = self) else: fl="" if self.gen_stats: - s=' stats_%(name)s_discarded++;\n' + s = """\ + stats_{self.name}_discarded++; +""".format(self = self) else: s="" -- 2.17.1