*/
#define ERR(s, c)\
- if(opterr){\
+ if(pgis_opterr){\
char errbuf[2];\
errbuf[0] = (char)c; errbuf[1] = '\n';\
(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
(void) write(2, errbuf, 2);\
}
-int opterr = 1;
-int optind = 1;
-int optopt;
-char *optarg;
+int pgis_opterr = 1;
+int pgis_optind = 1;
+int pgis_optopt;
+char *pgis_optarg;
int
pgis_getopt(int argc, char **argv, char *opts)
if (sp == 1)
{
- if (optind >= argc ||
- argv[optind][0] != '-' /* && argv[optind][0] != '/' */ ||
- argv[optind][1] == '\0')
+ if (pgis_optind >= argc ||
+ argv[pgis_optind][0] != '-' /* && argv[pgis_optind][0] != '/' */ ||
+ argv[pgis_optind][1] == '\0')
{
return(EOF);
}
- else if (strcmp(argv[optind], "--") == 0)
+ else if (strcmp(argv[pgis_optind], "--") == 0)
{
- optind++;
+ pgis_optind++;
return(EOF);
}
}
- optopt = c = argv[optind][sp];
+ pgis_optopt = c = argv[pgis_optind][sp];
if (c == ':' || (cp=strchr(opts, c)) == 0)
{
ERR(": illegal option -- ", c);
- if (argv[optind][++sp] == '\0')
+ if (argv[pgis_optind][++sp] == '\0')
{
- optind++;
+ pgis_optind++;
sp = 1;
}
return('?');
}
if (*++cp == ':')
{
- if (argv[optind][sp+1] != '\0')
- optarg = &argv[optind++][sp+1];
- else if (++optind >= argc)
+ if (argv[pgis_optind][sp+1] != '\0')
+ pgis_optarg = &argv[pgis_optind++][sp+1];
+ else if (++pgis_optind >= argc)
{
ERR(": option requires an argument -- ", c);
sp = 1;
return('?');
}
else
- optarg = argv[optind++];
+ pgis_optarg = argv[pgis_optind++];
sp = 1;
}
else
{
- if (argv[optind][++sp] == '\0')
+ if (argv[pgis_optind][++sp] == '\0')
{
sp = 1;
- optind++;
+ pgis_optind++;
}
- optarg = NULL;
+ pgis_optarg = NULL;
}
return(c);
}
/* declarations for getopt and envargs */
-extern int opterr;
-extern int optind;
-extern int optopt;
-extern char *optarg;
+extern int pgis_opterr;
+extern int pgis_optind;
+extern int pgis_optopt;
+extern char *pgis_optarg;
extern int pgis_getopt(int argc, char **argv, char *opts);
extern void envargs(int *pargc, char ***pargv, char *envstr);
binary = 1;
break;
case 'f':
- shp_file = optarg;
+ shp_file = pgis_optarg;
break;
case 'h':
- snprintf(buf + strlen(buf), 255, "host=%s ", optarg);
+ snprintf(buf + strlen(buf), 255, "host=%s ", pgis_optarg);
break;
case 'd':
dswitchprovided = 1;
unescapedattrs = 1;
break;
case 'u':
- snprintf(buf + strlen(buf), 255, "user=%s ", optarg);
+ snprintf(buf + strlen(buf), 255, "user=%s ", pgis_optarg);
break;
case 'p':
- snprintf(buf + strlen(buf), 255, "port=%s ", optarg);
+ snprintf(buf + strlen(buf), 255, "port=%s ", pgis_optarg);
break;
case 'P':
- snprintf(buf + strlen(buf), 255, "password=%s ", optarg);
+ snprintf(buf + strlen(buf), 255, "password=%s ", pgis_optarg);
break;
case 'g':
- geo_col_name = optarg;
+ geo_col_name = pgis_optarg;
break;
case 'k':
keep_fieldname_case = 1;
}
curindex=0;
- for (; optind<ARGC; optind++)
+ for (; pgis_optind<ARGC; pgis_optind++)
{
if (curindex == 0)
{
- snprintf(buf + strlen(buf), 255, "dbname=%s", ARGV[optind]);
+ snprintf(buf + strlen(buf), 255, "dbname=%s", ARGV[pgis_optind]);
}
else if (curindex == 1)
{
- parse_table(ARGV[optind]);
+ parse_table(ARGV[pgis_optind]);
}
curindex++;
break;
case 's':
- if (optarg)
+ if (pgis_optarg)
{
- sscanf(optarg, "%d", &(config->sr_id));
+ sscanf(pgis_optarg, "%d", &(config->sr_id));
}
else
{
break;
case 'g':
- config->geom = optarg;
+ config->geom = pgis_optarg;
break;
case 'k':
break;
case 'W':
- config->encoding = optarg;
+ config->encoding = pgis_optarg;
break;
case 'N':
- switch (optarg[0])
+ switch (pgis_optarg[0])
{
case 'a':
config->null_policy = POLICY_NULL_ABORT;
}
/* Determine the shapefile name from the next argument, if no shape file, exit. */
- if (optind < argc)
+ if (pgis_optind < argc)
{
- config->shp_file = argv[optind];
- optind++;
+ config->shp_file = argv[pgis_optind];
+ pgis_optind++;
}
else
{
}
/* Determine the table and schema names from the next argument */
- if (optind < argc)
+ if (pgis_optind < argc)
{
char *ptr;
- ptr = strchr(argv[optind], '.');
+ ptr = strchr(argv[pgis_optind], '.');
/* Schema qualified table name */
if (ptr)
{
- config->schema = malloc(strlen(argv[optind]) + 1);
- snprintf(config->schema, ptr - argv[optind] + 1, "%s", argv[optind]);
+ 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[optind]));
- snprintf(config->table, strlen(argv[optind]) - strlen(config->schema), "%s", ptr + 1);
+ config->table = malloc(strlen(argv[pgis_optind]));
+ snprintf(config->table, strlen(argv[pgis_optind]) - strlen(config->schema), "%s", ptr + 1);
}
else
{
- config->table = malloc(strlen(argv[optind]) + 1);
- strcpy(config->table, argv[optind]);
+ config->table = malloc(strlen(argv[pgis_optind]) + 1);
+ strcpy(config->table, argv[pgis_optind]);
}
}
{
lwcollection = lwcollection_construct(MULTILINETYPE, state->config->sr_id, NULL, obj->nParts, lwmultilinestrings);
serialized_lwgeom = lwgeom_serialize(lwcollection_as_lwgeom(lwcollection));
+
}
else
{
switch (c)
{
case 'U':
- conn->username = optarg;
+ conn->username = pgis_optarg;
break;
case 'p':
- conn->port = optarg;
+ conn->port = pgis_optarg;
break;
case 'W':
- conn->password = optarg;
+ conn->password = pgis_optarg;
break;
case 'd':
- conn->database = optarg;
+ conn->database = pgis_optarg;
break;
case 'h':
- conn->host = optarg;
+ conn->host = pgis_optarg;
break;
default:
usage();