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>
21 extern struct query Queries1[], Queries2[];
22 extern int QueryCount1, QueryCount2;
24 extern struct query Queries2[];
25 extern int QueryCount2;
29 get_query_by_name(name, version)
33 register struct query *q;
37 if (version == MR_VERSION_1) {
48 if (strlen(name) == 4) {
50 if (!strcmp(q->shortname, name)) return(q);
55 if (!strcmp(q->name, name)) return(q);
60 return((struct query *)0);
63 list_queries(version, action, actarg)
68 register struct query *q;
71 static struct query **squeries1 = (struct query **)0;
73 static struct query **squeries2 = (struct query **)0;
74 register struct query **sq;
81 if (version == MR_VERSION_1) {
83 if (squeries1 == (struct query **)0) {
84 sq = (struct query **)malloc(count * sizeof (struct query *));
87 for (i = count; --i >= 0; )
89 qsort(squeries1, count, sizeof (struct query *), qcmp);
95 if (squeries2 == (struct query **)0) {
96 sq = (struct query **)malloc(count * sizeof (struct query *));
99 for (i = count; --i >= 0; )
101 qsort(squeries2, count, sizeof (struct query *), qcmp);
104 #ifdef MULTIPROTOCOLS
109 for (i = count; --i >= 0; sq++) {
110 sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
111 (*action)(1, &qnp, actarg);
113 strcpy(qnames, "_help");
114 (*action)(1, &qnp, actarg);
115 strcpy(qnames, "_list_queries");
116 (*action)(1, &qnp, actarg);
117 strcpy(qnames, "_list_users");
118 (*action)(1, &qnp, actarg);
121 help_query(q, action, actarg)
122 register struct query *q;
126 register int argcount;
134 if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt;
138 sprintf(qname, " %s, %s ()", q->name, q->shortname);
144 sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]);
150 sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname,
151 q->fields[0], q->fields[1]);
157 sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]);
160 for (i = 1; i < argcount; i++) argv[i] = q->fields[i];
161 sprintf(argn, "%s)", q->fields[argcount]);
162 argv[argcount++] = argn;
165 if (q->type == RETRIEVE) {
166 sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
167 argv[argcount++] = argr;
169 for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
170 argv[argcount++] = q->fields[i];
172 (*action)(argcount, argv, actarg);
179 return(strcmp((*q1)->name, (*q2)->name));