summaryrefslogtreecommitdiffstats
path: root/firmware/logf.c
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2008-12-31 17:01:00 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2008-12-31 17:01:00 +0000
commit4c793febc8c4c828ab2bb7d7de3c37b05ac0cac2 (patch)
treed3804830e5ed45b93481c3111582bc42936f7772 /firmware/logf.c
parentd6def79dca7ed686196b860c9b160d1d0cbf93c5 (diff)
downloadrockbox-4c793febc8c4c828ab2bb7d7de3c37b05ac0cac2.tar.gz
rockbox-4c793febc8c4c828ab2bb7d7de3c37b05ac0cac2.tar.bz2
rockbox-4c793febc8c4c828ab2bb7d7de3c37b05ac0cac2.zip
Commit FS#9733 (multiline logf) by Yoshihisa Uchida
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19625 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/logf.c')
-rw-r--r--firmware/logf.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/firmware/logf.c b/firmware/logf.c
index 9599547907..539c2af9da 100644
--- a/firmware/logf.c
+++ b/firmware/logf.c
@@ -20,10 +20,23 @@
****************************************************************************/
/*
- * logf() logs MAX_LOGF_ENTRY (21) bytes per entry in a circular buffer. Each
+ * logf() logs MAX_LOGF_ENTRY (29) bytes per entry in a circular buffer. Each
* logged string is space- padded for easier and faster output on screen. Just
* output MAX_LOGF_ENTRY characters on each line. MAX_LOGF_ENTRY bytes fit
* nicely on the iRiver remote LCD (128 pixels with an 8x6 pixels font).
+ *
+ * When the length of log exceeds MAX_LOGF_ENTRY bytes, dividing into the
+ * string of length is MAX_LOGF_ENTRY-1 bytes.
+ *
+ * logfbuffer[*]:
+ *
+ * |<- MAX_LOGF_ENTRY bytes ->|1|
+ * | log data area |T|
+ *
+ * T : log terminate flag
+ * == LOGF_TERMINATE_ONE_LINE(0x00) : log data end (one line)
+ * == LOGF_TERMINATE_CONTINUE_LINE(0x01) : log data continues
+ * == LOGF_TERMINATE_MULTI_LINE(0x02) : log data end (multi line)
*/
#include <string.h>
@@ -43,7 +56,7 @@
#ifdef ROCKBOX_HAS_LOGF
#ifndef __PCTOOL__
-unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
+unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY+1];
int logfindex;
bool logfwrap;
#endif
@@ -84,6 +97,15 @@ static void displayremote(void)
#define displayremote()
#endif
+static void check_logfindex(void)
+{
+ if(logfindex >= MAX_LOGF_LINES) {
+ /* wrap */
+ logfwrap = true;
+ logfindex = 0;
+ }
+}
+
#ifdef __PCTOOL__
void _logf(const char *format, ...)
{
@@ -98,17 +120,17 @@ void _logf(const char *format, ...)
void _logf(const char *format, ...)
{
int len;
+ int tlen;
+ unsigned char buf[MAX_LOGF_ONE_LINE_SIZE];
unsigned char *ptr;
va_list ap;
+ bool multiline = false;
+
va_start(ap, format);
+ vsnprintf(buf, MAX_LOGF_ONE_LINE_SIZE, format, ap);
+ va_end(ap);
- if(logfindex >= MAX_LOGF_LINES) {
- /* wrap */
- logfwrap = true;
- logfindex = 0;
- }
- ptr = logfbuffer[logfindex];
- len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap);
+ len = strlen(buf);
#ifdef HAVE_SERIAL
serial_tx(ptr);
serial_tx("\r\n");
@@ -118,10 +140,26 @@ void _logf(const char *format, ...)
usb_serial_send("\r\n",2);
#endif
- va_end(ap);
+ tlen = 0;
+ check_logfindex();
+ while(len > MAX_LOGF_ENTRY)
+ {
+ ptr = logfbuffer[logfindex];
+ strncpy(ptr, buf + tlen, MAX_LOGF_ENTRY);
+ ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE;
+ logfindex++;
+ check_logfindex();
+ len -= MAX_LOGF_ENTRY;
+ tlen += MAX_LOGF_ENTRY;
+ multiline = true;
+ }
+ ptr = logfbuffer[logfindex];
+ strcpy(ptr, buf + tlen);
+
if(len < MAX_LOGF_ENTRY)
/* pad with spaces up to the MAX_LOGF_ENTRY byte border */
memset(ptr+len, ' ', MAX_LOGF_ENTRY-len);
+ ptr[MAX_LOGF_ENTRY] = (multiline)?LOGF_TERMINATE_MULTI_LINE:LOGF_TERMINATE_ONE_LINE;
logfindex++; /* leave it where we write the next time */