/** * SPDX-FileCopyrightText: 2016-2022 Dr. Tobias Quathamer * * SPDX-License-Identifier: GPL-3.0-or-later */ #include #include #include #include #include #include "options.h" #include "isocodes.h" int main(int argument_count, gchar **arguments) { // The first parameter is not used, but cannot be omitted. // This cast is to suppress the compiler warning about // unused parameters. (void) argument_count; GError *error = NULL; JsonParser *parser; gchar *filename; gchar **codes; // Set up I18N infrastructure // @TODO: Use LOCALEDIR bindtextdomain(GETTEXT_PACKAGE, "/usr/share/locale"); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); setlocale(LC_ALL, ""); // Parse command line and report possible errors if (!options_parse_command_line(arguments, &error)) { // TRANSLATORS: This is an error message. g_printerr(_("isoquery: %s\n"), error->message); if (error->domain == g_quark_from_string("g-option-context-error-quark")) { g_printerr(_("Run \"isoquery --help\" to see a full list of available command line options.\n")); } g_error_free(error); return EXIT_FAILURE; } // Show program version and copyright if (option_version) { options_show_version(); return EXIT_SUCCESS; } // Try opening and parsing the given file parser = json_parser_new(); filename = options_get_filename(); if (!json_parser_load_from_file(parser, filename, &error)) { // TRANSLATORS: This is an error message. g_printerr(_("isoquery: %s\n"), error->message); g_error_free(error); g_free(filename); g_object_unref(parser); return EXIT_FAILURE; } // The file could be parsed, now see if there's // valid iso-codes data in it. if (!isocodes_validate(parser, &error)) { // TRANSLATORS: This is an error message. g_printerr(_("isoquery: %s\n"), error->message); g_error_free(error); g_free(filename); g_object_unref(parser); return EXIT_FAILURE; } // Remove the program name from the arguments and collect // remaining arguments as codes to search for. codes = &arguments[1]; // Finally, show the codes isocodes_show_codes(parser, codes); // Cleanup and exit g_free(filename); g_object_unref(parser); return EXIT_SUCCESS; }