]> andersk Git - moira.git/blob - server/qsubs.c
eliminate use of the `register' keyword: let the compiler decide
[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 "mr_server.h"
19 #include "query.h"
20
21 extern struct query Queries2[];
22 extern int QueryCount2;
23
24 struct query *get_query_by_name(char *name, int version)
25 {
26   struct query *q;
27   int i;
28
29   q = Queries2;
30   i = QueryCount2;
31
32   if (strlen(name) == 4)
33     {
34       while (--i >= 0)
35         {
36           if (!strcmp(q->shortname, name))
37             return q;
38           q++;
39         }
40     }
41   else
42     {
43       while (--i >= 0)
44         {
45           if (!strcmp(q->name, name))
46             return q;
47           q++;
48         }
49     }
50
51   return NULL;
52 }
53
54 void list_queries(int version, int (*action)(), char *actarg)
55 {
56   struct query *q;
57   int i;
58   static struct query **squeries2 = NULL;
59   struct query **sq;
60   char qnames[80];
61   char *qnp;
62   int count;
63   int qcmp();
64
65   count = QueryCount2;
66   if (!squeries2)
67     {
68       sq = malloc(count * sizeof(struct query *));
69       squeries2 = sq;
70       q = Queries2;
71       for (i = count; --i >= 0; )
72         *sq++ = q++;
73       qsort(squeries2, count, sizeof(struct query *), qcmp);
74     }
75   sq = squeries2;
76
77   qnp = qnames;
78   for (i = count; --i >= 0; sq++)
79     {
80       sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
81       (*action)(1, &qnp, actarg);
82     }
83   strcpy(qnames, "_help");
84   (*action)(1, &qnp, actarg);
85   strcpy(qnames, "_list_queries");
86   (*action)(1, &qnp, actarg);
87   strcpy(qnames, "_list_users");
88   (*action)(1, &qnp, actarg);
89 }
90
91 void help_query(struct query *q, int (*action)(), char *actarg)
92 {
93   int argcount;
94   int i;
95   char argn[32];
96   char qname[512];
97   char argr[512];
98   char *argv[32];
99
100   argcount = q->argc;
101   if (q->type == UPDATE || q->type == APPEND)
102     argcount += q->vcnt;
103
104   switch (argcount)
105     {
106     case 0:
107       sprintf(qname, "   %s, %s ()", q->name, q->shortname);
108       argv[0] = qname;
109       argcount = 1;
110       break;
111
112     case 1:
113       sprintf(qname, "   %s, %s (%s)", q->name, q->shortname, q->fields[0]);
114       argv[0] = qname;
115       argcount = 1;
116       break;
117
118     case 2:
119       sprintf(qname, "   %s, %s (%s, %s)", q->name, q->shortname,
120               q->fields[0], q->fields[1]);
121       argv[0] = qname;
122       argcount = 1;
123       break;
124
125     default:
126       sprintf(qname, "   %s, %s (%s", q->name, q->shortname, q->fields[0]);
127       argv[0] = qname;
128       argcount--;
129       for (i = 1; i < argcount; i++)
130         argv[i] = q->fields[i];
131       sprintf(argn, "%s)", q->fields[argcount]);
132       argv[argcount++] = argn;
133       break;
134     }
135
136   if (q->type == RETRIEVE)
137     {
138       sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
139       argv[argcount++] = argr;
140       if (q->vcnt > 1)
141         {
142           for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
143             argv[argcount++] = q->fields[i];
144         }
145     }
146   (*action)(argcount, argv, actarg);
147 }
148
149 int qcmp(struct query **q1, struct query **q2)
150 {
151   return strcmp((*q1)->name, (*q2)->name);
152 }
This page took 0.042911 seconds and 5 git commands to generate.