1 /***************************************************************
2  *
3  * MODULE:       v.info
4  *
5  * AUTHOR(S):    CERL, updated to 5.7 by Markus Neteler
6  *               Update to 7.0 by Martin Landa <landa.martin gmail.com> (2009)
7  *               Support for level 1 by Markus Metz (2009)
8  *
9  * PURPOSE:      Print vector map info
10  *
11  * COPYRIGHT:    (C) 2002-2009, 2011 by the GRASS Development Team
12  *
13  *               This program is free software under the GNU General
14  *               Public License (>=v2).  Read the file COPYING that
15  *               comes with GRASS for details.
16  *
17  **************************************************************/
18 #include <stdlib.h>
19 #include <grass/gis.h>
20 #include <grass/vector.h>
21 #include <grass/glocale.h>
22 
23 #include "local_proto.h"
24 
main(int argc,char * argv[])25 int main(int argc, char *argv[])
26 {
27     struct GModule *module;
28 
29     char *input_opt, *field_opt;
30     int hist_flag, col_flag, shell_flag;
31 
32     struct Map_info Map;
33 
34     G_gisinit(argv[0]);
35 
36     module = G_define_module();
37     G_add_keyword(_("vector"));
38     G_add_keyword(_("metadata"));
39     G_add_keyword(_("topology"));
40     G_add_keyword(_("extent"));
41     G_add_keyword(_("history"));
42     G_add_keyword(_("attribute columns"));
43     G_add_keyword(_("level1"));
44 
45     module->description =
46 	_("Outputs basic information about a vector map.");
47 
48     G_debug(1, "LFS is %s", sizeof(off_t) == 8 ? "available" : "not available");
49 
50     parse_args(argc, argv,
51 	       &input_opt, &field_opt,
52 	       &hist_flag, &col_flag, &shell_flag);
53 
54      /* try to open head-only on level 2 */
55     if (Vect_open_old_head2(&Map, input_opt, "", field_opt) < 2) {
56 	/* force level 1, open fully
57 	 * NOTE: number of points, lines, boundaries, centroids, faces, kernels is still available */
58 	Vect_close(&Map);
59 	Vect_set_open_level(1); /* no topology */
60 	if (Vect_open_old2(&Map, input_opt, "", field_opt) < 1)
61 	    G_fatal_error(_("Unable to open vector map <%s>"), Vect_get_full_name(&Map));
62 
63 	/* level one info not needed for history, title, columns */
64 	if (!hist_flag && !col_flag)
65 	    level_one_info(&Map);
66     }
67 
68     if (hist_flag || col_flag) {
69 	if (hist_flag) {
70 	    char buf[1001];
71 
72 	    Vect_hist_rewind(&Map);
73 	    while (Vect_hist_read(buf, 1000, &Map) != NULL) {
74 		fprintf(stdout, "%s\n", buf);
75 	    }
76 	}
77 	else if (col_flag) {
78 	    print_columns(&Map, input_opt, field_opt);
79 	}
80 	Vect_close(&Map);
81 
82 	return (EXIT_SUCCESS);
83     }
84 
85     if (shell_flag & SHELL_BASIC) {
86 	print_shell(&Map, field_opt);
87     }
88     if (shell_flag & SHELL_REGION) {
89 	print_region(&Map);
90     }
91     if (shell_flag & SHELL_TOPO) {
92 	print_topo(&Map);
93     }
94     if (shell_flag == 0) {
95 	print_info(&Map);
96     }
97 
98     Vect_close(&Map);
99 
100     return (EXIT_SUCCESS);
101 }
102