summaryrefslogtreecommitdiff
path: root/lib/ZPeekIfNot.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-06-12 12:58:47 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-06-12 12:58:47 +0000
commit2a79930d731c6d85df0fc46e869a4466dbf1d1fd (patch)
tree69baaff8f1bc1fb934473a1fe7b31946f3ceb3b6 /lib/ZPeekIfNot.c
parent2a5fbec60dbc9c1a08e104760f64bbdc33c8a1fa (diff)
First working library - safe checkin
Diffstat (limited to 'lib/ZPeekIfNot.c')
-rw-r--r--lib/ZPeekIfNot.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/ZPeekIfNot.c b/lib/ZPeekIfNot.c
new file mode 100644
index 0000000..f52cdd6
--- /dev/null
+++ b/lib/ZPeekIfNot.c
@@ -0,0 +1,66 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZPeekIfNotice function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZPeekIfNotice(buffer,buffer_len,notice,auth,predicate,args)
+ ZPacket_t buffer;
+ int buffer_len;
+ ZNotice_t *notice;
+ int *auth;
+ int (*predicate)();
+ char *args;
+{
+ ZNotice_t tmpnotice;
+ int qcount,retval,tmpauth;
+ struct _Z_InputQ *qptr;
+
+ if (__Q_Length)
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
+
+ if (retval != ZERR_NONE)
+ return (retval);
+
+ qptr = __Q_Head;
+ qcount = __Q_Length;
+
+ for (;;qcount--) {
+ if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
+ &tmpnotice,&tmpauth)) != ZERR_NONE)
+ return (retval);
+ if ((predicate)(&tmpnotice,args)) {
+ if (qptr->packet_len > buffer_len)
+ return (ZERR_PKTLEN);
+ bcopy(qptr->packet,buffer,qptr->packet_len);
+ if ((retval = ZParseNotice(buffer,qptr->packet_len,
+ notice,auth))
+ != ZERR_NONE)
+ return (retval);
+ return (ZERR_NONE);
+ }
+ /* Grunch! */
+ if (qcount == 1) {
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ qcount++;
+ qptr = __Q_Tail;
+ }
+ else
+ qptr = qptr->next;
+ }
+}