Mercurial > pidgin.yaz
changeset 106:e05e6373ea5a
[gaim-migrate @ 116]
Modified spellchk.c so now it uses a more customizable dictionary and added
filectl.c to allow remote-control of gaim.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 12 Apr 2000 06:51:37 +0000 |
parents | c76d4c0c5e3a |
children | 55faf2e3a134 |
files | plugins/Makefile plugins/filectl.c plugins/spellchk.c |
diffstat | 3 files changed, 180 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/Makefile Wed Apr 12 06:46:38 2000 +0000 +++ b/plugins/Makefile Wed Apr 12 06:51:37 2000 +0000 @@ -2,7 +2,7 @@ CFLAGS = -Wall `gnome-config --cflags gtk` -I../src LDFLAGS = -ggdb `gnome-config --libs gtk` -shared -all: simple.so gaiminc.so autorecon.so spellchk.so chkmail.so +all: simple.so gaiminc.so autorecon.so spellchk.so chkmail.so filectl.so .SUFFIXES: .c .so
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/filectl.c Wed Apr 12 06:51:37 2000 +0000 @@ -0,0 +1,156 @@ +#define GAIM_PLUGINS +#include "gaim.h" + +#include <gtk/gtk.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <ctype.h> + +void *handle; +int check; +time_t mtime; + +void init_file(); +void check_file(); + +extern void dologin(GtkWidget *, GtkWidget *); +extern void do_quit(); + +/* parse char * as if were word array */ +char *getarg(char *, int, int); + +/* go through file and run any commands */ +void run_commands() { + struct stat finfo; + char filename[256]; + char buffer[1024]; + char *command, *arg1, *arg2; + FILE *file; + + sprintf(filename, "%s/.gaim/control", getenv("HOME")); + + file = fopen(filename, "r+"); + while (fgets(buffer, sizeof buffer, file)) { + if (buffer[strlen(buffer) - 1] == '\n') + buffer[strlen(buffer) - 1] = 0; + printf("read: %s\n", buffer); + command = getarg(buffer, 0, 0); + if (!strncasecmp(command, "signon", 6)) { + if (!blist) { + show_login(); + dologin(NULL, NULL); + } + } else if (!strncasecmp(command, "signoff", 7)) { + signoff(); + } else if (!strncasecmp(command, "send", 4)) { + struct conversation *c; + arg1 = getarg(buffer, 1, 0); + arg2 = getarg(buffer, 2, 1); + c = find_conversation(arg1); + if (!c) c = new_conversation(arg1); + write_to_conv(c, arg2, WFLAG_SEND); + serv_send_im(arg1, arg2, 0); + free(arg1); + free(arg2); + } else if (!strncasecmp(command, "away", 4)) { + struct away_message a; + arg1 = getarg(buffer, 1, 1); + snprintf(a.message, 2048, "%s", arg1); + a.name[0] = 0; + do_away_message(NULL, &a); + free(arg1); + } else if (!strncasecmp(command, "back", 4)) { + do_im_back(); + } else if (!strncasecmp(command, "quit", 4)) { + do_quit(); + } + free(command); + } + + fclose(file); + + if (stat (filename, &finfo) != 0) + return; + mtime = finfo.st_mtime; +} + +void gaim_plugin_init(void *h) { + handle = h; + init_file(); + check = gtk_timeout_add(5000, (GtkFunction)check_file, NULL); +} + +void gaim_plugin_remove() { + gtk_timeout_remove(check); +} + +char *name() { + return "Gaim File Control"; +} + +char *description() { + return "Allows you to control gaim by entering commands in a file."; +} + +/* check to see if the size of the file is > 0. if so, run commands */ +void init_file() { + /* most of this was taken from Bash v2.04 by the FSF */ + struct stat finfo; + char file[256]; + + sprintf(file, "%s/.gaim/control", getenv("HOME")); + + if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) + run_commands(); +} + +/* check to see if we need to run commands from the file */ +void check_file() { + /* most of this was taken from Bash v2.04 by the FSF */ + struct stat finfo; + char file[256]; + + sprintf(file, "%s/.gaim/control", getenv("HOME")); + + if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) + if (mtime != finfo.st_mtime) + run_commands(); +} + +char *getarg(char *line, int which, int remain) { + char *arr; + char *val; + int count = -1; + int i; + int state = 0; + + for (i = 0; i < strlen(line) && count < which; i++) { + switch (state) { + case 0: /* in whitespace, expecting word */ + if (isalnum(line[i])) { + count++; + state = 1; + } + break; + case 1: /* inside word, waiting for whitespace */ + if (isspace(line[i])) { + state = 0; + } + break; + } + } + + arr = strdup(&line[i - 1]); + if (remain) + return arr; + + for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); + arr[i] = 0; + val = strdup(arr); + arr[i] = ' '; + free(arr); + return val; +}
--- a/plugins/spellchk.c Wed Apr 12 06:46:38 2000 +0000 +++ b/plugins/spellchk.c Wed Apr 12 06:51:37 2000 +0000 @@ -45,26 +45,25 @@ void gaim_plugin_init(void *handle) { struct replace_words *p; - - p = malloc(sizeof *p); - p->bad = "definately"; - p->good = "definitely"; - words = g_list_append(words, p); + FILE *file; + char buffer[256]; + char *good; + char *bad; - p = malloc(sizeof *p); - p->bad = "u"; - p->good = "you"; - words = g_list_append(words, p); - - p = malloc(sizeof *p); - p->bad = "r"; - p->good = "are"; - words = g_list_append(words, p); - - p = malloc(sizeof *p); - p->bad = "teh"; - p->good = "the"; - words = g_list_append(words, p); + sprintf(buffer, "%s/.gaim/dict", getenv("HOME")); + file = fopen(buffer, "r"); + while (fgets(buffer, sizeof buffer, file)) { + buffer[strlen(buffer) - 1] = 0; + p = malloc(sizeof *p); + good = strdup(strpbrk(strpbrk(buffer, " \t\r\f\n"), + "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM")); + bad = strpbrk(buffer, " \t\r\f\n"); + bad[0] = 0; + bad = strdup(buffer); + p->bad = bad; + p->good = good; + words = g_list_append(words, p); + } gaim_signal_connect(handle, event_im_send, spell_check, NULL); } @@ -92,8 +91,10 @@ state = 2; break; case 1: /* inside word */ - if (isspace(m[pos])) + if (isspace(m[pos]) || m[pos] == '\'' || m[pos] == '.') state = 0; + else if (m[pos] == '<') + state = 2; break; case 2: /* inside HTML tag */ if (m[pos] == '>') @@ -119,7 +120,7 @@ state = 2; break; case 1: - if (isspace(m[pos])) + if (isspace(m[pos]) || m[pos] == '\'' || m[pos] == '.') state = 0; break; case 2: @@ -132,7 +133,7 @@ } char *have_word(char *m, int pos) { - char *tmp = strpbrk(&m[pos], "' \t\f\r\n"); + char *tmp = strpbrk(&m[pos], "' \t\f\r\n."); int len = (int)(tmp - &m[pos]); if (tmp == NULL) {