[ekg2-commit] r3882 - trunk/ekg: trunk/ekg/commands.c trunk/ekg/configfile.c trunk/ekg/ekg.c trunk/ekg/stuff.c trunk/ekg/stuff.h
SVN commit
svn w toxygen.net
Nie, 9 Mar 2008, 19:15:38 CET
Author: peres
Date: 2008-03-09 19:15:38 +0100 (Sun, 09 Mar 2008)
New Revision: 3882
Modified:
trunk/ekg/commands.c
trunk/ekg/configfile.c
trunk/ekg/ekg.c
trunk/ekg/stuff.c
trunk/ekg/stuff.h
Log:
Aliases and children.
Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c 2008-03-09 17:07:28 UTC (rev 3881)
+++ trunk/ekg/commands.c 2008-03-09 18:15:38 UTC (rev 3882)
@@ -436,7 +436,7 @@
}
if (!params[0] || match_arg(params[0], 'l', ("list"), 2) || params[0][0] != '-') {
- list_t l;
+ alias_t *a;
int count = 0;
const char *aname = NULL;
@@ -445,8 +445,7 @@
else if (params[0])
aname = params[0];
- for (l = aliases; l; l = l->next) {
- struct alias *a = l->data;
+ for (a = aliases; a; a = a->next) {
list_t m;
int first = 1, i;
char *tmp;
@@ -651,8 +650,7 @@
COMMAND(cmd_exec)
{
- list_t l;
- int pid;
+ pid_t pid;
if (params[0]) {
int fd[2] = { 0, 0 }, buf = 0, add_commandline = 0;
@@ -745,11 +743,10 @@
child_add(NULL, pid, command, cmd_exec_child_handler, NULL);
} else {
- for (l = children; l; l = l->next) {
- child_t *c = l->data;
-
+ child_t *c;
+
+ for (c = children; c; c = c->next)
printq("process", itoa(c->pid), ((c->name) ? (c->name) : ("?")));
- }
if (!children) {
printq("no_processes");
@@ -2849,12 +2846,11 @@
COMMAND(cmd_alias_exec)
{
- list_t l, tmp = NULL, m = NULL;
+ list_t tmp = NULL, m = NULL;
+ alias_t *a;
int need_args = 0;
- for (l = aliases; l; l = l->next) {
- struct alias *a = l->data;
-
+ for (a = aliases; a; a = a->next) {
if (!xstrcasecmp(name, a->name)) {
tmp = a->commands;
break;
Modified: trunk/ekg/configfile.c
===================================================================
--- trunk/ekg/configfile.c 2008-03-09 17:07:28 UTC (rev 3881)
+++ trunk/ekg/configfile.c 2008-03-09 18:15:38 UTC (rev 3882)
@@ -395,12 +395,15 @@
}
}
- for (l = aliases; l; l = l->next) {
- struct alias *a = l->data;
- list_t m;
+ {
+ alias_t *a;
- for (m = a->commands; m; m = m->next)
- fprintf(f, "alias %s %s\n", a->name, (char *) m->data);
+ for (a = aliases; a; a = a->next) {
+ list_t m;
+
+ for (m = a->commands; m; m = m->next)
+ fprintf(f, "alias %s %s\n", a->name, (char *) m->data);
+ }
}
{
Modified: trunk/ekg/ekg.c
===================================================================
--- trunk/ekg/ekg.c 2008-03-09 17:07:28 UTC (rev 3881)
+++ trunk/ekg/ekg.c 2008-03-09 18:15:38 UTC (rev 3882)
@@ -131,7 +131,8 @@
struct timeval stv;
list_t l;
fd_set rd, wd;
- int ret, maxfd, pid, status;
+ int ret, maxfd, status;
+ pid_t pid;
gettimeofday(&tv, NULL);
@@ -230,13 +231,12 @@
/* przeglądanie zdechłych dzieciaków */
#ifndef NO_POSIX_SYSTEM
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+ child_t *c, *next;
debug("child process %d exited with status %d\n", pid, WEXITSTATUS(status));
- for (l = children; l;) {
- child_t *c = l->data;
+ for (c = children; c; c = next) {
+ next = c->next;
- l = l->next;
-
if (pid != c->pid)
continue;
@@ -257,7 +257,7 @@
c->handler(c, c->pid, c->name, WEXITSTATUS(status), c->private);
xfree(c->name);
- list_remove(&children, c, 1);
+ LIST_REMOVE2(&children, c, NULL);
}
}
#endif
@@ -1082,17 +1082,19 @@
}
send_nicks_count = 0;
- for (l = children; l; l = l->next) {
- child_t *c = l->data;
+ {
+ child_t *c;
+ for (c = children; c; c = c->next) {
#ifndef NO_POSIX_SYSTEM
- kill(c->pid, SIGTERM);
+ kill(c->pid, SIGTERM);
#else
- /* TerminateProcess / TerminateThread */
+ /* TerminateProcess / TerminateThread */
#endif
- xfree(c->name);
+ xfree(c->name);
+ }
+ LIST_DESTROY2(children, NULL); children = NULL;
}
- list_destroy(children, 1); children = NULL;
{
watch_t *w;
Modified: trunk/ekg/stuff.c
===================================================================
--- trunk/ekg/stuff.c 2008-03-09 17:07:28 UTC (rev 3881)
+++ trunk/ekg/stuff.c 2008-03-09 18:15:38 UTC (rev 3882)
@@ -82,8 +82,8 @@
#include "queries.h"
-list_t children = NULL;
-list_t aliases = NULL;
+child_t *children = NULL;
+alias_t *aliases = NULL;
list_t autofinds = NULL;
list_t bindings = NULL; /**< list_t struct timer <b>all</b> ekg2 timers */
list_t timers = NULL;
@@ -259,9 +259,8 @@
int alias_add(const char *string, int quiet, int append)
{
char *cmd;
- list_t l;
command_t *c;
- struct alias *a;
+ alias_t *a;
char **params = NULL;
char *array;
@@ -270,19 +269,17 @@
*cmd++ = 0;
- for (l = aliases; l; l = l->next) {
- struct alias *j = l->data;
-
- if (!xstrcasecmp(string, j->name)) {
+ for (a = aliases; a; a = a->next) {
+ if (!xstrcasecmp(string, a->name)) {
if (!append) {
printq("aliases_exist", string);
return -1;
} else {
- list_add(&j->commands, xstrdup(cmd));
+ list_add(&a->commands, xstrdup(cmd));
/* przy wielu komendach trudno dopełniać, bo wg. której? */
for (c = commands; c; c = c->next) {
- if (!xstrcasecmp(c->name, j->name)) {
+ if (!xstrcasecmp(c->name, a->name)) {
xfree(c->params);
c->params = array_make(("?"), (" "), 0, 1, 1);
break;
@@ -311,7 +308,7 @@
a->name = xstrdup(string);
a->commands = NULL;
list_add(&(a->commands), xstrdup(cmd));
- list_add(&aliases, a);
+ LIST_ADD2(&aliases, a);
array = (params) ? array_join(params, (" ")) : xstrdup(("?"));
command_add(NULL, a->name, array, cmd_alias_exec, COMMAND_ISALIAS, NULL);
@@ -334,23 +331,26 @@
*/
int alias_remove(const char *name, int quiet)
{
- list_t l;
+ alias_t *a;
int removed = 0;
- for (l = aliases; l; ) {
- struct alias *a = l->data;
+ for (a = aliases; a; ) {
+ alias_t *next = a->next;
- l = l->next;
-
if (!name || !xstrcasecmp(a->name, name)) {
+ alias_t *tmp;
+
if (name)
printq("aliases_del", name);
command_remove(NULL, a->name);
xfree(a->name);
list_destroy(a->commands, 1);
- list_remove(&aliases, a, 1);
+ if ((tmp = (alias_t *) LIST_REMOVE2(&aliases, a, NULL)))
+ next = tmp;
removed = 1;
}
+
+ a = next;
}
if (!removed) {
@@ -375,18 +375,16 @@
*/
void alias_free() {
- list_t l;
+ alias_t *a;
if (!aliases)
return;
- for (l = aliases; l; l = l->next) {
- struct alias *a = l->data;
-
+ for (a = aliases; a; a = a->next) {
xfree(a->name);
list_destroy(a->commands, 1);
}
- list_destroy(aliases, 1);
+ LIST_DESTROY2(aliases, NULL);
aliases = NULL;
}
@@ -1437,7 +1435,7 @@
*
* 0/-1
*/
-child_t *child_add(plugin_t *plugin, int pid, const char *name, child_handler_t handler, void *private)
+child_t *child_add(plugin_t *plugin, pid_t pid, const char *name, child_handler_t handler, void *private)
{
child_t *c = xmalloc(sizeof(child_t));
@@ -1447,7 +1445,7 @@
c->handler = handler;
c->private = private;
- list_add(&children, c);
+ LIST_ADD2(&children, c);
return c;
}
Modified: trunk/ekg/stuff.h
===================================================================
--- trunk/ekg/stuff.h 2008-03-09 17:07:28 UTC (rev 3881)
+++ trunk/ekg/stuff.h 2008-03-09 18:15:38 UTC (rev 3882)
@@ -55,9 +55,11 @@
struct child_s;
-typedef void (*child_handler_t)(struct child_s *c, int pid, const char *name, int status, void *data);
+typedef void (*child_handler_t)(struct child_s *c, pid_t pid, const char *name, int status, void *data);
typedef struct child_s {
+ struct child_s *next;
+
pid_t pid; /* id procesu */
plugin_t *plugin; /* obsługujący plugin */
char *name; /* nazwa, wyświetlana przy /exec */
@@ -66,15 +68,18 @@
} child_t;
#ifndef EKG2_WIN32_NOFUNCTION
-child_t *child_add(plugin_t *plugin, int pid, const char *name, child_handler_t handler, void *private);
+child_t *child_add(plugin_t *plugin, pid_t pid, const char *name, child_handler_t handler, void *private);
#endif
#ifndef EKG2_WIN32_NOFUNCTION
-struct alias {
+typedef struct alias {
+ struct alias *next;
+
char *name; /* nazwa aliasu */
list_t commands; /* commands->data to (char*) */
-};
+ /* XXX: maybe commands to *char[]? */
+} alias_t;
#endif
#define BINDING_FUNCTION(x) void x(const char *arg)
@@ -146,9 +151,9 @@
};
#ifndef EKG2_WIN32_NOFUNCTION
-extern list_t children;
+extern child_t *children;
extern list_t autofinds;
-extern list_t aliases;
+extern alias_t *aliases;
extern list_t bindings;
extern list_t bindings_added;
extern list_t timers;
Więcej informacji o liście dyskusyjnej ekg2-commit