aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjames <>2008-03-06 16:49:05 +0000
committerjames <>2008-03-06 16:49:05 +0000
commitd7565f9da9ada7a0aa90abdb6d8d1ba192075791 (patch)
tree5a77a1803fc3ab97fb02e0dc6ee748e09deba03d /apps
parentd32c10b1eb919c4b82f882bcf29b06b287e2b50a (diff)
downloadsympathy-d7565f9da9ada7a0aa90abdb6d8d1ba192075791.tar.gz
sympathy-d7565f9da9ada7a0aa90abdb6d8d1ba192075791.tar.bz2
sympathy-d7565f9da9ada7a0aa90abdb6d8d1ba192075791.zip
*** empty log message ***
Diffstat (limited to 'apps')
-rw-r--r--apps/mainloop.c75
-rw-r--r--apps/mainloop.h8
-rw-r--r--apps/sympathy.c60
3 files changed, 80 insertions, 63 deletions
diff --git a/apps/mainloop.c b/apps/mainloop.c
index dd553e3..5772214 100644
--- a/apps/mainloop.c
+++ b/apps/mainloop.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.23 2008/03/06 16:49:05 james
+ * *** empty log message ***
+ *
* Revision 1.22 2008/03/03 06:04:42 james
* *** empty log message ***
*
@@ -121,7 +124,6 @@ static char rcsid[] =
#include "clients.h"
-Context *context;
typedef struct
{
@@ -378,6 +380,7 @@ check_status (Context * c, Clients * cs)
static int
msg_from_server (ANSI * a, IPC_Msg * m, Context * c)
{
+int err=0;
switch (m->hdr.type)
{
@@ -398,11 +401,11 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c)
if (a->one_shot)
{
a->one_shot (a, &c->v->crt);
- return 1;
+ err++;/*Simulate a fatal write error enclosing tty*/
}
break;
case IPC_MSG_TYPE_TERM:
- tty_parse (c, m->term.term, m->term.len);
+ err+=tty_parse (c, m->term.term, m->term.len);
break;
case IPC_MSG_TYPE_STATUS:
cmd_new_status (c->d, c, m->status.status);
@@ -410,54 +413,46 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c)
default:
fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
}
- return 0;
+ return err;
}
void
-mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
- ANSI * ansi, Log * log, int nhistory, CRT_Pos * size)
+mainloop ( Context *c, ANSI *ansi,Socket * server_socket, Socket * client_socket)
{
fd_set rfds, wfds;
- Context c = { 0 };
Clients *clients;
- context = &c;
+ c->tp = tty_parser_new ();
+ c->u = utf8_new ();
- c.tp = tty_parser_new ();
- c.u = utf8_new ();
-
- c.v = vt102_new (size);
- c.h = history_new (nhistory);
- c.l = log;
/* are we being fed by a tty or a socket */
if (client_socket)
{
if (server_socket)
abort ();
- c.k = keydis_ipc_new (client_socket);
+ c->k = keydis_ipc_new (client_socket);
}
else
{
- if (!tty)
+ if (!c->t)
abort ();
- c.t = tty;
- c.k = keydis_vt102_new ();
+ c->k = keydis_vt102_new ();
}
/* do we have an upstream terminal to talk to */
/* if so start a command parser */
if (ansi)
{
- c.d = cmd_new ();
+ c->d = cmd_new ();
}
else
{
- c.d = NULL;
+ c->d = NULL;
}
- vt102_reset (&c);
+ vt102_reset (c);
if (server_socket)
@@ -475,18 +470,18 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
{
struct timeval tv = { 0, 250000 };
- if ((c.d) && (c.d->disconnect))
+ if ((c->d) && (c->d->disconnect))
break;
/*update the status lines, locally or remotely */
- if (c.t)
- check_status (&c, clients);
+ if (c->t)
+ check_status (c, clients);
FD_ZERO (&rfds);
FD_ZERO (&wfds);
- if (c.t)
- tty_pre_select (c.t, &rfds, &wfds);
+ if (c->t)
+ tty_pre_select (c->t, &rfds, &wfds);
if (server_socket)
{
@@ -513,24 +508,24 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
Client *new_client;
/*New client connexion */
new_client =
- clients_new_client (clients, new_client_socket, &c);
+ clients_new_client (clients, new_client_socket, c);
- send_history (c.h, new_client);
- send_vt102 (c.v, new_client);
+ send_history (c->h, new_client);
+ send_vt102 (c->v, new_client);
}
}
- clients_post_select (clients, &c, &rfds, &wfds);
+ clients_post_select (clients, c, &rfds, &wfds);
}
/*any data from the port */
- if (c.t && FD_ISSET (c.t->rfd, &rfds))
+ if (c->t && FD_ISSET (c->t->rfd, &rfds))
{
char buf[IPC_MAX_BUF];
int red;
- red = c.t->recv (c.t, buf, sizeof (buf));
+ red = c->t->recv (c->t, buf, sizeof (buf));
if (red < 0)
break;
@@ -539,7 +534,8 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
{
if (clients)
send_output (clients, buf, red);
- tty_parse (&c, buf, red);
+ if (tty_parse (c, buf, red))
+ break;
}
}
@@ -548,19 +544,16 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
/*any data from the server */
if (client_socket)
{
- int one_shot;
if (socket_post_select (client_socket, &rfds, &wfds))
break;
while (client_socket->msg)
{
- if (msg_from_server (ansi, client_socket->msg, &c))
- one_shot++;
+ if (msg_from_server (ansi, client_socket->msg, c))
+ break;
socket_consume_msg (client_socket);
}
- if (one_shot)
- break;
}
@@ -568,10 +561,12 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
if (ansi)
{
if (ansi->dispatch)
- ansi->dispatch (ansi, &c);
+ if (ansi->dispatch (ansi, c))
+ break;
if (ansi->update)
- ansi->update (ansi, &c);
+ if (ansi->update (ansi, c))
+ break;
}
}
diff --git a/apps/mainloop.h b/apps/mainloop.h
index 418b641..e85b784 100644
--- a/apps/mainloop.h
+++ b/apps/mainloop.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.8 2008/03/06 16:49:05 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/03/03 06:04:42 james
* *** empty log message ***
*
@@ -40,8 +43,5 @@
#include <sympathy.h>
-extern void
-mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, ANSI * a,
- Log * log, int nhistory, CRT_Pos * size);
-
+extern void mainloop (Context *,ANSI *a,Socket *,Socket *);
#endif /* __MAINLOOP_H__ */
diff --git a/apps/sympathy.c b/apps/sympathy.c
index f5ed2e0..dc9dd66 100644
--- a/apps/sympathy.c
+++ b/apps/sympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.33 2008/03/06 16:49:05 james
+ * *** empty log message ***
+ *
* Revision 1.32 2008/03/03 06:04:42 james
* *** empty log message ***
*
@@ -433,11 +436,14 @@ get_hostname (void)
int
main (int argc, char *argv[])
{
+ Context ctx_store={0},*ctx=&ctx_store;
int c;
extern char *optarg;
extern int optind, opterr, optopt;
CRT_Pos size = { VT102_COLS_80, VT102_ROWS_24 };
+ ANSI *ansi=NULL;
+
int csnok_pipe[2] = { 0 };
int csnok = 0;
@@ -445,9 +451,6 @@ main (int argc, char *argv[])
char *oargs[128];
Socket *server_socket = NULL, *client_socket = NULL;
- ANSI *ansi = NULL;
- TTY *tty = NULL;
- Log *log = NULL;
int history = 200;
int pid;
@@ -458,7 +461,7 @@ main (int argc, char *argv[])
memset (oflags, 0, sizeof (oflags));
memset (oargs, 0, sizeof (oargs));
- while ((c = getopt (argc, argv, "RP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF)
+ while ((c = getopt (argc, argv, "I:NRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF)
{
switch (c)
{
@@ -548,6 +551,9 @@ main (int argc, char *argv[])
if (oflags['c'] && oflags['s'] && oflags['F'])
fatal_moan ("-F is incompatible with -c -s");
+ if (oflags['H'] && oflags['N'])
+ fatal_moan ("-H is incompatible with -N");
+
/*implement server and client: this process forks. The parent */
/*becomes the client and the child forks again to become the */
/*server. If there's no -k argument the client (parent) needs */
@@ -566,6 +572,8 @@ main (int argc, char *argv[])
case 0: /*child becomes the server */
oflags['c'] = 0;
oflags['H'] = 0;
+ oflags['N'] = 0;
+ oflags['I'] = 0;
if (csnok)
close (csnok_pipe[0]);
@@ -612,6 +620,9 @@ main (int argc, char *argv[])
if (oflags['c'] && !oflags['k'] && !oflags['r'])
fatal_moan ("-c requires a socket to be specified with -s or -k or -r");
+ if ((oflags['H'] || oflags['N'] || oflags['I'] ) && oflags['s'])
+ fatal_moan("-s is incompatible with -H, -N and -I");
+
if ((oflags['p'] || oflags['d'] || oflags['K'] || oflags['b'] || oflags['f']
|| oflags['L'] || oflags['R'] || oflags['P']) && oflags['c'])
fatal_moan
@@ -701,15 +712,15 @@ main (int argc, char *argv[])
if (oflags['L'])
{
- log = file_log_new (oargs['L'], oflags['R']);
- if (!log)
+ ctx->l = file_log_new (oargs['L'], oflags['R']);
+ if (!ctx->l)
fatal_moan ("unable to access log file %s", oargs['L']);
}
if (oflags['p'])
{
- tty = ptty_open (NULL, NULL, &size);
- if (!tty)
+ ctx->t = ptty_open (NULL, NULL, &size);
+ if (!ctx->t)
fatal_moan ("unable to open a ptty");
}
else
@@ -740,11 +751,11 @@ main (int argc, char *argv[])
fatal_moan ("/proc/cmdline contains %s", search_string);
}
- tty =
+ ctx->t =
serial_open (oargs['d'],
oflags['K'] ? SERIAL_LOCK_ACTIVE :
SERIAL_LOCK_PASSIVE);
- if (!tty)
+ if (!ctx->t)
fatal_moan ("unable to open serial port %s", oargs['d']);
}
@@ -755,11 +766,11 @@ main (int argc, char *argv[])
if (baud < 0)
fatal_moan ("Unable to parse baudrate %s", oargs['b']);
- tty_set_baud (tty, baud);
+ tty_set_baud (ctx->t, baud);
}
- tty_set_flow (tty, oflags['f'] ? 1 : 0);
+ tty_set_flow (ctx->t, oflags['f'] ? 1 : 0);
}
@@ -795,8 +806,10 @@ main (int argc, char *argv[])
if (oflags['c'] || oflags['t'])
{
-
- if (oflags['H'])
+ 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);
}
@@ -808,9 +821,18 @@ main (int argc, char *argv[])
oflags['u'] ? 0 : 1);
ansi->reset (ansi, NULL);
}
+ if (oflags['I']) {
+ //FIXME ...
+ }
}
- mainloop (tty, server_socket, client_socket, ansi, log, history, &size);
+
+ ctx->v = vt102_new (&size);
+ ctx->h = history_new (history);
+
+ mainloop (ctx,ansi, server_socket, client_socket);
+
+// mainloop (tty, server_socket, client_socket, ansi, log, history, &size);
if (ansi)
{
@@ -818,11 +840,11 @@ main (int argc, char *argv[])
terminal_atexit ();
}
- if (tty)
- tty->close (tty);
+ if (ctx->t)
+ ctx->t->close (ctx->t);
- if (log)
- log->close (log);
+ if (ctx->l)
+ ctx->l->close (ctx->l);
if (server_socket)
socket_free (server_socket);
if (client_socket)