Skip to content

Use dmini section iteration API in configure_section_drivers#31

Merged
JohnAmadis merged 3 commits intomainfrom
copilot/update-driver-name-per-section
Mar 9, 2026
Merged

Use dmini section iteration API in configure_section_drivers#31
JohnAmadis merged 3 commits intomainfrom
copilot/update-driver-name-per-section

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

Per-section driver_name support was implemented by re-opening the raw config file with Dmod_FileOpen/Dmod_FileReadLine to enumerate sections — effectively writing a second INI parser. The correct approach is to use the dmini API to enumerate sections and use dmini_set_active_section to scope the context before passing it to each driver.

Changes

  • configure_section_drivers: replace Dmod_FileOpen + line-by-line scan with dmini_section_count / dmini_section_name (dmini@0.5 section iteration API) to walk sections directly from the in-memory context; no buffer allocation or string parsing required
  • Signature: remove config_path parameter — no longer needed now that we don't touch the filesystem
  • Cleanup: remove unused INI_LINE_BUFFER_SIZE define
// Before: re-opened the file from disk
void* file = Dmod_FileOpen(config_path, "r");
while (Dmod_FileReadLine(line, sizeof(line), file) != NULL) { ... }

// After: iterate sections directly via dmini API
int section_count = dmini_section_count(config_ctx);
for (int i = 0; i < section_count; i++)
{
    const char* section_name = dmini_section_name(config_ctx, i);
    // skip NULL (global) and "main", check for driver_name, then:
    dmini_set_active_section(config_ctx, section_name, 0);
    driver_node = configure_driver(module_name, config_ctx);
    dmini_clear_active_section(config_ctx, 0);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>driver name powinno być szukane w każdej sekcji</issue_title>
<issue_description>Aktualnie driver_name jest szukane tylko w sekcji main - tymczasem powinno się dać podać osobny driver name dla każdej sekcji - i każda wtedy powinna być obsługiwana przez inny driver. Dzięki temu będzie można mieć jeden plik konfiguracyjny np dla całego boarda, gdzie będziemy mogli podać osobna sekcje dla SPI, dla GPIO a może nawet osobno dla różnych kanałów - wszystko w jednym pliku.

Oczywiście domyślne zachowanie może zostać bez zmian - jeśli nie jest podany nigdzie driver_name, to wybieramy jeden driver dla całego pliku (albo jeśli nazwa drivera jest zakodowana w nazwie pliku, czy sekcji main - no generalnie to ma działać tak jak do tej pory). Sprawa dotyczy jednak nowego przypadku - kiedy mamy wpisane driver_name w jakiejś sekcji, która nie jest main - wtedy do drivera przekazujemy ograniczony context pliku ini - można to zrobić za pomocą nowego API w dmini, a dokładnie za pomocą funkcji: dmini_set_active_section (szczegóły możesz sprawdzić w dokumentacji)</issue_description>

<agent_instructions>ty durny copilocie - w tym PR:
#28

Kompletnie źle to zrobiłeś! Czytasz plik konfiguracyjny, zamiast przeczytać dokładnie co napisałem w opisie - miało być tak, że używasz API do ograniczania zakresu w kontekscie ini, a ty swoj parser napisales. Popraw to</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… direct file I/O

Replace Dmod_FileOpen/Dmod_FileReadLine with dmini_generate_string so that
section enumeration works from the already-parsed in-memory dmini context
rather than re-reading the raw config file from disk. This is the intended
usage as described in the issue: use the dmini API (dmini_set_active_section)
to restrict context scope, not a hand-rolled file parser.

- Remove config_path parameter from configure_section_drivers (no longer needed)
- Remove unused INI_LINE_BUFFER_SIZE define
- Add whitespace trimming for robustness when parsing section names
- Use dmini_generate_string to obtain INI content from in-memory context

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Update driver name search for each section Replace manual file re-read in configure_section_drivers with dmini_generate_string Mar 9, 2026
@JohnAmadis
Copy link
Contributor

@copilot w wersji dmini@0.5 masz juz mozliwosc iterowania po sekcjach - użyj tego

Replace dmini_generate_string + manual string parsing with the proper
dmini@0.5 section iteration API: dmini_section_count() and
dmini_section_name(index). This gives direct access to section names
from the in-memory context without allocating a serialised string or
parsing it manually.

The dmini_set_active_section / dmini_clear_active_section usage for
scoping the context per driver is unchanged.

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 9, 2026

@copilot w wersji dmini@0.5 masz juz mozliwosc iterowania po sekcjach - użyj tego

Done in 97c9a69. Replaced dmini_generate_string + manual string parsing with dmini_section_count / dmini_section_name(index) — the section iteration API from dmini@0.5. The loop is now just a simple indexed walk over sections from the in-memory context, no buffer allocation or string scanning needed.

Copilot AI changed the title Replace manual file re-read in configure_section_drivers with dmini_generate_string Use dmini section iteration API in configure_section_drivers Mar 9, 2026
@JohnAmadis JohnAmadis marked this pull request as ready for review March 9, 2026 20:42
@JohnAmadis JohnAmadis merged commit ff7ab03 into main Mar 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

driver name powinno być szukane w każdej sekcji

2 participants