diff options
author | Benjamin Barenblat <bbarenblat@gmail.com> | 2021-11-23 23:13:26 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbarenblat@gmail.com> | 2021-11-23 23:13:26 -0500 |
commit | e5df1aafb6d1346207343ccb858fa373e6b86301 (patch) | |
tree | fb26f0091dda7dd69d48d6b06169ea618332b99e /Tools |
Check in the Palm OS Emulator, version 3.5 (2001). These files come from
the tarball present in the Debian archives [1]. The SHA-256 digest of
the tarball, c5e0d23424e88525bfba0ecdf0a432a8d93c885d04740df06a9eeee44e5f25e4,
matches the digest preserved in the FreeBSD ports tree [2], giving
further confidence that these files are as distributed by upstream.
[1] http://archive.debian.org/debian/pool/contrib/p/pose/
[2] https://svnweb.freebsd.org/ports/head/palm/pose/distinfo?revision=271305&view=markup&pathrev=282162
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/Strings2Resource.pl | 248 | ||||
-rwxr-xr-x | Tools/s2r.sh | 6 |
2 files changed, 254 insertions, 0 deletions
diff --git a/Tools/Strings2Resource.pl b/Tools/Strings2Resource.pl new file mode 100644 index 0000000..3950680 --- /dev/null +++ b/Tools/Strings2Resource.pl @@ -0,0 +1,248 @@ +# -*- mode: Perl; tab-width: 4 -*- + +use File::Basename; + +$language = "ENGLISH"; + +$input = $ARGV[0]; +$output = $ARGV[1]; + +if (not @ARGV or not -f $input) { + die "Usage: $0 <full path of Strings.txt> <full path to output dir>\n"; +} + + +$output_rez = $output . "Strings.cpp"; +$output_cpp = $output . "ResStrings.cpp"; +$output_vcpp = $output . "Strings.rc"; + + +@modes = ( +{ + output => $output_rez, + + maccreator => 'CWIE', + + prefix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#/* This file is generated from SrcShared:Strings.txt */ +# +#type 'STRA' { +# integer = $$CountOf(SomeArray); +# wide array SomeArray { +# integer; +# wstring; +# }; +#}; +# +#resource 'STRA' (1000) {{ +-EOT- + + suffix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#}}; +# +-EOT- + + print => sub { "\t$_[0], \"" . backslash_quotes($_[1]) . "\";" }, + + prefix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#/* This file is generated from SrcShared/Strings.txt */ +# +##include <map> +# +#static std::map<int, const char*> _ResStrMap; +# +#struct item +#{ +# int key; +# const char* value; +#}; +# +##pragma mpwc_newline on +# +#static const struct item _ResStrTable[] = { +-EOT- + + suffix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +# { 0, NULL } +#}; +# +#static void _ResStrTableInit (void) +#{ +# for (const struct item* it = _ResStrTable; it->value != NULL; it++) +# { +# _ResStrMap[it->key] = it->value; +# } +#} +# +# +#const char* _ResGetString(int idx); +#const char* _ResGetString(int idx) +#{ +# static int inited; +# if (!inited) +# { +# inited = 1; +# _ResStrTableInit(); +# } +# +# return _ResStrMap[idx]; +#} +-EOT- + + print => sub { "\t{ $_[0], \"" . backslash_quotes($_[1]) . "\" }," } +}, + +{ + output => $output_cpp, + + prefix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#/* This file is generated from SrcShared/Strings.txt */ +# +##include <map> +# +#static std::map<int, const char*> _ResStrMap; +# +#struct item +#{ +# int key; +# const char* value; +#}; +# +#static const struct item _ResStrTable[] = { +-EOT- + + suffix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +# { 0, NULL } +#}; +# +#static void _ResStrTableInit (void) +#{ +# for (const struct item* it = _ResStrTable; it->value != NULL; it++) +# { +# _ResStrMap[it->key] = it->value; +# } +#} +# +# +#const char* _ResGetString(int idx) +#{ +# static int inited; +# if (!inited) +# { +# inited = 1; +# _ResStrTableInit(); +# } +# +# return _ResStrMap[idx]; +#} +-EOT- + + print => sub { "\t{ $_[0], \"" . backslash_quotes(translate_high_ascii(1, $_[1])) . "\" }," } +}, + +{ + output => $output_vcpp, + + prefix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#/* This file is generated from SrcShared/Strings.txt */ +# +#STRINGTABLE DISCARDABLE +#BEGIN +-EOT- + + suffix => sub { local($_); $_=<<'-EOT-'; s/^#//gm; $_ }, +#END +-EOT- + + print => sub { "\t$_[0]\t\"" . double_quotes(translate_high_ascii(0, $_[1])) . "\"" } +} +); + +foreach $mode (@modes) { + + open (I, "<$input") or die "Unable to open $input: $!\n"; + open (O, ">$mode->{output}") or next; + + $text = ""; + $started = 0; + $id = ""; + $text = ""; + + while (<I>) { + if (/^\t(.+)/ and $text) { + $text .= $1; + next; + } + + print O &{$mode->{print}}($id,$text) if $text; + $text = ""; + + if (/^START$/) { + print O &{$mode->{prefix}}(); + $started = 1; + } elsif (/^END$/) { + print O &{$mode->{suffix}}(); + last; + } elsif ($started and /^([A-Z]+)=(.+)/) { + $id = $2 if $1 eq "ID"; + $text = $2 if $1 eq $language; + } else { + print O; + } + } + + if ($^O =~ /MacOS/i and $mode->{maccreator}) { + MacPerl::SetFileInfo($mode->{maccreator}, 'TEXT', $mode->{output}); + } + + close (O); + close (I); +} + + +sub backslash_quotes +{ + local($_)=@_; + s/\"/\\\"/g; # Turn a " into \" + return $_; +} + +sub double_quotes +{ + local($_)=@_; + s/\"/\"\"/g; # Turn a " into "" + return $_; +} + +sub translate_high_ascii +{ + local($unix, $_) = @_; + # Translate Macintosh High Ascii characters + # into the equivalents for Windows and Unix. + + # (Note: I tried turning the curly quotes into + # the equivalent on Windows, but they just looked + # really bad in dialogs, so I now turn them into + # straight quotes.) + + s/Ó/\"/g; # Turn Ó into " + s/Ò/\"/g; # Turn Ò into " + s/Õ/\'/g; # Turn Õ into ' + s/Ô/\'/g; # Turn Ô into ' + s/É/\.\.\./g; # Turn É into ... + s/ª/\(TM)/g; # Turn ª into (TM) + + if (!$unix) + { + s/¨/\®/g; # Turn ¨ into ® + } + else + { + s/¨/(R)/g; # Turn ¨ into (R) + s/©/(c)/g; # Turn © into (c) + } + + return $_; +} + + diff --git a/Tools/s2r.sh b/Tools/s2r.sh new file mode 100755 index 0000000..36224f2 --- /dev/null +++ b/Tools/s2r.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +perl ../Tools/Strings2Resource.pl ../SrcShared/Strings.txt + + + |