-/* If SYM_NAME is a completion candidate for TEXT, return this symbol
- name in a form that's appropriate for the completion. The result
- does not need to be deallocated, but is only good until the next call.
-
- TEXT_LEN is equal to the length of TEXT.
- Perform a wild match if WILD_MATCH is set.
- ENCODED should be set if TEXT represents the start of a symbol name
- in its encoded form. */
-
-static const char *
-symbol_completion_match (const char *sym_name,
- const char *text, int text_len,
- int wild_match, int encoded)
-{
- char *result;
- const int verbatim_match = (text[0] == '<');
- int match = 0;
-
- if (verbatim_match)
- {
- /* Strip the leading angle bracket. */
- text = text + 1;
- text_len--;
- }
-
- /* First, test against the fully qualified name of the symbol. */
-
- if (strncmp (sym_name, text, text_len) == 0)
- match = 1;
-
- if (match && !encoded)
- {
- /* One needed check before declaring a positive match is to verify
- that iff we are doing a verbatim match, the decoded version
- of the symbol name starts with '<'. Otherwise, this symbol name
- is not a suitable completion. */
- const char *sym_name_copy = sym_name;
- int has_angle_bracket;
-
- sym_name = ada_decode (sym_name);
- has_angle_bracket = (sym_name [0] == '<');
- match = (has_angle_bracket == verbatim_match);
- sym_name = sym_name_copy;
- }
-
- if (match && !verbatim_match)
- {
- /* When doing non-verbatim match, another check that needs to
- be done is to verify that the potentially matching symbol name
- does not include capital letters, because the ada-mode would
- not be able to understand these symbol names without the
- angle bracket notation. */
- const char *tmp;
-
- for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++);
- if (*tmp != '\0')
- match = 0;
- }
-
- /* Second: Try wild matching... */
-
- if (!match && wild_match)
- {
- /* Since we are doing wild matching, this means that TEXT
- may represent an unqualified symbol name. We therefore must
- also compare TEXT against the unqualified name of the symbol. */
- sym_name = ada_unqualified_name (ada_decode (sym_name));
-
- if (strncmp (sym_name, text, text_len) == 0)
- match = 1;
- }
-
- /* Finally: If we found a mach, prepare the result to return. */
-
- if (!match)
- return NULL;
-
- if (verbatim_match)
- sym_name = add_angle_brackets (sym_name);
-
- if (!encoded)
- sym_name = ada_decode (sym_name);
-
- return sym_name;
-}
-
-/* A companion function to ada_make_symbol_completion_list().
- Check if SYM_NAME represents a symbol which name would be suitable
- to complete TEXT (TEXT_LEN is the length of TEXT), in which case
- it is appended at the end of the given string vector SV.
-
- ORIG_TEXT is the string original string from the user command
- that needs to be completed. WORD is the entire command on which
- completion should be performed. These two parameters are used to
- determine which part of the symbol name should be added to the
- completion vector.
- if WILD_MATCH is set, then wild matching is performed.
- ENCODED should be set if TEXT represents a symbol name in its
- encoded formed (in which case the completion should also be
- encoded). */
-
-static void
-symbol_completion_add (struct string_vector *sv,
- const char *sym_name,
- const char *text, int text_len,
- const char *orig_text, const char *word,
- int wild_match, int encoded)
-{
- const char *match = symbol_completion_match (sym_name, text, text_len,
- wild_match, encoded);
- char *completion;
-
- if (match == NULL)
- return;
-
- /* We found a match, so add the appropriate completion to the given
- string vector. */
-
- if (word == orig_text)
- {
- completion = xmalloc (strlen (match) + 5);
- strcpy (completion, match);
- }
- else if (word > orig_text)
- {
- /* Return some portion of sym_name. */
- completion = xmalloc (strlen (match) + 5);
- strcpy (completion, match + (word - orig_text));
- }
- else
- {
- /* Return some of ORIG_TEXT plus sym_name. */
- completion = xmalloc (strlen (match) + (orig_text - word) + 5);
- strncpy (completion, word, orig_text - word);
- completion[orig_text - word] = '\0';
- strcat (completion, match);
- }
-
- string_vector_append (sv, completion);
-}
-
-/* Return a list of possible symbol names completing TEXT0. The list
- is NULL terminated. WORD is the entire command on which completion
- is made. */
-
-char **
-ada_make_symbol_completion_list (const char *text0, const char *word)
-{
- /* Note: This function is almost a copy of make_symbol_completion_list(),
- except it has been adapted for Ada. It is somewhat of a shame to
- duplicate so much code, but we don't really have the infrastructure
- yet to develop a language-aware version of he symbol completer... */
- char *text;
- int text_len;
- int wild_match;
- int encoded;
- struct string_vector result = xnew_string_vector (128);
- struct symbol *sym;
- struct symtab *s;
- struct partial_symtab *ps;
- struct minimal_symbol *msymbol;
- struct objfile *objfile;
- struct block *b, *surrounding_static_block = 0;
- int i;
- struct dict_iterator iter;
-
- if (text0[0] == '<')
- {
- text = xstrdup (text0);
- make_cleanup (xfree, text);
- text_len = strlen (text);
- wild_match = 0;
- encoded = 1;
- }
- else
- {
- text = xstrdup (ada_encode (text0));
- make_cleanup (xfree, text);
- text_len = strlen (text);
- for (i = 0; i < text_len; i++)
- text[i] = tolower (text[i]);
-
- /* FIXME: brobecker/2003-09-17: When we get rid of ADA_RETAIN_DOTS,
- we can restrict the wild_match check to searching "__" only. */
- wild_match = (strstr (text0, "__") == NULL
- && strchr (text0, '.') == NULL);
- encoded = (strstr (text0, "__") != NULL);
- }
-
- /* First, look at the partial symtab symbols. */
- ALL_PSYMTABS (objfile, ps)
- {
- struct partial_symbol **psym;
-
- /* If the psymtab's been read in we'll get it when we search
- through the blockvector. */
- if (ps->readin)
- continue;
-
- for (psym = objfile->global_psymbols.list + ps->globals_offset;
- psym < (objfile->global_psymbols.list + ps->globals_offset
- + ps->n_global_syms);
- psym++)
- {
- QUIT;
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym),
- text, text_len, text0, word,
- wild_match, encoded);
- }
-
- for (psym = objfile->static_psymbols.list + ps->statics_offset;
- psym < (objfile->static_psymbols.list + ps->statics_offset
- + ps->n_static_syms);
- psym++)
- {
- QUIT;
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym),
- text, text_len, text0, word,
- wild_match, encoded);
- }
- }
-
- /* At this point scan through the misc symbol vectors and add each
- symbol you find to the list. Eventually we want to ignore
- anything that isn't a text symbol (everything else will be
- handled by the psymtab code above). */
-
- ALL_MSYMBOLS (objfile, msymbol)
- {
- QUIT;
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (msymbol),
- text, text_len, text0, word,
- wild_match, encoded);
- }
-
- /* Search upwards from currently selected frame (so that we can
- complete on local vars. */
-
- for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
- {
- if (!BLOCK_SUPERBLOCK (b))
- surrounding_static_block = b; /* For elmin of dups */
-
- ALL_BLOCK_SYMBOLS (b, iter, sym)
- {
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
- text, text_len, text0, word,
- wild_match, encoded);
- }
- }
-
- /* Go through the symtabs and check the externs and statics for
- symbols which match. */
-
- ALL_SYMTABS (objfile, s)
- {
- QUIT;
- b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
- ALL_BLOCK_SYMBOLS (b, iter, sym)
- {
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
- text, text_len, text0, word,
- wild_match, encoded);
- }
- }
-
- ALL_SYMTABS (objfile, s)
- {
- QUIT;
- b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
- /* Don't do this block twice. */
- if (b == surrounding_static_block)
- continue;
- ALL_BLOCK_SYMBOLS (b, iter, sym)
- {
- symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym),
- text, text_len, text0, word,
- wild_match, encoded);
- }
- }
-
- /* Append the closing NULL entry. */
- string_vector_append (&result, NULL);
-
- return (result.array);
-}
-