Rename variables sectorbuf and verbose to avoid clashes in rbutil. Cleanup exports...
[Rockbox.git] / apps / logfdisp.c
blob4a5ab43089083b5fba974a2e88e98f942bd6a3df
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"
32 #include "settings.h"
33 #include "logfdisp.h"
35 #ifdef HAVE_LCD_BITMAP
36 bool logfdisplay(void)
39 int w, h;
40 int lines;
41 int columns;
42 int i;
44 bool lcd = false; /* fixed atm */
45 int index;
47 lcd_getstringsize("A", &w, &h);
48 lines = (lcd?
49 #ifdef HAVE_REMOTE_LCD
50 LCD_REMOTE_HEIGHT
51 #else
53 #endif
54 :LCD_HEIGHT)/h;
55 columns = (lcd?
56 #ifdef HAVE_REMOTE_LCD
57 LCD_REMOTE_WIDTH
58 #else
60 #endif
61 :LCD_WIDTH)/w;
63 if (columns > MAX_LOGF_ENTRY)
64 columns = MAX_LOGF_ENTRY;
66 if(!lines)
67 return false;
69 lcd_setmargins(0, 0);
70 lcd_clear_display();
72 do {
73 index = logfindex;
74 for(i = lines-1; i>=0; i--) {
75 unsigned char buffer[columns + 1];
77 if(--index < 0) {
78 if(logfwrap)
79 index = MAX_LOGF_LINES-1;
80 else
81 break; /* done */
84 memcpy(buffer, logfbuffer[index], columns);
85 buffer[columns]=0;
86 lcd_puts(0, i, buffer);
88 lcd_update();
89 } while(!action_userabort(HZ));
91 return false;
93 #else /* HAVE_LCD_BITMAP */
94 bool logfdisplay(void)
97 /* TODO: implement a browser for charcell bitmaps */
98 return false;
100 #endif /* HAVE_LCD_BITMAP */
102 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
103 * entries will be "reversed" so that the most recently logged entry is on the
104 * top of the file */
105 bool logfdump(void)
107 int fd;
109 if(!logfindex && !logfwrap)
110 /* nothing is logged just yet */
111 return false;
113 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
114 if(-1 != fd) {
115 unsigned char buffer[MAX_LOGF_ENTRY +1];
116 int index = logfindex-1;
117 int stop = logfindex;
120 while(index != stop) {
121 if(index < 0) {
122 if(logfwrap)
123 index = MAX_LOGF_LINES-1;
124 else
125 break; /* done */
128 memcpy(buffer, logfbuffer[index], MAX_LOGF_ENTRY);
129 buffer[MAX_LOGF_ENTRY]=0;
130 fdprintf(fd, "%s\n", buffer);
131 index--;
133 close(fd);
135 return false;
138 #endif /* ROCKBOX_HAS_LOGF */