1 /* -*- Mode: C++-C -*- 2 * 3 * Copyright 1994 Christopher B. Liebman 4 * 5 * Permission to use, copy, modify, distribute, and sell this software 6 * and its documentation for any purpose is hereby granted without fee, 7 * provided that the above copyright notice appear in all copies and that 8 * both that copyright notice and this permission notice appear in 9 * supporting documentation, and that the name Christopher B. Liebman not 10 * be used in advertising or publicity pertaining to distribution of this 11 * software without specific, written prior permission. 12 * 13 * THIS SOFTWARE IS PROVIDED `AS-IS'. CHRISTOPHER B. LIEBMAN, DISCLAIMS 14 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT 15 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL CHRISTOPHER 17 * B. LIEBMAN, BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING SPECIAL, 18 * INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, OR 19 * PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF 20 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF 21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 * 23 * Author : Chris Liebman 24 * Created On : Tue Jan 11 14:11:30 1994 25 * Last Modified By: Chris Liebman 26 * Last Modified On: Mon Mar 7 16:55:46 1994 27 * Update Count : 164 28 * Status : Released 29 * 30 * HISTORY 31 * 13-Feb-1994 Chris Liebman 32 * Last Modified: Sun Feb 13 00:38:34 1994 #150 (Chris Liebman) 33 * Added mail annotations. Also added new command stuff. 34 * 35 * 2-Feb-1994 Chris Liebman 36 * Last Modified: Tue Feb 1 14:38:13 1994 #120 (Chris Liebman) 37 * Added annotation support. 38 * 39 * 31-Jan-1994 Chris Liebman 40 * Last Modified: Mon Jan 31 22:35:28 1994 #116 (Chris Liebman) 41 * New search support and resources. 42 * 43 * 24-Jan-1994 Chris Liebman 44 * Last Modified: Sun Jan 23 18:54:23 1994 #47 (Chris Liebman) 45 * Added lots of new resources! 46 * 47 * 18-Jan-1994 Chris Liebman 48 * Last Modified: Tue Jan 18 16:57:29 1994 #31 (Chris Liebman) 49 * Handle the cases where index, rindex, bcopy, bzero are 50 * already defined as macros on SYSV. Added new resource: 51 * closeness. Added new header structs. 52 * 53 * 14-Jan-1994 Chris Liebman 54 * Last Modified: Fri Jan 14 10:22:29 1994 #5 (Chris Liebman) 55 * Added defines for index(), rindex(), bcopy() and bzero() for SYSV. 56 * Removed include of xpm.h, its now in face_image_xpm.c. 57 * Added new ignore message binding resource element to TheXFacesResources. 58 * Added the status header to the Face structure. 59 * 60 * PURPOSE 61 * Definitions structures and extern declarations for xfaces. 62 * 63 * $Id: faces.h,v 1.29 1994/03/12 20:05:52 liebman Exp $ 64 */ 65 66 #ifndef FACES_H_ 67 #define FACES_H_ 68 69 #include <stdio.h> 70 #include <ctype.h> 71 #include <pwd.h> 72 #include <X11/Intrinsic.h> 73 #include <X11/StringDefs.h> 74 #include <X11/Xaw/Label.h> 75 #include "Tiled.h" 76 77 #ifndef SYSV 78 #include <strings.h> 79 #else 80 81 /* 82 * Handle these functions if macros are not already defined. 83 */ 84 85 #ifndef index 86 #define index(a, b) strchr(a, b) 87 #endif 88 #ifndef rindex 89 #define rindex(a, b) strrchr(a, b) 90 #endif 91 #ifndef bcopy 92 #define bcopy(a, b, c) memcpy(b, a, c) 93 #endif 94 #ifndef bzero 95 #define bzero(a, b) memset(a, 0, b) 96 #endif 97 98 #endif /* SYSV */ 99 100 #include "regexp.h" 101 #include "patchlevel.h" 102 103 /* 104 * Compare a string. 105 */ 106 107 #define StringEqVal(s1, val) (strncmp((s1), (val), strlen(val)) == 0) 108 109 /* 110 * Application class. 111 */ 112 113 #ifndef XFACES_CLASS 114 #define XFACES_CLASS "XFaces" 115 #endif 116 117 /* 118 * Max size for mail seperator string. 119 */ 120 121 #define MAX_MAILSEP_SIZE 31 122 #define MAIL_SEP1 "From " 123 #define MAIL_SEP1_SKIP False 124 #define MAIL_SEP2 "\001\001\001\001\n" 125 #define MAIL_SEP2_SKIP True 126 127 /* 128 * The face type. 129 */ 130 131 typedef struct face Face; 132 typedef struct face_item FaceItem; 133 134 /* 135 *Image and sound types. 136 */ 137 138 typedef struct face_image FaceImage; 139 typedef struct face_image_type FaceImageType; 140 typedef struct face_sound FaceSound; 141 typedef struct face_sound_type FaceSoundType; 142 typedef struct face_command FaceCommand; 143 typedef struct face_search_type FaceSearchType; 144 typedef struct face_search_data FaceSearchData; 145 146 /* 147 * Here is a mail item structures. 148 */ 149 150 typedef struct mail_header MailHeader; 151 typedef struct mail_item MailItem; 152 153 /* 154 * Here is the binding structure. 155 */ 156 157 typedef struct face_binding 158 { 159 String name; /* Field to search. */ 160 String patsrc; 161 regexp *pattern; /* Pattern to search for. */ 162 String file; /* file for image/sound. */ 163 String label; /* Label for face. */ 164 int anno; /* Annotation number for label. */ 165 int casesensitive; /* Zero means case insensitive. */ 166 struct face_binding *next; 167 } FaceBinding; 168 169 /* 170 * The resource structure. 171 */ 172 173 typedef struct _faces_resources 174 { 175 String spool_dir; /* The directory for default spool */ 176 /* files. */ 177 String spool_file; /* This is the file to monitor */ 178 /* (full path!). */ 179 String list_command; 180 String pop_host; /* pop mailbox host. */ 181 int pop_port; 182 String pop_auth_file; /* login/passwd for pop server */ 183 /* (full path!) */ 184 String image_path; /* Where to find the images. */ 185 char* image_path_str; 186 char** image_paths; 187 String sound_path; /* Where to find the sounds. */ 188 char* sound_path_str; 189 char** sound_paths; 190 String facedb_path; /* Where to find the facedb's.*/ 191 char* facedb_path_str; 192 char** facedb_paths; 193 char* machine; /* name for machine file. */ 194 char* people; /* name for people file. */ 195 int update; /* How often to check the mail. */ 196 int volume; /* How loud to play sounds. */ 197 String from_field; /* String to use as the field name 198 * for getting the from name. */ 199 String no_mail_image; /* No mail picture. */ 200 String no_mail_sound; /* No mail sound. */ 201 Boolean keep_order; 202 Boolean compress_images; /* Show faces compressed. */ 203 Boolean use_sound; /* Play sounds. */ 204 Boolean use_shape; /* Shape windows. */ 205 Boolean use_commands; /* Shape windows. */ 206 Boolean use_content_length; /* Use Content-Length header (if 207 * available) to skip mail body. */ 208 Boolean shape_borders; 209 Boolean shape_internal; 210 int closeness; /* Allow similar colors. */ 211 String image_types_str; 212 FaceImageType** image_types; 213 String image_search_str; 214 FaceSearchData* image_search; 215 String sound_search_str; 216 FaceSearchData* sound_search; 217 String command_search_str; 218 FaceSearchData* command_search; 219 String ignore_message_bindings_str; 220 FaceBinding* ignore_message_bindings; 221 String before_image_bindings_str; 222 FaceBinding* before_image_bindings; 223 String after_image_bindings_str; 224 FaceBinding* after_image_bindings; 225 String before_sound_bindings_str; 226 FaceBinding* before_sound_bindings; 227 String after_sound_bindings_str; 228 FaceBinding* after_sound_bindings; 229 String before_command_bindings_str; 230 FaceBinding* before_command_bindings; 231 String after_command_bindings_str; 232 FaceBinding* after_command_bindings; 233 int annotation_count; 234 int unknown_annotation_count; 235 Boolean annotation_above; 236 Pixel background; 237 Boolean shape_extra; 238 Boolean path_by_chdir; 239 Boolean lookup_hostname; 240 } FacesResourcesRec, *FacesResources; 241 242 /* 243 * Headers are on a double linked list. 244 */ 245 246 struct mail_header 247 { 248 char* name; /* Header name. */ 249 char* value; /* Header value. */ 250 char* line; /* If we could not parse out name/value. */ 251 MailHeader* next; /* Next header. */ 252 MailHeader* prev; /* Previous header. */ 253 }; 254 255 struct mail_item 256 { 257 String user; /* User from From line. */ 258 String host; /* Host from From line. */ 259 String realhost; /* Unaliased hostname. */ 260 String label; /* Item label. */ 261 int use_label; /* Use label for annotation. */ 262 int unknown; /* if non zero use unknown annos. */ 263 int in_use; /* Message in use. */ 264 MailHeader *headers; /* List of mail headers. */ 265 char* body; /* Mail body. */ 266 FaceImage* image; /* Image for user. */ 267 FaceSound* sound; /* Sound to play. */ 268 FaceCommand* command; /* Command to run. */ 269 Face* face; 270 char** annotations; /* Annotation data. */ 271 MailItem* next; /* Pointer to next item. */ 272 MailItem* prev; /* Pointer to prev item. */ 273 }; 274 275 struct face_item 276 { 277 MailItem* item; 278 FaceItem* next; 279 }; 280 281 282 /* 283 * Here is a face structure. 284 */ 285 286 struct face 287 { 288 FaceImage *image; /* Image */ 289 char* label; /* Face label. */ 290 int count; /* Count of items using this face. */ 291 int last_count; /* Previous count. */ 292 FaceItem* items; /* List of mail items using face. */ 293 Widget widget; /* Widget used to display user. */ 294 Pixmap pixmap; /* Annotated pixmap. */ 295 Pixmap shape; /* Annotated shape pixmap. */ 296 char** annotations; /* Annotation data. */ 297 struct face *next; /* Pointer to next face. */ 298 struct face *prev; /* Pointer to prev face. */ 299 }; 300 301 typedef enum face_format 302 { 303 FormatImage = 1, 304 FormatAudio, 305 FormatCommand 306 } FaceFormat; 307 308 #ifdef __STDC__ 309 #define P_(xxx) xxx 310 #else 311 #define P_(xxx) () 312 #endif 313 314 /* 315 * Global variable definitions. 316 */ 317 318 /* face_display.c */ 319 320 extern Face *TheFaceList; 321 extern Widget NoMailWidget; 322 323 /* mail_box.c */ 324 extern char* MailSeperator; 325 extern int MailSeperatorLength; 326 extern Boolean MailSeperatorSkip; 327 328 /* mail_items.c */ 329 330 extern MailItem* TheMailItems; 331 332 /* main.c */ 333 extern FacesResourcesRec TheFacesResources; 334 extern Widget TheTopLevel; 335 extern Widget TheFrame; 336 extern FaceImage *NoMailImage; 337 extern FaceSound *NoMailSound; 338 339 340 extern char *getlogin(); 341 342 343 /* 344 * External functions. 345 */ 346 347 /* cmd_check.c */ 348 349 extern void CmdCheck P_((void)); 350 351 /* face_actions.c */ 352 extern void FaceActionsInit P_((void)); 353 354 /* face_annotate.c */ 355 356 extern int FaceAnnotate P_((Face* face)); 357 extern void FaceAnnotateFree P_((Face* face)); 358 extern void FaceAnnotateInit P_((void)); 359 360 /* face_binding.c */ 361 362 extern FaceBinding* FaceBindingParse P_((String str, 363 int has_value, 364 int has_label)); 365 extern FaceBinding* FaceBindingCheck P_((MailHeader* headers, 366 FaceBinding*bindings)); 367 368 /* face_command.c */ 369 370 extern void FaceCommandFree P_((FaceCommand* fc)); 371 extern int FaceCommandLoad P_((char* name, MailItem* item, FaceSearchData* data)); 372 extern void FaceCommandRun P_((FaceCommand* fc)); 373 extern void FaceCommandFind P_((MailItem* item)); 374 375 /* face_display.c */ 376 extern Face* FaceDisplay P_((MailItem* item)); 377 extern void FaceClear P_((void)); 378 extern void FaceClean P_((void)); 379 extern int FaceCount P_((void)); 380 extern void FaceDisplayInit P_((void)); 381 382 /* face_image.c */ 383 extern FaceImageType* FaceImageTypeByName P_((char* name)); 384 extern void FaceImageTypeRegister P_((FaceImageType* type)); 385 extern FaceImageType** FaceImageTypeListParse P_((char* str)); 386 extern int FaceImageLoad P_((char* file, MailItem* item, FaceSearchData* data)); 387 extern FaceImage* FaceImageCreate P_((char* file, 388 FaceImageType* type, 389 void* data)); 390 extern void FaceImageLabelCreate P_((MailItem* item)); 391 extern void FaceImageFree P_((FaceImage* fi)); 392 extern Pixmap FaceImagePixmap P_((FaceImage* fi)); 393 extern Pixmap FaceImageShape P_((FaceImage* fi)); 394 extern String StringConcat P_((String s1, 395 String s2)); 396 extern void FaceImageRef P_((FaceImage* fi)); 397 extern void FaceImageCount P_((FaceImage* fi)); 398 extern void FaceImageDecount P_((FaceImage* fi)); 399 extern String FaceImageLabelGet P_((FaceImage* fi)); 400 401 extern void FaceImageFind P_((MailItem* item)); 402 403 /* face_image_xbm.c */ 404 405 extern void FaceImageColorize P_((Pixmap* pixmap, int width, int height)); 406 extern void* FaceImageXbmRead P_((String file, void* type_data)); 407 #ifdef SHAPE 408 extern void* FaceImageShapedXbmRead P_((String file, void* type_data)); 409 #endif 410 extern void FaceImageXbmFree P_((void* data, void* type_data)); 411 extern Pixmap FaceImageXbmPixmap P_((void *data, void* type_data)); 412 extern Pixmap FaceImageXbmShape P_((void *data, void* type_data)); 413 extern void FaceImageXbmInit P_((void)); 414 415 /* face_image_xface.c */ 416 #ifdef XFACE 417 extern FaceImage* FaceImageXFaceCreate P_((String str)); 418 extern void FaceImageXFaceFree P_((void* data, void* type_data)); 419 extern Pixmap FaceImageXFacePixmap P_((void *data, void* type_data)); 420 extern Pixmap FaceImageXFaceShape P_((void *data, void* type_data)); 421 #endif 422 423 /* face_image_xpm.c */ 424 425 extern void* FaceImageXpmRead P_((String file, void* type_data)); 426 #ifdef SHAPE 427 extern void* FaceImageShapedXpmRead P_((String file, void* type_data)); 428 #endif 429 extern void FaceImageXpmFree P_((void* data, void* type_data)); 430 extern Pixmap FaceImageXpmPixmap P_((void *data, void* type_data)); 431 extern Pixmap FaceImageXpmShape P_((void *data, void* type_data)); 432 extern void FaceImageXpmInit P_((void)); 433 434 /* face_search.c */ 435 436 extern FaceSearchType* FaceSearchTypeByName P_((char *name)); 437 extern void FaceSearchTypeRegister P_((FaceSearchType* type)); 438 extern int FaceSearch P_((MailItem* item, FaceSearchData* search_list)); 439 extern int FaceSearchLoad P_((char *name, MailItem* item, FaceSearchData* data)); 440 extern FaceSearchData* FaceSearchParse P_((char* str, FaceFormat format)); 441 442 /* face_search_binding.c */ 443 444 extern void FaceSearchBindingInit P_((void)); 445 446 /* face_search_facedb.c */ 447 448 extern void FaceSearchFacedbInit P_((void)); 449 450 /* face_search_resource.c */ 451 452 extern void FaceSearchResourceInit P_((void)); 453 454 /* face_search_uh.c */ 455 456 extern void FaceSearchUserHostInit P_((void)); 457 458 /* face_search_xface.c */ 459 #ifdef XFACE 460 extern void FaceSearchXFaceInit P_((void)); 461 #endif 462 463 /* face_shape.c */ 464 465 extern void FaceShapeCreate P_((void)); 466 467 /* face_sound.c */ 468 469 #ifdef SOUND 470 extern FaceSound* FaceSoundCreate P_((char* file)); 471 extern void FaceSoundFree P_((FaceSound* fs)); 472 extern int FaceSoundLoad P_((char* name, MailItem* item, FaceSearchData* data)); 473 extern void FaceSoundPlay P_((FaceSound* fs)); 474 extern void FaceSoundInit P_((void)); 475 extern void FaceSoundFind P_((MailItem* item)); 476 #endif 477 478 /* mail_body.c */ 479 480 extern char* MailBodyRead P_((int content_length)); 481 extern void MailBodySkip P_((int content_length)); 482 483 /* mail_box.c */ 484 485 extern void MailBoxParse P_((void)); 486 487 /* mail_check.c */ 488 489 extern void MailCheck P_((void)); 490 491 /* mail_file.c */ 492 493 extern int MailFileOpen P_((char* name)); 494 extern void MailFileClose P_((void)); 495 extern int MailFileReadChar P_((void)); 496 extern void MailFileUnReadChar P_((int ch)); 497 extern void MailFileUnReadString P_((char* str)); 498 extern void MailFileClearUnRead P_((void)); 499 extern void MailFilePeekString P_((char* buf, int len)); 500 extern int MailFileReadString P_((char* buf, int len)); 501 extern int MailFileSkipString P_((int len)); 502 extern int MailFilePeekChar P_(()); 503 504 /* mail_header.c */ 505 506 extern char* MailHeaderLineRead P_((void)); 507 extern MailHeader* MailHeaderRead P_((void)); 508 extern MailHeader* MailHeaderListRead P_((void)); 509 extern void MailHeaderFree P_((MailHeader* header)); 510 extern void MailHeaderListFree P_((MailHeader* list)); 511 extern MailHeader* MailHeaderFind P_((char* name, MailHeader* list)); 512 extern int MailHeaderListCompare P_((MailHeader* list1, MailHeader* list2)); 513 514 /* mail_items.c */ 515 516 extern void MailBoxClear P_((void)); 517 extern void MailBoxUnClear P_((void)); 518 extern void MailBoxClean P_((void)); 519 extern void MailItemCreate P_((MailHeader* headers)); 520 extern void MailItemCreateNoHeaders P_((char* user, 521 char* host, 522 char** annotations)); 523 extern void MailBoxEmpty P_((void)); 524 extern void MailItemInit P_((void)); 525 526 /* mail_parse.c */ 527 528 extern void MailParseAddress P_((String from, 529 String* user, 530 String* host)); 531 532 /* main.c */ 533 534 extern void CheckMailNow P_((void)); 535 extern int main P_((int argc, char** argv)); 536 extern void regerror P_((String s)); 537 538 /* path.c */ 539 540 extern char** PathParse P_((char* path)); 541 extern int PathEnumerate P_((char* file, 542 char** paths, 543 int (*func)(char* file, char* path, void* data), 544 void* data)); 545 546 /* pop_check.c */ 547 548 extern void PopCheck P_((void)); 549 550 /* regexp.c */ 551 552 extern regexp* regcomp P_((char* exp)); 553 extern int regexec P_((regexp *prog, char *string)); 554 555 /* regsub.c */ 556 557 extern void regsub P_((regexp *prog, char *source, char *dest)); 558 559 /* string.c */ 560 561 extern char* SkipChars P_((char* str, char* delim)); 562 extern char* ParseToken P_((char** str, char* delim)); 563 extern char** StringParse P_((char* str, char* delims)); 564 565 #endif /* FACES_H_ */ 566