ref: cc4321d176fc13628687d6b7e7184282a0066a19
parent: 7b23dd89240537429a73d7c8a9cc866abf74838e
parent: 87e220f3631616f7fd10a858c92cbd8b53d9d495
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Sun Feb 23 13:00:49 EST 2025
Merge pull request #176 from bit101/allow_alternate_config Allow user to specify alternate config file with --config flag.
--- a/README.md
+++ b/README.md
@@ -166,6 +166,14 @@
* Linux: `/home/<username>/.local/share/m8c/config.ini`
* MacOS: `/Users/<username>/Library/Application Support/m8c/config.ini`
+You can choose to load an alternate configuration with the `--config` command line option. Example:
+
+```
+m8c --config alternate_config.ini
+```
+
+This looks for a config file with the given name in the same directory as the default config. If you specify a config file that does not exist, a new default config file with the specified name will be created, which you can then edit.
+
Enjoy making some nice music!
-----------
--- a/src/config.c
+++ b/src/config.c
@@ -18,10 +18,14 @@
}
}
-config_params_s init_config() {+config_params_s init_config(char *filename) {config_params_s c;
- c.filename = "config.ini"; // default config file to load
+ if (filename == NULL) {+ c.filename = "config.ini"; // default config file to load
+ } else {+ c.filename = filename;
+ }
c.init_fullscreen = 0; // default fullscreen state at load
c.init_use_gpu = 1; // default to use hardware acceleration
--- a/src/main.c
+++ b/src/main.c
@@ -40,11 +40,15 @@
SDL_Log("Using preferred device %s.\n", preferred_device);}
+ char *config_filename = NULL;
+ if (argc == 3 && SDL_strcmp(argv[1], "--config") == 0) {+ config_filename = argv[2];
+ SDL_Log("Using config file %s.\n", config_filename);+ }
+
// Initialize the config to defaults read in the params from the
// configfile if present
- config_params_s conf = init_config();
-
- // TODO: take cli parameter to override default configfile location
+ config_params_s conf = init_config(config_filename);
read_config(&conf);
// allocate memory for serial buffer
--
⑨