frmt.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <grass/config.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <grass/Vect.h>
  21. #include <grass/gis.h>
  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. G_debug(3, "dig_read_frmt_ascii()");
  33. /* read first line which must be FORMAT: */
  34. if (G_getl2(buff, 2000, dascii)) {
  35. G_chop(buff);
  36. if (!(ptr = G_index(buff, ':'))) {
  37. G_warning("Vector format not recognized: %s", buff);
  38. return (-1);
  39. }
  40. strcpy(buf1, buff);
  41. buf1[ptr - buff] = '\0';
  42. ptr++; /* Search for the start of text */
  43. while (*ptr == ' ')
  44. ptr++;
  45. if (strcmp(buf1, "FORMAT") == 0) {
  46. if (G_strcasecmp(ptr, "ogr") == 0) {
  47. frmt = GV_FORMAT_OGR;
  48. }
  49. }
  50. }
  51. if (frmt == -1) {
  52. G_warning("Vector format not recognized: %s", buff);
  53. return (-1);
  54. }
  55. /* init format info values */
  56. #ifdef HAVE_OGR
  57. finfo->ogr.dsn = NULL;
  58. finfo->ogr.layer_name = NULL;
  59. #endif
  60. while (G_getl2(buff, 2000, dascii)) {
  61. G_chop(buff);
  62. if (!(ptr = G_index(buff, ':'))) {
  63. G_warning("Format definition is not correct: %s", buff);
  64. continue;
  65. }
  66. strcpy(buf1, buff);
  67. buf1[ptr - buff] = '\0';
  68. ptr++; /* Search for the start of text */
  69. while (*ptr == ' ')
  70. ptr++;
  71. #ifdef HAVE_OGR
  72. if (strcmp(buf1, "DSN") == 0)
  73. finfo->ogr.dsn = G_store(ptr);
  74. if (strcmp(buf1, "LAYER") == 0)
  75. finfo->ogr.layer_name = G_store(ptr);
  76. #endif
  77. }
  78. return frmt;
  79. }
  80. /* Write vector format, currently does not work
  81. * Parse also connection string.
  82. *
  83. * Returns: 0 OK
  84. * -1 on error
  85. */
  86. int dig_write_frmt_ascii(FILE * dascii, struct Format_info *finfo, int format)
  87. {
  88. G_debug(3, "dig_write_frmt_ascii()");
  89. G_fatal_error("Format not supported by dig_write_frmt_ascii()");
  90. return 0;
  91. }