chiark / gitweb /
Notice and explicitly fail of display is <24bpp
[ypp-sc-tools.web-live.git] / pctb / pages.c
1 /*
2  * Interaction with the YPP client via X11
3  */
4 /*
5  *  This is part of ypp-sc-tools, a set of third-party tools for assisting
6  *  players of Yohoho Puzzle Pirates.
7  * 
8  *  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9  * 
10  *  This program is free software: you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation, either version 3 of the License, or
13  *  (at your option) any later version.
14  * 
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  * 
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  * 
23  *  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24  *  are used without permission.  This program is not endorsed or
25  *  sponsored by Three Rings.
26  */
27
28 /*
29  * Only this file #includes the X11 headers, as they're quite
30  * pollutant of the namespace.
31  */
32
33 #include "structure.h"
34
35 #include <X11/Xlib.h>
36 #include <X11/extensions/XTest.h>
37 #include <X11/keysym.h>
38 #include <X11/Xutil.h>
39
40 #include <X11/extensions/XShm.h>
41 #include <sys/ipc.h>
42 #include <sys/shm.h>
43
44 CanonImage *page_images[MAX_PAGES];
45 int npages;
46
47 const char *ocean, *pirate;
48
49 static XWindowAttributes attr;
50 static Window id;
51 static Display *disp;
52 static struct timeval tv_startup;
53 static unsigned wwidth, wheight;
54 static int max_relevant_y= -1;
55
56 static XImage *shmim;
57 static XShmSegmentInfo shminfo;
58
59 DEBUG_DEFINE_DEBUGF(pages)
60
61 #define xassert(what)                                   \
62   ((what) ? (void)0 :                                   \
63    fatal("X11 operation unexpectedly failed."           \
64          " %s:%d: %s\n", __FILE__,__LINE__,#what))
65
66 static KeyCode keycode(KeySym sym) {
67   return XKeysymToKeycode(disp,sym);
68 }
69
70 void screenshot_startup(void) {
71   progress("starting...");
72   disp= XOpenDisplay(0);
73   if (!disp) fatal("Unable to open X11 display.");
74   sysassert(! gettimeofday(&tv_startup,0) );
75 }
76
77 /*---------- pager ----------*/
78
79 typedef RgbImage Snapshot;
80
81 static double last_input;
82 static const double min_update_allowance= 0.25;
83
84 static double timestamp(void) {
85   struct timeval tv;
86   
87   sysassert(! gettimeofday(&tv,0) );
88   double t= (tv.tv_sec - tv_startup.tv_sec) +
89             (tv.tv_usec - tv_startup.tv_usec) * 1e-6;
90   debugf("PAGING %f\n",t);
91   return t;
92 }
93 static void delay(double need_sleep) {
94   debugf("PAGING     delay %f\n",need_sleep);
95   sysassert(! usleep(need_sleep * 1e6) );
96 }
97
98 static void sync_after_input(void) {
99   xassert( XSync(disp, False) );
100   last_input= timestamp();
101 }
102
103 static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
104   Window dummy;
105   xassert( XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy) );
106 }
107
108 static void check_client_window_all_on_screen(void) {
109   Rect onroot;
110   unsigned rwidth, rheight;
111   Window dummy;
112   unsigned bd, depth;
113   int rxpos, rypos;
114
115   xassert( XGetGeometry(disp,attr.root, &dummy, &rxpos,&rypos,
116                         &rwidth, &rheight,
117                         &bd,&depth) );
118   
119   translate_coords_toroot(0,0, &onroot.tl.x,&onroot.tl.y);
120   translate_coords_toroot(wwidth-1,wheight-1, &onroot.br.x,&onroot.br.y);
121   if (!(onroot.tl.x >= 0 &&
122         onroot.tl.y >= 0 &&
123         onroot.br.x < rwidth &&
124         onroot.br.y < rheight))
125     fatal("YPP client window is not entirely on the screen.");
126 }
127
128 static void check_not_disturbed(void) {
129   XEvent ev;
130   int r;
131   
132   for (;;) {
133     r= XCheckMaskEvent(disp, ~0, &ev);
134     if (r==False) return;
135
136     switch (ev.type) {
137     case VisibilityNotify:
138       if (ev.xvisibility.state != VisibilityUnobscured)
139         fatal("YPP client window has become obscured.");
140       break;
141     case ConfigureNotify:
142       check_client_window_all_on_screen();
143       break;
144     case FocusOut:
145       fatal("Focus left YPP client window.");
146       break;
147     case FocusIn:
148       warning("focus entered YPP client window ?!");
149       break;
150     default:
151       fatal("Received unexpected X11 event (type code %d)!", ev.type);
152     }
153   }
154 }      
155
156 static void send_key(KeySym sym) {
157   check_not_disturbed();
158   XTestFakeKeyEvent(disp, keycode(sym),1, 10);
159   XTestFakeKeyEvent(disp, keycode(sym),0, 10);
160 }
161 static void mouse_1_updown_here(void) {
162   check_not_disturbed();
163   XTestFakeButtonEvent(disp,1,1, 50);
164   XTestFakeButtonEvent(disp,1,0, 50);
165 }
166 static void mouse_1_updown(int x, int y) {
167   check_not_disturbed();
168   int screen= XScreenNumberOfScreen(attr.screen);
169   int xpos, ypos;
170   translate_coords_toroot(x,y, &xpos,&ypos);
171   XTestFakeMotionEvent(disp, screen, xpos,ypos, 0);
172   mouse_1_updown_here();
173 }
174
175 static int pgupdown;
176
177 static void send_pgup_many(void) {
178   int i;
179   for (i=0; i<25; i++) {
180     send_key(XK_Prior);
181     pgupdown--;
182   }
183   debugf("PAGING   PageUp x %d\n",i);
184   sync_after_input();
185 }
186 static void send_pgdown(void) {
187   send_key(XK_Next);
188   pgupdown++;
189   debugf("PAGING   PageDown\n");
190   sync_after_input();
191 }
192 static void send_pgdown_torestore(void) {
193   debugf("PAGING   PageDown x %d\n", -pgupdown);
194   while (pgupdown < 0) {
195     send_key(XK_Next);
196     pgupdown++;
197   }
198   sync_after_input();
199 }
200
201 static void free_snapshot(Snapshot **io) {
202   free(*io);
203   *io= 0;
204 }
205
206 #define SAMPLEMASK 0xfful
207
208 typedef struct {
209   int lshift, rshift;
210 } ShMask;
211
212 static void compute_shift_mask(ShMask *sm, unsigned long ximage_mask) {
213   sm->lshift= 0;
214   sm->rshift= 0;
215   
216   for (;;) {
217     if (ximage_mask <= (SAMPLEMASK>>1)) {
218       sm->lshift++;  ximage_mask <<= 1;
219     } else if (ximage_mask > SAMPLEMASK) {
220       sm->rshift++;  ximage_mask >>= 1;
221     } else {
222       break;
223     }
224     assert(!(sm->lshift && sm->rshift));
225   }
226   assert(sm->lshift < LONG_BIT);
227   assert(sm->rshift < LONG_BIT);
228 }
229
230 static void rtimestamp(double *t, const char *wh) {
231   double n= timestamp();
232   debugf("PAGING                INTERVAL %f  %s\n", n-*t, wh);
233   *t= n;
234 }
235
236 static void snapshot(Snapshot **output) {
237   XImage *im_use, *im_free=0;
238
239   ShMask shiftmasks[3];
240
241   debugf("PAGING   snapshot\n");
242
243   double begin= timestamp();
244   if (shmim) {
245     rtimestamp(&begin, "XShmGetImage before");
246     xassert( XShmGetImage(disp,id,shmim, 0,0, AllPlanes) );
247     rtimestamp(&begin, "XShmGetImage");
248
249     size_t dsz= shmim->bytes_per_line * shmim->height;
250     im_use= im_free= mmalloc(sizeof(*im_use) + dsz);
251     *im_free= *shmim;
252     im_free->data= (void*)(im_free+1);
253     memcpy(im_free->data, shmim->data, dsz);
254     rtimestamp(&begin, "mmalloc/memcpy");
255   } else {
256     rtimestamp(&begin, "XGetImage before");
257     xassert( im_use= im_free=
258              XGetImage(disp,id, 0,0, wwidth,wheight, AllPlanes, ZPixmap) );
259     rtimestamp(&begin, "XGetImage");
260   }
261
262 #define COMPUTE_SHIFT_MASK(ix, rgb) \
263   compute_shift_mask(&shiftmasks[ix], im_use->rgb##_mask)
264   COMPUTE_SHIFT_MASK(0, red);
265   COMPUTE_SHIFT_MASK(1, green);
266   COMPUTE_SHIFT_MASK(2, blue);
267   
268   if (!*output)
269     *output= alloc_rgb_image(wwidth, wheight);
270
271   rtimestamp(&begin, "compute_shift_masks+alloc_rgb_image");
272
273   int x,y,i;
274   unsigned char *op= (*output)->data;
275   for (y=0; y<wheight; y++) {
276     for (x=0; x<wwidth; x++) {
277       long xrgb= XGetPixel(im_use,x,y);
278       for (i=0; i<3; i++) {
279         unsigned long sample=
280           ((xrgb << shiftmasks[i].lshift) >> shiftmasks[i].rshift)
281           & SAMPLEMASK;
282         *op++= sample;
283       }
284     }
285   }
286
287   rtimestamp(&begin,"w*h*XGetPixel");
288   if (im_free)
289     XDestroyImage(im_free);
290   
291   rtimestamp(&begin,"XDestroyImage");
292   check_not_disturbed();
293
294   debugf("PAGING   snapshot done.\n");
295 }
296
297 static int identical(const Snapshot *a, const Snapshot *b) {
298   if (!(a->w == b->w &&
299         a->h == b->h))
300     return 0;
301
302   int compare_to= a->h;
303   if (max_relevant_y>=0 && compare_to > max_relevant_y)
304     compare_to= max_relevant_y;
305   
306   return !memcmp(a->data, b->data, a->w * 3 * compare_to);
307 }
308
309 static void wait_for_stability(Snapshot **output,
310                                const Snapshot *previously,
311                                void (*with_keypress)(void),
312                                const char *fmt, ...)
313      FMT(4,5);
314
315 static void wait_for_stability(Snapshot **output,
316                                const Snapshot *previously,
317                                void (*with_keypress)(void),
318                                const char *fmt, ...) {
319   va_list al;
320   va_start(al,fmt);
321
322   Snapshot *last=0;
323   int nidentical=0;
324   /* waits longer if we're going to return an image identical to previously
325    * if previously==0, all images are considered identical to it */
326
327   char *doing;
328   sysassert( vasprintf(&doing,fmt,al) >=0 );
329
330   debugf("PAGING  wait_for_stability"
331           "  last_input=%f previously=%p `%s'\n",
332           last_input, previously, doing);
333
334   double min_interval= 25000; /*us*/
335   for (;;) {
336     progress_spinner("%s",doing);
337     
338     double since_last_input= timestamp() - last_input;
339     double this_interval= min_interval - since_last_input;
340
341     if (this_interval >= 0)
342       usleep(this_interval);
343
344     snapshot(output);
345
346     if (!last) {
347       debugf("PAGING  wait_for_stability first...\n");
348       last=*output; *output=0;
349     } else if (!identical(*output,last)) {
350       debugf("PAGING  wait_for_stability changed...\n");
351       free_snapshot(&last); last=*output; *output=0;
352       nidentical=0;
353       if (!with_keypress) {
354         min_interval *= 3.0;
355         min_interval += 0.5;
356       }
357     } else {
358       nidentical++;
359       int threshold=
360         !previously ? 3 :
361         identical(*output,previously) ? 5
362         : 1;
363       debugf("PAGING  wait_for_stability nidentical=%d threshold=%d\n",
364               nidentical, threshold);
365       if (nidentical >= threshold)
366         break;
367
368       min_interval += 0.5;
369       min_interval *= 2.0;
370     }
371
372     if (with_keypress)
373       with_keypress();
374   }
375
376   free_snapshot(&last);
377   free(doing);
378   debugf("PAGING  wait_for_stability done.\n");
379   va_end(al);
380 }
381
382 static void raise_and_get_details(void) {
383   int evbase,errbase,majver,minver;
384   int wxpos, wypos;
385   unsigned bd,depth;
386
387   progress("raising and checking YPP client window...");
388
389   debugf("PAGING raise_and_get_details\n");
390
391   int xtest= XTestQueryExtension(disp, &evbase,&errbase,&majver,&minver);
392   if (!xtest) fatal("X server does not support the XTEST extension.");
393
394   xassert( XRaiseWindow(disp, id) );
395   /* in case VisibilityNotify triggers right away before we have had a
396    * change to raise; to avoid falsely detecting lowering in that case */
397   
398   xassert( XSelectInput(disp, id,
399                         StructureNotifyMask|
400                         VisibilityChangeMask
401                         ) );
402
403   xassert( XRaiseWindow(disp, id) );
404   /* in case the window was lowered between our Raise and our SelectInput;
405    * to avoid failing to detect that lowering */
406
407   xassert( XGetWindowAttributes(disp, id, &attr) );
408   xassert( XGetGeometry(disp,id, &attr.root,
409                         &wxpos,&wypos, &wwidth,&wheight,
410                         &bd,&depth) );
411
412   if (!(wwidth >= 320 && wheight >= 320))
413     fatal("YPP client window is implausibly small?");
414
415   if (attr.depth < 24)
416     fatal("Display is not 24bpp.");
417
418   check_client_window_all_on_screen();
419
420   Bool shmpixmaps=0;
421   int major=0,minor=0;
422   int shm= XShmQueryVersion(disp, &major,&minor,&shmpixmaps);
423   debugf("PAGING shm=%d %d.%d pixmaps=%d\n",shm,major,minor,shmpixmaps);
424   if (shm) {
425     xassert( shmim= XShmCreateImage(disp, attr.visual, attr.depth, ZPixmap,
426                                     0,&shminfo, wwidth,wheight) );
427
428     sigset_t oldset, all;
429     sigfillset(&all);
430     sysassert(! sigprocmask(SIG_BLOCK,&all,&oldset) );
431
432     int pfd[2];
433     pid_t cleaner;
434     sysassert(! pipe(pfd) );
435     sysassert( (cleaner= fork()) != -1 );
436     if (!cleaner) {
437       sysassert(! close(pfd[1]) );
438       for (;;) {
439         int r= read(pfd[0], &shminfo.shmid, sizeof(shminfo.shmid));
440         if (!r) exit(0);
441         if (r==sizeof(shminfo.shmid)) break;
442         assert(r==-1 && errno==EINTR);
443       }
444       for (;;) {
445         char bc;
446         int r= read(pfd[0],&bc,1);
447         if (r>=0) break;
448         assert(r==-1 && errno==EINTR);
449       }
450       sysassert(! shmctl(shminfo.shmid,IPC_RMID,0) );
451       exit(0);
452     }
453     sysassert(! close(pfd[0]) );
454
455     sysassert(! sigprocmask(SIG_SETMASK,&oldset,0) );
456
457     assert(shmim->height == wheight);
458     sysassert( (shminfo.shmid=
459                 shmget(IPC_PRIVATE, shmim->bytes_per_line * wheight,
460                        IPC_CREAT|0600)) >= 0 );
461
462     sysassert( write(pfd[1],&shminfo.shmid,sizeof(shminfo.shmid)) ==
463                sizeof(shminfo.shmid) );
464     sysassert( shminfo.shmaddr= shmat(shminfo.shmid,0,0) );
465     shmim->data= shminfo.shmaddr;
466     shminfo.readOnly= False;
467     xassert( XShmAttach(disp,&shminfo) );
468
469     close(pfd[1]); /* causes IPC_RMID */
470   }
471 }
472
473 static void set_focus_commodity(void) {
474   int screen= XScreenNumberOfScreen(attr.screen);
475
476   progress("taking control of YPP client window...");
477
478   debugf("PAGING set_focus\n");
479
480   mouse_1_updown(160,160);
481   sync_after_input();
482
483   delay(0.5);
484   xassert( XSelectInput(disp, id,
485                         StructureNotifyMask|
486                         VisibilityChangeMask|
487                         FocusChangeMask
488                         ) );
489
490   int xpos,ypos;
491   translate_coords_toroot(10,10, &xpos,&ypos);
492   XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
493
494   sync_after_input();
495
496   debugf("PAGING raise_and_set_focus done.\n");
497 }
498
499 static CanonImage *convert_page(Snapshot *sn) {
500   CanonImage *im;
501
502   fwrite_ppmraw(screenshot_file, sn);
503
504   unsigned char *pixel= sn->data;
505   CANONICALISE_IMAGE(im, sn->w, sn->h, {
506     rgb=
507       (pixel[0] << 16) |
508       (pixel[1] <<  8) |
509       (pixel[2]      );
510     pixel += 3;
511   });
512     
513   sysassert(!ferror(screenshot_file));
514   sysassert(!fflush(screenshot_file));
515
516   return im;
517 }
518
519 static void prepare_ypp_client(void) {
520   CanonImage *test;
521   Snapshot *current=0;
522   
523   /* find the window and check it's on the right kind of screen */
524   raise_and_get_details();
525   wait_for_stability(&current,0,0, "checking current YPP client screen...");
526
527   test= convert_page(current);
528   find_structure(test, &max_relevant_y);
529   check_correct_commodities();
530   Rect sunshine= find_sunshine_widget();
531
532   progress("poking client...");
533   mouse_1_updown((sunshine.tl.x   + sunshine.br.x) / 2,
534                  (sunshine.tl.y*9 + sunshine.br.y) / 10);
535
536   free(test);
537
538   wait_for_stability(&current,0,0, "checking basic YPP client screen...");
539   mouse_1_updown(250, wheight-10);
540   mouse_1_updown_here();
541   mouse_1_updown_here();
542   XSync(disp,False);
543   check_not_disturbed();
544   send_key(XK_slash);
545   send_key(XK_w);
546   send_key(XK_Return);
547   sync_after_input();
548
549   Snapshot *status=0;
550   wait_for_stability(&status,current,0, "awaiting status information...");
551   free_snapshot(&current);
552   free_snapshot(&status);
553 }
554
555 void take_screenshots(void) {
556   Snapshot *current=0, *last=0;
557
558   prepare_ypp_client();
559   
560   /* page to the top - keep pressing page up until the image stops changing */
561   set_focus_commodity();
562   wait_for_stability(&current,0, send_pgup_many,
563                      "paging up to top of commodity list...");
564
565   /* now to actually page down */
566   for (;;) {
567     debugf("paging page %d\n",npages);
568
569     if (!(npages < MAX_PAGES))
570       fatal("Paging down seems to generate too many pages - max is %d.",
571             MAX_PAGES);
572     
573     page_images[npages]= convert_page(current);
574     free_snapshot(&last); last=current; current=0;
575
576     debugf("PAGING page %d converted\n",npages);
577
578     wait_for_stability(&current,last, 0,
579                        "collecting screenshot of page %d...",
580                        npages+1);
581
582     if (npages &&  /* first pagedown doesn't do much */
583         identical(current,last)) {
584       free_snapshot(&current);
585       break;
586     }
587
588     send_pgdown();
589     npages++;
590   }
591   progress("finishing with the YPP client...");
592   send_pgdown_torestore();
593
594   debugf("PAGING all done.\n");
595   progress_log("collected %d screenshots.",npages);
596 }    
597
598 void take_one_screenshot(void) {
599   Snapshot *current=0;
600
601   prepare_ypp_client();
602   wait_for_stability(&current,0,0, "taking screenshot...");
603   page_images[0]= convert_page(current);
604   npages= 1;
605   progress_log("collected single screenshot.");
606 }
607
608 void set_yppclient_window(unsigned long wul) {
609   id= wul;
610 }
611
612 DEBUG_DEFINE_SOME_DEBUGF(findypp,debugfind)
613
614 static int nfound;
615 static Atom wm_name;
616 static int screen;
617
618 static void findypp_recurse(int depth, int targetdepth, Window w) {
619   unsigned int nchildren;
620   int i;
621   Window *children=0;
622   Window gotroot, gotparent;
623
624   static const char prefix[]= "Puzzle Pirates - ";
625   static const char onthe[]= " on the ";
626   static const char suffix[]= " ocean";
627 #define S(x) ((int)sizeof((x))-1)
628
629   debugfind("FINDYPP %d/%d screen %d  %*s %lx",
630             depth,targetdepth,screen,
631             depth,"",(unsigned long)w);
632   
633   if (depth!=targetdepth) {
634     xassert( XQueryTree(disp,w,
635                         &gotroot,&gotparent,
636                         &children,&nchildren) );
637     debugfind(" nchildren=%d\n",nchildren);
638   
639     for (i=0; i<nchildren; i++) {
640       Window child= children[i];
641       findypp_recurse(depth+1, targetdepth, child);
642     }
643     XFree(children);
644     return;
645   }
646     
647
648   int gotfmt;
649   Atom gottype;
650   unsigned long len, gotbytesafter;
651   char *title;
652   unsigned char *gottitle=0;
653   xassert( !XGetWindowProperty(disp,w, wm_name,0,512, False,
654                                AnyPropertyType,&gottype, &gotfmt, &len,
655                                &gotbytesafter, &gottitle) );
656   title= (char*)gottitle;
657
658   if (DEBUGP(findypp)) {
659     debugfind(" gf=%d len=%lu gba=%lu \"", gotfmt,len,gotbytesafter);
660     char *p;
661     for (p=title; p < title+len; p++) {
662       char c= *p;
663       if (c>=' ' && c<=126) fputc(c,debug);
664       else fprintf(debug,"\\x%02x",c & 0xff);
665     }
666     fputs("\": ",debug);
667   }
668
669 #define REQUIRE(pred)                                                   \
670   if (!(pred)) { debugfind(" failed test  %s\n", #pred); return; }      \
671   else
672
673   REQUIRE( gottype!=None );
674   REQUIRE( len );
675   REQUIRE( gotfmt==8 );
676
677   REQUIRE( len >= S(prefix) + 1 + S(onthe) + 1 + S(suffix) );
678
679   char *spc1= strchr(  title        + S(prefix), ' ');  REQUIRE(spc1);
680   char *spc2= strrchr((title + len) - S(suffix), ' ');  REQUIRE(spc2);
681
682   REQUIRE( (title + len) - spc1  >= S(onthe)  + S(suffix) );
683   REQUIRE(  spc2         - title >= S(prefix) + S(onthe) );
684
685   REQUIRE( !memcmp(title,                   prefix, S(prefix)) );
686   REQUIRE( !memcmp(title + len - S(suffix), suffix, S(suffix))  );
687   REQUIRE( !memcmp(spc1,                    onthe,  S(onthe))  );
688
689 #define ASSIGN(what, start, end)                        \
690   what= masprintf("%.*s", (int)((end)-(start)), start); \
691   if (o_##what) REQUIRE( !strcasecmp(o_##what, what) ); \
692   else
693
694   ASSIGN(ocean,  spc1 + S(onthe),   (title + len) - S(suffix));
695   ASSIGN(pirate, title + S(prefix),  spc1);
696
697   debugfind(" YES!\n");
698   id= w;
699   nfound++;
700   progress_log("found YPP client (0x%lx):"
701                " %s ocean - %s.",
702                (unsigned long)id, ocean, pirate);
703 }
704
705 void find_yppclient_window(void) {
706   int targetdepth;
707
708   nfound=0;
709   
710   if (id) return;
711   
712   progress("looking for YPP client window...");
713
714   xassert( (wm_name= XInternAtom(disp,"WM_NAME",True)) != None);
715
716   for (targetdepth=1; targetdepth<4; targetdepth++) {
717     for (screen=0; screen<ScreenCount(disp); screen++) {
718       debugfind("FINDYPP screen %d\n", screen);
719       findypp_recurse(0,targetdepth, RootWindow(disp,screen));
720     }
721     if (nfound) break;
722   }
723
724   if (nfound>1)
725     fatal("Found several possible YPP clients.   Close one,\n"
726           " disambiguate with --pirate or --ocean,"
727           " or specify --window-id.\n");
728   if (nfound<1)
729     fatal("Did not find %sYPP client."
730           " Use --window-id and/or report this as a fault.\n",
731           o_ocean || o_pirate ? "matching ": "");
732 }