Revert the recent change to bufread()
[Rockbox.git] / apps / logfdisp.c
blobaa84bf0f1bf8b2f62a59f542cc67a0f773b9d5ec
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"
34 #ifdef HAVE_LCD_BITMAP
35 bool logfdisplay(void)
38 int w, h;
39 int lines;
40 int columns;
41 int i;
43 bool lcd = false; /* fixed atm */
44 int index;
46 lcd_getstringsize("A", &w, &h);
47 lines = (lcd?
48 #ifdef HAVE_REMOTE_LCD
49 LCD_REMOTE_HEIGHT
50 #else
52 #endif
53 :LCD_HEIGHT)/h;
54 columns = (lcd?
55 #ifdef HAVE_REMOTE_LCD
56 LCD_REMOTE_WIDTH
57 #else
59 #endif
60 :LCD_WIDTH)/w;
62 if (columns > MAX_LOGF_ENTRY)
63 columns = MAX_LOGF_ENTRY;
65 if(!lines)
66 return false;
68 lcd_setmargins(0, 0);
69 lcd_clear_display();
71 do {
72 index = logfindex;
73 for(i = lines-1; i>=0; i--) {
74 unsigned char buffer[columns + 1];
76 if(--index < 0) {
77 if(logfwrap)
78 index = MAX_LOGF_LINES-1;
79 else
80 break; /* done */
83 memcpy(buffer, logfbuffer[index], columns);
84 buffer[columns]=0;
85 lcd_puts(0, i, buffer);
87 lcd_update();
88 } while(!action_userabort(HZ));
90 return false;
92 #else /* HAVE_LCD_BITMAP */
93 bool logfdisplay(void)
96 /* TODO: implement a browser for charcell bitmaps */
97 return false;
99 #endif /* HAVE_LCD_BITMAP */
101 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
102 * entries will be "reversed" so that the most recently logged entry is on the
103 * top of the file */
104 bool logfdump(void)
106 int fd;
108 if(!logfindex && !logfwrap)
109 /* nothing is logged just yet */
110 return false;
112 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
113 if(-1 != fd) {
114 unsigned char buffer[MAX_LOGF_ENTRY +1];
115 int index = logfindex-1;
116 int stop = logfindex;
119 while(index != stop) {
120 if(index < 0) {
121 if(logfwrap)
122 index = MAX_LOGF_LINES-1;
123 else
124 break; /* done */
127 memcpy(buffer, logfbuffer[index], MAX_LOGF_ENTRY);
128 buffer[MAX_LOGF_ENTRY]=0;
129 fdprintf(fd, "%s\n", buffer);
130 index--;
132 close(fd);
134 return false;
137 #endif /* ROCKBOX_HAS_LOGF */