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.
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

View File

@ -1,32 +1,25 @@
#include <cstdio>
#include <raptor2/raptor2.h>
#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);
}

View File

@ -1,3 +1,6 @@
#ifndef CHANNEL_H
#define CHANNEL_H
#include <DateTime.h>
#include <String.h>
#include <List.h>
@ -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

View File

@ -1,6 +1,8 @@
#include <raptor2/raptor2.h>
#include "Parse.h"
#include <StorageKit.h>
#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);

View File

@ -1,13 +1,14 @@
#include <raptor2/raptor2.h>
//#include "Channel.h"
#include "Parse.h"
#include "Channel.h"
#include "Item.h"
#include "parsing.h"
// predicate == sweet https version of tag (e.g. <http://purl.org/rss/1.0/modules/rss091#language> )
// 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

View File

@ -1,7 +1,9 @@
#ifndef PARSE_H
#define PARSE_H
#include <raptor2/raptor2.h>
#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