Mercurial > pidgin
annotate plugins/filectl.c @ 312:3069be4c291e
[gaim-migrate @ 322]
I don't know why I did this. I have homework due in 15 hours that I haven't
started yet, and it's in a language I don't know and it's a project I don't
understand. If my teacher knew about this, he would be pissed. He looks
pissed all the time, even when he's not. When he smiles he looks devilish.
Maybe I only think that because literally half the class flunked the midterm.
I am not joking about that. More people got F's than A, B, and C combined.
It's 2 am and the homework's due at 5 tomorrow so what do I do? Get chat to
work. Wow. That's going to look good on my resume. "Why did you flunk this
class?" "Because I was getting chat in Instant Messenger to work." Not that
that's not something to be proud of, but I wonder which is more important to
employers. The big battle, experience versus education. Just because you
got good grades in college doesn't mean you're smarter than someone who
flunked, it just means you put in the effort necessary to get a better grade
and the other person didn't. Maybe the person who flunked was working on
real honest-to-god actually *used* software, as opposed to some stupid tree
that only gets used for a fringe branch of computer science that doesn't
offer much more than a normal heap or binary search tree offers. Maybe the
person was out there reverse-engineering protocols and allowing cross-
platform communication to occur, creating interoperability and causing a
greater demand not only for the product, but for the platform it runs on!
Given the choices, who would you pick? Someone who was told how to code a
tree and managed to get it to work, or someone who increases your userbase
and marketability?
Enough of my rant for a while. I've had waaaaay too much sugar (gummy candy is
deadly).
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Fri, 02 Jun 2000 09:11:48 +0000 |
| parents | 8d8faeab01f6 |
| children | bb22fb4a7d39 |
| rev | line source |
|---|---|
| 106 | 1 #define GAIM_PLUGINS |
| 2 #include "gaim.h" | |
| 3 | |
| 4 #include <gtk/gtk.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <unistd.h> | |
| 7 #include <sys/types.h> | |
| 8 #include <sys/stat.h> | |
| 9 #include <string.h> | |
| 10 #include <ctype.h> | |
| 11 | |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
12 static void *handle; |
|
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 | 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 | 18 |
| 19 extern void dologin(GtkWidget *, GtkWidget *); | |
| 20 extern void do_quit(); | |
| 21 | |
| 22 /* parse char * as if were word array */ | |
| 23 char *getarg(char *, int, int); | |
| 24 | |
| 25 /* go through file and run any commands */ | |
| 26 void run_commands() { | |
| 27 struct stat finfo; | |
| 28 char filename[256]; | |
| 29 char buffer[1024]; | |
| 30 char *command, *arg1, *arg2; | |
| 31 FILE *file; | |
| 32 | |
| 33 sprintf(filename, "%s/.gaim/control", getenv("HOME")); | |
| 34 | |
| 35 file = fopen(filename, "r+"); | |
| 36 while (fgets(buffer, sizeof buffer, file)) { | |
| 37 if (buffer[strlen(buffer) - 1] == '\n') | |
| 38 buffer[strlen(buffer) - 1] = 0; | |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
39 sprintf(debug_buff, "read: %s\n", buffer); |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
40 debug_print(debug_buff); |
| 106 | 41 command = getarg(buffer, 0, 0); |
| 42 if (!strncasecmp(command, "signon", 6)) { | |
| 43 if (!blist) { | |
| 44 show_login(); | |
| 45 dologin(NULL, NULL); | |
| 46 } | |
| 47 } else if (!strncasecmp(command, "signoff", 7)) { | |
| 48 signoff(); | |
| 49 } else if (!strncasecmp(command, "send", 4)) { | |
| 50 struct conversation *c; | |
| 51 arg1 = getarg(buffer, 1, 0); | |
| 52 arg2 = getarg(buffer, 2, 1); | |
| 53 c = find_conversation(arg1); | |
| 54 if (!c) c = new_conversation(arg1); | |
| 55 write_to_conv(c, arg2, WFLAG_SEND); | |
| 56 serv_send_im(arg1, arg2, 0); | |
| 57 free(arg1); | |
| 58 free(arg2); | |
| 59 } else if (!strncasecmp(command, "away", 4)) { | |
| 60 struct away_message a; | |
| 61 arg1 = getarg(buffer, 1, 1); | |
| 62 snprintf(a.message, 2048, "%s", arg1); | |
| 63 a.name[0] = 0; | |
| 64 do_away_message(NULL, &a); | |
| 65 free(arg1); | |
| 66 } else if (!strncasecmp(command, "back", 4)) { | |
| 67 do_im_back(); | |
| 68 } else if (!strncasecmp(command, "quit", 4)) { | |
| 69 do_quit(); | |
| 70 } | |
| 71 free(command); | |
| 72 } | |
| 73 | |
| 74 fclose(file); | |
| 75 | |
| 76 if (stat (filename, &finfo) != 0) | |
| 77 return; | |
| 78 mtime = finfo.st_mtime; | |
| 79 } | |
| 80 | |
| 81 void gaim_plugin_init(void *h) { | |
| 82 handle = h; | |
| 83 init_file(); | |
| 84 check = gtk_timeout_add(5000, (GtkFunction)check_file, NULL); | |
| 85 } | |
| 86 | |
| 87 void gaim_plugin_remove() { | |
| 88 gtk_timeout_remove(check); | |
| 89 } | |
| 90 | |
| 91 char *name() { | |
| 92 return "Gaim File Control"; | |
| 93 } | |
| 94 | |
| 95 char *description() { | |
| 96 return "Allows you to control gaim by entering commands in a file."; | |
| 97 } | |
| 98 | |
| 99 /* check to see if the size of the file is > 0. if so, run commands */ | |
| 100 void init_file() { | |
| 101 /* most of this was taken from Bash v2.04 by the FSF */ | |
| 102 struct stat finfo; | |
| 103 char file[256]; | |
| 104 | |
| 105 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
| 106 | |
| 107 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
| 108 run_commands(); | |
| 109 } | |
| 110 | |
| 111 /* check to see if we need to run commands from the file */ | |
| 112 void check_file() { | |
| 113 /* most of this was taken from Bash v2.04 by the FSF */ | |
| 114 struct stat finfo; | |
| 115 char file[256]; | |
| 116 | |
| 117 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
| 118 | |
| 119 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
120 if (mtime != finfo.st_mtime) { |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
121 sprintf(debug_buff, "control changed, checking\n"); |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
122 debug_print(debug_buff); |
| 106 | 123 run_commands(); |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
124 } |
| 106 | 125 } |
| 126 | |
| 127 char *getarg(char *line, int which, int remain) { | |
| 128 char *arr; | |
| 129 char *val; | |
| 130 int count = -1; | |
| 131 int i; | |
| 132 int state = 0; | |
| 133 | |
| 134 for (i = 0; i < strlen(line) && count < which; i++) { | |
| 135 switch (state) { | |
| 136 case 0: /* in whitespace, expecting word */ | |
| 137 if (isalnum(line[i])) { | |
| 138 count++; | |
| 139 state = 1; | |
| 140 } | |
| 141 break; | |
| 142 case 1: /* inside word, waiting for whitespace */ | |
| 143 if (isspace(line[i])) { | |
| 144 state = 0; | |
| 145 } | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 arr = strdup(&line[i - 1]); | |
| 151 if (remain) | |
| 152 return arr; | |
| 153 | |
| 154 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); | |
| 155 arr[i] = 0; | |
| 156 val = strdup(arr); | |
| 157 arr[i] = ' '; | |
| 158 free(arr); | |
| 159 return val; | |
| 160 } |
