annotate plugins/filectl.c @ 8033:c417617ae0cf

[gaim-migrate @ 8713] I can't think of a good british joke, so insert your favorite one here. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 07 Jan 2004 04:04:44 +0000
parents 251e2e434a86
children e4952ba22fc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
1 /*
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
2 ** Send commands to gaim via ~/.gaim/control
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
3 **
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
4 ** By Eric Warmenhoven <eric@warmenhoven.org>
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
5 ** compile fixes/mini hacks Alex Bennee <alex@bennee.com>
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
6 */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
8 /* system includes */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <gtk/gtk.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <stdlib.h>
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
11 #include <stdio.h>
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #include <unistd.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #include <sys/types.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #include <sys/stat.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #include <string.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 #include <ctype.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
18 /* gaim includes */
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
19 #include "internal.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
20
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
21 #include "config.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
22 #include "gaim.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
23 #include "debug.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
24 #include "account.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
25 #include "conversation.h"
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
26
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
27
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
28
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
29 #define FILECTL_PLUGIN_ID "core-filectl"
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
30 static int check;
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
31 static time_t mtime;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
33 static void init_file();
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
34 static gboolean check_file();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 /* parse char * as if were word array */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 char *getarg(char *, int, int);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 /* go through file and run any commands */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 void run_commands() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 char filename[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 char buffer[1024];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 char *command, *arg1, *arg2;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 FILE *file;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 sprintf(filename, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 file = fopen(filename, "r+");
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 while (fgets(buffer, sizeof buffer, file)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 if (buffer[strlen(buffer) - 1] == '\n')
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 buffer[strlen(buffer) - 1] = 0;
5227
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
53 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 command = getarg(buffer, 0, 0);
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
55 if (!strncasecmp(command, "signon", 6)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
56 GaimAccount *account = NULL;
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
57 GList *accts = gaim_accounts_get_all();
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
58 arg1 = getarg(buffer, 1, 1);
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
59 if (arg1) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
60 while (accts) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
61 GaimAccount *a = accts->data;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
62 if (!strcmp(a->username, arg1)) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
63 account = a;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
64 break;
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
65 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
66 accts = accts->next;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
67 }
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
68 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4359
diff changeset
70 if (account) /* username found */
6036
547ba881bc7e [gaim-migrate @ 6486]
Mark Doliner <mark@kingant.net>
parents: 5920
diff changeset
71 gaim_account_connect(account);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 } else if (!strncasecmp(command, "signoff", 7)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
73 GaimConnection *gc = NULL;
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
74 GList *c = gaim_connections_get_all();
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
75 arg1 = getarg(buffer, 1, 1);
2766
0e082a9e4c32 [gaim-migrate @ 2779]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2765
diff changeset
76 while (arg1 && c) {
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
77 gc = c->data;
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
78 if (!strcmp(gc->account->username, arg1)) {
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
79 break;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
80 }
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
81 gc = NULL;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
82 c = c->next;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
83 }
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
84 if (gc)
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
85 gaim_connection_disconnect(gc);
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
86 else if (!arg1)
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
87 gaim_connections_disconnect_all();
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
88 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 } else if (!strncasecmp(command, "send", 4)) {
5676
dae79aefac8d [gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents: 5255
diff changeset
90 GaimConversation *c;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 arg1 = getarg(buffer, 1, 0);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 arg2 = getarg(buffer, 2, 1);
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
93 c = gaim_find_conversation(arg1);
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
94 if (c)
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
95 {
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
96 /* disable for now
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
97 gaim_conversation_write(c, arg2, WFLAG_SEND, NULL, time(NULL), -1);
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
98 serv_send_im(c->gc, arg1, arg2, 0);
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
99 */
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
100 }
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 free(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 free(arg2);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 } else if (!strncasecmp(command, "away", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 arg1 = getarg(buffer, 1, 1);
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
105 serv_set_away_all(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 free(arg1);
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
107 } else if (!strncasecmp(command, "hide", 4)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
108 //hide_buddy_list();
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
109 } else if (!strncasecmp(command, "unhide", 6)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
110 //unhide_buddy_list();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 } else if (!strncasecmp(command, "back", 4)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
112 //do_im_back();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 } else if (!strncasecmp(command, "quit", 4)) {
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
114 //gaim_core_quit();
106
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 free(command);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 }
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 fclose(file);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 if (stat (filename, &finfo) != 0)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 return;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 mtime = finfo.st_mtime;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 }
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 /* 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
127 void init_file() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 char file[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 sprintf(file, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 run_commands();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 /* check to see if we need to run commands from the file */
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
139 gboolean check_file() {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 char file[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 sprintf(file, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
147 {
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
148 if (mtime != finfo.st_mtime) {
5227
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
149 gaim_debug(GAIM_DEBUG_INFO, "filectl",
6d1707dc8c3d [gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
150 "control changed, checking\n");
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 run_commands();
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
152 }
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
153 }
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
154
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
155 return TRUE;
106
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 char *getarg(char *line, int which, int remain) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 char *arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 char *val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 int count = -1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 int i;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 int state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 for (i = 0; i < strlen(line) && count < which; i++) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 switch (state) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 case 0: /* in whitespace, expecting word */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 if (isalnum(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 count++;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 state = 1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 case 1: /* inside word, waiting for whitespace */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 if (isspace(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 arr = strdup(&line[i - 1]);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 if (remain)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 return arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 arr[i] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 val = strdup(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 arr[i] = ' ';
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 free(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 return val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 }
5255
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 * EXPORTED FUNCTIONS
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
194 */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
195
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
196 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
197 plugin_load(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
198 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
199 init_file();
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
200 check = g_timeout_add(5000, (GSourceFunc) check_file, NULL);
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
201
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
202 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
203 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
204
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
205 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
206 plugin_unload(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
207 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
208 g_source_remove(check);
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 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
211 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
212
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
213 static GaimPluginInfo info =
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
214 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
215 2, /**< api_version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
216 GAIM_PLUGIN_STANDARD, /**< type */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
217 NULL, /**< ui_requirement */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
218 0, /**< flags */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
219 NULL, /**< dependencies */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
220 GAIM_PRIORITY_DEFAULT, /**< priority */
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 FILECTL_PLUGIN_ID, /**< id */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
223 N_("Gaim File Control"), /**< name */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
224 VERSION, /**< version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
225 /** summary */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
226 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
227 /** description */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
228 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
229 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6179
diff changeset
230 GAIM_WEBSITE, /**< homepage */
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
231
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
232 plugin_load, /**< load */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
233 plugin_unload, /**< unload */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
234 NULL, /**< destroy */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
235
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
236 NULL, /**< ui_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
237 NULL /**< extra_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
238 };
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
239
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
240 static void
5920
7d385de2f9cd [gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
241 init_plugin(GaimPlugin *plugin)
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
242 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
243 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
244
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 6036
diff changeset
245 GAIM_INIT_PLUGIN(filectl, init_plugin, info)