* $Header$
*
* Copyright (C) 1987 by the Massachusetts Institute of Technology
- *
- * $Log$
- * Revision 1.2 1987-06-08 03:08:15 wesommer
- * Reindented; added header.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*
*/
static char *rcsid_qsubs_c = "$Header$";
#endif lint
+#include <mit-copyright.h>
+#include <sms.h>
#include "query.h"
-extern struct query Queries[];
-extern int QueryCount;
-#ifdef notdef
-extern struct s_query S_Queries[];
-extern int S_QueryCount;
-#endif notdef
+extern struct query Queries1[], Queries2[];
+extern int QueryCount1, QueryCount2;
struct query *
-get_query_by_name(name)
+get_query_by_name(name, version)
register char *name;
+ int version;
{
register struct query *q;
register int i;
- q = Queries;
- i = QueryCount;
+ if (version == SMS_VERSION_1) {
+ q = Queries1;
+ i = QueryCount1;
+ } else {
+ q = Queries2;
+ i = QueryCount2;
+ }
if (strlen(name) == 4) {
while (--i >= 0) {
return((struct query *)0);
}
-get_input_fields(q, argc, argv)
- register struct query *q;
- int *argc;
- char ***argv;
-{
- *argv = q->fields;
- *argc = q->sargc + q->argc;
- if (q->type == UPDATE || q->type == APPEND)
- *argc += q->vcnt;
-}
-
-get_output_fields(q, argc, argv)
- register struct query *q;
- int *argc;
- char ***argv;
-{
- if (q->type == RETRIEVE) {
- *argc = q->vcnt;
- *argv = &q->fields[q->sargc + q->argc];
- } else {
- *argc = 0;
- *argv = (char **)0;
- }
-}
-
-char *
-get_field(q, argv, name)
- register struct query *q;
- char *argv[];
- char *name;
+list_queries(version, action, actarg)
+ int version;
+ int (*action)();
+ int actarg;
{
- register char **fp;
- register char *field;
- register int i;
-
- if (q->type != RETRIEVE) return((char *)0);
-
- if (*name == '*') name++;
- fp = &q->fields[q->sargc + q->argc];
- for (i = 0; i < q->vcnt; i++) {
- field = *fp++;
- if (*field == '*') field++;
- if (!strcmp(field, name)) return(argv[i]);
- }
- return((char *)0);
+ register struct query *q;
+ register int i;
+ static struct query **squeries1 = (struct query **)0;
+ static struct query **squeries2 = (struct query **)0;
+ register struct query **sq;
+ char qnames[80];
+ char *qnp;
+ int count;
+ int qcmp();
+
+ if (version == SMS_VERSION_1) {
+ count = QueryCount1;
+ if (squeries1 == (struct query **)0) {
+ sq = (struct query **)malloc(count * sizeof (struct query *));
+ squeries1 = sq;
+ q = Queries1;
+ for (i = count; --i >= 0; )
+ *sq++ = q++;
+ qsort(squeries1, count, sizeof (struct query *), qcmp);
+ }
+ sq = squeries1;
+ } else {
+ count = QueryCount2;
+ if (squeries2 == (struct query **)0) {
+ sq = (struct query **)malloc(count * sizeof (struct query *));
+ squeries2 = sq;
+ q = Queries2;
+ for (i = count; --i >= 0; )
+ *sq++ = q++;
+ qsort(squeries2, count, sizeof (struct query *), qcmp);
+ }
+ sq = squeries2;
+ }
+
+ qnp = qnames;
+ for (i = count; --i >= 0; sq++) {
+ sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
+ (*action)(1, &qnp, actarg);
+ }
+ strcpy(qnames, "_help");
+ (*action)(1, &qnp, actarg);
+ strcpy(qnames, "_list_queries");
+ (*action)(1, &qnp, actarg);
+ strcpy(qnames, "_list_users");
+ (*action)(1, &qnp, actarg);
}
-put_field(q, argv, name, value)
+help_query(q, action, actarg)
register struct query *q;
- char *argv[];
- char *name;
- char *value;
+ int (*action)();
+ int actarg;
{
- register char **fp;
- register char *field;
+ register int argcount;
register int i;
- register int n;
-
- n = q->sargc + q->argc;
- if (q->type == UPDATE || q->type == APPEND) n += q->vcnt;
-
- if (*name == '*') name++;
- fp = q->fields;
- for (i = 0; i < n; i++) {
- field = *fp++;
- if (*field == '*') field++;
- if (!strcmp(field, name)) {
- strcpy(argv[i], value);
- return(0);
- }
+ char argn[32];
+ char qname[512];
+ char argr[512];
+ char *argv[32];
+
+ argcount = q->argc;
+ if (q->type == UPDATE || q->type == APPEND) argcount += q->vcnt;
+
+ switch (argcount) {
+ case 0:
+ sprintf(qname, " %s, %s ()", q->name, q->shortname);
+ argv[0] = qname;
+ argcount = 1;
+ break;
+
+ case 1:
+ sprintf(qname, " %s, %s (%s)", q->name, q->shortname, q->fields[0]);
+ argv[0] = qname;
+ argcount = 1;
+ break;
+
+ case 2:
+ sprintf(qname, " %s, %s (%s, %s)", q->name, q->shortname,
+ q->fields[0], q->fields[1]);
+ argv[0] = qname;
+ argcount = 1;
+ break;
+
+ default:
+ sprintf(qname, " %s, %s (%s", q->name, q->shortname, q->fields[0]);
+ argv[0] = qname;
+ argcount--;
+ for (i = 1; i < argcount; i++) argv[i] = q->fields[i];
+ sprintf(argn, "%s)", q->fields[argcount]);
+ argv[argcount++] = argn;
+ break;
}
- return(-1);
-}
-
-
-/* Generic Queue Routines */
-
-struct save_queue *
-sq_create()
-{
- register struct save_queue *sq;
-
- sq = (struct save_queue *)malloc(sizeof (struct save_queue));
- sq->q_next = sq;
- sq->q_prev = sq;
- sq->q_lastget = 0;
- return(sq);
-}
-
-sq_save_data(sq, data)
- register struct save_queue *sq;
- char *data;
-{
- register struct save_queue *q;
-
- q = (struct save_queue *)malloc(sizeof (struct save_queue));
- q->q_next = sq;
- q->q_prev = sq->q_prev;
- sq->q_prev->q_next = q;
- sq->q_prev = q;
- q->q_data = data;
-}
-
-sq_get_data(sq, data)
- register struct save_queue *sq;
- register char **data;
-{
- if (sq->q_lastget == (struct save_queue *)0) {
- sq->q_lastget = sq->q_next;
- } else {
- sq->q_lastget = sq->q_lastget->q_next;
+ if (q->type == RETRIEVE) {
+ sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
+ argv[argcount++] = argr;
+ if (q->vcnt > 1)
+ for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
+ argv[argcount++] = q->fields[i];
}
-
- if (sq->q_lastget == sq) return(0);
- *data = sq->q_lastget->q_data;
- return(1);
+ (*action)(argcount, argv, actarg);
}
-sq_destroy(sq)
- register struct save_queue *sq;
+qcmp(q1, q2)
+ struct query **q1;
+ struct query **q2;
{
- register struct save_queue *q;
-
- for (q = sq->q_next; q != sq; q = sq->q_next) {
- sq->q_next = q->q_next;
- free(q);
- }
- free(sq);
+ return(strcmp((*q1)->name, (*q2)->name));
}
-
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */