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>
20 extern struct query Queries1[], Queries2[];
21 extern int QueryCount1, QueryCount2;
24 get_query_by_name(name, version)
28 register struct query *q;
31 if (version == SMS_VERSION_1) {
39 if (strlen(name) == 4) {
41 if (!strcmp(q->shortname, name)) return(q);
46 if (!strcmp(q->name, name)) return(q);
51 return((struct query *)0);
54 list_queries(version, action, actarg)
59 register struct query *q;
61 static struct query **squeries1 = (struct query **)0;
62 static struct query **squeries2 = (struct query **)0;
63 register struct query **sq;
69 if (version == SMS_VERSION_1) {
71 if (squeries1 == (struct query **)0) {
72 sq = (struct query **)malloc(count * sizeof (struct query *));
75 for (i = count; --i >= 0; )
77 qsort(squeries1, count, sizeof (struct query *), qcmp);
82 if (squeries2 == (struct query **)0) {
83 sq = (struct query **)malloc(count * sizeof (struct query *));
86 for (i = count; --i >= 0; )
88 qsort(squeries2, count, sizeof (struct query *), qcmp);
94 for (i = count; --i >= 0; sq++) {
95 sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
96 (*action)(1, &qnp, actarg);
98 strcpy(qnames, "_help");
99 (*action)(1, &qnp, actarg);
100 strcpy(qnames, "_list_queries");
101 (*action)(1, &qnp, actarg);
102 strcpy(qnames, "_list_users");
103 (*action)(1, &qnp, actarg);
106 help_query(q, action, actarg)
107 register struct query *q;
111 register int argcount;
119 if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt;
123 sprintf(qname, " %s, %s ()", q->name, q->shortname);
129 sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]);
135 sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname,
136 q->fields[0], q->fields[1]);
142 sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]);
145 for (i = 1; i < argcount; i++) argv[i] = q->fields[i];
146 sprintf(argn, "%s)", q->fields[argcount]);
147 argv[argcount++] = argn;
150 if (q->type == RETRIEVE) {
151 sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
152 argv[argcount++] = argr;
154 for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
155 argv[argcount++] = q->fields[i];
157 (*action)(argcount, argv, actarg);
164 return(strcmp((*q1)->name, (*q2)->name));