]> andersk Git - moira.git/blob - server/qsubs.c
Diane Delgado's changes for a fixed table-locking order
[moira.git] / server / qsubs.c
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 "query.h"
19
20 #ifdef MULTIPROTOCOLS
21 extern struct query Queries1[], Queries2[];
22 extern int QueryCount1, QueryCount2;
23 #else
24 extern struct query Queries2[];
25 extern int QueryCount2;
26 #endif MULTIPROTOCOLS
27
28 struct query *
29 get_query_by_name(name, version)
30     register char *name;
31     int version;
32 {
33     register struct query *q;
34     register int i;
35
36 #ifdef MULTIPROTOCOLS
37     if (version == MR_VERSION_1) {
38         q = Queries1;
39         i = QueryCount1;
40     } else {
41 #endif
42         q = Queries2;
43         i = QueryCount2;
44 #ifdef MULTIPROTOCOLS
45     }   
46 #endif
47
48     if (strlen(name) == 4) {
49         while (--i >= 0) {
50             if (!strcmp(q->shortname, name)) return(q);
51             q++;
52         }
53     } else {
54         while (--i >= 0) {
55             if (!strcmp(q->name, name)) return(q);
56             q++;
57         }
58     }
59
60     return((struct query *)0);
61 }
62
63 list_queries(version, action, actarg)
64     int version;
65     int (*action)();
66     int actarg;
67 {
68   register struct query *q;
69   register int i;
70 #ifdef MULTIPROTOCOLS
71   static struct query **squeries1 = (struct query **)0;
72 #endif
73   static struct query **squeries2 = (struct query **)0;
74   register struct query **sq;
75   char qnames[80];
76   char *qnp;
77   int count;
78   int qcmp();
79
80 #ifdef MULTIPROTOCOLS
81   if (version == MR_VERSION_1) {
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 {
93 #endif
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;
104 #ifdef MULTIPROTOCOLS
105   }
106 #endif
107
108   qnp = qnames;
109   for (i = count; --i >= 0; sq++) {
110       sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
111       (*action)(1, &qnp, actarg);
112   }
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);
119 }
120
121 help_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];
129     char qname[512];
130     char argr[512];
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:
138         sprintf(qname, "   %s, %s ()", q->name, q->shortname);
139         argv[0] = qname;
140         argcount = 1;
141         break;
142
143     case 1:
144         sprintf(qname, "   %s, %s (%s)", q->name, q->shortname, q->fields[0]);
145         argv[0] = qname;
146         argcount = 1;
147         break;
148
149     case 2:
150         sprintf(qname, "   %s, %s (%s, %s)", q->name, q->shortname,
151                 q->fields[0], q->fields[1]);
152         argv[0] = qname;
153         argcount = 1;
154         break;
155
156     default:
157         sprintf(qname, "   %s, %s (%s", q->name, q->shortname, q->fields[0]);
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]);
162         argv[argcount++] = argn;
163         break;
164     }
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);
173 }
174
175 qcmp(q1, q2)
176     struct query **q1;
177     struct query **q2;
178 {
179   return(strcmp((*q1)->name, (*q2)->name));
180 }
This page took 0.152605 seconds and 5 git commands to generate.