2 #include <stdio.h> /* for printf, NULL */
3 #include <stdlib.h> /* for free */
4 #include <string.h> /* for strdup */
5 #include <ctype.h> /* for isdigit */
8 #include "pnd_container.h"
10 #include "pnd_discovery.h"
11 #include "pnd_locate.h"
12 #include "pnd_pndfiles.h"
15 static void usage ( char *argv[] ) {
16 printf ( "%s [-r runscript] [-n] [-X] path-to-pndfile\n", argv [ 0 ] );
17 printf ( "-r\tOptional. If not specified, will attempt to suss from configs.\n" );
18 printf ( "-X\tOptional. If present, run sub-app number 'X'; ex: -0 for first, -1 for second, etc.\n" );
19 printf ( "pndfile\tRequired. Full path to the pnd-file to execute.\n" );
23 int main ( int argc, char *argv[] ) {
27 unsigned char subapp = 0;
29 for ( i = 1; i < argc; i++ ) {
31 if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'r' ) {
32 pnd_run = argv [ i + 1 ];
35 printf ( "-r specified, but no argument provided.\n" );
38 } else if ( argv [ i ][ 0 ] == '-' && isdigit(argv [ i ][ 1 ]) ) {
39 subapp = atoi (argv[i] + 1);
42 if ( argv [ i ][ 0 ] == '-' ) {
45 } else if ( pndfile ) {
46 printf ( "Only one pndfile may be specified.\n" );
55 // if runscript was not specified on cmdline, attempt to pick it up from config
56 // ---> cribbed right out of discotest :/ copypaste ftw!
61 // attempt to fetch a sensible default searchpath for configs
62 configpath = pnd_conf_query_searchpath();
64 // attempt to fetch the apps config. since it finds us the runscript
67 apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
71 overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
73 if ( ! overridespath ) {
74 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
78 // couldn't find a useful app search path so use the default
79 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
82 // given app-config, try to locate a runscript
88 run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
89 run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
92 if ( ! run_searchpath ) {
93 run_searchpath = PND_APPS_SEARCHPATH;
94 run_script = PND_PNDRUN_FILENAME;
98 run_searchpath = NULL;
100 pndrun = PND_PNDRUN_DEFAULT;
104 pndrun = pnd_locate_filename ( run_searchpath, run_script );
107 // hand back to main proggy
108 pnd_run = pndrun; // lame, fix this
110 } // try to locate runscript
113 printf ( "Runscript could not be determined. Fail.\n" );
123 printf ( "Runscript\t%s\n", pnd_run );
124 printf ( "Pndfile\t\t%s\n", pndfile );
125 printf ( "Subapp Number\t%u\n", subapp );
127 // figure out path and filename
128 char *path, *filename;
130 if ( strchr ( pndfile, '/' ) ) {
131 char *foo = rindex ( pndfile, '/' );
141 pnd_box_handle h = pnd_disco_file ( path, filename );
144 pnd_disco_t *d = pnd_box_get_head ( h );
145 while ( subapp && d ) {
146 if ( d -> title_en ) {
147 printf ( "Skipping: '%s'\n", d -> title_en );
149 d = pnd_box_get_next ( d );
153 printf ( "No more applications in pnd-file.\n" );
156 if ( d -> title_en ) {
157 printf ( "Invoking: '%s'\n", d -> title_en );
160 pnd_apps_exec_disco ( pnd_run, d, PND_EXEC_OPTION_BLOCK, NULL );