Closed saeziae closed 2 years ago
Recently I thought of a new solution, as reading an empty config file does not affect the program to run, we can just remove the exit(-1)
then give an empty string to config
when the file pointer is NULL.
Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I iust thought of a bug with my suggestion: a new configuration file is created, but not initialized.
Something like this:
file=fopen(conf_file, "r");
if(file==NULL) {
fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n");
// reset to default configuration.
config->version = CONF_FILE_VERSION;
config->learn = 0;
config_save(config);
return;
}
Once this pr is merged I'll release v3.1 and then once I have time I'll rewrite the C version as I wrote it when I was learning C so the code is pretty bad.
Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I just thought of a bug with my suggestion: a new configuration file is created, but not initialized.
However reading an empty file does not affect the program. And I think it's okay to assume the learning mode is off if there is not a config file, like:
file=fopen(conf_file, "r");
if(file==NULL) {
// fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n");
config->version = CONF_FILE_VERSION;
config->learn = 0;
// config_save(config);
return;
}
Honestly the configuration system is really bad. I would rather keep it this way for now and rewrite it later on a better way. Also I just thought of a bug with my suggestion: a new configuration file is created, but not initialized.
However reading an empty file does not affect the program. And I think it's okay to assume the learning mode is off if there is not a config file, like:
file=fopen(conf_file, "r"); if(file==NULL) { // fprintf(stderr, "config_load(): configuration file not found, attempting to create a new one.\n"); config->version = CONF_FILE_VERSION; config->learn = 0; // config_save(config); return; }
You are right, that is a better idea.
I improved the help message and the comment.
Thanks a lot for the fix!
On a new installation, the programme will attempt to read the config file which yet does not exisit, causing the error
config_load: fopen: No such file or directory
.