annotate plugins/filectl.c @ 6552:65dc4d34f280

[gaim-migrate @ 7074] We like it when data can be passed through callbacks. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 21 Aug 2003 08:52:55 +0000
parents 8f94cce8faa5
children 083d1e4a9c78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
1 #include "config.h"
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #include "gaim.h"
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 #include <gtk/gtk.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <stdlib.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 #include <unistd.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #include <sys/types.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #include <sys/stat.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <string.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <ctype.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
12 #define FILECTL_PLUGIN_ID "core-filectl"
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
13 static int check;
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
14 static time_t mtime;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
16 static void init_file();
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
17 static void check_file();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 /* parse char * as if were word array */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 char *getarg(char *, int, int);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 /* go through file and run any commands */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 void run_commands() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 char filename[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 char buffer[1024];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 char *command, *arg1, *arg2;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 FILE *file;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 sprintf(filename, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 file = fopen(filename, "r+");
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 while (fgets(buffer, sizeof buffer, file)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 if (buffer[strlen(buffer) - 1] == '\n')
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 buffer[strlen(buffer) - 1] = 0;
5227
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
36 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 command = getarg(buffer, 0, 0);
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
38 if (!strncasecmp(command, "signon", 6)) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
39 struct gaim_account *account = NULL;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
40 GSList *accts = gaim_accounts;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
41 arg1 = getarg(buffer, 1, 1);
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
42 if (arg1) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
43 while (accts) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
44 struct gaim_account *a = accts->data;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
45 if (!strcmp(a->username, arg1)) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
46 account = a;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
47 break;
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
48 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
49 accts = accts->next;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
50 }
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
51 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
53 if (account) /* username found */
6036
547ba881bc7e [gaim-migrate @ 6486]
Mark Doliner <mark@kingant.net>
parents: 5920
diff changeset
54 gaim_account_connect(account);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 } else if (!strncasecmp(command, "signoff", 7)) {
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
56 struct gaim_connection *gc = NULL;
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
57 GSList *c = connections;
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
58 arg1 = getarg(buffer, 1, 1);
2766
0e082a9e4c32 [gaim-migrate @ 2779]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2765
diff changeset
59 while (arg1 && c) {
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
60 gc = c->data;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
61 if (!strcmp(gc->username, arg1)) {
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
62 break;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
63 }
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
64 gc = NULL;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
65 c = c->next;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
66 }
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
67 if (gc)
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
68 signoff(gc);
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
69 else if (!arg1)
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
70 signoff_all(NULL, NULL);
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
71 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 } else if (!strncasecmp(command, "send", 4)) {
5676
dae79aefac8d [gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents: 5255
diff changeset
73 GaimConversation *c;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 arg1 = getarg(buffer, 1, 0);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 arg2 = getarg(buffer, 2, 1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 c = find_conversation(arg1);
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4168
diff changeset
77 if (!c) c = gaim_conversation_new(GAIM_CONV_IM, arg1);
2906
538c58b43eff [gaim-migrate @ 2919]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2766
diff changeset
78 write_to_conv(c, arg2, WFLAG_SEND, NULL, time(NULL), -1);
3061
9349de0706e6 [gaim-migrate @ 3075]
Sean Egan <seanegan@gmail.com>
parents: 2906
diff changeset
79 serv_send_im(c->gc, arg1, arg2, -1, 0);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 free(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 free(arg2);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 } else if (!strncasecmp(command, "away", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 struct away_message a;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 arg1 = getarg(buffer, 1, 1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 snprintf(a.message, 2048, "%s", arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 a.name[0] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 do_away_message(NULL, &a);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 free(arg1);
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
89 } else if (!strncasecmp(command, "hide", 4)) {
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
90 hide_buddy_list();
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
91 } else if (!strncasecmp(command, "unhide", 6)) {
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
92 unhide_buddy_list();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 } else if (!strncasecmp(command, "back", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 do_im_back();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 } else if (!strncasecmp(command, "quit", 4)) {
6179
16e384bb7fbf [gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents: 6063
diff changeset
96 gaim_core_quit();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 free(command);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 fclose(file);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 if (stat (filename, &finfo) != 0)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 return;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 mtime = finfo.st_mtime;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 /* check to see if the size of the file is > 0. if so, run commands */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 void init_file() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 char file[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 sprintf(file, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 run_commands();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 /* check to see if we need to run commands from the file */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 void check_file() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 char file[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 sprintf(file, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
129 if (mtime != finfo.st_mtime) {
5227
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
130 gaim_debug(GAIM_DEBUG_INFO, "filectl",
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
131 "control changed, checking\n");
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 run_commands();
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
133 }
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 char *getarg(char *line, int which, int remain) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 char *arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 char *val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 int count = -1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 int i;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 int state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 for (i = 0; i < strlen(line) && count < which; i++) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 switch (state) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 case 0: /* in whitespace, expecting word */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 if (isalnum(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 count++;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 state = 1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 case 1: /* inside word, waiting for whitespace */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 if (isspace(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 arr = strdup(&line[i - 1]);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 if (remain)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 return arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 arr[i] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 val = strdup(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 arr[i] = ' ';
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 free(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 return val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 }
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
170 /*
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
171 * EXPORTED FUNCTIONS
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
172 */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
173
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
174 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
175 plugin_load(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
176 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
177 init_file();
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
178 check = g_timeout_add(5000, check_file, NULL);
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
179
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
180 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
181 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
182
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
183 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
184 plugin_unload(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
185 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
186 g_source_remove(check);
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
187
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
188 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
189 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
190
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
191 static GaimPluginInfo info =
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
192 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
193 2, /**< api_version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
194 GAIM_PLUGIN_STANDARD, /**< type */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
195 NULL, /**< ui_requirement */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
196 0, /**< flags */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
197 NULL, /**< dependencies */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
198 GAIM_PRIORITY_DEFAULT, /**< priority */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
199
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
200 FILECTL_PLUGIN_ID, /**< id */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
201 N_("Gaim File Control"), /**< name */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
202 VERSION, /**< version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
203 /** summary */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
204 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
205 /** description */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
206 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
207 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6179
diff changeset
208 GAIM_WEBSITE, /**< homepage */
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
209
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
210 plugin_load, /**< load */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
211 plugin_unload, /**< unload */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
212 NULL, /**< destroy */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
213
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
214 NULL, /**< ui_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
215 NULL /**< extra_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
216 };
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
217
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
218 static void
5920
7d385de2f9cd [gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
219 init_plugin(GaimPlugin *plugin)
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
220 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
221 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
222
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 6036
diff changeset
223 GAIM_INIT_PLUGIN(filectl, init_plugin, info)