summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-06-15 22:26:35 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-06-15 22:26:35 +0000
commit4bfcbaca733799e82367a518106aa0871c3cd575 (patch)
tree3352ce024b40e4f1502fbe7b281397dc056f0092
parent7da93d58fdc73c40a721f9f1c7d7a42609e10a53 (diff)
downloadrockbox-4bfcbaca733799e82367a518106aa0871c3cd575.tar.gz
rockbox-4bfcbaca733799e82367a518106aa0871c3cd575.zip
This is the start of a text file viewer for the Player. It is not called
from anywhere at this point. It still compiles nicely. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1018 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/showtext.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/apps/showtext.c b/apps/showtext.c
new file mode 100644
index 0000000000..2bd13826d2
--- /dev/null
+++ b/apps/showtext.c
@@ -0,0 +1,146 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Daniel Stenberg
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <string.h>
21
22#include "file.h"
23#include "lcd.h"
24#include "kernel.h"
25#include "button.h"
26#include "sprintf.h"
27
28char *strcat(char *s1,
29 const char *s2)
30{
31 char *s = s1;
32
33 while (*s1)
34 s1++;
35
36 while ((*s1++ = *s2++))
37 ;
38 return s;
39}
40
41
42static int here=0;
43
44char *singleshow(char *word)
45{
46 static unsigned char words[22];
47 int len = strlen(word);
48
49 if(len>=10) {
50 if(len < 12 ) {
51 lcd_clear_display();
52 lcd_puts(0,0, word);
53 strcpy(words, "");
54 here=0;
55 return words;
56 }
57 /* huuuge word, use two lines! */
58 return NULL;
59 }
60
61 else if(here +1 + len <= 11) { /* 1 is for space */
62 if(words[0])
63 strcat(words, " ");
64 strcat(words, word);
65 here+=1+len;
66 return NULL; /* no show right now */
67 }
68 else {
69 lcd_clear_display();
70 lcd_puts(0,0, words);
71 strcpy(words, word);
72 here=len;
73 return words;
74 }
75}
76
77#define SEP(x) (((x) == '\n') || ((x) == '\t') || ((x) == ' '))
78
79void showtext(char *filename)
80{
81 static char textbuffer[1024];
82
83 int fd;
84 int size;
85 char *ptr;
86 char *end;
87 unsigned char backup;
88 char num[8];
89 int count=0;
90 int b;
91 char *show;
92 int delay = HZ;
93
94 fd = open(filename, O_RDONLY);
95
96 if(-1 == fd)
97 return;
98
99 do {
100 size = read(fd, textbuffer, sizeof(textbuffer));
101
102 ptr = textbuffer;
103 while (size > 0) {
104 while(ptr && *ptr && SEP(*ptr)) {
105 ptr++;
106 size--;
107 count++;
108 }
109 end = ptr;
110
111 while(end && *end && !SEP(*end)) {
112 end++;
113 count++;
114 }
115
116 backup = *end;
117 *end = 0;
118
119
120 show = singleshow(ptr);
121
122 if(show) {
123 snprintf(num, sizeof(num), "%d", count);
124 lcd_puts(0,1, num);
125 }
126
127 *end = backup;
128
129 ptr += (end - ptr);
130 size -= (end - ptr);
131
132 b = button_get(false);
133 if(b) {
134 size = -1;
135 break;
136 }
137 if(show)
138 sleep(delay);
139 }
140
141
142 } while(size>0);
143
144 close(fd);
145
146}