3 * Perform a Moira query
5 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include "mr_private.h"
22 * This routine is the primary external interface to the mr library.
24 * It builds a new argument vector with the query handle prepended,
25 * and calls mr_query_internal.
29 int mr_query(char *name, int argc, char **argv,
30 int (*callproc)(int, char **, void *), void *callarg)
32 int status, stopcallbacks = 0;
33 mr_params params, reply;
37 return MR_QUERY_NOT_REENTRANT;
39 params.u.mr_procno = MR_QUERY;
40 params.mr_argc = argc + 1;
41 params.mr_argl = NULL;
42 params.mr_argv = malloc(sizeof(char *) * (argc + 1));
45 params.mr_argv[0] = name;
46 memcpy(params.mr_argv + 1, argv, sizeof(char *) * argc);
49 if ((status = mr_do_call(¶ms, &reply)))
52 while ((status = reply.u.mr_status) == MR_MORE_DATA)
54 if (callproc && !stopcallbacks)
55 stopcallbacks = (*callproc)(reply.mr_argc, reply.mr_argv, callarg);
56 mr_destroy_reply(reply);
58 if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
67 mr_destroy_reply(reply);