1 /* Including standard libraries */
10 /* Define a shorthand for unsigned int */
11 #define uint unsigned int
13 /* Define a boolean type */
18 /* Macro for resetting a pointer to all \0's. */
19 #define ZERO( pt ) ( memset( pt, '\0', sizeof( *pt ) ) )
21 /* Macro for dynamic allocation of memory. */
22 #define MEM_GET( pt ) ( pt = mem_get( sizeof( *pt ) ) )
24 /* Macro for cloning a structure in memroy. */
25 #define MEM_CLONE( pt ) mem_clone( pt, sizeof( ( pt )[ 0 ] ) )
27 /* Macros for determining min or max of two given values. */
28 #define MAX( a, b ) a < b ? b : a
29 #define MIN( a, b ) a > b ? b : a
31 /* Macros for abs and int functions. */
32 #define ABS( x ) ( ( x ) < 0 ) ? -( x ) : ( x )
33 #define INT( x ) ( int ) x
36 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
39 /* Singly linked list with a pointer to the next element and a pointer to a value. */
46 /* Singly linked list with a pointer to the next element and an integer value. */
54 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ERROR HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
57 /* Print error message to stderr and exit. */
58 void die( char *error_msg );
60 /* Print warning message to stderr. */
61 void warn( char *warn_msg );
64 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MEMORY HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
67 /* Get a pointer with a given size of allocated memory. */
68 void *mem_get( size_t size );
70 /* Get a pointer with a given size of allocated and zero'ed memory. */
71 void *mem_get_zero( size_t size );
73 /* Resize allocated memory for a given pointer. */
74 void *mem_resize( void* pt, size_t size );
76 /* Resize allocated memory for a given pointer with extra memory zero'ed. */
77 void *mem_resize_zero( void* pt, size_t old_size, size_t new_size );
79 /* Clone a structure in memory and return a pointer to the clone. */
80 void *mem_clone( void *old_pt, size_t size );
82 /* Free memory from a given pointer. */
83 void mem_free( void *pt );
86 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ARRAYS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
89 /* Binary search an array of integers for an integer value. */
90 bool binary_search_array( int *array, int array_size, int val );
93 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MISC <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
96 /* Remove the last char from a string. */
97 void chop( char *string );
99 /* Remove the last char from a string if the char is a newline (safer than chop). */
100 void chomp( char *string );
102 /* Split a given line and a delimiter return the split result as a list. */
103 void split( char *string, char delimit, struct list **fields );
105 /* Mockup version of Perl substr. */
106 char *substr( char *string, int offset, int len );
108 /* Return a binary number as a string of 1's and 0's. */
109 char *bits2string( uint bin );
112 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/