diff options
author | truelight <truelight@openttd.org> | 2006-08-24 12:08:25 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2006-08-24 12:08:25 +0000 |
commit | 76bcaba6011b4a3a3f2c3dcd65e3438bb46b79f0 (patch) | |
tree | 90e4385ba5c5f0ec5803661e46a5dbdf086057c6 | |
parent | d14ac4478d35f7ae9b7ced6e78673a27a85fc878 (diff) | |
download | openttd-76bcaba6011b4a3a3f2c3dcd65e3438bb46b79f0.tar.xz |
(svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | langs.vcproj | 52 | ||||
-rw-r--r-- | langs_vs80.vcproj | 52 | ||||
-rw-r--r-- | strgen/strgen.c | 129 | ||||
-rw-r--r-- | string.c | 26 | ||||
-rw-r--r-- | win32.c | 21 |
6 files changed, 170 insertions, 118 deletions
@@ -879,17 +879,17 @@ $(TTD): $(OBJS) $(MAKE_CONFIG) $(Q)$(CXX_TARGET) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@ endif -$(STRGEN): strgen/strgen.c endian_host.h +$(STRGEN): strgen/strgen.c string.c endian_host.h @echo '===> Compiling and Linking $@' - $(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@ + $(Q)$(CC_HOST) $(CFLAGS_HOST) -DSTRGEN strgen/strgen.c string.c -o $@ table/strings.h: lang/english.txt $(STRGEN) @echo '===> Generating $@' - $(Q)$(STRGEN) + $(Q)$(STRGEN) -s lang -d table lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt @echo '===> Compiling language $(*F)' - $(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS) || rm -f $@ + $(Q)$(STRGEN) $(STRGEN_FLAGS) -s lang -d lang $< $(LANG_ERRORS) || rm -f $@ # stupid KUDr doesn't know how to setup unittest dependencies (so rm,cp,rm) # please don't blame him and repair it: diff --git a/langs.vcproj b/langs.vcproj index 5633d4a10..db053ccf9 100644 --- a/langs.vcproj +++ b/langs.vcproj @@ -31,7 +31,7 @@ <Tool Name="VCPreBuildEventTool" Description="Generating strings.h" - CommandLine="strgen\debug\strgen.exe"/> + CommandLine="strgen\debug\strgen.exe -s lang -d table"/> </Configuration> </Configurations> <References> @@ -44,7 +44,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating american language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\american.lng"/> </FileConfiguration> @@ -56,7 +56,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating brazilian_portuguese language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\brazilian_portuguese.lng"/> </FileConfiguration> @@ -68,7 +68,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating catalan language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\catalan.lng"/> </FileConfiguration> @@ -80,7 +80,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating czech language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\czech.lng"/> </FileConfiguration> @@ -92,7 +92,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating danish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\danish.lng"/> </FileConfiguration> @@ -104,7 +104,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating dutch language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\dutch.lng"/> </FileConfiguration> @@ -116,7 +116,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating english language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\english.lng"/> </FileConfiguration> @@ -128,7 +128,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating estonian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)"" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"" Outputs="lang\estonian.lng"/> </FileConfiguration> </File> @@ -139,7 +139,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating finnish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\finnish.lng"/> </FileConfiguration> @@ -151,7 +151,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating french language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\french.lng"/> </FileConfiguration> @@ -163,7 +163,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating galician language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\galician.lng"/> </FileConfiguration> @@ -175,7 +175,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating german language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\german.lng"/> </FileConfiguration> @@ -187,7 +187,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating hungarian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\hungarian.lng"/> </FileConfiguration> @@ -199,7 +199,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating icelandic language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\icelandic.lng"/> </FileConfiguration> @@ -211,7 +211,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating italian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\italian.lng"/> </FileConfiguration> @@ -224,7 +224,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating lithuanian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\lithuanian.lng"/> </FileConfiguration> @@ -236,7 +236,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating norwegian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\norwegian.lng"/> </FileConfiguration> @@ -248,7 +248,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating Original Vehicle names file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\origveh.lng"/> </FileConfiguration> @@ -260,7 +260,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating polish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\polish.lng"/> </FileConfiguration> @@ -272,7 +272,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating portuguese language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\portuguese.lng"/> </FileConfiguration> @@ -284,7 +284,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating romanian language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\romanian.lng"/> </FileConfiguration> @@ -296,7 +296,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating slovak language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\slovak.lng"/> </FileConfiguration> @@ -308,7 +308,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating spanish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\spanish.lng"/> </FileConfiguration> @@ -320,7 +320,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating swedish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)" " Outputs="lang\swedish.lng"/> </FileConfiguration> @@ -332,7 +332,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating turkish language file" - CommandLine="strgen\debug\strgen.exe "$(InputPath)"" + CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"" Outputs="lang\turkish.lng"/> </FileConfiguration> </File> diff --git a/langs_vs80.vcproj b/langs_vs80.vcproj index 31f5c3c36..e7c7e5ae4 100644 --- a/langs_vs80.vcproj +++ b/langs_vs80.vcproj @@ -27,7 +27,7 @@ <Tool
Name="VCPreBuildEventTool"
Description="Generating strings.h"
- CommandLine="strgen\debug\strgen.exe"
+ CommandLine="strgen\debug\strgen.exe -s lang -d table"
/>
<Tool
Name="VCCustomBuildTool"
@@ -54,7 +54,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating american language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\american.lng"
/>
</FileConfiguration>
@@ -68,7 +68,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating brazilian_portuguese language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\brazilian_portuguese.lng"
/>
</FileConfiguration>
@@ -82,7 +82,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating catalan language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\catalan.lng"
/>
</FileConfiguration>
@@ -96,7 +96,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating czech language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\czech.lng"
/>
</FileConfiguration>
@@ -110,7 +110,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating danish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\danish.lng"
/>
</FileConfiguration>
@@ -124,7 +124,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating dutch language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\dutch.lng"
/>
</FileConfiguration>
@@ -138,7 +138,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating english language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\english.lng"
/>
</FileConfiguration>
@@ -152,7 +152,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating estonian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\estonian.lng"
/>
</FileConfiguration>
@@ -166,7 +166,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating finnish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\finnish.lng"
/>
</FileConfiguration>
@@ -180,7 +180,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating french language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\french.lng"
/>
</FileConfiguration>
@@ -194,7 +194,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating galician language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\galician.lng"
/>
</FileConfiguration>
@@ -208,7 +208,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating german language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\german.lng"
/>
</FileConfiguration>
@@ -222,7 +222,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating hungarian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\hungarian.lng"
/>
</FileConfiguration>
@@ -236,7 +236,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating icelandic language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\icelandic.lng"
/>
</FileConfiguration>
@@ -250,7 +250,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating italian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\italian.lng"
/>
</FileConfiguration>
@@ -265,7 +265,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating lithuanian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\lithuanian.lng"
/>
</FileConfiguration>
@@ -279,7 +279,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating norwegian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\norwegian.lng"
/>
</FileConfiguration>
@@ -293,7 +293,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating Original Vehicle names file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\origveh.lng"
/>
</FileConfiguration>
@@ -307,7 +307,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating polish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\polish.lng"
/>
</FileConfiguration>
@@ -321,7 +321,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating portuguese language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\portuguese.lng"
/>
</FileConfiguration>
@@ -335,7 +335,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating romanian language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\romanian.lng"
/>
</FileConfiguration>
@@ -349,7 +349,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating slovak language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\slovak.lng"
/>
</FileConfiguration>
@@ -363,7 +363,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating spanish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\spanish.lng"
/>
</FileConfiguration>
@@ -377,7 +377,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating swedish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\swedish.lng"
/>
</FileConfiguration>
@@ -391,7 +391,7 @@ <Tool
Name="VCCustomBuildTool"
Description="Generating turkish language file"
- CommandLine="strgen\debug\strgen.exe "$(InputPath)"
"
+ CommandLine="strgen\debug\strgen.exe -s lang -d lang "$(InputPath)"
"
Outputs="lang\turkish.lng"
/>
</FileConfiguration>
diff --git a/strgen/strgen.c b/strgen/strgen.c index 6fbccfb24..1bf6cf984 100644 --- a/strgen/strgen.c +++ b/strgen/strgen.c @@ -1,9 +1,14 @@ /* $Id$ */ -#define STRGEN +#if defined(WIN32) || defined(WIN64) || defined(__CYGWIN__) +#define WIN32 +#else +#define UNIX +#endif #include "../stdafx.h" #include "../macros.h" +#include "../string.h" #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -13,12 +18,16 @@ #include <unistd.h> #endif +#if defined WIN32 || defined __WATCOMC__ +#include <direct.h> +#endif /* WIN32 || __WATCOMC__ */ + #ifdef __MORPHOS__ #ifdef stderr #undef stderr #endif #define stderr stdout -#endif // __MORPHOS__ +#endif /* __MORPHOS__ */ #ifdef __WATCOMC__ uint _map_log_x; // an unpleasant hack required because Watcom is insisting on @@ -26,7 +35,7 @@ uint _map_size_y; uint _map_tile_mask; uint _map_size; -#endif +#endif /* __WATCOMC__ */ /* Compiles a list of strings into a compiled string list */ @@ -160,7 +169,7 @@ static void CDECL Warning(const char *s, ...) char buf[1024]; va_list va; va_start(va, s); - vsprintf(buf, s, va); + vsnprintf(buf, lengthof(buf), s, va); va_end(va); fprintf(stderr, "%s" LINE_NUM_FMT ": Warning: %s\n", _file, _cur_line, buf); _warnings++; @@ -172,7 +181,7 @@ static void CDECL Error(const char *s, ...) char buf[1024]; va_list va; va_start(va, s); - vsprintf(buf, s, va); + vsnprintf(buf, lengthof(buf), s, va); va_end(va); fprintf(stderr, "%s" LINE_NUM_FMT ": Error: %s\n", _file, _cur_line, buf); _errors++; @@ -184,21 +193,12 @@ static void NORETURN CDECL Fatal(const char *s, ...) char buf[1024]; va_list va; va_start(va, s); - vsprintf(buf, s, va); + vsnprintf(buf, lengthof(buf), s, va); va_end(va); fprintf(stderr, "%s" LINE_NUM_FMT ": FATAL: %s\n", _file, _cur_line, buf); exit(1); } - -static void ttd_strlcpy(char *dst, const char *src, size_t len) -{ - assert(len > 0); - while (--len > 0 && *src != '\0') *dst++ = *src++; - *dst = '\0'; -} - - static void PutByte(byte c) { if (_put_pos == lengthof(_put_buf)) Fatal("Put buffer too small"); @@ -1205,9 +1205,36 @@ static void WriteLangfile(const char *filename, int show_todo) fclose(f); } +/** Multi-OS mkdirectory function */ +static inline void ottd_mkdir(const char *directory) +{ +#if defined(WIN32) || defined(__WATCOMC__) + mkdir(directory); +#else + mkdir(directory, 0755); +#endif +} + +/** Create a path consisting of an already existing path, a possible + * path seperator and the filename. The seperator is only appended if the path + * does not already end with a seperator */ +static inline char *mkpath(char *buf, size_t buflen, const char *path, const char *file) +{ + char *p; + ttd_strlcpy(buf, path, buflen); // copy directory into buffer + + p = strchr(buf, '\0'); // add path seperator if necessary + if (p[-1] != PATHSEPCHAR && (size_t)(p - buf) + 1 < buflen) *p++ = PATHSEPCHAR; + ttd_strlcpy(p, file, buflen - (size_t)(p - buf)); // catenate filename at end of buffer + return buf; +} + int CDECL main(int argc, char* argv[]) { + char pathbuf[256]; + const char *src_dir, *dest_dir; + int show_todo = 0; if (argc > 1 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { @@ -1215,14 +1242,12 @@ int CDECL main(int argc, char* argv[]) return 0; } - if (argc > 1 && - (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0)) { + if (argc > 1 && (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0)) { show_todo = 1; argc--, argv++; } - if (argc > 1 && - (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0)) { + if (argc > 1 && (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0)) { show_todo = 2; argc--, argv++; } @@ -1235,45 +1260,69 @@ int CDECL main(int argc, char* argv[]) puts( "strgen - $Revision$\n" " -v | --version print version information and exit\n" - " -h | -? | --help print this help message and exit\n" " -t | --todo replace any untranslated strings with '<TODO>'\n" " -w | --warning print a warning for any untranslated strings\n" - " Run without parameters strgen will search for lang/english.txt and\n" - " parse it. Passing an argument, strgen will translate that language\n" - " file with lang/english.txt as a reference." + " -h | -? | --help print this help message and exit\n" + " -s | --source_dir search for english.txt in the specified directory\n" + " -d | --dest_dir put output file in the specified directory, create if needed\n" + " Run without parameters and strgen will search for english.txt and parse it,\n" + " creating strings.h. Passing an argument, strgen will translate that language\n" + " file using english.txt as a reference and output <language>.lng." ); return 0; } + src_dir = dest_dir = "."; + if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) { + src_dir = dest_dir = argv[2]; // if dest_dir is not specified, it equals src_dir + argc -= 2, argv += 2; + } + + if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) { + dest_dir = argv[2]; + argc -= 2, argv += 2; + } + + /* strgen has two modes of operation. If no (free) arguments are passed + * strgen generates strings.h to the destination directory. If it is supplied + * with a (free) parameter the program will translate that language to destination + * directory. As input english.txt is parsed from the source directory */ if (argc == 1) { + mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt"); + + /* parse master file */ _masterlang = true; - // parse master file - ParseFile("lang/english.txt", true); + ParseFile(pathbuf, true); MakeHashOfStrings(); if (_errors) return 1; - // write english.lng and strings.h - - WriteLangfile("lang/english.lng", 0); - WriteStringsH("table/strings.h"); + /* write strings.h */ + ottd_mkdir(dest_dir); + mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h"); + WriteStringsH(pathbuf); } else if (argc == 2) { - char buf[256]; - char* r; + char *r; + mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt"); + + /* parse master file and check if target file is correct */ _masterlang = false; - ParseFile("lang/english.txt", true); + ParseFile(pathbuf, true); MakeHashOfStrings(); - ParseFile(argv[1], false); - + ParseFile(argv[1], false); // target file if (_errors) return 1; - strcpy(buf, argv[1]); - r = strrchr(buf, '.'); - if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(buf, 0); - strcpy(r, ".lng"); - WriteLangfile(buf, show_todo); + /* get the targetfile, strip any directories and append to destination path */ + r = strrchr(argv[1], PATHSEPCHAR); + mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]); + + /* rename the .txt (input-extension) to .lng */ + r = strrchr(pathbuf, '.'); + if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0'); + ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf)); + WriteLangfile(pathbuf, show_todo); } else { - fprintf(stderr, "invalid arguments\n"); + fprintf(stderr, "Invalid arguments\n"); } return 0; @@ -52,7 +52,7 @@ char* CDECL str_fmt(const char* str, ...) char* p; va_start(va, str); - len = vsprintf(buf, str, va); + len = vsnprintf(buf, lengthof(buf), str, va); va_end(va); p = malloc(len + 1); if (p != NULL) memcpy(p, buf, len + 1); @@ -101,3 +101,27 @@ void strtolower(char *str) { for (; *str != '\0'; str++) *str = tolower(*str); } + +#ifdef WIN32 +int CDECL snprintf(char *str, size_t size, const char *format, ...) +{ + va_list ap; + int ret; + + va_start(ap, format); + ret = vsnprintf(str, size, format, ap); + va_end(ap); + return ret; +} + +#ifdef _MSC_VER +int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int ret; + ret = _vsnprintf(str, size, format, ap); + if (ret < 0) str[size - 1] = '\0'; + return ret; +} +#endif /* _MSC_VER */ + +#endif /* WIN32 */ @@ -917,27 +917,6 @@ void DeterminePaths(void) CreateDirectory(_path.heightmap_dir, NULL); } -int CDECL snprintf(char *str, size_t size, const char *format, ...) -{ - va_list ap; - int ret; - - va_start(ap, format); - ret = vsnprintf(str, size, format, ap); - va_end(ap); - return ret; -} - -#ifdef _MSC_VER -int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) -{ - int ret; - ret = _vsnprintf(str, size, format, ap); - if (ret < 0) str[size - 1] = '\0'; - return ret; -} -#endif - /** * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard * and append this up to the maximum length (either absolute or screenlength). If maxlength |