FS#6948 - Fix the broken 'follow playlist' feature
[Rockbox.git] / apps / logfdisp.c
blob734a6aec63bf365670a46b28e074a26211b00070
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #ifdef ROCKBOX_HAS_LOGF
22 #include <file.h>
23 #include <sprintf.h>
24 #include <timefuncs.h>
25 #include <string.h>
26 #include <kernel.h>
27 #include <action.h>
29 #include <lcd.h>
30 #include "menu.h"
31 #include "logf.h"
33 #ifdef HAVE_LCD_BITMAP
34 bool logfdisplay(void)
37 int w, h;
38 int lines;
39 int columns;
40 int i;
42 bool lcd = false; /* fixed atm */
43 int index;
45 lcd_getstringsize("A", &w, &h);
46 lines = (lcd?
47 #ifdef HAVE_REMOTE_LCD
48 LCD_REMOTE_HEIGHT
49 #else
51 #endif
52 :LCD_HEIGHT)/h;
53 columns = (lcd?
54 #ifdef HAVE_REMOTE_LCD
55 LCD_REMOTE_WIDTH
56 #else
58 #endif
59 :LCD_WIDTH)/w;
61 if (columns > MAX_LOGF_ENTRY)
62 columns = MAX_LOGF_ENTRY;
64 if(!lines)
65 return false;
67 lcd_setmargins(0, 0);
68 lcd_clear_display();
70 do {
71 index = logfindex;
72 for(i = lines-1; i>=0; i--) {
73 unsigned char buffer[columns + 1];
75 if(--index < 0) {
76 if(logfwrap)
77 index = MAX_LOGF_LINES-1;
78 else
79 break; /* done */
82 memcpy(buffer, logfbuffer[index], columns);
83 buffer[columns]=0;
84 lcd_puts(0, i, buffer);
86 lcd_update();
87 } while(!action_userabort(HZ));
89 return false;
91 #else /* HAVE_LCD_BITMAP */
92 bool logfdisplay(void)
95 /* TODO: implement a browser for charcell bitmaps */
96 return false;
98 #endif /* HAVE_LCD_BITMAP */
100 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
101 * entries will be "reversed" so that the most recently logged entry is on the
102 * top of the file */
103 bool logfdump(void)
105 int fd;
107 if(!logfindex && !logfwrap)
108 /* nothing is logged just yet */
109 return false;
111 fd = open("/.rockbox/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
112 if(-1 != fd) {
113 unsigned char buffer[MAX_LOGF_ENTRY +1];
114 int index = logfindex-1;
115 int stop = logfindex;
118 while(index != stop) {
119 if(index < 0) {
120 if(logfwrap)
121 index = MAX_LOGF_LINES-1;
122 else
123 break; /* done */
126 memcpy(buffer, logfbuffer[index], MAX_LOGF_ENTRY);
127 buffer[MAX_LOGF_ENTRY]=0;
128 fdprintf(fd, "%s\n", buffer);
129 index--;
131 close(fd);
133 return false;
136 #endif /* ROCKBOX_HAS_LOGF */