Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,17 @@
with Config; use Config;
with Ada.Text_IO; use Ada.Text_IO;
procedure Rosetta_Read_Cfg is
cfg: Configuration:= Init("rosetta_read.cfg", Case_Sensitive => False, Variable_Terminator => ' ');
fullname : String := cfg.Value_Of("*", "fullname");
favouritefruit : String := cfg.Value_Of("*", "favouritefruit");
needspeeling : Boolean := cfg.Is_Set("*", "needspeeling");
seedsremoved : Boolean := cfg.Is_Set("*", "seedsremoved");
otherfamily : String := cfg.Value_Of("*", "otherfamily");
begin
Put_Line("fullname = " & fullname);
Put_Line("favouritefruit = " & favouritefruit);
Put_Line("needspeeling = " & Boolean'Image(needspeeling));
Put_Line("seedsremoved = " & Boolean'Image(seedsremoved));
Put_Line("otherfamily = " & otherfamily);
end;

View file

@ -0,0 +1,30 @@
@echo off
setlocal enableextensions enabledelayedexpansion
for /f "delims==" %%a in ('set 2^>nul') do set "%%a="
(set #lf=^
)
for /f "usebackq tokens=1* eol=#" %%i in ("%~1") do (
set "#temp=%%i%%j"
if "!#temp:~0,1!"==";" (set !#temp:~1!=false) else (
set "#temp=%%j"
call :strip !#temp!
if "!#temp!"=="" (set %%i=true) else (
for %%l in ("!#lf!") do set "#list=!#temp:,=%%~l!"
if "!#temp!"=="!#list!" (set "%%i=!#temp!") else (
set #count=1
for /f "tokens=*" %%l in ("!#list!") do (
call :strip %%l
set "%%i(!#count!)=!#temp!"
set /a #count+=1
)
)))
)
set #lf=
set #count=
set #temp=
set #list=
set
goto:eof
:strip %= strip whitespaces =%
set "#temp=%*"

View file

@ -0,0 +1,96 @@
identification division.
program-id. ReadConfiguration.
environment division.
configuration section.
repository.
function all intrinsic.
input-output section.
file-control.
select config-file assign to "Configuration.txt"
organization line sequential.
data division.
file section.
fd config-file.
01 config-record pic is x(128).
working-storage section.
77 idx pic 9(3).
77 pos pic 9(3).
77 last-pos pic 9(3).
77 config-key pic x(32).
77 config-value pic x(64).
77 multi-value pic x(64).
77 full-name pic x(64).
77 favourite-fruit pic x(64).
77 other-family pic x(64) occurs 10.
77 need-speeling pic x(5) value "false".
77 seeds-removed pic x(5) value "false".
procedure division.
main.
open input config-file
perform until exit
read config-file
at end
exit perform
end-read
move trim(config-record) to config-record
if config-record(1:1) = "#" or ";" or spaces
exit perform cycle
end-if
unstring config-record delimited by spaces into config-key
move trim(config-record(length(trim(config-key)) + 1:)) to config-value
if config-value(1:1) = "="
move trim(config-value(2:)) to config-value
end-if
evaluate upper-case(config-key)
when "FULLNAME"
move config-value to full-name
when "FAVOURITEFRUIT"
move config-value to favourite-fruit
when "NEEDSPEELING"
if config-value = spaces
move "true" to config-value
end-if
if config-value = "true" or "false"
move config-value to need-speeling
end-if
when "SEEDSREMOVED"
if config-value = spaces
move "true" to config-value
end-if,
if config-value = "true" or "false"
move config-value to seeds-removed
end-if
when "OTHERFAMILY"
move 1 to idx, pos
perform until exit
unstring config-value delimited by "," into multi-value with pointer pos
on overflow
move trim(multi-value) to other-family(idx)
move pos to last-pos
not on overflow
if config-value(last-pos:) <> spaces
move trim(config-value(last-pos:)) to other-family(idx)
end-if,
exit perform
end-unstring
add 1 to idx
end-perform
end-evaluate
end-perform
close config-file
display "fullname = " full-name
display "favouritefruit = " favourite-fruit
display "needspeeling = " need-speeling
display "seedsremoved = " seeds-removed
perform varying idx from 1 by 1 until idx > 10
if other-family(idx) <> low-values
display "otherfamily(" idx ") = " other-family(idx)
end-if
end-perform
.

View file

@ -3,8 +3,8 @@ function readconf(file)
for line in eachline(file)
line = strip(line)
if !isempty(line) && !startswith(line, '#') && !startswith(line, ';')
fspace = searchindex(line, " ")
if fspace == 0
fspace = findfirst(isequal(' '), line)
if isnothing(fspace)
vars[Symbol(lowercase(line))] = true
else
vname, line = Symbol(lowercase(line[1:fspace-1])), line[fspace+1:end]

View file

@ -1,40 +1,20 @@
conf = {}
fp = io.open( "conf.txt", "r" )
for line in fp:lines() do
line = line:match( "%s*(.+)" )
if line and line:sub( 1, 1 ) ~= "#" and line:sub( 1, 1 ) ~= ";" then
option = line:match( "%S+" ):lower()
value = line:match( "%S*%s*(.*)" )
if not value then
conf[option] = true
else
if not value:find( "," ) then
conf[option] = value
else
value = value .. ","
conf[option] = {}
for entry in value:gmatch( "%s*(.-)," ) do
conf[option][#conf[option]+1] = entry
end
end
end
local conf = {}
-- Parsing
for line in io.lines"conf.txt" do
local option, delim, value = line:match'^%s*([^;# \t=]+)([%s=]?)%s*(.-)%s*$'
if option then
if value:find',' then local oldvalue
oldvalue, value = value, {}
for field in oldvalue:gmatch'[^,]+' do
table.insert(value, field:match"^%s*(.-)%s*$")
end
else
value = delim~="" and value~="" and value or true
end
conf[option:lower()] = value
end
end
fp:close()
print( "fullname = ", conf["fullname"] )
print( "favouritefruit = ", conf["favouritefruit"] )
if conf["needspeeling"] then print( "needspeeling = true" ) else print( "needspeeling = false" ) end
if conf["seedsremoved"] then print( "seedsremoved = true" ) else print( "seedsremoved = false" ) end
if conf["otherfamily"] then
print "otherfamily:"
for _, entry in pairs( conf["otherfamily"] ) do
print( "", entry )
end
end
-- Printing tables is usually left to the external module inspect
print(require"inspect"(conf))

View file

@ -0,0 +1,136 @@
package main
import "base:runtime"
import "core:fmt"
import "core:io"
import "core:os"
import str "core:strings"
import "core:unicode"
Value :: union {
string,
bool,
[]string,
}
iterate_config_fields :: proc(src: ^string) -> (key: string, value: Value, ok: bool) {
@(thread_local)
array_buffer: [64]string
for line in str.split_lines_iterator(src) {
line := str.trim_space(line)
// Skip empty and comment lines
if len(line) == 0 do continue
if line[0] == '#' || line[0] == ';' do continue
sep := str.index_any(line, " =")
// Boolean flag (no separator found)
if sep == -1 {return line, true, true}
key = str.trim_right_space(line[:sep])
value_str := str.trim_space(line[sep + 1:])
if value_str[0] == '=' {value_str = str.trim_left_space(value_str[1:])} // Handles spaces between key and '='
counter := 0
for el in str.split_iterator(&value_str, ",") {
if counter >= 64 {panic("Too many elements in array")}
array_buffer[counter] = str.trim_space(el)
counter += 1
}
if counter == 1 {value = array_buffer[0]} else {value = array_buffer[:counter]}
return key, value, true
}
return "", "", false
}
Config :: struct {
full_name: string,
favourite_fruit: string,
needs_peeling: bool,
seeds_removed: bool,
other_family: []string,
_allocator: runtime.Allocator `fmt:"-"`,
}
Parcing_Error :: union {
runtime.Allocator_Error,
io.Error,
}
parse_config :: proc(
src: string,
allocator := context.allocator,
) -> (
c: Config,
err: Parcing_Error,
) {
to_restore := context.allocator
src := src
c._allocator = allocator
context.allocator = allocator
defer context.allocator = to_restore
key_to_lower :: proc(s: string) -> (res: string, err: io.Error) {
assert(len(s) <= 512, "Key too long")
@(thread_local)
buffer: [512]byte
b := str.builder_from_slice(buffer[:])
for r in s {
str.write_rune(&b, unicode.to_lower(r)) or_return
}
return str.to_string(b), err
}
for key, value in iterate_config_fields(&src) {
key := key_to_lower(key) or_return
switch key {
case "fullname":
c.full_name = str.clone(value.(string)) or_return
case "favouritefruit":
c.favourite_fruit = str.clone(value.(string)) or_return
case "needspeeling":
c.needs_peeling = value.(bool)
case "seedsremoved":
c.seeds_removed = value.(bool)
case "otherfamily":
v := value.([]string)
c.other_family = make([]string, len(v)) or_return
for s, i in v {c.other_family[i] = str.clone(s) or_return}
}
}
return
}
free_config :: proc(c: ^Config) -> runtime.Allocator_Error {
to_restore := context.allocator
context.allocator = c._allocator
defer context.allocator = to_restore
delete(c.favourite_fruit) or_return
delete(c.full_name) or_return
for fm in c.other_family {
delete(fm) or_return
}
delete(c.other_family) or_return
return nil
}
main :: proc() {
cfg_raw := os.read_entire_file("test.conf") or_else panic("Can't open file")
cfg, err := parse_config(string(cfg_raw))
delete(cfg_raw)
if err != nil {
fmt.eprintf("Parse error: %v\n", err)
return
}
fmt.printfln("%#v", cfg)
}

View file

@ -0,0 +1,56 @@
class configuration
function __construct(map)
self.full_name = map["full_name"]
self.favourite_fruit = map["favourite_fruit"]
self.needs_peeling = map["needs_peeling"]
self.seeds_removed = map["seeds_removed"]
self.other_family = map["other_family"]
end
function __tostring()
return {
$"Full name = {self.full_name}",
$"Favourite fruit = {self.favourite_fruit}",
$"Needs peeling = {self.needs_peeling}",
$"Seeds removed = {self.seeds_removed}",
$"Other family = {self.other_family:concat()}"
}:concat("\n")
end
end
class map_entry
function __construct(public key, public value) end
end
local commented_out = |line| -> line:startswith("#") or line:startswith(";")
local function to_map_entry(line)
local ix = line:find(" ", 1, true)
if !ix then return new map_entry(line, "") end
return new map_entry(line:sub(1, ix - 1), line:sub(ix + 1))
end
local filename = "configuration.txt"
local nl = os.platform == "windows" ? "\r\n" : "\n"
local lines = io.contents(filename):rstrip():split(nl)
local map_entries = lines:map(|line| -> line:strip())
:filter(|line| -> line != ""):reorder()
:filter(|line| -> !commented_out(line)):reorder()
:map(|line| -> to_map_entry(line))
local configuration_map = { needs_peeling = false, seeds_removed = false }
for map_entries as me do
if me.key == "FULLNAME" then
configuration_map["full_name"] = me.value
elseif me.key == "FAVOURITEFRUIT" then
configuration_map["favourite_fruit"] = me.value
elseif me.key == "NEEDSPEELING" then
configuration_map["needs_peeling"] = true
elseif me.key == "OTHERFAMILY" then
configuration_map["other_family"] = me.value:split(" , "):map(|s| -> s:strip())
elseif me.key == "SEEDSREMOVED" then
configuration_map["seeds_removed"] = true
else
print($"Encountered unexpected key {me.key} = {me.value}")
end
end
print(new configuration(configuration_map))

View file

@ -0,0 +1,68 @@
function Read-ConfigurationFile
{
[CmdletBinding()]
Param
(
# Path to the configuration file. Default is "C:\ConfigurationFile.cfg"
[Parameter(Mandatory=$false, Position=0)]
[string]
$Path = "C:\ConfigurationFile.cfg"
)
[string]$script:fullName = ""
[string]$script:favouriteFruit = ""
[bool]$script:needsPeeling = $false
[bool]$script:seedsRemoved = $false
[string[]]$script:otherFamily = @()
function Get-Value ([string]$Line)
{
if ($Line -match "=")
{
[string]$value = $Line.Split("=",2).Trim()[1]
}
elseif ($Line -match " ")
{
[string]$value = $Line.Split(" ",2).Trim()[1]
}
$value
}
# Process each line in file that is not a comment.
Get-Content $Path | Select-String -Pattern "^[^#;]" | ForEach-Object {
[string]$line = $_.Line.Trim()
if ($line -eq [String]::Empty)
{
# do nothing for empty lines
}
elseif ($line.ToUpper().StartsWith("FULLNAME"))
{
$script:fullName = Get-Value $line
}
elseif ($line.ToUpper().StartsWith("FAVOURITEFRUIT"))
{
$script:favouriteFruit = Get-Value $line
}
elseif ($line.ToUpper().StartsWith("NEEDSPEELING"))
{
$script:needsPeeling = $true
}
elseif ($line.ToUpper().StartsWith("SEEDSREMOVED"))
{
$script:seedsRemoved = $true
}
elseif ($line.ToUpper().StartsWith("OTHERFAMILY"))
{
$script:otherFamily = (Get-Value $line).Split(',').Trim()
}
}
Write-Verbose -Message ("{0,-15}= {1}" -f "FULLNAME", $script:fullName)
Write-Verbose -Message ("{0,-15}= {1}" -f "FAVOURITEFRUIT", $script:favouriteFruit)
Write-Verbose -Message ("{0,-15}= {1}" -f "NEEDSPEELING", $script:needsPeeling)
Write-Verbose -Message ("{0,-15}= {1}" -f "SEEDSREMOVED", $script:seedsRemoved)
Write-Verbose -Message ("{0,-15}= {1}" -f "OTHERFAMILY", ($script:otherFamily -join ", "))
}

View file

@ -0,0 +1 @@
Read-ConfigurationFile -Path .\temp.txt -Verbose

View file

@ -0,0 +1 @@
Get-Variable -Name fullName, favouriteFruit, needsPeeling, seedsRemoved, otherFamily

View file

@ -0,0 +1,88 @@
Function Read-ConfigurationFile {
[CmdletBinding()]
[OutputType([Collections.Specialized.OrderedDictionary])]
Param (
[Parameter(
Mandatory=$true,
Position=0
)
]
[Alias('LiteralPath')]
[ValidateScript({
Test-Path -LiteralPath $PSItem -PathType 'Leaf'
})
]
[String]
$_LiteralPath
)
Begin {
Function Houdini-Value ([String]$_Text) {
$__Aux = $_Text.Trim()
If ($__Aux.Length -eq 0) {
$__Aux = $true
} ElseIf ($__Aux.Contains(',')) {
$__Aux = $__Aux.Split(',') |
ForEach-Object {
If ($PSItem.Trim().Length -ne 0) {
$PSItem.Trim()
}
}
}
Return $__Aux
}
}
Process {
$__Configuration = [Ordered]@{}
# Config equivalent pattern
# Select-String -Pattern '^\s*[^\s;#=]+.*\s*$' -LiteralPath '.\filename.cfg'
Switch -Regex -File $_LiteralPath {
'^\s*[;#=]|^\s*$' {
Write-Verbose -Message "v$(' '*20)ignored"
Write-Verbose -Message $Matches[0]
Continue
}
'^([^=]+)=(.*)$' {
Write-Verbose -Message '↓← ← ← ← ← ← ← ← ← ← equal pattern'
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[1..2]
$__Configuration[$__Name.Trim()] = Houdini-Value($__Value)
Continue
}
'^\s*([^\s;#=]+)(.*)(\s*)$' {
Write-Verbose -Message '↓← ← ← ← ← ← ← ← ← ← space or tab pattern or only name'
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[1..2]
$__Configuration[$__Name.Trim()] = Houdini-Value($__Value)
Continue
}
}
Return $__Configuration
}
}
Function Show-Value ([Collections.Specialized.OrderedDictionary]$_Dictionary, $_Index, $_SubIndex) {
$__Aux = $_Index + ' = '
If ($_Dictionary[$_Index] -eq $null) {
$__Aux += $false
} ElseIf ($_Dictionary[$_Index].Count -gt 1) {
If ($_SubIndex -eq $null) {
$__Aux += $_Dictionary[$_Index] -join ','
} Else {
$__Aux = $_Index + '(' + $_SubIndex + ') = '
If ($_Dictionary[$_Index][$_SubIndex] -eq $null) {
$__Aux += $false
} Else {
$__Aux += $_Dictionary[$_Index][$_SubIndex]
}
}
} Else {
$__Aux += $_Dictionary[$_Index]
}
Return $__Aux
}

View file

@ -0,0 +1 @@
$Configuration = Read-ConfigurationFile -LiteralPath '.\config.cfg'

View file

@ -0,0 +1 @@
$Configuration

View file

@ -0,0 +1,8 @@
Show-Value $Configuration 'fullname'
Show-Value $Configuration 'favouritefruit'
Show-Value $Configuration 'needspeeling'
Show-Value $Configuration 'seedsremoved'
Show-Value $Configuration 'otherfamily'
Show-Value $Configuration 'otherfamily' 0
Show-Value $Configuration 'otherfamily' 1
Show-Value $Configuration 'otherfamily' 2

View file

@ -0,0 +1,45 @@
'$Configuration[''fullname'']'
$Configuration['fullname']
'$Configuration.''fullname'''
$Configuration.'fullname'
'$Configuration.Item(''fullname'')'
$Configuration.Item('fullname')
'$Configuration[0]'
$Configuration[0]
'$Configuration.Item(0)'
$Configuration.Item(0)
' '
'=== $Configuration[''otherfamily''] ==='
$Configuration['otherfamily']
'=== $Configuration[''otherfamily''][0] ==='
$Configuration['otherfamily'][0]
'=== $Configuration[''otherfamily''][1] ==='
$Configuration['otherfamily'][1]
' '
'=== $Configuration.''otherfamily'' ==='
$Configuration.'otherfamily'
'=== $Configuration.''otherfamily''[0] ==='
$Configuration.'otherfamily'[0]
'=== $Configuration.''otherfamily''[1] ==='
$Configuration.'otherfamily'[1]
' '
'=== $Configuration.Item(''otherfamily'') ==='
$Configuration.Item('otherfamily')
'=== $Configuration.Item(''otherfamily'')[0] ==='
$Configuration.Item('otherfamily')[0]
'=== $Configuration.Item(''otherfamily'')[1] ==='
$Configuration.Item('otherfamily')[1]
' '
'=== $Configuration[3] ==='
$Configuration[3]
'=== $Configuration[3][0] ==='
$Configuration[3][0]
'=== $Configuration[3][1] ==='
$Configuration[3][1]
' '
'=== $Configuration.Item(3) ==='
$Configuration.Item(3)
'=== $Configuration.Item(3).Item(0) ==='
$Configuration.Item(3).Item(0)
'=== $Configuration.Item(3).Item(1) ==='
$Configuration.Item(3).Item(1)

View file

@ -0,0 +1,38 @@
Set ofso = CreateObject("Scripting.FileSystemObject")
Set config = ofso.OpenTextFile(ofso.GetParentFolderName(WScript.ScriptFullName)&"\config.txt",1)
config_out = ""
Do Until config.AtEndOfStream
line = config.ReadLine
If Left(line,1) <> "#" And Len(line) <> 0 Then
config_out = config_out & parse_var(line) & vbCrLf
End If
Loop
WScript.Echo config_out
Function parse_var(s)
'boolean false
If InStr(s,";") Then
parse_var = Mid(s,InStr(1,s,";")+2,Len(s)-InStr(1,s,";")+2) & " = FALSE"
'boolean true
ElseIf UBound(Split(s," ")) = 0 Then
parse_var = s & " = TRUE"
'multiple parameters
ElseIf InStr(s,",") Then
var = Left(s,InStr(1,s," ")-1)
params = Split(Mid(s,InStr(1,s," ")+1,Len(s)-InStr(1,s," ")+1),",")
n = 1 : tmp = ""
For i = 0 To UBound(params)
parse_var = parse_var & var & "(" & n & ") = " & LTrim(params(i)) & vbCrLf
n = n + 1
Next
'single var and paramater
Else
parse_var = Left(s,InStr(1,s," ")-1) & " = " & Mid(s,InStr(1,s," ")+1,Len(s)-InStr(1,s," ")+1)
End If
End Function
config.Close
Set ofso = Nothing