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