mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r22102) -Codechange: Also use the getopt function in strgen.
This commit is contained in:
parent
41a67a9b94
commit
ff1e0a3ed3
@ -54,11 +54,15 @@ alloc_func.o: $(SRC_DIR)/core/alloc_func.cpp endian_host.h
|
|||||||
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
|
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
|
||||||
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
|
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
|
||||||
|
|
||||||
|
getoptdata.o: $(SRC_DIR)/misc/getoptdata.cpp $(SRC_DIR)/misc/getoptdata.h
|
||||||
|
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/misc/%.cpp=%.cpp)'
|
||||||
|
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
|
||||||
|
|
||||||
lang/english.txt: $(LANG_DIR)/english.txt
|
lang/english.txt: $(LANG_DIR)/english.txt
|
||||||
$(Q)mkdir -p lang
|
$(Q)mkdir -p lang
|
||||||
$(Q)cp $(LANG_DIR)/english.txt lang/english.txt
|
$(Q)cp $(LANG_DIR)/english.txt lang/english.txt
|
||||||
|
|
||||||
$(STRGEN): alloc_func.o string.o strgen.o
|
$(STRGEN): alloc_func.o string.o strgen.o getoptdata.o
|
||||||
$(E) '$(STAGE) Compiling and Linking $@'
|
$(E) '$(STAGE) Compiling and Linking $@'
|
||||||
$(Q)$(CXX_BUILD) $(LDFLAGS_BUILD) $^ -o $@
|
$(Q)$(CXX_BUILD) $(LDFLAGS_BUILD) $^ -o $@
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@
|
|||||||
<ClCompile Include="..\src\core\alloc_func.cpp" />
|
<ClCompile Include="..\src\core\alloc_func.cpp" />
|
||||||
<ClCompile Include="..\src\strgen\strgen.cpp" />
|
<ClCompile Include="..\src\strgen\strgen.cpp" />
|
||||||
<ClCompile Include="..\src\string.cpp" />
|
<ClCompile Include="..\src\string.cpp" />
|
||||||
|
<ClCompile Include="..\src\misc\getoptdata.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\core\alloc_func.hpp" />
|
<ClInclude Include="..\src\core\alloc_func.hpp" />
|
||||||
@ -84,6 +85,7 @@
|
|||||||
<ClInclude Include="..\src\core\endian_func.hpp" />
|
<ClInclude Include="..\src\core\endian_func.hpp" />
|
||||||
<ClInclude Include="..\src\stdafx.h" />
|
<ClInclude Include="..\src\stdafx.h" />
|
||||||
<ClInclude Include="..\src\string.h" />
|
<ClInclude Include="..\src\string.h" />
|
||||||
|
<ClInclude Include="..\src\misc\getoptdata.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
<ClCompile Include="..\src\string.cpp">
|
<ClCompile Include="..\src\string.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\misc\getoptdata.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\core\alloc_func.hpp" />
|
<ClInclude Include="..\src\core\alloc_func.hpp" />
|
||||||
@ -24,5 +27,6 @@
|
|||||||
<ClInclude Include="..\src\core\endian_func.hpp" />
|
<ClInclude Include="..\src\core\endian_func.hpp" />
|
||||||
<ClInclude Include="..\src\stdafx.h" />
|
<ClInclude Include="..\src\stdafx.h" />
|
||||||
<ClInclude Include="..\src\string.h" />
|
<ClInclude Include="..\src\string.h" />
|
||||||
|
<ClInclude Include="..\src\misc\getoptdata.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -125,6 +125,10 @@
|
|||||||
RelativePath="..\src\string.cpp"
|
RelativePath="..\src\string.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\misc\getoptdata.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\core\alloc_func.hpp"
|
RelativePath="..\src\core\alloc_func.hpp"
|
||||||
@ -150,6 +154,10 @@
|
|||||||
RelativePath="..\src\string.h"
|
RelativePath="..\src\string.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\misc\getoptdata.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
</Globals>
|
</Globals>
|
||||||
|
@ -125,6 +125,10 @@
|
|||||||
RelativePath="..\src\string.cpp"
|
RelativePath="..\src\string.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\misc\getoptdata.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\core\alloc_func.hpp"
|
RelativePath="..\src\core\alloc_func.hpp"
|
||||||
@ -150,6 +154,10 @@
|
|||||||
RelativePath="..\src\string.h"
|
RelativePath="..\src\string.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\misc\getoptdata.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
</Globals>
|
</Globals>
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "../string_func.h"
|
#include "../string_func.h"
|
||||||
#include "../strings_type.h"
|
#include "../strings_type.h"
|
||||||
#include "../language.h"
|
#include "../language.h"
|
||||||
|
#include "../misc/getoptdata.h"
|
||||||
#include "../table/control_codes.h"
|
#include "../table/control_codes.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -1193,19 +1194,38 @@ static inline char *replace_pathsep(char *s)
|
|||||||
static inline char *replace_pathsep(char *s) { return s; }
|
static inline char *replace_pathsep(char *s) { return s; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Options of strgen. */
|
||||||
|
static const OptionData _opts[] = {
|
||||||
|
GETOPT_NOVAL( 'v', "--version"),
|
||||||
|
GETOPT_GENERAL('C', '\0', "-export-commands", ODF_NO_VALUE),
|
||||||
|
GETOPT_GENERAL('L', '\0', "-export-plurals", ODF_NO_VALUE),
|
||||||
|
GETOPT_GENERAL('P', '\0', "-export-pragmas", ODF_NO_VALUE),
|
||||||
|
GETOPT_NOVAL( 't', "--todo"),
|
||||||
|
GETOPT_NOVAL( 'w', "--warning"),
|
||||||
|
GETOPT_NOVAL( 'h', "--help"),
|
||||||
|
GETOPT_GENERAL('h', '?', NULL, ODF_NO_VALUE),
|
||||||
|
GETOPT_VALUE( 's', "--source_dir"),
|
||||||
|
GETOPT_VALUE( 'd', "--dest_dir"),
|
||||||
|
GETOPT_END(),
|
||||||
|
};
|
||||||
|
|
||||||
int CDECL main(int argc, char *argv[])
|
int CDECL main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char pathbuf[MAX_PATH];
|
char pathbuf[MAX_PATH];
|
||||||
const char *src_dir = ".";
|
const char *src_dir = ".";
|
||||||
const char *dest_dir = NULL;
|
const char *dest_dir = NULL;
|
||||||
|
|
||||||
while (argc > 1 && *argv[1] == '-') {
|
GetOptData mgo(argc - 1, argv + 1, _opts);
|
||||||
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
|
for (;;) {
|
||||||
|
int i = mgo.GetOpt();
|
||||||
|
if (i == -1) break;
|
||||||
|
|
||||||
|
switch (i) {
|
||||||
|
case 'v':
|
||||||
puts("$Revision$");
|
puts("$Revision$");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-export-commands") == 0) {
|
case 'C':
|
||||||
printf("args\tflags\tcommand\treplacement\n");
|
printf("args\tflags\tcommand\treplacement\n");
|
||||||
for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
|
for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
|
||||||
char flags;
|
char flags;
|
||||||
@ -1231,38 +1251,31 @@ int CDECL main(int argc, char *argv[])
|
|||||||
printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
|
printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-export-plurals") == 0) {
|
case 'L':
|
||||||
printf("count\tdescription\n");
|
printf("count\tdescription\n");
|
||||||
for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
|
for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
|
||||||
printf("%i\t\"%s\"\n", pf->plural_count, pf->description);
|
printf("%i\t\"%s\"\n", pf->plural_count, pf->description);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-export-pragmas") == 0) {
|
case 'P':
|
||||||
printf("name\tflags\tdefault\tdescription\n");
|
printf("name\tflags\tdefault\tdescription\n");
|
||||||
for (size_t i = 0; i < lengthof(_pragmas); i++) {
|
for (size_t i = 0; i < lengthof(_pragmas); i++) {
|
||||||
printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
|
printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
|
||||||
_pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]);
|
_pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0) {
|
case 't':
|
||||||
_show_todo |= 1;
|
_show_todo |= 1;
|
||||||
argc--, argv++;
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0) {
|
case 'w':
|
||||||
_show_todo |= 2;
|
_show_todo |= 2;
|
||||||
argc--, argv++;
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) {
|
case 'h':
|
||||||
puts(
|
puts(
|
||||||
"strgen - $Revision$\n"
|
"strgen - $Revision$\n"
|
||||||
" -v | --version print version information and exit\n"
|
" -v | --version print version information and exit\n"
|
||||||
@ -1279,23 +1292,20 @@ int CDECL main(int argc, char *argv[])
|
|||||||
" file using english.txt as a reference and output <language>.lng."
|
" file using english.txt as a reference and output <language>.lng."
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) {
|
case 's':
|
||||||
src_dir = replace_pathsep(argv[2]);
|
src_dir = replace_pathsep(mgo.opt);
|
||||||
argc -= 2, argv += 2;
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) {
|
case 'd':
|
||||||
dest_dir = replace_pathsep(argv[2]);
|
dest_dir = replace_pathsep(mgo.opt);
|
||||||
argc -= 2, argv += 2;
|
break;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
case -2:
|
||||||
fprintf(stderr, "Invalid arguments\n");
|
fprintf(stderr, "Invalid arguments\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
|
if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
|
||||||
|
|
||||||
@ -1303,7 +1313,7 @@ int CDECL main(int argc, char *argv[])
|
|||||||
* strgen generates strings.h to the destination directory. If it is supplied
|
* strgen generates strings.h to the destination directory. If it is supplied
|
||||||
* with a (free) parameter the program will translate that language to destination
|
* with a (free) parameter the program will translate that language to destination
|
||||||
* directory. As input english.txt is parsed from the source directory */
|
* directory. As input english.txt is parsed from the source directory */
|
||||||
if (argc == 1) {
|
if (mgo.numleft == 0) {
|
||||||
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
||||||
|
|
||||||
/* parse master file */
|
/* parse master file */
|
||||||
@ -1316,7 +1326,7 @@ int CDECL main(int argc, char *argv[])
|
|||||||
ottd_mkdir(dest_dir);
|
ottd_mkdir(dest_dir);
|
||||||
mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h");
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h");
|
||||||
WriteStringsH(pathbuf);
|
WriteStringsH(pathbuf);
|
||||||
} else if (argc == 2) {
|
} else if (mgo.numleft == 1) {
|
||||||
char *r;
|
char *r;
|
||||||
|
|
||||||
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
||||||
@ -1325,12 +1335,12 @@ int CDECL main(int argc, char *argv[])
|
|||||||
_masterlang = false;
|
_masterlang = false;
|
||||||
ParseFile(pathbuf, true);
|
ParseFile(pathbuf, true);
|
||||||
MakeHashOfStrings();
|
MakeHashOfStrings();
|
||||||
ParseFile(replace_pathsep(argv[1]), false); // target file
|
ParseFile(replace_pathsep(mgo.argv[0]), false); // target file
|
||||||
if (_errors) return 1;
|
if (_errors) return 1;
|
||||||
|
|
||||||
/* get the targetfile, strip any directories and append to destination path */
|
/* get the targetfile, strip any directories and append to destination path */
|
||||||
r = strrchr(argv[1], PATHSEPCHAR);
|
r = strrchr(mgo.argv[0], PATHSEPCHAR);
|
||||||
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]);
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[0]);
|
||||||
|
|
||||||
/* rename the .txt (input-extension) to .lng */
|
/* rename the .txt (input-extension) to .lng */
|
||||||
r = strrchr(pathbuf, '.');
|
r = strrchr(pathbuf, '.');
|
||||||
|
Loading…
Reference in New Issue
Block a user