\section{aversive\_\-10-03-12/include/aversive/list.h File Reference}
\label{include_2aversive_2list_8h}\index{aversive\_\-10-03-12/include/aversive/list.h@{aversive\_\-10-03-12/include/aversive/list.h}}
{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$aversive.h$>$}\par
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf list\_\-hdr}
\item 
struct {\bf generic\_\-list}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf LIST\_\-DEBUG}~0
\item 
\#define {\bf WOVERWRAPPED}~-1
\item 
\#define {\bf CR}~\char`\"{}$\backslash$r$\backslash$n\char`\"{}
\item 
\#define {\bf LIST\_\-TYPEDEF}(typename, elttype, size)
\item 
\#define {\bf LIST\_\-INIT}(list, beginning)
\item 
\#define {\bf LIST\_\-FULL}(list)~(list.hdr.size == list.hdr.cur\_\-size)
\item 
\#define {\bf LIST\_\-EMPTY}(list)~(list.hdr.cur\_\-size == 0)
\item 
\#define {\bf LIST\_\-CURSIZE}(list)~(list.hdr.cur\_\-size)
\item 
\#define {\bf LIST\_\-SIZE}(list)~(list.hdr.size)
\item 
\#define {\bf LIST\_\-FREESIZE}(list)~(list.hdr.size-list.hdr.cur\_\-size)
\item 
\#define {\bf LIST\_\-READ\_\-START}(list, elt\_\-p)
\item 
\#define {\bf LIST\_\-READ\_\-END}(list, elt\_\-p)
\item 
\#define {\bf LIST\_\-READ\_\-GOTO}(list, elt\_\-p, {\bf i})
\item 
\#define {\bf LIST\_\-READ\_\-MOVE}(list, elt\_\-p, {\bf i})
\item 
\#define {\bf LIST\_\-READ}(list, elt\_\-p)
\item 
\#define {\bf LIST\_\-PUSH\_\-START}(list, e)
\item 
\#define {\bf LIST\_\-PUSH\_\-END}(list, e)
\item 
\#define {\bf LIST\_\-PULL\_\-START}(list, elt\_\-p)
\item 
\#define {\bf LIST\_\-PULL\_\-END}(list, elt\_\-p)
\item 
\#define {\bf LIST\_\-ARRAY\_\-PUSH\_\-START}(list, array, nb)
\item 
\#define {\bf LIST\_\-ARRAY\_\-PUSH\_\-END}(list, array, nb)
\item 
\#define {\bf LIST\_\-ARRAY\_\-PULL\_\-START}(list, array, nb)
\item 
\#define {\bf LIST\_\-ARRAY\_\-PULL\_\-END}(list, array, nb)
\item 
\#define {\bf LIST\_\-TO\_\-ARRAY}(list, array, nb)
\item 
\#define {\bf LIST\_\-ALIGN\_\-LEFT}(list)
\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
struct {\bf list\_\-hdr} {\bf packed}
\end{CompactItemize}


\subsection{Define Documentation}
\index{include/aversive/list.h@{include/aversive/list.h}!CR@{CR}}
\index{CR@{CR}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[CR]{\setlength{\rightskip}{0pt plus 5cm}\#define CR~\char`\"{}$\backslash$r$\backslash$n\char`\"{}}\label{include_2aversive_2list_8h_876ce77f3c672c7162658151e648389e}




Definition at line 264 of file list.h.

Referenced by dumplist(), and main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-ALIGN\_\-LEFT@{LIST\_\-ALIGN\_\-LEFT}}
\index{LIST\_\-ALIGN\_\-LEFT@{LIST\_\-ALIGN\_\-LEFT}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-ALIGN\_\-LEFT]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-ALIGN\_\-LEFT(list)}\label{include_2aversive_2list_8h_71d0c53b6563274e286a97f68a7529f3}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
uint8_t __ret=0, __i; \
if(list.hdr.beg_indice != 0) { \
        if(list.hdr.beg_indice+list.hdr.cur_size <= list.hdr.size) { \
                for(__i=0 ; __i<list.hdr.cur_size ; __i++) { \
                        list.elt[__i] = list.elt[__i+list.hdr.beg_indice]; \
                } \
        } \
        else { \
          uint8_t buffer_size=(list.hdr.size - list.hdr.beg_indice < (list.hdr.cur_size + list.hdr.beg_indice)%list.hdr.size) ? \
                           (list.hdr.size - list.hdr.beg_indice) * sizeof(list.elt[0]) : \
                              ((list.hdr.cur_size + list.hdr.beg_indice)%list.hdr.size) * sizeof(list.elt[0]); \
                     { \
                                uint8_t buffer[buffer_size]; \
                                memcpy(buffer, list.elt, buffer_size); \
                                for(__i=0 ; __i<(list.hdr.cur_size - buffer_size/sizeof(list.elt[0])) ; __i++) { \
                                        list.elt[__i] = list.elt[__i+list.hdr.beg_indice]; \
                                } \
                                memcpy(&list.elt[list.hdr.cur_size - buffer_size/sizeof(list.elt[0])], buffer, buffer_size); \
                } \
        } \
 list.hdr.beg_indice=0; \
} \
 if(LIST_DEBUG) \
   printf("LIST_ALIGN_LEFT()"CR); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 504 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-ARRAY\_\-PULL\_\-END@{LIST\_\-ARRAY\_\-PULL\_\-END}}
\index{LIST\_\-ARRAY\_\-PULL\_\-END@{LIST\_\-ARRAY\_\-PULL\_\-END}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-ARRAY\_\-PULL\_\-END]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-ARRAY\_\-PULL\_\-END(list, \/  array, \/  nb)}\label{include_2aversive_2list_8h_52240d3c3bb490d2fda6884a3b5deeb8}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 uint8_t __ret=0; \
 int8_t __i; \
 for(__i=nb-1 ; (__i>=0) && (!__ret) ; __i--) { \
    __ret=LIST_PULL_END(list, (array+__i)); \
 } \
 if(LIST_DEBUG) \
   printf("LIST_ARRAY_PULL_END(%s, %s, %d) -> ret %d"CR,#list, #array, nb, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 479 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-ARRAY\_\-PULL\_\-START@{LIST\_\-ARRAY\_\-PULL\_\-START}}
\index{LIST\_\-ARRAY\_\-PULL\_\-START@{LIST\_\-ARRAY\_\-PULL\_\-START}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-ARRAY\_\-PULL\_\-START]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-ARRAY\_\-PULL\_\-START(list, \/  array, \/  nb)}\label{include_2aversive_2list_8h_088a7b33bb52226baf2f723d2e259aa3}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 uint8_t __ret=0, __i; \
 for(__i=0 ; (__i<nb) && (!__ret) ; __i++) { \
    __ret=LIST_PULL_START(list, (array+__i)); \
 } \
 if(LIST_DEBUG) \
   printf("LIST_ARRAY_PULL_START(%s, %s, %d) -> ret %d"CR,#list, #array, nb, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 469 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-ARRAY\_\-PUSH\_\-END@{LIST\_\-ARRAY\_\-PUSH\_\-END}}
\index{LIST\_\-ARRAY\_\-PUSH\_\-END@{LIST\_\-ARRAY\_\-PUSH\_\-END}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-ARRAY\_\-PUSH\_\-END]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-ARRAY\_\-PUSH\_\-END(list, \/  array, \/  nb)}\label{include_2aversive_2list_8h_b800546a3f1b23c068edb67e9cdfa7d0}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 uint8_t __ret=0, __i; \
 for(__i=0 ; (__i<nb) && (!__ret) ; __i++) { \
    __ret=LIST_PUSH_END(list, array[__i]); \
 } \
 if(LIST_DEBUG) \
   printf("LIST_ARRAY_PUSH_END(%s, %s, %d) -> ret %d"CR,#list, #array, nb, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 459 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-ARRAY\_\-PUSH\_\-START@{LIST\_\-ARRAY\_\-PUSH\_\-START}}
\index{LIST\_\-ARRAY\_\-PUSH\_\-START@{LIST\_\-ARRAY\_\-PUSH\_\-START}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-ARRAY\_\-PUSH\_\-START]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-ARRAY\_\-PUSH\_\-START(list, \/  array, \/  nb)}\label{include_2aversive_2list_8h_c93214b3b997470df59ad2dc788bac7a}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 uint8_t __ret=0; \
 int8_t __i; \
 for(__i=nb-1 ; (__i>=0) && (!__ret) ; __i--) { \
    __ret=LIST_PUSH_START(list, array[__i]); \
 } \
 if(LIST_DEBUG) \
   printf("LIST_ARRAY_PUSH_START(%s, %s, %d) -> ret %d"CR,#list, #array, nb, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 448 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-CURSIZE@{LIST\_\-CURSIZE}}
\index{LIST\_\-CURSIZE@{LIST\_\-CURSIZE}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-CURSIZE]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-CURSIZE(list)~(list.hdr.cur\_\-size)}\label{include_2aversive_2list_8h_85c30c3a28e547b9975ecfd3cfca54aa}


return current size of the list (number of used elements) 

Definition at line 320 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-DEBUG@{LIST\_\-DEBUG}}
\index{LIST\_\-DEBUG@{LIST\_\-DEBUG}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-DEBUG]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-DEBUG~0}\label{include_2aversive_2list_8h_7d0676759a0658dfcd378b4be750e829}


This header file provides LISTs implemented in tables. Don't use list size $>$ 127.

WARNING --------------------- This header file will probably be deprecated in a soon. future. Consider using the 'cirbuf' module (circular buffer) instead. Indeed, the full-macro implementation of this header file is not the most efficient in terms of code size.... :) WARNING ---------------------

Header ------

struct \doxyref{list\_\-hdr}{p.}{structlist__hdr} \{ u08 size; $<$ The size of the fifo u08 cur\_\-size; $<$ number of data in the fifo u08 beg\_\-indice; $<$ indice of the first elt u08 read\_\-cursor; $<$ read cursor \} \_\-\_\-attribute\_\-\_\- ((packed));

--------------------------------------------- I I I I I I size IcursizeI beg I rcurs I elements ... I I I I I ---------------------------------------------

$<$-------------------------------$>$ \doxyref{list\_\-hdr}{p.}{structlist__hdr}

Data ----

Data are stored in a circular buffer, beginning is specified by beg\_\-indice in header.

Type ----

For example, the type of a list of u08 with 10 elements is :

struct list\_\-u08\_\-10 \{ struct \doxyref{list\_\-hdr}{p.}{structlist__hdr} hdr; u08 elt[10]; \}

\begin{itemize}
\item With this example, an empty list is : size = 10 cursize = 0 beg = X curs = X\end{itemize}


\begin{itemize}
\item A full list : size = 10 cursize = 10 beg = X curs = X\end{itemize}


Functions \& Macros ------------------

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ Define and init

LIST\_\-TYPE(typename, elttype, size) -$>$ define type :

define LIST\_\-TYPE(typename, elttype, size) typedef struct typename \{ struct \doxyref{list\_\-hdr}{p.}{structlist__hdr} hdr; elttype elt[size]; \} typename;

\doxyref{LIST\_\-INIT(list, beginning)}{p.}{queue_8h_304b5b7f7bdcba2793eaba9c890991c3} -$>$ flushes the list, and set size and beginning

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ Control

u08 \doxyref{LIST\_\-FULL(list)}{p.}{include_2aversive_2list_8h_6c4ba0ce0af3de21dbdf47f11dc3a3e6} u08 \doxyref{LIST\_\-EMPTY(list)}{p.}{queue_8h_f59ab30a8f9a88af86422600c38125cf}

u08 \doxyref{LIST\_\-READ\_\-GOTO($\ast$elt, list, i)}{p.}{include_2aversive_2list_8h_e090a281a86e4df84ec3ad5387d25f67} -$>$ place the read cursor at position i (0 means the beginning of the list) and set the elt if pointer not NULL

u08 LIST\_\-READ\_\-LEFT($\ast$elt, list, i) -$>$ move the read cursor left by i u08 LIST\_\-READ\_\-RIGHT($\ast$elt, list, i) -$>$ move the read cursor right by i u08 \doxyref{LIST\_\-READ\_\-START($\ast$elt, list)}{p.}{include_2aversive_2list_8h_22528a37226c653a410fb1c0f7376aed} u08 \doxyref{LIST\_\-READ\_\-END($\ast$elt, list)}{p.}{include_2aversive_2list_8h_0a426e7d798e61d330978b533a6e954d}

Examples :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 3 2 3 X X A B C X

we do LIST\_\-READ\_\-LEFT(NULL, x,x, 1) :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 3 2 2 X X A B C X

we do LIST\_\-READ\_\-LEFT(NULL, x,x, 1), but return 1 instead of 0 because we overwrapped :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 3 4 4 X X A B C X

we do \doxyref{LIST\_\-READ\_\-GOTO(NULL, x,x, 0)}{p.}{include_2aversive_2list_8h_e090a281a86e4df84ec3ad5387d25f67} :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 3 4 2 X X A B C X

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ accesses modifying the list

u08 \doxyref{LIST\_\-PUSH\_\-START(elt, list)}{p.}{include_2aversive_2list_8h_c6f34994653a385f2e36b9f61e58fdcc} -$>$ add at the beginning (prepend) u08 \doxyref{LIST\_\-PUSH\_\-END(elt, list)}{p.}{include_2aversive_2list_8h_aaf0cd0f53a301b86976f1b3d67f3c12} -$>$ add at the end (append) u08 \doxyref{LIST\_\-PULL\_\-START(elt $\ast$, list)}{p.}{include_2aversive_2list_8h_c59bb004986a29bf2b22cf2aed52cf79} -$>$ del at the beginning u08 \doxyref{LIST\_\-PULL\_\-END(elt $\ast$, list)}{p.}{include_2aversive_2list_8h_757252bd716b870d67130ac25ce68496} -$>$ del at the end

u08 \doxyref{LIST\_\-ARRAY\_\-PUSH\_\-START($\ast$elt, list, n)}{p.}{include_2aversive_2list_8h_c93214b3b997470df59ad2dc788bac7a} -$>$ prepend n elts from elt pointer u08 \doxyref{LIST\_\-ARRAY\_\-PUSH\_\-END($\ast$elt, list, n)}{p.}{include_2aversive_2list_8h_b800546a3f1b23c068edb67e9cdfa7d0} -$>$ append n elts u08 \doxyref{LIST\_\-ARRAY\_\-PULL\_\-START(elt $\ast$, list, n)}{p.}{include_2aversive_2list_8h_088a7b33bb52226baf2f723d2e259aa3} -$>$ del n elts from buffer u08 \doxyref{LIST\_\-ARRAY\_\-PULL\_\-END(elt $\ast$, list, n)}{p.}{include_2aversive_2list_8h_52240d3c3bb490d2fda6884a3b5deeb8} -$>$ del at the end

Examples :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 4 2 3 X X B C D E

we do \doxyref{LIST\_\-PUSH\_\-START(A, l, u08)}{p.}{include_2aversive_2list_8h_c6f34994653a385f2e36b9f61e58fdcc} :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 5 1 3 X A B C D E

we do \doxyref{LIST\_\-PUSH\_\-END(F, l, u08)}{p.}{include_2aversive_2list_8h_aaf0cd0f53a301b86976f1b3d67f3c12} :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 6 1 3 F A B C D E

we do \doxyref{LIST\_\-PUSH\_\-END(X, l, u08)}{p.}{include_2aversive_2list_8h_aaf0cd0f53a301b86976f1b3d67f3c12} -$>$ return -1

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ Accesses NOT modifying the list

u08 \doxyref{LIST\_\-FIRST(elt $\ast$, list)}{p.}{queue_8h_8f223070a7fe7c5f24033e9d8fbeb610} -$>$ Return the first elt u08 LIST\_\-LAST(elt $\ast$, list) -$>$ Return the last elt

u08 \doxyref{LIST\_\-READ(elt $\ast$, list)}{p.}{include_2aversive_2list_8h_a3aaecb4f9272edffe3a7e79f5cde1a8} -$>$ Return the elt pointed by the read cursor

u08 LIST\_\-ARRAY\_\-READ(elt $\ast$, list, n) -$>$ reads n elts from read cursor

u08 LIST\_\-READ\_\-GET\_\-PTR(list) -$>$ return a pointer to the read cursor. Warning, perhaps you need to do LIST\_\-ALIGN\_\-XXXX() before

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ loop functions

define \doxyref{LIST\_\-FOREACH(list, elt)}{p.}{queue_8h_c1543beeb6d9224b60feb7a2703b2a87} for( u08 ret = \doxyref{LIST\_\-READ\_\-START(elt, list)}{p.}{include_2aversive_2list_8h_22528a37226c653a410fb1c0f7376aed} ; ret == 0 ; ret = LIST\_\-READ\_\-RIGHT($\ast$elt, list, 1) )

$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$ Alignement functions

these functions can by quite long to execute. If possible, try to avoid using them by choosing a good place for the beg\_\-indice when calling init of list. If you need it, prefer using LIST\_\-ALIGN\_\-CONTINUOUS if possible.

u08 \doxyref{LIST\_\-ALIGN\_\-LEFT(list)}{p.}{include_2aversive_2list_8h_71d0c53b6563274e286a97f68a7529f3} u08 LIST\_\-ALIGN\_\-RIGHT(list) u08 LIST\_\-ALIGN\_\-CONTINUOUS(list) -$>$ just try to put data in a countinuous memory region in minimum operations.

Example :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 4 3 4 D X X A B C

we do \doxyref{LIST\_\-ALIGN\_\-LEFT(list)}{p.}{include_2aversive_2list_8h_71d0c53b6563274e286a97f68a7529f3} :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 4 0 1 A B C D X X

we do LIST\_\-ALIGN\_\-RIGHT(list) :

size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 4 2 3 X X A B C D

With these functions, you can easily imagine a network stack, prepending headers to data, without copying the buffer multiple times.

Example :

\doxyref{LIST\_\-INIT(mylist, 5)}{p.}{queue_8h_304b5b7f7bdcba2793eaba9c890991c3} size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 0 5 5 X X X X X X

LIST\_\-ARRAY\_\-PUSH\_\-START(\char`\"{}DATA\char`\"{}, mylist, u08, strlen(\char`\"{}DATA\char`\"{})) size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 4 2 5 X X D A T A

LIST\_\-PUSH\_\-START('H', mylist, u08) (push header) size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 5 1 5 X H D A T A

LIST\_\-PUSH\_\-START('H', mylist, u08) (push another header) size $|$ cursize $|$ beg $|$ cursor $|$ elt0 $|$ elt1 $|$ elt2 $|$ elt3 $|$ elt4 $|$ elt5 $|$ 6 6 0 5 H H D A T A 

Definition at line 254 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-EMPTY@{LIST\_\-EMPTY}}
\index{LIST\_\-EMPTY@{LIST\_\-EMPTY}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-EMPTY]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-EMPTY(list)~(list.hdr.cur\_\-size == 0)}\label{include_2aversive_2list_8h_c157b9f1f332a4425af2f26c8e83127b}


Return 1 if the list is empty 

Definition at line 315 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-FREESIZE@{LIST\_\-FREESIZE}}
\index{LIST\_\-FREESIZE@{LIST\_\-FREESIZE}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-FREESIZE]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-FREESIZE(list)~(list.hdr.size-list.hdr.cur\_\-size)}\label{include_2aversive_2list_8h_375bad9033de22014d0e282122f92bec}


return the number of free elts 

Definition at line 330 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-FULL@{LIST\_\-FULL}}
\index{LIST\_\-FULL@{LIST\_\-FULL}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-FULL]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-FULL(list)~(list.hdr.size == list.hdr.cur\_\-size)}\label{include_2aversive_2list_8h_6c4ba0ce0af3de21dbdf47f11dc3a3e6}


Return 1 if the list is full 

Definition at line 310 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-INIT@{LIST\_\-INIT}}
\index{LIST\_\-INIT@{LIST\_\-INIT}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-INIT]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-INIT(list, \/  beginning)}\label{include_2aversive_2list_8h_6d4dc6ae8b85fedeb1d5786e382052b8}


\textbf{Value:}

\begin{Code}\begin{verbatim}do { \
  list.hdr.size = sizeof(list.elt)/sizeof(list.elt[0]); \
  list.hdr.cur_size = 0; \
  list.hdr.beg_indice = beginning; \
  list.hdr.read_cursor = beginning; \
} while(0)
\end{verbatim}
\end{Code}


Definition at line 298 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-PULL\_\-END@{LIST\_\-PULL\_\-END}}
\index{LIST\_\-PULL\_\-END@{LIST\_\-PULL\_\-END}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-PULL\_\-END]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-PULL\_\-END(list, \/  elt\_\-p)}\label{include_2aversive_2list_8h_757252bd716b870d67130ac25ce68496}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 if( LIST_EMPTY(list) ) \
         __ret=EINVAL; \
 else { \
         *elt_p = list.elt [ (list.hdr.beg_indice-1+list.hdr.cur_size) % list.hdr.size ] ; \
         list.hdr.cur_size -- ; \
 } \
if(LIST_DEBUG) \
 printf("LIST_PULL_END(%s, %s) -> ret %d"CR,#list, #elt_p, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 434 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-PULL\_\-START@{LIST\_\-PULL\_\-START}}
\index{LIST\_\-PULL\_\-START@{LIST\_\-PULL\_\-START}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-PULL\_\-START]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-PULL\_\-START(list, \/  elt\_\-p)}\label{include_2aversive_2list_8h_c59bb004986a29bf2b22cf2aed52cf79}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 if( LIST_EMPTY(list) ) \
         __ret=EINVAL; \
 else { \
         *elt_p = list.elt [ list.hdr.beg_indice ] ; \
         list.hdr.beg_indice = (list.hdr.beg_indice+1) % list.hdr.size; \
         list.hdr.cur_size -- ; \
 } \
if(LIST_DEBUG) \
 printf("LIST_PULL_START(%s, %s) -> ret %d"CR,#list, #elt_p, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 420 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-PUSH\_\-END@{LIST\_\-PUSH\_\-END}}
\index{LIST\_\-PUSH\_\-END@{LIST\_\-PUSH\_\-END}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-PUSH\_\-END]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-PUSH\_\-END(list, \/  e)}\label{include_2aversive_2list_8h_aaf0cd0f53a301b86976f1b3d67f3c12}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 if( LIST_FULL(list) ) \
         __ret=EINVAL; \
 else { \
         list.elt [ (list.hdr.beg_indice+list.hdr.cur_size) % list.hdr.size ] = e ; \
         list.hdr.cur_size ++ ; \
 } \
if(LIST_DEBUG) \
 printf("LIST_PUSH_END(%s, %s) -> ret %d"CR,#list, #e, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 407 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-PUSH\_\-START@{LIST\_\-PUSH\_\-START}}
\index{LIST\_\-PUSH\_\-START@{LIST\_\-PUSH\_\-START}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-PUSH\_\-START]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-PUSH\_\-START(list, \/  e)}\label{include_2aversive_2list_8h_c6f34994653a385f2e36b9f61e58fdcc}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 if( LIST_FULL(list) ) \
         __ret=EINVAL; \
 else { \
         list.hdr.beg_indice = (list.hdr.beg_indice-1+list.hdr.size) % list.hdr.size; \
         list.elt [ list.hdr.beg_indice ] = e ; \
         list.hdr.cur_size ++ ; \
 } \
if(LIST_DEBUG) \
 printf("LIST_PUSH_START(%s, %s) -> ret %d"CR,#list, #e, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 393 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-READ@{LIST\_\-READ}}
\index{LIST\_\-READ@{LIST\_\-READ}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-READ]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-READ(list, \/  elt\_\-p)}\label{include_2aversive_2list_8h_a3aaecb4f9272edffe3a7e79f5cde1a8}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 *elt_p = list.elt[(list.hdr.beg_indice+list.hdr.read_cursor) % list.hdr.size] ;  \
 0;  \
})
\end{verbatim}
\end{Code}


Definition at line 388 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-READ\_\-END@{LIST\_\-READ\_\-END}}
\index{LIST\_\-READ\_\-END@{LIST\_\-READ\_\-END}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-READ\_\-END]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-READ\_\-END(list, \/  elt\_\-p)}\label{include_2aversive_2list_8h_0a426e7d798e61d330978b533a6e954d}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 list.hdr.read_cursor = list.hdr.cur_size-1; \
 *elt_p = list.elt[(list.hdr.beg_indice-1+list.hdr.cur_size) % list.hdr.size] ;  \
 if(LIST_DEBUG) \
   printf("LIST_READ_END(%s, %s) -> ret %d"CR,#list, #elt_p, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 343 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-READ\_\-GOTO@{LIST\_\-READ\_\-GOTO}}
\index{LIST\_\-READ\_\-GOTO@{LIST\_\-READ\_\-GOTO}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-READ\_\-GOTO]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-READ\_\-GOTO(list, \/  elt\_\-p, \/  {\bf i})}\label{include_2aversive_2list_8h_e090a281a86e4df84ec3ad5387d25f67}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 if( (i<0) || (i>=list.hdr.cur_size) ) \
         __ret = EINVAL; \
 else { \
        list.hdr.read_cursor = i; \
        *elt_p = list.elt[(list.hdr.beg_indice+i) % list.hdr.size] ;  \
 } \
 if(LIST_DEBUG) \
   printf("LIST_READ_GOTO(%s, %s, %d) -> ret %d"CR,#list, #elt_p, i, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 353 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-READ\_\-MOVE@{LIST\_\-READ\_\-MOVE}}
\index{LIST\_\-READ\_\-MOVE@{LIST\_\-READ\_\-MOVE}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-READ\_\-MOVE]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-READ\_\-MOVE(list, \/  elt\_\-p, \/  {\bf i})}\label{include_2aversive_2list_8h_5c3f5a48d2e254b27be35d64693f9b0f}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
uint8_t __ret=0;  \
 if (i<0) { \
        if( (-i) > list.hdr.read_cursor ) \
                 __ret = WOVERWRAPPED ; \
        list.hdr.read_cursor -= ((-i) % list.hdr.cur_size) ; \
        if (list.hdr.read_cursor < 0)  \
                list.hdr.read_cursor += list.hdr.cur_size ;  \
 } \
 else {  \
         if( i >= list.hdr.cur_size - list.hdr.read_cursor )  \
                 __ret = WOVERWRAPPED ; \
         list.hdr.read_cursor += (i % list.hdr.cur_size) ; \
         if (list.hdr.read_cursor >= list.hdr.cur_size) \
                 list.hdr.read_cursor -= list.hdr.cur_size ; \
 } \
 if(LIST_DEBUG) \
   printf("LIST_READ_MOVE(%s, %s, %d) -> ret %d"CR,#list, #elt_p, i, __ret); \
 *elt_p = list.elt[(list.hdr.beg_indice+list.hdr.read_cursor) % list.hdr.size] ;  \
 __ret;  \
})
\end{verbatim}
\end{Code}


Definition at line 366 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-READ\_\-START@{LIST\_\-READ\_\-START}}
\index{LIST\_\-READ\_\-START@{LIST\_\-READ\_\-START}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-READ\_\-START]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-READ\_\-START(list, \/  elt\_\-p)}\label{include_2aversive_2list_8h_22528a37226c653a410fb1c0f7376aed}


\textbf{Value:}

\begin{Code}\begin{verbatim}({ \
 uint8_t __ret=0; \
 list.hdr.read_cursor = 0 ; \
 *elt_p = list.elt[list.hdr.beg_indice] ;  \
 if(LIST_DEBUG) \
   printf("LIST_READ_START(%s, %s) -> ret %d"CR,#list, #elt_p, __ret); \
 __ret; \
})
\end{verbatim}
\end{Code}


Definition at line 334 of file list.h.

Referenced by main().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-SIZE@{LIST\_\-SIZE}}
\index{LIST\_\-SIZE@{LIST\_\-SIZE}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-SIZE]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-SIZE(list)~(list.hdr.size)}\label{include_2aversive_2list_8h_44b8aa6854ba8c7dc5d79d1465f4be46}


return size of the list (used + free elements) 

Definition at line 325 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-TO\_\-ARRAY@{LIST\_\-TO\_\-ARRAY}}
\index{LIST\_\-TO\_\-ARRAY@{LIST\_\-TO\_\-ARRAY}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-TO\_\-ARRAY]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-TO\_\-ARRAY(list, \/  array, \/  nb)}\label{include_2aversive_2list_8h_739ca8715c2e4e6a31677ccead7555bd}


\textbf{Value:}

\begin{Code}\begin{verbatim}({\
 int8_t __i; \
 for(__i=0 ; __i<nb && __i<list.hdr.cur_size ; __i++) { \
    array[__i] = list.elt[(__i+list.hdr.beg_indice) % list.hdr.size]; \
 } \
 if(LIST_DEBUG) \
   printf("LIST_TO_ARRAY(%s, %s, %d) -> ret %d"CR,#list, #array, nb, __i); \
 __i; \
})
\end{verbatim}
\end{Code}


Definition at line 493 of file list.h.

Referenced by get\_\-scancode().\index{include/aversive/list.h@{include/aversive/list.h}!LIST\_\-TYPEDEF@{LIST\_\-TYPEDEF}}
\index{LIST\_\-TYPEDEF@{LIST\_\-TYPEDEF}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[LIST\_\-TYPEDEF]{\setlength{\rightskip}{0pt plus 5cm}\#define LIST\_\-TYPEDEF(typename, \/  elttype, \/  size)}\label{include_2aversive_2list_8h_c530f1e644b82d112c7c2c4cd65c35e7}


\textbf{Value:}

\begin{Code}\begin{verbatim}typedef struct typename { \
        struct list_hdr hdr; \
        elttype elt[size]; \
} typename;
\end{verbatim}
\end{Code}
Define a new list type 

Definition at line 292 of file list.h.\index{include/aversive/list.h@{include/aversive/list.h}!WOVERWRAPPED@{WOVERWRAPPED}}
\index{WOVERWRAPPED@{WOVERWRAPPED}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[WOVERWRAPPED]{\setlength{\rightskip}{0pt plus 5cm}\#define WOVERWRAPPED~-1}\label{include_2aversive_2list_8h_1ada4758aa9e22026776d44b51d92be5}




Definition at line 259 of file list.h.

\subsection{Variable Documentation}
\index{include/aversive/list.h@{include/aversive/list.h}!packed@{packed}}
\index{packed@{packed}!include/aversive/list.h@{include/aversive/list.h}}
\subsubsection[packed]{\setlength{\rightskip}{0pt plus 5cm}struct {\bf extract16} {\bf packed}}\label{include_2aversive_2list_8h_4110d3b0c84b51758ea703d221bd7ae8}


This structure is the header of a list type.

This is a generic kind of list, in which we suppose that elements are char 