Skip to content

Commit 15a9c5e

Browse files
committed
more
Signed-off-by: Jens Nyberg <[email protected]>
1 parent 9ca40f3 commit 15a9c5e

12 files changed

+74
-91
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GL:=GLES3
22
BIN_ALFI:=alfi
3-
OBJ_ALFI:=src/alfi.o src/list.o src/parser.o src/url.o src/resource.o src/pool.o src/attribute.o src/widget.o
3+
OBJ_ALFI:=src/alfi.o src/list.o src/parser.o src/url.o src/resource.o src/pool.o src/attribute.o src/widget.o src/history.o
44
BIN_NAVI:=navi
5-
OBJ_NAVI:=src/navi.o src/list.o src/parser.o src/url.o src/resource.o src/pool.o src/attribute.o src/widget.o src/view.o src/gridfmt.o src/style.o src/nvg.o src/nvg_gl.o src/fons.o src/render.o src/animation.o src/history.o
5+
OBJ_NAVI:=src/navi.o src/list.o src/parser.o src/url.o src/resource.o src/pool.o src/attribute.o src/widget.o src/history.o src/view.o src/gridfmt.o src/style.o src/nvg.o src/nvg_gl.o src/fons.o src/render.o src/animation.o
66
BIN_NAVI_RESOLVE:=navi-resolve
77
CFLAGS_GL2:=-DNVG_GL_VERSION_GL2 -DNVG_GL_GLEW
88
CFLAGS_GL3:=-DNVG_GL_VERSION_GL3 -DNVG_GL_GLEW

src/history.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
#include "url.h"
55
#include "history.h"
66

7-
static struct urlinfo stack[32];
7+
static struct history stack[32];
88
static unsigned int historycount;
99

10-
struct urlinfo *history_get(unsigned int index)
10+
struct history *history_get(unsigned int index)
1111
{
1212

1313
return &stack[historycount - index - 1];
1414

1515
}
1616

17-
struct urlinfo *history_push(void)
17+
struct history *history_push(void)
1818
{
1919

2020
if (historycount < 31)
@@ -24,7 +24,7 @@ struct urlinfo *history_push(void)
2424

2525
}
2626

27-
struct urlinfo *history_pop(void)
27+
struct history *history_pop(void)
2828
{
2929

3030
if (historycount > 1)
@@ -37,7 +37,7 @@ struct urlinfo *history_pop(void)
3737
char *history_geturl(unsigned int index)
3838
{
3939

40-
struct urlinfo *info = history_get(index);
40+
struct history *info = history_get(index);
4141

4242
if (info)
4343
return info->url;

src/history.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
struct urlinfo *history_get(unsigned int index);
2-
struct urlinfo *history_push(void);
3-
struct urlinfo *history_pop(void);
1+
struct history
2+
{
3+
4+
char url[URL_SIZE];
5+
6+
};
7+
8+
struct history *history_get(unsigned int index);
9+
struct history *history_push(void);
10+
struct history *history_pop(void);
411
char *history_geturl(unsigned int index);

src/navi.c

+28-29
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ static void loadresources_linklabel(struct attribute_link *link, struct attribut
291291
{
292292

293293
struct resource resource;
294-
struct urlinfo info;
294+
char url[URL_SIZE];
295295

296296
if (!strlen(link->url))
297297
return;
298298

299-
url_merge(&info, history_geturl(0), link->url);
300-
attribute_link_create(link, info.url);
299+
url_merge(url, history_geturl(0), link->url);
300+
attribute_link_create(link, url);
301301
resource_init(&resource, link->url);
302302
resource_load(&resource, 0, 0);
303303

@@ -320,13 +320,13 @@ static void loadresources_linklabel(struct attribute_link *link, struct attribut
320320
static void loadresources_image(struct attribute_link *link)
321321
{
322322

323-
struct urlinfo info;
323+
char url[URL_SIZE];
324324

325325
if (!strlen(link->url))
326326
return;
327327

328-
url_merge(&info, history_geturl(0), link->url);
329-
attribute_link_create(link, info.url);
328+
url_merge(url, history_geturl(0), link->url);
329+
attribute_link_create(link, url);
330330
render_loadimage(link->url);
331331

332332
}
@@ -374,16 +374,21 @@ static void urlself(char *url, unsigned int count, void *data)
374374
if (temp.count)
375375
{
376376

377-
struct frame *frame = pool_getframe(widget_root->index);
378-
struct urlinfo *info = history_get(0);
379-
struct frame keyframe;
377+
parser_parse(&parser, "main", temp.count, temp.data);
378+
379+
if (parser.errors)
380+
{
380381

381-
if (info)
382-
url_set(info, temp.urlinfo.url);
382+
urlself("navi://syntaxerror", strlen(temp.url), temp.url);
383383

384-
if (!parser_parse(&parser, "main", temp.count, temp.data))
384+
}
385+
386+
else
385387
{
386388

389+
struct frame *frame = pool_getframe(widget_root->index);
390+
struct frame keyframe;
391+
387392
loadresources();
388393
animation_initframe(&keyframe, view.scrollx + view.padw, view.scrolly + view.padh, view.unitw * 24, 0);
389394
animation_step(widget_root, &keyframe, &view, 1.0);
@@ -393,19 +398,12 @@ static void urlself(char *url, unsigned int count, void *data)
393398

394399
}
395400

396-
else
397-
{
398-
399-
urlself("navi://syntaxerror", strlen(temp.urlinfo.url), temp.urlinfo.url);
400-
401-
}
402-
403401
}
404402

405403
else
406404
{
407405

408-
urlself("navi://notfound", strlen(temp.urlinfo.url), temp.urlinfo.url);
406+
urlself("navi://notfound", strlen(temp.url), temp.url);
409407

410408
}
411409

@@ -429,20 +427,21 @@ static void urlblank(char *url, unsigned int count, void *data)
429427
static void loadself(char *url, unsigned int count, void *data)
430428
{
431429

432-
struct urlinfo info;
430+
char purl[URL_SIZE];
433431

434-
url_merge(&info, history_geturl(0), url);
435-
urlself(info.url, count, data);
432+
url_merge(purl, history_geturl(0), url);
433+
urlself(purl, count, data);
436434

437435
}
438436

439437
static void loadblank(char *url, unsigned int count, void *data)
440438
{
441439

442-
struct urlinfo *info = history_push();
440+
struct history *current = history_get(0);
441+
struct history *next = history_push();
443442

444-
url_merge(info, history_geturl(1), url);
445-
urlblank(info->url, count, data);
443+
url_merge(next->url, current->url, url);
444+
urlblank(next->url, count, data);
446445

447446
}
448447

@@ -1052,10 +1051,10 @@ static void onbutton(GLFWwindow *window, int button, int action, int mods)
10521051
else
10531052
{
10541053

1055-
struct urlinfo *info = history_pop();
1054+
struct history *last = history_pop();
10561055

1057-
if (info)
1058-
urlblank(info->url, 0, 0);
1056+
if (last)
1057+
urlblank(last->url, 0, 0);
10591058

10601059
}
10611060

src/parser.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ static void parse_command_update(struct parser *parser)
13261326

13271327
}
13281328

1329-
static unsigned int parse(struct parser *parser, char *in)
1329+
static void parse(struct parser *parser, char *in)
13301330
{
13311331

13321332
while (!parser->errors && parser->expr.offset < parser->expr.count)
@@ -1369,11 +1369,9 @@ static unsigned int parse(struct parser *parser, char *in)
13691369

13701370
}
13711371

1372-
return parser->errors;
1373-
13741372
}
13751373

1376-
unsigned int parser_parse(struct parser *parser, char *in, unsigned int count, void *data)
1374+
void parser_parse(struct parser *parser, char *in, unsigned int count, void *data)
13771375
{
13781376

13791377
parser->errors = 0;
@@ -1385,14 +1383,13 @@ unsigned int parser_parse(struct parser *parser, char *in, unsigned int count, v
13851383
parser->expr.inside = 0;
13861384
parser->expr.escaped = 0;
13871385

1388-
return parse(parser, in);
1386+
parse(parser, in);
13891387

13901388
}
13911389

13921390
void parser_init(struct parser *parser, void (*fail)(void), struct widget *(*find)(char *name), struct widget *(*create)(unsigned int type, char *id, char *in), struct widget *(*destroy)(struct widget *widget), void (*clear)(struct widget *widget))
13931391
{
13941392

1395-
parser->errors = 0;
13961393
parser->fail = fail;
13971394
parser->find = find;
13981395
parser->create = create;

src/parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ struct parser
2323

2424
};
2525

26-
unsigned int parser_parse(struct parser *parser, char *in, unsigned int count, void *data);
26+
void parser_parse(struct parser *parser, char *in, unsigned int count, void *data);
2727
void parser_init(struct parser *parser, void (*fail)(void), struct widget *(*find)(char *name), struct widget *(*create)(unsigned int type, char *id, char *in), struct widget *(*destroy)(struct widget *widget), void (*clear)(struct widget *widget));

src/pool.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ struct resource *pool_resource_find(char *url)
134134
while ((resource = nextresource(&usedresources, resource)))
135135
{
136136

137-
if (!strlen(resource->urlinfo.url))
137+
if (!strlen(resource->url))
138138
continue;
139139

140-
if (!strcmp(resource->urlinfo.url, url))
140+
if (!strcmp(resource->url, url))
141141
return resource;
142142

143143
}

src/render.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ void render_filltextinput(struct style *style, char *text, int offset, struct st
487487
for (i = 0; (current = calcline(&style->font, style->box.w, current, end, &row)); i++)
488488
{
489489

490-
int length = row.end - row.start + 1;
490+
int length = row.end - row.start;
491491

492-
if (offset >= 0 && offset < length)
492+
if (offset >= 0 && offset <= length)
493493
{
494494

495495
x = rendertext(&textpaint, &scissor, &style->font, x, y, row.start, row.start + offset);

src/resource.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "list.h"
66
#include "url.h"
77
#include "resource.h"
8+
#include "history.h"
89

910
static void save(struct resource *resource, unsigned int count, void *data)
1011
{
@@ -75,7 +76,7 @@ static unsigned int resolve(struct resource *resource, const char *name, char *
7576
static unsigned int _curl_match(struct resource *resource)
7677
{
7778

78-
return !strncmp(resource->urlinfo.url, "http:", 5) || !strncmp(resource->urlinfo.url, "https:", 6);
79+
return !strncmp(resource->url, "http:", 5) || !strncmp(resource->url, "https:", 6);
7980

8081
}
8182

@@ -98,7 +99,7 @@ static unsigned int _curl_load(struct resource *resource, unsigned int count, vo
9899
q[8] = "Content-Type: application/x-www-form-urlencoded";
99100
q[9] = "-d";
100101
q[10] = data;
101-
q[11] = resource->urlinfo.url;
102+
q[11] = resource->url;
102103
q[12] = 0;
103104

104105

@@ -114,7 +115,7 @@ static unsigned int _curl_load(struct resource *resource, unsigned int count, vo
114115
q[4] = "Navi/1.0";
115116
q[5] = "-X";
116117
q[6] = "GET";
117-
q[7] = resource->urlinfo.url;
118+
q[7] = resource->url;
118119
q[8] = 0;
119120

120121
}
@@ -126,14 +127,14 @@ static unsigned int _curl_load(struct resource *resource, unsigned int count, vo
126127
static unsigned int _navi_match(struct resource *resource)
127128
{
128129

129-
return !strncmp(resource->urlinfo.url, "navi:", 5);
130+
return !strncmp(resource->url, "navi:", 5);
130131

131132
}
132133

133134
static unsigned int _navi_load(struct resource *resource, unsigned int count, void *data)
134135
{
135136

136-
char *path = resource->urlinfo.url + 7;
137+
char *path = resource->url + 7;
137138

138139
if (!strncmp(path, "blank", 5))
139140
{
@@ -264,10 +265,11 @@ static unsigned int _navi_load(struct resource *resource, unsigned int count, vo
264265
else if (!strncmp(path, "lookup", 6))
265266
{
266267

268+
struct history *current = history_get(0);
267269
char *urlparam = data;
268270

269-
url_set(&resource->urlinfo, urlparam + 4);
270-
271+
strcpy(resource->url, urlparam + 4);
272+
strcpy(current->url, resource->url);
271273
resource_load(resource, 0, 0);
272274

273275
return resource->count;
@@ -291,7 +293,7 @@ static unsigned int _external_load(struct resource *resource, unsigned int count
291293
char *q[4];
292294

293295
q[0] = "navi-resolve";
294-
q[1] = resource->urlinfo.url;
296+
q[1] = resource->url;
295297
q[2] = data;
296298
q[3] = 0;
297299

@@ -336,7 +338,7 @@ unsigned int resource_dref(struct resource *resource)
336338
void resource_init(struct resource *resource, char *url)
337339
{
338340

339-
url_set(&resource->urlinfo, url);
341+
strcpy(resource->url, url);
340342

341343
resource->data = 0;
342344
resource->size = 0;
@@ -348,7 +350,7 @@ void resource_init(struct resource *resource, char *url)
348350
void resource_destroy(struct resource *resource)
349351
{
350352

351-
url_unset(&resource->urlinfo);
353+
strcpy(resource->url, "");
352354

353355
resource->data = 0;
354356
resource->size = 0;

src/resource.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct resource
44
{
55

66
struct list_item item;
7-
struct urlinfo urlinfo;
7+
char url[URL_SIZE];
88
void *data;
99
unsigned int size;
1010
unsigned int count;

0 commit comments

Comments
 (0)