-/* $Id: cql2pqf.c,v 1.1 2003-10-27 12:21:39 adam Exp $
- Copyright (C) 2002-2003
+/* $Id: cql2pqf.c,v 1.7 2005-06-25 15:46:07 adam Exp $
+ Copyright (C) 1995-2005, Index Data ApS
Index Data Aps
This file is part of the YAZ toolkit.
#include <stdio.h>
#include <yaz/cql.h>
+#include <yaz/options.h>
+
+static void usage()
+{
+ fprintf (stderr, "usage\n cql2pqf [-n <n>] <properties> [<query>]\n");
+ exit (1);
+}
int main(int argc, char **argv)
{
cql_transform_t ct;
- int r;
- int i, it = 1;
+ int r = 0;
+ int i, iterations = 1;
CQL_parser cp = cql_parser_create();
+ char *query = 0;
+ char *fname = 0;
- if (argc < 2)
+ int ret;
+ char *arg;
+
+ while ((ret = options("n:", argv, argc, &arg)) != -2)
{
- fprintf (stderr, "usage\n cqltransform <properties> [<query>] [interations]\n");
- exit (1);
+ switch (ret)
+ {
+ case 0:
+ if (!fname)
+ fname = arg;
+ else
+ query = arg;
+ break;
+ case 'n':
+ iterations = atoi(arg);
+ break;
+ default:
+ usage();
+ }
}
- ct = cql_transform_open_fname(argv[1]);
+ if (!fname)
+ usage();
+ ct = cql_transform_open_fname(fname);
if (!ct)
{
- fprintf (stderr, "failed to read properties %s\n", argv[1]);
+ fprintf (stderr, "failed to read properties %s\n", fname);
exit (1);
}
- if (argc >= 4)
- it = atoi(argv[3]);
- for (i = 0; i<it; i++)
+ if (query)
{
- if (argc >= 3)
- r = cql_parser_string(cp, argv[2]);
+ for (i = 0; i<iterations; i++)
+ r = cql_parser_string(cp, query);
+ }
else
r = cql_parser_stdio(cp, stdin);
else
{
r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
- printf("\n");
+ printf("\n");
if (r)
{
const char *addinfo;
cql_transform_error(ct, &addinfo);
printf ("Transform error %d %s\n", r, addinfo ? addinfo : "");
}
- }
+ else
+ {
+ FILE *null = fopen("/dev/null", "w");
+ for (i = 1; i<iterations; i++)
+ cql_transform_FILE(ct, cql_parser_result(cp), null);
+ fclose(null);
+ }
}
cql_transform_close(ct);
cql_parser_destroy(cp);
return 0;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+