Mercurial > pidgin
view 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 |
line wrap: on
line source
#define GAIM_PLUGINS #include "gaim.h" #include <gtk/gtk.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include <ctype.h> static void *handle; static int check; static time_t mtime; static void init_file(); static void check_file(); extern void dologin(GtkWidget *, GtkWidget *); extern void do_quit(); /* parse char * as if were word array */ char *getarg(char *, int, int); /* go through file and run any commands */ void run_commands() { struct stat finfo; char filename[256]; char buffer[1024]; char *command, *arg1, *arg2; FILE *file; sprintf(filename, "%s/.gaim/control", getenv("HOME")); file = fopen(filename, "r+"); while (fgets(buffer, sizeof buffer, file)) { if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0; sprintf(debug_buff, "read: %s\n", buffer); debug_print(debug_buff); command = getarg(buffer, 0, 0); if (!strncasecmp(command, "signon", 6)) { if (!blist) { show_login(); dologin(NULL, NULL); } } else if (!strncasecmp(command, "signoff", 7)) { signoff(); } else if (!strncasecmp(command, "send", 4)) { struct conversation *c; arg1 = getarg(buffer, 1, 0); arg2 = getarg(buffer, 2, 1); c = find_conversation(arg1); if (!c) c = new_conversation(arg1); write_to_conv(c, arg2, WFLAG_SEND); serv_send_im(arg1, arg2, 0); free(arg1); free(arg2); } else if (!strncasecmp(command, "away", 4)) { struct away_message a; arg1 = getarg(buffer, 1, 1); snprintf(a.message, 2048, "%s", arg1); a.name[0] = 0; do_away_message(NULL, &a); free(arg1); } else if (!strncasecmp(command, "back", 4)) { do_im_back(); } else if (!strncasecmp(command, "quit", 4)) { do_quit(); } free(command); } fclose(file); if (stat (filename, &finfo) != 0) return; mtime = finfo.st_mtime; } void gaim_plugin_init(void *h) { handle = h; init_file(); check = gtk_timeout_add(5000, (GtkFunction)check_file, NULL); } void gaim_plugin_remove() { gtk_timeout_remove(check); } char *name() { return "Gaim File Control"; } char *description() { return "Allows you to control gaim by entering commands in a file."; } /* check to see if the size of the file is > 0. if so, run commands */ void init_file() { /* most of this was taken from Bash v2.04 by the FSF */ struct stat finfo; char file[256]; sprintf(file, "%s/.gaim/control", getenv("HOME")); if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) run_commands(); } /* check to see if we need to run commands from the file */ void check_file() { /* most of this was taken from Bash v2.04 by the FSF */ struct stat finfo; char file[256]; sprintf(file, "%s/.gaim/control", getenv("HOME")); if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) if (mtime != finfo.st_mtime) { sprintf(debug_buff, "control changed, checking\n"); debug_print(debug_buff); run_commands(); } } char *getarg(char *line, int which, int remain) { char *arr; char *val; int count = -1; int i; int state = 0; for (i = 0; i < strlen(line) && count < which; i++) { switch (state) { case 0: /* in whitespace, expecting word */ if (isalnum(line[i])) { count++; state = 1; } break; case 1: /* inside word, waiting for whitespace */ if (isspace(line[i])) { state = 0; } break; } } arr = strdup(&line[i - 1]); if (remain) return arr; for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); arr[i] = 0; val = strdup(arr); arr[i] = ' '; free(arr); return val; }
