]> granicus.if.org Git - postgis/commitdiff
Simplify table/schema copying, hopefully fix windows.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 25 Feb 2012 20:30:42 +0000 (20:30 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 25 Feb 2012 20:30:42 +0000 (20:30 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9301 b70326c6-7e19-0410-871a-916f4a2858ee

loader/shp2pgsql-cli.c

index 6fa41b8494cfaf3fe6359152d2504377a58c1f15..b62ff6d6370f9ca189b402930bc91df1b12731a0 100644 (file)
@@ -259,23 +259,27 @@ main (int argc, char **argv)
        /* Determine the table and schema names from the next argument */
        if (pgis_optind < argc)
        {
-               char *ptr;
-
-               ptr = strchr(argv[pgis_optind], '.');
+               char *strptr = argv[pgis_optind];
+               char *chrptr = strchr(strptr, '.');
 
                /* Schema qualified table name */
-               if (ptr)
+               if (chrptr)
                {
-                       config->schema = malloc(strlen(argv[pgis_optind]) + 1);
-                       snprintf(config->schema, ptr - argv[pgis_optind] + 1, "%s", argv[pgis_optind]);
-
-                       config->table = malloc(strlen(argv[pgis_optind]));
-                       snprintf(config->table, strlen(argv[pgis_optind]) - strlen(config->schema), "%s", ptr + 1);
+                       if ( chrptr == strptr ) 
+                       {
+                               /* ".something" ??? */
+                               usage();
+                               exit(0);
+                       }
+                       /* Null terminate the '.' */
+                       *chrptr = 0;
+                       /* Copy in the parts */
+                       config->schema = strdup(strptr);
+                       config->table = strdup(chrptr+1);
                }
                else
                {
-                       config->table = malloc(strlen(argv[pgis_optind]) + 1);
-                       strcpy(config->table, argv[pgis_optind]);
+                       config->table = strdup(strptr);
                }
        }