Skip to content

Commit

Permalink
Merge pull request #176 from bit101/allow_alternate_config
Browse files Browse the repository at this point in the history
Allow user to specify alternate config file with --config flag.
  • Loading branch information
laamaa authored Feb 23, 2025
2 parents 7b23dd8 + 87e220f commit cc4321d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ If the file does not exist, it will be created in one of these locations:
* 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!

-----------
Expand Down
8 changes: 6 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ static int strcmpci(const char *a, const char *b) {
}
}

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
Expand Down
10 changes: 7 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ int main(const int argc, char *argv[]) {
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
Expand Down

0 comments on commit cc4321d

Please sign in to comment.