frmt.c

Go to the documentation of this file.
00001 /*
00002 * $Id: frmt.c,v 1.9 2006/02/09 03:08:58 glynn Exp $
00003 *
00004 ****************************************************************************
00005 *
00006 * MODULE:       Vector library 
00007 *               
00008 * AUTHOR(S):    Radim Blazek
00009 *
00010 * PURPOSE:      Lower level functions for reading/writing/manipulating vectors.
00011 *
00012 * COPYRIGHT:    (C) 2001 by the GRASS Development Team
00013 *
00014 *               This program is free software under the GNU General Public
00015 *               License (>=v2). Read the file COPYING that comes with GRASS
00016 *               for details.
00017 *
00018 *****************************************************************************/
00019 #include <string.h>
00020 #include <stdio.h>
00021 #include <grass/Vect.h>
00022 #include <grass/gis.h>
00023 
00024 /* Read vector format.
00025 *
00026 *  Returns: format number
00027 *           -1 on error
00028 */           
00029 int 
00030 dig_read_frmt_ascii ( FILE *dascii, struct Format_info *finfo)
00031 {
00032   char buff[20001], buf1[1024];
00033   char *ptr;
00034   int  frmt = -1;
00035 
00036   G_debug ( 3, "dig_read_frmt_ascii()" );
00037           
00038   /* read first line which must be FORMAT: */
00039   if ( G_getl2 (buff, 2000, dascii) ) {
00040       G_chop (buff);
00041       
00042       if (!(ptr = G_index (buff, ':'))) {
00043           G_warning ("Vector format not recognized: %s", buff);
00044           return (-1);   
00045       }
00046 
00047       strcpy ( buf1, buff ); buf1[ptr - buff] = '\0';
00048       
00049       ptr++;                    /* Search for the start of text */
00050       while (*ptr == ' ') ptr++;
00051 
00052       if (strcmp (buf1, "FORMAT" ) == 0) {
00053           if ( G_strcasecmp (ptr, "ogr") == 0) {
00054               frmt = GV_FORMAT_OGR; 
00055           }       
00056       }
00057   }    
00058   if ( frmt == -1) {
00059       G_warning ("Vector format not recognized: %s", buff);
00060       return (-1);       
00061   }
00062 
00063   /* init format info values */
00064 #ifdef HAVE_OGR   
00065   finfo->ogr.dsn        = NULL;
00066   finfo->ogr.layer_name = NULL;
00067 #endif
00068           
00069   while ( G_getl2 (buff, 2000, dascii) )
00070   {
00071       G_chop (buff);
00072       
00073       if (!(ptr = G_index (buff, ':'))) {
00074           G_warning ("Format definition is not correct: %s", buff);
00075           continue;
00076       }
00077 
00078       strcpy ( buf1, buff ); buf1[ptr - buff] = '\0';
00079 
00080       ptr++;                    /* Search for the start of text */
00081       while (*ptr == ' ') ptr++;
00082      
00083 #ifdef HAVE_OGR   
00084       if (strcmp (buf1, "DSN") == 0)
00085           finfo->ogr.dsn    = G_store (ptr);
00086       if (strcmp (buf1, "LAYER") == 0)
00087           finfo->ogr.layer_name = G_store (ptr);
00088 #endif
00089     }
00090 
00091     return frmt;
00092 }
00093 
00094 /* Write vector format, currently does not work
00095 *  Parse also connection string.
00096 *
00097 *  Returns: 0 OK
00098 *           -1 on error
00099 */           
00100 int 
00101 dig_write_frmt_ascii ( FILE *dascii, struct Format_info *finfo, int format)
00102 {
00103     G_debug ( 3, "dig_write_frmt_ascii()");
00104     
00105     G_fatal_error ("Format not supported by dig_write_frmt_ascii()");
00106 
00107     return 0;
00108 }
00109 

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5