aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/sympathy.c11
-rw-r--r--src/context.h4
-rw-r--r--src/log.c74
-rw-r--r--src/log.h4
-rw-r--r--src/tty.c5
-rw-r--r--src/utf8.c8
-rw-r--r--src/vt102.c7
7 files changed, 101 insertions, 12 deletions
diff --git a/apps/sympathy.c b/apps/sympathy.c
index dc79ed0..92ee3e1 100644
--- a/apps/sympathy.c
+++ b/apps/sympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.52 2010/07/27 14:49:34 james
+ * add support for byte logging
+ *
* Revision 1.51 2010/07/16 11:04:10 james
* ignore tedious return values
*
@@ -553,7 +556,7 @@ main (int argc, char *argv[])
memset (oflags, 0, sizeof (oflags));
memset (oargs, 0, sizeof (oargs));
- while ((c = getopt (argc, argv, "I:NCSRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF)
+ while ((c = getopt (argc, argv, "BI:NCSRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF)
{
switch (c)
{
@@ -691,6 +694,7 @@ main (int argc, char *argv[])
oflags['f'] = 0;
oflags['L'] = 0;
oflags['R'] = 0;
+ oflags['B'] = 0;
oflags['P'] = 0;
oflags['n'] = 0;
oflags['w'] = 0;
@@ -729,9 +733,9 @@ main (int argc, char *argv[])
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'])
+ || oflags['L'] || oflags['R'] || oflags['B'] || oflags['P']) && oflags['c'])
fatal_moan
- ("-c or -r are incompatible with -p, -d, -K, -b, -f, -R, -P or -L");
+ ("-c or -r are incompatible with -p, -d, -K, -b, -f, -R, -P, -B or -L");
if (oflags['C'] && (!oflags['d']))
fatal_moan ("-C requires -d");
@@ -826,6 +830,7 @@ main (int argc, char *argv[])
if (oflags['L'])
{
ctx->l = file_log_new (oargs['L'], oflags['R']);
+ ctx->byte_logging=oflags['B'];
if (!ctx->l)
fatal_moan ("unable to access log file %s", oargs['L']);
}
diff --git a/src/context.h b/src/context.h
index a1ce8d2..affa883 100644
--- a/src/context.h
+++ b/src/context.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.14 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.13 2008/03/10 11:49:32 james
* *** empty log message ***
*
@@ -66,6 +69,7 @@ typedef struct Context_struct {
Cmd *d;
UTF8 *u;
RX *r;
+ int byte_logging;
} Context;
#endif /* __CONTEXT_H__ */
diff --git a/src/log.c b/src/log.c
index 19e7c81..c311ddf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.16 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.15 2010/07/16 11:04:10 james
* ignore tedious return values
*
@@ -65,6 +68,7 @@ typedef struct {
int rotate;
FILE *fp;
char *filename;
+ int needs_newline;
} File_Log;
@@ -116,6 +120,18 @@ log_remove (Log * l)
*ptr = l->next;
}
+static void flog_newline(Log *_l,int force)
+{
+ File_Log *l = (File_Log *) _l;
+
+ if (force || !l->needs_newline) return;
+
+ l->needs_newline=0;
+
+ fputc ('\n', l->fp);
+ fflush (l->fp);
+}
+
static void
flog_sighup (Log * _l)
@@ -131,9 +147,8 @@ flog_sighup (Log * _l)
log_f (_l, "<sighup received - opening log file>");
}
-
-static void
-flog_log (Log * _l, char *buf)
+static void
+flog_emit_stamp(Log *_l)
{
File_Log *l = (File_Log *) _l;
struct timeval tv = { 0 };
@@ -150,16 +165,20 @@ flog_log (Log * _l, char *buf)
if (!l->fp)
return;
+ flog_newline(_l,0);
+
gettimeofday (&tv, NULL);
t = tv.tv_sec;
tm = localtime (&t);
fprintf (l->fp, "%s %2d %02d:%02d:%02d ", months[tm->tm_mon],
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+}
- fputs (buf, l->fp);
- fputc ('\n', l->fp);
- fflush (l->fp);
+
+static void flog_check_rotate(Log *_l)
+{
+ File_Log *l = (File_Log *) _l;
if (l->rotate && rotate_check (l->filename)) {
fclose (l->fp);
@@ -169,6 +188,46 @@ flog_log (Log * _l, char *buf)
}
+static void
+flog_log_bytes (Log * _l, void *_buf,int len)
+{
+ File_Log *l = (File_Log *) _l;
+ uint8_t *buf=(uint8_t *) _buf;
+
+ if (!l->fp)
+ return;
+
+ while (len--) {
+ if (*buf=='\n') {
+ flog_newline(_l,1);
+ flog_check_rotate(_l);
+ flog_emit_stamp(_l);
+ } else {
+ l->needs_newline++;
+ fputc (*buf, l->fp);
+ }
+ buf++;
+ }
+}
+
+static void
+flog_log (Log * _l, char *buf)
+{
+ File_Log *l = (File_Log *) _l;
+
+ if (!l->fp)
+ return;
+
+ flog_emit_stamp(_l);
+
+ fputs (buf, l->fp);
+ fputc ('\n', l->fp);
+ fflush (l->fp);
+
+ flog_check_rotate(_l);
+}
+
+
static void
@@ -204,11 +263,14 @@ file_log_new (char *fn, int rotate)
l->log = flog_log;
+ l->log_bytes = flog_log_bytes;
l->close = flog_close;
l->do_close = dc;
l->rotate = rotate;
l->filename = strdup (fn);
+ l->needs_newline=0;
+
fput_cp (l->fp, 0xffef);
log_add ((Log *) l);
diff --git a/src/log.h b/src/log.h
index 81a95c4..ed0f6cb 100644
--- a/src/log.h
+++ b/src/log.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.7 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.6 2008/03/10 11:49:33 james
* *** empty log message ***
*
@@ -38,6 +41,7 @@
#define LOG_SIGNATURE \
struct Log_struct *next; \
void (*log)(struct Log_struct *,char *); \
+ void (*log_bytes)(struct Log_struct *,void *,int); \
void (*sighup)(struct Log_struct *); \
void (*close)(struct Log_struct *)
diff --git a/src/tty.c b/src/tty.c
index 86551d1..505e70c 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.27 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.26 2008/03/10 11:49:33 james
* *** empty log message ***
*
@@ -493,7 +496,7 @@ tty_analyse (Context * c)
p->guessed_baud = -1;
} else {
- if (i > 0)
+ if (i > 0 && j > 0)
p->guessed_baud = i / j;
else
p->guessed_baud = 0;
diff --git a/src/utf8.c b/src/utf8.c
index f909666..d4c9248 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.16 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.15 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -108,6 +111,11 @@ utf8_parse (Context * c, uint32_t ch)
return err;
}
+ if (c->l && c->byte_logging) {
+ uint8_t ch8=(uint8_t) ch;
+ c->l->log_bytes(c->l,&ch8,1);
+ }
+
if (!u->in_utf8) {
/* FIXME: for the moment we bodge utf8 support - need to do */
/* L->R and R->L and double width characters */
diff --git a/src/vt102.c b/src/vt102.c
index 14a8327..b82556f 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.67 2010/07/27 14:49:35 james
+ * add support for byte logging
+ *
* Revision 1.66 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -443,10 +446,9 @@ vt102_log_line (Context * c, int line)
CRT_Pos p = { 0, line };
char logbuf[4 * (VT102_MAX_COLS + 1)], *logptr = logbuf;
- if (!c->l)
+ if (!c->l || c->byte_logging)
return;
-
for (; e.x > 0; --e.x) {
if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
break;
@@ -1657,6 +1659,7 @@ vt102_parse_char (Context * c, int ch)
p->cmd_termination, v->pos.x, v->pos.y, v->pending_wrap);
#endif
+
if (ch == SYM_CHAR_RESET) {
vt102_reset_state (c);
} else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination)) {