Support multiple freeargs

This commit is contained in:
Jaidyn Ann 2020-07-04 12:53:08 -05:00
parent 11e7f34be2
commit 0099e88164
4 changed files with 60 additions and 31 deletions

View File

@ -6,4 +6,5 @@ Config::Config () {
daemon = true; daemon = true;
mimetype = BString("text/xml"); mimetype = BString("text/xml");
outDir = BString("/boot/home/feeds/"); outDir = BString("/boot/home/feeds/");
targetFeeds = NULL;
} }

View File

@ -10,7 +10,7 @@ public:
bool daemon; bool daemon;
BString mimetype; BString mimetype;
BString outDir; BString outDir;
BString targetFeed; // file or url BList targetFeeds; // file or url
Config ( ); Config ( );
}; };

View File

@ -9,6 +9,20 @@
Config* main_cfg; Config* main_cfg;
int
main ( int argc, char** argv )
{
main_cfg = new Config;
usageMsg.ReplaceAll("%app%", "Rifen");
invocation( argc, argv, &main_cfg );
main_cfg->targetFeeds.DoForEach(&processFeed);
return 0;
}
// ----------------------------------------------------------------------------
int int
usage () usage ()
{ {
@ -16,15 +30,6 @@ usage ()
return 2; return 2;
} }
bool
create_item ( void* item )
{
Item* itemPtr = (Item*)item;
itemPtr->Filetize( main_cfg, false );
return false;
}
int int
invocation ( int argc, char** argv, Config** cfgPtr ) invocation ( int argc, char** argv, Config** cfgPtr )
{ {
@ -45,8 +50,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
switch (c) { switch (c) {
case -1: case -1:
if ( optind < argc ) freeargInvocation( argc, argv, optind, cfgPtr );
cfg->targetFeed = BString(argv[optind]);
return 0; return 0;
case 'h': case 'h':
return usage(); return usage();
@ -70,24 +74,46 @@ invocation ( int argc, char** argv, Config** cfgPtr )
return 2; return 2;
} }
} }
return 0;
} }
// ―――――――――――――――――
int void
main ( int argc, char** argv ) freeargInvocation ( int argc, char** argv, int optind, Config** cfgPtr )
{ {
main_cfg = new Config; Config* cfg = *(cfgPtr);
usageMsg.ReplaceAll("%app%", "Rifen"); if ( optind < argc ) {
int freeargc = argc - optind;
cfg->targetFeeds = BList( freeargc );
invocation( argc, argv, &main_cfg ); for ( int i = 0; i < freeargc; i++ ) {
BString* newFeed = new BString( argv[optind + i] );
cfg->targetFeeds.AddItem( newFeed );
}
}
}
// ----------------------------------------------------------------------------
bool
processItem ( void* item )
{
Item* itemPtr = (Item*)item;
itemPtr->Filetize( main_cfg, false );
return false;
}
bool
processFeed ( void* feed )
{
BString* feedStr = (BString*)feed;
Channel* chan = (Channel*)malloc( sizeof(Channel) ); Channel* chan = (Channel*)malloc( sizeof(Channel) );
chan = new Channel(main_cfg->targetFeed, main_cfg->outDir); chan = new Channel(*(feedStr), main_cfg->outDir);
chan->Parse(main_cfg); chan->Parse(main_cfg);
BList items = chan->items; BList items = chan->items;
items.DoForEach(&create_item); items.DoForEach(&processItem);
return 0; free(chan);
return false;
} }

View File

@ -1,9 +1,11 @@
#include <StorageKit.h> #include <StorageKit.h>
int main ( int, char** ); int main ( int, char** );
int invocation ( int, char**, Config** );
int usage ( ); int usage ( );
bool create_item ( void* ); int invocation ( int, char**, Config** );
void freeargInvocation ( int, char**, int, Config** );
bool processItem ( void* );
bool processFeed ( void* );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------