1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
####################################################################
# Script.awk #
####################################################################
# Load options from the initialization script.
function loadOptions(script, i, j, tokens, name, value) {
tokenize(tokens, script)
for (i in tokens) {
if (tokens[i] ~ /^:/) {
name = substr(tokens[i], 2)
value = tokens[i + 1]
if (value ~ /^[+-]?((0|[1-9][0-9]*)|[.][0-9]*|(0|[1-9][0-9]*)[.][0-9]*)([Ee][+-]?[0-9]+)?$/) {
# Decimal number
delete Option[name]
Option[name] = value
} else if (value == "false" || value == "true") {
# Boolean
delete Option[name]
Option[name] = yn(value)
} else if (value ~ /^".*"$/) {
# String
delete Option[name]
Option[name] = literal(value)
} else if (value == "[") {
# List of strings
delete Option[name]
for (j = 1; tokens[i + j + 1] && tokens[i + j + 1] != "]"; j++) {
if (tokens[i + j + 1] ~ /^".*"$/)
Option[name][j] = literal(tokens[i + j + 1])
else {
e("[ERROR] Malformed configuration.")
return
}
}
} else {
e("[ERROR] Malformed configuration.")
return
}
}
}
}
# Check for upgrade.
function upgrade( i, newVersion, registry, tokens) {
RegistryIndex = "https://raw.githubusercontent.com/soimort/translate-shell/registry/index.trans"
registry = curl(RegistryIndex)
if (!registry) {
e("[ERROR] Failed to check for upgrade.")
ExitCode = 1
return
}
tokenize(tokens, registry)
for (i in tokens)
if (tokens[i] == ":translate-shell")
newVersion = literal(tokens[i + 1])
if (newerVersion(newVersion, Version)) {
w("Current version: \t" Version)
w("New version available: \t" newVersion)
w("Download from: \t" "https://www.soimort.org/translate-shell/trans")
} else {
w("Current version: \t" Version)
w("Already up-to-date.")
}
}
|