]> andersk Git - moira.git/blobdiff - lib/mr_ops.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / mr_ops.c
index 4a67b302a303a38570d236b049380101271a9e74..50d2194cda2c85b49189e083cd670718a95a5086 100644 (file)
@@ -1,46 +1,40 @@
-/*
- *     $Source$
- *     $Author$
- *     $Header$
+/* $Id$
  *
- *     Copyright (C) 1987, 1989, 1990 by the Massachusetts Institute of
- *     Technology
- *     For copying and distribution information, please see the file
- *     <mit-copyright.h>.
+ * This routine is part of the client library.  It handles
+ * the protocol operations: invoking an update and getting the
+ * Moira message of the day.
  *
- *     This routine is part of the client library.  It handles
- *     the protocol operations: invoking an update and getting the
- *     MR message of the day.
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-#ifndef lint
-static char *rcsid_sms_do_update_c = "$Header$";
-#endif
-
 #include <mit-copyright.h>
-#include <string.h>
+#include <moira.h>
 #include "mr_private.h"
 
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+RCSID("$Header$");
 
 /* Invoke a DCM update. */
 
 int mr_do_update(void)
 {
   int status;
-  mr_params param_st;
-  struct mr_params *params = NULL;
-  struct mr_params *reply = NULL;
+  mr_params params, reply;
 
   CHECK_CONNECTED;
-  params = &param_st;
-  params->mr_version_no = sending_version_no;
-  params->mr_procno = MR_DO_UPDATE;
-  params->mr_argc = 0;
-  params->mr_argl = NULL;
-  params->mr_argv = NULL;
+  params.u.mr_procno = MR_DO_UPDATE;
+  params.mr_argc = 0;
+  params.mr_argl = NULL;
+  params.mr_argv = NULL;
 
-  if ((status = mr_do_call(params, &reply)) == 0)
-    status = reply->mr_status;
+  if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
+    status = reply.u.mr_status;
 
   mr_destroy_reply(reply);
 
@@ -48,114 +42,80 @@ int mr_do_update(void)
 }
 
 
-/* Get the MR motd.  This returns an MR status, and motd will either
+/* Get the Moira motd.  This returns a Moira status, and motd will either
  * point to NULL or the motd in a static buffer.
  */
 
 int mr_motd(char **motd)
 {
   int status;
-  mr_params param_st;
-  struct mr_params *params = NULL;
-  struct mr_params *reply = NULL;
-  static char buffer[1024];
+  mr_params params, reply;
+  static char *buffer = NULL;
 
   *motd = NULL;
   CHECK_CONNECTED;
-  params = &param_st;
-  params->mr_version_no = sending_version_no;
-  params->mr_procno = MR_MOTD;
-  params->mr_argc = 0;
-  params->mr_argl = NULL;
-  params->mr_argv = NULL;
-
-  if ((status = mr_do_call(params, &reply)))
+  params.u.mr_procno = MR_MOTD;
+  params.mr_argc = 0;
+  params.mr_argl = NULL;
+  params.mr_argv = NULL;
+
+  if ((status = mr_do_call(&params, &reply)))
     goto punt;
 
-  while ((status = reply->mr_status) == MR_MORE_DATA)
+  while ((status = reply.u.mr_status) == MR_MORE_DATA)
     {
-      if (reply->mr_argc > 0)
+      if (reply.mr_argc > 0)
        {
-         strncpy(buffer, reply->mr_argv[0], sizeof(buffer));
+         buffer = realloc(buffer, reply.mr_argl[0] + 1);
+         if (!buffer)
+           {
+             mr_disconnect();
+             return ENOMEM;
+           }
+         strcpy(buffer, reply.mr_argv[0]);
          *motd = buffer;
        }
       mr_destroy_reply(reply);
-      reply = NULL;
-
-      initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL);
-      queue_operation(_mr_conn, CON_INPUT, _mr_recv_op);
-
-      mr_complete_operation(_mr_recv_op);
-      if (OP_STATUS(_mr_recv_op) != OP_COMPLETE)
+      if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
        {
          mr_disconnect();
-         status = MR_ABORTED;
-         return status;
+         return MR_ABORTED;
        }
     }
 punt:
   mr_destroy_reply(reply);
-  /* for backwards compatability */
-  if (status == MR_UNKNOWN_PROC)
-    return 0;
-  else
-    return status;
-}
-
-
-/* Tell the library to take care of another input source while it is
- * processing a query.  For instance, an X toolkit application would
- * do something like
- *    mr_set_alternate_input(ConnectionNumber(XtDisplay(widget)), doxinput);
- * where doxinput is defined as:
- *    doxinput() {
- *     extern Widget toplevel;
- *     XEvent event;
- *     while (XPending(XtDisplay(toplevel))) {
- *         XNextEvent(XtDisplay(toplevel), &event);
- *         XtDispatchEvent(&event);
- *      }
- *      XFlush(XtDisplay(toplevel));
- *    }
- */
-
-static int mr_alternate_input = 0;
-static int (*mr_alternate_handler)();
 
-int mr_set_alternate_input(int fd, int (*proc)())
-{
-  if (mr_alternate_input != 0)
-    return MR_ALREADY_CONNECTED;
-  mr_alternate_input = fd;
-  mr_alternate_handler = proc;
-  return MR_SUCCESS;
+  return status;
 }
 
+/* Exchange query version info with the server. */
 
-/* This is used by the parts of the library that must wait for GDB.  It
- * handles alternate input streams (such as X) as well.
- */
-
-int mr_complete_operation(OPERATION op)
+int mr_version(int version)
 {
-  long infd, outfd, exfd;
-  int rc;
+  int status;
+  mr_params params, reply;
+  char vbuf[10], *arg;
 
-  gdb_progress();              /* try for an immediate completion */
+  CHECK_CONNECTED;
 
-  if (mr_alternate_input == 0)
-    return complete_operation(op);
+  sprintf(vbuf, "%d", version);
+  arg = strdup(vbuf);
+  params.u.mr_procno = MR_SETVERSION;
+  params.mr_argc = 1;
+  params.mr_argl = NULL;
+  params.mr_argv = &arg;
 
-  infd = 1 << mr_alternate_input;
-  outfd = exfd = 0;
+  status = mr_do_call(&params, &reply);
+  free(arg);
 
-  while (op->status != OP_COMPLETE && op->status != OP_CANCELLED)
+  if (status == MR_SUCCESS)
     {
-      rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd,
-                     (fd_set *)&exfd, NULL);
-      if (rc > 0 && mr_alternate_handler)
-       (*mr_alternate_handler)();
+      status = reply.u.mr_status;
+
+      if (status == MR_VERSION_LOW && getenv("MOIRA_LOW_VERSION_WARNING"))
+       fprintf(stderr, "Warning: This client is out of date.\n");
     }
-  return op->status;
-}
+  mr_destroy_reply(reply);
 
+  return status;
+}
This page took 0.074776 seconds and 4 git commands to generate.