annotate plugins/filectl.c @ 3315:c685bb6109c7

[gaim-migrate @ 3333] Protocol-specific "edit buddy menu" capability and Jabber "Remove From Roster" option. committer: Tailor Script <tailor@pidgin.im>
author Jim Seymour <jseymour>
date Sat, 15 Jun 2002 20:24:01 +0000
parents ccf5cd2f0354
children d33ec392a5e1
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"
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
3 #include "applet.h"
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <gtk/gtk.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 #include <stdlib.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #include <unistd.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #include <sys/types.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #include <sys/stat.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <string.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 #include <ctype.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
13 static void *handle;
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
14 static int check;
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
15 static time_t mtime;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
17 static void init_file();
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
18 static void check_file();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 extern void do_quit();
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 /* parse char * as if were word array */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 char *getarg(char *, int, int);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 /* go through file and run any commands */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 void run_commands() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 char filename[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 char buffer[1024];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 char *command, *arg1, *arg2;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 FILE *file;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 sprintf(filename, "%s/.gaim/control", getenv("HOME"));
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 file = fopen(filename, "r+");
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 while (fgets(buffer, sizeof buffer, file)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 if (buffer[strlen(buffer) - 1] == '\n')
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 buffer[strlen(buffer) - 1] = 0;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
39 debug_printf("read: %s\n", buffer);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 command = getarg(buffer, 0, 0);
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
41 if (!strncasecmp(command, "signon", 6)) {
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
42 struct aim_user *u = NULL;
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
43 GSList *userlist = aim_users;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
44 arg1 = getarg(buffer, 1, 1);
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
45 if (arg1) {
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
46 while (userlist) {
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
47 struct aim_user *current = userlist->data;
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
48 if (!strcmp(current->username, arg1)) {
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
49 u = current;
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
50 break;
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
51 }
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
52 userlist = userlist->next;
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
53 }
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
54 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 }
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
56 if (u) /* username found */
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
57 serv_login(u);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 } else if (!strncasecmp(command, "signoff", 7)) {
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
59 struct gaim_connection *gc = NULL;
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
60 GSList *c = connections;
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
61 arg1 = getarg(buffer, 1, 1);
2766
0e082a9e4c32 [gaim-migrate @ 2779]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2765
diff changeset
62 while (arg1 && c) {
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
63 gc = c->data;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
64 if (!strcmp(gc->username, arg1)) {
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
65 break;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
66 }
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
67 gc = NULL;
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
68 c = c->next;
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
69 }
2765
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
70 if (gc)
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
71 signoff(gc);
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
72 else if (!arg1)
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
73 signoff_all(NULL, NULL);
dfd9705bc750 [gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2324
diff changeset
74 free(arg1);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 } else if (!strncasecmp(command, "send", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 struct conversation *c;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 arg1 = getarg(buffer, 1, 0);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 arg2 = getarg(buffer, 2, 1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 c = find_conversation(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 if (!c) c = new_conversation(arg1);
2906
538c58b43eff [gaim-migrate @ 2919]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2766
diff changeset
81 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
82 serv_send_im(c->gc, arg1, arg2, -1, 0);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 free(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 free(arg2);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 } else if (!strncasecmp(command, "away", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 struct away_message a;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 arg1 = getarg(buffer, 1, 1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 snprintf(a.message, 2048, "%s", arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 a.name[0] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 do_away_message(NULL, &a);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 free(arg1);
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
92 } else if (!strncasecmp(command, "hide", 4)) {
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
93 hide_buddy_list();
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
94 } else if (!strncasecmp(command, "unhide", 6)) {
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
95 unhide_buddy_list();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 } else if (!strncasecmp(command, "back", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 do_im_back();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 } else if (!strncasecmp(command, "quit", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 do_quit();
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 free(command);
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
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 fclose(file);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 if (stat (filename, &finfo) != 0)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 return;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 mtime = finfo.st_mtime;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110
1047
ece2d1543b20 [gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 576
diff changeset
111 char *gaim_plugin_init(GModule *h) {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 handle = h;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 init_file();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 check = gtk_timeout_add(5000, (GtkFunction)check_file, NULL);
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
115 return NULL;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 }
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 void gaim_plugin_remove() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 gtk_timeout_remove(check);
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
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 char *name() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 return "Gaim File Control";
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 char *description() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 return "Allows you to control gaim by entering commands in a file.";
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 /* 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
131 void init_file() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 char file[256];
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 sprintf(file, "%s/.gaim/control", getenv("HOME"));
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 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 run_commands();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 /* check to see if we need to run commands from the file */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 void check_file() {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 char file[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 sprintf(file, "%s/.gaim/control", getenv("HOME"));
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 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
151 if (mtime != finfo.st_mtime) {
2324
9ab820049ede [gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1047
diff changeset
152 debug_printf("control changed, checking\n");
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 run_commands();
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
154 }
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 }
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 char *getarg(char *line, int which, int remain) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 char *arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 char *val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 int count = -1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 int i;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 int state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 for (i = 0; i < strlen(line) && count < which; i++) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 switch (state) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 case 0: /* in whitespace, expecting word */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 if (isalnum(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 count++;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 state = 1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 case 1: /* inside word, waiting for whitespace */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 if (isspace(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 }
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 arr = strdup(&line[i - 1]);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 if (remain)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 return arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 arr[i] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 val = strdup(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 arr[i] = ' ';
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 free(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 return val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 }