GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
frmt.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: Vector library
5  *
6  * AUTHOR(S): Radim Blazek
7  *
8  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
9  *
10  * COPYRIGHT: (C) 2001 by the GRASS Development Team
11  *
12  * This program is free software under the GNU General Public
13  * License (>=v2). Read the file COPYING that comes with GRASS
14  * for details.
15  *
16  *****************************************************************************/
17 #include <string.h>
18 #include <stdio.h>
19 #include <grass/Vect.h>
20 #include <grass/gis.h>
21 
22 /* Read vector format.
23  *
24  * Returns: format number
25  * -1 on error
26  */
27 int dig_read_frmt_ascii(FILE * dascii, struct Format_info *finfo)
28 {
29  char buff[20001], buf1[1024];
30  char *ptr;
31  int frmt = -1;
32 
33  G_debug(3, "dig_read_frmt_ascii()");
34 
35  /* read first line which must be FORMAT: */
36  if (G_getl2(buff, 2000, dascii)) {
37  G_chop(buff);
38 
39  if (!(ptr = G_index(buff, ':'))) {
40  G_warning("Vector format not recognized: %s", buff);
41  return (-1);
42  }
43 
44  strcpy(buf1, buff);
45  buf1[ptr - buff] = '\0';
46 
47  ptr++; /* Search for the start of text */
48  while (*ptr == ' ')
49  ptr++;
50 
51  if (strcmp(buf1, "FORMAT") == 0) {
52  if (G_strcasecmp(ptr, "ogr") == 0) {
53  frmt = GV_FORMAT_OGR;
54  }
55  }
56  }
57  if (frmt == -1) {
58  G_warning("Vector format not recognized: %s", buff);
59  return (-1);
60  }
61 
62  /* init format info values */
63 #ifdef HAVE_OGR
64  finfo->ogr.dsn = NULL;
65  finfo->ogr.layer_name = NULL;
66 #endif
67 
68  while (G_getl2(buff, 2000, dascii)) {
69  G_chop(buff);
70 
71  if (!(ptr = G_index(buff, ':'))) {
72  G_warning("Format definition is not correct: %s", buff);
73  continue;
74  }
75 
76  strcpy(buf1, buff);
77  buf1[ptr - buff] = '\0';
78 
79  ptr++; /* Search for the start of text */
80  while (*ptr == ' ')
81  ptr++;
82 
83 #ifdef HAVE_OGR
84  if (strcmp(buf1, "DSN") == 0)
85  finfo->ogr.dsn = G_store(ptr);
86  if (strcmp(buf1, "LAYER") == 0)
87  finfo->ogr.layer_name = G_store(ptr);
88 #endif
89  }
90 
91  return frmt;
92 }
93 
94 /* Write vector format, currently does not work
95  * Parse also connection string.
96  *
97  * Returns: 0 OK
98  * -1 on error
99  */
100 int dig_write_frmt_ascii(FILE * dascii, struct Format_info *finfo, int format)
101 {
102  G_debug(3, "dig_write_frmt_ascii()");
103 
104  G_fatal_error("Format not supported by dig_write_frmt_ascii()");
105 
106  return 0;
107 }
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
Definition: strings.c:192
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
char * G_index(const char *str, int delim)
delimiter
Definition: gis/index.c:16
char * G_chop(char *line)
Chop leading and trailing white spaces:
Definition: strings.c:418
int dig_write_frmt_ascii(FILE *dascii, struct Format_info *finfo, int format)
Definition: frmt.c:100
char buff[1024]
Definition: g3dcats.c:89
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig_read_frmt_ascii(FILE *dascii, struct Format_info *finfo)
Definition: frmt.c:27