-
-static int lc_opts_default_error_handler(const char *prefix, const lc_opt_err_info_t *err)
-{
- fprintf(stderr, "%s: %s; %s\n", prefix, err->msg, err->arg);
- return 0;
-}
-
-void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_prefix, int argc, const char **argv)
-{
- FILE *f;
- char path[MAX_PATH];
- char local_ini_file[MAX_PATH];
- char home_dir_ini_file[MAX_PATH];
-
- /* <cmnt>.ini */
- strncpy(local_ini_file, ini_name, sizeof(local_ini_file));
- strncat(local_ini_file, ".ini", sizeof(local_ini_file));
- local_ini_file[sizeof(local_ini_file) - 1] = '\0';
- path[0] = '\0';
-
-#ifdef _WIN32
-#if _MSC_VER > 1200
- /* ARG: need newer SDK to compile this */
- SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path);
- strncat(path, "\\", sizeof(path));
-#endif
- strncpy(home_dir_ini_file, local_ini_file, sizeof(home_dir_ini_file));
- home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
-#else
- {
- struct passwd *entry = getpwuid(getuid());
- if (entry != NULL) {
- strcpy(path, entry->pw_dir);
- strncat(path, "/", sizeof(path));
- /* .<cmnt>rc */
- snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name);
- home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
- } else {
- /* FIXME: some error occured */
- home_dir_ini_file[0] = '\0';
- }
- }
-#endif
-
- strncat(path, home_dir_ini_file, sizeof(path));
- path[sizeof(path) - 1] = '\0';
-
- /* Process ini file in user's home. */
- f = fopen(path, "rt");
- if (f) {
- lc_opt_from_file(path, f, lc_opts_default_error_handler);
- fclose(f);
- }
-
- /* Process ini file in current directory. */
- f = fopen(local_ini_file, "rt");
- if (f) {
- lc_opt_from_file(local_ini_file, f, lc_opts_default_error_handler);
- fclose(f);
- }
-
- /* process arguments from the command line */
- lc_opt_from_argv(root, arg_prefix, argc, argv, lc_opts_default_error_handler);
-}