| 231 | }; |
| 232 | |
| 233 | int main(int argc, char** argv) { |
| 234 | Gjs::AutoError error; |
| 235 | int gjs_argc = argc; |
| 236 | bool interactive_mode = false; |
| 237 | |
| 238 | setlocale(LC_ALL, ""); |
| 239 | |
| 240 | GjsAutoGOptionContext context = g_option_context_new(nullptr); |
| 241 | g_option_context_set_ignore_unknown_options(context, true); |
| 242 | g_option_context_set_help_enabled(context, false); |
| 243 | |
| 244 | Gjs::AutoStrv argv_copy_addr{g_strdupv(argv)}; |
| 245 | char** argv_copy = argv_copy_addr; |
| 246 | |
| 247 | g_option_context_add_main_entries(context, entries, nullptr); |
| 248 | if (!g_option_context_parse_strv(context, &argv_copy, &error)) |
| 249 | g_error("option parsing failed: %s", error->message); |
| 250 | |
| 251 | // Split options so we pass unknown ones through to the JS script |
| 252 | int argc_copy = g_strv_length(argv_copy); |
| 253 | for (int ix = 1; ix < argc; ix++) { |
| 254 | // Check if a file was given and split after it |
| 255 | if (argc_copy >= 2 && strcmp(argv[ix], argv_copy[1]) == 0) { |
| 256 | // Filename given; split after this argument |
| 257 | gjs_argc = ix + 1; |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | // Check if -c or --command was given and split after following arg |
| 262 | if (command && (strcmp(argv[ix], "-c") == 0 || |
| 263 | strcmp(argv[ix], "--command") == 0)) { |
| 264 | gjs_argc = ix + 2; |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | Gjs::AutoStrv gjs_argv_addr{strndupv(gjs_argc, argv)}; |
| 269 | char** gjs_argv = gjs_argv_addr; |
| 270 | int script_argc = argc - gjs_argc; |
| 271 | char* const* script_argv = argv + gjs_argc; |
| 272 | |
| 273 | // Parse again, only the GJS options this time |
| 274 | include_path.release(); |
| 275 | coverage_prefixes.release(); |
| 276 | coverage_output_path.release(); |
| 277 | command.release(); |
| 278 | print_version = false; |
| 279 | print_js_version = false; |
| 280 | debugging = false; |
| 281 | exec_as_module = false; |
| 282 | g_option_context_set_ignore_unknown_options(context, false); |
| 283 | g_option_context_set_help_enabled(context, true); |
| 284 | if (!g_option_context_parse_strv(context, &gjs_argv, &error)) { |
| 285 | Gjs::AutoChar help_text{ |
| 286 | g_option_context_get_help(context, true, nullptr)}; |
| 287 | g_printerr("%s\n\n%s\n", error->message, help_text.get()); |
| 288 | return EXIT_FAILURE; |
| 289 | } |
| 290 |
nothing calls this directly
no test coverage detected