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;
23 char dotdesktoppath [ 1024 ] = "";
25 for ( i = 1; i < argc; i++ ) {
27 if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'e' ) {
28 printf ( "Will attempt a random exec.\n" );
30 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'i' ) {
31 printf ( "Will attempt to extract icons.\n" );
33 } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
34 printf ( "Will attempt to extract dotdesktop.\n" );
36 } else if ( strstr ( argv [ i ], ".desktop" ) ) {
37 strncpy ( dotdesktoppath, argv [ i ], 1023 );
38 printf ( "Will scan '%s' instead of performing discovery\n", dotdesktoppath );
40 printf ( "%s [-e] [-i] [-d] [dotdesktop-file]\n", argv [ 0 ] );
41 printf ( "-e\tOptional. Attempt to exec a random app.\n" );
42 printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
43 printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
44 printf ( "dotdesktop-file\tIf path specified and ends with .desktop, try to scan that .desktop instead of pnd-discovery\n" );
50 /* attempt to sort out the config file madness
53 // attempt to fetch a sensible default searchpath for configs
54 configpath = pnd_conf_query_searchpath();
56 // attempt to fetch the apps config to pick up a searchpath
59 apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
62 appspath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
65 appspath = PND_APPS_SEARCHPATH;
68 overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
70 if ( ! overridespath ) {
71 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
75 // couldn't find a useful app search path so use the default
76 appspath = PND_APPS_SEARCHPATH;
77 overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
80 printf ( "Apps searchpath is '%s'\n", appspath );
81 printf ( "Apps overrides searchpath is '%s'\n", overridespath );
90 run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
91 run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
94 if ( ! run_searchpath ) {
95 run_searchpath = PND_APPS_SEARCHPATH;
96 run_script = PND_PNDRUN_FILENAME;
100 run_searchpath = NULL;
102 pndrun = PND_PNDRUN_DEFAULT;
106 pndrun = pnd_locate_filename ( run_searchpath, run_script );
109 if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
110 if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
111 if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
113 /* attempt to discover apps in the path
115 pnd_box_handle applist;
117 if ( dotdesktoppath [ 0 ] ) {
118 pnd_disco_t *p = pnd_parse_dotdesktop ( dotdesktoppath );
119 pnd_box_handle disco_box = pnd_box_new ( "discovery" );
121 pnd_disco_t *ai = pnd_box_allocinsert ( disco_box, dotdesktoppath, sizeof(pnd_disco_t) );
122 memmove ( ai, p, sizeof(pnd_disco_t) );
126 applist = pnd_disco_search ( appspath, overridespath );
129 // list the found apps (if any)
132 pnd_disco_t *d = pnd_box_get_head ( applist );
136 // display the app 'as is'
138 printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
140 printf ( " Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
142 if ( d -> title_en ) {
143 printf ( " Name EN: %s\n", d -> title_en );
145 if ( d -> desc_en ) {
146 printf ( " Desc EN: %s\n", d -> desc_en );
149 printf ( " Icon: %s\n", d -> icon );
151 if ( d -> pnd_icon_pos ) {
152 printf ( " Icon in pnd might be at: %u\n", d -> pnd_icon_pos );
154 if ( d -> unique_id ) {
155 printf ( " Unique ID: %s\n", d -> unique_id );
157 if ( d -> main_category ) {
158 printf ( " Category: %s\n", d -> main_category );
161 printf ( " Executable: %s\n", d -> exec );
163 if ( d -> startdir ) {
164 printf ( " Start dir: %s\n", d -> startdir );
166 if ( d -> clockspeed ) {
167 printf ( " Clockspeed: %s\n", d -> clockspeed );
169 if ( d -> preview_pic1 ) {
170 printf ( " Preview Pic 1: %s\n", d -> preview_pic1 );
172 if ( d -> preview_pic2 ) {
173 printf ( " Preview Pic 2: %s\n", d -> preview_pic2 );
175 if ( d -> mkdir_sp ) {
176 printf ( " mkdir requests: %s\n", d -> mkdir_sp );
180 if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
181 printf ( " -> icon dump succeeded\n" );
183 // fix up icon path to new one..
185 char buffer [ FILENAME_MAX ];
186 sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
187 d -> icon = strdup ( buffer );
190 printf ( " -> icon dump failed\n" );
194 if ( do_dotdesktop ) {
195 if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
196 printf ( " -> dotdesktop dump succeeded\n" );
198 printf ( " -> dotdesktop dump failed\n" );
202 // free current disco <o/
203 pnd_disco_destroy( d );
206 d = pnd_box_get_next ( d );
211 pnd_box_delete( applist );
214 printf ( "No applications found in search path\n" );
217 // lets toy with executing an application
221 printf ( "*** Couldn't locate a pnd runscript.\n" );
223 printf ( "Found a pnd runscript of %s\n", pndrun );
225 pnd_disco_t *d = pnd_box_get_head ( applist );
227 d = pnd_box_get_next ( d );
230 char fullpath [ FILENAME_MAX ];
231 if ( d -> object_type == pnd_object_type_directory ) {
232 sprintf ( fullpath, "%s", d -> object_path );
233 } else if ( d -> object_type == pnd_object_type_pnd ) {
234 sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
237 printf ( "Guessing appdata path..\n" );
238 char appdata_path [ 1024 ];
239 pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 );
240 printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path );
241 if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) {
242 printf ( " Appdata should be: %s\n", appdata_path );
244 printf ( " Error determining appdata path..\n" );
247 printf ( "Trying to exec '%s'\n", fullpath );
248 pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, NULL, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
256 // exeunt with alarums
259 pnd_box_delete ( apph );
262 // extra testing - tilde-substitution
263 printf ( "Unrelated test..\n" );
264 char *p = strdup ( "~/.applications" );
265 printf ( "Tilde substitution: in '%s'\n", p );
266 char *expand = pnd_expand_tilde ( p );
267 printf ( " out '%s'\n", expand ); free(expand);