/*
* Copyright (c) 2021 Clementine Computing LLC.
*
* This file is part of PopuFare.
*
* PopuFare is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PopuFare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with PopuFare. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "../common/common_config.h"
#include "../passdb/passdb.h"
#define VERSION "0.1.0"
void _version(FILE *fp) {
fprintf(fp, "version: %s\n", VERSION);
}
void _usage(FILE *fp) {
_version(fp);
fprintf(fp, "usage:\n\n");
fprintf(fp, " passdb_inspect [-h] [-v] [passdb]\n\n");
fprintf(fp, " [passdb] passdb file (defualt '%s')\n", PASSES_FILE);
fprintf(fp, " [-h] help (this screen)\n");
fprintf(fp, " [-v] show version\n");
fprintf(fp, "\n");
}
struct option g_long_option[] = {
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{0,0,0,0}
};
char *g_pass_file = NULL;
double del_tv( struct timeval *tv_e, struct timeval *tv_s) {
double d=0.0;
d += (double)(tv_e->tv_sec - tv_s->tv_sec) * (1000000.0);
d += (double)(tv_e->tv_usec - tv_s->tv_usec);
return d;
}
int main(int argc, char **argv) {
int i, j, k;
extern char *optarg;
extern int optind;
int option_index;
int ch;
int retcode = 0;
int fd;
ssize_t del_s=0;
size_t offset=0, pass_size=0;
rider_record *passmem = NULL;
struct timeval tv_s, tv_e;
while ((ch = getopt_long(argc, argv, "hv", g_long_option, &option_index)) > 0) switch(ch) {
case 'h':
_usage(stdout);
exit(0);
break;
case 'v':
_version(stdout);
exit(0);
break;
case 0:
default:
fprintf(stderr, "bad option (%i, %i)\n", option_index, (int)ch);
_usage(stderr);
exit(-2);
break;
}
if (optind < argc) {
g_pass_file = strdup(argv[optind]);
} else {
g_pass_file = strdup(PASSES_FILE);
}
//---
gettimeofday(&tv_s, NULL);
pass_size = sizeof(rider_record)*NUM_STORED_PASSES;
passmem = (rider_record *)malloc(pass_size);
fd = open(g_pass_file, O_RDONLY);
if (fd<0) {
perror(g_pass_file);
retcode = -1;
goto free_and_exit;
}
while (offset < pass_size) {
del_s = read(fd, ((void *)passmem) + offset, pass_size - offset);
if (del_s<0) {
perror(g_pass_file);
goto free_and_exit;
}
offset += del_s;
}
close(fd);
gettimeofday(&tv_e, NULL);
printf("## loaded in %f\n", del_tv(&tv_e, &tv_s));
//---
for (i=0; i