tree
texmacs_best_match (tree ids, tree p, int c,
                    hashmap<tree,tree> corr,
                    hashmap<tree,tree> pred,
                    hashmap<tree,tree> succ) {
  if (N(ids) == 1) return ids[0];
  int best= -1, best_len= -1;
  for (int i=0; i<N(ids); i++) {
    int plen= common_len (ids[i], p, c, -1, corr, pred);
    int slen= common_len (ids[i], p, c,  1, corr, succ);
    int len = plen + slen;
    if (len > best_len) {
      best= i;
      best_len= len;
    }
    else if (len == best_len)
      best= -1;
  }
  //if (best >= 0)
  //cout << HRULE << "Multiple matches: " << ids
  //<< " -> " << ids[best] << LF << HRULE;
  return best >= 0? ids[best]: tree (UNINIT);
}
//*****************************************************************************
static void microrl_get_complite (microrl_t * pThis) 
{
	char const * tkn_arr[_COMMAND_TOKEN_NMB];
	const char ** compl_token; 
	
	if (pThis->get_completion == NULL) // callback was not set
		return;
	
	int status = split (pThis, pThis->cursor, tkn_arr);
	if (pThis->cmdline[pThis->cursor-1] == '\0')
		tkn_arr[status++] = "";
	compl_token = pThis->get_completion (status, tkn_arr);
	if (compl_token[0] != NULL) {
		int i = 0;
		int len;

		if (compl_token[1] == NULL) {
			len = strlen (compl_token[0]);
		} else {
			len = common_len (compl_token);
			terminal_newline (pThis);
			while (compl_token [i] != NULL) {
				pThis->print (compl_token[i]);
				pThis->print (" ");
				i++;
			}
			terminal_newline (pThis);
			print_prompt (pThis);
		}
		
		if (len) {
			microrl_insert_text (pThis, compl_token[0] + strlen(tkn_arr[status-1]), 
																	len - strlen(tkn_arr[status-1]));
			if (compl_token[1] == NULL) 
				microrl_insert_text (pThis, " ", 1);
		}
		terminal_reset_cursor (pThis);
		terminal_print_line (pThis, 0, pThis->cursor);
	} 
}
Exemple #3
0
int get_common_str(char *a1,char *a2)  
{

	int l1=strlen(a1);
	int l2=strlen(a2);
	int max_common=0;
	int start=0;
	for(int i=0;i<l1;i++)
	{
		for(int j=0;j<l2;j++)
		{
			int len=common_len(a1+i,a2+j);
			if(len>max_common)
			{
				start = i;
				max_common=len;
			}
		}
	}
	printf("common str = %s \n",a1+start);
	return max_common;
}