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 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);

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 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);

View File

@ -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;

View File

@ -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,13 +39,14 @@ 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);
@ -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]);
}
}
}
@ -94,6 +163,8 @@ function cleanHeader($headerFile)
}
function recurseDir($dir)
{
if ($dir != "../src/json")
{
$files = array_diff(scandir($dir), array('..', '.'));
@ -109,6 +180,7 @@ function recurseDir($dir)
}
}
}
}
if (isset($argv[1]))
{