chiark / gitweb /
Regression test scripts set EF_DISABLE_BANNER (for Electric Fence).
[adns.git] / regress / hplayback.c.m4
index 5f8b45627d51e104ae44993d9e8b9d954cbbd447..908886957f7fea3285b64811b1bd753bce12cc3d 100644 (file)
@@ -2,7 +2,12 @@ m4_dnl hplayback.c.m4
 m4_dnl (part of complex test harness, not of the library)
 m4_dnl - playback routines
 
-m4_dnl  This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
+m4_dnl  This file is
+m4_dnl    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+m4_dnl
+m4_dnl  It is part of adns, which is
+m4_dnl    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+m4_dnl    Copyright (C) 1999 Tony Finch <dot@dotat.at>
 m4_dnl  
 m4_dnl  This program is free software; you can redistribute it and/or modify
 m4_dnl  it under the terms of the GNU General Public License as published by
@@ -89,6 +94,20 @@ static void Parg(const char *argname) {
   if (vb2.buf[vb2.used++] != hm_squote=hm_squote) Psyntax("not = after argument name");
 }
 
+static int Pstring_maybe(const char *string) {
+  int l;
+
+  l= strlen(string);
+  if (memcmp(vb2.buf+vb2.used,string,l)) return 0;
+  vb2.used+= l;
+  return 1;
+}
+
+static void Pstring(const char *string, const char *emsg) {
+  if (Pstring_maybe(string)) return;
+  Psyntax(emsg);
+}
+
 static int Perrno(const char *stuff) {
   const struct Terrno *te;
   int r;
@@ -96,8 +115,8 @@ static int Perrno(const char *stuff) {
 
   for (te= Terrnos; te->n && strcmp(te->n,stuff); te++);
   if (te->n) return te->v;
-  r= strtoul(stuff+1,&ep,10);
-  if (ep) Psyntax("errno value not recognised, not numeric");
+  r= strtoul(stuff+2,&ep,10);
+  if (*ep) Psyntax("errno value not recognised, not numeric");
   return r;
 }
 
@@ -136,6 +155,49 @@ static void Pfdset(fd_set *set, int max) {
   }
 }
 
+#ifdef HAVE_POLL
+static int Ppollfdevents(void) {
+  int events;
+
+  if (Pstring_maybe("0")) return 0;
+  events= 0;
+
+  if (Pstring_maybe("POLLIN")) {
+    events |= POLLIN;
+    if (!Pstring_maybe("|")) return events;
+  }
+
+  if (Pstring_maybe("POLLOUT")) {
+    events |= POLLOUT;
+    if (!Pstring_maybe("|")) return events;
+  }
+
+  Pstring("POLLPRI","pollfdevents PRI?");
+  return events;
+}
+
+static void Ppollfds(struct pollfd *fds, int nfds) {
+  int i;
+  char *ep;
+  const char *comma= "";
+  
+  if (vb2.buf[vb2.used++] != hm_squote[hm_squote) Psyntax("pollfds start not [");
+  for (i=0; i<nfds; i++) {
+    Pstring("{fd=","{fd= in pollfds");
+    fds->fd= strtoul(vb2.buf+vb2.used,&ep,10);
+    vb2.used= ep - (char*)vb2.buf;    
+    Pstring(", events=",", events= in pollfds");
+    fds->events= Ppollfdevents();
+    Pstring(", revents=",", revents= in pollfds");
+    fds->revents= Ppollfdevents();
+    Pstring("}","} in pollfds");
+    Pstring(comma,"separator in pollfds");
+    comma= ", ";
+  }
+  if (vb2.buf[vb2.used++] != hm_squote]hm_squote) Psyntax("pollfds end not ]");
+}
+#endif
+
 static void Paddr(struct sockaddr *addr, int *lenr) {
   struct sockaddr_in *sa= (struct sockaddr_in*)addr;
   char *p, *ep;
@@ -281,6 +343,7 @@ int H$1(hm_args_massage($3,void)) {
 
  hm_create_nothing
  m4_define(`hm_arg_fdset_io',`Parg("$'`1"); Pfdset($'`1,$'`2);')
+ m4_define(`hm_arg_pollfds_io',`Parg("$'`1"); Ppollfds($'`1,$'`2);')
  m4_define(`hm_arg_addr_out',`Parg("$'`1"); Paddr($'`1,$'`2);')
  $3
  if (vb2.used != vb2.avail) Psyntax("junk at end of line");