/*
* $Log$
+ * Revision 1.24 2008/02/28 22:00:42 james
+ * *** empty log message ***
+ *
* Revision 1.23 2008/02/28 16:57:51 james
* *** empty log message ***
*
extern int optind, opterr, optopt;
CRT_Pos size = { VT102_COLS_80, VT102_ROWS_24 };
+ int csnok_pipe[2] = { 0 };
+ int csnok = 0;
+
int oflags[128];
char *oargs[128];
Log *log = NULL;
int history = 200;
-
+ int pid;
get_hostname ();
if (oflags['p'] && oflags['d'])
fatal_moan ("-p incompatible with -d");
- /*implement server and client by opening the server socket to prevent */
- /*a race condition, and then forking and munging the cmd line options */
- /*in the parent and child so that the child is the server and the */
- /*parent becomes its client */
if (oflags['c'] && oflags['s'] && oflags['F'])
fatal_moan ("-F is incompatible with -c -s");
- if (oflags['s'] && !oflags['k'])
- {
- char *path;
- path = mome ("/.sympathy");
- mkdir (path, 0700);
- free (path);
-
- oargs['k'] = mome ("/.sympathy/%s%d", hostname, getpid ());
- oflags['k']++;
- }
-
- if (oflags['s'])
- {
- server_socket = socket_listen (oargs['k']);
- if (!server_socket)
- fatal_moan ("failed to create socket %s for listening", oargs['k']);
- }
+ /*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 */
+ /*to find out the pid of the server, we use a pipe */
if (oflags['s'] && oflags['c'])
{
- switch (fork ())
+ if (!oflags['k'])
+ {
+ csnok++;
+ pipe (csnok_pipe);
+ }
+
+ switch (pid = fork ())
{
case 0: /*child becomes the server */
oflags['c'] = 0;
oflags['H'] = 0;
+
+ if (csnok)
+ close (csnok_pipe[0]);
break;
case -1:
fatal_moan ("fork failed");
- default:
+ default: /*parent becomes client*/
oflags['s'] = 0;
oflags['K'] = 0;
oflags['d'] = 0;
oflags['L'] = 0;
oflags['n'] = 0;
oflags['w'] = 0;
- if (server_socket)
+
+ /*Collect the child*/
+ waitpid (pid, NULL, 0);
+
+ /*if there was no k argument we need to find the*/
+ /*pid of the server process so that we can work out*/
+ /*what the socket is called. The server tells us on*/
+ /*a pipe*/
+
+ if (csnok)
{
- socket_free_parent (server_socket);
- server_socket = NULL;
+ close (csnok_pipe[1]);
+
+ if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid))
+ fatal_moan ("Failed to receive pid of server process");
+
+ close (csnok_pipe[0]);
+
+ oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid);
+ oflags['k']++;
}
}
}
if (oflags['s'] && !oflags['F'])
{
- daemon (1, 0); /*incase socket is relative path, unlink then will fail */
+ /*nochdir incase socket is relative path, unlink then will fail */
+ daemon (1, 0);
+
+ /*Tell our parent's parent what our pid is */
+ if (csnok)
+ {
+ pid = getpid ();
+
+ write (csnok_pipe[1], &pid, sizeof (pid));
+ close (csnok_pipe[1]);
+ }
}
+ if (oflags['s'] )
+ {
+ char *path;
+ path = mome ("/.sympathy");
+ mkdir (path, 0700);
+ free (path);
+
+
+ if (!oflags['k']) {
+ pid = getpid ();
+
+ oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid);
+ oflags['k']++;
+ }
+
+ server_socket = socket_listen (oargs['k']);
+ if (!server_socket)
+ fatal_moan ("failed to create socket %s for listening", oargs['k']);
+
+ }
+
if (oflags['s'] || oflags['t'])
{
/*
* $Log$
+ * Revision 1.36 2008/02/28 22:00:42 james
+ * *** empty log message ***
+ *
* Revision 1.35 2008/02/28 16:57:51 james
* *** empty log message ***
*
ansi_move (a, p);
}
+
+int ansi_key(ANSI *a,Context *c,int key)
+{
+
+ if (!c->d)
+ return c->k->key (c->k, c, key);
+
+ cmd_show_status (c->d, c);
+
+ if (c->d->active)
+ return cmd_key (c->d, c,a, key);
+
+ if (key == CMD_KEY)
+ return cmd_activate (c->d, c);
+
+
+ return c->k->key (c->k, c, key);
+}
+
+
static void
ansi_flush_escape (ANSI * a, Context * c)
{
for (i = 0; i < p->escape_ptr; ++i)
{
- keydis_key (c->k, c, p->escape_buf[i]);
+ ansi_key (a, c, p->escape_buf[i]);
}
p->escape_ptr = 0;
if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
{
- keydis_key (c->k, c, KEY_UP + (p->escape_buf[2] - 'A'));
+ ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A'));
}
else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
{
- keydis_key (c->k, c, KEY_154 + (p->escape_buf[2] - 'a'));
+ ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a'));
}
else
{
}
if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
{
- keydis_key (c->k, c, KEY_180 + (p->escape_buf[2] - '0'));
+ ansi_key (a, c, KEY_180 + (p->escape_buf[2] - '0'));
}
else
{
}
else
{
- keydis_key (c->k, c, ch);
+ ansi_key (a, c, ch);
}
}
/*
* $Log$
+ * Revision 1.7 2008/02/28 22:00:42 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/28 16:57:51 james
* *** empty log message ***
*
int
-cmd_parse (Cmd * c, Context * ctx, char *buf)
+cmd_parse (Cmd * c, Context * ctx,ANSI *a, char *buf)
{
if (!strcmp (buf, "quit"))
c->disconnect++;
ctx->k->hangup (ctx->k, ctx);
else if (!strcmp (buf, "reset"))
ctx->k->reset (ctx->k, ctx);
+ else if (!strcmp (buf, "expand")) {
+ int w=a->terminal->size.x;
+ int h=a->terminal->size.y-1;
+ ctx->k->set_size (ctx->k, ctx, w,h);
+ }
else if (!strncmp (buf, "width", 5))
ctx->k->set_size (ctx->k, ctx, atoi (buf + 5), 0);
else if (!strncmp (buf, "height", 6))
}
int
-cmd_key (Cmd * c, Context * ctx, int key)
+cmd_key (Cmd * c, Context * ctx,ANSI *a, int key)
{
if (c->error)
if (key == 13)
{
- if (cmd_parse (c, ctx, c->buf + 1))
+ if (cmd_parse (c, ctx, a,c->buf + 1))
{
c->error++;
}
/*
* $Log$
+ * Revision 1.9 2008/02/28 22:00:42 james
+ * *** empty log message ***
+ *
* Revision 1.8 2008/02/28 16:57:52 james
* *** empty log message ***
*
+#if 0
int
keydis_key (KeyDis * t, Context * c, int key)
{
return t->key (t, c, key);
}
+#endif
/* ansi.c */
+extern int ansi_key(ANSI *a, Context *c, int key);
extern int ansi_dispatch(ANSI *a, Context *c);
extern ANSI *ansi_new_from_terminal(TTY *t, int utf8);
/* crt.c */
extern void tty_send_break(TTY *t);
extern void tty_set_flow(TTY *t, int flow);
extern void tty_hangup(TTY *t);
+extern void tty_length(TTY *t, int l);
extern void tty_winch(TTY *t, CRT_Pos size);
extern void tty_parse_reset(Context *c);
extern void tty_analyse(Context *c);
/* keydis.c */
extern KeyDis *keydis_vt102_new(void);
extern KeyDis *keydis_ipc_new(Socket *s);
-extern int keydis_key(KeyDis *t, Context *c, int key);
/* history.c */
extern History *history_new(int n);
extern void history_free(History *h);
/* serial.c */
extern TTY *serial_open(char *path, int lock_mode);
/* cmd.c */
-extern int cmd_parse(Cmd *c, Context *ctx, char *buf);
+extern int cmd_parse(Cmd *c, Context *ctx, ANSI *a, char *buf);
extern void cmd_show_status(Cmd *c, Context *ctx);
-extern int cmd_key(Cmd *c, Context *ctx, int key);
extern int cmd_activate(Cmd *c, Context *ctx);
extern void cmd_new_status(Cmd *c, Context *ctx, char *msg);
extern Cmd *cmd_new(void);
that logging to \fIstdout\fP only makes sense with the \-\fBF\fP \fIserver_option\fP.
.TP 5
.B \-w \fIwidth\fP[x\fIheight\fP]
-set the initialise size of the terminal emulator's frame buffer to be \fIwidth\fP columns
+set the initial size of the terminal emulator's frame buffer to be \fIwidth\fP columns
by \fIheight\fP rows. If \fIheight\fP is omitted it defaults to 24, the default width
is 80. These values may
be overridden later by terminal escape sequences. If \-\fBp\fP is also specified
.B reset
reset the terminal emulator
.TP 7
+.B expand
+expand the size of the screen to fit the size of the current outer terminal emulator window
+.TP 7
.B quit
exit this instance of sympathy (disconnect from the server if present)
.SH CHARACTER ENCODINGS
0baf4bcc06f0271dba444738df2ef1e3 1.1.6
30b3685c955c05efa7ba0affb9fbca1a 1.1.7
b9ef98229248516850808e590721c0e5 1.1.8
+a5ee6f647e6d98d5f06b75a70b7bf9a5 1.1.9
0baf4bcc06f0271dba444738df2ef1e3 "February 28, 2008"
30b3685c955c05efa7ba0affb9fbca1a "February 28, 2008"
b9ef98229248516850808e590721c0e5 "February 28, 2008"
+a5ee6f647e6d98d5f06b75a70b7bf9a5 "February 28, 2008"