SOLIB = libpnd.so.1 # canonicle name
SOLIB1 = libpnd.so.1.0.1 # versioned name
XMLOBJ = lib/tinyxml/tinystr.o lib/tinyxml/tinyxml.o lib/tinyxml/tinyxmlerror.o lib/tinyxml/tinyxmlparser.o
-ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_locate.o pnd_tinyxml.o pnd_pndfiles.o pnd_apps.o
+ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_locate.o pnd_tinyxml.o pnd_pndfiles.o pnd_apps.o pnd_utility.o
all: ${SOLIB} ${LIB} conftest discotest notifytest locatetest pndnotifyd
#include "../lib/pnd_pathiter.h"
#include "pnd_discovery.h"
#include "pnd_locate.h"
+#include "pnd_utility.h"
static unsigned char g_daemon_mode = 0;
if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
}
+ /* handle globbing or variable substitution
+ */
+ dotdesktoppath = pnd_expand_tilde ( strdup ( dotdesktoppath ) );
+
+ /* validate paths
+ */
+ mkdir ( dotdesktoppath, 0777 );
+
/* startup
*/
--- /dev/null
+
+#ifndef h_pnd_utility_h
+#define h_pnd_utility_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// given a malloc'd pointer to a string, expand ~ to $HOME as often as it is found, returning a
+// new string; the old string is destroyed in the process, or returned as-is.
+char *pnd_expand_tilde ( char *freeable_buffer );
+
+#ifdef __cplusplus
+} /* "C" */
+#endif
+
+#endif
--- /dev/null
+
+#include <stdio.h> /* for FILE etc */
+#include <stdlib.h> /* for malloc */
+#include <string.h> /* for making ftw.h happy */
+
+#include "pnd_utility.h"
+
+// a generalized variable-substitution routine might be nice; for now we need a quick tilde one,
+// so here goes. Brute force ftw!
+char *pnd_expand_tilde ( char *freeable_buffer ) {
+ char *p;
+ char *s = freeable_buffer;
+ char *home = getenv ( "HOME" );
+
+ if ( ! home ) {
+ return ( s ); // can't succeed
+ }
+
+ while ( ( p = strchr ( s, '~' ) ) ) {
+ char *temp = malloc ( strlen ( s ) + strlen ( home ) + 1 );
+ memset ( temp, '\0', strlen ( s ) + strlen ( home ) + 1 );
+ // copy in stuff prior to ~
+ strncpy ( temp, s, p - s );
+ // copy tilde in
+ strcat ( temp, home );
+ // copy stuff after tilde in
+ strcat ( temp, s + 1 );
+ // swap ptrs
+ free ( s );
+ s = temp;
+ } // while finding matches
+
+ return ( s );
+}
#include "pnd_pxml.h"
#include "pnd_discovery.h"
#include "pnd_locate.h"
+#include "pnd_utility.h"
int main ( int argc, char *argv[] ) {
char *configpath;
pnd_box_delete ( apph );
}
+ // extra testing - tilde-substitution
+ char *p = strdup ( "~/.applications" );
+ printf ( "Tilde substitution: in '%s'\n", p );
+ printf ( " out '%s'\n", pnd_expand_tilde ( p ) );
+
return ( 0 );
}
# Desktop configuration
[dotfiles]
-dotdesktoppath ./testdata/dotdesktop # path for pndnotifyd to spit .desktop files into
+#dotdesktoppath ./testdata/dotdesktop # path for pndnotifyd to spit .desktop files into
+dotdesktoppath ~/.applications # path for pndnotifyd to spit .desktop files into