diff --git a/Makefile b/Makefile index ec94eef..5c180d1 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,9 @@ APP_MIME_SIG = application/x-vnd.Rifen # Also note that spaces in folder names do not work well with this Makefile. SRCS = \ src/Channel.cpp, \ + src/Item.cpp, \ src/Fetch.cpp, \ - src/Parse.cpp, \ + src/parsing.cpp, \ src/Rifen.cpp # Specify the resource definition files to use. Full or relative paths can be diff --git a/src/Channel.cpp b/src/Channel.cpp index 530796e..d386a79 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -1,32 +1,25 @@ #include +#include #include "Channel.h" +#include "Item.h" +#include "parsing.h" -Channel::Channel ( int itemCount ) +Channel::Channel ( BString path ) { title = BString("Untitled Feed"); description = BString("Nondescript, N/A."); homePage = BString(""); xmlUrl = BString(""); - items = BList(itemCount); + filePath = path; topLevelSubject = ""; lastSubject = ""; } -// ============================================================================ - -Item::Item ( BString localSubject ) -{ - subject = localSubject; - title = BString(""); - description = BString(""); - homePage = BString(""); - postUrl = BString(""); - content = BString(""); -} - void -Item::Print () +Channel::Parse ( ) { -// printf("%s\t%s\n%s\n\n", subject.String(), title.String(), content.String()); - printf("%s\t%s\n", subject.String(), title.String()); + int itemCount = countFeedItems( filePath.String() ); + items = BList(itemCount); + Channel* chan = this; + processFeedItems(&chan); } diff --git a/src/Channel.h b/src/Channel.h index 600cf0e..1568aaa 100644 --- a/src/Channel.h +++ b/src/Channel.h @@ -1,3 +1,6 @@ +#ifndef CHANNEL_H +#define CHANNEL_H + #include #include #include @@ -18,23 +21,10 @@ public: BString filePath; - Channel ( int ); + Channel ( BString ); // Channel ( BEntry ); // Channel ( BUrl ); void Parse ( void ); }; -class Item { -public: - BString title; - BString description; - BDate pubDate; - BString homePage; - BString postUrl; - BString content; - - BString subject; - - void Print ( void ); - Item ( BString ); -}; +#endif diff --git a/src/Rifen.cpp b/src/Rifen.cpp index 0a76ceb..762183c 100644 --- a/src/Rifen.cpp +++ b/src/Rifen.cpp @@ -1,6 +1,8 @@ #include -#include "Parse.h" #include +#include "Channel.h" +#include "Item.h" +#include "parsing.h" bool create_item ( void* item ) @@ -27,7 +29,9 @@ create_item ( void* item ) int main ( int argc, char** argv ) { - Channel* chan = parseRssFile( argv[1] ); + Channel* chan = (Channel*)malloc( sizeof(Channel) ); + chan = new Channel(argv[1]); + chan->Parse(); BList items = chan->items; printf("%s\n", chan->title.String()); items.DoForEach(&create_item); diff --git a/src/Parse.cpp b/src/parsing.cpp similarity index 87% rename from src/Parse.cpp rename to src/parsing.cpp index c20703d..5bd9d44 100644 --- a/src/Parse.cpp +++ b/src/parsing.cpp @@ -1,13 +1,14 @@ #include -//#include "Channel.h" -#include "Parse.h" +#include "Channel.h" +#include "Item.h" +#include "parsing.h" // predicate == sweet https version of tag (e.g. ) // subject == parent // object == data int -countAllShit ( const char* filePath ) +countFeedItems ( const char* filePath ) { raptor_parser* rss_parser = NULL; raptor_world* world; @@ -36,9 +37,10 @@ countAllShit ( const char* filePath ) return *(itemCount); } -Channel* -parseRssFile ( const char* filePath ) +void +processFeedItems ( Channel** chanPtr ) { + Channel* chan = *(chanPtr); raptor_parser* rss_parser = NULL; raptor_world* world; world = raptor_new_world(); @@ -47,20 +49,10 @@ parseRssFile ( const char* filePath ) raptor_uri *uri, *base_uri; rss_parser = raptor_new_parser(world, "rss-tag-soup"); - uri_string = raptor_uri_filename_to_uri_string( filePath ); + uri_string = raptor_uri_filename_to_uri_string( chan->filePath.String() ); uri = raptor_new_uri( world, uri_string ); base_uri = raptor_uri_copy( uri ); - int itemCount = countAllShit( filePath ); - -// int* itemCount = (int*)malloc( sizeof(int) ); -// *itemCount = 0; -// raptor_parser_set_statement_handler( rss_parser, &itemCount, countItemHandler ); -// raptor_parser_parse_file( rss_parser, uri, base_uri ); - - Channel* chan = (Channel*)malloc( sizeof(Channel) ); - chan = new Channel(itemCount); - raptor_parser_set_statement_handler( rss_parser, &chan, channelHandler ); raptor_parser_parse_file( rss_parser, uri, base_uri ); @@ -69,8 +61,6 @@ parseRssFile ( const char* filePath ) raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world( world ); - - return chan; } void diff --git a/src/Parse.h b/src/parsing.h similarity index 78% rename from src/Parse.h rename to src/parsing.h index 4037c27..ae9db58 100644 --- a/src/Parse.h +++ b/src/parsing.h @@ -1,7 +1,9 @@ +#ifndef PARSE_H +#define PARSE_H + #include #include "Channel.h" -Channel* parseRssFile ( const char* ); void channelHandler ( void*, raptor_statement* ); void countItemHandler ( void*, raptor_statement* ); @@ -11,3 +13,7 @@ BString getPredicateTag ( BString ); void parseChannelStatement ( Channel**, BString, BString ); void parseItemStatement ( Channel**, BString, BString, BString ); +int countFeedItems ( const char* ); +void processFeedItems (Channel**); + +#endif