polygon intersector: added horizontal line reconstruction
[swftools.git] / lib / gocr / list.h
1 /*
2 This is a Optical-Character-Recognition program
3 Copyright (C) 2000  Joerg Schulenburg
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19  see README for EMAIL-address
20  
21  */
22
23 #ifndef GOCR_LIST_H
24 #define GOCR_LIST_H
25
26 #ifdef DEBUG
27 #define g_debug(a)      a
28 #else
29 #define g_debug(a)      
30 #endif
31
32 /*
33  * Structures
34  */
35  
36 struct element {
37    struct element *next, *previous;
38    void *data;
39 };
40 typedef struct element Element;
41
42 struct list {
43    Element start;               /* simplifies for(each_element) { ... */
44    Element stop;                /*   ... list_del() ... }  v0.41      */
45    Element **current;           /* for(each_element) */
46    int n;                       /* number of elements */
47    int level;                   /* level of nested fors */
48 };
49 typedef struct list List;
50
51 /*
52  * Functions
53  */
54
55 void    list_init               ( List *l );
56 int     list_app                ( List *l, void *data );
57 int     list_ins                ( List *l, void *data_after, void *data);
58 Element*list_element_from_data  ( List *l, void *data );
59 int     list_del                ( List *l, void *data );
60 void    list_free               ( List *l );
61 int     list_and_data_free      ( List *l, void (*free_data)(void *data));
62 int     list_higher_level       ( List *l );
63 void    list_lower_level        ( List *l );
64 void *  list_next               ( List *l, void *data );
65 void *  list_prev               ( List *l, void *data );
66 void    list_sort               ( List *l, int (*compare)(const void *, const void *) );
67
68 #define list_empty(l)                   ((l)->start.next == &(l)->stop ? 1 : 0)
69 #define list_get_header(l)              ((l)->start.next->data)
70 #define list_get_tail(l)                ((l)->stop.previous->data)
71 #define list_get_current(l)             ((l)->current[(l)->level]->data)
72 #define list_get_cur_prev(l)            ((l)->current[(l)->level]->previous == NULL ? \
73                         NULL : (l)->current[(l)->level]->previous->data )
74 #define list_get_cur_next(l)            ((l)->current[(l)->level]->next == NULL ? \
75                         NULL : (l)->current[(l)->level]->next->data )
76 #define list_total(l)                   ((l)->n)
77
78 #define for_each_data(l)                \
79  if (list_higher_level(l) == 0) { \
80    for ( ; (l)->current[(l)->level] \
81         && (l)->current[(l)->level]!=&(l)->stop; (l)->current[(l)->level] = \
82         (l)->current[(l)->level]->next ) {
83
84
85 #define end_for_each(l)                 \
86    } \
87  list_lower_level(l); \
88  }
89
90 #endif