Support multiple freeargs
This commit is contained in:
parent
11e7f34be2
commit
0099e88164
|
@ -6,4 +6,5 @@ Config::Config () {
|
|||
daemon = true;
|
||||
mimetype = BString("text/xml");
|
||||
outDir = BString("/boot/home/feeds/");
|
||||
targetFeeds = NULL;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public:
|
|||
bool daemon;
|
||||
BString mimetype;
|
||||
BString outDir;
|
||||
BString targetFeed; // file or url
|
||||
BList targetFeeds; // file or url
|
||||
|
||||
Config ( );
|
||||
};
|
||||
|
|
|
@ -9,6 +9,20 @@
|
|||
|
||||
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
|
||||
usage ()
|
||||
{
|
||||
|
@ -16,15 +30,6 @@ usage ()
|
|||
return 2;
|
||||
}
|
||||
|
||||
bool
|
||||
create_item ( void* item )
|
||||
{
|
||||
Item* itemPtr = (Item*)item;
|
||||
itemPtr->Filetize( main_cfg, false );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
invocation ( int argc, char** argv, Config** cfgPtr )
|
||||
{
|
||||
|
@ -45,8 +50,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
|||
|
||||
switch (c) {
|
||||
case -1:
|
||||
if ( optind < argc )
|
||||
cfg->targetFeed = BString(argv[optind]);
|
||||
freeargInvocation( argc, argv, optind, cfgPtr );
|
||||
return 0;
|
||||
case 'h':
|
||||
return usage();
|
||||
|
@ -70,24 +74,46 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
|||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main ( int argc, char** argv )
|
||||
// ―――――――――――――――――
|
||||
|
||||
void
|
||||
freeargInvocation ( int argc, char** argv, int optind, Config** cfgPtr )
|
||||
{
|
||||
main_cfg = new Config;
|
||||
usageMsg.ReplaceAll("%app%", "Rifen");
|
||||
Config* cfg = *(cfgPtr);
|
||||
if ( optind < argc ) {
|
||||
int freeargc = argc - optind;
|
||||
cfg->targetFeeds = BList( freeargc );
|
||||
|
||||
invocation( argc, argv, &main_cfg );
|
||||
|
||||
Channel* chan = (Channel*)malloc( sizeof(Channel) );
|
||||
chan = new Channel(main_cfg->targetFeed, main_cfg->outDir);
|
||||
chan->Parse(main_cfg);
|
||||
|
||||
BList items = chan->items;
|
||||
items.DoForEach(&create_item);
|
||||
return 0;
|
||||
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) );
|
||||
chan = new Channel(*(feedStr), main_cfg->outDir);
|
||||
chan->Parse(main_cfg);
|
||||
BList items = chan->items;
|
||||
items.DoForEach(&processItem);
|
||||
free(chan);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <StorageKit.h>
|
||||
|
||||
int main ( int, char** );
|
||||
int invocation ( int, char**, Config** );
|
||||
int main ( int, char** );
|
||||
int usage ( );
|
||||
bool create_item ( void* );
|
||||
int invocation ( int, char**, Config** );
|
||||
void freeargInvocation ( int, char**, int, Config** );
|
||||
bool processItem ( void* );
|
||||
bool processFeed ( void* );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue