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_locate.h"
12 #include "pnd_utility.h"
14 int main ( int argc, char *argv[] ) {
19 unsigned char do_exec = 0;
20 unsigned char do_icon = 0;
21 unsigned char do_dotdesktop = 0;
23 for ( i = 1; i < argc; i++ ) {
25 if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'e' ) {
26 printf ( "Will attempt a random exec.\n" );
28 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'i' ) {
29 printf ( "Will attempt to extract icons.\n" );
31 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
32 printf ( "Will attempt to extract dotdesktop.\n" );
35 printf ( "%s [-e] [-i] [-d]\n", argv [ 0 ] );
36 printf ( "-e\tOptional. Attempt to exec a random app.\n" );
37 printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
38 printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
44 /* attempt to sort out the config file madness
47 // attempt to fetch a sensible default searchpath for configs
48 configpath = pnd_conf_query_searchpath();
50 // attempt to fetch the apps config to pick up a searchpath
53 apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
56 appspath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
59 appspath = PND_APPS_SEARCHPATH;
62 overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
64 if ( ! overridespath ) {
65 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
69 // couldn't find a useful app search path so use the default
70 appspath = PND_APPS_SEARCHPATH;
71 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
74 printf ( "Apps searchpath is '%s'\n", appspath );
75 printf ( "Apps overrides searchpath is '%s'\n", overridespath );
84 run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
85 run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
88 if ( ! run_searchpath ) {
89 run_searchpath = PND_APPS_SEARCHPATH;
90 run_script = PND_PNDRUN_FILENAME;
94 run_searchpath = NULL;
96 pndrun = PND_PNDRUN_DEFAULT;
100 pndrun = pnd_locate_filename ( run_searchpath, run_script );
103 if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
104 if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
105 if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
107 /* attempt to discover apps in the path
109 pnd_box_handle applist;
111 applist = pnd_disco_search ( appspath, overridespath );
113 // list the found apps (if any)
116 pnd_disco_t *d = pnd_box_get_head ( applist );
120 // display the app 'as is'
122 printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
124 printf ( " Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
126 if ( d -> title_en ) {
127 printf ( " Name EN: %s\n", d -> title_en );
129 if ( d -> desc_en ) {
130 printf ( " Desc EN: %s\n", d -> desc_en );
133 printf ( " Icon: %s\n", d -> icon );
135 if ( d -> pnd_icon_pos ) {
136 printf ( " Icon in pnd might be at: %u\n", d -> pnd_icon_pos );
138 if ( d -> unique_id ) {
139 printf ( " Unique ID: %s\n", d -> unique_id );
141 if ( d -> main_category ) {
142 printf ( " Category: %s\n", d -> main_category );
145 printf ( " Executable: %s\n", d -> exec );
147 if ( d -> startdir ) {
148 printf ( " Start dir: %s\n", d -> startdir );
150 if ( d -> clockspeed ) {
151 printf ( " Clockspeed: %s\n", d -> clockspeed );
153 if ( d -> preview_pic1 ) {
154 printf ( " Preview Pic 1: %s\n", d -> preview_pic1 );
156 if ( d -> preview_pic2 ) {
157 printf ( " Preview Pic 2: %s\n", d -> preview_pic2 );
161 if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
162 printf ( " -> icon dump succeeded\n" );
164 // fix up icon path to new one..
166 char buffer [ FILENAME_MAX ];
167 sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
168 d -> icon = strdup ( buffer );
171 printf ( " -> icon dump failed\n" );
175 if ( do_dotdesktop ) {
176 if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
177 printf ( " -> dotdesktop dump succeeded\n" );
179 printf ( " -> dotdesktop dump failed\n" );
184 d = pnd_box_get_next ( d );
189 printf ( "No applications found in search path\n" );
192 // lets toy with executing an application
196 printf ( "*** Couldn't locate a pnd runscript.\n" );
198 printf ( "Found a pnd runscript of %s\n", pndrun );
200 pnd_disco_t *d = pnd_box_get_head ( applist );
202 d = pnd_box_get_next ( d );
205 char fullpath [ FILENAME_MAX ];
206 if ( d -> object_type == pnd_object_type_directory ) {
207 sprintf ( fullpath, "%s", d -> object_path );
208 } else if ( d -> object_type == pnd_object_type_pnd ) {
209 sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
212 printf ( "Guessing appdata path..\n" );
213 char appdata_path [ 1024 ];
214 pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 );
215 printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path );
216 if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) {
217 printf ( " Appdata should be: %s\n", appdata_path );
219 printf ( " Error determining appdata path..\n" );
222 printf ( "Trying to exec '%s'\n", fullpath );
223 pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
231 // exeunt with alarums
234 pnd_box_delete ( apph );
237 // extra testing - tilde-substitution
238 printf ( "Unrelated test..\n" );
239 char *p = strdup ( "~/.applications" );
240 printf ( "Tilde substitution: in '%s'\n", p );
241 printf ( " out '%s'\n", pnd_expand_tilde ( p ) );