Commit 0cb921f3 authored by Nick Mathewson's avatar Nick Mathewson 🌉
Browse files

Convert all include-guard macros to avoid reserved identifiers.

In C, we technically aren't supposed to define our own things that
start with an underscore.

This is a purely machine-generated commit.  First, I ran this script
on all the headers in src/{common,or,test,tools/*}/*.h :
==============================

use strict;

my %macros = ();
my %skipped = ();
FILE: for my $fn (@ARGV) {
    my $f = $fn;
    if ($fn !~ /^\.\//) {
	$f = "./$fn";
    }
    $skipped{$fn} = 0;
    open(F, $fn);
    while (<F>) {
	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});
	next;
    }
    if ($macros{$fn} !~ /_H_?$/) {
	print "# Weird macro for $fn...\n";
    }
    my $goodmacro = uc $fn;
    $goodmacro =~ s#.*/##;
    $goodmacro =~ s#[\/\-\.]#_#g;
    print "s/(?<![A-Za-z0-9_])$macros{$fn}(?![A-Za-z0-9_])/TOR_${goodmacro}/g;\n"
}
==============================

It produced the following output, which I then re-ran on those same files:

==============================

s/(?<![A-Za-z0-9_])_TOR_ADDRESS_H(?![A-Za-z0-9_])/TOR_ADDRESS_H/g;
s/(?<![A-Za-z0-9_])_TOR_AES_H(?![A-Za-z0-9_])/TOR_AES_H/g;
s/(?<![A-Za-z0-9_])_TOR_COMPAT_H(?![A-Za-z0-9_])/TOR_COMPAT_H/g;
s/(?<![A-Za-z0-9_])_TOR_COMPAT_LIBEVENT_H(?![A-Za-z0-9_])/TOR_COMPAT_LIBEVENT_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONTAINER_H(?![A-Za-z0-9_])/TOR_CONTAINER_H/g;
s/(?<![A-Za-z0-9_])_TOR_CRYPTO_H(?![A-Za-z0-9_])/TOR_CRYPTO_H/g;
s/(?<![A-Za-z0-9_])TOR_DI_OPS_H(?![A-Za-z0-9_])/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
s/(?<![A-Za-z0-9_])_TOR_COMMAND_H(?![A-Za-z0-9_])/TOR_COMMAND_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONFIG_H(?![A-Za-z0-9_])/TOR_CONFIG_H/g;
s/(?<![A-Za-z0-9_])TOR_CONFPARSE_H(?![A-Za-z0-9_])/TOR_CONFPARSE_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONNECTION_EDGE_H(?![A-Za-z0-9_])/TOR_CONNECTION_EDGE_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONNECTION_H(?![A-Za-z0-9_])/TOR_CONNECTION_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONNECTION_OR_H(?![A-Za-z0-9_])/TOR_CONNECTION_OR_H/g;
s/(?<![A-Za-z0-9_])_TOR_CONTROL_H(?![A-Za-z0-9_])/TOR_CONTROL_H/g;
s/(?<![A-Za-z0-9_])_TOR_CPUWORKER_H(?![A-Za-z0-9_])/TOR_CPUWORKER_H/g;
s/(?<![A-Za-z0-9_])_TOR_DIRECTORY_H(?![A-Za-z0-9_])/TOR_DIRECTORY_H/g;
s/(?<![A-Za-z0-9_])_TOR_DIRSERV_H(?![A-Za-z0-9_])/TOR_DIRSERV_H/g;
s/(?<![A-Za-z0-9_])_TOR_DIRVOTE_H(?![A-Za-z0-9_])/TOR_DIRVOTE_H/g;
s/(?<![A-Za-z0-9_])_TOR_DNS_H(?![A-Za-z0-9_])/TOR_DNS_H/g;
s/(?<![A-Za-z0-9_])_TOR_DNSSERV_H(?![A-Za-z0-9_])/TOR_DNSSERV_H/g;
s/(?<![A-Za-z0-9_])TOR_EVENTDNS_TOR_H(?![A-Za-z0-9_])/TOR_EVENTDNS_TOR_H/g;
s/(?<![A-Za-z0-9_])_TOR_GEOIP_H(?![A-Za-z0-9_])/TOR_GEOIP_H/g;
s/(?<![A-Za-z0-9_])_TOR_HIBERNATE_H(?![A-Za-z0-9_])/TOR_HIBERNATE_H/g;
s/(?<![A-Za-z0-9_])_TOR_MAIN_H(?![A-Za-z0-9_])/TOR_MAIN_H/g;
s/(?<![A-Za-z0-9_])_TOR_MICRODESC_H(?![A-Za-z0-9_])/TOR_MICRODESC_H/g;
s/(?<![A-Za-z0-9_])_TOR_NETWORKSTATUS_H(?![A-Za-z0-9_])/TOR_NETWORKSTATUS_H/g;
s/(?<![A-Za-z0-9_])_TOR_NODELIST_H(?![A-Za-z0-9_])/TOR_NODELIST_H/g;
s/(?<![A-Za-z0-9_])_TOR_NTMAIN_H(?![A-Za-z0-9_])/TOR_NTMAIN_H/g;
s/(?<![A-Za-z0-9_])_TOR_ONION_H(?![A-Za-z0-9_])/TOR_ONION_H/g;
s/(?<![A-Za-z0-9_])_TOR_OR_H(?![A-Za-z0-9_])/TOR_OR_H/g;
s/(?<![A-Za-z0-9_])_TOR_POLICIES_H(?![A-Za-z0-9_])/TOR_POLICIES_H/g;
s/(?<![A-Za-z0-9_])_TOR_REASONS_H(?![A-Za-z0-9_])/TOR_REASONS_H/g;
s/(?<![A-Za-z0-9_])_TOR_RELAY_H(?![A-Za-z0-9_])/TOR_RELAY_H/g;
s/(?<![A-Za-z0-9_])_TOR_RENDCLIENT_H(?![A-Za-z0-9_])/TOR_RENDCLIENT_H/g;
s/(?<![A-Za-z0-9_])_TOR_RENDCOMMON_H(?![A-Za-z0-9_])/TOR_RENDCOMMON_H/g;
s/(?<![A-Za-z0-9_])_TOR_RENDMID_H(?![A-Za-z0-9_])/TOR_RENDMID_H/g;
s/(?<![A-Za-z0-9_])_TOR_RENDSERVICE_H(?![A-Za-z0-9_])/TOR_RENDSERVICE_H/g;
s/(?<![A-Za-z0-9_])_TOR_REPHIST_H(?![A-Za-z0-9_])/TOR_REPHIST_H/g;
s/(?<![A-Za-z0-9_])_TOR_REPLAYCACHE_H(?![A-Za-z0-9_])/TOR_REPLAYCACHE_H/g;
s/(?<![A-Za-z0-9_])_TOR_ROUTER_H(?![A-Za-z0-9_])/TOR_ROUTER_H/g;
s/(?<![A-Za-z0-9_])_TOR_ROUTERLIST_H(?![A-Za-z0-9_])/TOR_ROUTERLIST_H/g;
s/(?<![A-Za-z0-9_])_TOR_ROUTERPARSE_H(?![A-Za-z0-9_])/TOR_ROUTERPARSE_H/g;
s/(?<![A-Za-z0-9_])TOR_ROUTERSET_H(?![A-Za-z0-9_])/TOR_ROUTERSET_H/g;
s/(?<![A-Za-z0-9_])TOR_STATEFILE_H(?![A-Za-z0-9_])/TOR_STATEFILE_H/g;
s/(?<![A-Za-z0-9_])_TOR_STATUS_H(?![A-Za-z0-9_])/TOR_STATUS_H/g;
s/(?<![A-Za-z0-9_])TOR_TRANSPORTS_H(?![A-Za-z0-9_])/TOR_TRANSPORTS_H/g;
s/(?<![A-Za-z0-9_])_TOR_TEST_H(?![A-Za-z0-9_])/TOR_TEST_H/g;
s/(?<![A-Za-z0-9_])_TOR_FW_HELPER_H(?![A-Za-z0-9_])/TOR_TOR_FW_HELPER_H/g;
s/(?<![A-Za-z0-9_])_TOR_FW_HELPER_NATPMP_H(?![A-Za-z0-9_])/TOR_TOR_FW_HELPER_NATPMP_H/g;
s/(?<![A-Za-z0-9_])_TOR_FW_HELPER_UPNP_H(?![A-Za-z0-9_])/TOR_TOR_FW_HELPER_UPNP_H/g;
==============================
parent d7b79bf0
......@@ -8,8 +8,8 @@
* \brief Headers for address.h
**/
#ifndef _TOR_ADDRESS_H
#define _TOR_ADDRESS_H
#ifndef TOR_ADDRESS_H
#define TOR_ADDRESS_H
#include "orconfig.h"
#include "torint.h"
......
......@@ -5,8 +5,8 @@
/* Implements a minimal interface to counter-mode AES. */
#ifndef _TOR_AES_H
#define _TOR_AES_H
#ifndef TOR_AES_H
#define TOR_AES_H
/**
* \file aes.h
......
......@@ -3,8 +3,8 @@
* Copyright (c) 2007-2012, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef _TOR_COMPAT_H
#define _TOR_COMPAT_H
#ifndef TOR_COMPAT_H
#define TOR_COMPAT_H
#include "orconfig.h"
#include "torint.h"
......
/* Copyright (c) 2009-2012, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef _TOR_COMPAT_LIBEVENT_H
#define _TOR_COMPAT_LIBEVENT_H
#ifndef TOR_COMPAT_LIBEVENT_H
#define TOR_COMPAT_LIBEVENT_H
#include "orconfig.h"
......
......@@ -3,8 +3,8 @@
* Copyright (c) 2007-2012, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef _TOR_CONTAINER_H
#define _TOR_CONTAINER_H
#ifndef TOR_CONTAINER_H
#define TOR_CONTAINER_H
#include "util.h"
......
......@@ -10,8 +10,8 @@
* \brief Headers for crypto.c
**/
#ifndef _TOR_CRYPTO_H
#define _TOR_CRYPTO_H
#ifndef TOR_CRYPTO_H
#define TOR_CRYPTO_H
#include <stdio.h>
#include "torint.h"
......
......@@ -2,8 +2,8 @@
/* See LICENSE for licensing information */
/* Tor dependencies */
#ifndef _TOR_MEMAREA_H
#define _TOR_MEMAREA_H
#ifndef TOR_MEMAREA_H
#define TOR_MEMAREA_H
typedef struct memarea_t memarea_t;
......
......@@ -6,8 +6,8 @@
* \brief Headers for mempool.c
**/
#ifndef _TOR_MEMPOOL_H
#define _TOR_MEMPOOL_H
#ifndef TOR_MEMPOOL_H
#define TOR_MEMPOOL_H
/** A memory pool is a context in which a large number of fixed-sized
* objects can be allocated efficiently. See mempool.c for implementation
......
......@@ -8,8 +8,8 @@
* \brief Headers for torgzip.h
**/
#ifndef _TOR_TORGZIP_H
#define _TOR_TORGZIP_H
#ifndef TOR_TORGZIP_H
#define TOR_TORGZIP_H
/** Enumeration of what kind of compression to use. Only ZLIB_METHOD is
* guaranteed to be supported by the compress/uncompress functions here;
......
......@@ -8,8 +8,8 @@
* \brief Header file to define uint32_t and friends
**/
#ifndef _TOR_TORINT_H
#define _TOR_TORINT_H
#ifndef TOR_TORINT_H
#define TOR_TORINT_H
#include "orconfig.h"
......
......@@ -10,7 +10,7 @@
* \brief Headers for log.c
**/
#ifndef _TOR_LOG_H
#ifndef TOR_TORLOG_H
#include "compat.h"
......@@ -213,6 +213,6 @@ extern const char *_log_fn_function_name;
#endif /* !GNUC */
# define _TOR_LOG_H
# define TOR_TORLOG_H
#endif
......@@ -3,8 +3,8 @@
* Copyright (c) 2007-2012, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef _TOR_TORTLS_H
#define _TOR_TORTLS_H
#ifndef TOR_TORTLS_H
#define TOR_TORTLS_H
/**
* \file tortls.h
......
......@@ -8,8 +8,8 @@
* \brief Headers for util.c
**/
#ifndef _TOR_UTIL_H
#define _TOR_UTIL_H
#ifndef TOR_UTIL_H
#define TOR_UTIL_H
#include "orconfig.h"
#include "torint.h"
......
......@@ -9,8 +9,8 @@
* \brief Header file for buffers.c.
**/
#ifndef _TOR_BUFFERS_H
#define _TOR_BUFFERS_H
#ifndef TOR_BUFFERS_H
#define TOR_BUFFERS_H
buf_t *buf_new(void);
buf_t *buf_new_with_capacity(size_t size);
......
......@@ -6,8 +6,8 @@
* \brief Header file for channel.c
**/
#ifndef _TOR_CHANNEL_H
#define _TOR_CHANNEL_H
#ifndef TOR_CHANNEL_H
#define TOR_CHANNEL_H
#include "or.h"
#include "circuitmux.h"
......
......@@ -6,8 +6,8 @@
* \brief Header file for channeltls.c
**/
#ifndef _TOR_CHANNEL_TLS_H
#define _TOR_CHANNEL_TLS_H
#ifndef TOR_CHANNELTLS_H
#define TOR_CHANNELTLS_H
#include "or.h"
#include "channel.h"
......
......@@ -9,8 +9,8 @@
* \brief Header file for circuitbuild.c.
**/
#ifndef _TOR_CIRCUITBUILD_H
#define _TOR_CIRCUITBUILD_H
#ifndef TOR_CIRCUITBUILD_H
#define TOR_CIRCUITBUILD_H
char *circuit_list_path(origin_circuit_t *circ, int verbose);
char *circuit_list_path_for_controller(origin_circuit_t *circ);
......
......@@ -9,8 +9,8 @@
* \brief Header file for circuitlist.c.
**/
#ifndef _TOR_CIRCUITLIST_H
#define _TOR_CIRCUITLIST_H
#ifndef TOR_CIRCUITLIST_H
#define TOR_CIRCUITLIST_H
circuit_t * _circuit_get_global_list(void);
const char *circuit_state_to_string(int state);
......
......@@ -6,8 +6,8 @@
* \brief Header file for circuitmux.c
**/
#ifndef _TOR_CIRCUITMUX_H
#define _TOR_CIRCUITMUX_H
#ifndef TOR_CIRCUITMUX_H
#define TOR_CIRCUITMUX_H
#include "or.h"
......@@ -132,5 +132,5 @@ void circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ);
void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
unsigned int n_cells);
#endif /* _TOR_CIRCUITMUX_H */
#endif /* TOR_CIRCUITMUX_H */
......@@ -6,8 +6,8 @@
* \brief Header file for circuitmux_ewma.c
**/
#ifndef _TOR_CIRCUITMUX_EWMA_H
#define _TOR_CIRCUITMUX_EWMA_H
#ifndef TOR_CIRCUITMUX_EWMA_H
#define TOR_CIRCUITMUX_EWMA_H
#include "or.h"
#include "circuitmux.h"
......@@ -25,5 +25,5 @@ unsigned int cell_ewma_get_tick(void);
void cell_ewma_set_scale_factor(const or_options_t *options,
const networkstatus_t *consensus);
#endif /* _TOR_CIRCUITMUX_EWMA_H */
#endif /* TOR_CIRCUITMUX_EWMA_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment