The International Simutrans Forum

 

Author Topic: Include guard cleanup  (Read 464 times)

0 Members and 1 Guest are viewing this topic.

Offline ceeac

  • Devotee
  • *
  • Posts: 259
Include guard cleanup
« on: March 28, 2020, 02:20:11 PM »
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:
Code: [Select]
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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10675
  • Languages: De,EN,JP
Re: Include guard cleanup
« Reply #1 on: March 29, 2020, 12:14:35 PM »
I think this (and the trailing whitespace patch) needs to run quite often, as file renames happen from time to time.