1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/* Copyright (C) (2001) (Antonio SJ Musumeci) <bile_@hotmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ntaim.h"
extern buddylist_node *buddylist_head;
extern commandalias_node *commandaliasesroot;
extern char *command_list[];
extern int commandnum;
extern window_node *current_window;
extern color_pref colors;
extern preferences pref;
unsigned short find_tabbed_string(char *string_to_find, char *input_string)
{
int i, numberofmatches = 0;
unsigned short quote_begin = 0, quote_end = 0;
int string_to_finds_length, input_strings_length;
unsigned int amount_to_add;
char *matches[MAXMATCHES];
buddylist_node *current_buddy;
commandalias_node *cmdaliasnode;
string_to_finds_length = strlen(string_to_find);
if(string_to_finds_length == 0)
return 0;
if(string_to_find[0] == '/') /* search through commands and command aliases */
{
for(i = 0; i < commandnum; i++)
{
if( !strncmp(command_list[i], string_to_find, string_to_finds_length) )
{
if(numberofmatches < MAXMATCHES)
matches[numberofmatches++] = command_list[i];
else
break;
}
}
if (numberofmatches < MAXMATCHES)
{
for(cmdaliasnode = commandaliasesroot; cmdaliasnode; cmdaliasnode = cmdaliasnode -> next)
{
if (!strncmp(cmdaliasnode->name, string_to_find, string_to_finds_length))
{
if(numberofmatches < MAXMATCHES)
matches[numberofmatches++] = cmdaliasnode->name;
else
break;
}
}
}
}
else /* search through buddies and buddy aliases */
{
for(current_buddy = buddylist_head; current_buddy; current_buddy = current_buddy->next)
{
if( !strncmp(current_buddy->screenname, string_to_find, string_to_finds_length) )
{
if(numberofmatches < MAXMATCHES)
matches[numberofmatches++] = current_buddy->screenname;
else
break;
}
if( !strncmp(current_buddy->buddy_alias, string_to_find, string_to_finds_length) )
{
if(numberofmatches < MAXMATCHES)
matches[numberofmatches++] = current_buddy->buddy_alias;
else
break;
}
}
}
switch(numberofmatches)
{
case 0:
beep();
return 0;
case 1:
input_strings_length = strlen(input_string);
/* check to see if they started with a quote, note parse_args gets rid of
quotes so we have to actually check input_string */
if (input_string[input_strings_length - string_to_finds_length - 1] == '"')
quote_end = 1; /* tag a quote on the end if they started with one */
else /* if they didn't start with a quote see if the match has spaces in it */
{
for (i = 0; i < strlen(matches[0]); i++)
{
if (matches[0][i] == ' ')
{
/* if we've got spaces put quotes around the result */
quote_begin = 1;
quote_end = 1;
break;
}
}
}
if (quote_begin)
{
input_string[input_strings_length - string_to_finds_length] = '"';
strcpy(input_string + input_strings_length - string_to_finds_length + 1, matches[0]);
}
else
strcat(input_string, (char*)(matches[0] + string_to_finds_length));
if (quote_end)
strcat(input_string, "\"");
/* put a space on the end all the time unless it's a command and they
want to see tard tips. */
if (!(pref.tardtips && string_to_find[0] == '/'))
strcat(input_string, " ");
break;
default:
if(numberofmatches >= MAXMATCHES)
{
info("Maxium matches exceeded.");
beep();
}
else
{
int numofcharsmatch = 0, tmplength = string_to_finds_length - 1;
wattrset(current_window->window, CP(colors.tabfore, colors.tabback)|A_BOLD);
wprintw(current_window->window, "Possible Matches: ");
wattroff(current_window->window, A_BOLD);
for(i = 0; i < numberofmatches; i++)
wprintw(current_window->window, "%s ", matches[i]);
wprintw(current_window->window, "\n");
wattrset(current_window->window, CP(colors.mainfore, colors.mainback));
wrefresh(current_window->window);
do
{
char tmpchr = matches[0][tmplength];
numofcharsmatch = 0;
for(i = 0; i < numberofmatches; i++)
{
if(matches[i][tmplength] == tmpchr)
numofcharsmatch++;
}
tmplength++;
}
while(numofcharsmatch == numberofmatches);
amount_to_add = tmplength - string_to_finds_length - 1;
if (amount_to_add > 0)
{
strncat(input_string, matches[0] + string_to_finds_length, amount_to_add);
return 1;
}
else
beep();
}
return 0;
}
return 1;
}
|