use lib display text to display help messages (FS#10099).
[kugel-rb.git] / apps / logfdisp.c
blobda711bf1d383420d864deabb2e80474179b8ff2d
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"
36 #include "action.h"
38 #ifdef HAVE_LCD_BITMAP
39 bool logfdisplay(void)
41 int w, h;
42 int lines;
43 int columns;
44 int i;
45 int action;
47 bool lcd = false; /* fixed atm */
48 int index, user_index=0;
50 lcd_getstringsize("A", &w, &h);
51 lines = (lcd?
52 #ifdef HAVE_REMOTE_LCD
53 LCD_REMOTE_HEIGHT
54 #else
56 #endif
57 :LCD_HEIGHT)/h;
58 columns = (lcd?
59 #ifdef HAVE_REMOTE_LCD
60 LCD_REMOTE_WIDTH
61 #else
63 #endif
64 :LCD_WIDTH)/w;
66 if (columns > MAX_LOGF_ENTRY+1)
67 columns = MAX_LOGF_ENTRY+1;
69 if(!lines)
70 return false;
72 do {
73 lcd_clear_display();
75 index = logfindex + user_index;
76 for(i = lines-1; i>=0; i--) {
77 unsigned char buffer[columns + 1];
79 if(--index < 0) {
80 if(logfwrap)
81 index = MAX_LOGF_LINES-1;
82 else
83 break; /* done */
86 memcpy(buffer, logfbuffer[index], columns);
87 if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE)
88 buffer[columns-1] = '>';
89 else if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE)
90 buffer[columns-1] = '\0';
91 buffer[columns] = '\0';
93 lcd_puts(0, i, buffer);
95 lcd_update();
97 action = get_action(CONTEXT_STD, HZ);
98 if(action == ACTION_STD_NEXT)
99 user_index++;
100 else if(action == ACTION_STD_PREV)
101 user_index--;
102 else if(action == ACTION_STD_OK)
103 user_index = 0;
104 #ifdef HAVE_TOUCHSCREEN
105 else if(action == ACTION_TOUCHSCREEN)
107 short x, y;
108 static int prev_y;
110 action = action_get_touchscreen_press(&x, &y);
112 if(action & BUTTON_REL)
113 prev_y = 0;
114 else
116 if(prev_y != 0)
117 user_index += (prev_y - y) / h;
119 prev_y = y;
122 #endif
123 } while(action != ACTION_STD_CANCEL);
125 return false;
127 #else /* HAVE_LCD_BITMAP */
128 bool logfdisplay(void)
131 /* TODO: implement a browser for charcell bitmaps */
132 return false;
134 #endif /* HAVE_LCD_BITMAP */
136 /* Store the logf log to logf.txt in the .rockbox directory. The order of the
137 * entries will be "reversed" so that the most recently logged entry is on the
138 * top of the file */
139 bool logfdump(void)
141 int fd;
143 if(!logfindex && !logfwrap)
144 /* nothing is logged just yet */
145 return false;
147 fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC);
148 if(-1 != fd) {
149 unsigned char buffer[MAX_LOGF_ONE_LINE_SIZE +1];
150 unsigned char *ptr;
151 int index = logfindex-1;
152 int stop = logfindex;
153 int tindex;
154 bool dumpwrap = false;
155 bool multiline;
157 while(!dumpwrap || (index >= stop)) {
158 if(index < 0) {
159 if(logfwrap)
161 index = MAX_LOGF_LINES-1;
162 dumpwrap = true;
164 else
165 break; /* done */
168 multiline = false;
169 if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE)
171 multiline = true;
172 do {
173 index--;
174 if(index < 0) {
175 if(logfwrap)
177 index = MAX_LOGF_LINES-1;
178 dumpwrap = true;
180 else
181 goto end_loop;
183 } while(logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE);
184 index++;
185 if (index >= MAX_LOGF_LINES)
186 index = 0;
189 tindex = index-1;
190 ptr = buffer;
191 do {
192 tindex++;
193 memcpy(ptr, logfbuffer[tindex], MAX_LOGF_ENTRY);
194 ptr += MAX_LOGF_ENTRY;
195 if (tindex >= MAX_LOGF_LINES)
196 tindex = 0;
197 } while(logfbuffer[tindex][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE);
198 *ptr = '\0';
200 fdprintf(fd, "%s\n", buffer);
201 index--;
203 end_loop:
204 close(fd);
206 return false;
209 #endif /* ROCKBOX_HAS_LOGF */