From 3f8c7cd0353f4b2adcf19a90ffd3b8ba42b68209 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 29 Feb 2012 15:07:31 -0500 Subject: Convert include-guard macro convention to avoid reserved identifiers Previously we used include-guards with names like _EVENT2_EVENT_H_. But C reserves macros beginning with an underscore for use by the system. This patch converts all include guards for files like include/event2/ to be of form EVENT2__INCLUDED_, and all Libevent 1.x headers in include/ to be of the form EVENT1__INCLUDED_, and all internal libevent headers with names like to the form _INCLUDED_. FNAME_H is here derived from fname.h by replacing every non-macro-usable character in fname.h with an underscore, and putting every remaining character in uppercase. This is an automatic conversion. The script that produced was made by running the following script over all header files: ===== #!/usr/bin/perl -w # Run this on every .h file except config.h, sys/queue.h, WIN32/event2/event-config.h use strict; my %macros = (); my %skipped = (); FILE: for my $fn (@ARGV) { my $f = $fn; if ($fn !~ /^\.\//) { $f = "./$fn"; } if ($f eq './config.h' or $f =~ m#/tree.h$# or $f =~ m#/queue.h# or $f =~ m#/event-config.h# or $f =~ m#/evconfig-private.h#) { $skipped{$fn} = 1; next FILE; } $skipped{$fn} = 0; open(F, $fn); while () { if (/^#ifndef ([A-Za-z0-9_]+)/) { $macros{$fn} = $1; next FILE; } } } print "#!/usr/bin/perl -w -i -p\n\n"; for my $fn (@ARGV) { if (! exists $macros{$fn}) { print "# No macro known for $fn!\n" if (!$skipped{$fn}); } else { if ($macros{$fn} !~ /_H_?$/) { print "# Weird macro for $fn...\n"; } my $goodmacro = uc $fn; $goodmacro =~ s#^\./##; $goodmacro =~ s#INCLUDE/EVENT2#EVENT2#; $goodmacro =~ s#INCLUDE/#EVENT1_#; $goodmacro =~ s#TEST/##; $goodmacro =~ s#[\/\-\.]#_#g; print "s/(?