Skip to content

Commit

Permalink
generate_packets.py: clean up string formatting for Variant.get_send(…
Browse files Browse the repository at this point in the history
…) helpers

See osdn#44606

Signed-off-by: Alina Lenk <alina.v.lenk@gmail.com>
  • Loading branch information
alien-valkyrie committed May 16, 2022
1 parent 8086281 commit 79fa330
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions common/generate_packets.py
Expand Up @@ -1283,7 +1283,7 @@ def get_send(self):
""".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 */"
Expand Down Expand Up @@ -1353,20 +1353,20 @@ def get_send(self):

# 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. */
'''
Expand All @@ -1376,11 +1376,15 @@ def get_delta_send_body(self, before_return=""):
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=""

Expand Down

0 comments on commit 79fa330

Please sign in to comment.