1 /* Including standard libraries */
9 /* Define a shorthand for unsigned int */
10 #define uint unsigned int
12 /* Define a boolean type */
17 /* Macro for resetting a pointer to all \0's. */
18 #define ZERO( pt ) ( memset( pt, '\0', sizeof( *pt ) ) )
20 /* Macro for dynamic allocation of memory. */
21 #define MEM_GET( pt ) ( pt = mem_get( sizeof( *pt ) ) )
23 /* Macro for cloning a structure in memroy. */
24 #define MEM_CLONE( pt ) mem_clone( pt, sizeof( ( pt )[ 0 ] ) )
26 /* Macros for determining min or max of two given values. */
27 #define MAX( a, b ) a < b ? b : a
28 #define MIN( a, b ) a > b ? b : a
30 /* Macros for abs and int functions. */
31 #define ABS( x ) ( ( x ) < 0 ) ? -( x ) : ( x )
32 #define INT( x ) ( int ) x
35 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
38 /* Singly linked list with a pointer to the next element and a pointer to a value. */
45 /* Singly linked list with a pointer to the next element and an integer value. */
53 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ERROR HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
56 /* Print error message to stderr and exit. */
57 void die( char *error_msg );
59 /* Print warning message to stderr. */
60 void warn( char *warn_msg );
63 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MEMORY HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
66 /* Get a pointer with a given size of allocated memory. */
67 void *mem_get( size_t size );
69 /* Get a pointer with a given size of allocated and zero'ed memory. */
70 void *mem_get_zero( size_t size );
72 /* Resize allocated memory for a given pointer. */
73 void *mem_resize( void* pt, size_t size );
75 /* Resize allocated memory for a given pointer with extra memory zero'ed. */
76 void *mem_resize_zero( void* pt, size_t old_size, size_t new_size );
78 /* Clone a structure in memory and return a pointer to the clone. */
79 void *mem_clone( void *old_pt, size_t size );
81 /* Free memory from a given pointer. */
82 void mem_free( void *pt );
85 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ARRAYS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
88 /* Binary search an array of integers for an integer value. */
89 bool binary_search_array( int *array, int array_size, int val );
92 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MISC <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
95 /* Remove the last char from a string. */
96 void chop( char *string );
98 /* Remove the last char from a string if the char is a newline (safer than chop). */
99 void chomp( char *string );
101 /* Split a given line and a delimiter return the split result as a list. */
102 void split( char *string, char delimit, struct list **fields );
104 /* Mockup version of Perl substr. */
105 char *substr( char *string, int offset, int len );
107 /* Return a binary number as a string of 1's and 0's. */
108 char *bits2string( uint bin );
111 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/