Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

smileys.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <glib.h>
00005 
00006 #include "pixmaps/smile.xpm"
00007 #include "pixmaps/sad.xpm"
00008 #include "pixmaps/wink.xpm"
00009 #include "pixmaps/biglaugh.xpm"
00010 #include "pixmaps/laugh.xpm"
00011 #include "pixmaps/cry.xpm"
00012 #include "pixmaps/tongue.xpm"
00013 #include "pixmaps/cooldude.xpm"
00014 #include "pixmaps/note.xpm"
00015 #include "pixmaps/dude.xpm"
00016 #include "pixmaps/worried.xpm"
00017 #include "pixmaps/confused.xpm"
00018 #include "pixmaps/grin.xpm"
00019 #include "pixmaps/blankface.xpm"
00020 #include "pixmaps/blush.xpm"
00021 #include "pixmaps/oh.xpm"
00022 #include "pixmaps/heyyy.xpm"
00023 #include "pixmaps/lovey.xpm"
00024 #include "pixmaps/angry.xpm"
00025 #include "pixmaps/wine.xpm"
00026 #include "pixmaps/beer.xpm"
00027 
00028 #include "globals.h"
00029 #include "service.h"
00030 #include "smileys.h"
00031 
00032 static char *no_smileys[] = {
00033     "http://",
00034     "https://",
00035     "ftp://",
00036     "mailto:/",
00037     NULL
00038 };
00039 
00040 GList *smileys=NULL;
00041 GList *default_smileys=NULL;
00042 
00043 static GList *_eb_smileys=NULL;
00044 
00045 /* someone figure out how to do this with GList * const */
00046 GList * eb_smileys(void)
00047 {
00048   return _eb_smileys;
00049 }
00050 
00051 void init_smileys(void)
00052 {
00053   smileys=add_smiley(smileys, "smile", smile_xpm);
00054   smileys=add_smiley(smileys, "sad", sad_xpm);
00055   smileys=add_smiley(smileys, "wink", wink_xpm);
00056   smileys=add_smiley(smileys, "biglaugh", biglaugh_xpm);
00057   smileys=add_smiley(smileys, "laugh", laugh_xpm);
00058   smileys=add_smiley(smileys, "cry", cry_xpm);
00059   smileys=add_smiley(smileys, "tongue", tongue_xpm);
00060   smileys=add_smiley(smileys, "cooldude", cooldude_xpm);
00061   smileys=add_smiley(smileys, "note", note_xpm);
00062   smileys=add_smiley(smileys, "dude", dude_xpm);
00063   smileys=add_smiley(smileys, "worried", worried_xpm);
00064   smileys=add_smiley(smileys, "grin", grin_xpm);
00065   smileys=add_smiley(smileys, "confused", confused_xpm);
00066   smileys=add_smiley(smileys, "blank", blankface_xpm);
00067   smileys=add_smiley(smileys, "blush", blush_xpm);
00068   smileys=add_smiley(smileys, "oh", oh_xpm);
00069   smileys=add_smiley(smileys, "heyyy", heyyy_xpm);
00070   smileys=add_smiley(smileys, "lovey", lovey_xpm);
00071   smileys=add_smiley(smileys, "angry", angry_xpm);
00072   smileys=add_smiley(smileys, "wine", wine_xpm);
00073   smileys=add_smiley(smileys, "beer", beer_xpm);
00074 
00075   _eb_smileys = smileys;
00076 
00077   default_smileys=add_protocol_smiley(default_smileys, ":-)", "smile");
00078   default_smileys=add_protocol_smiley(default_smileys, ":)", "smile");
00079   default_smileys=add_protocol_smiley(default_smileys, "=)", "smile");
00080 
00081   default_smileys=add_protocol_smiley(default_smileys, ":-(", "sad");
00082   default_smileys=add_protocol_smiley(default_smileys, ":(", "sad");
00083 
00084   default_smileys=add_protocol_smiley(default_smileys, ";-)", "wink");
00085   default_smileys=add_protocol_smiley(default_smileys, ";)", "wink");
00086 
00087   default_smileys=add_protocol_smiley(default_smileys, ":-D", "biglaugh");
00088   default_smileys=add_protocol_smiley(default_smileys, ":D", "biglaugh");
00089 
00090   default_smileys=add_protocol_smiley(default_smileys, ":-P", "tongue");
00091   default_smileys=add_protocol_smiley(default_smileys, ":P", "tongue");
00092 
00093   default_smileys=add_protocol_smiley(default_smileys, ":-p", "tongue");
00094   default_smileys=add_protocol_smiley(default_smileys, ":p", "tongue");
00095 
00096   default_smileys=add_protocol_smiley(default_smileys, ":-S", "worried");
00097   default_smileys=add_protocol_smiley(default_smileys, ":S", "worried");
00098   default_smileys=add_protocol_smiley(default_smileys, ":-s", "worried");
00099   default_smileys=add_protocol_smiley(default_smileys, ":s", "worried");
00100 
00101   default_smileys=add_protocol_smiley(default_smileys, ":-/", "worried");
00102   default_smileys=add_protocol_smiley(default_smileys, ":/", "worried");
00103 
00104   default_smileys=add_protocol_smiley(default_smileys, ">:-O", "angry");
00105   default_smileys=add_protocol_smiley(default_smileys, ">:O", "angry");
00106   default_smileys=add_protocol_smiley(default_smileys, ">:-o", "angry");
00107   default_smileys=add_protocol_smiley(default_smileys, ">:o", "angry");
00108 
00109   default_smileys=add_protocol_smiley(default_smileys, ":'(", "cry");
00110 }
00111 
00112 gchar * eb_smilify(gchar * text, GList * protocol_smileys)
00113 {
00114   int ipos=0;
00115   int found;
00116   int i;
00117   GList * l=protocol_smileys;
00118   GString * newstr;
00119   char * result;
00120 
00121   if(!do_smiley)
00122   {
00123       return text;
00124   }
00125 
00126   newstr=g_string_sized_new(2048);
00127 
00128   while(text[ipos]!='\0')
00129   {
00130     /* ignore anything in < > */
00131     if(text[ipos] == '<') {
00132       while(text[ipos] && text[ipos] != '>') {
00133         g_string_append_c(newstr, text[ipos++]);
00134       }
00135       if(text[ipos] == '>')
00136         g_string_append_c(newstr, text[ipos++]);
00137       else  /* text[ipos] is null */
00138         break;
00139     }
00140 
00141     /* ignore anything in the ignore list (http://, ftp://, etc.) */
00142     for(i=0; no_smileys[i]; i++) {
00143       int len = strlen(no_smileys[i]);
00144       if( !strncmp( text + ipos, no_smileys[i], len ) ) {
00145         g_string_append(newstr, no_smileys[i]);
00146     ipos += len;
00147       }
00148     }
00149 
00150     
00151     l=protocol_smileys;
00152 
00153     found=0;
00154 
00155     while(l!=NULL)
00156     {
00157       protocol_smiley * ps=(protocol_smiley *)l->data;
00158       if(!strncmp(text+ipos, ps->text, strlen(ps->text)))
00159       {
00160         g_string_append(newstr, "<smiley name=\"");
00161         g_string_append(newstr, ps->name);
00162     g_string_append(newstr, "\" alt=\"");
00163     g_string_append(newstr, ps->text);
00164         g_string_append(newstr, "\">");
00165         ipos += strlen(ps->text);
00166         found=1;
00167         break;
00168       }
00169       l=l->next;
00170     }
00171     if(!found) { g_string_append_c(newstr, text[ipos++]); }
00172   }
00173 
00174 
00175   free(text);
00176   result = newstr->str;
00177   g_string_free(newstr, FALSE);
00178 
00179   return result;
00180 }
00181 
00182 GList * eb_default_smileys(void)
00183 {
00184   return default_smileys;
00185 }
00186 
00187 GList * add_protocol_smiley(GList * list, char * text, char * name)
00188 {
00189   protocol_smiley * psmile;
00190 
00191   psmile=g_new0(protocol_smiley, 1);
00192   strcpy(psmile->text, text);
00193   strcpy(psmile->name, name);
00194   return g_list_append(list, psmile);
00195 }
00196 
00197 GList * add_smiley(GList * list, char * name, gchar ** data)
00198 {
00199   smiley * psmile;
00200 
00201   psmile=g_new0(smiley, 1);
00202   strcpy(psmile->name, name);
00203   psmile->pixmap=data;
00204   return g_list_append(list, psmile);
00205 }
00206 
00207 smiley * get_smiley_by_name(char * name) {
00208   smiley * psmile;
00209   GList * l = smileys;
00210   while(l != NULL) {
00211     psmile = (smiley *)(l->data);
00212     if(!strcmp(psmile->name,name)) 
00213        return psmile;
00214     l=g_list_next(l);
00215   }
00216   return NULL;
00217 }

Contact: Andy Maloney     [Documentation generated by doxygen]