From 340607a064e91f943f54e48e9e72d6f2b958d720 Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 15 Feb 2010 09:54:55 -0500 Subject: [PATCH] Added pnd_info.c since I'm an idiot --- apps/pnd_info.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 apps/pnd_info.c diff --git a/apps/pnd_info.c b/apps/pnd_info.c new file mode 100644 index 0000000..a2acb4b --- /dev/null +++ b/apps/pnd_info.c @@ -0,0 +1,113 @@ + +#include /* for printf, NULL */ +#include /* for free */ +#include /* for strdup */ + +#include "pnd_conf.h" +#include "pnd_container.h" +#include "pnd_apps.h" +#include "pnd_discovery.h" +#include "pnd_locate.h" +#include "pnd_pndfiles.h" +#include "pnd_pxml.h" + +static void usage ( char *argv[] ) { + printf ( "%s\tObtain a description, install guide or other info about a pnd-file\n", argv [ 0 ] ); + printf ( "\n" ); + printf ( "%s path-to-pndfile [section] [section-2...]\n", argv [ 0 ] ); + printf ( "\n" ); + printf ( "section\tOptional. If not specified, general description is shown. (Section 'description')\n" ); + printf ( "\tIf present, show the named section of the PXML -- such as to obtain install instructions etc.\n" ); + printf ( "pndfile\tRequired. Full path to the pnd-file to execute.\n" ); + return; +} + +#define SECTIONMAX 100 + +int main ( int argc, char *argv[] ) { + char *pndfile = NULL; + char *section [ SECTIONMAX ]; + unsigned char sections = 0; + int i; + + for ( i = 1; i < argc; i++ ) { + + if ( ! pndfile ) { + pndfile = argv [ i ]; + continue; + } + + section [ sections++ ] = argv [ i ]; + + if ( sections == SECTIONMAX ) { + break; + } + + } // for args + + if ( ! pndfile ) { + usage ( argv ); + exit ( 0 ); + } + + if ( ! sections ) { + section [ sections++ ] = "description"; + } + + // summary + printf ( "Pndfile\t%s\n", pndfile ); + printf ( "Sections to include:\n" ); + for ( i = 0; i < sections; i++ ) { + printf ( "- %s\n", section [ i ] ); + } // for + printf ( "\n" ); + + // pull PXML + unsigned int pxmlbuflen = 96 * 1024; // lame, need to calculate it + char *pxmlbuf = malloc ( pxmlbuflen ); + if ( ! pxmlbuf ) { + printf ( "ERROR: RAM exhausted!\n" ); + exit ( 0 ); + } + memset ( pxmlbuf, '\0', pxmlbuflen ); + + FILE *f = fopen ( pndfile, "r" ); + if ( ! f ) { + printf ( "ERROR: Couldn't open pndfile %s!\n", pndfile ); + exit ( 0 ); + } + + pnd_pxml_handle h = NULL; + if ( pnd_pnd_seek_pxml ( f ) ) { + if ( pnd_pnd_accrue_pxml ( f, pxmlbuf, pxmlbuflen ) ) { + h = pnd_pxml_fetch_buffer ( "pnd_run", pxmlbuf ); + } + } + + fclose ( f ); + + if ( ! h ) { + printf ( "ERROR: Couldn't pull PXML.xml from the pndfile.\n" ); + exit ( 0 ); + } + + // display sections + for ( i = 0; i < sections; i++ ) { + char *t; + + if ( strcasecmp ( section [ i ], "description" ) == 0 ) { + + printf ( "Section: %s\n", section [ i ] ); + + if ( ( t = pnd_pxml_get_description_en ( h ) ) ) { + printf ( "%s\n", t ); + } else { + printf ( "Not supplied by PXML.xml in the pnd-file\n" ); + } + + } + + } // for + + return ( 0 ); +} // main -- 2.39.2