#include "csv.h"
#include "csv_local.h"
#include "csv_extern.h"
static int usage(void);
DB_ENV *dbenv;
DB *db;
DB **secondary;
int verbose;
char *progname;
int
main(int argc, char *argv[])
{
input_fmt ifmt;
u_long version;
int ch, ret, t_ret;
char *home;
dbenv = NULL;
db = NULL;
if ((progname = strrchr(argv[0], '/')) == NULL)
progname = argv[0];
else
++progname;
verbose = 0;
home = NULL;
ifmt = FORMAT_NL;
version = 1;
while ((ch = getopt(argc, argv, "F:f:h:V:v")) != EOF)
switch (ch) {
case 'f':
if (freopen(optarg, "r", stdin) == NULL) {
fprintf(stderr,
"%s: %s\n", optarg, db_strerror(errno));
return (EXIT_FAILURE);
}
break;
case 'F':
if (strcasecmp(optarg, "excel") == 0) {
ifmt = FORMAT_EXCEL;
break;
}
return (usage());
case 'h':
home = optarg;
break;
case 'V':
if (strtoul_err(optarg, &version))
return (EXIT_FAILURE);
break;
case 'v':
++verbose;
break;
case '?':
default:
return (usage());
}
argc -= optind;
argv += optind;
if (*argv != NULL)
return (usage());
if (home == NULL)
home = getenv("DB_HOME");
if (home != NULL)
(void)mkdir(home, S_IRWXU);
if (csv_env_open(home, 0) != 0)
return (EXIT_FAILURE);
ret = input_load(ifmt, version);
if ((t_ret = csv_env_close()) != 0 && ret == 0)
ret = t_ret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
static int
usage(void)
{
(void)fprintf(stderr,
"usage: %s [-v] [-F excel] [-f csv-file] [-h home]\n", progname);
return (EXIT_FAILURE);
}