-/*
- * $Source$
- * $Author$
- * $Header$
- *
- * Copyright (C) 1987 by the Massachusetts Institute of Technology
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
+/* $Id$
*
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
-#ifndef lint
-static char *rcsid_qsubs_c = "$Header$";
-#endif lint
-
#include <mit-copyright.h>
-#include <moira.h>
#include "mr_server.h"
#include "query.h"
-extern struct query Queries2[];
-extern int QueryCount2;
+#include <stdlib.h>
+
+RCSID("$Header$");
+
+extern struct query Queries[];
+extern int QueryCount;
+
+int qcmp(const void *q1, const void *q2);
struct query *get_query_by_name(char *name, int version)
{
- struct query *q;
int i;
- q = Queries2;
- i = QueryCount2;
+ i = QueryCount;
if (strlen(name) == 4)
{
while (--i >= 0)
{
- if (!strcmp(q->shortname, name))
- return q;
- q++;
+ if (!strcmp(Queries[i].shortname, name) &&
+ Queries[i].version <= version)
+ return &Queries[i];
}
}
else
{
while (--i >= 0)
{
- if (!strcmp(q->name, name))
- return q;
- q++;
+ if (!strcmp(Queries[i].name, name) &&
+ Queries[i].version <= version)
+ return &Queries[i];
}
}
return NULL;
}
-void list_queries(int version, int (*action)(), char *actarg)
+void list_queries(client *cl, int (*action)(int, char *[], void *),
+ void *actarg)
{
- struct query *q;
- int i;
- static struct query **squeries2 = NULL;
- struct query **sq;
+ static struct query **squeries = NULL;
+ static int qcount;
+ struct query *q, **sq;
char qnames[80];
char *qnp;
- int count;
- int qcmp();
+ int i;
- count = QueryCount2;
- if (!squeries2)
+ if (!squeries)
{
- sq = malloc(count * sizeof(struct query *));
- squeries2 = sq;
- q = Queries2;
- for (i = count; --i >= 0; )
- *sq++ = q++;
- qsort(squeries2, count, sizeof(struct query *), qcmp);
+ squeries = sq = xmalloc(QueryCount * sizeof(struct query *));
+ q = Queries;
+ for (i = 0; i < QueryCount; i++)
+ {
+ if (q->version > cl->version)
+ continue;
+ if (i > 0 && strcmp((*sq)->name, q->name))
+ sq++;
+ *sq = q++;
+ }
+ qcount = (sq - squeries) + 1;
+ qsort(squeries, qcount, sizeof(struct query *), qcmp);
}
- sq = squeries2;
+ sq = squeries;
qnp = qnames;
- for (i = count; --i >= 0; sq++)
+ for (i = qcount; --i >= 0; sq++)
{
sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
(*action)(1, &qnp, actarg);
(*action)(1, &qnp, actarg);
}
-void help_query(struct query *q, int (*action)(), char *actarg)
+void help_query(struct query *q, int (*action)(int, char *[], void *),
+ void *actarg)
{
int argcount;
int i;
(*action)(argcount, argv, actarg);
}
-int qcmp(struct query **q1, struct query **q2)
+int qcmp(const void *q1, const void *q2)
{
- return strcmp((*q1)->name, (*q2)->name);
+ return strcmp((*(struct query **)q1)->name, (*(struct query **)q2)->name);
}