Removed duplicate externs from headers.

This commit is contained in:
Steve 2016-05-06 16:14:41 +01:00
parent e27c60156e
commit 9063ec84a7
4 changed files with 83 additions and 14 deletions

View File

@ -34,7 +34,6 @@ extern char *readFile(char *filename);
extern long flagsToLong(char *flags, int *add); extern long flagsToLong(char *flags, int *add);
extern long lookup(char *name); extern long lookup(char *name);
extern void doAI(void); extern void doAI(void);
extern float getAngle(int x1, int y1, int x2, int y2);
extern float mod(float n, float x); extern float mod(float n, float x);
extern void applyFighterThrust(void); extern void applyFighterThrust(void);
extern void addLargeEngineEffect(void); extern void addLargeEngineEffect(void);

View File

@ -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 void blitRotated(SDL_Texture *texture, int x, int y, float angle);
extern char *getTranslatedString(char *string); extern char *getTranslatedString(char *string);
extern void addSmallExplosion(void); extern void addSmallExplosion(void);
extern void playBattleSound(int id, int x, int y);
extern void addDebris(int x, int y, int amount); extern void addDebris(int x, int y, int amount);
extern void runScriptFunction(char *format, ...); extern void runScriptFunction(char *format, ...);
extern void updateObjective(char *name, int type); extern void updateObjective(char *name, int type);

View File

@ -60,7 +60,6 @@ extern void clearInput(void);
extern void initTrophiesDisplay(void); extern void initTrophiesDisplay(void);
extern void drawTrophies(void); extern void drawTrophies(void);
extern void doTrophies(void); extern void doTrophies(void);
extern void destroyBattle(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;

View File

@ -30,6 +30,7 @@ function cleanHeader($headerFile)
$func_pattern = "/(([A-Z0-9_]+)\\()/i"; $func_pattern = "/(([A-Z0-9_]+)\\()/i";
$struct_pattern = "/([A-Z]+);/i"; $struct_pattern = "/([A-Z]+);/i";
$define_pattern = "/#define ([A-Z]+)/i";
$bodyFile = $headerFile; $bodyFile = $headerFile;
$bodyFile[strlen($bodyFile) - 1] = 'c'; $bodyFile[strlen($bodyFile) - 1] = 'c';
@ -38,13 +39,14 @@ function cleanHeader($headerFile)
{ {
$header = file($headerFile); $header = file($headerFile);
$body = file_get_contents($bodyFile); $body = file_get_contents($bodyFile);
$lines = [];
$i = 0; $i = 0;
$hasChanges = false; $hasChanges = false;
foreach ($header as $line) 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); preg_match($func_pattern, $line, $matches);
@ -62,6 +64,21 @@ function cleanHeader($headerFile)
echo "\t- $line"; echo "\t- $line";
unset($header[$i]); 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); preg_match($struct_pattern, $line, $matches);
@ -70,6 +87,8 @@ function cleanHeader($headerFile)
{ {
$extern = $matches[1]; $extern = $matches[1];
$externs[] = $extern;
if (strstr($body, "$extern") === FALSE) if (strstr($body, "$extern") === FALSE)
{ {
if (!$hasChanges) if (!$hasChanges)
@ -80,6 +99,56 @@ function cleanHeader($headerFile)
echo "\t- $line"; echo "\t- $line";
unset($header[$i]); 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) function recurseDir($dir)
{ {
$files = array_diff(scandir($dir), array('..', '.')); if ($dir != "../src/json")
foreach ($files as $file)
{ {
if (is_dir("$dir/$file")) $files = array_diff(scandir($dir), array('..', '.'));
foreach ($files as $file)
{ {
recurseDir("$dir/$file"); if (is_dir("$dir/$file"))
} {
else if (strstr($file, ".h") !== FALSE) recurseDir("$dir/$file");
{ }
cleanHeader("$dir/$file"); else if (strstr($file, ".h") !== FALSE)
{
cleanHeader("$dir/$file");
}
} }
} }
} }