6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_qsubs_c = "$Header$";
16 #include <mit-copyright.h>
18 #include "mr_server.h"
22 extern struct query Queries1[], Queries2[];
23 extern int QueryCount1, QueryCount2;
25 extern struct query Queries2[];
26 extern int QueryCount2;
30 get_query_by_name(name, version)
34 register struct query *q;
38 if (version == MR_VERSION_1) {
49 if (strlen(name) == 4) {
51 if (!strcmp(q->shortname, name)) return(q);
56 if (!strcmp(q->name, name)) return(q);
61 return((struct query *)0);
64 void list_queries(version, action, actarg)
69 register struct query *q;
72 static struct query **squeries1 = (struct query **)0;
74 static struct query **squeries2 = (struct query **)0;
75 register struct query **sq;
82 if (version == MR_VERSION_1) {
84 if (squeries1 == (struct query **)0) {
85 sq = (struct query **)malloc(count * sizeof (struct query *));
88 for (i = count; --i >= 0; )
90 qsort(squeries1, count, sizeof (struct query *), qcmp);
96 if (squeries2 == (struct query **)0) {
97 sq = (struct query **)malloc(count * sizeof (struct query *));
100 for (i = count; --i >= 0; )
102 qsort(squeries2, count, sizeof (struct query *), qcmp);
105 #ifdef MULTIPROTOCOLS
110 for (i = count; --i >= 0; sq++) {
111 sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
112 (*action)(1, &qnp, actarg);
114 strcpy(qnames, "_help");
115 (*action)(1, &qnp, actarg);
116 strcpy(qnames, "_list_queries");
117 (*action)(1, &qnp, actarg);
118 strcpy(qnames, "_list_users");
119 (*action)(1, &qnp, actarg);
122 void help_query(q, action, actarg)
123 register struct query *q;
127 register int argcount;
135 if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt;
139 sprintf(qname, " %s, %s ()", q->name, q->shortname);
145 sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]);
151 sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname,
152 q->fields[0], q->fields[1]);
158 sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]);
161 for (i = 1; i < argcount; i++) argv[i] = q->fields[i];
162 sprintf(argn, "%s)", q->fields[argcount]);
163 argv[argcount++] = argn;
166 if (q->type == RETRIEVE) {
167 sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
168 argv[argcount++] = argr;
170 for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
171 argv[argcount++] = q->fields[i];
173 (*action)(argcount, argv, actarg);
180 return(strcmp((*q1)->name, (*q2)->name));