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