Skip to content

Commit 51c6fdc

Browse files
committed
fix
Signed-off-by: Jens Nyberg <[email protected]>
1 parent 6d076ef commit 51c6fdc

22 files changed

+20179
-1246
lines changed

Makefile

+33-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
1-
BIN1:=navi
2-
OBJ1:=src/navi.o src/list.o src/parser.o src/box.o
3-
BIN2:=alfi
4-
OBJ2:=src/alfi.o src/list.o src/parser.o
1+
BIN_ALFI:=alfi
2+
OBJ_ALFI:=src/alfi.o src/list.o src/parser.o src/call.o src/pool.o
3+
BIN_NAVI:=navi
4+
OBJ_NAVI:=src/navi.o src/list.o src/parser.o src/call.o src/pool.o src/box.o src/nvg.o src/nvg_gl.o
5+
BIN_NAVI_RESOLVE:=navi-resolve
56

6-
all: $(BIN1) $(BIN2)
7+
all: $(BIN_ALFI) $(BIN_NAVI) $(BIN_NAVI_RESOLVE)
78

89
%.o: %.c
9-
$(CC) -c -o $@ -Wall -Werror -std=c89 -pedantic $^
10+
@echo CC $@
11+
@$(CC) -c -o $@ -Wall -Werror -Wno-misleading-indentation -pedantic $^
1012

11-
$(BIN1): $(OBJ1)
12-
$(CC) -o $@ -Wall -Werror -std=c89 -pedantic $^ -lm -lGL -lglfw -lnanovg
13+
$(BIN_ALFI): $(OBJ_ALFI)
14+
@echo LD $@
15+
@$(CC) -o $@ -Wall -Werror -pedantic $^
1316

14-
$(BIN2): $(OBJ2)
15-
$(CC) -o $@ -Wall -Werror -std=c89 -pedantic $^
17+
$(BIN_NAVI): $(OBJ_NAVI)
18+
@echo LD $@
19+
@$(CC) -o $@ -Wall -Werror -pedantic $^ -lm -lGL -lGLEW -lglfw
20+
21+
$(BIN_NAVI_RESOLVE): src/$(BIN_NAVI_RESOLVE)
22+
@echo CP $@
23+
@cp $^ $@
1624

1725
clean:
18-
$(RM) $(BIN1) $(OBJ1) $(BIN2) $(OBJ2)
26+
@$(RM) $(BIN_ALFI) $(OBJ_ALFI) $(BIN_NAVI) $(OBJ_NAVI) $(BIN_NAVI_RESOLVE)
27+
28+
install:
29+
mkdir -p /usr/bin
30+
cp $(BIN_NAVI) /usr/bin/$(BIN_NAVI)
31+
cp $(BIN_ALFI) /usr/bin/$(BIN_ALFI)
32+
cp $(BIN_NAVI_RESOLVE) /usr/bin/$(BIN_NAVI_RESOLVE)
33+
mkdir -p /usr/share/navi
34+
cp data/icofont.ttf /usr/share/navi/icofont.ttf
35+
cp data/roboto-bold.ttf /usr/share/navi/roboto-bold.ttf
36+
cp data/roboto-light.ttf /usr/share/navi/roboto-light.ttf
37+
cp data/roboto-regular.ttf /usr/share/navi/roboto-regular.ttf
38+
cp data/image6.jpg /usr/share/navi/image6.jpg
39+
cp data/example.alfi /usr/share/navi/example.alfi
40+

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ renders widgets in OpenGL. It is currently very much under development.
2121

2222
## Building / Installing
2323

24-
You need to have the glfw3 and nanovg libraries installed in order to be able to
25-
build NAVI. Installing these depends on your distribution of choice.
24+
You need to have the glfw3 libraries installed in order to build NAVI from
25+
soure. How you install those depends on your distribution of choice.
2626

2727
Build:
2828

example.alfi data/example.alfi

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
= window label "Example window"
33

44
# A header and some text
5-
+ header label "What a wonderful world"
6-
+ text label "This is some text."
5+
+ header label "This is the title that doesn't say anything right now!"
6+
+ text label "This is some text. It is just here so I can see if word wrapping works the way it should or if there are some troubles with it. Word wrapping was actually one of the more trickier things to solve."
77
+ subheader label "This is a subheader"
88
+ text label "Below is a form."
99

1010
# Basic form elements
1111
+ field id field1 type regular label "Username"
1212
+ field id field2 type password label "Password"
13-
+ select id select1 range 1 1 label "Select"
14-
+ choice in select1 id choice1 label "Option 1"
15-
+ choice in select1 id choice2 label "Option 2"
16-
+ choice in select1 id choice3 label "Option 3"
17-
+ button id submit label "Submit"
13+
+ field id field3 type regular label "Phone" data "+46"
14+
+ select id select1 range 1 1 label "Make a choice"
15+
+ choice in select1 label "Choice 1-1"
16+
+ choice in select1 label "Choice 1-2"
17+
+ choice in select1 label "Choice 1-3"
18+
+ select id select2 range 1 1 label "Country" data "Sweden"
19+
+ choice in select2 label "Denmark"
20+
+ choice in select2 label "Finland"
21+
+ choice in select2 label "Norway"
22+
+ choice in select2 label "Sweden"
23+
+ button id submit label "SEND"
1824

1925
# Two nested lists
2026
+ list id list1
@@ -24,6 +30,9 @@
2430
+ text in list2 label "Item 2-1"
2531
+ text in list2 label "Item 2-2"
2632

33+
# An anchor link to another site
34+
+ anchor label "This is a link" link "http://www.blunder.se/" "text/alfi"
35+
2736
# A row of images
2837
+ hstack id gallery halign left valign top
2938
+ image in gallery link "data/image6.jpg" "image/jpeg"
@@ -47,14 +56,14 @@
4756
+ table id table1 grid 24 0 0 0 6 0
4857
+ text in table1 label "Cell 0-0"
4958
+ text in table1 label "Cell 0-1"
50-
+ text in table1 label "Cell 0-2"
59+
+ text in table1 label "Cell 0-2 containing a lot of extra text"
5160
+ text in table1 label "Cell 0-3"
5261
+ text in table1 label "Cell 1-0"
5362
+ text in table1 label "Cell 1-1"
5463
+ image in table1 link "data/image6.jpg" "image/jpeg"
5564
+ text in table1 label "Cell 1-3"
5665
+ text in table1 label "Cell 2-0"
57-
+ text in table1 label "Cell 2-1"
66+
+ text in table1
5867
+ text in table1 label "Cell 2-2"
5968
+ text in table1 label "Cell 2-3"
6069
+ text in table1 label "Cell 3-0"

src/alfi.c

+18-90
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,46 @@
11
#include <stdlib.h>
22
#include <stdio.h>
33
#include <string.h>
4+
#include <unistd.h>
45
#include "list.h"
56
#include "box.h"
67
#include "widgets.h"
78
#include "parser.h"
9+
#include "call.h"
10+
#include "pool.h"
811

9-
#define NWIDGETS 512
10-
#define STRINGTABLESIZE 8192
11-
12-
static struct alfi_widget widgets[NWIDGETS];
13-
static char strings[STRINGTABLESIZE];
1412
static struct parser parser;
15-
static struct list freelist;
16-
static struct list usedlist;
1713

18-
static struct alfi_widget *nextwidget(struct list *list, struct alfi_widget *widget)
14+
static struct alfi_widget *parser_find(char *name, unsigned int group)
1915
{
2016

21-
struct list_item *current = (widget) ? widget->item.next : list->head;
22-
23-
return (current) ? current->data : 0;
17+
return pool_findbyname(group, name);
2418

2519
}
2620

27-
static struct alfi_widget *findwidgetbyname(struct list *list, unsigned int group, char *name)
21+
static char *parser_createstring(unsigned int size)
2822
{
2923

30-
struct alfi_widget *widget = 0;
31-
32-
while ((widget = nextwidget(list, widget)))
33-
{
34-
35-
if (widget->group != group)
36-
continue;
37-
38-
if (!widget->id.name)
39-
continue;
40-
41-
if (!strcmp(widget->id.name, name))
42-
return widget;
43-
44-
}
45-
46-
return 0;
24+
return malloc(size);
4725

4826
}
4927

50-
static struct alfi_widget *nextchild(struct list *list, struct alfi_widget *widget, struct alfi_widget *parent)
28+
static void parser_destroystring(char *string)
5129
{
5230

53-
while ((widget = nextwidget(list, widget)))
54-
{
55-
56-
if (widget->group != parent->group)
57-
continue;
58-
59-
if (!widget->in.name)
60-
continue;
61-
62-
if (findwidgetbyname(list, widget->group, widget->in.name) == parent)
63-
return widget;
64-
65-
}
66-
67-
return 0;
68-
69-
}
70-
71-
static struct alfi_widget *parser_find(char *name, unsigned int group)
72-
{
73-
74-
return findwidgetbyname(&usedlist, group, name);
31+
free(string);
7532

7633
}
7734

7835
static struct alfi_widget *parser_create(unsigned int type, unsigned int group, char *in)
7936
{
8037

81-
struct list_item *item = list_pickhead(&freelist);
82-
struct alfi_widget *widget = item->data;
38+
struct alfi_widget *widget = pool_create();
8339

8440
widget->type = type;
8541
widget->group = group;
8642
widget->in.name = in;
8743

88-
list_add(&usedlist, item);
89-
9044
return widget;
9145

9246
}
@@ -96,7 +50,7 @@ static void parser_destroy(struct alfi_widget *widget)
9650

9751
struct alfi_widget *child = 0;
9852

99-
while ((child = nextchild(&usedlist, child, widget)))
53+
while ((child = pool_nextchild(child, widget)))
10054
{
10155

10256
parser_destroy(child);
@@ -105,7 +59,8 @@ static void parser_destroy(struct alfi_widget *widget)
10559

10660
}
10761

108-
list_move(&freelist, &usedlist, &widget->item);
62+
call_destroy(widget);
63+
pool_destroy(widget);
10964

11065
}
11166

@@ -117,29 +72,6 @@ static void parser_fail(unsigned int line)
11772

11873
}
11974

120-
static void load(void)
121-
{
122-
123-
unsigned int i;
124-
125-
for (i = 0; i < NWIDGETS; i++)
126-
{
127-
128-
list_inititem(&widgets[i].item, &widgets[i]);
129-
list_add(&freelist, &widgets[i].item);
130-
131-
}
132-
133-
parser.string.data = strings;
134-
parser.string.count = STRINGTABLESIZE;
135-
parser.string.offset = 0;
136-
parser.find = parser_find;
137-
parser.create = parser_create;
138-
parser.destroy = parser_destroy;
139-
parser.fail = parser_fail;
140-
141-
}
142-
14375
static void loadbase(unsigned int group)
14476
{
14577

@@ -172,18 +104,14 @@ int main(int argc, char **argv)
172104
{
173105

174106
char data[4096];
107+
int count;
175108

176-
load();
109+
pool_init();
110+
parser_init(&parser, parser_fail, parser_find, parser_create, parser_destroy, parser_createstring, parser_destroystring);
177111
loadbase(1);
178112

179-
parser.expr.data = data;
180-
parser.expr.count = fread(data, 1, 4096, stdin);
181-
parser.expr.offset = 0;
182-
parser.expr.line = 0;
183-
parser.expr.linebreak = 0;
184-
parser.expr.inside = 0;
185-
186-
parse(&parser, 1, "main");
113+
while ((count = read(0, data, 4096)))
114+
parser_parsedata(&parser, 1, "main", count, data);
187115

188116
return 0;
189117

0 commit comments

Comments
 (0)