]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * For copying and distribution information, please see the file | |
8 | * <mit-copyright.h>. | |
9 | * | |
10 | */ | |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_qsubs_c = "$Header$"; | |
14 | #endif lint | |
15 | ||
16 | #include <mit-copyright.h> | |
17 | #include <moira.h> | |
18 | #include "mr_server.h" | |
19 | #include "query.h" | |
20 | ||
21 | #ifdef MULTIPROTOCOLS | |
22 | extern struct query Queries1[], Queries2[]; | |
23 | extern int QueryCount1, QueryCount2; | |
24 | #else | |
25 | extern struct query Queries2[]; | |
26 | extern int QueryCount2; | |
27 | #endif MULTIPROTOCOLS | |
28 | ||
29 | struct query * | |
30 | get_query_by_name(name, version) | |
31 | register char *name; | |
32 | int version; | |
33 | { | |
34 | register struct query *q; | |
35 | register int i; | |
36 | ||
37 | #ifdef MULTIPROTOCOLS | |
38 | if (version == MR_VERSION_1) { | |
39 | q = Queries1; | |
40 | i = QueryCount1; | |
41 | } else { | |
42 | #endif | |
43 | q = Queries2; | |
44 | i = QueryCount2; | |
45 | #ifdef MULTIPROTOCOLS | |
46 | } | |
47 | #endif | |
48 | ||
49 | if (strlen(name) == 4) { | |
50 | while (--i >= 0) { | |
51 | if (!strcmp(q->shortname, name)) return(q); | |
52 | q++; | |
53 | } | |
54 | } else { | |
55 | while (--i >= 0) { | |
56 | if (!strcmp(q->name, name)) return(q); | |
57 | q++; | |
58 | } | |
59 | } | |
60 | ||
61 | return((struct query *)0); | |
62 | } | |
63 | ||
64 | void list_queries(version, action, actarg) | |
65 | int version; | |
66 | int (*action)(); | |
67 | char *actarg; | |
68 | { | |
69 | register struct query *q; | |
70 | register int i; | |
71 | #ifdef MULTIPROTOCOLS | |
72 | static struct query **squeries1 = (struct query **)0; | |
73 | #endif | |
74 | static struct query **squeries2 = (struct query **)0; | |
75 | register struct query **sq; | |
76 | char qnames[80]; | |
77 | char *qnp; | |
78 | int count; | |
79 | int qcmp(); | |
80 | ||
81 | #ifdef MULTIPROTOCOLS | |
82 | if (version == MR_VERSION_1) { | |
83 | count = QueryCount1; | |
84 | if (squeries1 == (struct query **)0) { | |
85 | sq = (struct query **)malloc(count * sizeof (struct query *)); | |
86 | squeries1 = sq; | |
87 | q = Queries1; | |
88 | for (i = count; --i >= 0; ) | |
89 | *sq++ = q++; | |
90 | qsort(squeries1, count, sizeof (struct query *), qcmp); | |
91 | } | |
92 | sq = squeries1; | |
93 | } else { | |
94 | #endif | |
95 | count = QueryCount2; | |
96 | if (squeries2 == (struct query **)0) { | |
97 | sq = (struct query **)malloc(count * sizeof (struct query *)); | |
98 | squeries2 = sq; | |
99 | q = Queries2; | |
100 | for (i = count; --i >= 0; ) | |
101 | *sq++ = q++; | |
102 | qsort(squeries2, count, sizeof (struct query *), qcmp); | |
103 | } | |
104 | sq = squeries2; | |
105 | #ifdef MULTIPROTOCOLS | |
106 | } | |
107 | #endif | |
108 | ||
109 | qnp = qnames; | |
110 | for (i = count; --i >= 0; sq++) { | |
111 | sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname); | |
112 | (*action)(1, &qnp, actarg); | |
113 | } | |
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); | |
120 | } | |
121 | ||
122 | void help_query(q, action, actarg) | |
123 | register struct query *q; | |
124 | int (*action)(); | |
125 | char *actarg; | |
126 | { | |
127 | register int argcount; | |
128 | register int i; | |
129 | char argn[32]; | |
130 | char qname[512]; | |
131 | char argr[512]; | |
132 | char *argv[32]; | |
133 | ||
134 | argcount = q->argc; | |
135 | if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt; | |
136 | ||
137 | switch (argcount) { | |
138 | case 0: | |
139 | sprintf(qname, " %s, %s ()", q->name, q->shortname); | |
140 | argv[0] = qname; | |
141 | argcount = 1; | |
142 | break; | |
143 | ||
144 | case 1: | |
145 | sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]); | |
146 | argv[0] = qname; | |
147 | argcount = 1; | |
148 | break; | |
149 | ||
150 | case 2: | |
151 | sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname, | |
152 | q->fields[0], q->fields[1]); | |
153 | argv[0] = qname; | |
154 | argcount = 1; | |
155 | break; | |
156 | ||
157 | default: | |
158 | sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]); | |
159 | argv[0] = qname; | |
160 | argcount--; | |
161 | for (i = 1; i < argcount; i++) argv[i] = q->fields[i]; | |
162 | sprintf(argn, "%s)", q->fields[argcount]); | |
163 | argv[argcount++] = argn; | |
164 | break; | |
165 | } | |
166 | if (q->type == RETRIEVE) { | |
167 | sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]); | |
168 | argv[argcount++] = argr; | |
169 | if (q->vcnt > 1) | |
170 | for (i = q->argc + 1; i < q->vcnt + q->argc; i++) | |
171 | argv[argcount++] = q->fields[i]; | |
172 | } | |
173 | (*action)(argcount, argv, actarg); | |
174 | } | |
175 | ||
176 | qcmp(q1, q2) | |
177 | struct query **q1; | |
178 | struct query **q2; | |
179 | { | |
180 | return(strcmp((*q1)->name, (*q2)->name)); | |
181 | } |