[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Ayttm-commits] CVS: ayttm/modules/utility autotrans.c,1.9,1.10 middle.
From: |
Philip S Tellis <address@hidden> |
Subject: |
[Ayttm-commits] CVS: ayttm/modules/utility autotrans.c,1.9,1.10 middle.c,1.7,1.8 rainbow.c,1.8,1.9 |
Date: |
Fri, 07 Feb 2003 03:25:36 -0500 |
Update of /cvsroot/ayttm/ayttm/modules/utility
In directory subversions:/tmp/cvs-serv11196/modules/utility
Modified Files:
autotrans.c middle.c rainbow.c
Log Message:
fixed autotrans, and mem leaks in filters
Index: autotrans.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/utility/autotrans.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- autotrans.c 29 Jan 2003 19:19:22 -0000 1.9
+++ autotrans.c 7 Feb 2003 08:25:33 -0000 1.10
@@ -1,5 +1,5 @@
/*
- * EveryBuddy
+ * Autotrans module for Ayttm
*
* Copyright (C) 2003, the Ayttm team
*
@@ -33,66 +33,38 @@
#include "plugin_api.h"
#include "prefs.h"
#include "util.h"
+#include "tcp_util.h"
/* already declared in dialog.h - but that uses gtk */
void do_message_dialog(char *message, char *title, int modal);
-void do_list_dialog( gchar * message, gchar * title, char **list, void
(*action)(char * text, gpointer data), gpointer data );
+void do_list_dialog(char * message, char * title, char **list,
+ void (*action) (char *text, gpointer data),
+ gpointer data);
/*******************************************************************************
* Begin Module Code
******************************************************************************/
/* Module defines */
#define plugin_info autotrans_LTX_plugin_info
-#define plugin_init autotrans_LTX_plugin_init
-#define plugin_finish autotrans_LTX_plugin_finish
/* Function Prototypes */
-static gchar * doTranslate(gchar * string, gchar * from, gchar * to);
-static gchar * translate_out(eb_local_account * local, eb_account * remote,
struct contact * contact, gchar * s);
-static gchar * translate_in(eb_local_account * local, eb_account * remote,
struct contact * contact, gchar * s);
+static char *translate_out(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char * s);
+static char *translate_in(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char * s);
-static char * trans_URLEncode(char * s);
static int trans_init();
static int trans_finish();
-static void language_select(ebmCallbackData *data);
-static void language_selected(char * text, gpointer data);
+static void language_select(ebmCallbackData * data);
-static int doTrans=0;
-static gchar myLanguage[MAX_PREF_LEN]="en";
+static int doTrans = 0;
+static char myLanguage[MAX_PREF_LEN] = "en";
-static void * tag1;
-static void * tag2;
+static void *tag1;
+static void *tag2;
-static int ref_count=0;
-
-/*
-** Name: Utf8ToStr
-** Purpose: revert UTF-8 string conversion
-** Input: in - the string to decode
-** Output: a new decoded string
-*/
-static char *Utf8ToStr(char *in)
-{
- int i = 0;
- unsigned int n;
- char *result = NULL;
- result = (char *) malloc(strlen(in) + 1);
-
- /* convert a string from UTF-8 Format */
- for (n = 0; n < strlen(in); n++) {
- unsigned char c = in[n];
-
- if (c < 128) {
- result[i++] = (char) c;
- }
- else {
- result[i++] = (c << 6) | (in[++n] & 63);
- }
- }
- result[i] = '\0';
- return result;
-}
+static int ref_count = 0;
/* Module Exports */
@@ -111,262 +83,296 @@
static int trans_init()
{
+ input_list *il = calloc(1, sizeof(input_list));
+ plugin_info.prefs = il;
+ il->widget.checkbox.value = &doTrans;
+ il->widget.checkbox.name = "doTrans";
+ il->widget.checkbox.label = strdup(_("Enable automatic translation"));
+ il->type = EB_INPUT_CHECKBOX;
+
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = myLanguage;
+ il->widget.entry.name = "myLanguage";
+ il->widget.entry.label = strdup(_("My language code:"));
+ il->type = EB_INPUT_ENTRY;
+
+ eb_debug(DBG_MOD, "Auto-trans initialised\n");
- input_list * il=g_new0(input_list, 1);
- plugin_info.prefs=il;
-
- il->widget.checkbox.value = &doTrans;
- il->widget.checkbox.name = "doTrans";
- il->widget.checkbox.label = g_strdup(_("Enable automatic translation"));
- il->type=EB_INPUT_CHECKBOX;
-
- il->next=g_new0(input_list, 1);
- il=il->next;
- il->widget.entry.value = myLanguage;
- il->widget.entry.name = "myLanguage";
- il->widget.entry.label = g_strdup(_("My language code:"));
- il->type=EB_INPUT_ENTRY;
-
- eb_debug(DBG_MOD, "Auto-trans initialised\n");
+ outgoing_message_filters = l_list_append(outgoing_message_filters,
&translate_out);
+ incoming_message_filters = l_list_append(incoming_message_filters,
&translate_in);
- outgoing_message_filters=l_list_append(outgoing_message_filters,
&translate_out);
- incoming_message_filters=l_list_append(incoming_message_filters,
&translate_in);
+ /* the following is adapted from notes.c */
- /* the following is adapted from notes.c */
-
- if((tag1=eb_add_menu_item(_("Set Language"), EB_CHAT_WINDOW_MENU,
language_select, ebmCONTACTDATA, NULL))==NULL) {
+ if ((tag1 = eb_add_menu_item(_("Set Language"), EB_CHAT_WINDOW_MENU,
+ language_select, ebmCONTACTDATA, NULL)) == NULL) {
eb_debug(DBG_MOD, "Error! Unable to add Language menu to chat
window menu\n");
- return(-1);
+ return (-1);
}
- if((tag2=eb_add_menu_item(_("Set Language"), EB_CONTACT_MENU,
language_select, ebmCONTACTDATA, NULL))==NULL) {
+ if ((tag2 = eb_add_menu_item(_("Set Language"), EB_CONTACT_MENU,
+ language_select, ebmCONTACTDATA, NULL)) == NULL) {
eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1);
eb_debug(DBG_MOD, "Error! Unable to add Language menu to
contact menu\n");
- return(-1);
+ return (-1);
}
- return 0;
+ return 0;
}
static int trans_finish()
{
- int result=0;
+ int result = 0;
- eb_debug(DBG_MOD, "Auto-trans shutting down\n");
- outgoing_message_filters=l_list_remove(outgoing_message_filters,
&translate_out);
- incoming_message_filters=l_list_remove(incoming_message_filters,
&translate_in);
+ eb_debug(DBG_MOD, "Auto-trans shutting down\n");
+ outgoing_message_filters = l_list_remove(outgoing_message_filters,
&translate_out);
+ incoming_message_filters = l_list_remove(incoming_message_filters,
&translate_in);
- /* This is also from utility.c */
+ /* This is also from utility.c */
- result=eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1);
- if(result) {
+ result = eb_remove_menu_item(EB_CHAT_WINDOW_MENU, tag1);
+ if (result) {
g_warning("Unable to remove Language menu item from chat window
menu!");
- return(-1);
+ return (-1);
}
- result=eb_remove_menu_item(EB_CONTACT_MENU, tag2);
- if(result) {
+ result = eb_remove_menu_item(EB_CONTACT_MENU, tag2);
+ if (result) {
g_warning("Unable to remove Language menu item from chat window
menu!");
- return(-1);
+ return (-1);
}
- return 0;
+ return 0;
}
/*******************************************************************************
* End Module Code
******************************************************************************/
-static void language_select(ebmCallbackData *data)
+static void language_selected(char *text, gpointer data)
{
- ebmContactData *ecd=(ebmContactData *)data;
- struct contact * cont;
- gchar buf[1024];
+ struct contact *cont = (struct contact *) data;
- char ** languages;
+ cont->language[0] = text[0];
+ cont->language[1] = text[1];
+ cont->language[2] = '\0';
+
+ write_contact_list();
+
+ if (!doTrans) {
+ do_message_dialog(_("Warning - you have just selected a
language "
+ "with which to talk to a buddy. This
will "
+ "only affect you if you have the
auto-translator"
+ "plugin turned on. If you do, beware
that it will"
+ "hang each time you send or receive a
message, for"
+ "the time it takes to contact
BabelFish. This can"
+ "take several seconds."),
+ _("Warning"), 0);
+ }
+}
- languages=(char **)malloc(15 * sizeof(char *));
- // Colin - when you translate this: the important thing is that the first
two characters
- // are the language code. The rest is ignored, so you can translate it as
you see fit
- languages[0]=g_strdup("en (English)");
- languages[1]=g_strdup("fr (French)");
- languages[2]=g_strdup("de (German)");
- languages[3]=g_strdup("it (Italian)");
- languages[4]=g_strdup("pt (Portuguese)");
- languages[5]=g_strdup("es (Spanish)");
- languages[6]=g_strdup("ru (Russian)");
- languages[7]=g_strdup("ko (Korean)");
- languages[8]=g_strdup("ja (Japanese)");
- languages[9]=g_strdup("zh (Chinese)");
- languages[10]=NULL;
+static void language_select(ebmCallbackData * data)
+{
+ ebmContactData *ecd = (ebmContactData *) data;
+ struct contact *cont;
+ char buf[1024];
+
+ char **languages;
+
+ /* FIXME: do_list_dialog frees the list passed into it. How ridiculous!
*/
+ languages = (char **) malloc(15 * sizeof(char *));
+ languages[0] = strdup("en (English)");
+ languages[1] = strdup("fr (French)");
+ languages[2] = strdup("de (German)");
+ languages[3] = strdup("it (Italian)");
+ languages[4] = strdup("pt (Portuguese)");
+ languages[5] = strdup("es (Spanish)");
+ languages[6] = strdup("ru (Russian)");
+ languages[7] = strdup("ko (Korean)");
+ languages[8] = strdup("ja (Japanese)");
+ languages[9] = strdup("zh (Chinese)");
+ languages[10] = NULL;
- cont=find_contact_by_nick(ecd->contact);
+ cont = find_contact_by_nick(ecd->contact);
- if(cont==NULL) { return; }
+ if (cont == NULL) {
+ return;
+ }
- g_snprintf(buf, 1024, _("Select the code for the language to use when
talking to %s"), cont->nick);
+ g_snprintf(buf, 1024, _("Select the code for the language to use when
talking to %s"),
+ cont->nick);
- do_list_dialog(buf, _("Select Language"), languages, &language_selected,
(gpointer)cont);
+ do_list_dialog(buf, _("Select Language"), languages,
+ &language_selected, (gpointer) cont);
}
-static void language_selected(char * text, gpointer data)
+/*
+** Name: Utf8ToStr
+** Purpose: revert UTF-8 string conversion
+** Input: in - the string to decode
+** Output: a new decoded string
+*/
+static char *Utf8ToStr(const char *in)
{
- struct contact * cont=(struct contact *)data;
-
- cont->language[0]=text[0];
- cont->language[1]=text[1];
- cont->language[2]='\0';
-
- write_contact_list();
+ int i = 0;
+ unsigned int n;
+ char *result = NULL;
+ result = (char *) malloc(strlen(in) + 1);
+
+ /* convert a string from UTF-8 Format */
+ for (n = 0; n < strlen(in); n++) {
+ unsigned char c = in[n];
- if(!doTrans)
- {
- do_message_dialog(_("Warning - you have just selected a language with
which to talk to a buddy. This will only affect you if you have the
auto-translator plugin turned on. If you do, beware that it will hang each time
you send or receive a message, for the time it takes to contact BabelFish. This
can take several seconds."), _("Warning"), 0);
- }
+ if (c < 128) {
+ result[i++] = (char) c;
+ } else {
+ result[i++] = (c << 6) | (in[++n] & 63);
+ }
+ }
+ result[i] = '\0';
+ return result;
}
-
-static gchar * translate_out(eb_local_account * local, eb_account * remote,
struct contact * contact, gchar * s)
+static int isurlchar(unsigned char c)
{
- gchar *p;
- if(!doTrans) { return s; }
-
- if(contact->language[0]=='\0') { return s; } // no translation
-
- if(!strcmp(contact->language, myLanguage)) { return s; } // speak same
language
-
- p = doTranslate(s, myLanguage, contact->language);
- eb_debug(DBG_MOD, "%s translated to %s\n",s,p);
- return p;
+ return (isalnum(c) || '-' == c || '_' == c);
}
-static gchar * translate_in(eb_local_account * local, eb_account * remote,
struct contact * contact, gchar * s)
+char *trans_urlencode(const char *instr)
{
- gchar *p;
- if(!doTrans) { return s; }
-
- if(contact->language[0]=='\0') { return s; } // no translation
+ int ipos=0, bpos=0;
+ char *str = NULL;
+ int len = strlen(instr);
+
+ if(!(str = malloc(sizeof(char) * (3*len + 1)) ))
+ return strdup("");
+
+ while(instr[ipos]) {
+ while(isurlchar(instr[ipos]))
+ str[bpos++] = instr[ipos++];
+ if(!instr[ipos])
+ break;
+
+ snprintf(&str[bpos], 4, "%%%.2x",
+ (instr[ipos]=='\r' || instr[ipos]=='\n'?
+ ' ':instr[ipos]));
+ bpos+=3;
+ ipos++;
+ }
+ str[bpos]='\0';
- if(!strcmp(contact->language, myLanguage)) { return s; } // speak same
language
+ /* free extra alloc'ed mem. */
+ len = strlen(str);
+ str = realloc(str, sizeof(char) * (len+1));
- p = doTranslate(s, contact->language, myLanguage);
- return p;
+ return str;
}
-static gchar * doTranslate(gchar * ostring, gchar * from, gchar * to)
+static int do_http_post(const char *host, const char *path, const char
*enc_data)
{
- gchar buf[2048];
- char lastfew[5]={'\0','\0','\0','\0', '\0'};
- int a, pos;
- FILE * dat;
- int printing=0;
- gchar * string;
- gchar * result;
-
- string=trans_URLEncode(ostring);
-
- g_snprintf(buf, 2048, "rm /tmp/.eb.%s.translator -f ; wget -O
/tmp/.eb.%s.translator
'http://world.altavista.com/sites/gben/pos/babelfish/tr?tt=urltext&lp=%s_%s&urltext=%s'",
- getenv("USER"), getenv("USER"), from, to, string);
-
- eb_debug(DBG_MOD, "Running command line:\n%s\n", buf);
-
- if(system(buf)!=0)
- {
- eb_debug(DBG_MOD, "COULD NOT TRANSLATE: %s\n", ostring);
- free(string);
- return g_strdup(ostring);
- }
-
- g_snprintf(buf, 2048, "/tmp/.eb.%s.translator", getenv("USER"));
-
- if((dat=fopen(buf, "r"))==NULL)
- {
- eb_debug(DBG_MOD, "COULD NOT TRANSLATE: %s\n", ostring);
- free(string);
- return g_strdup(ostring);
- }
+ char buff[1024];
+ int fd;
- pos=0;
+ fd = ay_socket_new(host, 80);
- while(!feof(dat))
- {
- for(a=0; a<3; a++)
- {
- lastfew[a]=lastfew[a+1];
- }
- lastfew[3]=(char)getc(dat);
+ if (fd > 0) {
+ snprintf(buff, sizeof(buff),
+ "POST %s HTTP/1.1\r\n"
+ "Host: %s\r\n"
+ "User-Agent: Mozilla/4.5 [en] (%s/%s)\r\n"
+ "Content-type: application/x-www-form-urlencoded\r\n"
+ "Content-length: %d\r\n"
+ "\r\n",
+ path, host, PACKAGE, VERSION, strlen(enc_data));
- if(printing>=1)
- {
- buf[pos++]=lastfew[3];
- if(pos==1023) { buf[pos]='\0'; break; }
- }
-
- if(!strcmp(lastfew, "</TE"))
- {
- eb_debug(DBG_MOD, "Found end\n");
- if (pos >= 5) {
- buf[pos-4]='\0';
- printing++;
- while(pos>=5 && (buf[pos-5]=='\n' || buf[pos-5]=='\r'))
- {
- buf[pos-5]='\0';
- pos--;
- }
- }
- break;
- }
-
- if(!strcmp(lastfew, "UAL>") || !strcmp(lastfew, "AL\">"))
- {
- printing=1;
- eb_debug(DBG_MOD, "Found start\n");
- }
- }
+ write(fd, buff, strlen(buff));
+ write(fd, enc_data, strlen(enc_data));
+ }
- fclose(dat);
+ return fd;
+}
- if(printing<2)
- {
- eb_debug(DBG_MOD, "TRANSLATION FAILED: %s, printing=%d\n", ostring,
printing);
- free(string);
- return g_strdup(ostring);
- }
+#define START_POS "<input type=hidden name=\"q\" value=\""
+#define END_POS "\">"
+static char *doTranslate(const char * ostring, const char * from, const char *
to)
+{
+ char buf[2048];
+ int fd;
+ int offset=0;
+ char *string;
+ char *result;
+
+ string = trans_urlencode(ostring);
+ snprintf(buf, 2048, "tt=urltext&lp=%s_%s&urltext=%s",
+ from, to, string);
+ free(string);
+
+ fd = do_http_post("babelfish.altavista.com", "/babelfish/tr", buf);
+
+ while((ay_tcp_readline(buf+offset, sizeof(buf)-offset, fd)) > 0) {
+ char *end, *start = strstr(buf, START_POS);
+ offset=0;
+ if(!start)
+ continue;
+
+ start += strlen(START_POS);
+ end = strstr(start, END_POS);
+ if(end) {
+ *end='\0';
+ string = start;
+ break;
+ } else {
+ /* append next line */
+ offset = strlen(buf);
+ }
+
+ }
+
+ eb_debug(DBG_MOD, "Translated %s to %s\n", string, buf);
- eb_debug(DBG_MOD, "Translated %s to %s\n", string, buf);
+ result = Utf8ToStr(string);
+ eb_debug(DBG_MOD, "%s\n", result);
+ return result;
+}
- free(string);
+static char *translate_out(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char * s)
+{
+ char *p;
+ if (!doTrans) {
+ return strdup(s);
+ }
- result = Utf8ToStr(buf);
- eb_debug(DBG_MOD, "%s\n", result);
- return result;
+ if (contact->language[0] == '\0') {
+ return strdup(s);
+ } // no translation
+
+ if (!strcmp(contact->language, myLanguage)) {
+ return strdup(s);
+ } // speak same language
+
+ p = doTranslate(s, myLanguage, contact->language);
+ eb_debug(DBG_MOD, "%s translated to %s\n", s, p);
+ return p;
}
-static char * trans_URLEncode(char * s)
+static char *translate_in(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char * s)
{
- char * rptr;
- char * wptr;
- char * retval;
-
- wptr=retval=(char *)malloc(sizeof(char)*strlen(s)*3);
- rptr=s;
+ char *p;
+ if (!doTrans) {
+ return strdup(s);
+ }
- while(1)
- {
- if(*rptr=='\0')
- { *wptr='\0'; break; }
- if(!(isalpha(*rptr) || isdigit(*rptr)))
- {
- sprintf(wptr, "%%%2x", (int)(*rptr));
+ if (contact->language[0] == '\0') {
+ return strdup(s);
+ } // no translation
+
+ if (!strcmp(contact->language, myLanguage)) {
+ return strdup(s);
+ } // speak same language
- rptr++;
- wptr+=3;
- continue;
- }
+ p = doTranslate(s, contact->language, myLanguage);
+ return p;
+}
- *wptr=*rptr;
- wptr++;
- rptr++;
- }
- return retval;
-}
Index: middle.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/utility/middle.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- middle.c 29 Jan 2003 19:19:22 -0000 1.7
+++ middle.c 7 Feb 2003 08:25:33 -0000 1.8
@@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-
+
#ifdef __MINGW32__
#define __IN_PLUGIN__
#endif
@@ -43,13 +43,14 @@
#define plugin_finish middle_LTX_plugin_finish
/* Function Prototypes */
-static char * plstripHTML(eb_local_account * local, eb_account * remote,
struct contact * contact, char * s);
+static char *plstripHTML(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char *s);
static int middle_init();
static int middle_finish();
-static int doLeet=0;
+static int doLeet = 0;
-static int ref_count=0;
+static int ref_count = 0;
/* Module Exports */
PLUGIN_INFO plugin_info = {
@@ -67,50 +68,67 @@
static int middle_init()
{
- input_list * il=calloc(1, sizeof(input_list));
- plugin_info.prefs=il;
-
- il->widget.checkbox.value = &doLeet;
- il->widget.checkbox.name = "doLeet";
- il->widget.entry.label = strdup(_("Enable L33t-speak conversion"));
- il->type=EB_INPUT_CHECKBOX;
+ input_list *il = calloc(1, sizeof(input_list));
+ plugin_info.prefs = il;
- eb_debug(DBG_MOD, "L33tSp33k initialised\n");
+ il->widget.checkbox.value = &doLeet;
+ il->widget.checkbox.name = "doLeet";
+ il->widget.entry.label = strdup(_("Enable L33t-speak conversion"));
+ il->type = EB_INPUT_CHECKBOX;
+
+ eb_debug(DBG_MOD, "L33tSp33k initialised\n");
+
+ outgoing_message_filters =
+ l_list_append(outgoing_message_filters, &plstripHTML);
+ incoming_message_filters =
+ l_list_append(incoming_message_filters, &plstripHTML);
- outgoing_message_filters=l_list_append(outgoing_message_filters,
&plstripHTML);
- incoming_message_filters=l_list_append(incoming_message_filters,
&plstripHTML);
-
- return 0;
+ return 0;
}
static int middle_finish()
{
- eb_debug(DBG_MOD, "L33tSp33k shutting down\n");
- outgoing_message_filters=l_list_remove(outgoing_message_filters,
&plstripHTML);
- incoming_message_filters=l_list_remove(incoming_message_filters,
&plstripHTML);
+ eb_debug(DBG_MOD, "L33tSp33k shutting down\n");
+ outgoing_message_filters =
+ l_list_remove(outgoing_message_filters, &plstripHTML);
+ incoming_message_filters =
+ l_list_remove(incoming_message_filters, &plstripHTML);
- return 0;
+ return 0;
}
/*******************************************************************************
* End Module Code
******************************************************************************/
-static char * plstripHTML(eb_local_account * local, eb_account * remote,
struct contact * contact, char * s)
+static char *plstripHTML(const eb_local_account * local, const eb_account *
remote,
+ const struct contact *contact, const char *in)
{
- int pos=0;
-
- if(!doLeet) { return s; }
+ int pos = 0;
+ char * s = strdup(in);
- while(s[pos]!='\0')
- {
- if(s[pos]=='e' || s[pos]=='E') { s[pos]='3'; }
- if(s[pos]=='i' || s[pos]=='I') { s[pos]='1'; }
- if(s[pos]=='o' || s[pos]=='O') { s[pos]='0'; }
- if(s[pos]=='a' || s[pos]=='A') { s[pos]='4'; }
- if(s[pos]=='s' || s[pos]=='S') { s[pos]='5'; }
+ if (!doLeet) {
+ return s;
+ }
+
+ while (s[pos] != '\0') {
+ if (s[pos] == 'e' || s[pos] == 'E') {
+ s[pos] = '3';
+ }
+ if (s[pos] == 'i' || s[pos] == 'I') {
+ s[pos] = '1';
+ }
+ if (s[pos] == 'o' || s[pos] == 'O') {
+ s[pos] = '0';
+ }
+ if (s[pos] == 'a' || s[pos] == 'A') {
+ s[pos] = '4';
+ }
+ if (s[pos] == 's' || s[pos] == 'S') {
+ s[pos] = '5';
+ }
- pos++;
- }
+ pos++;
+ }
- return s;
+ return s;
}
Index: rainbow.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/utility/rainbow.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- rainbow.c 29 Jan 2003 19:19:22 -0000 1.8
+++ rainbow.c 7 Feb 2003 08:25:33 -0000 1.9
@@ -23,7 +23,7 @@
*/
#include "intl.h"
-
+
#include <stdlib.h>
#include <string.h>
@@ -45,24 +45,28 @@
/* Function Prototypes */
/* ebmCallbackData is a parent struct, the child of which will be an
ebmContactData */
-static char * dorainbow(eb_local_account * local, eb_account * remote, struct
contact * contact, char * s);
+static char *dorainbow(const eb_local_account * local,
+ const eb_account * remote,
+ const struct contact *contact, const char *s);
static int rainbow_init();
static int rainbow_finish();
-static int doRainbow=0;
-
-static char sstart_r[MAX_PREF_LEN]="255";
-static char sstart_g[MAX_PREF_LEN]="0";
-static char sstart_b[MAX_PREF_LEN]="0";
-
-static char send_r[MAX_PREF_LEN]="0";
-static char send_g[MAX_PREF_LEN]="0";
-static char send_b[MAX_PREF_LEN]="255";
+static int doRainbow = 0;
-static char * html_tags[] = {"html", "body", "font", "p", "i", "b", "u",
"img", "a", "br", "hr", "head"};
-static int num_tags=12;
+static char sstart_r[MAX_PREF_LEN] = "255";
+static char sstart_g[MAX_PREF_LEN] = "0";
+static char sstart_b[MAX_PREF_LEN] = "0";
+
+static char send_r[MAX_PREF_LEN] = "0";
+static char send_g[MAX_PREF_LEN] = "0";
+static char send_b[MAX_PREF_LEN] = "255";
+
+static char *html_tags[] =
+ { "html", "body", "font", "p", "i", "b", "u", "img", "a", "br", "hr",
+"head" };
+static int num_tags = 12;
-static int ref_count=0;
+static int ref_count = 0;
/* Module Exports */
PLUGIN_INFO plugin_info = {
@@ -80,129 +84,153 @@
static int rainbow_init()
{
- input_list * il=calloc(1, sizeof(input_list));
- plugin_info.prefs=il;
+ input_list *il = calloc(1, sizeof(input_list));
+ plugin_info.prefs = il;
- il->widget.checkbox.value = &doRainbow;
- il->widget.checkbox.name = "doRainbow";
- il->widget.checkbox.label = strdup(_("Enable rainbow conversion"));
- il->type=EB_INPUT_CHECKBOX;
-
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = sstart_r;
- il->widget.entry.name = "sstart_r";
- il->widget.entry.label = strdup(_("Starting R value"));
- il->type=EB_INPUT_ENTRY;
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = sstart_g;
- il->widget.entry.name = "sstart_g";
- il->widget.entry.label = strdup(_("Starting G value"));
- il->type=EB_INPUT_ENTRY;
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = sstart_b;
- il->widget.entry.name = "sstart_b";
- il->widget.entry.label = strdup(_("Starting B value"));
- il->type=EB_INPUT_ENTRY;
-
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = send_r;
- il->widget.entry.name = "send_r";
- il->widget.entry.label = strdup(_("Ending R value"));
- il->type=EB_INPUT_ENTRY;
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = send_g;
- il->widget.entry.name = "send_g";
- il->widget.entry.label = strdup(_("Ending G value"));
- il->type=EB_INPUT_ENTRY;
- il->next=calloc(1, sizeof(input_list));
- il=il->next;
- il->widget.entry.value = send_b;
- il->widget.entry.name = "send_b";
- il->widget.entry.label = strdup(_("Ending B value"));
- il->type=EB_INPUT_ENTRY;
+ il->widget.checkbox.value = &doRainbow;
+ il->widget.checkbox.name = "doRainbow";
+ il->widget.checkbox.label = strdup(_("Enable rainbow conversion"));
+ il->type = EB_INPUT_CHECKBOX;
+
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = sstart_r;
+ il->widget.entry.name = "sstart_r";
+ il->widget.entry.label = strdup(_("Starting R value"));
+ il->type = EB_INPUT_ENTRY;
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = sstart_g;
+ il->widget.entry.name = "sstart_g";
+ il->widget.entry.label = strdup(_("Starting G value"));
+ il->type = EB_INPUT_ENTRY;
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = sstart_b;
+ il->widget.entry.name = "sstart_b";
+ il->widget.entry.label = strdup(_("Starting B value"));
+ il->type = EB_INPUT_ENTRY;
+
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = send_r;
+ il->widget.entry.name = "send_r";
+ il->widget.entry.label = strdup(_("Ending R value"));
+ il->type = EB_INPUT_ENTRY;
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = send_g;
+ il->widget.entry.name = "send_g";
+ il->widget.entry.label = strdup(_("Ending G value"));
+ il->type = EB_INPUT_ENTRY;
+ il->next = calloc(1, sizeof(input_list));
+ il = il->next;
+ il->widget.entry.value = send_b;
+ il->widget.entry.name = "send_b";
+ il->widget.entry.label = strdup(_("Ending B value"));
+ il->type = EB_INPUT_ENTRY;
- eb_debug(DBG_MOD, "Rainbow initialised\n");
+ eb_debug(DBG_MOD, "Rainbow initialised\n");
- outgoing_message_filters=l_list_append(outgoing_message_filters, &dorainbow);
+ outgoing_message_filters =
+ l_list_append(outgoing_message_filters, &dorainbow);
- return 0;
+ return 0;
}
static int rainbow_finish()
{
- eb_debug(DBG_MOD, "Rainbow shutting down\n");
- outgoing_message_filters=l_list_remove(outgoing_message_filters, &dorainbow);
+ eb_debug(DBG_MOD, "Rainbow shutting down\n");
+ outgoing_message_filters =
+ l_list_remove(outgoing_message_filters, &dorainbow);
- return 0;
+ return 0;
}
/*******************************************************************************
* End Module Code
******************************************************************************/
-static char * dorainbow(eb_local_account * local, eb_account * remote, struct
contact * contact, char * s)
+static char *dorainbow(const eb_local_account * local,
+ const eb_account * remote,
+ const struct contact *contact, const char *s)
{
- char * retval;
- char * wptr;
- int pos=0;
- int start_r=atoi(sstart_r);
- int start_g=atoi(sstart_g);
- int start_b=atoi(sstart_b);
- int end_r=atoi(send_r);
- int end_g=atoi(send_g);
- int end_b=atoi(send_b);
- int len=strlen(s);
-
- if(!doRainbow) { return s; }
-
- if(start_r>255 || start_r<0) { start_r=0; }
- if(start_g>255 || start_g<0) { start_g=0; }
- if(start_b>255 || start_b<0) { start_b=0; }
- if(end_r>255 || end_r<0) { end_r=0; }
- if(end_g>255 || end_g<0) { end_g=0; }
- if(end_b>255 || end_b<0) { end_b=0; }
-
- wptr=retval=malloc(23*len*sizeof(char));
-
- while(s[pos]!='\0')
- {
- if(s[pos]=='<')
- {
- int p2=pos+1;
- int a, found=0;
-
- while(s[p2]==' ' || s[p2]=='/') { p2++; } // strip space before HTML tag
- for(a=0; a<num_tags; a++)
- {
- if(!strncasecmp(s+p2, html_tags[a], strlen(html_tags[a])))
- { found=1; break; }
- }
-
- if(found)
- {
- while(1)
- {
- *(wptr++)=s[pos++];
- if(s[pos-1]=='\0' || s[pos-1]=='>') { break; }
- }
- *wptr='\0'; // in case this is the last char
-
- continue;
- }
- }
-
- wptr+=g_snprintf(wptr, 22*(len-pos), "<font color=#%02x%02x%02x>%c",
- (pos*end_r+(len-pos)*start_r)/len,
- (pos*end_g+(len-pos)*start_g)/len,
- (pos*end_b+(len-pos)*start_b)/len, s[pos]);
- pos++;
- }
+ char *retval;
+ char *wptr;
+ int pos = 0;
+ int start_r = atoi(sstart_r);
+ int start_g = atoi(sstart_g);
+ int start_b = atoi(sstart_b);
+ int end_r = atoi(send_r);
+ int end_g = atoi(send_g);
+ int end_b = atoi(send_b);
+ int len = strlen(s);
+
+ if (!doRainbow) {
+ return strdup(s);
+ }
+
+ if (start_r > 255 || start_r < 0) {
+ start_r = 0;
+ }
+ if (start_g > 255 || start_g < 0) {
+ start_g = 0;
+ }
+ if (start_b > 255 || start_b < 0) {
+ start_b = 0;
+ }
+ if (end_r > 255 || end_r < 0) {
+ end_r = 0;
+ }
+ if (end_g > 255 || end_g < 0) {
+ end_g = 0;
+ }
+ if (end_b > 255 || end_b < 0) {
+ end_b = 0;
+ }
+
+ wptr = retval = malloc(23 * len * sizeof(char));
+
+ while (s[pos] != '\0') {
+ if (s[pos] == '<') {
+ int p2 = pos + 1;
+ int a, found = 0;
+
+ while (s[p2] == ' ' || s[p2] == '/') {
+ p2++;
+ } // strip space before HTML tag
+ for (a = 0; a < num_tags; a++) {
+ if (!strncasecmp
+ (s + p2, html_tags[a],
+ strlen(html_tags[a]))) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (found) {
+ while (1) {
+ *(wptr++) = s[pos++];
+ if (s[pos - 1] == '\0'
+ || s[pos - 1] == '>') {
+ break;
+ }
+ }
+ *wptr = '\0'; // in case this is the last char
+
+ continue;
+ }
+ }
+
+ wptr +=
+ g_snprintf(wptr, 22 * (len - pos),
+ "<font color=#%02x%02x%02x>%c",
+ (pos * end_r + (len - pos) * start_r) / len,
+ (pos * end_g + (len - pos) * start_g) / len,
+ (pos * end_b + (len - pos) * start_b) / len,
+ s[pos]);
+ pos++;
+ }
- free(s);
- return retval;
+ return retval;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Ayttm-commits] CVS: ayttm/modules/utility autotrans.c,1.9,1.10 middle.c,1.7,1.8 rainbow.c,1.8,1.9,
Philip S Tellis <address@hidden> <=
- Prev by Date:
[Ayttm-commits] CVS: ayttm ChangeLog,1.282,1.283 configure.in,1.278,1.279
- Next by Date:
[Ayttm-commits] CVS: ayttm/src tcp_util.c,NONE,1.1 tcp_util.h,NONE,1.1 util.c,1.43,1.44 chat_window.c,1.46,1.47 Makefile.am,1.22,1.23
- Previous by thread:
[Ayttm-commits] CVS: ayttm ChangeLog,1.282,1.283 configure.in,1.278,1.279
- Next by thread:
[Ayttm-commits] CVS: ayttm/src tcp_util.c,NONE,1.1 tcp_util.h,NONE,1.1 util.c,1.43,1.44 chat_window.c,1.46,1.47 Makefile.am,1.22,1.23
- Index(es):