summaryrefslogtreecommitdiff
path: root/support/dktools/hbnode.c
blob: 87da973e0b5c1f1304e559c7dc74a723cefa3d99 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*
Copyright (C) 2013-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: hbnode.ctr
*/

/**	@file hbnode.c The hbnode module.
*/


#line 85 "hbnode.ctr"

#include "htmlbook.h"
#include "dk3all.h"
#include "dk3unused.h"





#line 93 "hbnode.ctr"



void
hbnode_link_delete(hb_link_t *ptr)
{
  

#line 100 "hbnode.ctr"
  if(ptr) {
    ptr->lno = 0UL;
    dk3_release(ptr->url);
    dk3_delete(ptr);
  } 

#line 105 "hbnode.ctr"
}



hb_link_t *
hbnode_link_new(dkChar const *url, unsigned long lno, dk3_app_t *app)
{
  hb_link_t	*back	= NULL;
  

#line 114 "hbnode.ctr"
  if(url) {
    back = dk3_new_app(hb_link_t,1,app);
    if(back) {
      back->lno		= lno;
      back->url		= dk3str_dup_app(url,app);
      back->flags	= 0;
      if(!(back->url)) {
        hbnode_link_delete(back);
	back = NULL;
      }
    }
  } 

#line 126 "hbnode.ctr"
  return back;
}



int
hbnode_link_compare(const void *l, const void *r, int cr)
{
  hb_link_t	*pl;
  hb_link_t	*pr;
  int		 back	= 0;
  

#line 138 "hbnode.ctr"
  if(l) {
    if(r) {
      pl = (hb_link_t *)l;
      switch(cr) {
        case 0: {
	  pr = (hb_link_t *)r;
	  back = dk3str_cmp(pl->url, pr->url);
	} break;
	case 1: {
	  back = dk3str_cmp(pl->url, (dkChar const *)r);
	} break;
	default: {
	  pr = (hb_link_t *)r;
	  if(pl->lno > pr->lno) {
	    back = 1;
	  } else {
	    if(pl->lno < pr->lno) {
	      back = -1;
	    }
	  }
	} break;
      }
      if(-1 > back) { back = -1; }
      if( 1 < back) { back =  1; }
    } else back = 1;
  } else {
    if(r) back = -1;
  } 

#line 166 "hbnode.ctr"
  return back;
}



int
hb_node_compare(void const *l, void const *r, int DK3_ARG_UNUSED(cr) )
{
  hb_node_t const	*pl;
  hb_node_t const	*pr;
  int			 back = 0;
  

#line 178 "hbnode.ctr"
  DK3_UNUSED_ARG(cr)
  if(l) {
    if(r) {
      pl = (hb_node_t const *)l;
      pr = (hb_node_t const *)r;
      if(pl->objno > pr->objno) {
        back = 1;
      } else {
        if(pr->objno > pl->objno) {
	  back = -1;
	}
      }
    } else {
      back = 1;
    }
  } else {
    if(r) {
      back = -1;
    }
  } 

#line 198 "hbnode.ctr"
  return back;
}



void
hb_node_delete(hb_node_t *ptr)
{
  hb_link_t		*linkptr;
  hb_line_t		*hp;
  dk3_key_value_t	*kp;
  if(ptr) {
    

#line 211 "hbnode.ctr"
    if(ptr->s_lbylno) {
      if(ptr->i_lbylno) {
        dk3sto_it_close(ptr->i_lbylno);
      }
      dk3sto_close(ptr->s_lbylno);
    }
    ptr->s_lbylno = NULL; ptr->i_lbylno = NULL;
    if(ptr->s_lbyurl) {
      if(ptr->i_lbyurl) {
        dk3sto_it_reset(ptr->i_lbyurl);
	while(NULL != (linkptr = (hb_link_t *)dk3sto_it_next(ptr->i_lbyurl))) {
	  hbnode_link_delete(linkptr);
	}
        dk3sto_it_close(ptr->i_lbyurl);
      }
      dk3sto_close(ptr->s_lbyurl);
    }
    ptr->s_lbyurl = NULL; ptr->i_lbyurl = NULL;
    if(ptr->s_lines) {
      if(ptr->i_lines) {
        dk3sto_it_reset(ptr->i_lines);
	while(NULL != (hp = (hb_line_t *)dk3sto_it_next(ptr->i_lines))) {
	  hbcont_line_delete(hp);
	}
        dk3sto_it_close(ptr->i_lines);
      }
      dk3sto_close(ptr->s_lines);
    } ptr->s_lines = NULL; ptr->i_lines = NULL;
    if(ptr->s_variables) {
      if(ptr->i_variables) {
        dk3sto_it_reset(ptr->i_variables);
	do {
	  kp = (dk3_key_value_t *)dk3sto_it_next(ptr->i_variables);
	  if(kp) { dk3kv_delete(kp); }
	} while(kp);
        dk3sto_it_close(ptr->i_variables);
      }
      dk3sto_close(ptr->s_variables);
    }
    ptr->s_variables = NULL; ptr->i_variables = NULL;
    if(ptr->s_jsfiles) {
      if(ptr->i_jsfiles) {
        dk3sto_it_reset(ptr->i_jsfiles);
	while(NULL != (linkptr = (hb_link_t *)dk3sto_it_next(ptr->i_jsfiles))) {
	  

#line 256 "hbnode.ctr"
	  hbnode_link_delete(linkptr);
	}
        dk3sto_it_close(ptr->i_jsfiles);
      }
      dk3sto_close(ptr->s_jsfiles);
    } ptr->s_jsfiles = NULL; ptr->i_jsfiles = NULL;
    /*	We can simply close the storage here, all nodes are listed
    	in the s_nodes storage of the job structure.
    */
    if(ptr->s_subnodes) {		
      if(ptr->i_subnodes) {
        dk3sto_it_close(ptr->i_subnodes);
      }
      dk3sto_close(ptr->s_subnodes);
    }
    ptr->s_subnodes = NULL;
    ptr->i_subnodes = NULL;
    ptr->parent = NULL;
    ptr->curchild = NULL;
    ptr->jumpnode = NULL;
#if TRACE_DEBUG
    

#line 278 "hbnode.ctr"
    

#line 279 "hbnode.ctr"
    

#line 280 "hbnode.ctr"
    

#line 281 "hbnode.ctr"
    if(ptr->parent) {	

#line 282 "hbnode.ctr"
    }
    if(ptr->title) {	

#line 284 "hbnode.ctr"
    }
    if(ptr->shorttitle) {	

#line 286 "hbnode.ctr"
    }
    if(ptr->fulltitle) {	

#line 288 "hbnode.ctr"
    }
    if(ptr->filename) {	

#line 290 "hbnode.ctr"
    }
    if(ptr->suffix) {	

#line 292 "hbnode.ctr"
    }
    if(ptr->templatefi) {	

#line 294 "hbnode.ctr"
    }
    if(ptr->stylefile) {	

#line 296 "hbnode.ctr"
    }
    if(ptr->author) {	

#line 298 "hbnode.ctr"
    }
    if(ptr->location) {	

#line 300 "hbnode.ctr"
    }
    if(ptr->icontoc) {	

#line 302 "hbnode.ctr"
    }
    if(ptr->iconprev) {	

#line 304 "hbnode.ctr"
    }
    if(ptr->iconnext) {	

#line 306 "hbnode.ctr"
    }
    if(ptr->iconhome) {	

#line 308 "hbnode.ctr"
    }
    if(ptr->iconindex) {	

#line 310 "hbnode.ctr"
    }
    if(ptr->favicon) {	

#line 312 "hbnode.ctr"
    }
    if(ptr->metadesc) {	

#line 314 "hbnode.ctr"
    }
    if(ptr->metakeyw) {	

#line 316 "hbnode.ctr"
    }
#endif
    dk3_release(ptr->title);
    dk3_release(ptr->shorttitle);
    dk3_release(ptr->fulltitle);
    dk3_release(ptr->filename);
    dk3_release(ptr->suffix);
    dk3_release(ptr->templatefi);
    dk3_release(ptr->stylefile);
    dk3_release(ptr->author);
    dk3_release(ptr->location);
    dk3_release(ptr->icontoc);
    dk3_release(ptr->iconprev);
    dk3_release(ptr->iconnext);
    dk3_release(ptr->iconindex);
    dk3_release(ptr->iconhome);
    dk3_release(ptr->favicon);
    dk3_release(ptr->metadesc);
    dk3_release(ptr->metakeyw);
    ptr->lineno = 0UL;
    ptr->objno = 0UL;
    ptr->indent = 0;
    ptr->inenc = 0;
    ptr->options = 0U;
    ptr->havenavimenu = 0;
    dk3_delete(ptr);
    

#line 343 "hbnode.ctr"
  }
}



/**	Find depth of a node.
	@param	ptr	Node to inspect.
	@return	Node depth.
*/
static
int
hbnode_find_depth(hb_node_t *ptr)
{
  int		 back = 0;
  

#line 358 "hbnode.ctr"
  ptr = ptr->parent;
  while(ptr) {
    back++;
    ptr = ptr->parent;
  } 

#line 363 "hbnode.ctr"
  return back;
}



hb_node_t *
hb_node_new(
  hb_job_t		*job,
  hb_node_t		*parent,
  unsigned long		 lineno,
  unsigned long		 objno,
  int			 indent
)
{
  hb_node_t		*back	= NULL;
  int			 ok	= 0;
  

#line 380 "hbnode.ctr"
  back = dk3_new_app(hb_node_t,1,job->app);
  if(back) {
    back->parent = parent;
    back->curchild = NULL;
    back->jumpnode = NULL;
    back->s_subnodes = NULL;
    back->i_subnodes = NULL;
    back->s_variables = NULL;
    back->i_variables = NULL;
    back->s_lines = NULL;
    back->i_lines = NULL;
    back->s_lbyurl = NULL;
    back->i_lbyurl = NULL;
    back->s_lbylno = NULL;
    back->i_lbylno = NULL;
    back->s_jsfiles = NULL;
    back->i_jsfiles = NULL;
    back->title = NULL;
    back->shorttitle = NULL;
    back->fulltitle = NULL;
    back->filename = NULL;
    back->suffix = NULL;
    back->templatefi = NULL;
    back->stylefile = NULL;
    back->author = NULL;
    back->location = NULL;
    back->icontoc = NULL;
    back->iconprev = NULL;
    back->iconnext = NULL;
    back->iconindex = NULL;
    back->iconhome = NULL;
    back->favicon = NULL;
    back->metadesc = NULL;
    back->metakeyw = NULL;
    back->lineno = lineno;
    back->objno = objno;
    back->pobjno = 0UL;
    back->nextlink = 0UL;
    back->nextindex = 0UL;
    back->outFileName = NULL;
    back->headno = 0UL;
    back->nextsubheadno = 0UL;
    back->nextjs = 0UL;
    back->contnum = 0L;
    back->havenavimenu = 0;
    back->htdt = HTML_DOCTYPE_UNSPECIFIED;
    /* back->inenc = -1; */
    if(parent) {
      back->inenc = parent->inenc;
    } else {
      back->inenc = job->iecmd;
    }
    /*	As each node is configured after the parent is finished we can
    	implement option inheritance by simply copying the parents options.
    */
    back->options = 0U; if(parent) { back->options = parent->options; }
    back->indent = indent;
    back->depth = 0;
    back->tocstate = HB_TOC_STATE_INIT;
    back->s_subnodes = dk3sto_open_app(job->app);
    if(back->s_subnodes) {
      dk3sto_set_comp(back->s_subnodes, hb_node_compare, 0);
      back->i_subnodes = dk3sto_it_open(back->s_subnodes);
      if(back->i_subnodes) {
        back->s_variables = dk3sto_open_app(job->app);
	if(back->s_variables) {
	  dk3sto_set_comp(back->s_variables, dk3kv_compare, 0);
	  back->i_variables = dk3sto_it_open(back->s_variables);
	  if(back->i_variables) {
	    back->s_lbyurl = dk3sto_open_app(job->app);
	    if(back->s_lbyurl) {
	      dk3sto_set_comp(back->s_lbyurl, hbnode_link_compare, 0);
	      back->i_lbyurl = dk3sto_it_open(back->s_lbyurl);
	      if(back->i_lbyurl) {
	        back->s_lbylno = dk3sto_open_app(job->app);
		if(back->s_lbylno) {
		  dk3sto_set_comp(back->s_lbylno, hbnode_link_compare, 2);
		  back->i_lbylno = dk3sto_it_open(back->s_lbylno);
		  if(back->i_lbylno) {
		    ok = 1;
		  }
		}
	      }
	    }
	  }
	}
      }
    }
    if(!(ok)) {
      hb_node_delete(back);
      back = NULL;
    }
    if(back) {
      back->depth = hbnode_find_depth(back);
    }
  } 

#line 476 "hbnode.ctr"
  return back;
}



dkChar const *
hbnode_variable(hb_node_t *node, dkChar const *name)
{
  dk3_key_value_t	*kvp;
  dkChar const		*back	= NULL;
  int			 cc	= 1;
  

#line 488 "hbnode.ctr"
  if((node) && (name)) {
    while(cc) {
      if(node) {
        kvp = (dk3_key_value_t *)dk3sto_it_find_like(node->i_variables,name,1);
	if(kvp) {
	  cc = 0;
	  back = kvp->val;
	} else {
	  node = node->parent;
	}
      } else {
        cc = 0;
      }
    }
  } 

#line 503 "hbnode.ctr"
  return back;
}