00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004
00005
00006
00007 extern int linenum;
00008
00009
00010
00011
00012 #ifndef TRUE
00013 typedef enum
00014 { FALSE, TRUE }
00015 boolean;
00016 #else
00017 typedef int boolean;
00018 #endif
00019
00020
00021 #define IN
00022 #define OUT
00023 #define INOUT
00024
00025
00026 #define ERRTAG "ERROR:\t"
00027 #define WARNTAG "WARN:\t"
00028
00029 #define BUFSIZE 300
00030 #ifndef max
00031 #define max(a,b) (((a) > (b))? (a) : (b))
00032 #define min(a,b) ((a) > (b)? (b) : (a))
00033 #endif
00034 #define nint(a) ((int) floor (a + 0.5))
00035
00036 int limit_value(int cur,
00037 int max,
00038 const char *name);
00039
00040
00041
00042 struct s_linked_vptr
00043 {
00044 void *data_vptr;
00045 struct s_linked_vptr *next;
00046 };
00047
00048 struct s_linked_int
00049 {
00050 int data;
00051 struct s_linked_int *next;
00052 };
00053 typedef struct s_linked_int t_linked_int;
00054
00055
00056
00057
00058
00059 struct s_ivec
00060 {
00061 int nelem;
00062 int *list;
00063 };
00064 typedef struct s_ivec t_ivec;
00065
00066
00067
00068
00069 void *my_calloc(size_t nelem,
00070 size_t size);
00071 void *my_malloc(size_t size);
00072 void *my_realloc(void *ptr,
00073 size_t size);
00074
00075 void *my_chunk_malloc(size_t size,
00076 struct s_linked_vptr **chunk_ptr_head,
00077 int *mem_avail_ptr,
00078 char **next_mem_loc_ptr);
00079
00080 void free_chunk_memory(struct s_linked_vptr *chunk_ptr_head);
00081
00082
00083
00084
00085 void free_ivec_vector(struct s_ivec *ivec_vector,
00086 int nrmin,
00087 int nrmax);
00088
00089 void free_ivec_matrix(struct s_ivec **ivec_matrix,
00090 int nrmin,
00091 int nrmax,
00092 int ncmin,
00093 int ncmax);
00094
00095 void free_ivec_matrix3(struct s_ivec ***ivec_matrix3,
00096 int nrmin,
00097 int nrmax,
00098 int ncmin,
00099 int ncmax,
00100 int ndmin,
00101 int ndmax);
00102
00103 void **alloc_matrix(int nrmin,
00104 int nrmax,
00105 int ncmin,
00106 int ncmax,
00107 size_t elsize);
00108
00109 void ***alloc_matrix3(int nrmin,
00110 int nrmax,
00111 int ncmin,
00112 int ncmax,
00113 int ndmin,
00114 int ndmax,
00115 size_t elsize);
00116
00117 void ****alloc_matrix4(int nrmin,
00118 int nrmax,
00119 int ncmin,
00120 int ncmax,
00121 int ndmin,
00122 int ndmax,
00123 int nemin,
00124 int nemax,
00125 size_t elsize);
00126
00127 void free_matrix(void *vptr,
00128 int nrmin,
00129 int nrmax,
00130 int ncmin,
00131 size_t elsize);
00132
00133 void free_matrix3(void *vptr,
00134 int nrmin,
00135 int nrmax,
00136 int ncmin,
00137 int ncmax,
00138 int ndmin,
00139 size_t elsize);
00140
00141 void free_matrix4(void *vptr,
00142 int nrmin,
00143 int nrmax,
00144 int ncmin,
00145 int ncmax,
00146 int ndmin,
00147 int ndmax,
00148 int nemin,
00149 size_t elsize);
00150
00151 void print_int_matrix3(int ***vptr,
00152 int nrmin,
00153 int nrmax,
00154 int ncmin,
00155 int ncmax,
00156 int ndmin,
00157 int ndmax,
00158 char *file);
00159
00160 struct s_linked_vptr *insert_in_vptr_list(struct s_linked_vptr *head,
00161 void *vptr_to_add);
00162
00163 t_linked_int *insert_in_int_list(t_linked_int * head,
00164 int data,
00165 t_linked_int ** free_list_head_ptr);
00166
00167 void free_int_list(t_linked_int ** int_list_head_ptr);
00168
00169 void alloc_ivector_and_copy_int_list(t_linked_int ** list_head_ptr,
00170 int num_items,
00171 struct s_ivec *ivec,
00172 t_linked_int ** free_list_head_ptr);
00173
00174
00175
00176
00177 FILE *my_fopen(const char *fname,
00178 const char *flag);
00179
00180 char *my_strtok(char *ptr,
00181 char *tokens,
00182 FILE * fp,
00183 char *buf);
00184
00185 char *my_fgets(char *buf,
00186 int max_size,
00187 FILE * fp);
00188
00189 int my_atoi(const char *str);
00190
00191 char *my_strdup(const char *str);
00192
00193 char *my_strncpy(char *dest,
00194 const char *src,
00195 size_t size);
00196
00197
00198
00199 void my_srandom(int seed);
00200 int my_irand(int imax);
00201 float my_frand(void);