Codechange: rework how grf and ob[msg] are generated
For grfs, it now uses CMake scripts to do its job, and both grf files are split into their own folder to make more clear what is going on. Additionally, it no longer builds in-source (although the resulting grf is copied back in the source folder). For ob[msg] it now uses CMake scripts to generate the translation files; the result is no longer stored in-source (but in the build folder). Although all files are available to create the GRFs and basesets, it won't really work till CMake is introduced (which will happen in a few commits from here)desync-debugging
@ -0,0 +1,53 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a single baseset meta file with the correct translations.
|
||||||
|
#
|
||||||
|
|
||||||
|
set(ARGC 1)
|
||||||
|
set(ARG_READ NO)
|
||||||
|
|
||||||
|
# Read all the arguments given to CMake; we are looking for -- and everything
|
||||||
|
# that follows. Those are our language files.
|
||||||
|
while(ARGC LESS CMAKE_ARGC)
|
||||||
|
set(ARG ${CMAKE_ARGV${ARGC}})
|
||||||
|
|
||||||
|
if (ARG_READ)
|
||||||
|
list(APPEND LANG_SOURCE_FILES "${ARG}")
|
||||||
|
endif (ARG_READ)
|
||||||
|
|
||||||
|
if (ARG STREQUAL "--")
|
||||||
|
set(ARG_READ YES)
|
||||||
|
endif (ARG STREQUAL "--")
|
||||||
|
|
||||||
|
math(EXPR ARGC "${ARGC} + 1")
|
||||||
|
endwhile()
|
||||||
|
|
||||||
|
# Place holder format is @<ini_key>_<str_id>@
|
||||||
|
file(STRINGS "${BASESET_SOURCE_FILE}" PLACE_HOLDER REGEX "^@")
|
||||||
|
string(REGEX REPLACE "@([^_]+).*@" "\\1" INI_KEY "${PLACE_HOLDER}")
|
||||||
|
string(REGEX REPLACE "@[^_]+_(.*)@" "\\1" STR_ID "${PLACE_HOLDER}")
|
||||||
|
string(REGEX REPLACE "@(.*)@" "\\1" PLACE_HOLDER "${PLACE_HOLDER}")
|
||||||
|
|
||||||
|
# Get the translations
|
||||||
|
foreach(LANGFILE IN LISTS LANG_SOURCE_FILES)
|
||||||
|
file(STRINGS "${LANGFILE}" LANGLINES REGEX "^(##isocode|${STR_ID})" ENCODING UTF-8)
|
||||||
|
string(FIND "${LANGLINES}" "${STR_ID}" HAS_STR_ID)
|
||||||
|
if (HAS_STR_ID LESS 0)
|
||||||
|
continue()
|
||||||
|
endif (HAS_STR_ID LESS 0)
|
||||||
|
string(REGEX REPLACE "##isocode ([^;]+).*" "\\1" ISOCODE "${LANGLINES}")
|
||||||
|
if ("${ISOCODE}" STREQUAL "en_GB")
|
||||||
|
string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY} = \\1" LANGLINES "${LANGLINES}")
|
||||||
|
else()
|
||||||
|
string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}.${ISOCODE} = \\1" LANGLINES "${LANGLINES}")
|
||||||
|
endif()
|
||||||
|
list(APPEND ${PLACE_HOLDER} ${LANGLINES})
|
||||||
|
endforeach(LANGFILE)
|
||||||
|
list(SORT ${PLACE_HOLDER})
|
||||||
|
string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}")
|
||||||
|
|
||||||
|
# Get the grf md5
|
||||||
|
file(MD5 ${BASESET_EXTRAGRF_FILE} ORIG_EXTRA_GRF_MD5)
|
||||||
|
|
||||||
|
configure_file(${BASESET_SOURCE_FILE} ${BASESET_BINARY_FILE})
|
@ -0,0 +1,44 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create a single GRF file based on sprites/<grfname>.nfo and sprites/*.png
|
||||||
|
# files.
|
||||||
|
#
|
||||||
|
|
||||||
|
if (NOT NFORENUM_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR "Script needs NFORENUM_EXECUTABLE defined")
|
||||||
|
endif (NOT NFORENUM_EXECUTABLE)
|
||||||
|
if (NOT GRFCODEC_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR "Script needs GRFCODEC_EXECUTABLE defined")
|
||||||
|
endif (NOT GRFCODEC_EXECUTABLE)
|
||||||
|
if (NOT GRF_SOURCE_FOLDER)
|
||||||
|
message(FATAL_ERROR "Script needs GRF_SOURCE_FOLDER defined")
|
||||||
|
endif (NOT GRF_SOURCE_FOLDER)
|
||||||
|
if (NOT GRF_BINARY_FILE)
|
||||||
|
message(FATAL_ERROR "Script needs GRF_BINARY_FILE defined")
|
||||||
|
endif (NOT GRF_BINARY_FILE)
|
||||||
|
|
||||||
|
get_filename_component(GRF_SOURCE_FOLDER_NAME "${GRF_SOURCE_FOLDER}" NAME)
|
||||||
|
|
||||||
|
file(WRITE sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "")
|
||||||
|
file(READ ${GRF_SOURCE_FOLDER}/${GRF_SOURCE_FOLDER_NAME}.nfo NFO_LINES)
|
||||||
|
# Replace ; with \;, and make a list out of this based on \n
|
||||||
|
string(REPLACE ";" "\\;" NFO_LINES "${NFO_LINES}")
|
||||||
|
string(REPLACE "\n" ";" NFO_LINES "${NFO_LINES}")
|
||||||
|
|
||||||
|
foreach(NFO_LINE IN LISTS NFO_LINES)
|
||||||
|
# Recover the ; that was really in the text (and not a newline)
|
||||||
|
string(REPLACE "\\;" ";" NFO_LINE "${NFO_LINE}")
|
||||||
|
|
||||||
|
if (NFO_LINE MATCHES "^#include")
|
||||||
|
string(REGEX REPLACE "^#include \"(.*)\"$" "\\1" INCLUDE_FILE ${NFO_LINE})
|
||||||
|
file(READ ${GRF_SOURCE_FOLDER}/${INCLUDE_FILE} INCLUDE_LINES)
|
||||||
|
file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${INCLUDE_LINES}")
|
||||||
|
else (NFO_LINE MATCHES "^#include")
|
||||||
|
file(APPEND sprites/${GRF_SOURCE_FOLDER_NAME}.nfo "${NFO_LINE}\n")
|
||||||
|
endif (NFO_LINE MATCHES "^#include")
|
||||||
|
endforeach(NFO_LINE)
|
||||||
|
|
||||||
|
execute_process(COMMAND ${NFORENUM_EXECUTABLE} -s sprites/${GRF_SOURCE_FOLDER_NAME}.nfo)
|
||||||
|
execute_process(COMMAND ${GRFCODEC_EXECUTABLE} -n -s -e -p1 ${GRF_SOURCE_FOLDER_NAME}.grf)
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${GRF_SOURCE_FOLDER_NAME}.grf ${GRF_BINARY_FILE})
|
@ -0,0 +1,87 @@
|
|||||||
|
add_subdirectory(openttd)
|
||||||
|
add_subdirectory(orig_extra)
|
||||||
|
|
||||||
|
set(BASESET_SOURCE_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos_de.obg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obg
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/no_music.obm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_tto.obm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/no_sound.obs
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_dos.obs
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_win.obs
|
||||||
|
)
|
||||||
|
set(BASESET_OTHER_SOURCE_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/openttd.grf
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/opntitle.dat
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf
|
||||||
|
)
|
||||||
|
|
||||||
|
# Done by the subdirectories, if nforenum / grfcodec is installed
|
||||||
|
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
||||||
|
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/openttd.grf PROPERTIES GENERATED TRUE)
|
||||||
|
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf PROPERTIES GENERATED TRUE)
|
||||||
|
|
||||||
|
list(APPEND BASESET_BINARY_FILES openttd.grf)
|
||||||
|
list(APPEND BASESET_BINARY_FILES orig_extra.grf)
|
||||||
|
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
||||||
|
|
||||||
|
set(BASESET_EXTRAGRF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/orig_extra.grf)
|
||||||
|
|
||||||
|
# Walk over all the baseset files, and generate a command to configure them
|
||||||
|
foreach(BASESET_SOURCE_FILE IN LISTS BASESET_SOURCE_FILES)
|
||||||
|
get_filename_component(BASESET_SOURCE_FILE_NAME "${BASESET_SOURCE_FILE}" NAME)
|
||||||
|
set(BASESET_BINARY_FILE "${CMAKE_BINARY_DIR}/baseset/${BASESET_SOURCE_FILE_NAME}")
|
||||||
|
|
||||||
|
get_target_property(LANG_SOURCE_FILES language_files LANG_SOURCE_FILES)
|
||||||
|
|
||||||
|
add_custom_command_timestamp(OUTPUT ${BASESET_BINARY_FILE}
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DBASESET_SOURCE_FILE=${BASESET_SOURCE_FILE}
|
||||||
|
-DBASESET_BINARY_FILE=${BASESET_BINARY_FILE}
|
||||||
|
-DBASESET_EXTRAGRF_FILE=${BASESET_EXTRAGRF_FILE}
|
||||||
|
-P ${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake
|
||||||
|
--
|
||||||
|
${LANG_SOURCE_FILES}
|
||||||
|
MAIN_DEPENDENCY ${BASESET_SOURCE_FILE}
|
||||||
|
DEPENDS ${LANG_SOURCE_FILES}
|
||||||
|
${BASESET_EXTRAGRF_FILE}
|
||||||
|
${CMAKE_SOURCE_DIR}/cmake/scripts/Baseset.cmake
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMENT "Generating ${BASESET_SOURCE_FILE_NAME} baseset metadata file"
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND BASESET_BINARY_FILES ${BASESET_BINARY_FILE})
|
||||||
|
endforeach(BASESET_SOURCE_FILE)
|
||||||
|
|
||||||
|
# Walk over all the other baseset files, and generate a command to copy them
|
||||||
|
foreach(BASESET_OTHER_SOURCE_FILE IN LISTS BASESET_OTHER_SOURCE_FILES)
|
||||||
|
get_filename_component(BASESET_OTHER_SOURCE_FILE_NAME "${BASESET_OTHER_SOURCE_FILE}" NAME)
|
||||||
|
set(BASESET_OTHER_BINARY_FILE "${CMAKE_BINARY_DIR}/baseset/${BASESET_OTHER_SOURCE_FILE_NAME}")
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${BASESET_OTHER_BINARY_FILE}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${BASESET_OTHER_SOURCE_FILE}
|
||||||
|
${BASESET_OTHER_BINARY_FILE}
|
||||||
|
MAIN_DEPENDENCY ${BASESET_OTHER_SOURCE_FILE}
|
||||||
|
COMMENT "Copying ${BASESET_OTHER_SOURCE_FILE_NAME} baseset file"
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND BASESET_BINARY_FILES ${BASESET_OTHER_BINARY_FILE})
|
||||||
|
endforeach(BASESET_OTHER_SOURCE_FILE)
|
||||||
|
|
||||||
|
# Create a new target which generates all baseset metadata files
|
||||||
|
add_custom_target_timestamp(baseset_files
|
||||||
|
DEPENDS
|
||||||
|
${BASESET_BINARY_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(basesets
|
||||||
|
INTERFACE
|
||||||
|
)
|
||||||
|
add_dependencies(basesets
|
||||||
|
baseset_files
|
||||||
|
)
|
||||||
|
add_library(openttd::basesets ALIAS basesets)
|
@ -0,0 +1,9 @@
|
|||||||
|
# In case both NFORenum and GRFCodec are found, generate the GRF.
|
||||||
|
# Otherwise, just use them from the cache (read: git).
|
||||||
|
# This is mainly because not many people have both of these tools installed,
|
||||||
|
# so it is cheaper to cache them in git, and only regenerate when you are
|
||||||
|
# working on it / have the tools installed.
|
||||||
|
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
||||||
|
include(CreateGrfCommand REQUIRED)
|
||||||
|
create_grf_command()
|
||||||
|
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@ -0,0 +1,14 @@
|
|||||||
|
# In case both NFORenum and GRFCodec are found, generate the GRF.
|
||||||
|
# Otherwise, just use them from the cache (read: git).
|
||||||
|
# This is mainly because not many people have both of these tools installed,
|
||||||
|
# so it is cheaper to cache them in git, and only regenerate when you are
|
||||||
|
# working on it / have the tools installed.
|
||||||
|
if (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
||||||
|
include(CreateGrfCommand REQUIRED)
|
||||||
|
create_grf_command(
|
||||||
|
# We share some files with 'openttd' grf
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/airports.png
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/canals.png
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../openttd/chars.png
|
||||||
|
)
|
||||||
|
endif (NFORENUM_FOUND AND GRFCODEC_FOUND)
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@ -1,67 +0,0 @@
|
|||||||
# This file is part of OpenTTD.
|
|
||||||
# OpenTTD 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, version 2.
|
|
||||||
# OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#
|
|
||||||
# Awk script to extract translations for baseset descriptions
|
|
||||||
# from lang files for insertion into .obg/obs/obm files.
|
|
||||||
# If there is no translation, there is no output.
|
|
||||||
#
|
|
||||||
# The input file is scanned for the pattern
|
|
||||||
# !! <ini-key> <STR_id>
|
|
||||||
#
|
|
||||||
# The lang files (passed as variable 'langfiles') are scanned for <STR_id> and
|
|
||||||
# the translations are added to the output file:
|
|
||||||
# <ini-key>.<iso-code> = <translation>
|
|
||||||
#
|
|
||||||
|
|
||||||
# Simple insertion sort since not all AWKs have a sort implementation
|
|
||||||
function isort(A) {
|
|
||||||
n = 0
|
|
||||||
for (val in A) {
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 2; i <= n; i++) {
|
|
||||||
j = i;
|
|
||||||
hold = A[j]
|
|
||||||
while (A[j - 1] > hold) {
|
|
||||||
j--;
|
|
||||||
A[j + 1] = A[j]
|
|
||||||
}
|
|
||||||
A[j] = hold
|
|
||||||
}
|
|
||||||
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
/^!!/ {
|
|
||||||
ini_key = $2;
|
|
||||||
str_id = $3;
|
|
||||||
|
|
||||||
file = langfiles
|
|
||||||
while ((getline < file) > 0) {
|
|
||||||
if (match($0, "##isocode") > 0) {
|
|
||||||
lang = $2;
|
|
||||||
} else if (match($0, "^" str_id " *:") > 0) {
|
|
||||||
sub("^[^:]*:", "", $0)
|
|
||||||
i++;
|
|
||||||
if (lang == "en_GB") {
|
|
||||||
texts[i] = ini_key " = "$0;
|
|
||||||
} else {
|
|
||||||
texts[i] = ini_key "." lang " = "$0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(file);
|
|
||||||
|
|
||||||
count = isort(texts);
|
|
||||||
for (i = 1; i <= count; i++) {
|
|
||||||
print texts[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
{ print }
|
|
@ -1,145 +0,0 @@
|
|||||||
Option Explicit
|
|
||||||
|
|
||||||
' This file is part of OpenTTD.
|
|
||||||
' OpenTTD 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, version 2.
|
|
||||||
' OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Dim FSO
|
|
||||||
Set FSO = CreateObject("Scripting.FileSystemObject")
|
|
||||||
|
|
||||||
Dim inputfile, outputfile, langpath, extra_grf
|
|
||||||
inputfile = WScript.Arguments(0)
|
|
||||||
outputfile = WScript.Arguments(1)
|
|
||||||
langpath = WScript.Arguments(2)
|
|
||||||
|
|
||||||
If WScript.Arguments.Length > 3 Then
|
|
||||||
extra_grf = WScript.Arguments(3)
|
|
||||||
End If
|
|
||||||
|
|
||||||
Function GetExtraGrfHash
|
|
||||||
Dim WSO, exe, line
|
|
||||||
|
|
||||||
Set WSO = WScript.CreateObject("WScript.Shell")
|
|
||||||
Set exe = WSO.Exec("certutil -hashfile " & extra_grf & " MD5")
|
|
||||||
|
|
||||||
Do Until exe.StdOut.AtEndOfStream
|
|
||||||
line = exe.StdOut.ReadLine
|
|
||||||
If Len(line) = 32 Then GetExtraGrfHash = line
|
|
||||||
Loop
|
|
||||||
|
|
||||||
Set WSO = Nothing
|
|
||||||
End Function
|
|
||||||
|
|
||||||
' Simple insertion sort, copied from translations.awk
|
|
||||||
Sub ISort(a)
|
|
||||||
Dim i, j, n, hold
|
|
||||||
n = UBound(a)
|
|
||||||
|
|
||||||
For i = 1 To n
|
|
||||||
j = i
|
|
||||||
hold = a(j)
|
|
||||||
Do While a(j - 1) > hold
|
|
||||||
j = j - 1
|
|
||||||
a(j + 1) = a(j)
|
|
||||||
|
|
||||||
If j = 0 Then Exit Do
|
|
||||||
Loop
|
|
||||||
a(j) = hold
|
|
||||||
Next
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Sub Lookup(ini_key, str_id, outfile)
|
|
||||||
Dim folder, file, line, p, lang, i
|
|
||||||
|
|
||||||
' Ensure only complete string matches
|
|
||||||
str_id = str_id & " "
|
|
||||||
|
|
||||||
Set folder = FSO.GetFolder(langpath)
|
|
||||||
|
|
||||||
Dim output()
|
|
||||||
ReDim output(folder.Files.Count)
|
|
||||||
|
|
||||||
For Each file In folder.Files
|
|
||||||
If UCase(FSO.GetExtensionName(file.Name)) = "TXT" Then
|
|
||||||
Dim f
|
|
||||||
Set f = CreateObject("ADODB.Stream")
|
|
||||||
f.Charset = "utf-8"
|
|
||||||
f.LineSeparator = 10 ' Assume lines end with \n even for \r\n files
|
|
||||||
f.Open
|
|
||||||
f.LoadFromFile(file.Path)
|
|
||||||
|
|
||||||
Do Until f.EOS
|
|
||||||
line = Replace(f.ReadText(-2), Chr(13), "") ' Read a line and remove any \r
|
|
||||||
|
|
||||||
If InStr(1, line, "##isocode ") = 1 Then
|
|
||||||
p = Split(line)
|
|
||||||
lang = p(1)
|
|
||||||
ElseIf InStr(1, line, str_id) = 1 Then
|
|
||||||
p = Split(line, ":", 2)
|
|
||||||
If lang = "en_GB" Then
|
|
||||||
output(i) = ini_key & " = " & p(1)
|
|
||||||
Else
|
|
||||||
output(i) = ini_key & "." & lang & " = " & p(1)
|
|
||||||
End If
|
|
||||||
i = i + 1
|
|
||||||
End If
|
|
||||||
Loop
|
|
||||||
|
|
||||||
f.Close
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
|
|
||||||
ReDim Preserve output(i - 1)
|
|
||||||
ISort output
|
|
||||||
|
|
||||||
For Each line In output
|
|
||||||
outfile.WriteText line, 1
|
|
||||||
Next
|
|
||||||
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Dim line, p
|
|
||||||
|
|
||||||
Dim infile
|
|
||||||
Set infile = FSO.OpenTextFile(inputfile)
|
|
||||||
|
|
||||||
Dim outfile
|
|
||||||
Set outfile = CreateObject("ADODB.Stream")
|
|
||||||
outfile.Charset = "utf-8"
|
|
||||||
outfile.Open
|
|
||||||
|
|
||||||
Do Until infile.atEndOfStream
|
|
||||||
|
|
||||||
line = infile.ReadLine()
|
|
||||||
|
|
||||||
If InStr(1, line, "ORIG_EXTRA.GRF ") = 1 Then
|
|
||||||
p = Split(line, "=")
|
|
||||||
If Trim(p(1)) = "" Then
|
|
||||||
outfile.WriteText "ORIG_EXTRA.GRF = " & GetExtraGrfHash(), 1
|
|
||||||
Else
|
|
||||||
outfile.WriteText line, 1
|
|
||||||
End If
|
|
||||||
ElseIf InStr(1, line, "!! ") = 1 Then
|
|
||||||
p = Split(line)
|
|
||||||
Lookup p(1), p(2), outfile
|
|
||||||
Else
|
|
||||||
outfile.WriteText line, 1
|
|
||||||
End If
|
|
||||||
|
|
||||||
Loop
|
|
||||||
|
|
||||||
' UTF-8 Text ADO Stream includes BOM, so we need to remove it
|
|
||||||
Dim outfile_noBOM
|
|
||||||
Set outfile_noBOM = CreateObject("ADODB.Stream")
|
|
||||||
outfile_noBOM.Type = 1
|
|
||||||
outfile_noBOM.Open
|
|
||||||
|
|
||||||
' Copy Text stream to Binary stream, skiping the BOM
|
|
||||||
outfile.Position = 3
|
|
||||||
outfile.CopyTo outfile_noBOM
|
|
||||||
outfile.Close
|
|
||||||
|
|
||||||
' Write the Binary stream
|
|
||||||
outfile_noBOM.SaveToFile outputfile, 2
|
|
||||||
outfile_noBOM.Close
|
|
@ -1,30 +0,0 @@
|
|||||||
# This file is part of OpenTTD.
|
|
||||||
# OpenTTD 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, version 2.
|
|
||||||
# OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
# Very basic variant function; barely any error checking.
|
|
||||||
# Just use the first argument as the file to start from when assembling everything
|
|
||||||
path = ARGV[1];
|
|
||||||
gsub("[^/\\\\]*$", "", path);
|
|
||||||
assemble(ARGV[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Recursive function for assembling by means of resolving the #includes.
|
|
||||||
function assemble(filename) {
|
|
||||||
while ((getline < filename) > 0) {
|
|
||||||
if (NF == 2 && $1 == "#include" ) {
|
|
||||||
# Remove the quotes.
|
|
||||||
gsub("[\"'<>]", "", $2);
|
|
||||||
assemble(path $2);
|
|
||||||
} else {
|
|
||||||
print $0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close(filename) < 0) {
|
|
||||||
print "Could not open " filename > "/dev/stderr";
|
|
||||||
exit -1;
|
|
||||||
}
|
|
||||||
}
|
|