GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
vector/Vlib/handler.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/Vlib/handler.c
3
4 \brief Vector library - standard error handlers
5
6 Higher level functions for reading/writing/manipulating vectors.
7
8 SPDX-FileCopyrightText: 2011 GRASS Development Team
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 \author Martin Landa <landa.martin gmail.com>
12 */
13
14#include <grass/gis.h>
15#include <grass/vector.h>
16
17struct handler_data_io {
18 struct Map_info *In;
19 struct Map_info *Out;
20};
21
22static struct handler_data_io *handler_io;
23
24static void error_handler_io(void *p G_UNUSED)
25{
26 char *name;
27 struct Map_info *In, *Out;
28
29 In = handler_io->In;
30 Out = handler_io->Out;
31
32 if (In && In->open == VECT_OPEN_CODE)
33 Vect_close(In);
34
35 if (Out && Out->open == VECT_OPEN_CODE) {
36 name = G_store(Out->name);
37 Vect_close(Out);
39 G_free(name);
40 }
41}
42
43/*!
44 \brief Define standard error handler for input and output vector maps
45
46 This handler:
47 - close input vector map on error
48 - close and delete output vector map on error
49
50 Note: It's recommended to call this routine after Vect_open_old() or
51 Vect_open_old2().
52
53 \param In pointer in Map_info struct (input vector map) or NULL
54 \param Out pointer to Map_info struct (output vector map) or NULL
55 */
56void Vect_set_error_handler_io(struct Map_info *In, struct Map_info *Out)
57{
58 if (!handler_io)
59 handler_io = G_malloc(sizeof(struct handler_data_io));
60
61 handler_io->In = In;
62 handler_io->Out = Out;
63
64 G_add_error_handler(error_handler_io, handler_io);
65}
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_malloc(n)
Definition defs/gis.h:136
void G_add_error_handler(void(*)(void *), void *)
Add new error handler.
Definition gis/handler.c:68
char * G_store(const char *)
Copy string to allocated memory.
Definition strings.c:85
int Vect_close(struct Map_info *)
Close vector map.
int Vect_delete(const char *)
Delete vector map including attribute tables.
Definition map.c:365
#define VECT_OPEN_CODE
Vector map open code.
#define G_UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition gis.h:43
const char * name
Definition named_colr.c:6
Vector map info.
char * name
Map name (for 4.0)
int open
Open indicator.
void Vect_set_error_handler_io(struct Map_info *In, struct Map_info *Out)
Define standard error handler for input and output vector maps.