RetroPie / RetroPie/RetroPie-Setup

Some considerations about inifuncs.sh

Open
#1,605 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
10.4k
Forks
1.4k
Avg merge
2d 12h
Merged PRs (30d)
11

Description

The inifuncs.sh are really useful. It's a good tool to manage retroarch.cfg-like files, and it's better than build all those REGEXes everytime.

I'm posting this to give some feedback about using it to manage retroarch.cfg-like files and to share some thoughts.

[If I sounded like a smartass before, that was not my intention. Please take into consideration that English is not my native language and maybe I don't know how to joke using this idiom. No jokes from now on!]

Let's get started...

1. Is there a reason to get the last match in iniProcess?

In iniProcess the match variable allways gets the last occurrence of the key.

If iniSet/iniUnset is used to manage a retroarch.cfg file ("first match if finds" behavior), the comment character is put in the last match. This isn't what the caller expect. The comment on the first match is more like what RetroArch would do (or maybe it's just my opinion).

example:

[prompt]$ source ~/RetroPie-Setup/scriptmodules/inifuncs.sh                     
[prompt]$ iniConfig '=' '"'
[prompt]$ cat test.cfg 
var1="var1 content one"
var1="var1 content two"
var1="var1 content three"
[prompt]$ iniUnset var1 disabled test.cfg 
[prompt]$ cat test.cfg 
var1="var1 content one"
var1="var1 content two"
# var1="disabled"
[prompt]$ iniSet var1 'new value' test.cfg 
[prompt]$ cat test.cfg 
var1="var1 content one"
var1="var1 content two"
var1="new value"
2. The iniGet gets every occurrences of a key and puts their values in ini_value.

Thinking like RetroArch again. If the file has multiple occurrences of a key, the iniGet appends all the values in the ini_value variable. This can bring unexpected (and hard to detect) problems to the caller.

Again, I think RetroArch would get only the first match and ignore the rest.

Example:

[prompt]$ cat test.cfg 
var1="var1 content one"
var1="var1 content two"
var1="new value"
[prompt]$ iniGet var1 test.cfg 
[prompt]$ echo "$ini_value"
var1 content one
var1 content two
new value

I know the inifuncs.sh is not for retroarch.cfg manipulation only. So, I would like to know if you guys see any problem on making this "first match if finds" the default behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with scriptmodules/inifuncs.sh, especially the iniProcess code around line 45 and iniGet around line 120, then review how iniSet and iniUnset use those results. Confirm the intended handling of repeated keys and add or update coverage for the examples in the issue; done means the selected match and ini_value behavior are consistent and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.