annotate plugins/spellchk.c @ 103:c5a1a1b05c26

[gaim-migrate @ 113] Added a spell check plugin. Shows proof-of-concept, mostly. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 10 Apr 2000 00:12:21 +0000
parents
children e05e6373ea5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
103
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 #define GAIM_PLUGINS
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #include "gaim.h"
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 #include <string.h>
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <ctype.h>
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 #include <stdlib.h>
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 struct replace_words {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 char *bad;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 char *good;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 };
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 GList *words = NULL;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 int num_words(char *);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 int get_word(char *, int);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 char *have_word(char *, int);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 void substitute(char **, int, int, char *);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 void spell_check(char *who, char **message, void *m) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 int i, l;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 int word;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 GList *w;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 char *tmp;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 if (message == NULL || *message == NULL)
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 return;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 l = num_words(*message);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 for (i = 0; i < l; i++) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 word = get_word(*message, i);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 w = words;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 while (w) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 struct replace_words *r;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 r = (struct replace_words *)(w->data);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 tmp = have_word(*message, word);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 if (!strcmp(have_word(*message, word), r->bad))
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 substitute(message, word, strlen(r->bad),
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 r->good);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 free(tmp);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 w = w->next;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 void gaim_plugin_init(void *handle) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 struct replace_words *p;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 p = malloc(sizeof *p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 p->bad = "definately";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 p->good = "definitely";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 words = g_list_append(words, p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 p = malloc(sizeof *p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 p->bad = "u";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 p->good = "you";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 words = g_list_append(words, p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 p = malloc(sizeof *p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 p->bad = "r";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 p->good = "are";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 words = g_list_append(words, p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 p = malloc(sizeof *p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 p->bad = "teh";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 p->good = "the";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 words = g_list_append(words, p);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 gaim_signal_connect(handle, event_im_send, spell_check, NULL);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 char *name() {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 return "IM Spell Check";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 char *description() {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 return "Watches outgoing IM text and corrects common spelling errors.";
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 int num_words(char *m) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 int count = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 int pos;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 int state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 for (pos = 0; pos < strlen(m); pos++) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 switch (state) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 case 0: /* expecting word */
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 if (isalnum(m[pos])) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 count++;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 state = 1;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 } else if (m[pos] == '<')
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 state = 2;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 case 1: /* inside word */
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 if (isspace(m[pos]))
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 case 2: /* inside HTML tag */
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 if (m[pos] == '>')
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 return count;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 int get_word(char *m, int word) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 int count = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 int pos = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 int state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 for (pos = 0; pos < strlen(m) && count <= word; pos++) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 switch (state) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 case 0:
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 if (isalnum(m[pos])) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 count++;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 state = 1;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 } else if (m[pos] == '<')
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 state = 2;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 case 1:
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 if (isspace(m[pos]))
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 case 2:
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 if (m[pos] == '>')
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 state = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 break;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 return pos - 1;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 char *have_word(char *m, int pos) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 char *tmp = strpbrk(&m[pos], "' \t\f\r\n");
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 int len = (int)(tmp - &m[pos]);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 if (tmp == NULL) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 tmp = strdup(&m[pos]);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 return tmp;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 tmp = malloc(len + 1);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 tmp[0] = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 strncat(tmp, &m[pos], len);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 return tmp;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 }
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 void substitute(char **mes, int pos, int m, char *text) {
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 char *new = malloc(strlen(*mes) + strlen(text) + 1);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 char *tmp;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 new[0] = 0;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 strncat(new, *mes, pos);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 strcat(new, text);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 strcat(new, &(*mes)[pos + m]);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 tmp = *mes;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 *mes = new;
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 free(tmp);
c5a1a1b05c26 [gaim-migrate @ 113]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 }