37 lines
1.4 KiB
CMake
Executable File
37 lines
1.4 KiB
CMake
Executable File
#!/usr/bin/cmake -DOUTPUT_PATH=iana_language_subtag_registry.cpp -P
|
|
# generates C++ code for the language-subtag-registry from www.iana.org, see https://tools.ietf.org/html/bcp47 and https://tools.ietf.org/html/rfc5646
|
|
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
|
|
|
if (NOT LANGUAGE_FILE)
|
|
set(LANGUAGE_FILE "language-subtag-registry.txt")
|
|
endif ()
|
|
if (EXISTS "${LANGUAGE_FILE}")
|
|
message(STATUS "Using existing language-subtag-registry file \"${LANGUAGE_FILE}\"")
|
|
else()
|
|
message(STATUS "Downloading language-subtag-registry file from www.iana.org")
|
|
file(DOWNLOAD "https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry" "${LANGUAGE_FILE}")
|
|
endif()
|
|
if (NOT OUTPUT_PATH)
|
|
message(FATAL_ERROR "No OUTPUT_PATH specified.")
|
|
endif()
|
|
|
|
file(STRINGS "${LANGUAGE_FILE}" LANGUAGE_LIST)
|
|
set(CURRENT_TYPE "")
|
|
foreach (LINE ${LANGUAGE_LIST})
|
|
if (NOT CURRENT_TYPE)
|
|
if (LINE MATCHES "Type: (.*)")
|
|
set(CURRENT_TYPE "${CMAKE_MATCH_1}")
|
|
endif ()
|
|
else ()
|
|
if (LINE STREQUAL "%%")
|
|
unset(CURRENT_TYPE)
|
|
continue()
|
|
endif ()
|
|
if (CURRENT_TYPE STREQUAL "language")
|
|
if (LINE MATCHES "Description: (.*)")
|
|
message(STATUS "${CMAKE_MATCH_1}")
|
|
endif ()
|
|
endif ()
|
|
endif ()
|
|
#message(STATUS "Processing line: ${LINE}")
|
|
endforeach() |