How to add a command line parameter to edit a configuration?

Discussion of development and patch submission.
Post Reply
sharkbyte16
Posts: 4
Joined: Mon 17 Jan, 2022 6:39 pm

How to add a command line parameter to edit a configuration?

Post by sharkbyte16 »

Hi all,

Currently PCem allows directly launching a configuration from the command line with the --config option without showing the main window. What I think I understand from the source code it sets the default configuration to the --config specified one and than launches the configuration.

While running PCem a selected configuration can be edited in the Configure window which is opened by pressing the Configure button. I would like to add a command line parameter --edit to be used in conjunction with --config to open the Configure PCem window directly, preferably without showing the main window, and saving the configuration upon closing the window.

I have looked in the source code and see that the command line options are handled in the initpc function in pc.c. Is this the place to add a direct call to how the Configure window? And what function should be called? I have with my limited C knowledge a hard time grasping how the code works. Any help is appreciated.

Regards.
User avatar
Arjen42
Posts: 137
Joined: Fri 11 Jun, 2021 3:15 pm

Re: How to add a command line parameter to edit a configuration?

Post by Arjen42 »

The function that opens the configuration window is void config_open(void *hwnd). The argument of this function is the handle of the parent window.

You do need to load the configuration first before calling this function using void loadconfig(char *fn).
sharkbyte16
Posts: 4
Joined: Mon 17 Jan, 2022 6:39 pm

Re: How to add a command line parameter to edit a configuration?

Post by sharkbyte16 »

Thank you, Arjen! I'll try it from there.
sharkbyte16
Posts: 4
Joined: Mon 17 Jan, 2022 6:39 pm

Re: How to add a command line parameter to edit a configuration?

Post by sharkbyte16 »

My idea was to add a switch variable to bypass the configuration selection window and open the configuration dialog instead, similar to how the command line argument --config sets the config_override variable which also leads to bypass the configuration selection window and directly run the specified config. This than allows PCem to be controlled from the command line for both configuring and running machines.

I tried to follow the logic in the source code, but without any documentation I get lost in the event-driven code after wxEntry in wx-main.cc. I can´t figure out the structure of the program. Where to call config_open and with which window handle (NULL?) if the configuration selection window is not opened?
User avatar
Arjen42
Posts: 137
Joined: Fri 11 Jun, 2021 3:15 pm

Re: How to add a command line parameter to edit a configuration?

Post by Arjen42 »

I would start at the code where command line arguments are parsed. That is in the initpc() function in the src/pc.c file.
sharkbyte16
Posts: 4
Joined: Mon 17 Jan, 2022 6:39 pm

Re: How to add a command line parameter to edit a configuration?

Post by sharkbyte16 »

By use of ChatGPT I have come some way by adding the --settings argument parsing in initpc(). To be able to call the C++ config_open() function in the pc.c file, I added a wrapper C++ function. In that wrapper function I tried to initialize all the wxWidgets stuff needed to open the configuration window. It all compiles and links, but at runtime it fails to load resources. I get lost resolving those. I am afraid that what seemed a doable task has grown way above my programming skills. Anyway, thanx Arjen for thinking along.
Post Reply