]> andersk Git - moira.git/blobdiff - lib/mr_query.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / mr_query.c
index 8adee778bc490c51d5f1c8aec01e7ebe76f4a5c7..798fbfb8824f898c0cc9a5bfbdcee092f76577a3 100644 (file)
-/*
- *     $Source$
- *     $Author$
- *     $Header$
+/* $Id$
  *
- *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ * Perform a Moira query
  *
- *     $Log$
- *     Revision 1.4  1987-08-22 17:11:16  wesommer
- *     Increment the nesting level only after we know we're connected.
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  *
- * Revision 1.3  87/08/02  21:49:53  wesommer
- * Prevent recursive query call.
- * 
- * Revision 1.2  87/06/16  17:48:58  wesommer
- * Clean up memory allocation, indenting.
- * 
- * Revision 1.1  87/06/04  01:29:32  wesommer
- * Initial revision
- * 
  */
 
-#ifndef lint
-static char *rcsid_sms_query_c = "$Header$";
-#endif lint
+#include <mit-copyright.h>
+#include <moira.h>
+#include "mr_private.h"
 
-#include "sms_private.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
 
-/*
- * This routine is the primary external interface to the sms library.
- *
- * It builds a new argument vector with the query handle prepended,
- * and calls sms_query_internal.
- */
-int level = 0;
+RCSID("$Header$");
 
-int sms_query(name, argc, argv, callproc, callarg)
-    char *name;                /* Query name */
-    int argc;          /* Arg count */
-    char **argv;               /* Args */
-    int (*callproc)(); /* Callback procedure */
-    char *callarg;             /* Callback argument */
-{
-    register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
-    register int status = 0;
-    nargv[0] = name;
-    bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
-    status = sms_query_internal(argc+1, nargv, callproc, callarg);
-    free(nargv);
-    return status;
-}
 /*
- * This routine makes an SMS query.
+ * This routine is the primary external interface to the mr library.
  *
- * argv[0] is the query name.
- * argv[1..argc-1] are the query arguments.
- *
- * callproc is called once for each returned value, with arguments
- * argc, argv, and callarg.
- * If it returns a non-zero value, further calls to it are not done, and
- * all future data from the server is ignored (there should be some
- * way to send it a quench..)
+ * It builds a new argument vector with the query handle prepended,
+ * and calls mr_query_internal.
  */
+static int level = 0;
 
-int sms_query_internal(argc, argv, callproc, callarg)
-    int argc;          /* Arg count */
-    char **argv;               /* Args */
-    int (*callproc)(); /* Callback procedure */
-    char *callarg;             /* Callback argument */
+int mr_query(char *name, int argc, char **argv,
+            int (*callproc)(int, char **, void *), void *callarg)
 {
-    int status;
-    sms_params params_st;
-    register sms_params *params = NULL;
-    sms_params *reply = NULL;
-    int stopcallbacks = 0;
+  int status, stopcallbacks = 0;
+  mr_params params, reply;
 
-    if (level) return SMS_QUERY_NOT_REENTRANT;
-    
-    CHECK_CONNECTED;
-    level++;
+  CHECK_CONNECTED;
+  if (level)
+    return MR_QUERY_NOT_REENTRANT;
 
-    params = &params_st;
-    params->sms_procno = SMS_QUERY;
-    params->sms_argc = argc;
-    params->sms_argl = NULL;
-    params->sms_argv = argv;
-       
-    if ((status = sms_do_call(params, &reply)))
-       goto punt;
+  params.u.mr_procno = MR_QUERY;
+  params.mr_argc = argc + 1;
+  params.mr_argl = NULL;
+  params.mr_argv = malloc(sizeof(char *) * (argc + 1));
+  if (!params.mr_argv)
+    return ENOMEM;
+  params.mr_argv[0] = name;
+  memcpy(params.mr_argv + 1, argv, sizeof(char *) * argc);
 
-    while ((status = reply->sms_status) == SMS_MORE_DATA) {
-       if (!stopcallbacks) 
-           stopcallbacks =
-               (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
-       sms_destroy_reply(reply);
-       reply = NULL;
+  level++;
+  if ((status = mr_do_call(&params, &reply)))
+    goto punt;
 
-       initialize_operation(_sms_recv_op, sms_start_recv, &reply,
-                            (int (*)())NULL);
-       queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
+  while ((status = reply.u.mr_status) == MR_MORE_DATA)
+    {
+      if (callproc && !stopcallbacks)
+       stopcallbacks = (*callproc)(reply.mr_argc, reply.mr_argv, callarg);
+      mr_destroy_reply(reply);
 
-       complete_operation(_sms_recv_op);
-       if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
-           sms_disconnect();
-           status = SMS_ABORTED;
-           goto punt_1;
+      if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
+       {
+         mr_disconnect();
+         status = MR_ABORTED;
+         goto punt_1;
        }
-    }  
+    }
+
 punt:
-    sms_destroy_reply(reply);
+  mr_destroy_reply(reply);
 punt_1:
-    level--;
-    return status;
+  level--;
+  free(params.mr_argv);
+
+  return status;
 }
-/*
- * 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:
- */
This page took 0.232049 seconds and 4 git commands to generate.