~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/vector/diglib/plus_struct.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *              for details.
16
16
 *
17
17
 *****************************************************************************/
 
18
#include <sys/types.h>
18
19
#include <string.h>
19
 
#include <grass/gis.h>
20
 
#include <grass/Vect.h>
 
20
#include <grass/vector.h>
 
21
#include <grass/glocale.h>
21
22
#include <grass/version.h>
22
 
 
23
23
/*
24
24
 * Routines for reading and writing Dig+ structures.
25
25
 * return 0 on success, -1 on failure of whatever kind
47
47
 *    plus_t is changed to a type that is larger than an int.
48
48
 */
49
49
 
50
 
int dig_Rd_P_node(struct Plus_head *Plus, int n, GVFILE * fp)
 
50
int dig_Rd_P_node(struct Plus_head *Plus, int n, struct gvfile * fp)
51
51
{
52
52
    int cnt, n_edges;
53
 
    P_NODE *ptr;
54
 
 
55
 
    G_debug(3, "dig_Rd_P_node()");
56
 
 
 
53
    struct P_node *ptr;
 
54
 
 
55
    G_debug(4, "dig_Rd_P_node()");
57
56
 
58
57
    if (0 >= dig__fread_port_P(&cnt, 1, fp))
59
58
        return (-1);
60
59
 
61
60
    if (cnt == 0) {             /* dead */
62
 
        G_debug(3, "    node is dead");
 
61
        G_debug(4, "    node is dead");
63
62
        Plus->Node[n] = NULL;
64
63
        return 0;
65
64
    }
101
100
    return (0);
102
101
}
103
102
 
104
 
int dig_Wr_P_node(struct Plus_head *Plus, int n, GVFILE * fp)
 
103
int dig_Wr_P_node(struct Plus_head *Plus, int n, struct gvfile * fp)
105
104
{
106
105
    int i, n_edges = 0;
107
 
    P_NODE *ptr;
 
106
    struct P_node *ptr;
108
107
 
109
 
    G_debug(3, "dig_Wr_P_node()");
 
108
    G_debug(4, "dig_Wr_P_node()");
110
109
    ptr = Plus->Node[n];
111
110
 
112
111
    /* If NULL i.e. dead write just 0 instead of number of lines */
113
112
    if (ptr == NULL) {
114
 
        G_debug(3, "    node is dead -> write 0 only");
 
113
        G_debug(4, "    node is dead -> write 0 only");
115
114
        i = 0;
116
115
        if (0 >= dig__fwrite_port_P(&i, 1, fp))
117
116
            return (-1);
146
145
    return (0);
147
146
}
148
147
 
149
 
int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
 
148
int dig_Rd_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
150
149
{
151
 
    int n_edges, vol;
 
150
    int n_edges;
152
151
    char tp;
153
 
    P_LINE *ptr;
154
 
    P_NODE *Node;
 
152
    struct P_line *ptr;
155
153
 
156
 
    G_debug(3, "dig_Rd_P_line()");
 
154
    G_debug(4, "dig_Rd_P_line()");
157
155
 
158
156
    if (0 >= dig__fread_port_C(&tp, 1, fp))
159
157
        return (-1);
160
158
 
161
159
    if (tp == 0) {              /* dead */
162
 
        G_debug(3, "    line is dead");
 
160
        G_debug(4, "    line is dead");
163
161
        Plus->Line[n] = NULL;
164
162
        return 0;
165
163
    }
166
164
 
167
165
    ptr = dig_alloc_line();
168
166
 
 
167
    /* type */
169
168
    ptr->type = dig_type_from_store(tp);
170
169
    G_debug(5, "    line type  %d -> %d", tp, ptr->type);
171
170
 
172
 
    if (0 >= dig__fread_port_L(&(ptr->offset), 1, fp))
 
171
    /* offset */
 
172
    if (0 >= dig__fread_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
173
173
        return (-1);
174
174
 
175
 
    /* First node */
176
 
    if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
177
 
        if (0 >= dig__fread_port_P(&(ptr->N1), 1, fp))
178
 
            return -1;
179
 
 
180
 
    /* Second node, for points/centroids not needed */
181
 
    if (ptr->type & (GV_LINE | GV_BOUNDARY)) {
182
 
        if (0 >= dig__fread_port_P(&(ptr->N2), 1, fp))
183
 
            return -1;
184
 
    }
185
 
    else if (ptr->type & (GV_POINTS | GV_KERNEL))
186
 
        ptr->N2 = ptr->N1;
187
 
 
188
 
    /* left area for boundary, area for centroid */
189
 
    if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
190
 
        if (0 >= dig__fread_port_P(&(ptr->left), 1, fp))
191
 
            return -1;
192
 
 
193
 
    /* right area */
194
 
    if (ptr->type & GV_BOUNDARY)
195
 
        if (0 >= dig__fread_port_P(&(ptr->right), 1, fp))
196
 
            return -1;
197
 
 
198
 
    if ((ptr->type & GV_FACE) && Plus->with_z) {        /* reserved for face edges */
 
175
    if (ptr->type == GV_POINT) {
 
176
        ptr->topo = NULL;
 
177
    }
 
178
    else {
 
179
        ptr->topo = dig_alloc_topo(ptr->type);
 
180
    }
 
181
 
 
182
    /* centroids */
 
183
    if (ptr->type & GV_CENTROID) {
 
184
        struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
 
185
 
 
186
        if (0 >= dig__fread_port_P(&(topo->area), 1, fp))
 
187
            return -1;
 
188
    }
 
189
    /* lines */
 
190
    else if (ptr->type & GV_LINE) {
 
191
        struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
 
192
 
 
193
        if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
 
194
            return -1;
 
195
        if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
 
196
            return -1;
 
197
    }
 
198
    /* boundaries */
 
199
    else if (ptr->type & GV_BOUNDARY) {
 
200
        struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
 
201
 
 
202
        if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
 
203
            return -1;
 
204
        if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
 
205
            return -1;
 
206
        if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
 
207
            return -1;
 
208
        if (0 >= dig__fread_port_P(&(topo->right), 1, fp))
 
209
            return -1;
 
210
    }
 
211
    /* faces */
 
212
    else if ((ptr->type & GV_FACE) && Plus->with_z) {   /* reserved for face edges */
 
213
        struct P_topo_f *topo = (struct P_topo_f *)ptr->topo;
 
214
 
199
215
        if (0 >= dig__fread_port_I(&n_edges, 1, fp))
200
216
            return -1;
201
217
 
202
218
        /* here will be list of edges */
203
219
 
204
220
        /* left / right volume */
205
 
        if (0 >= dig__fread_port_P(&vol, 1, fp))
206
 
            return -1;
207
 
        if (0 >= dig__fread_port_P(&vol, 1, fp))
208
 
            return -1;
209
 
    }
210
 
 
211
 
    if ((ptr->type & GV_KERNEL) && Plus->with_z)        /* reserved for kernel (volume number) */
212
 
        if (0 >= dig__fread_port_P(&vol, 1, fp))
213
 
            return -1;
214
 
 
215
 
    /* Bounding box */
216
 
    if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
217
 
        if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
218
 
            return -1;
219
 
        if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
220
 
            return -1;
221
 
        if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
222
 
            return -1;
223
 
        if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
224
 
            return -1;
225
 
 
226
 
        if (Plus->with_z) {
227
 
            if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
228
 
                return -1;
229
 
            if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
230
 
                return -1;
231
 
        }
232
 
        else {
233
 
            ptr->T = 0.0;
234
 
            ptr->B = 0.0;
235
 
        }
236
 
    }
237
 
    else {
238
 
        Node = Plus->Node[ptr->N1];
239
 
        ptr->N = Node->y;
240
 
        ptr->S = Node->y;
241
 
        ptr->E = Node->x;
242
 
        ptr->W = Node->x;
243
 
        ptr->T = Node->z;
244
 
        ptr->B = Node->z;
 
221
        if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
 
222
            return -1;
 
223
        if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
 
224
            return -1;
 
225
    }
 
226
    /* kernels */
 
227
    else if ((ptr->type & GV_KERNEL) && Plus->with_z) { /* reserved for kernel (volume number) */
 
228
        struct P_topo_k *topo = (struct P_topo_k *)ptr->topo;
 
229
 
 
230
        if (0 >= dig__fread_port_P(&(topo->volume), 1, fp))
 
231
            return -1;
245
232
    }
246
233
 
247
234
    Plus->Line[n] = ptr;
 
235
 
248
236
    return (0);
249
237
}
250
238
 
251
 
int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
 
239
int dig_Wr_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
252
240
{
253
 
    int n_edges = 0, vol = 0;
 
241
    int n_edges = 0;
254
242
    char ch;
255
 
    P_LINE *ptr;
 
243
    struct P_line *ptr;
256
244
 
257
245
    G_debug(4, "dig_Wr_P_line() line = %d", n);
258
246
 
259
247
    ptr = Plus->Line[n];
260
248
 
261
 
    /* If NULL i.e. dead write just 0 instead of type */
 
249
    /* if NULL i.e. dead write just 0 instead of type */
262
250
    if (ptr == NULL) {
263
 
        G_debug(3, "    line is dead -> write 0 only");
 
251
        G_debug(4, "    line is dead -> write 0 only");
264
252
        ch = 0;
265
253
        if (0 >= dig__fwrite_port_C(&ch, 1, fp))
266
254
            return (-1);
267
255
        return 0;
268
256
    }
269
257
 
 
258
    /* type */
270
259
    ch = (char)dig_type_to_store(ptr->type);
271
260
    G_debug(5, "    line type  %d -> %d", ptr->type, ch);
272
261
    if (0 >= dig__fwrite_port_C(&ch, 1, fp))
273
262
        return (-1);
274
 
    if (0 >= dig__fwrite_port_L(&(ptr->offset), 1, fp))
 
263
 
 
264
    /* offset */
 
265
    if (0 >= dig__fwrite_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
275
266
        return (-1);
276
 
 
277
 
    /* First node */
278
 
    if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
279
 
        if (0 >= dig__fwrite_port_P(&(ptr->N1), 1, fp))
280
 
            return (-1);
281
 
 
282
 
    /* Second node, for points/centroids not needed */
283
 
    if (ptr->type & (GV_LINE | GV_BOUNDARY))
284
 
        if (0 >= dig__fwrite_port_P(&(ptr->N2), 1, fp))
285
 
            return (-1);
286
 
 
287
 
    /* left area for boundary, area for centroid */
288
 
    if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
289
 
        if (0 >= dig__fwrite_port_P(&(ptr->left), 1, fp))
290
 
            return (-1);
291
 
 
292
 
    /* right area */
293
 
    if (ptr->type & GV_BOUNDARY)
294
 
        if (0 >= dig__fwrite_port_P(&(ptr->right), 1, fp))
295
 
            return (-1);
296
 
 
297
 
    if ((ptr->type & GV_FACE) && Plus->with_z) {        /* reserved for face */
 
267
        
 
268
    if (!ptr->topo)
 
269
        return (0);
 
270
        
 
271
    /* nothing else for points */
 
272
 
 
273
    /* centroids */
 
274
    if (ptr->type & GV_CENTROID) {
 
275
        struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
 
276
        
 
277
        if (0 >= dig__fwrite_port_P(&(topo->area), 1, fp))
 
278
            return (-1);
 
279
    }
 
280
    /* lines */
 
281
    else if (ptr->type & GV_LINE) {
 
282
        struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
 
283
 
 
284
        if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
 
285
            return (-1);
 
286
        if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
 
287
            return (-1);
 
288
    }
 
289
    /* boundaries */
 
290
    else if (ptr->type & GV_BOUNDARY) {
 
291
        struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
 
292
 
 
293
        if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
 
294
            return (-1);
 
295
        if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
 
296
            return (-1);
 
297
        if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
 
298
            return (-1);
 
299
        if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
 
300
            return (-1);
 
301
    }
 
302
    /* faces */
 
303
    else if ((ptr->type & GV_FACE) && Plus->with_z) {   /* reserved for face */
 
304
        struct P_topo_f *topo = (struct P_topo_f *)ptr->topo;
 
305
 
298
306
        if (0 >= dig__fwrite_port_I(&n_edges, 1, fp))
299
307
            return (-1);
300
308
 
301
309
        /* here will be list of edges */
302
310
 
303
 
        /* left / right volume */
304
 
        if (0 >= dig__fwrite_port_P(&vol, 1, fp))
 
311
        /* left / right volume / hole */
 
312
        if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
305
313
            return (-1);
306
 
        if (0 >= dig__fwrite_port_P(&vol, 1, fp))
 
314
        if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
307
315
            return (-1);
308
316
    }
309
 
 
310
 
    if ((ptr->type & GV_KERNEL) && Plus->with_z)        /* reserved for kernel (volume number) */
311
 
        if (0 >= dig__fwrite_port_P(&vol, 1, fp))
312
 
            return (-1);
313
 
 
314
 
    /* Bounding box */
315
 
    if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
316
 
        if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
317
 
            return (-1);
318
 
        if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
319
 
            return (-1);
320
 
        if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
321
 
            return (-1);
322
 
        if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
323
 
            return (-1);
324
 
 
325
 
        if (Plus->with_z) {
326
 
            if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
327
 
                return (-1);
328
 
            if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
329
 
                return (-1);
330
 
        }
 
317
    /* kernels */
 
318
    else if ((ptr->type & GV_KERNEL) && Plus->with_z) { /* reserved for kernel (volume number) */
 
319
        struct P_topo_k *topo = (struct P_topo_k *)ptr->topo;
 
320
 
 
321
        /* volume */
 
322
        if (0 >= dig__fwrite_port_P(&(topo->volume), 1, fp))
 
323
            return (-1);
331
324
    }
332
325
 
333
326
    return (0);
334
327
}
335
328
 
336
 
int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
 
329
int dig_Rd_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
337
330
{
338
331
    int cnt;
339
 
    P_AREA *ptr;
 
332
    struct P_area *ptr;
340
333
 
341
 
#ifdef GDEBUG
342
 
    G_debug(3, "dig_Rd_P_area(): n = %d", n);
343
 
#endif
 
334
    G_debug(4, "dig_Rd_P_area(): n = %d", n);
344
335
 
345
336
    if (0 >= dig__fread_port_P(&cnt, 1, fp))
346
337
        return (-1);
352
343
 
353
344
    ptr = dig_alloc_area();
354
345
 
355
 
    /* lines */
 
346
    /* boundaries */
356
347
    ptr->n_lines = cnt;
357
348
 
358
349
    if (dig_area_alloc_line(ptr, ptr->n_lines) == -1)
377
368
    if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp))
378
369
        return -1;
379
370
 
380
 
    if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
381
 
        return -1;
382
 
    if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
383
 
        return -1;
384
 
    if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
385
 
        return -1;
386
 
    if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
387
 
        return -1;
388
 
 
389
 
    if (Plus->with_z) {
390
 
        if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
391
 
            return -1;
392
 
        if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
393
 
            return -1;
394
 
    }
395
 
    else {
396
 
        ptr->T = 0.0;
397
 
        ptr->B = 0.0;
398
 
    }
399
 
 
400
371
    Plus->Area[n] = ptr;
401
372
 
402
373
    return (0);
403
374
}
404
375
 
405
 
int dig_Wr_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
 
376
int dig_Wr_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
406
377
{
407
378
    int i;
408
 
    P_AREA *ptr;
 
379
    struct P_area *ptr;
409
380
 
410
381
    ptr = Plus->Area[n];
411
382
 
417
388
        return 0;
418
389
    }
419
390
 
420
 
    /* lines */
 
391
    /* boundaries */
421
392
    if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
422
393
        return (-1);
423
394
 
437
408
    if (0 >= dig__fwrite_port_P(&(ptr->centroid), 1, fp))
438
409
        return (-1);
439
410
 
440
 
    if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
441
 
        return (-1);
442
 
    if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
443
 
        return (-1);
444
 
    if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
445
 
        return (-1);
446
 
    if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
447
 
        return (-1);
448
 
 
449
 
    if (Plus->with_z) {
450
 
        if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
451
 
            return (-1);
452
 
        if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
453
 
            return (-1);
454
 
    }
455
 
 
456
411
    return (0);
457
412
}
458
413
 
459
 
int dig_Rd_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
 
414
int dig_Rd_P_isle(struct Plus_head *Plus, int n, struct gvfile * fp)
460
415
{
461
416
    int cnt;
462
 
    P_ISLE *ptr;
 
417
    struct P_isle *ptr;
463
418
 
464
 
#ifdef GDEBUG
465
419
    G_debug(3, "dig_Rd_P_isle()");
466
 
#endif
467
420
 
468
421
    if (0 >= dig__fread_port_P(&cnt, 1, fp))
469
422
        return (-1);
475
428
 
476
429
    ptr = dig_alloc_isle();
477
430
 
478
 
    /* lines */
 
431
    /* boundaries */
479
432
    ptr->n_lines = cnt;
480
433
 
481
434
    if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1)
489
442
    if (0 >= dig__fread_port_P(&(ptr->area), 1, fp))
490
443
        return -1;
491
444
 
492
 
    if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
493
 
        return -1;
494
 
    if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
495
 
        return -1;
496
 
    if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
497
 
        return -1;
498
 
    if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
499
 
        return -1;
500
 
 
501
 
    if (Plus->with_z) {
502
 
        if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
503
 
            return -1;
504
 
        if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
505
 
            return -1;
506
 
    }
507
 
    else {
508
 
        ptr->T = 0.0;
509
 
        ptr->B = 0.0;
510
 
    }
511
 
 
512
445
    Plus->Isle[n] = ptr;
513
446
 
514
447
    return (0);
515
448
}
516
449
 
517
 
int dig_Wr_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
 
450
int dig_Wr_P_isle(struct Plus_head *Plus, int n, struct gvfile * fp)
518
451
{
519
452
    int i;
520
 
    P_ISLE *ptr;
 
453
    struct P_isle *ptr;
521
454
 
522
455
    ptr = Plus->Isle[n];
523
456
 
541
474
    if (0 >= dig__fwrite_port_P(&(ptr->area), 1, fp))
542
475
        return (-1);
543
476
 
544
 
    if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
545
 
        return (-1);
546
 
    if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
547
 
        return (-1);
548
 
    if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
549
 
        return (-1);
550
 
    if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
551
 
        return (-1);
552
 
 
553
 
    if (Plus->with_z) {
554
 
        if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
555
 
            return (-1);
556
 
        if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
557
 
            return (-1);
558
 
    }
559
 
 
560
477
    return (0);
561
478
}
562
479
 
563
 
/*
564
 
   \return -1 error
565
 
   \return  0 OK 
566
 
 */
567
 
int dig_Rd_Plus_head(GVFILE * fp, struct Plus_head *ptr)
 
480
/*!
 
481
  \brief Read Plus_head from file
 
482
 
 
483
  \param fp pointer to gvfile structure
 
484
  \param[in,out] ptr pointer to Plus_head structure
 
485
 
 
486
  \return -1 error
 
487
  \return  0 OK 
 
488
*/
 
489
int dig_Rd_Plus_head(struct gvfile * fp, struct Plus_head *ptr)
568
490
{
569
491
    unsigned char buf[5];
570
492
    int byte_order;
572
494
    dig_rewind(fp);
573
495
 
574
496
    /* bytes 1 - 5 */
575
 
    if (0 >= dig__fread_port_C(buf, 5, fp))
 
497
    if (0 >= dig__fread_port_C((char *)buf, 5, fp))
576
498
        return (-1);
577
 
    ptr->Version_Major = buf[0];
578
 
    ptr->Version_Minor = buf[1];
579
 
    ptr->Back_Major = buf[2];
580
 
    ptr->Back_Minor = buf[3];
 
499
    ptr->version.topo.major = buf[0];
 
500
    ptr->version.topo.minor = buf[1];
 
501
    ptr->version.topo.back_major = buf[2];
 
502
    ptr->version.topo.back_minor = buf[3];
581
503
    byte_order = buf[4];
582
504
 
583
505
    G_debug(2,
584
506
            "Topo header: file version %d.%d , supported from GRASS version %d.%d",
585
 
            ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major,
586
 
            ptr->Back_Minor);
 
507
            ptr->version.topo.major, ptr->version.topo.minor, ptr->version.topo.back_major,
 
508
            ptr->version.topo.back_minor);
587
509
 
588
510
    G_debug(2, "  byte order %d", byte_order);
589
511
 
590
512
    /* check version numbers */
591
 
    if (ptr->Version_Major > GV_TOPO_VER_MAJOR ||
592
 
        ptr->Version_Minor > GV_TOPO_VER_MINOR) {
 
513
    if (ptr->version.topo.major > GV_TOPO_VER_MAJOR ||
 
514
        ptr->version.topo.minor > GV_TOPO_VER_MINOR) {
593
515
        /* The file was created by GRASS library with higher version than this one */
594
516
 
595
 
        if (ptr->Back_Major > GV_TOPO_VER_MAJOR ||
596
 
            ptr->Back_Minor > GV_TOPO_VER_MINOR) {
 
517
        if (ptr->version.topo.back_major > GV_TOPO_VER_MAJOR ||
 
518
            ptr->version.topo.back_minor > GV_TOPO_VER_MINOR) {
597
519
            /* This version of GRASS lib is lower than the oldest which can read this format */
598
520
            G_debug(1, "Topology format version %d.%d",
599
 
                    ptr->Version_Major, ptr->Version_Minor);
 
521
                    ptr->version.topo.major, ptr->version.topo.minor);
600
522
            G_fatal_error
601
 
                ("This version of GRASS (%d.%d) is too old to read this topology format."
602
 
                 " Try to rebuild topology or upgrade GRASS to at least version %d.",
 
523
                (_("This version of GRASS (%d.%d) is too old to read this topology format."
 
524
                 " Try to rebuild topology or upgrade GRASS to at least version %d."),
603
525
                 GRASS_VERSION_MAJOR, GRASS_VERSION_MINOR, GRASS_VERSION_MAJOR + 1);
604
526
            return (-1);
605
527
        }
606
528
 
607
 
        G_warning
608
 
            ("Your GRASS version does not fully support topology format %d.%d of the vector."
609
 
             " Consider to rebuild topology or upgrade GRASS.",
610
 
             ptr->Version_Major, ptr->Version_Minor);
611
 
    }
612
 
 
 
529
        G_warning(_("Your GRASS version does not fully support topology format %d.%d of the vector."
 
530
                    " Consider to rebuild topology or upgrade GRASS."),
 
531
                  ptr->version.topo.major, ptr->version.topo.minor);
 
532
    }
 
533
    if (ptr->version.topo.major < GV_TOPO_VER_MAJOR ||
 
534
        (ptr->version.topo.major == GV_TOPO_VER_MAJOR &&
 
535
         ptr->version.topo.minor < GV_TOPO_VER_MINOR)) {
 
536
        /* The file was created by GRASS library with lower version than this one */
 
537
 
 
538
        /* This version of GRASS lib can not read this old format */
 
539
        G_warning(_("Old topology format version %d.%d is not supported by this release."
 
540
                    " Try to rebuild topology."),
 
541
                  ptr->version.topo.major, ptr->version.topo.minor);
 
542
        return (-1);
 
543
    }
 
544
 
 
545
    /* init Port_info structure and set as default */
613
546
    dig_init_portable(&(ptr->port), byte_order);
614
547
    dig_set_cur_port(&(ptr->port));
615
548
 
618
551
        return (-1);
619
552
    G_debug(2, "  header size %ld", ptr->head_size);
620
553
 
 
554
    /* determine required offset size from header size */
 
555
    /* this is not safe in case new fields get added in later versions */
 
556
    /* better: add a new field with off_t_size after byte_order? */
 
557
    if (ptr->head_size >= 142 + 32) /* keep in sync with dig_Wr_Plus_head() */
 
558
        ptr->off_t_size = 8;
 
559
    else
 
560
        ptr->off_t_size = 4;
 
561
 
 
562
    if (sizeof(off_t) < ptr->off_t_size) {
 
563
        G_warning(_("Vector exceeds supported file size limit"));
 
564
        return (-1);
 
565
    }
 
566
 
 
567
    G_debug(2, "topo off_t size = %d", ptr->off_t_size);
 
568
 
621
569
    /* byte 10 : dimension 2D or 3D */
622
 
    if (0 >= dig__fread_port_C(buf, 1, fp))
 
570
    if (0 >= dig__fread_port_C((char *)buf, 1, fp))
623
571
        return (-1);
624
572
    ptr->with_z = buf[0];
625
573
    G_debug(2, "  with_z %d", ptr->with_z);
669
617
        return (-1);
670
618
 
671
619
    /* bytes 111 - 138 : Offset */
672
 
    if (0 >= dig__fread_port_L(&(ptr->Node_offset), 1, fp))
673
 
        return (-1);
674
 
    if (0 >= dig__fread_port_L(&(ptr->Edge_offset), 1, fp))
675
 
        return (-1);
676
 
    if (0 >= dig__fread_port_L(&(ptr->Line_offset), 1, fp))
677
 
        return (-1);
678
 
    if (0 >= dig__fread_port_L(&(ptr->Area_offset), 1, fp))
679
 
        return (-1);
680
 
    if (0 >= dig__fread_port_L(&(ptr->Isle_offset), 1, fp))
681
 
        return (-1);
682
 
    if (0 >= dig__fread_port_L(&(ptr->Volume_offset), 1, fp))
683
 
        return (-1);
684
 
    if (0 >= dig__fread_port_L(&(ptr->Hole_offset), 1, fp))
 
620
    if (0 >= dig__fread_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
 
621
        return (-1);
 
622
    if (0 >= dig__fread_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
 
623
        return (-1);
 
624
    if (0 >= dig__fread_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
 
625
        return (-1);
 
626
    if (0 >= dig__fread_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
 
627
        return (-1);
 
628
    if (0 >= dig__fread_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
 
629
        return (-1);
 
630
    if (0 >= dig__fread_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
 
631
        return (-1);
 
632
    if (0 >= dig__fread_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
685
633
        return (-1);
686
634
 
687
635
    /* bytes 139 - 142 : Coor size and time */
688
 
    if (0 >= dig__fread_port_L(&(ptr->coor_size), 1, fp))
 
636
    if (0 >= dig__fread_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
689
637
        return (-1);
690
638
 
691
 
    G_debug(2, "  coor size %ld", ptr->coor_size);
 
639
    G_debug(2, "  coor size %"PRI_OFF_T, ptr->coor_size);
692
640
 
693
641
    dig_fseek(fp, ptr->head_size, SEEK_SET);
694
642
 
695
643
    return (0);
696
644
}
697
645
 
698
 
int dig_Wr_Plus_head(GVFILE * fp, struct Plus_head *ptr)
 
646
int dig_Wr_Plus_head(struct gvfile * fp, struct Plus_head *ptr)
699
647
{
700
648
    unsigned char buf[10];
701
649
    long length = 142;
709
657
    buf[2] = GV_TOPO_EARLIEST_MAJOR;
710
658
    buf[3] = GV_TOPO_EARLIEST_MINOR;
711
659
    buf[4] = ptr->port.byte_order;
712
 
    if (0 >= dig__fwrite_port_C(buf, 5, fp))
 
660
    if (0 >= dig__fwrite_port_C((char *)buf, 5, fp))
713
661
        return (-1);
714
662
 
 
663
    /* determine required offset size from coor file size */
 
664
    if (ptr->coor_size > (off_t)PORT_LONG_MAX) {
 
665
        /* can only happen when sizeof(off_t) == 8 */
 
666
        ptr->off_t_size = 8;
 
667
    }
 
668
    else
 
669
        ptr->off_t_size = 4;
 
670
 
 
671
    /* add a new field with off_t_size after byte_order? */
 
672
 
 
673
    /* adjust header size for large files */
 
674
    if (ptr->off_t_size == 8) {
 
675
        /* 7 offset values and coor file size: add 8 * 4 */
 
676
        length += 32;
 
677
    }
 
678
 
715
679
    /* bytes 6 - 9 : header size */
716
680
    if (0 >= dig__fwrite_port_L(&length, 1, fp))
717
681
        return (0);
718
682
 
719
683
    /* byte 10 : dimension 2D or 3D */
720
684
    buf[0] = ptr->with_z;
721
 
    if (0 >= dig__fwrite_port_C(buf, 1, fp))
 
685
    if (0 >= dig__fwrite_port_C((char *)buf, 1, fp))
722
686
        return (0);
723
687
 
724
688
    /* bytes 11 - 58 : bound box */
766
730
        return (-1);
767
731
 
768
732
    /* bytes 111 - 138 : Offset */
769
 
    if (0 >= dig__fwrite_port_L(&(ptr->Node_offset), 1, fp))
770
 
        return (-1);
771
 
    if (0 >= dig__fwrite_port_L(&(ptr->Edge_offset), 1, fp))
772
 
        return (-1);
773
 
    if (0 >= dig__fwrite_port_L(&(ptr->Line_offset), 1, fp))
774
 
        return (-1);
775
 
    if (0 >= dig__fwrite_port_L(&(ptr->Area_offset), 1, fp))
776
 
        return (-1);
777
 
    if (0 >= dig__fwrite_port_L(&(ptr->Isle_offset), 1, fp))
778
 
        return (-1);
779
 
    if (0 >= dig__fwrite_port_L(&(ptr->Volume_offset), 1, fp))
780
 
        return (-1);
781
 
    if (0 >= dig__fwrite_port_L(&(ptr->Hole_offset), 1, fp))
 
733
    if (0 >= dig__fwrite_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
 
734
        return (-1);
 
735
    if (0 >= dig__fwrite_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
 
736
        return (-1);
 
737
    if (0 >= dig__fwrite_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
 
738
        return (-1);
 
739
    if (0 >= dig__fwrite_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
 
740
        return (-1);
 
741
    if (0 >= dig__fwrite_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
 
742
        return (-1);
 
743
    if (0 >= dig__fwrite_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
 
744
        return (-1);
 
745
    if (0 >= dig__fwrite_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
782
746
        return (-1);
783
747
 
784
748
    /* bytes 139 - 142 : Coor size and time */
785
 
    if (0 >= dig__fwrite_port_L(&(ptr->coor_size), 1, fp))
 
749
    if (0 >= dig__fwrite_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
786
750
        return (-1);
787
751
 
788
 
    G_debug(2, "topo body offset %ld", dig_ftell(fp));
 
752
    G_debug(2, "topo body offset %"PRI_OFF_T, dig_ftell(fp));
789
753
 
790
754
    return (0);
791
755
}