Move Parse to parsing

This commit is contained in:
Jaidyn Ann 2020-06-19 17:03:19 -05:00
parent ddb78008cc
commit 95d20c751c
6 changed files with 38 additions and 54 deletions

View File

@ -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. # Also note that spaces in folder names do not work well with this Makefile.
SRCS = \ SRCS = \
src/Channel.cpp, \ src/Channel.cpp, \
src/Item.cpp, \
src/Fetch.cpp, \ src/Fetch.cpp, \
src/Parse.cpp, \ src/parsing.cpp, \
src/Rifen.cpp src/Rifen.cpp
# Specify the resource definition files to use. Full or relative paths can be # Specify the resource definition files to use. Full or relative paths can be

View File

@ -1,32 +1,25 @@
#include <cstdio> #include <cstdio>
#include <raptor2/raptor2.h>
#include "Channel.h" #include "Channel.h"
#include "Item.h"
#include "parsing.h"
Channel::Channel ( int itemCount ) Channel::Channel ( BString path )
{ {
title = BString("Untitled Feed"); title = BString("Untitled Feed");
description = BString("Nondescript, N/A."); description = BString("Nondescript, N/A.");
homePage = BString(""); homePage = BString("");
xmlUrl = BString(""); xmlUrl = BString("");
items = BList(itemCount); filePath = path;
topLevelSubject = ""; topLevelSubject = "";
lastSubject = ""; lastSubject = "";
} }
// ============================================================================
Item::Item ( BString localSubject )
{
subject = localSubject;
title = BString("");
description = BString("");
homePage = BString("");
postUrl = BString("");
content = BString("");
}
void void
Item::Print () Channel::Parse ( )
{ {
// printf("%s\t%s\n%s\n\n", subject.String(), title.String(), content.String()); int itemCount = countFeedItems( filePath.String() );
printf("%s\t%s\n", subject.String(), title.String()); items = BList(itemCount);
Channel* chan = this;
processFeedItems(&chan);
} }

View File

@ -1,3 +1,6 @@
#ifndef CHANNEL_H
#define CHANNEL_H
#include <DateTime.h> #include <DateTime.h>
#include <String.h> #include <String.h>
#include <List.h> #include <List.h>
@ -18,23 +21,10 @@ public:
BString filePath; BString filePath;
Channel ( int ); Channel ( BString );
// Channel ( BEntry ); // Channel ( BEntry );
// Channel ( BUrl ); // Channel ( BUrl );
void Parse ( void ); void Parse ( void );
}; };
class Item { #endif
public:
BString title;
BString description;
BDate pubDate;
BString homePage;
BString postUrl;
BString content;
BString subject;
void Print ( void );
Item ( BString );
};

View File

@ -1,6 +1,8 @@
#include <raptor2/raptor2.h> #include <raptor2/raptor2.h>
#include "Parse.h"
#include <StorageKit.h> #include <StorageKit.h>
#include "Channel.h"
#include "Item.h"
#include "parsing.h"
bool bool
create_item ( void* item ) create_item ( void* item )
@ -27,7 +29,9 @@ create_item ( void* item )
int int
main ( int argc, char** argv ) 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; BList items = chan->items;
printf("%s\n", chan->title.String()); printf("%s\n", chan->title.String());
items.DoForEach(&create_item); items.DoForEach(&create_item);

View File

@ -1,13 +1,14 @@
#include <raptor2/raptor2.h> #include <raptor2/raptor2.h>
//#include "Channel.h" #include "Channel.h"
#include "Parse.h" #include "Item.h"
#include "parsing.h"
// predicate == sweet https version of tag (e.g. <http://purl.org/rss/1.0/modules/rss091#language> ) // predicate == sweet https version of tag (e.g. <http://purl.org/rss/1.0/modules/rss091#language> )
// subject == parent // subject == parent
// object == data // object == data
int int
countAllShit ( const char* filePath ) countFeedItems ( const char* filePath )
{ {
raptor_parser* rss_parser = NULL; raptor_parser* rss_parser = NULL;
raptor_world* world; raptor_world* world;
@ -36,9 +37,10 @@ countAllShit ( const char* filePath )
return *(itemCount); return *(itemCount);
} }
Channel* void
parseRssFile ( const char* filePath ) processFeedItems ( Channel** chanPtr )
{ {
Channel* chan = *(chanPtr);
raptor_parser* rss_parser = NULL; raptor_parser* rss_parser = NULL;
raptor_world* world; raptor_world* world;
world = raptor_new_world(); world = raptor_new_world();
@ -47,20 +49,10 @@ parseRssFile ( const char* filePath )
raptor_uri *uri, *base_uri; raptor_uri *uri, *base_uri;
rss_parser = raptor_new_parser(world, "rss-tag-soup"); 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 ); uri = raptor_new_uri( world, uri_string );
base_uri = raptor_uri_copy( uri ); 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_set_statement_handler( rss_parser, &chan, channelHandler );
raptor_parser_parse_file( rss_parser, uri, base_uri ); raptor_parser_parse_file( rss_parser, uri, base_uri );
@ -69,8 +61,6 @@ parseRssFile ( const char* filePath )
raptor_free_uri(uri); raptor_free_uri(uri);
raptor_free_memory(uri_string); raptor_free_memory(uri_string);
raptor_free_world( world ); raptor_free_world( world );
return chan;
} }
void void

View File

@ -1,7 +1,9 @@
#ifndef PARSE_H
#define PARSE_H
#include <raptor2/raptor2.h> #include <raptor2/raptor2.h>
#include "Channel.h" #include "Channel.h"
Channel* parseRssFile ( const char* );
void channelHandler ( void*, raptor_statement* ); void channelHandler ( void*, raptor_statement* );
void countItemHandler ( void*, raptor_statement* ); void countItemHandler ( void*, raptor_statement* );
@ -11,3 +13,7 @@ BString getPredicateTag ( BString );
void parseChannelStatement ( Channel**, BString, BString ); void parseChannelStatement ( Channel**, BString, BString );
void parseItemStatement ( Channel**, BString, BString, BString ); void parseItemStatement ( Channel**, BString, BString, BString );
int countFeedItems ( const char* );
void processFeedItems (Channel**);
#endif