Make the mips compiler not complain when bitwise operations do not have parenthesis.
[kugel-rb.git] / apps / logfdisp.c
blobd55b3ba7739bbbdd6faa60740072698286a57c20
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #ifdef ROCKBOX_HAS_LOGF
24 #include <file.h>
25 #include <sprintf.h>
26 #include <timefuncs.h>
27 #include <string.h>
28 #include <kernel.h>
29 #include <action.h>
31 #include <lcd.h>
32 #include "menu.h"
33 #include "logf.h"
34 #include "settings.h"
35 #include "logfdisp.h"
37 #ifdef HAVE_LCD_BITMAP
38 bool logfdisplay(void)
41 int w, h;
42 int lines;
43 int columns;
44 int i;
46 bool lcd = false; /* fixed atm */
47 int index;
49 lcd_getstringsize("A", &w, &h);
50 lines = (lcd?
51 #ifdef HAVE_REMOTE_LCD
52 LCD_REMOTE_HEIGHT
53 #else
55 #endif
56 :LCD_HEIGHT)/h;
57 columns = (lcd?
58 #ifdef HAVE_REMOTE_LCD
59 LCD_REMOTE_WIDTH
60 #else
62 #endif
63 :LCD_WIDTH)/w;
65 if (columns > MAX_LOGF_ENTRY+1)
66 columns = MAX_LOGF_ENTRY+1;
68 if(!lines)
69 return false;
71 lcd_clear_display();
73 do {
74 index = logfindex;
75 for(i = lines-1; i>=0; i--) {
76 unsigned char buffer[columns + 1];
78 if(--index < 0) {
79 if(logfwrap)
80 index = MAX_LOGF_LINES-1;
81 else
82 break; /* done */
85 memcpy(buffer, logfbuffer[index], columns);
86 if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE)
87 buffer[columns-1] = '>';
88 else if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE)
89 buffer[columns-1] = '\0';
90 buffer[columns] = '\0';
92 lcd_puts(0, i, buffer);
94 lcd_update();
95 } while(!action_userabort(HZ));
97 return false;
99 #else /* HAVE_LCD_BITMAP */
100 bool logfdisplay(void)
103 /* TODO: implement a browser for charcell bitmaps */
104 return false;
106 #endif /* HAVE_LCD_BITMAP */
108 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
109 * entries will be "reversed" so that the most recently logged entry is on the
110 * top of the file */
111 bool logfdump(void)
113 int fd;
115 if(!logfindex && !logfwrap)
116 /* nothing is logged just yet */
117 return false;
119 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
120 if(-1 != fd) {
121 unsigned char buffer[MAX_LOGF_ONE_LINE_SIZE +1];
122 unsigned char *ptr;
123 int index = logfindex-1;
124 int stop = logfindex;
125 int tindex;
126 bool dumpwrap = false;
127 bool multiline;
129 while(!dumpwrap || (index >= stop)) {
130 if(index < 0) {
131 if(logfwrap)
133 index = MAX_LOGF_LINES-1;
134 dumpwrap = true;
136 else
137 break; /* done */
140 multiline = false;
141 if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE)
143 multiline = true;
144 do {
145 index--;
146 if(index < 0) {
147 if(logfwrap)
149 index = MAX_LOGF_LINES-1;
150 dumpwrap = true;
152 else
153 goto end_loop;
155 } while(logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE);
156 index++;
157 if (index >= MAX_LOGF_LINES)
158 index = 0;
161 tindex = index-1;
162 ptr = buffer;
163 do {
164 tindex++;
165 memcpy(ptr, logfbuffer[tindex], MAX_LOGF_ENTRY);
166 ptr += MAX_LOGF_ENTRY;
167 if (tindex >= MAX_LOGF_LINES)
168 tindex = 0;
169 } while(logfbuffer[tindex][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE);
170 *ptr = '\0';
172 fdprintf(fd, "%s\n", buffer);
173 index--;
175 end_loop:
176 close(fd);
178 return false;
181 #endif /* ROCKBOX_HAS_LOGF */