00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <grass/Vect.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 P_NODE *dig_alloc_node()
00041 {
00042 P_NODE *Node;
00043
00044 Node = (P_NODE *) malloc(sizeof(P_NODE));
00045 if (Node == NULL)
00046 return NULL;
00047
00048 Node->n_lines = 0;
00049 Node->alloc_lines = 0;
00050 Node->lines = NULL;
00051 Node->angles = NULL;
00052
00053 return (Node);
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 int dig_node_alloc_line(P_NODE * node, int add)
00064 {
00065 int num;
00066 char *p;
00067
00068 G_debug(3, "dig_node_alloc_line(): add = %d", add);
00069
00070 num = node->n_lines + add;
00071
00072 p = realloc(node->lines, num * sizeof(plus_t));
00073 if (p == NULL)
00074 return -1;
00075 node->lines = (plus_t *) p;
00076
00077 p = realloc(node->angles, num * sizeof(float));
00078 if (p == NULL)
00079 return -1;
00080 node->angles = (float *)p;
00081
00082 node->alloc_lines = num;
00083 return (0);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093 int dig_alloc_nodes(struct Plus_head *Plus, int add)
00094 {
00095 int size;
00096 char *p;
00097
00098 size = Plus->alloc_nodes + 1 + add;
00099 p = realloc(Plus->Node, size * sizeof(P_NODE *));
00100 if (p == NULL)
00101 return -1;
00102
00103 Plus->Node = (P_NODE **) p;
00104 Plus->alloc_nodes = size - 1;
00105
00106 return (0);
00107 }
00108
00109
00110 P_LINE *dig_alloc_line()
00111 {
00112 P_LINE *Line;
00113
00114 Line = (P_LINE *) malloc(sizeof(P_LINE));
00115 if (Line == NULL)
00116 return NULL;
00117
00118 return (Line);
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 int dig_alloc_lines(struct Plus_head *Plus, int add)
00128 {
00129 int size;
00130 char *p;
00131
00132 size = Plus->alloc_lines + 1 + add;
00133 p = realloc(Plus->Line, size * sizeof(P_LINE *));
00134 if (p == NULL)
00135 return -1;
00136
00137 Plus->Line = (P_LINE **) p;
00138 Plus->alloc_lines = size - 1;
00139
00140 return (0);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 int dig_alloc_areas(struct Plus_head *Plus, int add)
00150 {
00151 int size;
00152 char *p;
00153
00154 size = Plus->alloc_areas + 1 + add;
00155 p = realloc(Plus->Area, size * sizeof(P_AREA *));
00156 if (p == NULL)
00157 return -1;
00158
00159 Plus->Area = (P_AREA **) p;
00160 Plus->alloc_areas = size - 1;
00161
00162 return (0);
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 int dig_alloc_isles(struct Plus_head *Plus, int add)
00172 {
00173 int size;
00174 char *p;
00175
00176 G_debug(3, "dig_alloc_isle():");
00177 size = Plus->alloc_isles + 1 + add;
00178 p = realloc(Plus->Isle, size * sizeof(P_ISLE *));
00179 if (p == NULL)
00180 return -1;
00181
00182 Plus->Isle = (P_ISLE **) p;
00183 Plus->alloc_isles = size - 1;
00184
00185 return (0);
00186 }
00187
00188
00189 P_AREA *dig_alloc_area()
00190 {
00191 P_AREA *Area;
00192
00193 Area = (P_AREA *) malloc(sizeof(P_AREA));
00194 if (Area == NULL)
00195 return NULL;
00196
00197 Area->n_lines = 0;
00198 Area->alloc_lines = 0;
00199 Area->lines = NULL;
00200
00201 Area->alloc_isles = 0;
00202 Area->n_isles = 0;
00203 Area->isles = NULL;
00204
00205 Area->centroid = 0;
00206
00207 return (Area);
00208 }
00209
00210
00211 P_ISLE *dig_alloc_isle()
00212 {
00213 P_ISLE *Isle;
00214
00215 Isle = (P_ISLE *) malloc(sizeof(P_ISLE));
00216 if (Isle == NULL)
00217 return NULL;
00218
00219 Isle->n_lines = 0;
00220 Isle->alloc_lines = 0;
00221 Isle->lines = NULL;
00222
00223 Isle->area = 0;
00224
00225 return (Isle);
00226 }
00227
00228
00229
00230
00231
00232 int dig_alloc_points(struct line_pnts *points, int num)
00233 {
00234 int alloced;
00235 char *p;
00236
00237 alloced = points->alloc_points;
00238
00239 if (!(p =
00240 dig__alloc_space(num, &alloced, 50, (char *)points->x,
00241 sizeof(double)))) {
00242 return (dig_out_of_memory());
00243 }
00244 points->x = (double *)p;
00245
00246 alloced = points->alloc_points;
00247
00248 if (!(p =
00249 dig__alloc_space(num, &alloced, 50, (char *)points->y,
00250 sizeof(double)))) {
00251 return (dig_out_of_memory());
00252 }
00253 points->y = (double *)p;
00254
00255 alloced = points->alloc_points;
00256
00257 if (!(p =
00258 dig__alloc_space(num, &alloced, 50, (char *)points->z,
00259 sizeof(double)))) {
00260 return (dig_out_of_memory());
00261 }
00262 points->z = (double *)p;
00263
00264 points->alloc_points = alloced;
00265 return (0);
00266 }
00267
00268
00269
00270
00271
00272 int dig_alloc_cats(struct line_cats *cats, int num)
00273 {
00274 int alloced;
00275 char *p;
00276
00277
00278 alloced = cats->alloc_cats;
00279 if (!(p =
00280 dig__alloc_space(num, &alloced, 1, (int *)cats->field,
00281 sizeof(int)))) {
00282 return (dig_out_of_memory());
00283 }
00284 cats->field = (int *)p;
00285
00286 alloced = cats->alloc_cats;
00287 if (!(p =
00288 dig__alloc_space(num, &alloced, 1, (int *)cats->cat,
00289 sizeof(int)))) {
00290 return (dig_out_of_memory());
00291 }
00292 cats->cat = (int *)p;
00293
00294 cats->alloc_cats = alloced;
00295 return (0);
00296 }
00297
00298
00299
00300
00301
00302
00303 int dig_area_alloc_line(P_AREA * area, int add)
00304 {
00305 int num;
00306 char *p;
00307
00308 num = area->alloc_lines + add;
00309
00310 p = realloc(area->lines, num * sizeof(plus_t));
00311 if (p == NULL)
00312 return -1;
00313 area->lines = (plus_t *) p;
00314
00315 area->alloc_lines = num;
00316
00317 return (0);
00318 }
00319
00320
00321
00322
00323
00324
00325 int dig_area_alloc_isle(P_AREA * area, int add)
00326 {
00327 int num;
00328 char *p;
00329
00330 G_debug(5, "dig_area_alloc_isle(): add = %d", add);
00331 num = area->alloc_isles + add;
00332
00333 p = realloc(area->isles, num * sizeof(plus_t));
00334 if (p == NULL)
00335 return -1;
00336 area->isles = (plus_t *) p;
00337
00338 area->alloc_isles = num;
00339 return (0);
00340 }
00341
00342
00343
00344
00345
00346
00347
00348 int dig_isle_alloc_line(P_ISLE * isle, int add)
00349 {
00350 int num;
00351 char *p;
00352
00353 G_debug(3, "dig_isle_alloc_line():");
00354 num = isle->alloc_lines + add;
00355
00356 p = realloc(isle->lines, num * sizeof(plus_t));
00357 if (p == NULL)
00358 return -1;
00359 isle->lines = (plus_t *) p;
00360
00361 isle->alloc_lines = num;
00362
00363 return (0);
00364 }
00365
00366
00367
00368
00369 int dig_out_of_memory()
00370 {
00371 fprintf(stderr, "OUT OF MEMORY!\n");
00372 return (-1);
00373 }