[GRASS-CVS] martinl: grass6/vector/v.in.ascii a2b.c, 1.17, 1.18 in.c, 1.50, 1.51

grass at intevation.de grass at intevation.de
Sun Nov 25 06:23:59 EST 2007


Author: martinl

Update of /grassrepository/grass6/vector/v.in.ascii
In directory doto:/tmp/cvs-serv22219

Modified Files:
	a2b.c in.c 
Log Message:
Run indent
Message standardization


Index: a2b.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/a2b.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- a2b.c	6 Oct 2007 01:54:22 -0000	1.17
+++ a2b.c	25 Nov 2007 11:23:57 -0000	1.18
@@ -6,158 +6,164 @@
 
 #define BUFFSIZE 128
 
-int asc_to_bin(
-	FILE *ascii ,
-	struct Map_info *Map)
+int asc_to_bin(FILE * ascii, struct Map_info *Map)
 {
-	char ctype ;
-	char buff[BUFFSIZE];
-	double *xarray ;
-	double *yarray ;
-	double *zarray ;	
-	double *x, *y, *z;
-	int i, n_points, n_coors, n_cats ;
-	int type;
-	int alloc_points ;
-	int end_of_file ;
-	struct line_pnts *Points;
-	struct line_cats *Cats;	
-	int catn;
-	int cat;
+    char ctype;
+    char buff[BUFFSIZE];
+    double *xarray;
+    double *yarray;
+    double *zarray;
+    double *x, *y, *z;
+    int i, n_points, n_coors, n_cats;
+    int type;
+    int alloc_points;
+    int end_of_file;
+    struct line_pnts *Points;
+    struct line_cats *Cats;
+    int catn;
+    int cat;
 
-	/* Must always use this to create an initialized  line_pnts structure */
-	Points = Vect_new_line_struct ();
-	Cats = Vect_new_cats_struct ();	
+    /* Must always use this to create an initialized  line_pnts structure */
+    Points = Vect_new_line_struct();
+    Cats = Vect_new_cats_struct();
 
-	end_of_file = 0 ;
-	/*alloc_points     = 1000 ; */
-	alloc_points     = 1;
-	xarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
-	yarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
-	zarray = (double *) G_calloc(alloc_points, sizeof(double)) ;
+    end_of_file = 0;
+    /*alloc_points     = 1000 ; */
+    alloc_points = 1;
+    xarray = (double *)G_calloc(alloc_points, sizeof(double));
+    yarray = (double *)G_calloc(alloc_points, sizeof(double));
+    zarray = (double *)G_calloc(alloc_points, sizeof(double));
 
 
-	while( G_getl2(buff,BUFFSIZE-1,ascii) != 0 )
-	{
-	    n_cats=0;
-	    if (buff[0] == '\0') {
-		G_debug(3, "a2b: skipping blank line");
-		continue;
-	    }
+    while (G_getl2(buff, BUFFSIZE - 1, ascii) != 0) {
+	n_cats = 0;
+	if (buff[0] == '\0') {
+	    G_debug(3, "a2b: skipping blank line");
+	    continue;
+	}
 
-	    if (  sscanf(buff, "%1c%d%d", &ctype, &n_coors, &n_cats) < 2  || n_coors < 0 || n_cats < 0 ) {
-		if (ctype == '#') {
-		    G_debug(2, "a2b: skipping commented line");
-		    continue;
-		}
-		G_fatal_error(_("Error reading ASCII file: (bad type) [%s]"), buff);
-	    }
+	if (sscanf(buff, "%1c%d%d", &ctype, &n_coors, &n_cats) < 2 ||
+	    n_coors < 0 || n_cats < 0) {
 	    if (ctype == '#') {
-		G_debug(2, "a2b: Skipping commented line");
+		G_debug(2, "a2b: skipping commented line");
 		continue;
 	    }
+	    G_fatal_error(_("Error reading ASCII file: (bad type) [%s]"), buff);
+	}
+	if (ctype == '#') {
+	    G_debug(2, "a2b: Skipping commented line");
+	    continue;
+	}
 
-	    switch(ctype){
-		case 'A':
-			type = GV_BOUNDARY ;
-			break ;
-		case 'B':
-			type = GV_BOUNDARY ;
-			break ;
-		case 'C':
-			type = GV_CENTROID ;
-			break ;			
-		case 'L':
-			type = GV_LINE ;
-			break ;
-		case 'P':
-			type = GV_POINT ;
-			break ;
-		case 'F':
-			type = GV_FACE ;
-			break ;
-		case 'K':
-			type = GV_KERNEL ;
-			break ;
-		case 'a':
-		case 'b':
-		case 'c':
-		case 'l':
-		case 'p':
-			type = 0; /* dead -> ignore */
-			break;
-		default:
-			G_fatal_error(_("Error reading ASCII file: (unknown type) [%s]"), buff);
-	    }
-	    G_debug(5, "feature type = %d", type);
+	switch (ctype) {
+	case 'A':
+	    type = GV_BOUNDARY;
+	    break;
+	case 'B':
+	    type = GV_BOUNDARY;
+	    break;
+	case 'C':
+	    type = GV_CENTROID;
+	    break;
+	case 'L':
+	    type = GV_LINE;
+	    break;
+	case 'P':
+	    type = GV_POINT;
+	    break;
+	case 'F':
+	    type = GV_FACE;
+	    break;
+	case 'K':
+	    type = GV_KERNEL;
+	    break;
+	case 'a':
+	case 'b':
+	case 'c':
+	case 'l':
+	case 'p':
+	    type = 0;		/* dead -> ignore */
+	    break;
+	default:
+	    G_fatal_error(_("Error reading ASCII file: (unknown type) [%s]"),
+			  buff);
+	}
+	G_debug(5, "feature type = %d", type);
 
-	    n_points = 0 ;
-	    x = xarray ;
-	    y = yarray ;
-	    z = zarray ;		
+	n_points = 0;
+	x = xarray;
+	y = yarray;
+	z = zarray;
 
-	    /* Collect the points */
-	    for( i=0; i<n_coors; i++)
-	    {
-		    if ( G_getl2(buff,BUFFSIZE-1,ascii) == 0 )
-			G_fatal_error(_("End of ASCII file reached before end of coordinates")) ;
+	/* Collect the points */
+	for (i = 0; i < n_coors; i++) {
+	    if (G_getl2(buff, BUFFSIZE - 1, ascii) == 0)
+		G_fatal_error(_
+			      ("End of ASCII file reached before end of coordinates"));
 
-		    if (buff[0] == '\0') {
-			G_debug(3, "a2b: skipping blank line while reading vertices");
-			i--;
-			continue;
-		    }
+	    if (buff[0] == '\0') {
+		G_debug(3, "a2b: skipping blank line while reading vertices");
+		i--;
+		continue;
+	    }
 
-		    *z=0;
-		    if ( sscanf(buff, "%lf%lf%lf", x, y, z) < 2 )
-		        G_fatal_error(_("Error reading ASCII file: (bad point) [%s]"), buff);
+	    *z = 0;
+	    if (sscanf(buff, "%lf%lf%lf", x, y, z) < 2)
+		G_fatal_error(_("Error reading ASCII file: (bad point) [%s]"),
+			      buff);
 
-		    G_debug( 5, "coor in: %s -> x = %f y = %f z = %f", G_chop(buff), *x, *y, *z);
-		    
-		    n_points++;
-		    x++;
-		    y++;
-		    z++;			
-    
-		    if (n_points >= alloc_points)
-		    {
-			    alloc_points = n_points + 1000 ;
-			    xarray = (double *) G_realloc((void *)xarray, alloc_points * sizeof(double) );
-			    yarray = (double *) G_realloc((void *)yarray, alloc_points * sizeof(double) );
-			    zarray = (double *) G_realloc((void *)zarray, alloc_points * sizeof(double) );
-			    x = xarray + n_points ;
-			    y = yarray + n_points ;
-			    z = zarray + n_points ;
-		    }
-	    }
+	    G_debug(5, "coor in: %s -> x = %f y = %f z = %f", G_chop(buff), *x,
+		    *y, *z);
 
-	    /* Collect the cats */
-	    for( i=0; i<n_cats; i++)
-	    {
-		    if ( G_getl2(buff,BUFFSIZE-1,ascii) == 0 )
-			G_fatal_error(_("End of ASCII file reached before end of categories"));
+	    n_points++;
+	    x++;
+	    y++;
+	    z++;
 
-		    if (buff[0] == '\0') {
-			G_debug(3, "a2b: skipping blank line while reading category info");
-			i--;
-			continue;
-		    }
+	    if (n_points >= alloc_points) {
+		alloc_points = n_points + 1000;
+		xarray =
+		    (double *)G_realloc((void *)xarray,
+					alloc_points * sizeof(double));
+		yarray =
+		    (double *)G_realloc((void *)yarray,
+					alloc_points * sizeof(double));
+		zarray =
+		    (double *)G_realloc((void *)zarray,
+					alloc_points * sizeof(double));
+		x = xarray + n_points;
+		y = yarray + n_points;
+		z = zarray + n_points;
+	    }
+	}
 
-		    if ( sscanf(buff, "%u%u", &catn, &cat) != 2 )
-			G_fatal_error(_("Error reading categories: [%s]"), buff);
+	/* Collect the cats */
+	for (i = 0; i < n_cats; i++) {
+	    if (G_getl2(buff, BUFFSIZE - 1, ascii) == 0)
+		G_fatal_error(_
+			      ("End of ASCII file reached before end of categories"));
 
-		    Vect_cat_set ( Cats, catn, cat );
+	    if (buff[0] == '\0') {
+		G_debug(3,
+			"a2b: skipping blank line while reading category info");
+		i--;
+		continue;
 	    }
 
-	    /* Allocation is handled for line_pnts */
-	    if (0 > Vect_copy_xyz_to_pnts (Points, xarray, yarray, zarray, n_points))
-		G_fatal_error(_("Out of memory"));
+	    if (sscanf(buff, "%u%u", &catn, &cat) != 2)
+		G_fatal_error(_("Error reading categories: [%s]"), buff);
 
-	    if ( type > 0 )
-		Vect_write_line ( Map, type, Points, Cats );
-    
-	    Vect_reset_cats ( Cats ); 
+	    Vect_cat_set(Cats, catn, cat);
 	}
-	return 0;	
-}
 
+	/* Allocation is handled for line_pnts */
+	if (0 > Vect_copy_xyz_to_pnts(Points, xarray, yarray, zarray, n_points))
+	    G_fatal_error(_("Out of memory"));
+
+	if (type > 0)
+	    Vect_write_line(Map, type, Points, Cats);
+
+	Vect_reset_cats(Cats);
+    }
+    return 0;
+}

Index: in.c
===================================================================
RCS file: /grassrepository/grass6/vector/v.in.ascii/in.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- in.c	14 Oct 2007 16:43:29 -0000	1.50
+++ in.c	25 Nov 2007 11:23:57 -0000	1.51
@@ -1,3 +1,4 @@
+
 /****************************************************************************
  *
  * MODULE:       v.in.ascii
@@ -26,474 +27,513 @@
 
 #define	A_DIR	"dig_ascii"
 
-int 
-main (int argc, char *argv[])
+int main(int argc, char *argv[])
 {
-	FILE *ascii;
-	struct GModule *module;
-	struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt, 
-		*ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
-	int    xcol, ycol, zcol, catcol, format, skip_lines;
-	struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag, *region_flag;
-	char   *table;
-	char   *fs;
-	int    zcoor=WITHOUT_Z, make_table; 
+    FILE *ascii;
+    struct GModule *module;
+    struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
+	*ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
+    int xcol, ycol, zcol, catcol, format, skip_lines;
+    struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag,
+	*region_flag;
+    char *table;
+    char *fs;
+    int zcoor = WITHOUT_Z, make_table;
 
-	struct Map_info Map;
+    struct Map_info Map;
 
-	G_gisinit(argv[0]);
+    G_gisinit(argv[0]);
 
-	module = G_define_module();
-	module->keywords = _("vector, import");
-	module->description =
-	    _("Creates a vector map from ASCII points file or ASCII vector file.");
+    module = G_define_module();
+    module->keywords = _("vector, import");
+    module->description =
+	_("Creates a vector map from ASCII points file or ASCII vector file.");
 
-        /************************** Command Parser ************************************/
-	old = G_define_standard_option (G_OPT_F_INPUT);
-	old->required	 =  NO;
-	old->description =
-	    _("ASCII file to be imported, if not given reads from standard input");
+    /************************** Command Parser ************************************/
+    old = G_define_standard_option(G_OPT_F_INPUT);
+    old->required = NO;
+    old->description =
+	_("ASCII file to be imported, if not given reads from standard input");
 
-	new = G_define_standard_option(G_OPT_V_OUTPUT);
+    new = G_define_standard_option(G_OPT_V_OUTPUT);
 
-	format_opt = G_define_option();
-	format_opt->key         = "format";
-	format_opt->type        =  TYPE_STRING;
-	format_opt->required    =  NO;
-	format_opt->multiple    =  NO;
-	format_opt->options     = "point,standard";
-	format_opt->answer      = "point";
-	format_opt->description = _("Input file format");
+    format_opt = G_define_option();
+    format_opt->key = "format";
+    format_opt->type = TYPE_STRING;
+    format_opt->required = NO;
+    format_opt->multiple = NO;
+    format_opt->options = "point,standard";
+    format_opt->answer = "point";
+    format_opt->description = _("Input file format");
 
-	delim_opt = G_define_option();
-	delim_opt->key = "fs";
-	delim_opt->type = TYPE_STRING;
-	delim_opt->required = NO;
-	delim_opt->description = _("Field separator");
-	delim_opt->answer = "|";
+    delim_opt = G_define_standard_option(G_OPT_F_SEP);
 
-	skip_opt = G_define_option();
-	skip_opt->key = "skip";
-	skip_opt->type = TYPE_INTEGER;
-	skip_opt->required = NO;
-	skip_opt->multiple = NO;
-	skip_opt->answer = "0";
-	skip_opt->description =
-	    _("Number of header lines to skip at top of input file (points mode)");
+    skip_opt = G_define_option();
+    skip_opt->key = "skip";
+    skip_opt->type = TYPE_INTEGER;
+    skip_opt->required = NO;
+    skip_opt->multiple = NO;
+    skip_opt->answer = "0";
+    skip_opt->description =
+	_("Number of header lines to skip at top of input file (points mode)");
 
-	columns_opt = G_define_option();
-	columns_opt->key = "columns";
-	columns_opt->type = TYPE_STRING;
-	columns_opt->required = NO;
-	columns_opt->multiple = NO;
-	columns_opt->guisection = _("Columns");
-	columns_opt->label = _("Column definition in SQL style (points mode)");
-	columns_opt->description = _("For example: "
-				     "'x double precision, y double precision, cat int, name varchar(10)'");
+    columns_opt = G_define_standard_option(G_OPT_COLUMNS);
+    columns_opt->multiple = NO;
+    columns_opt->guisection = _("Columns");
+    columns_opt->label = _("Column definition in SQL style (points mode)");
+    columns_opt->description = _("For example: "
+				 "'x double precision, y double precision, cat int, "
+				 "name varchar(10)'");
 
-	xcol_opt = G_define_option();
-	xcol_opt->key = "x";
-	xcol_opt->type = TYPE_INTEGER;
-	xcol_opt->required = NO;
-	xcol_opt->multiple = NO;
-	xcol_opt->answer = "1";
-	xcol_opt->guisection = _("Columns");
-	xcol_opt->description =
-	    _("Number of column used as x coordinate (first column is 1) for points mode");
+    xcol_opt = G_define_option();
+    xcol_opt->key = "x";
+    xcol_opt->type = TYPE_INTEGER;
+    xcol_opt->required = NO;
+    xcol_opt->multiple = NO;
+    xcol_opt->answer = "1";
+    xcol_opt->guisection = _("Columns");
+    xcol_opt->description =
+	_
+	("Number of column used as x coordinate (first column is 1) for points mode");
 
-	ycol_opt = G_define_option();
-	ycol_opt->key = "y";
-	ycol_opt->type = TYPE_INTEGER;
-	ycol_opt->required = NO;
-	ycol_opt->multiple = NO;
-	ycol_opt->answer = "2";
-	ycol_opt->guisection = _("Columns");
-	ycol_opt->description =
-	    _("Number of column used as y coordinate (first column is 1) for points mode");
+    ycol_opt = G_define_option();
+    ycol_opt->key = "y";
+    ycol_opt->type = TYPE_INTEGER;
+    ycol_opt->required = NO;
+    ycol_opt->multiple = NO;
+    ycol_opt->answer = "2";
+    ycol_opt->guisection = _("Columns");
+    ycol_opt->description =
+	_
+	("Number of column used as y coordinate (first column is 1) for points mode");
 
-	zcol_opt = G_define_option();
-	zcol_opt->key = "z";
-	zcol_opt->type = TYPE_INTEGER;
-	zcol_opt->required = NO;
-	zcol_opt->multiple = NO;
-	zcol_opt->answer = "0";
-	zcol_opt->guisection = _("Columns");
-	zcol_opt->label =
-	    _("Number of column used as z coordinate (first column is 1) for "
-	      "points mode");
-	zcol_opt->description = 
-	    _("If 0, z coordinate is not used");
+    zcol_opt = G_define_option();
+    zcol_opt->key = "z";
+    zcol_opt->type = TYPE_INTEGER;
+    zcol_opt->required = NO;
+    zcol_opt->multiple = NO;
+    zcol_opt->answer = "0";
+    zcol_opt->guisection = _("Columns");
+    zcol_opt->label =
+	_("Number of column used as z coordinate (first column is 1) for "
+	  "points mode");
+    zcol_opt->description = _("If 0, z coordinate is not used");
 
-	catcol_opt = G_define_option();
-	catcol_opt->key = "cat";
-	catcol_opt->type = TYPE_INTEGER;
-	catcol_opt->required = NO;
-	catcol_opt->multiple = NO;
-	catcol_opt->answer = "0";
-	catcol_opt->guisection = _("Columns");
-	catcol_opt->label =
-	    _("Number of column used as category (first column is 1) for points mode");
-	catcol_opt->description = 
-	    _("If 0, unique category is assigned to each row and written to new column 'cat'");
+    catcol_opt = G_define_option();
+    catcol_opt->key = "cat";
+    catcol_opt->type = TYPE_INTEGER;
+    catcol_opt->required = NO;
+    catcol_opt->multiple = NO;
+    catcol_opt->answer = "0";
+    catcol_opt->guisection = _("Columns");
+    catcol_opt->label =
+	_
+	("Number of column used as category (first column is 1) for points mode");
+    catcol_opt->description =
+	_
+	("If 0, unique category is assigned to each row and written to new column 'cat'");
 
-	zcoorf = G_define_flag ();
-	zcoorf->key           	= 'z';
-	zcoorf->description   	= _("Create 3D file");  
+    zcoorf = G_define_flag();
+    zcoorf->key = 'z';
+    zcoorf->description = _("Create 3D file");
 
-	e_flag = G_define_flag();
-	e_flag->key              = 'e';
-	e_flag->description      =
-	    _("Create a new empty map and exit. Nothing is read from input");
+    e_flag = G_define_flag();
+    e_flag->key = 'e';
+    e_flag->description =
+	_("Create a new empty map and exit. Nothing is read from input");
 
-	noheader_flag = G_define_flag();
-	noheader_flag->key          = 'n';
-	noheader_flag->description  =
-	    _("Don't expect a header when reading in standard format");
+    noheader_flag = G_define_flag();
+    noheader_flag->key = 'n';
+    noheader_flag->description =
+	_("Don't expect a header when reading in standard format");
 
-	t_flag = G_define_flag();
-	t_flag->key              = 't';
-	t_flag->description      = _("Do not create table in points mode");
+    t_flag = G_define_flag();
+    t_flag->key = 't';
+    t_flag->description = _("Do not create table in points mode");
 
-	notopol_flag = G_define_flag();
-	notopol_flag->key          = 'b';
-	notopol_flag->description  = _("Do not build topology in points mode");
+    notopol_flag = G_define_flag();
+    notopol_flag->key = 'b';
+    notopol_flag->description = _("Do not build topology in points mode");
 
-	region_flag = G_define_flag();
-	region_flag->key          = 'r';
-	region_flag->description  =
-	    _("Only import points falling within current region (points mode)");
+    region_flag = G_define_flag();
+    region_flag->key = 'r';
+    region_flag->description =
+	_("Only import points falling within current region (points mode)");
 
 
-	if (G_parser (argc, argv))
-	    exit(EXIT_FAILURE);
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
 
 
-	if ( format_opt->answer[0] == 'p' )
-	    format = FORMAT_POINT;
-	else
-            format = FORMAT_ALL;
+    if (format_opt->answer[0] == 'p')
+	format = FORMAT_POINT;
+    else
+	format = FORMAT_ALL;
 
-	skip_lines = atoi(skip_opt->answer);
-	if(skip_lines < 0)
-	    G_fatal_error(_("Please specify reasonable number of lines to skip"));
+    skip_lines = atoi(skip_opt->answer);
+    if (skip_lines < 0)
+	G_fatal_error(_("Please specify reasonable number of lines to skip"));
 
-	if (zcoorf->answer && format == FORMAT_POINT && zcol_opt->answer == "0")
-	    G_fatal_error(_("Please specify z column"));
+    if (zcoorf->answer && format == FORMAT_POINT && !zcol_opt->answer)
+	G_fatal_error(_("Please specify z column"));
 
-	xcol = atoi(xcol_opt->answer) - 1;
-	ycol = atoi(ycol_opt->answer) - 1;
-	zcol = atoi(zcol_opt->answer) - 1;
+    xcol = atoi(xcol_opt->answer) - 1;
+    ycol = atoi(ycol_opt->answer) - 1;
+    zcol = atoi(zcol_opt->answer) - 1;
 
-	/* specifying zcol= implies that a 3D map is needed */
-	if(zcol>=0 && !zcoorf->answer)
-	    zcoorf->answer = 1;
+    /* specifying zcol= implies that a 3D map is needed */
+    if (zcol >= 0 && !zcoorf->answer)
+	zcoorf->answer = 1;
 
-	if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
-	    G_fatal_error(_("Please specify reasonable z column"));
+    if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
+	G_fatal_error(_("Please specify reasonable z column"));
 
-	catcol = atoi(catcol_opt->answer) - 1;
+    catcol = atoi(catcol_opt->answer) - 1;
 
-	if ( old->answer != NULL ) {
-	    if ( (ascii = fopen ( old->answer, "r" ) ) == NULL )
-	    {
-	        G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
-	    }
-        } else {
-	    ascii = stdin;
-        }
+    if (old->answer != NULL) {
+	if ((ascii = fopen(old->answer, "r")) == NULL) {
+	    G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
+	}
+    }
+    else {
+	ascii = stdin;
+    }
 
-	fs = delim_opt->answer;
-	if ( strcmp(fs,"\\t") == 0 ) fs = "\t";
-	if ( strcmp(fs,"tab") == 0 ) fs = "\t";
-	if ( strcmp(fs,"space") == 0 ) fs = " ";
+    fs = delim_opt->answer;
+    if (strcmp(fs, "\\t") == 0)
+	fs = "\t";
+    if (strcmp(fs, "tab") == 0)
+	fs = "\t";
+    if (strcmp(fs, "space") == 0)
+	fs = " ";
 
-	/* check dimension */
-	if (zcoorf->answer) {
-	    zcoor = 1;	    
-	}
+    /* check dimension */
+    if (zcoorf->answer) {
+	zcoor = 1;
+    }
 
-	Vect_open_new (&Map, new->answer, zcoor);
-	Vect_hist_command ( &Map );
+    Vect_open_new(&Map, new->answer, zcoor);
+    Vect_hist_command(&Map);
 
-	if ( e_flag->answer ) { 
-	    Vect_build ( &Map, stdout );
-	    Vect_close ( &Map );
-	    exit(EXIT_SUCCESS) ;
+    if (e_flag->answer) {
+	Vect_build(&Map, stdout);
+	Vect_close(&Map);
+	exit(EXIT_SUCCESS);
+    }
+
+    if (format == FORMAT_POINT) {
+	int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen;
+	int n_int = 0, n_double = 0, n_string = 0;
+	char buf[1000];
+	struct field_info *Fi;
+	char *tmp, *key;
+	dbDriver *driver;
+	dbString sql;
+	FILE *tmpascii;
+
+	/* Open temporary file */
+	tmp = G_tempfile();
+	if (NULL == (tmpascii = fopen(tmp, "w+"))) {
+	    G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
 	}
+	unlink(tmp);
 
-	if ( format == FORMAT_POINT ) {
-	    int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen;
-	    int n_int = 0, n_double = 0, n_string = 0;
-	    char buf[1000];
-	    struct field_info *Fi;
-	    char *tmp, *key;
-	    dbDriver *driver;
-	    dbString sql;
-	    FILE *tmpascii;
+	points_analyse(ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
+		       &coltype, &collen, skip_lines, xcol, ycol,
+		       region_flag->answer);
 
-	    /* Open temporary file */
-	    tmp = G_tempfile();
-	    if (NULL == (tmpascii = fopen(tmp, "w+"))) {
-		G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
-	    }
-	    unlink(tmp);
+	G_message(_("Maximum input row length: %d"), rowlen);
+	G_message(_("Maximum number of columns: %d"), ncols);
+	G_message(_("Minimum number of columns: %d"), minncols);
 
-	    points_analyse ( ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
-			     &coltype, &collen, skip_lines, xcol, ycol, region_flag->answer);
+	/* check column numbers */
+	if (xcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_
+			  ("x column number > minimum last column number\n(incorrect field separator?)"));
+	}
+	if (ycol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_
+			  ("y column number > minimum last column number\n(incorrect field separator?)"));
+	}
+	if (zcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("z column number > minimum last column number "
+			    "(incorrect field separator?)"));
+	}
+	if (catcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("cat column number > minimum last column number "
+			    "(incorrect field separator?)"));
+	}
 
-	    G_message(_("Maximum input row length: %d"), rowlen);
-	    G_message(_("Maximum number of columns: %d"), ncols);
-	    G_message(_("Minimum number of columns: %d"), minncols);
+	if (coltype[xcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("x column is not of number type"));
+	}
+	if (coltype[ycol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("y column is not of number type"));
+	}
+	if (zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("z column is not of number type"));
+	}
+	if (catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("cat column is not of number type"));
+	}
 
-	    /* check column numbers */
-	    if ( xcol >= minncols ) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("x column number > minimum last column number\n(incorrect field separator?)"));
-	    }
-	    if ( ycol >= minncols ) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("y column number > minimum last column number\n(incorrect field separator?)"));
-	    }
-	    if ( zcol >= minncols ) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("z column number > minimum last column number\n(incorrect field separator?)"));
+	/* Create table */
+	make_table = 0;
+	for (i = 0; i < ncols; i++) {
+	    if (xcol != i && ycol != i && zcol != i && catcol != i) {
+		make_table = 1;
+		break;
 	    }
-	    if ( catcol >= minncols ) {
+	}
+	if (t_flag->answer) {
+	    make_table = 0;
+	}
+
+	if (make_table) {
+	    Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
+	    driver =
+		db_start_driver_open_database(Fi->driver,
+					      Vect_subst_var(Fi->database,
+							     &Map));
+	    if (driver == NULL) {
 		Vect_delete(new->answer);
-		G_fatal_error(_("cat column number > minimum last column number\n(incorrect field separator?)"));
+		G_fatal_error(_("Unavle to open database <%s> by driver <%s>"),
+			      Vect_subst_var(Fi->database, &Map), Fi->driver);
 	    }
+	    db_begin_transaction(driver);
 
-	    if ( coltype[xcol] == DB_C_TYPE_STRING ) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("x column is not of number type"));
-	    }
-	    if ( coltype[ycol] == DB_C_TYPE_STRING ) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("y column is not of number type"));
-	    }
-	    if ( zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING ) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("z column is not of number type"));
+	    db_init_string(&sql);
+	    sprintf(buf, "create table %s ( ", Fi->table);
+	    db_append_string(&sql, buf);
+
+	    if (catcol < 0) {
+		db_append_string(&sql, "cat integer, ");
 	    }
-	    if ( catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING ) {
+
+	    for (i = 0; i < ncols; i++) {
+		if (i > 0 && !columns_opt->answer) {
+		    db_append_string(&sql, ", ");
+		}
+		if (catcol == i && coltype[i] != DB_C_TYPE_INT) {
 		    Vect_delete(new->answer);
-		    G_fatal_error(_("cat column is not of number type"));
-	    }
+		    G_fatal_error(_("Category column is not of integer type"));
+		}
 
-	    /* Create table */
-	    make_table = 0;
-	    for ( i = 0 ; i < ncols; i++ ) {
-		if ( xcol != i && ycol != i && zcol != i && catcol != i ) {
-		    make_table = 1;
+		switch (coltype[i]) {
+		case DB_C_TYPE_INT:
+		    G_verbose_message("Column: %d  type: integer", i + 1);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "int_%d integer", n_int + 1);
+			db_append_string(&sql, buf);
+			if (catcol == i) {
+			    sprintf(buf, "int_%d", n_int + 1);
+			    key = G_store(buf);
+			}
+		    }
+		    n_int++;
+		    break;
+		case DB_C_TYPE_DOUBLE:
+		    G_verbose_message("Column: %d  type: double", i + 1);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "dbl_%d double precision", n_double + 1);
+			db_append_string(&sql, buf);
+		    }
+		    n_double++;
+		    break;
+		case DB_C_TYPE_STRING:
+		    G_verbose_message("Column: %d  type: string length: %d",
+				      i + 1, collen[i]);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "str_%d varchar(%d)", n_string + 1,
+				collen[i]);
+			db_append_string(&sql, buf);
+		    }
+		    n_string++;
 		    break;
 		}
 	    }
-	    if ( t_flag->answer ) {
-		make_table = 0;
+	    if (columns_opt->answer) {
+		db_append_string(&sql, columns_opt->answer);
 	    }
+	    db_append_string(&sql, " )");
 
-	    if ( make_table ) {	
-		Fi = Vect_default_field_info ( &Map, 1, NULL, GV_1TABLE );
-		driver = db_start_driver_open_database ( Fi->driver, Vect_subst_var(Fi->database,&Map) );
-		if ( driver == NULL ) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("Cannot open database <%s> by driver <%s>"),
-			    Vect_subst_var(Fi->database,&Map), Fi->driver );
-		}
-		db_begin_transaction ( driver );
+	    /* this link is added with default 'cat' key, later deleted and replaced by true key name,
+	     * otherwise if module crashes when the table exists but link is not written it makes troubles */
+	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, "cat", Fi->database,
+				Fi->driver);
 
-		db_init_string (&sql);
-		sprintf ( buf, "create table %s ( ", Fi->table );
-		db_append_string ( &sql, buf );
+	    /* Create table */
+	    G_debug(3, db_get_string(&sql));
+	    if (db_execute_immediate(driver, &sql) != DB_OK) {
+		Vect_delete(new->answer);
+		G_fatal_error(_("Unable create table: %s"),
+			      db_get_string(&sql));
+	    }
 
-		if ( catcol < 0 ) { 
-		    db_append_string ( &sql, "cat integer, " );
-		}
+	    /* Grant */
+	    if (db_grant_on_table
+		(driver, Fi->table, DB_PRIV_SELECT,
+		 DB_GROUP | DB_PUBLIC) != DB_OK) {
+		Vect_delete(new->answer);
+		G_fatal_error(_("Unable to grant privileges on table <%s>"),
+			      Fi->table);
+	    }
 
-		for ( i = 0 ; i < ncols; i++ ) {
-		    if ( i > 0 && !columns_opt->answer ) {
-			db_append_string ( &sql, ", " );
-		    }
-		    if ( catcol == i && coltype[i] != DB_C_TYPE_INT ) {
-			Vect_delete(new->answer); 
-			G_fatal_error(_("Category column is not of integer type"));
-		    }
+	    /* Check column types */
+	    if (columns_opt->answer) {
+		int nc;
+		dbTable *table;
+		dbColumn *column;
 
-		    switch ( coltype[i] ) {
-			case DB_C_TYPE_INT:
-                            G_verbose_message ("Column: %d  type: integer", i+1);
-			    if ( !columns_opt->answer ) {
-				sprintf ( buf, "int_%d integer", n_int+1);
-				db_append_string ( &sql, buf);
-				if ( catcol == i ) {
-				    sprintf ( buf, "int_%d", n_int+1);
-				    key = G_store( buf );
-				}
-			    }
-			    n_int++;
-			    break;
-			case DB_C_TYPE_DOUBLE:
-                            G_verbose_message ("Column: %d  type: double", i+1);
-			    if ( !columns_opt->answer ) {
-				sprintf ( buf, "dbl_%d double precision", n_double+1);
-				db_append_string ( &sql, buf);
-			    }
-			    n_double++;
-			    break;
-			case DB_C_TYPE_STRING:
-                            G_verbose_message ("Column: %d  type: string length: %d", i+1, collen[i]);
-			    if ( !columns_opt->answer ) {
-				sprintf ( buf, "str_%d varchar(%d)", n_string+1, collen[i]);
-				db_append_string ( &sql, buf);
-			    }
-			    n_string++;
-			    break;
-		    }
-		}
-		if ( columns_opt->answer ) {
-		    db_append_string ( &sql, columns_opt->answer );
+		db_set_string(&sql, Fi->table);
+		if (db_describe_table(driver, &sql, &table) != DB_OK) {
+		    Vect_delete(new->answer);
+		    G_fatal_error(_("Unable to describe table <%s>"),
+				  Fi->table);
 		}
-		db_append_string ( &sql, " )" );
 
-		/* this link is added with default 'cat' key, later deleted and replaced by true key name,
-		 * otherwise if module crashes when the table exists but link is not written it makes troubles */ 
-		Vect_map_add_dblink ( &Map, 1, NULL, Fi->table, "cat", Fi->database, Fi->driver);
+		nc = db_get_table_number_of_columns(table);
 
-		/* Create table */
-		G_debug ( 3, db_get_string ( &sql ) );
-		if (db_execute_immediate (driver, &sql) != DB_OK ) {
+		if ((catcol >= 0 && nc != ncols) ||
+		    (catcol < 0 && (nc - 1) != ncols)) {
 		    Vect_delete(new->answer);
-		    G_fatal_error(_("Cannot create table: %s"), db_get_string ( &sql )  );
+		    G_fatal_error(_
+				  ("Number of columns defined (%d) does not match number "
+				   "of columns (%d) in input"),
+				  catcol < 0 ? nc - 1 : nc, ncols);
 		}
 
-		/* Grant */
-		if (db_grant_on_table (driver, Fi->table, DB_PRIV_SELECT, DB_GROUP|DB_PUBLIC ) != DB_OK ) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("Cannot grant privileges on table <%s>"), Fi->table );
-		}
+		coltype2 = (int *)G_malloc(ncols * sizeof(int));
 
-		/* Check column types */
-		if ( columns_opt->answer ) {
-		    int nc;
-		    dbTable *table;
-		    dbColumn *column;
-		    
-		    db_set_string ( &sql, Fi->table );
-		    if(db_describe_table (driver, &sql, &table) != DB_OK) {
-			Vect_delete(new->answer);
-			G_fatal_error(_("Cannot describe table <%s>"), Fi->table);
-		    }
-				
-		    nc = db_get_table_number_of_columns(table);
+		for (i = 0; i < ncols; i++) {
+		    int dbcol, ctype, length;
 
-		    if ( (catcol >= 0 && nc != ncols) || (catcol < 0 && (nc-1) != ncols) ) {
-			Vect_delete(new->answer);
-			G_fatal_error(_("Number of columns defined (%d) does not match number "
-					"of columns (%d) in input"), catcol < 0 ? nc-1 : nc, ncols);
-		    }
+		    if (catcol < 0)
+			dbcol = i + 1;	/* first is category */
+		    else
+			dbcol = i;
 
-		    coltype2 = (int *) G_malloc ( ncols * sizeof(int) );
+		    column = db_get_table_column(table, dbcol);
+		    ctype = db_sqltype_to_Ctype(db_get_column_sqltype(column));
+		    length = db_get_column_length(column);
+		    coltype2[i] = ctype;
 
-		    for ( i = 0; i < ncols; i++ ) {
-			int dbcol, ctype, length;
+		    if (catcol == i) {	/* if catcol == -1 it cannot be tru */
+			key = G_store(db_get_column_name(column));
+		    }
 
-			if ( catcol < 0 ) dbcol = i+1; /* first is category */
-			else dbcol = i;
-			
-			column = db_get_table_column ( table, dbcol );
-			ctype =  db_sqltype_to_Ctype ( db_get_column_sqltype(column) );
-			length = db_get_column_length ( column );
-			coltype2[i] = ctype;
-			
-			if ( catcol == i ) { /* if catcol == -1 it cannot be tru */
-			    key = G_store(db_get_column_name(column));
+		    switch (coltype[i]) {
+		    case DB_C_TYPE_INT:
+			if (ctype == DB_C_TYPE_DOUBLE) {
+			    G_warning(_("Column number %d defined as double "
+					"has only integer values"), i + 1);
 			}
-
-			switch ( coltype[i] ) {
-			    case DB_C_TYPE_INT:
-				if ( ctype == DB_C_TYPE_DOUBLE ) {
-				    G_warning(_("Column number [%d] defined as double has only integer values"), i+1);
-				} else if ( ctype == DB_C_TYPE_STRING ) {
-				    G_warning(_("Column number [%d] defined as string has only integer values"), i+1);
-				}
-				break;
-			    case DB_C_TYPE_DOUBLE:
-				if ( ctype == DB_C_TYPE_INT ) {
-				    Vect_delete(new->answer);
-				    G_fatal_error(_("Column number [%d] defined as integer has double values"), i+1);
-				} else if ( ctype == DB_C_TYPE_STRING ) {
-				    G_warning(_("Column number [%d] defined as string has double values"), i+1);
-				}
-				break;
-			    case DB_C_TYPE_STRING:
-				if ( ctype == DB_C_TYPE_INT ) {
-				    Vect_delete(new->answer);
-				    G_fatal_error(_("Column number [%d] defined as integer has string values"), i+1);
-				} else if ( ctype == DB_C_TYPE_DOUBLE ) {
-				    Vect_delete(new->answer);
-				    G_fatal_error(_("Column number [%d] defined as double has string values"), i+1);
-				}
-				if ( length < collen[i] ) {
-				    Vect_delete(new->answer);
-				    G_fatal_error(_("Length of column [%d] (%d) is less than maximum value "
-						    "length (%d)"), i+1, length, collen[i]);
-				}
-				break;
+			else if (ctype == DB_C_TYPE_STRING) {
+			    G_warning(_("Column number %d defined as string "
+					"has only integer values"), i + 1);
+			}
+			break;
+		    case DB_C_TYPE_DOUBLE:
+			if (ctype == DB_C_TYPE_INT) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_
+					  ("Column number %d defined as integer "
+					   "has double values"), i + 1);
+			}
+			else if (ctype == DB_C_TYPE_STRING) {
+			    G_warning(_("Column number %d defined as string "
+					"has double values"), i + 1);
+			}
+			break;
+		    case DB_C_TYPE_STRING:
+			if (ctype == DB_C_TYPE_INT) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_
+					  ("Column number %d defined as integer "
+					   "has string values"), i + 1);
+			}
+			else if (ctype == DB_C_TYPE_DOUBLE) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_
+					  ("Column number %d defined as double "
+					   "has string values"), i + 1);
+			}
+			if (length < collen[i]) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_
+					  ("Length of column %d (%d) is less than "
+					   "maximum value " "length (%d)"),
+					  i + 1, length, collen[i]);
 			}
+			break;
 		    }
-		} else {
-		    coltype2 = coltype;
-		}
-
-		if ( catcol < 0 ) {
-		   key = "cat";	
-		} else if ( !columns_opt->answer ) {
-		    
-
 		}
+	    }
+	    else {
+		coltype2 = coltype;
+	    }
 
-		if ( db_create_index2(driver, Fi->table, key ) != DB_OK )
-		    G_warning(_("Cannot create index"));
+	    if (catcol < 0) {
+		key = "cat";
+	    }
+	    else if (!columns_opt->answer) {
 
-		Vect_map_del_dblink ( &Map, 1 );
-		Vect_map_add_dblink ( &Map, 1, NULL, Fi->table, key, Fi->database, Fi->driver);
 
-		table = Fi->table;
-	    } else { 
-		driver = NULL;
-		table = NULL;
 	    }
 
-	    points_to_bin ( tmpascii, rowlen, &Map, driver, table, fs, ncols,
-			    coltype2, xcol, ycol, zcol, catcol, skip_lines );
+	    if (db_create_index2(driver, Fi->table, key) != DB_OK)
+		G_warning(_("Unable to create index for table <%s>, key <%s>"),
+			  Fi->table, key);
 
-	    if ( driver ) {
-		G_message(_("Populating table..."));
-	        db_commit_transaction ( driver );
-	        db_close_database_shutdown_driver ( driver );
-	    }
-	    fclose (tmpascii);
+	    Vect_map_del_dblink(&Map, 1);
+	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, key, Fi->database,
+				Fi->driver);
+
+	    table = Fi->table;
+	}
+	else {
+	    driver = NULL;
+	    table = NULL;
 	}
 
-	else {  /* FORMAT_ALL (standard mode) */
-    	    if ( ! noheader_flag->answer )
-		read_head(ascii, &Map);
+	points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, ncols,
+		      coltype2, xcol, ycol, zcol, catcol, skip_lines);
 
-	    asc_to_bin(ascii, &Map) ;
+	if (driver) {
+	    G_message(_("Populating table..."));
+	    db_commit_transaction(driver);
+	    db_close_database_shutdown_driver(driver);
 	}
+	fclose(tmpascii);
+    }
 
-	if ( old->answer != NULL )
-	    fclose(ascii);
+    else {			/* FORMAT_ALL (standard mode) */
+	if (!noheader_flag->answer)
+	    read_head(ascii, &Map);
 
-        if ( notopol_flag->answer ) {
-            Vect_close ( &Map );
-        }
-        else {
-	    Vect_build ( &Map, stdout );
-	    Vect_close ( &Map );
-        }
+	asc_to_bin(ascii, &Map);
+    }
 
-	G_done_msg("");
+    if (old->answer != NULL)
+	fclose(ascii);
 
-	exit(EXIT_SUCCESS);
+    if (notopol_flag->answer) {
+	Vect_close(&Map);
+    }
+    else {
+	Vect_build(&Map, stdout);
+	Vect_close(&Map);
+    }
+
+    G_done_msg(" ");
+
+    exit(EXIT_SUCCESS);
 }




More information about the grass-commit mailing list