Thanks! Both of these are essentially patches from j-r; the tracker urls are..
[pandora-libraries.git] / lib / pnd_discovery.c
1
2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <unistd.h> /* for unlink */
5 #include <limits.h> /* for PATH_MAX */
6 #include <sys/types.h>
7 #include <sys/stat.h>
8
9 #define __USE_GNU /* for strcasestr */
10 #include <string.h> /* for making ftw.h happy */
11
12 #define _XOPEN_SOURCE 500
13 #define __USE_XOPEN_EXTENDED
14 #define _GNU_SOURCE
15 #include <ftw.h> /* for nftw, tree walker */
16
17 #include "pnd_container.h"
18 #include "pnd_pxml.h"
19 #include "pnd_discovery.h"
20 #include "pnd_pathiter.h"
21 #include "pnd_apps.h"
22 #include "pnd_pndfiles.h"
23 #include "pnd_logger.h"
24 #include "pnd_conf.h"
25
26 // need these 'globals' due to the way nftw and ftw work :/
27 static pnd_box_handle disco_box;
28 static char *disco_overrides = NULL;
29
30 void pnd_disco_destroy ( pnd_disco_t *p ) {
31   if ( p -> package_id ) {     free ( p -> package_id);   }
32   if ( p -> title_en ) {       free ( p -> title_en );    }
33   if ( p -> desc_en ) {        free ( p -> desc_en );    }
34   if ( p -> unique_id ) {      free ( p -> unique_id );   }
35   if ( p -> appdata_dirname ) { free ( p -> appdata_dirname );   }
36   if ( p -> icon )     {       free ( p -> icon );        }
37   if ( p -> exec )     {       free ( p -> exec );        }
38   if ( p -> execargs ) {       free ( p -> execargs );    }
39   if ( p -> clockspeed ) {     free ( p -> clockspeed );  }
40   if ( p -> startdir ) {       free ( p -> startdir );    }
41   if ( p -> option_no_x11 ) {  free ( p -> option_no_x11 );  }
42   if ( p -> main_category ) {  free ( p -> main_category );  }
43   if ( p -> main_category1 ) { free ( p -> main_category1 ); }
44   if ( p -> main_category2 ) { free ( p -> main_category2 ); }
45   if ( p -> alt_category ) {   free ( p -> alt_category );   }
46   if ( p -> alt_category1 ) {  free ( p -> alt_category1 );  }
47   if ( p -> alt_category2 ) {  free ( p -> alt_category2 );  }
48   if ( p -> object_filename ) { free ( p -> object_filename ); }
49   if ( p -> object_path )     { free ( p -> object_path ); }
50   if ( p -> mkdir_sp )      {  free ( p -> mkdir_sp );       }
51   if ( p -> info_name )     {  free ( p -> info_name );       }
52   if ( p -> info_type )     {  free ( p -> info_type );       }
53   if ( p -> info_filename ) {  free ( p -> info_filename );       }
54   if ( p -> preview_pic1 )  {  free ( p -> preview_pic1 );     }
55   if ( p -> preview_pic2 )  {  free ( p -> preview_pic2 );     }
56   if ( p -> version_major ) {  free ( p -> version_major );    }
57   if ( p -> version_minor ) {  free ( p -> version_minor );    }
58   if ( p -> version_release ) {free ( p -> version_release );  }
59   if ( p -> version_build ) {  free ( p -> version_build );    }
60   if ( p -> package_version_major ) { free ( p -> package_version_major ); }
61   if ( p -> package_version_minor ) { free ( p -> package_version_minor ); }
62   if ( p -> package_version_release ) { free ( p -> package_version_release ); }
63   if ( p -> package_version_build ) { free ( p -> package_version_build ); }
64   if ( p -> associationitem1_name ) { free ( p -> associationitem1_name ); }
65   if ( p -> associationitem1_filetype ) { free ( p -> associationitem1_filetype ); }
66   if ( p -> exec_dashdash_args ) { free ( p -> exec_dashdash_args ); }
67
68   return;
69 }
70
71 static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
72                                 int typeflag, struct FTW *ftwbuf )
73 {
74   unsigned char valid = pnd_object_type_unknown;
75   pnd_pxml_handle pxmlh = 0;
76   pnd_pxml_handle *pxmlapps = NULL;
77   pnd_pxml_handle *pxmlappiter;
78   unsigned int pxml_close_pos = 0;
79   unsigned char logit = pnd_log_do_buried_logging();
80
81   if ( logit ) {
82     pnd_log ( PND_LOG_DEFAULT, "disco callback encountered '%s'\n", fpath );
83   }
84
85   // PXML.xml is a possible application candidate (and not a dir named PXML.xml :)
86   if ( typeflag & FTW_D ) {
87     if ( logit ) {
88       pnd_log ( PND_LOG_DEFAULT, " .. is dir, skipping\n" );
89     }
90     if ( ftwbuf -> level >= pathiter_depthlimit ) {
91       return ( FTW_SKIP_SUBTREE );
92     }
93     return ( FTW_CONTINUE ); // skip directories and other non-regular files
94   }
95
96   // PND/PNZ file and others may be valid as well .. but lets leave that for now
97   //   printf ( "%s %s\n", fpath + ftwbuf -> base, PND_PACKAGE_FILEEXT );
98   if ( strcasecmp ( fpath + ftwbuf -> base, PXML_FILENAME ) == 0 ) {
99     valid = pnd_object_type_directory;
100   } else if ( strcasestr ( fpath + ftwbuf -> base, PND_PACKAGE_FILEEXT "\0" ) ) {
101     valid = pnd_object_type_pnd;
102   }
103
104   // if not a file of interest, just keep looking until we run out
105   if ( ! valid ) {
106     if ( logit ) {
107       pnd_log ( PND_LOG_DEFAULT, " .. bad filename, skipping\n" );
108     }
109     return ( FTW_CONTINUE );
110   }
111
112   // potentially a valid application
113   if ( valid == pnd_object_type_directory ) {
114     // Plaintext PXML file
115     //printf ( "PXML: disco callback encountered '%s'\n", fpath );
116
117     // pick up the PXML if we can
118     pxmlapps = pnd_pxml_fetch ( (char*) fpath );
119
120   } else if ( valid == pnd_object_type_pnd ) {
121     // PND ... ??
122     FILE *f;
123     char pxmlbuf [ 32 * 1024 ]; // TBD: assuming 32k pxml accrual buffer is a little lame
124
125     //printf ( "PND: disco callback encountered '%s'\n", fpath );
126
127     // is this a valid .pnd file? The filename is a candidate already, but verify..
128     // .. presence of PXML appended, or at least contained within?
129     // .. presence of an icon appended after PXML?
130
131     // open it up..
132     f = fopen ( fpath, "r" );
133
134     // try to locate the PXML portion
135     if ( ! pnd_pnd_seek_pxml ( f ) ) {
136       fclose ( f );
137       return ( FTW_CONTINUE ); // pnd or not, but not to spec. Pwn'd the pnd?
138     }
139
140     // accrue it into a buffer
141     if ( ! pnd_pnd_accrue_pxml ( f, pxmlbuf, 32 * 1024 ) ) {
142       fclose ( f );
143       return ( FTW_CONTINUE );
144     }
145
146     //printf ( "buffer is %s\n", pxmlbuf );
147     //fflush ( stdout );
148
149 #if 1 // icon
150     // for convenience, lets skip along past trailing newlines/CR's in hopes of finding icon data?
151     {
152       char pngbuffer [ 16 ]; // \211 P N G \r \n \032 \n
153       pngbuffer [ 0 ] = 137;      pngbuffer [ 1 ] = 80;      pngbuffer [ 2 ] = 78;      pngbuffer [ 3 ] = 71;
154       pngbuffer [ 4 ] = 13;       pngbuffer [ 5 ] = 10;       pngbuffer [ 6 ] = 26;      pngbuffer [ 7 ] = 10;
155
156       unsigned char padtests = 20;
157       unsigned int padstart = ftell ( f );
158
159       // seek back 10 (should be back into the /PXML> part) to catch any appending-icon-no-line-endings funny business
160       fseek ( f, -10, SEEK_CUR );
161
162       while ( padtests ) {
163
164         if ( fread ( pngbuffer + 8, 8, 1, f ) == 1 ) {
165           if ( memcmp ( pngbuffer, pngbuffer + 8, 8 ) == 0 ) {
166             pxml_close_pos = ftell ( f ) - 8;
167             break;
168           } // if
169           fseek ( f, -7, SEEK_CUR ); // seek back 7 (so we're 1 further than we started, since PNG header is 8b)
170         } // if read
171
172         padtests --;
173       } // while
174
175       if ( ! padtests ) {
176         // no icon found, so back to where we started looking
177         fseek ( f, padstart, SEEK_SET );
178       }
179
180     } // icon
181 #endif
182
183     // by now, we have <PXML> .. </PXML>, try to parse..
184     pxmlapps = pnd_pxml_fetch_buffer ( (char*) fpath, pxmlbuf );
185
186     // done with file
187     fclose ( f );
188
189   }
190
191   // pxmlh is useful?
192   if ( ! pxmlapps ) {
193     return ( FTW_CONTINUE ); // continue tree walk
194   }
195
196   // for ovr-file
197   char ovrfile [ PATH_MAX ];
198   pnd_box_handle ovrh = 0; // 0 didn't try, -1 tried and failed, >0 tried and got
199
200   // iterate across apps in the PXML
201   pxmlappiter = pxmlapps;
202   while ( 1 ) {
203     pxmlh = *pxmlappiter;
204     pxmlappiter++;
205
206     if ( ! pxmlh ) {
207       break; // all done
208     }
209
210     // check for validity and add to resultset if it looks executable
211     if ( pnd_is_pxml_valid_app ( pxmlh ) ) {
212       pnd_disco_t *p;
213       char *fixpxml;
214       char *z;
215
216       //pnd_log ( PND_LOG_DEFAULT, "Setting up discovered app %u\n", ((pnd_pxml_t*) pxmlh) -> subapp_number );
217
218       p = pnd_box_allocinsert ( disco_box, (char*) fpath, sizeof(pnd_disco_t) );
219
220       // base paths
221       p -> object_path = strdup ( fpath );
222
223       if ( ( fixpxml = strcasestr ( p -> object_path, PXML_FILENAME ) ) ) {
224         *fixpxml = '\0'; // if this is not a .pnd, lop off the PXML.xml at the end
225       } else if ( ( fixpxml = strrchr ( p -> object_path, '/' ) ) ) {
226         *(fixpxml+1) = '\0'; // for pnd, lop off to last /
227       }
228
229       if ( ( fixpxml = strrchr ( fpath, '/' ) ) ) {
230         p -> object_filename = strdup ( fixpxml + 1 );
231       }
232
233       // subapp-number
234       p -> subapp_number = ((pnd_pxml_t*) pxmlh) -> subapp_number;
235
236       // png icon path
237       p -> pnd_icon_pos = pxml_close_pos;
238
239       // type
240       p -> object_type = valid;
241
242       // PXML fields
243       if ( pnd_pxml_get_package_id ( pxmlh ) ) {
244         p -> package_id = strdup ( pnd_pxml_get_package_id ( pxmlh ) );
245       }
246       char *name_en = pnd_pxml_get_app_name_en ( pxmlh );
247       if (name_en) {
248         p -> title_en = name_en; /* already strdupped */
249       }
250       char *desc_en = pnd_pxml_get_description_en ( pxmlh );
251       if ( desc_en ) {
252         p -> desc_en = desc_en; /* already strdupped */
253       }
254       if ( pnd_pxml_get_icon ( pxmlh ) ) {
255         p -> icon = strdup ( pnd_pxml_get_icon ( pxmlh ) );
256       }
257       if ( pnd_pxml_get_exec ( pxmlh ) ) {
258         p -> exec = strdup ( pnd_pxml_get_exec ( pxmlh ) );
259       }
260       if ( pnd_pxml_get_execargs ( pxmlh ) ) {
261         p -> execargs = strdup ( pnd_pxml_get_execargs ( pxmlh ) );
262       }
263       if ( pnd_pxml_get_exec_option_no_x11 ( pxmlh ) ) {
264         p -> option_no_x11 = strdup ( pnd_pxml_get_exec_option_no_x11 ( pxmlh ) );
265       }
266       if ( pnd_pxml_get_unique_id ( pxmlh ) ) {
267         p -> unique_id = strdup ( pnd_pxml_get_unique_id ( pxmlh ) );
268       }
269       if ( pnd_pxml_get_appdata_dirname ( pxmlh ) ) {
270         p -> appdata_dirname = strdup ( pnd_pxml_get_appdata_dirname ( pxmlh ) );
271       }
272       if ( pnd_pxml_get_clockspeed ( pxmlh ) ) {
273         p -> clockspeed = strdup ( pnd_pxml_get_clockspeed ( pxmlh ) );
274       }
275       if ( pnd_pxml_get_startdir ( pxmlh ) ) {
276         p -> startdir = strdup ( pnd_pxml_get_startdir ( pxmlh ) );
277       }
278       // category kruft
279       if ( pnd_pxml_get_main_category ( pxmlh ) ) {
280         p -> main_category = strdup ( pnd_pxml_get_main_category ( pxmlh ) );
281       }
282       if ( pnd_pxml_get_subcategory1 ( pxmlh ) ) {
283         p -> main_category1 = strdup ( pnd_pxml_get_subcategory1 ( pxmlh ) );
284       }
285       if ( pnd_pxml_get_subcategory2 ( pxmlh ) ) {
286         p -> main_category2 = strdup ( pnd_pxml_get_subcategory2 ( pxmlh ) );
287       }
288       if ( pnd_pxml_get_altcategory ( pxmlh ) ) {
289         p -> alt_category = strdup ( pnd_pxml_get_altcategory ( pxmlh ) );
290       }
291       if ( pnd_pxml_get_altsubcategory1 ( pxmlh ) ) {
292         p -> alt_category1 = strdup ( pnd_pxml_get_altsubcategory1 ( pxmlh ) );
293       }
294       if ( pnd_pxml_get_altsubcategory2 ( pxmlh ) ) {
295         p -> alt_category2 = strdup ( pnd_pxml_get_altsubcategory2 ( pxmlh ) );
296       }
297       // preview pics
298       if ( ( z = pnd_pxml_get_previewpic1 ( pxmlh ) ) ) {
299         p -> preview_pic1 = strdup ( z );
300       }
301       if ( ( z = pnd_pxml_get_previewpic2 ( pxmlh ) ) ) {
302         p -> preview_pic2 = strdup ( z );
303       }
304       // mkdirs
305       if ( pnd_pxml_get_mkdir ( pxmlh ) ) {
306         p -> mkdir_sp = strdup ( pnd_pxml_get_mkdir ( pxmlh ) );
307       }
308       // info
309       if ( pnd_pxml_get_info_src ( pxmlh ) ) {
310         p -> info_filename = strdup ( pnd_pxml_get_info_src ( pxmlh ) );
311       }
312       if ( pnd_pxml_get_info_name ( pxmlh ) ) {
313         p -> info_name = strdup ( pnd_pxml_get_info_name ( pxmlh ) );
314       }
315       if ( pnd_pxml_get_info_type ( pxmlh ) ) {
316         p -> info_type = strdup ( pnd_pxml_get_info_type ( pxmlh ) );
317       }
318       if ( pnd_pxml_get_version_major ( pxmlh ) ) {
319    p -> version_major = strdup ( pnd_pxml_get_version_major ( pxmlh ) );
320       }
321       if ( pnd_pxml_get_version_minor ( pxmlh ) ) {
322    p -> version_minor = strdup ( pnd_pxml_get_version_minor ( pxmlh ) );
323       }
324       if ( pnd_pxml_get_version_release ( pxmlh ) ) {
325    p -> version_release = strdup ( pnd_pxml_get_version_release ( pxmlh ) );
326       }
327       if ( pnd_pxml_get_version_build ( pxmlh ) ) {
328    p -> version_build = strdup ( pnd_pxml_get_version_build ( pxmlh ) );
329       }
330       if ( pnd_pxml_get_package_version_major ( pxmlh ) ) {
331         p -> package_version_major = strdup ( pnd_pxml_get_package_version_major ( pxmlh ) );
332       }
333       if ( pnd_pxml_get_package_version_minor ( pxmlh ) ) {
334    p -> package_version_minor = strdup ( pnd_pxml_get_package_version_minor ( pxmlh ) );
335       }
336       if ( pnd_pxml_get_package_version_release ( pxmlh ) ) {
337    p -> package_version_release = strdup ( pnd_pxml_get_package_version_release ( pxmlh ) );
338       }
339       if ( pnd_pxml_get_package_version_build ( pxmlh ) ) {
340    p -> package_version_build = strdup ( pnd_pxml_get_package_version_build ( pxmlh ) );
341       }
342 #if 1
343       // file associations
344       if ( pnd_pxml_get_associationitem1_name ( pxmlh ) ) {
345         p -> associationitem1_name = strdup ( pnd_pxml_get_associationitem1_name ( pxmlh ) );
346         p -> associationitem1_filetype = strdup ( pnd_pxml_get_associationitem1_filetype ( pxmlh ) );
347         //pnd_log ( PND_LOG_DEFAULT, "  Disco: Found file association request in PXML (%s)\n", p -> title_en );
348       }
349 #endif
350       if ( pnd_pxml_get_execdashdashargs ( pxmlh ) ) {
351         p -> exec_dashdash_args = strdup ( pnd_pxml_get_execdashdashargs ( pxmlh ) );
352       }
353
354       // look for any PXML overrides, if requested
355       if ( disco_overrides ) {
356         pnd_pxml_merge_override ( pxmlh, disco_overrides );
357       }
358
359       // handle ovr overrides
360       // try to load a same-path-as-pnd override file
361       if ( ovrh == 0 ) {
362         sprintf ( ovrfile, "%s/%s", p -> object_path, p -> object_filename );
363         fixpxml = strcasestr ( ovrfile, PND_PACKAGE_FILEEXT );
364         if ( fixpxml ) {
365           strcpy ( fixpxml, PXML_SAMEPATH_OVERRIDE_FILEEXT );
366           struct stat statbuf;
367           if ( stat ( ovrfile, &statbuf ) == 0 ) {
368             ovrh = pnd_conf_fetch_by_path ( ovrfile );
369
370             if ( ! ovrh ) {
371               // couldn't pull conf out of file, so don't try again
372               ovrh = (void*)(-1);
373             }
374
375           } else {
376             ovrh = (void*)(-1); // not found, don't try again
377           } // stat
378         } // can find .pnd
379       } // tried ovr yet?
380
381       // is ovr file open?
382       if ( ovrh != 0 && ovrh != (void*)(-1) ) {
383         // pull in appropriate values
384         char key [ 100 ];
385         char *v;
386
387         // set the flag regardless, so its for all subapps
388         p -> object_flags |= PND_DISCO_FLAG_OVR;
389
390         // title
391         snprintf ( key, 100, "Application-%u.title", p -> subapp_number );
392         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
393           if ( p -> title_en ) {
394             free ( p -> title_en );
395           }
396           p -> title_en = strdup ( v );
397         }
398
399         // clockspeed
400         snprintf ( key, 100, "Application-%u.clockspeed", p -> subapp_number );
401         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
402           if ( p -> clockspeed ) {
403             free ( p -> clockspeed );
404           }
405           p -> clockspeed = strdup ( v );
406         }
407
408         // appdata dirname
409         snprintf ( key, 100, "Application-%u.appdata", p -> subapp_number );
410         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
411           if ( p -> appdata_dirname ) {
412             free ( p -> appdata_dirname );
413           }
414           p -> appdata_dirname = strdup ( v );
415         }
416
417         // categories
418         snprintf ( key, 100, "Application-%u.maincategory", p -> subapp_number );
419         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
420           if ( p -> main_category ) {
421             free ( p -> main_category );
422           }
423           // the override file cannot suppress the main category
424           p -> main_category = strdup ( v );
425         }
426         snprintf ( key, 100, "Application-%u.maincategorysub1", p -> subapp_number );
427         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
428           if ( p -> main_category1 ) {
429             free ( p -> main_category1 );
430             p -> main_category1 = NULL;
431           }
432           if ( strcasecmp ( v, "NoSubcategory" ) != 0 ) {
433             p -> main_category1 = strdup ( v );
434           }
435         }
436         snprintf ( key, 100, "Application-%u.maincategorysub2", p -> subapp_number );
437         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
438           if ( p -> main_category2 ) {
439             free ( p -> main_category2 );
440             p -> main_category2 = NULL;
441           }
442           if ( strcasecmp ( v, "NoSubcategory" ) != 0 ) {
443             p -> main_category2 = strdup ( v );
444           }
445         }
446         // alt categories
447         snprintf ( key, 100, "Application-%u.altcategory", p -> subapp_number );
448         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
449           if ( p -> alt_category ) {
450             free ( p -> alt_category );
451             p -> alt_category = NULL;
452           }
453           // but it makes sense to allow full suppression of the alternate category
454           if ( strcasecmp ( v, "NoCategory" ) != 0 ) {
455             p -> alt_category = strdup ( v );
456           }
457         }
458         snprintf ( key, 100, "Application-%u.altcategorysub1", p -> subapp_number );
459         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
460           if ( p -> alt_category1 ) {
461             free ( p -> alt_category1 );
462             p -> alt_category1 = NULL;
463           }
464           if ( strcasecmp ( v, "NoSubcategory" ) != 0 ) {
465             p -> alt_category1 = strdup ( v );
466           }
467         }
468         snprintf ( key, 100, "Application-%u.altcategorysub2", p -> subapp_number );
469         if ( ( v = pnd_conf_get_as_char ( ovrh, key ) ) ) {
470           if ( p -> alt_category2 ) {
471             free ( p -> alt_category2 );
472             p -> alt_category2 = NULL;
473           }
474           if ( strcasecmp ( v, "NoSubcategory" ) != 0 ) {
475             p -> alt_category2 = strdup ( v );
476           }
477         }
478
479       } // got ovr conf loaded?
480
481     } else {
482       //printf ( "Invalid PXML; skipping.\n" );
483     }
484
485     // ditch pxml
486     pnd_pxml_delete ( pxmlh );
487
488   } // while pxmlh is good
489
490   // free up ovr
491   if ( ovrh != 0 && ovrh != (void*)(-1) ) {
492     pnd_box_delete ( ovrh );
493   }
494
495   // free up the applist
496   free ( pxmlapps );
497
498   return ( FTW_CONTINUE ); // continue the tree walk
499 }
500
501 pnd_box_handle pnd_disco_search ( char *searchpath, char *overridespath ) {
502
503   //printf ( "Searchpath to discover: '%s'\n", searchpath );
504
505   // alloc a container for the result set
506   disco_box = pnd_box_new ( "discovery" );
507   disco_overrides = overridespath;
508
509   /* iterate across the paths within the searchpath, attempting to locate applications
510    */
511
512   SEARCHPATH_PRE
513   {
514
515     // invoke the dir walking function; thankfully Linux includes a pretty good one
516     nftw ( buffer,               // path to descend
517            pnd_disco_callback,   // callback to do processing
518            10,                   // no more than X open fd's at once
519            FTW_PHYS | FTW_ACTIONRETVAL );   // do not follow symlinks
520
521   }
522   SEARCHPATH_POST
523
524   // return whatever we found, or NULL if nada
525   if ( ! pnd_box_get_head ( disco_box ) ) {
526     pnd_box_delete ( disco_box );
527     disco_box = NULL;
528   }
529
530   return ( disco_box );
531 }
532
533 pnd_box_handle pnd_disco_file ( char *path, char *filename ) {
534   struct stat statbuf;
535
536   // set up container
537   disco_overrides = NULL;
538   disco_box = pnd_box_new ( "discovery" );
539
540   // path
541   char fullpath [ PATH_MAX ];
542   sprintf ( fullpath, "%s/%s", path, filename );
543
544   // fake it
545   if ( stat ( fullpath, &statbuf ) < 0 ) {
546     return ( 0 );
547   }
548
549   struct FTW ftw;
550   ftw.base = strlen ( path );
551   ftw.level = 0;
552
553   pnd_disco_callback ( fullpath, &statbuf, FTW_F, &ftw );
554
555   // return whatever we found, or NULL if nada
556   if ( ! pnd_box_get_head ( disco_box ) ) {
557     pnd_box_delete ( disco_box );
558     disco_box = NULL;
559   }
560
561   return ( disco_box );
562 }