2 #include <stdio.h> /* for printf, NULL */
3 #include <stdlib.h> /* for free */
4 #include <string.h> /* for strdup */
7 #include "pnd_container.h"
10 #include "pnd_discovery.h"
11 #include "pnd_desktop.h"
12 #include "pnd_locate.h"
13 #include "pnd_utility.h"
15 int main ( int argc, char *argv[] ) {
20 unsigned char do_exec = 0;
21 unsigned char do_icon = 0;
22 unsigned char do_dotdesktop = 0;
24 for ( i = 1; i < argc; i++ ) {
26 if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'e' ) {
27 printf ( "Will attempt a random exec.\n" );
29 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'i' ) {
30 printf ( "Will attempt to extract icons.\n" );
32 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
33 printf ( "Will attempt to extract dotdesktop.\n" );
36 printf ( "%s [-e] [-i] [-d]\n", argv [ 0 ] );
37 printf ( "-e\tOptional. Attempt to exec a random app.\n" );
38 printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
39 printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
45 /* attempt to sort out the config file madness
48 // attempt to fetch a sensible default searchpath for configs
49 configpath = pnd_conf_query_searchpath();
51 // attempt to fetch the apps config to pick up a searchpath
54 apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
57 appspath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
60 appspath = PND_APPS_SEARCHPATH;
63 overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
65 if ( ! overridespath ) {
66 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
70 // couldn't find a useful app search path so use the default
71 appspath = PND_APPS_SEARCHPATH;
72 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
75 printf ( "Apps searchpath is '%s'\n", appspath );
76 printf ( "Apps overrides searchpath is '%s'\n", overridespath );
85 run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
86 run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
89 if ( ! run_searchpath ) {
90 run_searchpath = PND_APPS_SEARCHPATH;
91 run_script = PND_PNDRUN_FILENAME;
95 run_searchpath = NULL;
97 pndrun = PND_PNDRUN_DEFAULT;
101 pndrun = pnd_locate_filename ( run_searchpath, run_script );
104 if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
105 if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
106 if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
108 /* attempt to discover apps in the path
110 pnd_box_handle applist;
112 applist = pnd_disco_search ( appspath, overridespath );
114 // list the found apps (if any)
117 pnd_disco_t *d = pnd_box_get_head ( applist );
121 // display the app 'as is'
123 printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
125 printf ( " Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
127 if ( d -> title_en ) {
128 printf ( " Name EN: %s\n", d -> title_en );
130 if ( d -> desc_en ) {
131 printf ( " Desc EN: %s\n", d -> desc_en );
134 printf ( " Icon: %s\n", d -> icon );
136 if ( d -> pnd_icon_pos ) {
137 printf ( " Icon in pnd might be at: %u\n", d -> pnd_icon_pos );
139 if ( d -> unique_id ) {
140 printf ( " Unique ID: %s\n", d -> unique_id );
142 if ( d -> main_category ) {
143 printf ( " Category: %s\n", d -> main_category );
146 printf ( " Executable: %s\n", d -> exec );
148 if ( d -> startdir ) {
149 printf ( " Start dir: %s\n", d -> startdir );
151 if ( d -> clockspeed ) {
152 printf ( " Clockspeed: %s\n", d -> clockspeed );
154 if ( d -> preview_pic1 ) {
155 printf ( " Preview Pic 1: %s\n", d -> preview_pic1 );
157 if ( d -> preview_pic2 ) {
158 printf ( " Preview Pic 2: %s\n", d -> preview_pic2 );
160 if ( d -> mkdir_sp ) {
161 printf ( " mkdir requests: %s\n", d -> mkdir_sp );
165 if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
166 printf ( " -> icon dump succeeded\n" );
168 // fix up icon path to new one..
170 char buffer [ FILENAME_MAX ];
171 sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
172 d -> icon = strdup ( buffer );
175 printf ( " -> icon dump failed\n" );
179 if ( do_dotdesktop ) {
180 if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
181 printf ( " -> dotdesktop dump succeeded\n" );
183 printf ( " -> dotdesktop dump failed\n" );
188 d = pnd_box_get_next ( d );
193 printf ( "No applications found in search path\n" );
196 // lets toy with executing an application
200 printf ( "*** Couldn't locate a pnd runscript.\n" );
202 printf ( "Found a pnd runscript of %s\n", pndrun );
204 pnd_disco_t *d = pnd_box_get_head ( applist );
206 d = pnd_box_get_next ( d );
209 char fullpath [ FILENAME_MAX ];
210 if ( d -> object_type == pnd_object_type_directory ) {
211 sprintf ( fullpath, "%s", d -> object_path );
212 } else if ( d -> object_type == pnd_object_type_pnd ) {
213 sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
216 printf ( "Guessing appdata path..\n" );
217 char appdata_path [ 1024 ];
218 pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 );
219 printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path );
220 if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) {
221 printf ( " Appdata should be: %s\n", appdata_path );
223 printf ( " Error determining appdata path..\n" );
226 printf ( "Trying to exec '%s'\n", fullpath );
227 pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, NULL, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
235 // exeunt with alarums
238 pnd_box_delete ( apph );
241 // extra testing - tilde-substitution
242 printf ( "Unrelated test..\n" );
243 char *p = strdup ( "~/.applications" );
244 printf ( "Tilde substitution: in '%s'\n", p );
245 printf ( " out '%s'\n", pnd_expand_tilde ( p ) );