2005-05-23 22:47:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Daniel Stenberg
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-05-23 22:47:42 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2009-08-21 22:54:23 +00:00
|
|
|
* logf() logs entries in a circular buffer. Each logged string is null-terminated.
|
2008-12-31 17:01:00 +00:00
|
|
|
*
|
2009-08-21 22:54:23 +00:00
|
|
|
* When the length of log exceeds MAX_LOGF_SIZE bytes, the buffer wraps.
|
2008-12-31 17:01:00 +00:00
|
|
|
*
|
2005-05-23 22:47:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "config.h"
|
2010-05-06 22:17:34 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "font.h"
|
2014-01-05 21:20:26 +00:00
|
|
|
#include "lcd.h"
|
2012-01-07 19:54:47 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2005-05-24 14:28:48 +00:00
|
|
|
#include "lcd-remote.h"
|
2012-01-07 19:54:47 +00:00
|
|
|
#endif
|
2005-05-24 14:26:54 +00:00
|
|
|
#include "logf.h"
|
2006-10-12 20:22:16 +00:00
|
|
|
#include "serial.h"
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
#include "vuprintf.h"
|
2005-05-23 22:47:42 +00:00
|
|
|
|
2008-03-02 20:45:33 +00:00
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
#include "usb_core.h"
|
|
|
|
#include "usbstack/usb_serial.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-04 01:45:29 +00:00
|
|
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
|
|
|
#include "logdiskf.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "rbpaths.h"
|
|
|
|
#include "ata_idle_notify.h"
|
|
|
|
|
|
|
|
unsigned char logdiskfbuffer[MAX_LOGDISKF_SIZE];
|
2015-01-11 17:02:43 +00:00
|
|
|
static int logdiskfindex;
|
2012-07-04 01:45:29 +00:00
|
|
|
#endif
|
|
|
|
|
2005-05-30 13:00:43 +00:00
|
|
|
/* Only provide all this if asked to */
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifndef __PCTOOL__
|
2009-08-21 22:54:23 +00:00
|
|
|
unsigned char logfbuffer[MAX_LOGF_SIZE];
|
2005-05-24 14:01:16 +00:00
|
|
|
int logfindex;
|
2005-05-23 22:47:42 +00:00
|
|
|
bool logfwrap;
|
2016-03-31 11:33:11 +00:00
|
|
|
bool logfenabled = true;
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2005-05-23 22:47:42 +00:00
|
|
|
|
2005-05-24 14:26:54 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
static void displayremote(void)
|
|
|
|
{
|
|
|
|
/* TODO: we should have a debug option that enables/disables this! */
|
2009-08-21 22:54:23 +00:00
|
|
|
int w, h, i;
|
|
|
|
int fontnr;
|
|
|
|
int cur_x, cur_y, delta_y, delta_x;
|
|
|
|
struct font* font;
|
|
|
|
int nb_lines;
|
|
|
|
char buf[2];
|
|
|
|
/* Memorize the pointer to the beginning of the last ... lines
|
|
|
|
I assume delta_y >= 6 to avoid wasting memory and allocating memory dynamically
|
|
|
|
I hope there is no font with height < 6 ! */
|
|
|
|
const int NB_ENTRIES=LCD_REMOTE_HEIGHT / 6;
|
|
|
|
int line_start_ptr[NB_ENTRIES];
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
fontnr = lcd_getfont();
|
|
|
|
font = font_get(fontnr);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
/* get the horizontal size of each line */
|
|
|
|
font_getstringsize("A", NULL, &delta_y, fontnr);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
/* font too small ? */
|
|
|
|
if(delta_y < 6)
|
|
|
|
return;
|
|
|
|
/* nothing to print ? */
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
|
|
|
return;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
w = LCD_REMOTE_WIDTH;
|
|
|
|
h = LCD_REMOTE_HEIGHT;
|
|
|
|
nb_lines = 0;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(logfwrap)
|
|
|
|
i = logfindex;
|
|
|
|
else
|
|
|
|
i = 0;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
cur_x = 0;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
line_start_ptr[0] = i;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
line_start_ptr[++nb_lines % NB_ENTRIES] = i+1;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
cur_x = 0;
|
|
|
|
line_start_ptr[++nb_lines % NB_ENTRIES] = i;
|
|
|
|
}
|
|
|
|
/* update pointer */
|
|
|
|
cur_x += delta_x;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2005-05-24 14:26:54 +00:00
|
|
|
lcd_remote_clear_display();
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
i = line_start_ptr[ MAX(nb_lines - h / delta_y, 0) % NB_ENTRIES];
|
|
|
|
cur_x = 0;
|
|
|
|
cur_y = 0;
|
|
|
|
buf[1] = '\0';
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
do {
|
|
|
|
if(logfbuffer[i] == '\0')
|
|
|
|
{
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* does character fit on this line ? */
|
|
|
|
delta_x = font_get_width(font, logfbuffer[i]);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(cur_x + delta_x > w)
|
|
|
|
{
|
|
|
|
cur_y += delta_y;
|
|
|
|
cur_x = 0;
|
|
|
|
}
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
buf[0] = logfbuffer[i];
|
|
|
|
lcd_remote_putsxy(cur_x, cur_y, buf);
|
|
|
|
cur_x += delta_x;
|
2005-05-24 14:26:54 +00:00
|
|
|
}
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
i++;
|
|
|
|
if(i >= MAX_LOGF_SIZE)
|
|
|
|
i = 0;
|
|
|
|
} while(i != logfindex);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
|
|
|
lcd_remote_update();
|
2005-05-24 14:26:54 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define displayremote()
|
|
|
|
#endif
|
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
#ifdef __PCTOOL__
|
|
|
|
void _logf(const char *format, ...)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2006-11-10 08:03:33 +00:00
|
|
|
vsnprintf(buf, sizeof buf, format, ap);
|
|
|
|
printf("DEBUG: %s\n", buf);
|
|
|
|
}
|
|
|
|
#else
|
2009-02-07 19:59:51 +00:00
|
|
|
static void check_logfindex(void)
|
|
|
|
{
|
2012-07-04 01:45:29 +00:00
|
|
|
if(logfindex >= MAX_LOGF_SIZE)
|
2009-08-21 22:54:23 +00:00
|
|
|
{
|
2009-02-07 19:59:51 +00:00
|
|
|
/* wrap */
|
|
|
|
logfwrap = true;
|
|
|
|
logfindex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
static int logf_push(void *userp, int c)
|
2005-05-23 22:47:42 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
(void)userp;
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
logfbuffer[logfindex++] = c;
|
|
|
|
check_logfindex();
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2011-09-09 10:28:36 +00:00
|
|
|
#if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL)
|
2009-08-21 22:54:23 +00:00
|
|
|
if(c != '\0')
|
|
|
|
{
|
|
|
|
char buf[2];
|
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
|
|
|
serial_tx(buf);
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-04 01:45:29 +00:00
|
|
|
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
return 1;
|
2009-08-21 22:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _logf(const char *fmt, ...)
|
|
|
|
{
|
2016-03-31 11:33:11 +00:00
|
|
|
if (!logfenabled)
|
|
|
|
return;
|
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
#ifdef USB_ENABLE_SERIAL
|
|
|
|
int old_logfindex = logfindex;
|
|
|
|
#endif
|
2005-05-23 22:47:42 +00:00
|
|
|
va_list ap;
|
2008-12-31 17:01:00 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
va_start(ap, fmt);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2010-06-21 16:53:00 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
|
2009-11-02 15:30:06 +00:00
|
|
|
char buf[1024];
|
|
|
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
|
|
|
DEBUGF("%s\n", buf);
|
2010-08-02 09:10:35 +00:00
|
|
|
/* restart va_list otherwise the result if undefined when vuprintf is called */
|
|
|
|
va_end(ap);
|
|
|
|
va_start(ap, fmt);
|
2009-11-02 15:30:06 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-03 21:20:09 +00:00
|
|
|
vuprintf(logf_push, NULL, fmt, ap);
|
2008-12-31 17:01:00 +00:00
|
|
|
va_end(ap);
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
/* add trailing zero */
|
|
|
|
logf_push(NULL, '\0');
|
2012-07-04 01:45:29 +00:00
|
|
|
|
2011-09-09 10:28:36 +00:00
|
|
|
#if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL)
|
2006-10-12 20:22:16 +00:00
|
|
|
serial_tx("\r\n");
|
|
|
|
#endif
|
2009-05-23 14:30:20 +00:00
|
|
|
#ifdef USB_ENABLE_SERIAL
|
2008-03-02 20:45:33 +00:00
|
|
|
|
2009-08-21 22:54:23 +00:00
|
|
|
if(logfindex < old_logfindex)
|
2008-12-31 17:01:00 +00:00
|
|
|
{
|
2009-08-21 22:54:23 +00:00
|
|
|
usb_serial_send(logfbuffer + old_logfindex, MAX_LOGF_SIZE - old_logfindex);
|
|
|
|
usb_serial_send(logfbuffer, logfindex - 1);
|
2008-12-31 17:01:00 +00:00
|
|
|
}
|
2009-08-21 22:54:23 +00:00
|
|
|
else
|
|
|
|
usb_serial_send(logfbuffer + old_logfindex, logfindex - old_logfindex - 1);
|
|
|
|
usb_serial_send("\r\n", 2);
|
2012-07-04 01:45:29 +00:00
|
|
|
#endif
|
2005-05-24 14:26:54 +00:00
|
|
|
|
|
|
|
displayremote();
|
2005-05-23 22:47:42 +00:00
|
|
|
}
|
2006-11-10 08:03:33 +00:00
|
|
|
#endif
|
2005-05-30 13:00:43 +00:00
|
|
|
|
2014-01-05 21:20:26 +00:00
|
|
|
void logf_panic_dump(int *y)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* nothing to print ? */
|
|
|
|
if(logfindex == 0 && !logfwrap)
|
|
|
|
{
|
|
|
|
lcd_puts(1, (*y)++, "no logf data");
|
|
|
|
lcd_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_puts(1, (*y)++, "start of logf data");
|
|
|
|
lcd_update();
|
|
|
|
i = logfindex - 2; /* The last actual characer (i.e. not '\0') */
|
|
|
|
|
|
|
|
while(i >= 0)
|
|
|
|
{
|
|
|
|
while(logfbuffer[i] != 0 && i>=0)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
if(strlen( &logfbuffer[i + 1]) > 0)
|
|
|
|
{
|
|
|
|
lcd_puts(1, (*y)++, &logfbuffer[i + 1]);
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
if(logfwrap)
|
|
|
|
{
|
|
|
|
i = MAX_LOGF_SIZE - 1;
|
|
|
|
while(i >= logfindex)
|
|
|
|
{
|
|
|
|
while(logfbuffer[i] != 0 && i >= logfindex)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
if(strlen( &logfbuffer[i + 1]) > 0)
|
|
|
|
{
|
|
|
|
lcd_putsf(1, (*y)++, "%*s", (MAX_LOGF_SIZE-i) &logfbuffer[i + 1]);
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
lcd_puts(1, (*y)++, "end of logf data");
|
|
|
|
lcd_update();
|
|
|
|
}
|
2005-05-30 13:00:43 +00:00
|
|
|
#endif
|
2012-07-04 01:45:29 +00:00
|
|
|
|
|
|
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
static int logdiskf_push(void *userp, int c)
|
2012-07-04 01:45:29 +00:00
|
|
|
{
|
|
|
|
(void)userp;
|
|
|
|
|
|
|
|
/*just stop logging if out of space*/
|
|
|
|
if(logdiskfindex>=MAX_LOGDISKF_SIZE-1)
|
|
|
|
{
|
|
|
|
strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL");
|
|
|
|
logdiskfindex=MAX_LOGDISKF_SIZE;
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
return 0;
|
2012-07-04 01:45:29 +00:00
|
|
|
}
|
|
|
|
logdiskfbuffer[logdiskfindex++] = c;
|
|
|
|
|
Implement a much more capable vuprintf()
New support as well as some buggy support fixed.
Still no floating point support if ever that would be desired.
Support (*):
* Flags: '-', '+', ' ', '#', '0'
* Width and precision: 'n', '.n', '*' and '.*'
* Length modifiers: 'hh', 'h', 'j', 'l', 'll', 't', 'z'
* Radix: 'c', 'd', 'i', 'n', 'o', 'p/P', 's', 'u', 'x/X'
(*) Provision exists to switch lesser-used stuff on or off or when
certain functionality isn't desired (bootloader?). The compulsory
radixes are everything but 'o', 'n', 'p/P' and 'x/X' with length
modifiers being optional. The default setup is 'l', 'z', 'c', 'd',
'p/P', 's', 'u', 'x/X'.
* Move fdprintf() to its own file. It was in a strange place.
* Make callers compatible and fix a couple snprintf() bugs while
at it.
Could smush it down in size but I'm gonna get over the binsize
neurosis and just the let optimizer do its thing.
Change-Id: Ibdc613a9b6775802c188b29b9dd46c568c94f7c3
2017-09-08 23:28:02 +00:00
|
|
|
return 1;
|
2012-07-04 01:45:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
static void flush_buffer(void);
|
2013-08-16 19:55:09 +00:00
|
|
|
|
2012-07-04 01:45:29 +00:00
|
|
|
void _logdiskf(const char* file, const char level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int len =strlen(file);
|
|
|
|
if(logdiskfindex +len + 4 > MAX_LOGDISKF_SIZE-1)
|
|
|
|
{
|
|
|
|
strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL");
|
|
|
|
logdiskfindex=MAX_LOGDISKF_SIZE;
|
2014-12-20 12:47:28 +00:00
|
|
|
va_end(ap);
|
2012-07-04 01:45:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logdiskf_push(NULL, level);
|
|
|
|
logdiskf_push(NULL, ' ');
|
|
|
|
logdiskf_push(NULL, '[');
|
|
|
|
strcpy(&logdiskfbuffer[logdiskfindex], file);
|
|
|
|
logdiskfindex += len;
|
|
|
|
logdiskf_push(NULL, ']');
|
|
|
|
|
|
|
|
vuprintf(logdiskf_push, NULL, fmt, ap);
|
|
|
|
va_end(ap);
|
2013-08-16 19:55:09 +00:00
|
|
|
register_storage_idle_func(flush_buffer);
|
2012-07-04 01:45:29 +00:00
|
|
|
}
|
2013-08-16 19:55:09 +00:00
|
|
|
|
2014-03-14 22:15:16 +00:00
|
|
|
static void flush_buffer(void)
|
2012-07-04 01:45:29 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
if(logdiskfindex < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fd = open(HOME_DIR"/rockbox_log.txt", O_RDWR | O_CREAT | O_APPEND, 0666);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
write(fd, logdiskfbuffer, logdiskfindex);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
logdiskfindex = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-06 23:18:20 +00:00
|
|
|
#endif
|