summaryrefslogtreecommitdiff
path: root/render.awk
blob: d617e39af581b3a27f38a191a853280f410a20da (plain)
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
139
140
141
142
143
144

function mylen(a){
	l=0;
	for (d in a)
		l+=1;
	return l;
}

function info_line(name, sel, host, port, dst){
	printf("[i|%s|%s|%s|%s]\r\n", name, sel, host, port) > dst;
}

function show_link(l, i, dst){

	if(l[i,"Category"] == "")
		print "Uncategorised link:", l[i,"Selector"];
	else{
		printf("[1|%s|%s|%s|%s]\r\n", l[i,"LinkName"], l[i,"Selector"], l[i,"Host"], l[i,"Port"] ) > dst;
		split(l[i,"Description"], descr, "\n");
		dl=mylen(descr);
		for (d=1;d<=dl;d++){
			info_line(descr[d],"Err", HOST, PORT, dst);
		}
		info_line("", "Err", HOST, PORT, dst);
	}

}


function show_category_link(category, i, dst){
	printf("[1|%s|%s|%s|%s]\r\n", category[i,"LinkName"], category[i,"Selector"], category[i,"Host"], category[i,"Port"]) > dst;
}



function get_parents(a){
	delete pars;
	split(a, pars, /\ \f\n\r\t\v*,\ \f\n\r\t\v*/);
	for (k in pars){
		gsub(/ +/, "", pars[k]);
	}

}

function category_in_parents(category, i){

	get_parents(category[i,"Parent"]);
	for (p in pars){
		if (pars[p]!="none"){### the root page does not have parents...
			dst=cfiles[pars[p]];
			if (has_categories[pars[p]] == ""){
				info_line("", "Err", HOST, PORT, dst);
				info_line("Sub-categories:", "Err", HOST, PORT, dst) ;
			}
			has_categories[pars[p]]=1;
			show_category_link(category, i, dst);
		}
	}
}

function category_header(category, i, dst){
	info_line(category[i,"Title"], "Err", HOST, PORT, dst);
	info_line("", "Err", HOST, PORT, dst);
	delete descr
	split(category[i,"Description"], descr, "\n");
	dl=mylen(descr);
	for (d=1;d<=dl;d++){
		info_line(descr[d], "Err", HOST, PORT, dst);
	}
}

function get_link_categories(a){
	delete cats;
	split(a, cats, /([\ \f\n\r\t\v*],[\ \f\n\r\t\v]*|,[\ \f\n\r\t\v]*)/);
	for (k in cats){
		gsub(/ +/, "", cats[k]);
	}
}

########################################


function render_init(){

}


function render_categories(){
	for (i=1; i<=cnum; i++){
		cname=category[i,"Name"];
		cfiles[cname]=BASEDIR category[i,"Selector"];
		cmd="dirname " cfiles[cname]; 
		cmd | getline bdir;
		cmd="ls -d " bdir " 2>/dev/null";
		if (system(cmd) != 0){
			cmd="mkdir -p " bdir;
			system(cmd);
		}
		cmd=sprintf("rm -f %s", cfiles[cname]);
		system(cmd);
		category_header(category, i, cfiles[cname]);
		category_in_parents(category, i);
	}
}

function render_post_categories(){


}


function render_links(){

	for (i=1;i<=lnum;i++){
		get_link_categories(link[i,"Category"]);
		for (c in cats){
			if (cfiles[cats[c]]!=""){
				dst=cfiles[cats[c]];
				if (has_links[cats[c]] == ""){
					info_line("_______________", "Err", \
					        HOST, PORT, dst);
					info_line("Links:", "Err", HOST, PORT,\
					        dst);
				}
				has_links[cats[c]]=1;
				show_link(link, i, dst);
			}
		}
	}	
}


function render_finalise(){

	for(i=1;i<=cnum; i++){
		info_line("_______________", "Err", HOST, PORT, cfiles[category[i,"Name"]]);
		printf("[1|%s|%s|%s|%s]\r\n", "Back to the lawn", ROOTSEL, HOST, PORT ) > cfiles[category[i,"Name"]];
	}
}

function dump_links(){


}