2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #define __USE_GNU /* for strcasestr */
5 #include <string.h> /* for making ftw.h happy */
6 #include <unistd.h> /* for fork exec */
9 #include "pnd_container.h"
10 #include "pnd_utility.h"
11 #include "pnd_pndfiles.h"
12 #include "pnd_discovery.h"
14 // a generalized variable-substitution routine might be nice; for now we need a quick tilde one,
15 // so here goes. Brute force ftw!
16 char *pnd_expand_tilde ( char *freeable_buffer ) {
18 char *s = freeable_buffer;
19 char *home = getenv ( "HOME" );
22 return ( s ); // can't succeed
25 while ( ( p = strchr ( s, '~' ) ) ) {
26 char *temp = malloc ( strlen ( s ) + strlen ( home ) + 1 );
27 memset ( temp, '\0', strlen ( s ) + strlen ( home ) + 1 );
28 // copy in stuff prior to ~
29 strncpy ( temp, s, p - s );
31 strcat ( temp, home );
32 // copy stuff after tilde in
33 strcat ( temp, p + 1 );
37 } // while finding matches
42 void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 ) {
45 if ( ( i = fork() ) < 0 ) {
46 printf ( "ERROR: Couldn't fork()\n" );
51 return; // parent process, don't care
54 // child process, do something
56 execl ( fullpath, fullpath, arg1, (char*) NULL );
58 execl ( fullpath, fullpath, (char*) NULL );
61 // getting here is an error
62 //printf ( "Error attempting to run %s\n", fullpath );
67 pnd_pxml_handle pnd_pxml_get_by_path ( char *fullpath ) {
68 unsigned char valid = pnd_object_type_unknown;
69 pnd_pxml_handle pxmlh = 0;
71 // WARN: this is way too close to callback in pnd_disco .. should be refactored!
73 if ( strcasestr ( fullpath, PXML_FILENAME ) ) {
74 valid = pnd_object_type_directory;
75 } else if ( strcasestr ( fullpath, PND_PACKAGE_FILEEXT "\0" ) ) {
76 valid = pnd_object_type_pnd;
79 // if not a file of interest, just keep looking until we run out
84 // potentially a valid application
85 if ( valid == pnd_object_type_directory ) {
86 pxmlh = pnd_pxml_fetch ( (char*) fullpath );
88 } else if ( valid == pnd_object_type_pnd ) {
90 char pxmlbuf [ 32 * 1024 ]; // TBD: assuming 32k pxml accrual buffer is a little lame
93 f = fopen ( fullpath, "r" );
95 // try to locate the PXML portion
96 if ( ! pnd_pnd_seek_pxml ( f ) ) {
98 return ( 0 ); // pnd or not, but not to spec. Pwn'd the pnd?
101 // accrue it into a buffer
102 if ( ! pnd_pnd_accrue_pxml ( f, pxmlbuf, 32 * 1024 ) ) {
107 // by now, we have <PXML> .. </PXML>, try to parse..
108 pxmlh = pnd_pxml_fetch_buffer ( (char*) fullpath, pxmlbuf );