1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006 Frederik M.J. Vestre
* Copyright (C) 2006 Adam Gashlin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "mallocer.h" /*mallocer resetable memory allocator*/
#include "inflate.h"
#include "shared/btsearch.h"
#include <inttypes.h>
#include "plugin.h"
/*Remember to require this:
extern struct plugin_api *rb;
Matthias Larisch: This is already done in btsearch.h. maybe it should be
moved
*/
unsigned int mwdb_p_xtpt;
static int mwdb_nprintf(const char *fmt, ...)
{
char p_buf[50];
bool ok;
va_list ap;
va_start(ap, fmt);
ok = rb->vsnprintf(p_buf,sizeof(p_buf), fmt, ap);
va_end(ap);
rb->lcd_putsxy(1,mwdb_p_xtpt, (unsigned char *)p_buf);
rb->lcd_update();
mwdb_p_xtpt+=rb->font_get(FONT_UI)->height;
if(mwdb_p_xtpt>LCD_HEIGHT-rb->font_get(FONT_UI)->height)
{
mwdb_p_xtpt=0;
rb->lcd_clear_display();
}
return 1;
}
int mwdb_findarticle(const char* filename,
char* artnme,
uint16_t artnmelen,
uint32_t * res_lo,
uint32_t * res_hi,
bool progress,
bool promptname,
bool casesense)
{
int fd;
char fnbuf[rb->strlen(filename)+6];
if(promptname)
{
#ifdef HAVE_TOUCHSCREEN
/* this is a hack till proper touchscreen keyboard input arrives */
rb->touchscreen_set_mode(TOUCHSCREEN_BUTTON);
#endif
if (rb->kbd_input(artnme,artnmelen))
{
artnme[0]='\0';
#ifdef HAVE_TOUCHSCREEN
rb->touchscreen_set_mode(TOUCHSCREEN_POINT);
#endif
return false; /* proper abort on keyboard abort */
}
#ifdef HAVE_TOUCHSCREEN
rb->touchscreen_set_mode(TOUCHSCREEN_POINT);
#endif
}
rb->snprintf(fnbuf,rb->strlen(filename)+6,"%s.wwi",filename);
fd = rb->open(fnbuf, 0);
if (fd==-1)
return false;
if(progress)
{
mwdb_p_xtpt=0;
rb->lcd_clear_display();
mwdb_nprintf("Searching...");
}
search_btree((void*)fd,artnme,rb->strlen(artnme),0,res_lo,res_hi,casesense);
rb->close(fd);
if(*res_hi==0) /* not found */
return false;
else if(progress)
mwdb_nprintf("Found:%d%d",*res_lo,*res_hi);
return true;
}
int mwdb_loadarticle(const char * filename,
void * scratchmem,
void * articlemem,
uint32_t articlememlen,
uint32_t *articlelen,
uint32_t res_lo,
uint32_t res_hi)
{
char fnbuf[rb->strlen(filename)+6];
mwdb_p_xtpt=0;
rb->lcd_clear_display();
mwdb_nprintf("Loading %d%d...",res_lo,res_hi);
rb->snprintf(fnbuf,rb->strlen(filename)+6,"%s%lu.wwa",filename,res_lo);
*articlelen=decompress(fnbuf,articlemem,articlememlen,res_hi,scratchmem);
((unsigned char*)articlemem)[*articlelen]='\0';
return true;
}
|