1 /* Including standard libraries */
11 /* Define a shorthand for unsigned int */
12 #define uint unsigned int
14 /* Define a boolean type */
19 /* Macro for resetting a pointer to all \0's. */
20 #define MEM_ZERO( pt ) ( memset( pt, '\0', sizeof( *pt ) ) )
22 /* Macro for dynamic allocation of memory. */
23 #define MEM_GET( pt ) ( pt = mem_get( sizeof( *pt ) ) )
25 /* Macro for cloning a structure in memroy. */
26 #define MEM_CLONE( pt ) mem_clone( pt, sizeof( ( pt )[ 0 ] ) )
28 /* Macros for determining min or max of two given values. */
29 #define MAX( a, b ) a < b ? b : a
30 #define MIN( a, b ) a > b ? b : a
32 /* Macros for abs and int functions. */
33 #define ABS( x ) ( ( x ) < 0 ) ? -( x ) : ( x )
34 #define INT( x ) ( int ) x
37 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> STRUCTURE DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
40 // At some point test if typdef struct list list will allow us to move all this stuff to list.h and list.c
43 /* Singly linked list with a pointer to the next element and a pointer to a value. */
50 /* Singly linked list with a pointer to the next element and an integer value. */
58 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ERROR HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
61 /* Print error message to stderr and exit. */
62 void die( char *error_msg );
64 /* Print warning message to stderr. */
65 void warn( char *warn_msg );
68 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MEMORY HANDLING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
71 /* Get a pointer with a given size of allocated memory. */
72 void *mem_get( size_t size );
74 /* Get a pointer with a given size of allocated and zero'ed memory. */
75 void *mem_get_zero( size_t size );
77 /* Resize allocated memory for a given pointer. */
78 void *mem_resize( void* pt, size_t size );
80 /* Resize allocated memory for a given pointer with extra memory zero'ed. */
81 void *mem_resize_zero( void* pt, size_t old_size, size_t new_size );
83 /* Clone a structure in memory and return a pointer to the clone. */
84 void *mem_clone( void *old_pt, size_t size );
86 /* Free memory from a given pointer. */
87 void mem_free( void *pt );
89 /* Zero and then free memory from a given pointer. */
90 void mem_free( void *pt );
92 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ARRAYS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
95 /* Binary search an array of integers for an integer value. */
96 bool binary_search_array( int *array, int array_size, int val );
99 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MISC <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
102 /* Remove the last char from a string. */
103 void chop( char *string );
105 /* Remove the last char from a string if the char is a newline (safer than chop). */
106 void chomp( char *string );
108 /* Split a given line and a delimiter return the split result as a list. */
109 void split( char *string, char delimit, struct list **fields );
111 /* Mockup version of Perl substr. */
112 char *substr( char *string, int offset, int len );
114 /* Return a binary number as a string of 1's and 0's. */
115 char *bits2string( uint bin );
118 /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/