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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
/* -*- Mode: C++-C -*-
*
* Copyright 1994 Christopher B. Liebman
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name Christopher B. Liebman not
* be used in advertising or publicity pertaining to distribution of this
* software without specific, written prior permission.
*
* THIS SOFTWARE IS PROVIDED `AS-IS'. CHRISTOPHER B. LIEBMAN, DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
* LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL CHRISTOPHER
* B. LIEBMAN, BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING SPECIAL,
* INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, OR
* PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
* WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author : Chris Liebman
* Created On : Thu Jan 27 09:53:07 1994
* Last Modified By: Chris Liebman
* Last Modified On: Sun Feb 13 17:07:36 1994
* Update Count : 65
* Status : Released
*
* HISTORY
* 13-Feb-1994 Chris Liebman
* Last Modified: Sat Feb 12 22:04:13 1994 #64 (Chris Liebman)
* Added FormatCommand support.
*
* PURPOSE
* Handle searching for images/sounds.
*/
#ifndef lint
static char *RCSid = "$Id: face_search.c,v 1.5 1994/02/13 22:33:30 liebman Exp $";
#endif
#include "faces.h"
#include "face_search.h"
/*
* This is the master list of supported search types.
*/
static FaceSearchType* AllSearchTypes = NULL;
/*
* Look up an search type by name.
*/
FaceSearchType*
FaceSearchTypeByName(name)
char* name;
{
FaceSearchType* type;
for (type = AllSearchTypes; type != NULL; type = type->next)
{
if (strcmp(name, type->name) == 0)
{
return type;
}
}
return NULL;
}
/*
* Register a new search type.
*/
void
FaceSearchTypeRegister(type)
FaceSearchType* type;
{
type->next = AllSearchTypes;
AllSearchTypes = type;
}
/*
* Use the search data and search for something.
*/
int
FaceSearch(item, search_list)
MailItem* item;
FaceSearchData* search_list;
{
FaceSearchData* data;
#ifdef SEARCH_DEBUG
fprintf(stderr, "FaceSearch failed.\n");
#endif
/*
* Foreach search specifier we look for each type with each path.
*/
for(data = search_list; data != NULL; data = data->next)
{
#ifdef SEARCH_DEBUG
fprintf(stderr, "Attempting search type: <%s>\n", data->search->name);
#endif
if (data->search->search(item, data))
{
#ifdef SEARCH_DEBUG
fprintf(stderr, "Succeded with search type: <%s>\n",
data->search->name);
#endif
return 1;
}
}
#ifdef SEARCH_DEBUG
fprintf(stderr, "FaceSearch failed.\n");
#endif
return 0;
}
/*
* Load a sound/image
*/
int
FaceSearchLoad(name, item, data)
char* name;
MailItem* item;
FaceSearchData* data;
{
int ret = 0;
switch(data->format)
{
case FormatImage:
ret = FaceImageLoad(name, item, data);
break;
#ifdef SOUND
case FormatAudio:
ret = FaceSoundLoad(name, item, data);
break;
#endif
case FormatCommand:
ret = FaceCommandLoad(name, item, data);
break;
default:
fprintf(stderr, "FaceSearchLoad: unknown format flag!\n");
ret = 0;
break;
}
return ret;
}
/*
* Parse the search bindings.
*/
FaceSearchData*
FaceSearchParse(str, format)
char* str;
FaceFormat format;
{
FaceSearchData* head = NULL;
FaceSearchData* tail = NULL;
FaceSearchData* data;
FaceSearchType* search = NULL;
FaceImageType** itypes = NULL;
char** paths = NULL;
char* line;
char* value;
if (str == NULL)
{
return(NULL);
}
while((line = ParseToken(&str, "\n")) != NULL)
{
/*
* Skip past any leading whitespace.
*/
line = SkipChars(line, "\t \n");
/*
* Get name of search type.
*/
value = ParseToken(&line, " \t\n");
/*
* if there was no search name then skip this line.
*/
if ((value == NULL) || ((search = FaceSearchTypeByName(value)) == NULL))
{
if (value != NULL)
{
fprintf(stderr, "FaceSearchParse: bad search type: <%s>\n", value);
}
continue;
}
/*
* Get the list of types.
*/
value = ParseToken(&line, " \t\n");
if (value != NULL)
{
if (format == FormatImage)
{
itypes = FaceImageTypeListParse(value);
}
else
{
/*
* We ignore the type list for sounds.
*/
}
}
/*
* Get the path list.
*/
value = ParseToken(&line, " \t\n");
if (value != NULL)
{
paths = PathParse(value);
}
/*
* Construct a new search data.
*/
data = XtNew(FaceSearchData);
data->format = format;
data->search = search;
if (format == FormatImage)
{
data->stypes = NULL;
data->itypes = itypes;
}
else
{
data->itypes = NULL;
data->stypes = NULL;
}
data->paths = paths;
data->next = NULL;
/*
* Construct list.
*/
if (!head)
{
head = data;
tail = data;
}
else
{
tail->next = data;
tail = data;
}
}
return(head);
}
|