diff options
| author | james <> | 2010-07-27 14:49:35 +0000 | 
|---|---|---|
| committer | james <> | 2010-07-27 14:49:35 +0000 | 
| commit | 789f759f4cea382053851669bb7076d9a990a2cd (patch) | |
| tree | 26776194e6b4ce257e526876a2a0518844a9a258 /src | |
| parent | 6faf91bb7c43b69f7132f76bc520e60e8b8677c6 (diff) | |
| download | sympathy-789f759f4cea382053851669bb7076d9a990a2cd.tar.gz sympathy-789f759f4cea382053851669bb7076d9a990a2cd.tar.bz2 sympathy-789f759f4cea382053851669bb7076d9a990a2cd.zip | |
add support for byte logging
Diffstat (limited to 'src')
| -rw-r--r-- | src/context.h | 4 | ||||
| -rw-r--r-- | src/log.c | 74 | ||||
| -rw-r--r-- | src/log.h | 4 | ||||
| -rw-r--r-- | src/tty.c | 5 | ||||
| -rw-r--r-- | src/utf8.c | 8 | ||||
| -rw-r--r-- | src/vt102.c | 7 | 
6 files changed, 93 insertions, 9 deletions
| 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__ */ @@ -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); @@ -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 *) @@ -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; @@ -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)) { | 
