-/* Collect scripts to be printed in a vec. */
-
-typedef struct loaded_script *loaded_script_ptr;
-DEF_VEC_P (loaded_script_ptr);
-
-/* Traversal function for htab_traverse.
- Collect the entry if it matches the regexp. */
-
-static int
-collect_matching_scripts (void **slot, void *info)
-{
- struct loaded_script *script = *slot;
- VEC (loaded_script_ptr) *scripts = info;
-
- if (re_exec (script->name))
- VEC_safe_push (loaded_script_ptr, scripts, script);
-
- return 1;
-}
-
-/* Print SCRIPT. */
-
-static void
-print_script (struct loaded_script *script)
-{
- struct cleanup *chain;
-
- chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-
- ui_out_field_string (uiout, "loaded", script->full_path ? "Yes" : "Missing");
- ui_out_field_string (uiout, "script", script->name);
- ui_out_text (uiout, "\n");
-
- /* If the name isn't the full path, print it too. */
- if (script->full_path != NULL
- && strcmp (script->name, script->full_path) != 0)
- {
- ui_out_text (uiout, "\tfull name: ");
- ui_out_field_string (uiout, "full_path", script->full_path);
- ui_out_text (uiout, "\n");
- }
-
- do_cleanups (chain);
-}
-
-/* Helper for info_auto_load_scripts to sort the scripts by name. */
-
-static int
-sort_scripts_by_name (const void *ap, const void *bp)
-{
- const struct loaded_script *a = *(const struct loaded_script **) ap;
- const struct loaded_script *b = *(const struct loaded_script **) bp;
-
- return FILENAME_CMP (a->name, b->name);
-}
-
-/* "info auto-load-scripts" command. */
-
-static void
-info_auto_load_scripts (char *pattern, int from_tty)
-{
- struct auto_load_pspace_info *pspace_info;
- struct cleanup *script_chain;
- VEC (loaded_script_ptr) *scripts;
- int nr_scripts;
-
- dont_repeat ();
-
- pspace_info = get_auto_load_pspace_data (current_program_space);
-
- if (pattern && *pattern)
- {
- char *re_err = re_comp (pattern);
-
- if (re_err)
- error (_("Invalid regexp: %s"), re_err);
- }
- else
- {
- re_comp ("");
- }
-
- /* We need to know the number of rows before we build the table.
- Plus we want to sort the scripts by name.
- So first traverse the hash table collecting the matching scripts. */
-
- scripts = VEC_alloc (loaded_script_ptr, 10);
- script_chain = make_cleanup (VEC_cleanup (loaded_script_ptr), &scripts);
-
- if (pspace_info != NULL && pspace_info->loaded_scripts != NULL)
- {
- immediate_quit++;
- htab_traverse_noresize (pspace_info->loaded_scripts,
- collect_matching_scripts, scripts);
- immediate_quit--;
- }
-
- nr_scripts = VEC_length (loaded_script_ptr, scripts);
- make_cleanup_ui_out_table_begin_end (uiout, 2, nr_scripts,
- "AutoLoadedScriptsTable");
-
- ui_out_table_header (uiout, 7, ui_left, "loaded", "Loaded");
- ui_out_table_header (uiout, 70, ui_left, "script", "Script");
- ui_out_table_body (uiout);
-
- if (nr_scripts > 0)
- {
- int i;
- loaded_script_ptr script;
-
- qsort (VEC_address (loaded_script_ptr, scripts),
- VEC_length (loaded_script_ptr, scripts),
- sizeof (loaded_script_ptr), sort_scripts_by_name);
- for (i = 0; VEC_iterate (loaded_script_ptr, scripts, i, script); ++i)
- print_script (script);
- }
-
- do_cleanups (script_chain);
-
- if (nr_scripts == 0)
- {
- if (pattern && *pattern)
- ui_out_message (uiout, 0, "No auto-load scripts matching %s.\n",
- pattern);
- else
- ui_out_message (uiout, 0, "No auto-load scripts.\n");
- }
-}
-\f