fix sorting and cleanup toml sort bash script
This commit is contained in:
@@ -22,16 +22,16 @@ task_list = "FM"
|
||||
name = "Emulators"
|
||||
|
||||
[[data.entries]]
|
||||
name = "RetroArch Game Emulator"
|
||||
description = "Frontend for emulators, game engines and media players. NO Games or Bios' are included"
|
||||
script = "emulators/retroarch.sh"
|
||||
name = "Blastem"
|
||||
description = "A Genesis emulator. NO Games are included"
|
||||
script = "emulators/sega/blastem.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "snes9x"
|
||||
description = "Super Nintendo Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/snes9x.sh"
|
||||
task_list = "FM"
|
||||
# [[data.entries]]
|
||||
# name = "Yabause"
|
||||
# description = "A Sega Saturn emulator"
|
||||
# script = "emulators/sega/yabause.sh"
|
||||
# task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "bsnes"
|
||||
@@ -39,6 +39,36 @@ description = "Super Nintendo Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/bsnes.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Dolphin Emulator"
|
||||
description = "GameCube and Wii Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/dolphin-emu.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Flycast"
|
||||
description = "A Dreamcase emulator. NO Games are included"
|
||||
script = "emulators/sega/flycast.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Gopher 64"
|
||||
description = "N64 Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/gopher64.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Kronos"
|
||||
description = "A Sega Saturn emulator. NO Games are included"
|
||||
script = "emulators/sega/kronos.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "MelonDS"
|
||||
description = "Nintendo DS and DSi Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/melonds.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "mGBA"
|
||||
description = "Nintendo Game Boy Advance Emulator. NO Games are included"
|
||||
@@ -52,21 +82,27 @@ script = "emulators/nintendo/mupen64plus.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Gopher 64"
|
||||
description = "N64 Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/gopher64.sh"
|
||||
name = "PCSX2"
|
||||
description = "A Playstation 2 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/pcsx2.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Dolphin Emulator"
|
||||
description = "GameCube and Wii Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/dolphin-emu.sh"
|
||||
name = "Play!"
|
||||
description = "An Experimental Playstation 2 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/play-emu.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "MelonDS"
|
||||
description = "Nintendo DS and DSi Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/melonds.sh"
|
||||
name = "RetroArch Game Emulator"
|
||||
description = "Frontend for emulators, game engines and media players. NO Games or Bios' are included"
|
||||
script = "emulators/retroarch.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "RPCS3"
|
||||
description = "A Playstation 3 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/rpcs3.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
@@ -82,45 +118,9 @@ task_list = "FM"
|
||||
# task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "PCSX2"
|
||||
description = "A Playstation 2 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/pcsx2.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Play!"
|
||||
description = "An Experimental Playstation 2 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/play-emu.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "RPCS3"
|
||||
description = "A Playstation 3 emulator. NO Games or Bios' are included"
|
||||
script = "emulators/playstation/rpcs3.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Blastem"
|
||||
description = "A Genesis emulator. NO Games are included"
|
||||
script = "emulators/sega/blastem.sh"
|
||||
task_list = "FM"
|
||||
|
||||
# [[data.entries]]
|
||||
# name = "Yabause"
|
||||
# description = "A Sega Saturn emulator"
|
||||
# script = "emulators/sega/yabause.sh"
|
||||
# task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Kronos"
|
||||
description = "A Sega Saturn emulator. NO Games are included"
|
||||
script = "emulators/sega/kronos.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Flycast"
|
||||
description = "A Dreamcase emulator. NO Games are included"
|
||||
script = "emulators/sega/flycast.sh"
|
||||
name = "snes9x"
|
||||
description = "Super Nintendo Emulator. NO Games are included"
|
||||
script = "emulators/nintendo/snes9x.sh"
|
||||
task_list = "FM"
|
||||
|
||||
[[data.entries]]
|
||||
|
||||
+90
-43
@@ -1,6 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Sort all tab_data.toml files in the core/tabs directory
|
||||
# - Sorts [[data]] blocks alphabetically by name
|
||||
# - Sorts [[data.entries]] within each block alphabetically by name
|
||||
# - Places blocks with entries before blocks without entries
|
||||
|
||||
set -e
|
||||
|
||||
echo "Sorting all tab_data.toml files..."
|
||||
@@ -9,79 +13,122 @@ find core/tabs -name "tab_data.toml" | while IFS= read -r file; do
|
||||
echo "Processing: $file"
|
||||
|
||||
awk '
|
||||
BEGIN {
|
||||
data_block = ""
|
||||
data_name = ""
|
||||
data_count = 0
|
||||
BEGIN {
|
||||
in_data = 0
|
||||
header = ""
|
||||
in_entry = 0
|
||||
data_count = 0
|
||||
entry_count = 0
|
||||
}
|
||||
|
||||
# Capture header (lines before first [[data]])
|
||||
# Capture file header (lines before first [[data]])
|
||||
!in_data && !/^\[\[data\]\]$/ {
|
||||
header = header $0 "\n"
|
||||
next
|
||||
}
|
||||
|
||||
# Start of a new [[data]] section
|
||||
# Start of new [[data]] block
|
||||
/^\[\[data\]\]$/ {
|
||||
# Save previous data block if exists
|
||||
if (data_block != "") {
|
||||
data_blocks[data_name] = data_block
|
||||
data_names[++data_count] = data_name
|
||||
# Check if block has entries
|
||||
if (data_block ~ /\[\[data\.entries\]\]/) {
|
||||
has_entries[data_name] = 1
|
||||
}
|
||||
}
|
||||
# Start new data block
|
||||
data_block = $0 "\n"
|
||||
save_entry_block()
|
||||
save_data_block()
|
||||
data_header = $0 "\n"
|
||||
in_data = 1
|
||||
in_entry = 0
|
||||
data_name = ""
|
||||
next
|
||||
}
|
||||
|
||||
# Inside a [[data]] block - collect everything until next [[data]]
|
||||
# Start of new [[data.entries]] block
|
||||
in_data && /^\[\[data\.entries\]\]$/ {
|
||||
save_entry_block()
|
||||
entry_block = $0 "\n"
|
||||
in_entry = 1
|
||||
entry_name = ""
|
||||
next
|
||||
}
|
||||
|
||||
# Lines inside [[data.entries]]
|
||||
in_entry {
|
||||
entry_block = entry_block $0 "\n"
|
||||
if ($0 ~ /^name = / && !entry_name) {
|
||||
entry_name = extract_name($0)
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
# Lines inside [[data]] but outside [[data.entries]]
|
||||
in_data {
|
||||
data_block = data_block $0 "\n"
|
||||
# Extract the name field from [[data]] section
|
||||
if ($0 ~ /^name = / && data_name == "") {
|
||||
gsub(/^name = "/, "", $0)
|
||||
gsub(/".*$/, "", $0)
|
||||
data_name = tolower($0)
|
||||
data_header = data_header $0 "\n"
|
||||
if ($0 ~ /^name = / && !data_name) {
|
||||
data_name = extract_name($0)
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
END {
|
||||
# Save last data block
|
||||
if (data_block != "") {
|
||||
data_blocks[data_name] = data_block
|
||||
data_names[++data_count] = data_name
|
||||
# Check if block has entries
|
||||
if (data_block ~ /\[\[data\.entries\]\]/) {
|
||||
save_entry_block()
|
||||
save_data_block()
|
||||
print_sorted_output()
|
||||
}
|
||||
|
||||
# Helper function to extract and normalize name field
|
||||
function extract_name(line) {
|
||||
gsub(/^name = "/, "", line)
|
||||
gsub(/".*$/, "", line)
|
||||
return tolower(line)
|
||||
}
|
||||
|
||||
# Save current entry block
|
||||
function save_entry_block() {
|
||||
if (entry_block && entry_name) {
|
||||
entry_blocks[entry_name] = entry_block
|
||||
entry_names[++entry_count] = entry_name
|
||||
entry_block = ""
|
||||
entry_name = ""
|
||||
}
|
||||
}
|
||||
|
||||
# Save current data block with sorted entries
|
||||
function save_data_block() {
|
||||
if (data_name) {
|
||||
# Sort and append entries
|
||||
if (entry_count > 0) {
|
||||
n = asort(entry_names, sorted)
|
||||
for (i = 1; i <= n; i++) {
|
||||
data_header = data_header entry_blocks[sorted[i]]
|
||||
}
|
||||
has_entries[data_name] = 1
|
||||
}
|
||||
|
||||
data_blocks[data_name] = data_header
|
||||
data_names[++data_count] = data_name
|
||||
|
||||
# Reset for next block
|
||||
entry_count = 0
|
||||
delete entry_blocks
|
||||
delete entry_names
|
||||
data_header = ""
|
||||
data_name = ""
|
||||
}
|
||||
|
||||
# Print header
|
||||
}
|
||||
|
||||
# Print sorted output
|
||||
function print_sorted_output() {
|
||||
printf "%s", header
|
||||
|
||||
# Sort and print data blocks - first those with entries, then those without
|
||||
if (data_count > 0) {
|
||||
n = asort(data_names, sorted_names)
|
||||
# First pass: blocks with entries
|
||||
n = asort(data_names, sorted)
|
||||
|
||||
# First: blocks with entries
|
||||
for (i = 1; i <= n; i++) {
|
||||
name = sorted_names[i]
|
||||
if (has_entries[name]) {
|
||||
printf "%s", data_blocks[name]
|
||||
if (has_entries[sorted[i]]) {
|
||||
printf "%s", data_blocks[sorted[i]]
|
||||
}
|
||||
}
|
||||
# Second pass: blocks without entries
|
||||
|
||||
# Second: blocks without entries
|
||||
for (i = 1; i <= n; i++) {
|
||||
name = sorted_names[i]
|
||||
if (!has_entries[name]) {
|
||||
printf "%s", data_blocks[name]
|
||||
if (!has_entries[sorted[i]]) {
|
||||
printf "%s", data_blocks[sorted[i]]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user