VPATH = lib test apps
CFLAG_SO = -fPIC #-fPIC not always needed, but good to have
CFLAGS = -Wall -I./include -g ${CFLAG_SO}
+CXXFLAGS = -Wall -I./include -g ${CFLAG_SO}
# code
LIB = libpnd.a
- review pnd_tinyxml to ensure the PXML_FILENAME is csae insensitive as needed
+- make pnd_pndfiles seek of PXML more efficient; fread ( 1, nmemb ) gotta be slow :)
+
apps/pndnotifyd.c:// TODO: Catch HUP and reparse config
apps/pndnotifyd.c:// TODO: Should perhaps direct all printf's through a vsprintf handler to avoid redundant "if ! g_daemon_mode"
apps/pndnotifyd.c:// TODO: During daemon mode, should perhaps syslog or log errors
// fetch the full PXML and get all the details. But I think we got out of control here :)
typedef struct
{
- char *title_en;
- char *title_de;
- char *title_it;
- char *title_fr;
- char *unique_id;
- char *standalone;
- char *icon;
- char *description_en;
- char *description_de;
- char *description_it;
- char *description_fr;
- char *previewpic1;
- char *previewpic2;
- char *author_name;
- char *author_website;
- char *version_major;
- char *version_minor;
- char *version_release;
- char *version_build;
- char *exec;
- char *main_category;
- char *subcategory1;
- char *subcategory2;
- char *altcategory;
- char *altsubcategory1;
- char *altsubcategory2;
- char *osversion_major;
- char *osversion_minor;
- char *osversion_release;
- char *osversion_build;
- char *associationitem1_name;
- char *associationitem1_filetype;
- char *associationitem1_parameter;
- char *associationitem2_name;
- char *associationitem2_filetype;
- char *associationitem2_parameter;
- char *associationitem3_name;
- char *associationitem3_filetype;
- char *associationitem3_parameter;
- char *clockspeed;
- char *background;
- char *startdir;
-
+ char *title_en;
+ char *unique_id;
+ char *icon;
+ char *exec;
+ char *main_category;
+ char *clockspeed;
} pnd_disco_t;
void pnd_disco_destroy ( pnd_disco_t *p ); // a function name that simply could not be avoided
extern "C" {
#endif
+// the filename of PND files must end with a well defined (case insensitive!) extension
#define PND_PACKAGE_FILEEXT ".pnd" /* case insensitive due to SD FAT fs */
+// when seeking the PXML appended (or embedded within if they forgot to append it)
+// to a PND file, this buffer size will be used in the seek. It'll actually under-seek
+// a bit, so in the odd chance the "<PXML>" tag borders right on the window size, we'll
+// still find it.
+// Being SD reads, it might be nice to pick a decent size .. SD is constant read regardless
+// of read size for certain sizes, but of course strstr() within a giant buffer is no good
+// either if the goods are near the end. How big is an average .png for an average icon
+// size?
+#define PND_PXML_WINDOW_SIZE 4096
+
+// pnd_seek_pxml should vaguely work like fseek, trying to position at begin of the appended/found PXML
+// On return of 0, assuming nothing.
+// On 1, assume that the FILE pointer is positioned for next read to pull in the PXML line by line
+unsigned char pnd_pnd_seek_pxml ( FILE *f );
+
#ifdef __cplusplus
} /* "C" */
#endif
// this code is for very basic PXML.xml file parsing
#define PXML_FILENAME "PXML.xml" /* a specification defined name */
+#define PXML_TAGHEAD "<PXML>" /* case insensitive */
+#define PXML_TAGFOOT "</PXML>" /* case insensitive */
// use this handle to interact with PXML; this hides the mechanics of parsing a PXML file so that
// it can be upgraded with impacting applications
/* pxml_fetch() will return NULL on fail, otherwise a valid handle which may be further queried
*/
pnd_pxml_handle pnd_pxml_fetch ( char *fullpath );
+pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer );
void pnd_pxml_delete ( pnd_pxml_handle h );
/* overrides() allow for customization of a PXML that persists; ie: An application might be sitting
--- /dev/null
+
+#ifndef h_pnd_tinyxml_h
+#define h_pnd_tinyxml_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app );
+unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
} else if ( valid == 2 ) {
// PND ... ??
+ printf ( "PND: disco callback encountered '%s'\n", fpath );
+
+ // is this a valid .pnd file? The filename is a candidate already, but verify..
+ // .. presence of PXML appeneded, or at least contained within?
+ // .. presence of an icon appended after PXML?
+
}
return ( 0 ); // continue the tree walk
fprintf ( f, "%s", buffer );
}
+#if 0
if ( p -> description_en ) {
snprintf ( buffer, 1020, "Comment=%s\n", p -> description_en );
fprintf ( f, "%s", buffer );
}
+#endif
+#if 0
if ( p -> startdir ) {
snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
fprintf ( f, "%s", buffer );
} else {
fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
}
+#endif
if ( p -> exec ) {
snprintf ( buffer, 1020, "Exec=%s\n", p -> exec );
#include "pnd_pxml.h"
#include "pnd_apps.h"
#include "pnd_pndfiles.h"
+
+unsigned char pnd_pnd_seek_pxml ( FILE *f ) {
+ char *b;
+ unsigned int len;
+
+ b = malloc ( PND_PXML_WINDOW_SIZE );
+
+ if ( ! b ) {
+ return ( 0 );
+ }
+
+ memset ( b, '\0', PND_PXML_WINDOW_SIZE );
+
+ // determine length of file
+ fseek ( f, 0, SEEK_END );
+
+ len = ftell ( f );
+
+ fseek ( f, 0, SEEK_SET );
+
+ /* ready to scan through the file, backwards
+ */
+
+ //strcasestr ( b, PXML_TAGHEAD );
+
+
+
+ // exeunt, with alarums
+
+ free ( b );
+
+ return ( 1 );
+}
#include "pnd_pxml.h"
#include "pnd_pathiter.h"
-
-void pnd_pxml_load(const char* pFilename, pnd_pxml_t *app);
+#include "pnd_tinyxml.h"
pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) {
memset ( p, '\0', sizeof(pnd_pxml_t) );
- pnd_pxml_load ( fullpath, p );
+ if ( ! pnd_pxml_load ( fullpath, p ) ) {
+ return ( 0 );
+ }
+
+ return ( p );
+}
+
+pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ) {
+
+ pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) );
+
+ memset ( p, '\0', sizeof(pnd_pxml_t) );
+
+ if ( ! pnd_pxml_parse ( filename, buffer, strlen ( buffer ), p ) ) {
+ return ( 0 );
+ }
return ( p );
}
+
#include "tinyxml/tinyxml.h"
#include "../include/pnd_pxml.h"
+#include "pnd_tinyxml.h"
extern "C" {
-void pnd_pxml_load(const char* pFilename, pnd_pxml_t *app)
-{
+unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) {
+ FILE *f;
+ char *b;
+ unsigned int len;
+
+ f = fopen ( pFilename, "r" );
+
+ if ( ! f ) {
+ return ( 0 );
+ }
+
+ fseek ( f, 0, SEEK_END );
+
+ len = ftell ( f );
+
+ fseek ( f, 0, SEEK_SET );
+
+ b = (char*) malloc ( len );
+
+ if ( ! b ) {
+ fclose ( f );
+ return ( 0 );
+ }
- TiXmlDocument doc(pFilename);
- if (!doc.LoadFile()) return;
+ fread ( b, 1, len, f );
+
+ return ( pnd_pxml_parse ( pFilename, b, len, app ) );
+}
+
+unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ) {
+
+ //TiXmlDocument doc(pFilename);
+ //if (!doc.LoadFile()) return;
+
+ TiXmlDocument doc;
+
+ doc.Parse ( buffer );
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlHandle hRoot(0);
pElem=hDoc.FirstChildElement().Element();
- if (!pElem) return;
+ if (!pElem) return ( 0 );
hRoot=TiXmlHandle(pElem);
pElem = hRoot.FirstChild( "title" ).FirstChildElement("en").Element();
{
app->startdir = strdup(pElem->GetText());
}
-}
+ return ( 1 );
}
+} // extern C