4 * Copyright (c) 2012 project bchan
6 * This software is provided 'as-is', without any express or implied
7 * warranty. In no event will the authors be held liable for any damages
8 * arising from the use of this software.
10 * Permission is granted to anyone to use this software for any purpose,
11 * including commercial applications, and to alter it and redistribute it
12 * freely, subject to the following restrictions:
14 * 1. The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software
16 * in a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source
33 #include <btron/hmi.h>
36 #include <tad/traydata_iterator.h>
38 #ifdef BCHANL_CONFIG_DEBUG
39 # define DP(arg) printf arg
40 # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
43 # define DP_ER(msg, err) /**/
46 EXPORT TCURL_CHECK_VALID_BBSURL tcurl_check_valid_bbsurl(CONST TC *url, W url_len)
48 TC scheme[] = {TK_h, TK_t, TK_t, TK_p, TK_COLN, TK_SLSH, TK_SLSH, TNULL};
52 cmp = tc_strncmp(url, scheme, 7);
54 return TCURL_CHECK_VALID_BBSURL_INVALID_SCHEME;
57 return TCURL_CHECK_VALID_BBSURL_INVALID_HOST;
59 p = tc_strchr(url+7, TK_SLSH);
61 return TCURL_CHECK_VALID_BBSURL_INVALID_PATH;
63 if ((p+1) == (url+url_len)) {
64 return TCURL_CHECK_VALID_BBSURL_INVALID_PATH;
67 return TCURL_CHECK_VALID_BBSURL_INVALID_HOST;
69 if ((p+1) == (url+url_len)) {
70 return TCURL_CHECK_VALID_BBSURL_INVALID_PATH;
72 p = tc_strchr(p+1, TK_SLSH);
74 return TCURL_CHECK_VALID_BBSURL_NO_LAST_SLSH;
76 if ((p+1) != (url+url_len)) {
77 return TCURL_CHECK_VALID_BBSURL_INVALID_PATH;
80 return TCURL_CHECK_VALID_BBSURL_OK;
83 EXPORT W tray_pushstring(TC *str, W len)
88 TADSEG *base = (TADSEG*)bin;
89 TEXTSEG *textseg = (TEXTSEG*)(bin + 4);
93 textseg->view = (RECT){{0, 0, 0, 0}};
94 textseg->draw = (RECT){{0, 0, 0, 0}};
95 textseg->h_unit = -120;
96 textseg->v_unit = -120;
100 trayrec[0].id = 0xE1;
103 trayrec[1].id = TR_TEXT;
104 trayrec[1].len = len * sizeof(TC);
105 trayrec[1].dt = (B*)str;
107 err = tpsh_dat(trayrec, 2, NULL);
109 DP_ER("tpsh_dat", err);
114 struct traydata_textiterator_t_ {
115 traydata_iterator_t base;
117 typedef struct traydata_textiterator_t_ traydata_textiterator_t;
119 LOCAL VOID traydata_textiterator_initialize(traydata_textiterator_t *iter, TRAYREC *rec, W recnum)
121 traydata_iterator_initialize(&iter->base, rec, recnum);
124 LOCAL Bool traydata_textiterator_getnext(traydata_textiterator_t *iter, TC *ch)
126 traydata_iterator_result result;
130 cont = traydata_iterator_next(&iter->base, &result);
134 if (result.type == TRAYDATA_ITERATOR_RESULTTYPE_FIXED_SEGMENT) {
143 LOCAL VOID traydata_textiterator_finalize(traydata_textiterator_t *iter)
145 traydata_iterator_finalize(&iter->base);
148 EXPORT W tray_popstring(TC *str, W len)
151 W size, recs, err, i;
152 traydata_textiterator_t iter;
156 err = tpop_dat(NULL, 0, &size, -1, NULL);
158 DP_ER("tpop_dat: get size error", err);
165 data = (TRAYREC*)malloc(size);
169 recs = tpop_dat(data, size, NULL, -1, NULL);
171 DP_ER("tpop_dat: get data error", recs);
176 traydata_textiterator_initialize(&iter, data, recs);
177 for (i = 0; i < len - 1;) {
178 cont = traydata_textiterator_getnext(&iter, &ch);
189 traydata_textiterator_finalize(&iter);
199 EXPORT W tray_deletedata()
204 EXPORT Bool tray_isempty()
209 DP_ER("tsel_dat", ret);