aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-03-07 13:56:39 +0000
committerjames <>2008-03-07 13:56:39 +0000
commit535429244c611970a7f54a12d570bfd861d6a397 (patch)
tree603d8f88a157e26a74ae33a2a6251d64a775e51a
parentbe42afab1c325fae5c3c270876a3447220adcca5 (diff)
downloadsympathy-535429244c611970a7f54a12d570bfd861d6a397.tar.gz
sympathy-535429244c611970a7f54a12d570bfd861d6a397.tar.bz2
sympathy-535429244c611970a7f54a12d570bfd861d6a397.zip
*** empty log message ***
-rw-r--r--apps/Makefile.am5
-rw-r--r--apps/clients.c22
-rw-r--r--apps/expand.c188
-rw-r--r--apps/mainloop.c11
-rw-r--r--apps/sympathy.c62
5 files changed, 249 insertions, 39 deletions
diff --git a/apps/Makefile.am b/apps/Makefile.am
index 51a39e4..c308bee 100644
--- a/apps/Makefile.am
+++ b/apps/Makefile.am
@@ -7,6 +7,9 @@
# $Id$
#
# $Log$
+# Revision 1.12 2008/03/07 13:56:39 james
+# *** empty log message ***
+#
# Revision 1.11 2008/02/24 00:42:53 james
# *** empty log message ***
#
@@ -48,7 +51,7 @@ INCLUDES = -I$(srcdir)/../src
bin_PROGRAMS = sympathy
HDRS=clients.h mainloop.h
-SRCS=sympathy.c usage.c clients.c mainloop.c
+SRCS=sympathy.c usage.c clients.c mainloop.c expand.c
noinst_HEADERS=${HDRS}
diff --git a/apps/clients.c b/apps/clients.c
index 0dcd863..346439e 100644
--- a/apps/clients.c
+++ b/apps/clients.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.20 2008/03/07 13:56:39 james
+ * *** empty log message ***
+ *
* Revision 1.19 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -78,15 +81,16 @@ static char rcsid[] = "$Id$";
#include "clients.h"
-void client_initialize(Client *c,Context *ctx)
+void
+client_initialize (Client * c, Context * ctx)
{
- send_history (ctx->h, c);
- send_vt102 (ctx->v, c);
- c->initialized=1;
+ send_history (ctx->h, c);
+ send_vt102 (ctx->v, c);
+ c->initialized = 1;
}
void
-client_execute_message (Client *client,IPC_Msg * m, Context * c)
+client_execute_message (Client * client, IPC_Msg * m, Context * c)
{
switch (m->hdr.type) {
case IPC_MSG_TYPE_NOOP:
@@ -124,7 +128,7 @@ client_execute_message (Client *client,IPC_Msg * m, Context * c)
vt102_reset (c);
break;
case IPC_MSG_TYPE_INITIALIZE:
- client_initialize(client,c);
+ client_initialize (client, c);
break;
default:
log_f (c->l, "<Unhandled message type %d>", m->hdr.type);
@@ -151,7 +155,7 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx)
c = (Client *) xmalloc (sizeof (Client));
- c->initialized=0;
+ c->initialized = 0;
c->dead = 0;
c->s = s;
c->next = cs->head;
@@ -224,8 +228,8 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
}
if (c->s->msg) {
- client_execute_message (c,c->s->msg,ctx);
- socket_consume_msg (c->s);
+ client_execute_message (c, c->s->msg, ctx);
+ socket_consume_msg (c->s);
}
}
diff --git a/apps/expand.c b/apps/expand.c
new file mode 100644
index 0000000..2c07ca1
--- /dev/null
+++ b/apps/expand.c
@@ -0,0 +1,188 @@
+/*
+ * expand.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1 2008/03/07 13:56:39 james
+ * *** empty log message ***
+ *
+ */
+
+#include <sympathy.h>
+
+
+static int
+xdigit_to_i (char c)
+{
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ return c - '0';
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ return 0xa + (c - 'a');
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ return 0xA + (c - 'A');
+ }
+ return -1;
+}
+
+static int
+my_isxdigit (char c)
+{
+ return (xdigit_to_i (c) == -1) ? 0 : 1;
+}
+
+
+static int
+my_isodigit (char c)
+{
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ return 1;
+ }
+ return 0;
+}
+
+static int
+octal (const char **in)
+{
+ int o = 0;
+
+ while (**in) {
+ if (!my_isodigit (**in))
+ return o;
+ o <<= 3;
+ o += (*((*in)++)) - '0';
+ }
+
+ return o;
+}
+
+static int
+hex (const char **in)
+{
+ int x = 0;
+
+ (*in)++;
+ while (**in) {
+ printf("%c %d\n",**in,x);
+ if (!my_isxdigit (**in))
+ return x;
+ x <<= 4;
+ x += xdigit_to_i (*((*in)++));
+ }
+
+ return x;
+}
+
+char *
+expand (const char *in)
+{
+ const char *iptr = in;
+ int l;
+ char *optr;
+ char *ret;
+
+ if (!in)
+ return (char *) 0;
+ l = strlen (in);
+
+ optr = ret = malloc (l + 1);
+ if (!ret) return ret;
+
+
+ while (*iptr) {
+ if (*iptr == '\\') {
+ iptr++;
+ switch (*iptr) {
+ case '\'':
+ case '\"':
+ case '\?':
+ case '\\':
+ *(optr++) = *(iptr++);
+ break;
+ case 'a':
+ *(optr++) = '\a';
+ iptr++;
+ break;
+ case 'b':
+ *(optr++) = '\b';
+ iptr++;
+ break;
+ case 'f':
+ *(optr++) = '\f';
+ iptr++;
+ break;
+ case 'n':
+ *(optr++) = '\n';
+ iptr++;
+ break;
+ case 'r':
+ *(optr++) = '\r';
+ iptr++;
+ break;
+ case 't':
+ *(optr++) = '\t';
+ iptr++;
+ break;
+ case 'v':
+ *(optr++) = '\v';
+ iptr++;
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ *(optr++) = octal (&iptr);
+ break;
+ case 'x':
+ *(optr++) = hex (&iptr);
+ break;
+ default:
+ *(optr++) = '\\';
+ *(optr++) = *(iptr++);
+ }
+ } else {
+ *(optr++) = *(iptr++);
+ }
+ }
+
+ *(optr++) = 0;
+ return ret;
+}
diff --git a/apps/mainloop.c b/apps/mainloop.c
index 6eec7be..15c30ed 100644
--- a/apps/mainloop.c
+++ b/apps/mainloop.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.28 2008/03/07 13:56:39 james
+ * *** empty log message ***
+ *
* Revision 1.27 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -392,7 +395,7 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c)
break;
case IPC_MSG_TYPE_VT102:
if (sizeof (VT102) != m->vt102.len)
- crash_out("sizeof(VT102) differs in client and server");
+ crash_out ("sizeof(VT102) differs in client and server");
*(c->v) = m->vt102.vt102;
@@ -428,11 +431,11 @@ mainloop (Context * c, ANSI * ansi, Socket * server_socket,
/* are we being fed by a tty or a socket */
if (client_socket) {
if (server_socket)
- crash_out("mainloop cannot both be a server and a client");
+ crash_out ("mainloop cannot both be a server and a client");
c->k = keydis_ipc_new (client_socket);
} else {
if (!c->t)
- crash_out("mainloop must have either a client_socket or a terminal");
+ crash_out ("mainloop must have either a client_socket or a terminal");
c->k = keydis_vt102_new ();
}
@@ -450,7 +453,7 @@ mainloop (Context * c, ANSI * ansi, Socket * server_socket,
if (server_socket) {
if (client_socket)
- crash_out("mainloop cannot both be a server and a client");
+ crash_out ("mainloop cannot both be a server and a client");
clients = clients_new ();
} else {
clients = NULL;
diff --git a/apps/sympathy.c b/apps/sympathy.c
index bb141b1..7c68529 100644
--- a/apps/sympathy.c
+++ b/apps/sympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.38 2008/03/07 13:56:39 james
+ * *** empty log message ***
+ *
* Revision 1.37 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -142,6 +145,7 @@ static char rcsid[] =
#include "mainloop.h"
extern void usage (void);
+extern char * expand(const char *);
static char hostname[1024];
char *socket_dirs[] =
@@ -409,7 +413,6 @@ list_sockets (void)
return 0;
}
-
void
get_hostname (void)
{
@@ -425,6 +428,12 @@ get_hostname (void)
strcat (hostname, ".");
}
+void send_to_server(Socket *c,char *s)
+{
+s=expand(s);
+//FIXME
+
+}
int
main (int argc, char *argv[])
@@ -760,34 +769,37 @@ main (int argc, char *argv[])
}
- if (oflags['I']) {
- // FIXME ...
-
- } else {
- if (client_socket)
- ipc_msg_send_initialize(client_socket);
-
- if (oflags['c'] || oflags['t']) {
- if (oflags['N']) {
- ctx->r = rx_new_raw (0, 1);
- ansi = ansi_new_raw (0, 1);
- } else if (oflags['H']) {
- ansi = ansi_new_html (stdout);
- } else {
- terminal_register_handlers ();
- ansi =
- ansi_new_from_terminal (terminal_open (0, 1), oflags['u'] ? 0 : 1);
- ansi->reset (ansi, NULL);
- if (ansi->set_title)
- ansi->set_title (ansi, oargs['k']);
+ if (oflags['I']) {
+ if (!client_socket)
+ fatal_moan ("-I requires either -c or -r", oargs['k']);
+ if (!oargs['I'])
+ fatal_moan ("-I requires an arugment");
+ send_to_server(client_socket,oargs['I']);
+ } else {
+ if (client_socket)
+ ipc_msg_send_initialize (client_socket);
+
+ if (oflags['c'] || oflags['t']) {
+ if (oflags['N']) {
+ ctx->r = rx_new_raw (0, 1);
+ ansi = ansi_new_raw (0, 1);
+ } else if (oflags['H']) {
+ ansi = ansi_new_html (stdout);
+ } else {
+ terminal_register_handlers ();
+ ansi =
+ ansi_new_from_terminal (terminal_open (0, 1), oflags['u'] ? 0 : 1);
+ ansi->reset (ansi, NULL);
+ if (ansi->set_title)
+ ansi->set_title (ansi, oargs['k']);
+ }
}
- }
- ctx->v = vt102_new (&size);
- ctx->h = history_new (history);
+ ctx->v = vt102_new (&size);
+ ctx->h = history_new (history);
- mainloop (ctx, ansi, server_socket, client_socket);
+ mainloop (ctx, ansi, server_socket, client_socket);
}
if (ansi) {