Skip to content

Commit ab25cfb

Browse files
committed
Rewrite the document_stack modules
document_stack now takes a void pointer, but perhaps this module will be deleted in favour of a more procedural approach based on state machines.
1 parent 19b101b commit ab25cfb

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

include/html_parser_document_stack.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef __document_stack_included__
22
#define __document_stack_included__
33

4-
#include "html_parser_document_node.h"
5-
64
#ifdef __cplusplus
75
extern "C" {
86
#endif
@@ -12,11 +10,11 @@ typedef struct T *T;
1210

1311
extern T Stack_stack(void);
1412
extern int Stack_empty(T stk);
15-
extern void Stack_push(T stk, Node_T *n);
16-
extern Node_T *Stack_peek(T stk);
17-
extern int Stack_find(T stk, const char *tag_name);
18-
extern Node_T *Stack_pop(T stk);
19-
extern void Stack_free(T *Stk);
13+
extern void Stack_push(T stk, void *n);
14+
extern void *Stack_peek(T stk);
15+
// extern int Stack_find(T stk, const char *tag_name);
16+
extern void *Stack_pop(T stk);
17+
extern void Stack_free(T *stk);
2018

2119
#undef T
2220
#ifdef __cplusplus

src/html_parser_document_stack.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
struct T {
1111
int count;
1212
struct elem {
13-
Node_T *n;
13+
void *n;
1414
struct elem *link;
1515
} *head;
1616
};
@@ -33,7 +33,7 @@ int Stack_empty(T stk)
3333
return (stk->count == 0);
3434
}
3535

36-
void Stack_push(T stk, Node_T *n)
36+
void Stack_push(T stk, void *n)
3737
{
3838
struct elem *t;
3939

@@ -45,37 +45,37 @@ void Stack_push(T stk, Node_T *n)
4545
stk->count++;
4646
}
4747

48-
Node_T *Stack_peek(T stk)
48+
void *Stack_peek(T stk)
4949
{
5050
assert(stk);
5151
assert(stk->count > 0);
5252

5353
return stk->head->n;
5454
}
5555

56-
int Stack_find(T stk, const char *tag_name)
57-
{
58-
int index = 0; /* 0 : not found */
56+
/*int Stack_find(T stk, const char *tag_name)*/
57+
/*{*/
58+
/*int index = 0; [> 0 : not found <]*/
5959

60-
assert(stk);
60+
/*assert(stk);*/
6161

62-
if (!Stack_empty(stk)) {
63-
struct elem *t = stk->head;
62+
/*if (!Stack_empty(stk)) {*/
63+
/*struct elem *t = stk->head;*/
6464

65-
while (index++ < stk->count) {
66-
if (tag_name == Node_name(*t->n))
67-
break;
65+
/*while (index++ < stk->count) {*/
66+
/*if (tag_name == Node_name(*t->n))*/
67+
/*break;*/
6868

69-
t = t->link;
70-
}
71-
}
69+
/*t = t->link;*/
70+
/*}*/
71+
/*}*/
7272

73-
index = (index > stk->count) ? 0 : index;
73+
/*index = (index > stk->count) ? 0 : index;*/
7474

75-
return index;
76-
}
75+
/*return index;*/
76+
/*}*/
7777

78-
Node_T *Stack_pop(T stk)
78+
void *Stack_pop(T stk)
7979
{
8080
Node_T *n;
8181
struct elem *t;

tests/html_parser_document_stack_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int Test_stack_stack(T t, void *, const void *);
2323
static int Test_stack_empty(T t, void *, const void *);
2424
static int Test_stack_push(T t, void *, const void *);
2525
static int Test_stack_peek(T t, void *, const void *);
26-
static int Test_stack_find(T t, void *, const void *);
26+
// static int Test_stack_find(T t, void *, const void *);
2727
static int Test_stack_pop(T t, void *, const void *);
2828
static int Test_stack_free(T t, void *, const void *);
2929

@@ -47,8 +47,8 @@ int main(int argc, const char *argv[])
4747
(const void *) nodes);
4848
Test_add(suite, Test_stack_peek, PREV_INPUT(suite),
4949
(const void *) nodes);
50-
Test_add(suite, Test_stack_find, PREV_INPUT(suite),
51-
(const void *) st);
50+
// Test_add(suite, Test_stack_find, PREV_INPUT(suite),
51+
// (const void *) st);
5252
Test_add(suite, Test_stack_pop, PREV_INPUT(suite),
5353
(const void *) nodes);
5454
Test_add(suite, Test_stack_free, PREV_INPUT(suite), NULL);

0 commit comments

Comments
 (0)