From 9063ec84a7ccd5c13ced21f029c6681b37538203 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 6 May 2016 16:14:41 +0100 Subject: [PATCH] Removed duplicate externs from headers. --- src/battle/capitalShips.h | 1 - src/battle/jumpgate.h | 1 - src/game/title.h | 1 - tools/tidyHeaders.sh | 94 ++++++++++++++++++++++++++++++++++----- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/src/battle/capitalShips.h b/src/battle/capitalShips.h index d3d1163..ec2b596 100644 --- a/src/battle/capitalShips.h +++ b/src/battle/capitalShips.h @@ -34,7 +34,6 @@ extern char *readFile(char *filename); extern long flagsToLong(char *flags, int *add); extern long lookup(char *name); extern void doAI(void); -extern float getAngle(int x1, int y1, int x2, int y2); extern float mod(float n, float x); extern void applyFighterThrust(void); extern void addLargeEngineEffect(void); diff --git a/src/battle/jumpgate.h b/src/battle/jumpgate.h index f0a76b1..cbb8b8e 100644 --- a/src/battle/jumpgate.h +++ b/src/battle/jumpgate.h @@ -30,7 +30,6 @@ extern void playBattleSound(int id, int x, int y); extern void blitRotated(SDL_Texture *texture, int x, int y, float angle); extern char *getTranslatedString(char *string); extern void addSmallExplosion(void); -extern void playBattleSound(int id, int x, int y); extern void addDebris(int x, int y, int amount); extern void runScriptFunction(char *format, ...); extern void updateObjective(char *name, int type); diff --git a/src/game/title.h b/src/game/title.h index 94738cb..0a1df9e 100644 --- a/src/game/title.h +++ b/src/game/title.h @@ -60,7 +60,6 @@ extern void clearInput(void); extern void initTrophiesDisplay(void); extern void drawTrophies(void); extern void doTrophies(void); -extern void destroyBattle(void); extern App app; extern Battle battle; diff --git a/tools/tidyHeaders.sh b/tools/tidyHeaders.sh index 08e9114..76c9d52 100755 --- a/tools/tidyHeaders.sh +++ b/tools/tidyHeaders.sh @@ -30,6 +30,7 @@ function cleanHeader($headerFile) $func_pattern = "/(([A-Z0-9_]+)\\()/i"; $struct_pattern = "/([A-Z]+);/i"; + $define_pattern = "/#define ([A-Z]+)/i"; $bodyFile = $headerFile; $bodyFile[strlen($bodyFile) - 1] = 'c'; @@ -38,16 +39,17 @@ function cleanHeader($headerFile) { $header = file($headerFile); $body = file_get_contents($bodyFile); + $lines = []; $i = 0; $hasChanges = false; foreach ($header as $line) { - if (strstr($line, "extern") !== FALSE && strstr($line, "getTranslatedString") === FALSE) + if (preg_match("/extern|define/", $line) && strstr($line, "getTranslatedString") === FALSE) { preg_match($func_pattern, $line, $matches); - + if (count($matches) == 3) { $extern = $matches[2]; @@ -62,6 +64,21 @@ function cleanHeader($headerFile) echo "\t- $line"; unset($header[$i]); } + + if (!in_array($line, $lines)) + { + $lines[] = $line; + } + else + { + if (!$hasChanges) + { + echo "$headerFile\n"; + $hasChanges = true; + } + echo "\t- $line"; + unset($header[$i]); + } } preg_match($struct_pattern, $line, $matches); @@ -70,6 +87,8 @@ function cleanHeader($headerFile) { $extern = $matches[1]; + $externs[] = $extern; + if (strstr($body, "$extern") === FALSE) { if (!$hasChanges) @@ -80,6 +99,56 @@ function cleanHeader($headerFile) echo "\t- $line"; unset($header[$i]); } + + if (!in_array($line, $lines)) + { + $lines[] = $line; + } + else + { + if (!$hasChanges) + { + echo "$headerFile\n"; + $hasChanges = true; + } + echo "\t- $line"; + unset($header[$i]); + } + } + + preg_match($define_pattern, $line, $matches); + + if (count($matches) == 2) + { + $extern = $matches[1]; + + $externs[] = $extern; + + if (strstr($body, "$extern") === FALSE) + { + if (!$hasChanges) + { + echo "$headerFile\n"; + $hasChanges = true; + } + echo "\t- $line"; + unset($header[$i]); + } + + if (!in_array($line, $lines)) + { + $lines[] = $line; + } + else + { + if (!$hasChanges) + { + echo "$headerFile\n"; + $hasChanges = true; + } + echo "\t- $line"; + unset($header[$i]); + } } } @@ -95,17 +164,20 @@ function cleanHeader($headerFile) function recurseDir($dir) { - $files = array_diff(scandir($dir), array('..', '.')); - - foreach ($files as $file) + if ($dir != "../src/json") { - if (is_dir("$dir/$file")) + $files = array_diff(scandir($dir), array('..', '.')); + + foreach ($files as $file) { - recurseDir("$dir/$file"); - } - else if (strstr($file, ".h") !== FALSE) - { - cleanHeader("$dir/$file"); + if (is_dir("$dir/$file")) + { + recurseDir("$dir/$file"); + } + else if (strstr($file, ".h") !== FALSE) + { + cleanHeader("$dir/$file"); + } } } }