Misc. tidying.

This commit is contained in:
Steve 2021-05-01 13:35:52 +01:00
parent 732a86aefd
commit 786df47e09
6 changed files with 1 additions and 504 deletions

2
.gitignore vendored
View File

@ -43,5 +43,5 @@ build/*
# Misc # Misc
.DS_Store .DS_Store
/.errors /.errors
tools

View File

@ -25,9 +25,7 @@ MAKEFLAGS += -j$(NPROCS)
CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" -DLOCALE_DIR=\"$(LOCALE_DIR)\" CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" -DLOCALE_DIR=\"$(LOCALE_DIR)\"
CXXFLAGS += -ansi -pedantic CXXFLAGS += -ansi -pedantic
CXXFLAGS += -g -lefence CXXFLAGS += -g -lefence
ifneq ("$(wildcard .errors)","")
CXXFLAGS += -Wall -Wempty-body -Werror -Wstrict-prototypes -Werror=maybe-uninitialized -Warray-bounds CXXFLAGS += -Wall -Wempty-body -Werror -Wstrict-prototypes -Werror=maybe-uninitialized -Warray-bounds
endif
LDFLAGS += `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm LDFLAGS += `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm

View File

@ -1,17 +0,0 @@
# PO file for TBFTSS : The Pandoran War
# Copyright 2015-2016, Stephen J Sweeney
# This file is distributed under the GNU GPL 3.0
# Email: stephenjsweeney@battleforthesolarsystem.com
# https://github.com/stephenjsweeney/tbftss
msgid ""
msgstr ""
"Project-Id-Version: TBFTSS: The Pandoran War\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: {POT_CREATION_DATE}\n"
"PO-Revision-Date: ???\n"
"Last-Translator: ???\n"
"Language-Team: ???\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@ -1,42 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright (C) 2015-2016 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
$reg = "/msgid \"(.*)\"/i";
$data = file_get_contents("../locale/tbftss.pot");
preg_match_all($reg, $data, $matches);
$words = [];
foreach ($matches[1] as $match)
{
$words[] = exec("echo \"$match\" | aspell list --encoding utf-8");
}
$words = array_unique($words);
print_r($words);
?>

View File

@ -1,267 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright (C) 2015-2019 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
$UPDATE_FILES = false;
function funcSort($a, $b)
{
$a = str_replace("*", "", $a);
$b = str_replace("*", "", $b);
$aParts = explode(" ", $a);
$bParts = explode(" ", $b);
return strcmp($aParts[2], $bParts[2]);
}
function updateExterns($header, $defines, $functions, $structs)
{
asort($defines);
usort($functions, "funcSort");
asort($structs);
$newHeader = [];
foreach ($header as $line)
{
$newHeader[] = $line;
}
if (count($defines) > 0)
{
$newHeader[] = "\n";
$newHeader = array_merge($newHeader, $defines);
}
if (count($functions) > 0)
{
$newHeader[] = "\n";
$newHeader = array_merge($newHeader, $functions);
}
if (count($structs) > 0)
{
$newHeader[] = "\n";
$newHeader = array_merge($newHeader, $structs);
}
return $newHeader;
}
function cleanHeader($headerFile)
{
global $UPDATE_FILES;
$func_pattern = "/(([A-Z0-9_]+)\\()/i";
$struct_pattern = "/([A-Z]+);/i";
$define_pattern = "/#define ([A-Z]+)/i";
$bodyFile = $headerFile;
$bodyFile[strlen($bodyFile) - 1] = 'c';
if (file_exists($bodyFile))
{
$header = file($headerFile);
$body = file_get_contents($bodyFile);
$isMain = strpos($body, "int main(");
$lines = [];
$defines = [];
$functions = [];
$structs = [];
$i = 0;
$hasChanges = false;
foreach ($header as $line)
{
if ((preg_match("/extern|define/", $line) || preg_match("/;$/", $line)))
{
preg_match($func_pattern, $line, $matches);
if (count($matches) == 3)
{
unset($header[$i]);
$extern = $matches[2];
if (!preg_match_all("/\b${extern}\b/", $body))
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
}
else if (!in_array($line, $lines))
{
$functions[] = $line;
}
}
preg_match($struct_pattern, $line, $matches);
if (count($matches) == 2)
{
unset($header[$i]);
$extern = $matches[1];
$externs[] = $extern;
if (!$isMain)
{
if (!preg_match_all("/\b${extern}\b/", $body))
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
}
else if (!in_array($line, $lines))
{
$structs[] = $line;
}
}
else if (!in_array($line, $lines))
{
$structs[] = $line;
}
}
preg_match($define_pattern, $line, $matches);
if (count($matches) == 2)
{
unset($header[$i]);
$extern = $matches[1];
$externs[] = $extern;
if (strstr($body, "$extern") === FALSE)
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
}
else if (!in_array($line, $lines))
{
$defines[] = $line;
}
}
}
$i++;
}
do
{
$wasBlank = false;
$line = trim(end($header));
if (strlen($line) == 0)
{
array_pop($header);
$wasBlank = true;
}
}
while ($wasBlank);
$defines = array_unique($defines);
$functions = array_unique($functions);
$structs = array_unique($structs);
$defines = alignDefines($defines);
$header = updateExterns($header, $defines, $functions, $structs);
if ($UPDATE_FILES)
{
file_put_contents($headerFile, $header);
}
}
}
function alignDefines($defines)
{
$newAligns = [];
$largest = 0;
$defineName;
$defineValue;
foreach ($defines as $define)
{
sscanf($define, "%*s %s", $defineName);
$largest = max($largest, strlen($defineName) + 4);
}
foreach ($defines as $define)
{
sscanf($define, "%*s %s %[^\n]", $defineName, $defineValue);
$newAligns[] = "#define " . str_pad($defineName, $largest, " ") . $defineValue . "\n";
}
return $newAligns;
}
function recurseDir($dir)
{
if ($dir != "../src/json")
{
$files = array_diff(scandir($dir), array('..', '.'));
foreach ($files as $file)
{
if (is_dir("$dir/$file"))
{
recurseDir("$dir/$file");
}
else if (strstr($file, ".h") !== FALSE && $file != 'i18n.h')
{
cleanHeader("$dir/$file");
}
}
}
}
if (isset($argv[1]))
{
$UPDATE_FILES = ($argv[1] == "-commit");
}
recurseDir("../src");
if (!$UPDATE_FILES)
{
echo "\nNo files updated. Use -commit to update headers\n";
}
?>

View File

@ -1,175 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright (C) 2015-2016 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
$strings = [];
function addString($string)
{
global $strings;
if ($string != "")
{
if (!in_array($string, $strings))
{
$strings[] = $string;
}
}
}
function extractC($filename)
{
$i = 0;
$lines = file($filename);
$reg = "(_\\(\"([^\\\"]*)\")";
foreach ($lines as $line)
{
$i++;
if (preg_match($reg, $line, $matches) > 0)
{
addString($matches[1]);
}
}
}
function extractJSON($filename)
{
$data = file_get_contents($filename);
$json = json_decode($data);
if (strpos($filename, "widget") !== false)
{
foreach ($json as $widget)
{
if (array_key_exists("text", $widget))
{
addString($widget->{"text"}, $filename);
}
}
}
else if (strpos($filename, "trophies") !== false)
{
foreach ($json as $trophy)
{
addString($trophy->{"title"});
addString($trophy->{"description"});
}
}
else if (strpos($filename, "missions") !== false)
{
addString($json->{"name"});
addString($json->{"description"});
if (array_key_exists("objectives", $json))
{
foreach ($json->{"objectives"} as $objective)
{
addString($objective->{"description"}, $filename);
}
}
if (array_key_exists("script", $json))
{
foreach ($json->{"script"} as $scripts)
{
foreach ($scripts->{"lines"} as $line)
{
if (strpos($line, "MSG_BOX") === 0 || strpos($line, "IMPORTANT_MSG_BOX") === 0)
{
$i = strpos($line, ";") + 1;
$line = substr($line, $i);
addString($line, $filename);
}
}
}
}
}
else if (strpos($filename, "challenges") !== false)
{
addString($json->{"description"});
}
else if (strpos($filename, "fighters") !== false)
{
addString($json->{"description"});
}
}
function recurseDir($dir)
{
$files = array_diff(scandir($dir), array('..', '.'));
foreach ($files as $file)
{
if (is_dir("$dir/$file"))
{
recurseDir("$dir/$file");
}
else if (strstr($file, ".c") !== FALSE)
{
extractC("$dir/$file");
}
else if (strstr($file, ".json") !== FALSE)
{
extractJSON("$dir/$file");
}
}
}
recurseDir("../src");
recurseDir("../data/widgets");
recurseDir("../data/missions");
recurseDir("../data/challenges");
recurseDir("../data/trophies");
recurseDir("../data/fighters");
$potHeader = file_get_contents("../tools/potHeader.txt");
$handle = fopen("../locale/tbftss.pot", "w");
$dateTime = date("Y-m-d H:i:sO");
$potHeader = str_replace("{POT_CREATION_DATE}", $dateTime, $potHeader);
fwrite($handle, "$potHeader\n");
foreach ($strings as $string)
{
fwrite($handle, "msgid \"$string\"\n");
fwrite($handle, "msgstr \"\"\n");
fwrite($handle, "\n");
}
fclose($handle);
?>