summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-05 15:45:03 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-05 15:45:03 +0000
commitd80d7faac9bec9719378c19c06c8f6ebf7a9921f (patch)
tree5e8fe842200cfdc9213883a51a47fedb6117d49f /src
parente52e0fa01f6ab8fc0f3a8c7574be8468948b3bd0 (diff)
2007-07-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Reads URIs from stdin when "-i -" is specified. * src/UriFileListParser.h, src/UriFileListParser.cc: Removed. * src/UriListParser.h, src/UriListParser.cc: New class. * src/StreamUriListParser.h: New class. * src/FileUriListParser.h: New class. * src/main.cc (main): Use StreamUriListParser and FileUriListParser instead of UriFileListParser.
Diffstat (limited to 'src')
-rw-r--r--src/FileUriListParser.h63
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in8
-rw-r--r--src/StreamUriListParser.h59
-rw-r--r--src/UriListParser.cc (renamed from src/UriFileListParser.cc)10
-rw-r--r--src/UriListParser.h (renamed from src/UriFileListParser.h)32
-rw-r--r--src/main.cc9
7 files changed, 148 insertions, 35 deletions
diff --git a/src/FileUriListParser.h b/src/FileUriListParser.h
new file mode 100644
index 00000000..a69c71cf
--- /dev/null
+++ b/src/FileUriListParser.h
@@ -0,0 +1,63 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_FILE_URI_LIST_PARSER_H_
+#define _D_FILE_URI_LIST_PARSER_H_
+
+#include "UriListParser.h"
+#include <fstream>
+
+class FileUriListParser : public UriListParser {
+private:
+ string _filename;
+ ifstream _ifs;
+
+protected:
+ virtual istream& getInputStream()
+ {
+ return _ifs;
+ }
+
+ virtual const istream& getInputStream() const
+ {
+ return _ifs;
+ }
+
+public:
+ FileUriListParser(const string& filename):_filename(filename), _ifs(filename.c_str()) {}
+
+ virtual ~FileUriListParser() {}
+};
+
+#endif // _D_FILE_URI_LIST_PARSER_H_
diff --git a/src/Makefile.am b/src/Makefile.am
index f59bdd0b..77246d84 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,7 +87,7 @@ SRCS = Socket.h\
FileAllocationDispatcherCommand.cc FileAllocationDispatcherCommand.h\
FileAllocationEntry.cc FileAllocationEntry.h\
MultiUrlRequestInfo.cc MultiUrlRequestInfo.h\
- UriFileListParser.cc UriFileListParser.h\
+ UriListParser.cc UriListParser.h\
SegmentManFactory.h\
AbstractSegmentManFactory.h\
DefaultSegmentManFactory.cc DefaultSegmentManFactory.h\
diff --git a/src/Makefile.in b/src/Makefile.in
index d3a4e06f..4775683b 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -236,7 +236,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \
FileAllocationDispatcherCommand.h FileAllocationEntry.cc \
FileAllocationEntry.h MultiUrlRequestInfo.cc \
- MultiUrlRequestInfo.h UriFileListParser.cc UriFileListParser.h \
+ MultiUrlRequestInfo.h UriListParser.cc UriListParser.h \
SegmentManFactory.h AbstractSegmentManFactory.h \
DefaultSegmentManFactory.cc DefaultSegmentManFactory.h \
RealtimeCommand.cc RealtimeCommand.h ProgressAwareEntry.h \
@@ -432,7 +432,7 @@ am__objects_4 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
FillRequestGroupCommand.$(OBJEXT) \
FileAllocationDispatcherCommand.$(OBJEXT) \
FileAllocationEntry.$(OBJEXT) MultiUrlRequestInfo.$(OBJEXT) \
- UriFileListParser.$(OBJEXT) DefaultSegmentManFactory.$(OBJEXT) \
+ UriListParser.$(OBJEXT) DefaultSegmentManFactory.$(OBJEXT) \
RealtimeCommand.$(OBJEXT) RequestGroupEntry.$(OBJEXT) \
Cookie.$(OBJEXT) CookieParser.$(OBJEXT) \
CookieBoxFactory.$(OBJEXT) HttpHeaderProcessor.$(OBJEXT) \
@@ -661,7 +661,7 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \
FileAllocationDispatcherCommand.h FileAllocationEntry.cc \
FileAllocationEntry.h MultiUrlRequestInfo.cc \
- MultiUrlRequestInfo.h UriFileListParser.cc UriFileListParser.h \
+ MultiUrlRequestInfo.h UriListParser.cc UriListParser.h \
SegmentManFactory.h AbstractSegmentManFactory.h \
DefaultSegmentManFactory.cc DefaultSegmentManFactory.h \
RealtimeCommand.cc RealtimeCommand.h ProgressAwareEntry.h \
@@ -906,7 +906,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerSegmentManFactory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerUpdateCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerWatcherCommand.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UriFileListParser.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UriListParser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Xml2MetalinkProcessor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
diff --git a/src/StreamUriListParser.h b/src/StreamUriListParser.h
new file mode 100644
index 00000000..f169f445
--- /dev/null
+++ b/src/StreamUriListParser.h
@@ -0,0 +1,59 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_STREAM_URI_LIST_PARSER_H_
+#define _D_STREAM_URI_LIST_PARSER_H_
+
+#include "UriListParser.h"
+
+class StreamUriListParser : public UriListParser {
+private:
+ istream* _ifs;
+protected:
+ virtual istream& getInputStream()
+ {
+ return *_ifs;
+ }
+
+ virtual const istream& getInputStream() const
+ {
+ return *_ifs;
+ }
+public:
+ StreamUriListParser(istream& ifs):_ifs(&ifs) {}
+
+ virtual ~StreamUriListParser() {}
+};
+
+#endif // _D_STREAM_URI_LIST_PARSER_H_
diff --git a/src/UriFileListParser.cc b/src/UriListParser.cc
index bed46448..b5a06ebb 100644
--- a/src/UriFileListParser.cc
+++ b/src/UriListParser.cc
@@ -32,18 +32,18 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
-#include "UriFileListParser.h"
+#include "UriListParser.h"
#include "Util.h"
-bool UriFileListParser::hasNext() const
+bool UriListParser::hasNext() const
{
- return *_ifs;
+ return getInputStream();
}
-Strings UriFileListParser::next()
+Strings UriListParser::next()
{
string line;
- while(getline(*_ifs, line)) {
+ while(getline(getInputStream(), line)) {
if(Util::trim(line) != "") {
Strings uris;
Util::slice(uris, line, '\t', true);
diff --git a/src/UriFileListParser.h b/src/UriListParser.h
index 83f720d2..5356c728 100644
--- a/src/UriFileListParser.h
+++ b/src/UriListParser.h
@@ -32,35 +32,25 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
-#ifndef _D_URI_FILE_LIST_PARSER_H_
-#define _D_URI_FILE_LIST_PARSER_H_
+#ifndef _D_URI_LIST_PARSER_H_
+#define _D_URI_LIST_PARSER_H_
#include "common.h"
-#include <fstream>
+#include <istream>
-class UriFileListParser {
-private:
- string _filename;
- istream* _ifs;
- bool _deleteOnExit;
-public:
- UriFileListParser(const string& filename):_filename(filename), _ifs(new ifstream(filename.c_str())), _deleteOnExit(true) {}
-
- UriFileListParser():_ifs(0) {}
+class UriListParser {
+protected:
+ virtual istream& getInputStream() = 0;
+ virtual const istream& getInputStream() const = 0;
- UriFileListParser(istream& ifs):_filename("-"), _ifs(&ifs), _deleteOnExit(false)
- {}
+public:
+ UriListParser() {}
- ~UriFileListParser()
- {
- if(_deleteOnExit) {
- delete _ifs;
- }
- }
+ virtual ~UriListParser() {}
bool hasNext() const;
Strings next();
};
-#endif // _D_URI_FILE_LIST_PARSER_H_
+#endif // _D_URI_LIST_PARSER_H_
diff --git a/src/main.cc b/src/main.cc
index 209c149b..933c6be9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -49,7 +49,8 @@
#include "FatalException.h"
#include "File.h"
#include "CUIDCounter.h"
-#include "UriFileListParser.h"
+#include "FileUriListParser.h"
+#include "StreamUriListParser.h"
#include "CookieBoxFactory.h"
#include "a2algo.h"
#include "message.h"
@@ -755,14 +756,14 @@ int main(int argc, char* argv[]) {
else
#endif // ENABLE_METALINK
if(op->defined(PREF_INPUT_FILE)) {
- SharedHandle<UriFileListParser> flparser(0);
+ SharedHandle<UriListParser> flparser(0);
if(op->get(PREF_INPUT_FILE) == "-") {
- flparser = new UriFileListParser(cin);
+ flparser = new StreamUriListParser(cin);
} else {
if(!File(op->get(PREF_INPUT_FILE)).isFile()) {
throw new FatalException(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(), "No such file");
}
- flparser = new UriFileListParser(op->get(PREF_INPUT_FILE));
+ flparser = new FileUriListParser(op->get(PREF_INPUT_FILE));
}
RequestGroups groups;
while(flparser->hasNext()) {