News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Include guard cleanup

Started by ceeac, March 28, 2020, 02:20:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ceeac

This patch cleans up include guards for all header files, except the files in squirrel/. Currently, the include guards do not have a consistent format, and some either begin with an underscore and a capital letter, or two leading underscores (these are technically reserved so they should not be used).

The patch changes include guards to the path of the file relative to a common base directory, with non-alphanumeric characters replaced by underscores (example: file "descriptor/writer/xref_writer.h" has include guard "DESCRIPTOR_WRITER_XREF_WRITER_H"). With this format the include guard is guaranteed to be unique.

I used the following one-liner to create the patch:

find . -type f -name "*.h" | grep -v "squirrel/" | while read f; do guard="$(echo $f | cut -b 3- | tr '[[:lower:]]' '[[:upper:]]' | tr -C '[[:alnum:]]' '_' | rev | cut -c2- | rev)"; perl -i -p0e "s/(\n){2,}#ifndef [^\n]*\n#define [^\n]*(\n)+/\n\n#ifndef $guard\n#define $guard\n\n\n/" $f; done


I also included a fix for the fact that the declaration of tick_to_string in simintr.h was not guarded.

prissi

I think this (and the trailing whitespace patch) needs to run quite often, as file renames happen from time to time.