@@ -327,6 +327,105 @@ parser_list_iterator_next (parser_list_iterator_t *iterator_p) /**< iterator */
327
327
return result ;
328
328
} /* parser_list_iterator_next */
329
329
330
+ /*
331
+ * Init branch linked list.
332
+ */
333
+ void
334
+ parser_branch_list_init (parser_context_t * context_p )
335
+ {
336
+ context_p -> branch_list = (parser_branch_list_t * ) parser_malloc (context_p , sizeof (parser_branch_list_t ));
337
+ context_p -> branch_list -> branch_node_p = NULL ;
338
+ context_p -> branch_list -> next_p = NULL ;
339
+ } /* parser_branch_list_init */
340
+
341
+ /**
342
+ * Append a branch node to the branch list.
343
+ *
344
+ * @return the newly created branch node.
345
+ */
346
+ void *
347
+ parser_branch_list_append (parser_context_t * context_p )
348
+ {
349
+ parser_branch_node_t * result = parser_malloc (context_p , sizeof (parser_branch_node_t ));
350
+
351
+ if (result == NULL )
352
+ {
353
+ return NULL ;
354
+ }
355
+
356
+ parser_branch_list_t * last_pos = context_p -> branch_list ;
357
+ while (last_pos -> next_p != NULL )
358
+ {
359
+ last_pos = last_pos -> next_p ;
360
+ }
361
+
362
+ last_pos -> next_p = (parser_branch_list_t * ) parser_malloc (context_p , sizeof (parser_branch_list_t ));
363
+ last_pos -> next_p -> branch_node_p = result ;
364
+ last_pos -> next_p -> next_p = NULL ;
365
+
366
+ return result ;
367
+ } /* parser_branch_list_append */
368
+
369
+ /**
370
+ * Remove a branch node from the branch list.
371
+ */
372
+ void
373
+ parser_branch_list_remove (const parser_context_t * context_p , const parser_branch_node_t * node_p )
374
+ {
375
+ parser_branch_list_t * pos = context_p -> branch_list ;
376
+ parser_branch_list_t * prev_pos = NULL ;
377
+
378
+ while (pos -> next_p != NULL && pos -> branch_node_p != node_p )
379
+ {
380
+ prev_pos = pos ;
381
+ pos = pos -> next_p ;
382
+ }
383
+
384
+ if (pos -> branch_node_p != node_p )
385
+ {
386
+ return ;
387
+ }
388
+
389
+ parser_branch_list_t * next_pos = pos -> next_p ;
390
+
391
+ parser_free (pos -> branch_node_p , sizeof (parser_branch_node_t ));
392
+
393
+ if (prev_pos == NULL && next_pos == NULL )
394
+ {
395
+ context_p -> branch_list -> branch_node_p = NULL ;
396
+ return ;
397
+ }
398
+
399
+ parser_free (pos , sizeof (parser_branch_list_t ));
400
+
401
+ if (prev_pos != NULL )
402
+ {
403
+ prev_pos -> next_p = next_pos ;
404
+ }
405
+ } /* parser_branch_list_remove */
406
+
407
+ /**
408
+ * Free the branch list.
409
+ */
410
+ void
411
+ parser_branch_list_free (const parser_context_t * context_p )
412
+ {
413
+ parser_branch_list_t * pos = context_p -> branch_list ;
414
+ parser_branch_list_t * prev_pos = NULL ;
415
+
416
+ while (pos != NULL )
417
+ {
418
+ prev_pos = pos ;
419
+ pos = pos -> next_p ;
420
+ if (prev_pos -> branch_node_p != NULL )
421
+ {
422
+ parser_free (prev_pos -> branch_node_p , sizeof (parser_branch_node_t ));
423
+ }
424
+
425
+ parser_free (prev_pos , sizeof (parser_branch_list_t ));
426
+ }
427
+ } /* parser_branch_list_free */
428
+
330
429
/**********************************************************************/
331
430
/* Parser stack management functions */
332
431
/**********************************************************************/
0 commit comments