]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2002-05-05 Robert Collins <rbtcollins@hotmail.com>
authorRobert Collins <rbtcollins@hotmail.com>
Sun, 5 May 2002 04:02:01 +0000 (04:02 +0000)
committerRobert Collins <rbtcollins@hotmail.com>
Sun, 5 May 2002 04:02:01 +0000 (04:02 +0000)
        * Makefile.am (noinst_PROGRAMS): Make inilint configurable.
        * configure.in: Ditto.
        Fix incorrect header checking syntax.
        * aclocal.m4: Regenerate.
        * configure: Regenerate.
        * Makefile.in: Regenerate.
        * io_stream.cc: Remove platform specific and provider specific code.
        (io_stream::registerProvider): New method, registers a Url provider with
        the io_stream code.
        Make all methods consistently throw invalid_argument exceptions when
        a provider that is requested is not present.
        (findProvider): New private function, finds a provider.
        * io_stream.h: Declare io_stream::registerProvider.
        * io_stream_cygfile.cc: Create a Provider class to register with
        io_stream.cc.
        * io_stream_file.cc: Ditto.
        * archive.cc: Remove unneeded includes.
        * archive_tar.cc: Remove unneeded includes.
        * archive_tar.h: Add required include.
        * archive_tar_file.cc: Remove unneded includes.
        * choose.cc: Remove unneeded includes:

16 files changed:
ChangeLog
IOStreamProvider.h [new file with mode: 0644]
Makefile.am
Makefile.in
archive.cc
archive_tar.cc
archive_tar.h
archive_tar_file.cc
choose.cc
configure
configure.ac
configure.in
io_stream.cc
io_stream.h
io_stream_cygfile.cc
io_stream_file.cc

index 821151b179b4c10d448cbb9708db695e0753a7e8..49b26d7b331c5689356e66fd42000c01da1ab01f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2002-05-05 Robert Collins  <rbtcollins@hotmail.com>
+
+       * Makefile.am (noinst_PROGRAMS): Make inilint configurable.
+       * configure.in: Ditto.
+       Fix incorrect header checking syntax.
+       * aclocal.m4: Regenerate.
+       * configure: Regenerate.
+       * Makefile.in: Regenerate.
+       * io_stream.cc: Remove platform specific and provider specific code.
+       (io_stream::registerProvider): New method, registers a Url provider with
+       the io_stream code.
+       Make all methods consistently throw invalid_argument exceptions when
+       a provider that is requested is not present.
+       (findProvider): New private function, finds a provider.
+       * io_stream.h: Declare io_stream::registerProvider.
+       * io_stream_cygfile.cc: Create a Provider class to register with
+       io_stream.cc.
+       * io_stream_file.cc: Ditto.
+       * archive.cc: Remove unneeded includes.
+       * archive_tar.cc: Remove unneeded includes.
+       * archive_tar.h: Add required include.
+       * archive_tar_file.cc: Remove unneded includes.
+       * choose.cc: Remove unneeded includes:
+
 2002-05-04 Robert Collins  <rbtcollins@hotmail.com>
 
        * io_stream.cc: Use the new log interface thruout.
diff --git a/IOStreamProvider.h b/IOStreamProvider.h
new file mode 100644 (file)
index 0000000..d18b9e7
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002, Robert Collins.
+ *
+ *     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.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by Robert Collins  <rbtcollins@hotmail.com>
+ *
+ */
+
+#ifndef _IOSTREAMPROVIDER_H_
+#define _IOSTREAMPROVIDER_H_
+
+#include "io_stream.h"
+#include "String++.h"
+
+/* An IOStreamProvider provides the interface for io_stream::open and 
+ * related calls to operate.
+ */
+
+class IOStreamProvider
+{
+public:
+  virtual int exists (String const &) const = 0;
+  virtual int remove (String const &) const = 0;
+  virtual int mklink (String const &, String const &, io_stream_link_t) const = 0;
+  virtual io_stream *open (String const &,String const &) const = 0;
+  virtual ~IOStreamProvider (){}
+  virtual int move (String const &,String const &) const = 0;
+  virtual int mkdir_p (enum path_type_t isadir, String const &path) const = 0;
+  String key; // Do not set - managed automatically.
+protected:
+  IOStreamProvider(){} // no base instances
+  IOStreamProvider(IOStreamProvider const &); // no copy cons
+  IOStreamProvider &operator=(IOStreamProvider const &); // no assignment
+};
+
+#endif /* _IOSTREAMPROVIDER_H_ */
index 2ddb87143f107bce2c0164eff9e1631ba631cc64..703efb458db0bf9d8aee2da7ae592046cc263178 100644 (file)
@@ -33,10 +33,11 @@ WINDRES             := @WINDRES@
 INCLUDES       = -I$(srcdir)/bz2lib -I$(srcdir)/libgetopt++/include
 
 noinst_PROGRAMS = \
-  setup
+  setup \
+  @INILINT@
 
 EXTRA_PROGRAMS = inilint
-##noinst_PROGRAMS +=inilint
+## noinst_PROGRAMS +=inilint
 
 # to avoid false errors that assembly generates
 WARNONLY_CFLAGS        = -Winline -Wall -Wpointer-arith -Wcast-align \
@@ -71,6 +72,7 @@ inilint_SOURCES = \
   iniparse.h \
   io_stream.h \
   io_stream.cc \
+  IOStreamProvider.h \
   PackageTrust.h \
   rfc1738.cc \
   rfc1738.h \
@@ -141,6 +143,7 @@ setup_SOURCES = \
        io_stream_file.h \
        io_stream_memory.cc \
        io_stream_memory.h \
+       IOStreamProvider.h \
        list.h \
        localdir.cc \
        localdir.h \
index 326716ad25aa2700bbd512c457cec61b07eb162c..20b93e0b36f1e97494a4b5f611e58e4c25632239 100644 (file)
@@ -94,6 +94,7 @@ DLLTOOL = @DLLTOOL@
 ECHO = @ECHO@
 GCJ = @GCJ@
 GCJFLAGS = @GCJFLAGS@
+INILINT = @INILINT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LEX = @LEX@
 LEXLIB = @LEXLIB@
@@ -126,7 +127,8 @@ AM_CXXFLAGS = $(AM_CFLAGS)
 INCLUDES = -I$(srcdir)/bz2lib -I$(srcdir)/libgetopt++/include
 
 noinst_PROGRAMS = \
-  setup
+  setup \
+  @INILINT@
 
 
 EXTRA_PROGRAMS = inilint
@@ -167,6 +169,7 @@ inilint_SOURCES = \
   iniparse.h \
   io_stream.h \
   io_stream.cc \
+  IOStreamProvider.h \
   PackageTrust.h \
   rfc1738.cc \
   rfc1738.h \
@@ -239,6 +242,7 @@ setup_SOURCES = \
        io_stream_file.h \
        io_stream_memory.cc \
        io_stream_memory.h \
+       IOStreamProvider.h \
        list.h \
        localdir.cc \
        localdir.h \
@@ -331,7 +335,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/cfgaux/mkinstalldirs
 CONFIG_CLEAN_FILES =
 EXTRA_PROGRAMS = inilint$(EXEEXT)
-noinst_PROGRAMS = setup$(EXEEXT)
+noinst_PROGRAMS = setup$(EXEEXT) @INILINT@
 PROGRAMS = $(noinst_PROGRAMS)
 
 am_inilint_OBJECTS = filemanip.$(OBJEXT) LogSingleton.$(OBJEXT) \
index b63276c47917442fab46465fe894ee66b38c4ef9..682c1b2f0d6054bfb6d038eb904d11578a469f2e 100644 (file)
@@ -21,11 +21,11 @@ static const char *cvsid =
   "\n%%% $Id$\n";
 #endif
 
-#include "win32.h"
-#include <stdio.h>
-#include <stdlib.h>
+//#include "win32.h"
+//#include <stdio.h>
+//#include <stdlib.h>
 #include "LogSingleton.h"
-#include "port.h"
+//#include "port.h"
 #include "String++.h"
 
 #include "io_stream.h"
index ad7c1f6e304eb8f52c3fa0aca74941423b4671bf..66ea3859d4591628370dda3a1bab093d68cbb9d0 100644 (file)
@@ -20,7 +20,6 @@ static const char *cvsid =
   "\n%%% $Id$\n";
 #endif
 
-#include "win32.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
index bf03ae1e2049cba1b63fd7b36992ac6c2a5ecc33..2b342161cbe99f2a7952e8162d9f6266a09c0508 100644 (file)
@@ -21,6 +21,7 @@
 #include "io_stream.h"
 #include "archive.h"
 #include "String++.h"
+#include "win32.h"
 
 typedef struct
 {
index 2deaf9d4b9199713a41423229000869665e33664..4385c2a6f85f2631955ae83643d559732eb7980a 100644 (file)
 static const char *cvsid = "\n%%% $Id$\n";
 #endif
 
-#include "win32.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/fcntl.h>
 #include <errno.h>
 
 #include "zlib/zlib.h"
index c428b2029332690e4a1ffb0fa7973d8c42dbeb2d..7fc8ed607a982ed1a0f85858580898215ff8ff56 100644 (file)
--- a/choose.cc
+++ b/choose.cc
@@ -33,7 +33,6 @@ static const char *cvsid =
 #include "win32.h"
 #include <commctrl.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <io.h>
 #include <ctype.h>
 #include <process.h>
index 2c20c08bc2b7c40732ce7268b2deee3b66dd8300..3cd84b78b4ee7d78a4360cadf1daed99bce4cdb8 100755 (executable)
--- a/configure
+++ b/configure
@@ -998,6 +998,7 @@ Optional Features:
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-maintainer-mode enable make rules and dependencies not useful
                           (and sometimes confusing) to the casual installer
+  --enable-inilint        Build the inilint tool
   --disable-dependency-tracking Speeds up one-time builds
   --enable-dependency-tracking  Do not reject slow dependency extractors
   --enable-shared[=PKGS]
@@ -1783,6 +1784,24 @@ fi
 
 
 
+echo "$as_me:$LINENO: checking Whether to build inilint" >&5
+echo $ECHO_N "checking Whether to build inilint... $ECHO_C" >&6
+# Check whether --enable-inilint or --disable-inilint was given.
+if test "${enable_inilint+set}" = set; then
+  enableval="$enable_inilint"
+  ac_cv_enable_inilint=$enableval
+else
+  ac_cv_enable_inilint=no
+fi;
+echo "$as_me:$LINENO: result: $ac_cv_enable_inilint" >&5
+echo "${ECHO_T}$ac_cv_enable_inilint" >&6
+if test $ac_cv_enable_inilint = yes; then
+  INILINT="inilint"
+else
+  INILINT=
+fi
+
+
 ac_ext=cc
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -4084,7 +4103,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 4087 "configure"' > conftest.$ac_ext
+  echo '#line 4106 "configure"' > conftest.$ac_ext
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7783,7 +7802,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 7786 "configure"
+#line 7805 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -7881,7 +7900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 7884 "configure"
+#line 7903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11025,7 +11044,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 11028 "configure"
+#line 11047 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11123,7 +11142,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 11126 "configure"
+#line 11145 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13772,7 +13791,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13775 "configure"
+#line 13794 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13870,7 +13889,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 13873 "configure"
+#line 13892 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
 
 
 
-for ac_header in alloca.h
+
+
+
+
+for ac_header in alloca.h \
+                errno.h \
+                string \
+                string.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-echo "$as_me:$LINENO: checking for $ac_header" >&5
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
 #line $LINENO "configure"
 #include "confdefs.h"
-\
-                string.h
-
+$ac_includes_default
 #include <$ac_header>
 _ACEOF
 rm -f conftest.$ac_objext
@@ -14975,25 +15006,82 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  eval "$as_ac_Header=yes"
+  ac_header_compiler=yes
 else
   echo "$as_me: failed program was:" >&5
 cat conftest.$ac_ext >&5
-eval "$as_ac_Header=no"
+ac_header_compiler=no
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  egrep -v '^ *\+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_cxx_preproc_warn_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc in
+  yes:no )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;};;
+  no:yes )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;};;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=$ac_header_preproc"
 fi
 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
 echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
 if test `eval echo '${'$as_ac_Header'}'` = yes; then
   cat >>confdefs.h <<_ACEOF
 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
- \
-                errno.h
-else
-  \
-                string
+
 fi
 
 done
@@ -15638,6 +15726,7 @@ s,@SET_MAKE@,$SET_MAKE,;t t
 s,@MAINTAINER_MODE_TRUE@,$MAINTAINER_MODE_TRUE,;t t
 s,@MAINTAINER_MODE_FALSE@,$MAINTAINER_MODE_FALSE,;t t
 s,@MAINT@,$MAINT,;t t
+s,@INILINT@,$INILINT,;t t
 s,@CXX@,$CXX,;t t
 s,@CXXFLAGS@,$CXXFLAGS,;t t
 s,@LDFLAGS@,$LDFLAGS,;t t
index 468866eb649e434eb44b806ac32f7ad8275b5c15..c937f1ab37c8bd88ec76798fa2feca5fe41707cd 100644 (file)
@@ -26,6 +26,19 @@ AM_MAINTAINER_MODE
 AC_CONFIG_SRCDIR([Makefile.in])
 AC_REVISION($Revision$)dnl
 
+AC_MSG_CHECKING([Whether to build inilint])
+AC_ARG_ENABLE(inilint,
+           AC_HELP_STRING([--enable-inilint],
+                          [Build the inilint tool]),
+           ac_cv_enable_inilint=$enableval, ac_cv_enable_inilint=no)
+AC_MSG_RESULT([$ac_cv_enable_inilint])
+if test $ac_cv_enable_inilint = yes; then
+  INILINT="inilint"
+else
+  INILINT=
+fi
+AC_SUBST(INILINT)
+
 AC_LANG_CPLUSPLUS
 AC_PROG_CXX
 AM_PROG_CC_C_O
@@ -52,10 +65,10 @@ dnl AC_SUBST(OBJCOPY)
 
 AC_CHECK_LIB(mingw32,main)
 
-AC_CHECK_HEADERS(alloca.h, \
-                errno.h, \
-                string, \
-                string.h)
+AC_CHECK_HEADERS(alloca.h \
+                errno.h \
+                string \
+                string.h )
 
 AC_CONFIG_SUBDIRS(zlib)
 AC_CONFIG_SUBDIRS(bz2lib)
index 468866eb649e434eb44b806ac32f7ad8275b5c15..c937f1ab37c8bd88ec76798fa2feca5fe41707cd 100644 (file)
@@ -26,6 +26,19 @@ AM_MAINTAINER_MODE
 AC_CONFIG_SRCDIR([Makefile.in])
 AC_REVISION($Revision$)dnl
 
+AC_MSG_CHECKING([Whether to build inilint])
+AC_ARG_ENABLE(inilint,
+           AC_HELP_STRING([--enable-inilint],
+                          [Build the inilint tool]),
+           ac_cv_enable_inilint=$enableval, ac_cv_enable_inilint=no)
+AC_MSG_RESULT([$ac_cv_enable_inilint])
+if test $ac_cv_enable_inilint = yes; then
+  INILINT="inilint"
+else
+  INILINT=
+fi
+AC_SUBST(INILINT)
+
 AC_LANG_CPLUSPLUS
 AC_PROG_CXX
 AM_PROG_CC_C_O
@@ -52,10 +65,10 @@ dnl AC_SUBST(OBJCOPY)
 
 AC_CHECK_LIB(mingw32,main)
 
-AC_CHECK_HEADERS(alloca.h, \
-                errno.h, \
-                string, \
-                string.h)
+AC_CHECK_HEADERS(alloca.h \
+                errno.h \
+                string \
+                string.h )
 
 AC_CONFIG_SUBDIRS(zlib)
 AC_CONFIG_SUBDIRS(bz2lib)
index 22bb3728dd5022d5b1174f503fa6e2ec983cc7b7..1321a037a6d013dfb9a1e7d43d940a4fbda701df 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Robert Collins.
+ * Copyright (c) 2001, 2002, Robert Collins.
  *
  *     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
@@ -24,16 +24,49 @@ static const char *cvsid =
   "\n%%% $Id$\n";
 #endif
 
-#include "win32.h"
-#include <stdio.h>
 #include "LogSingleton.h"
-#include "port.h"
 
 #include "io_stream.h"
-#include "io_stream_file.h"
-#include "io_stream_cygfile.h"
-#include "mkdir.h"
 #include "String++.h"
+#include "list.h"
+#include <stdexcept>
+#include "IOStreamProvider.h"
+
+static list <IOStreamProvider const, String const, String::casecompare> *providers;
+static size_t longestPrefix = 0;
+static int inited = 0;
+  
+void
+io_stream::registerProvider (IOStreamProvider &theProvider,
+                            String const &urlPrefix)
+{
+  if (!inited)
+    {
+      providers = new list <IOStreamProvider const, String const, 
+        String::casecompare>;
+      inited = true;
+    }
+  theProvider.key = urlPrefix;
+  IOStreamProvider const &testProvider = providers->registerbyobject (theProvider);
+  if (&testProvider != &theProvider)
+    throw new invalid_argument ("urlPrefix already registered!");
+  if (urlPrefix.size() > longestPrefix)
+    longestPrefix = urlPrefix.size();
+}
+
+static IOStreamProvider const *
+findProvider (String const &path)
+{
+  if (path.size() < longestPrefix)
+    return NULL;
+  for (unsigned int i = 1; i <= providers->number(); ++i)
+    {
+      IOStreamProvider const *p = (*providers)[i];
+      if (!path.casecompare (p->key, p->key.size()))
+               return p;
+    }
+  return NULL;
+}
 
 /* Static members */
 io_stream *
@@ -54,58 +87,33 @@ io_stream::factory (io_stream * parent)
 io_stream *
 io_stream::open (String const &name, String const &mode)
 {
-  if (name.size() < 7 ||
-      mode.size() == 0)
-    return NULL;
-  /* iterate through the known url prefix's */
-  if (!name.casecompare ("file://", 7))
-    {
-      io_stream_file *rv = new io_stream_file (&name.cstr_oneuse()[7], mode.cstr_oneuse());
-      if (!rv->error ())
-       return rv;
-      delete rv;
-      return NULL;
-    }
-  if (!name.casecompare ("cygfile://", 10))
-    {
-      io_stream_cygfile *rv = new io_stream_cygfile (&name.cstr_oneuse()[10], mode.cstr_oneuse());
-      if (!rv->error ())
-       return rv;
-      delete rv;
-      return NULL;
-    }
+  IOStreamProvider const *p = findProvider (name);
+  if (!p)
+    throw new invalid_argument ("URL Scheme not registered!");
+  io_stream *rv = p->open (&name.cstr_oneuse()[p->key.size()], mode);
+  if (!rv->error ())
+    return rv;
+  delete rv;
   return NULL;
 }
 
 int
 io_stream::mkpath_p (path_type_t isadir, String const &name)
 {
-  if (name.size() < 7)
-    return 1;
-  /* iterate through the known url prefix's */
-  if (!name.casecompare ("file://", 7))
-    {
-      return mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, &name.cstr_oneuse()[7]);
-    }
-  if (!name.casecompare ("cygfile://", 10))
-    {
-      return cygmkdir_p (isadir, &name.cstr_oneuse()[10]);
-    }
-  return 1;
+  IOStreamProvider const *p = findProvider (name);
+  if (!p)
+    throw new invalid_argument ("URL Scheme not registered!");
+  return p->mkdir_p (isadir, &name.cstr_oneuse()[p->key.size()]);
 }
 
 /* remove a file or directory. */
 int
 io_stream::remove (String const &name)
 {
-  if (!name.size())
-    return 1;
-  /* iterate through the known url prefix's */
-  if (!name.casecompare ("file://", 7))
-    return io_stream_file::remove (&name.cstr_oneuse()[7]);
-  if (!name.casecompare ("cygfile://", 10))
-    return io_stream_cygfile::remove (&name.cstr_oneuse()[10]);
-  return 1;
+  IOStreamProvider const *p = findProvider (name);
+  if (!p)
+    throw new invalid_argument ("URL Scheme not registered!");
+  return p->remove (&name.cstr_oneuse()[p->key.size()]);
 }
 
 int
@@ -114,39 +122,14 @@ io_stream::mklink (String const &from, String const &to,
 {
   log (LOG_BABBLE) << "io_stream::mklink (" << from << "->" << to << ")"
     << endLog;
-  if (!from.size() || !to.size())
-    {
-      log (LOG_TIMESTAMP) << "invalid string in from or to parameters to mklink"
-       << endLog;
-      return 1;
-    }
-  /* iterate through the known url prefixes */
-  if (!from.casecompare ("file://", 7))
-    {
-      /* file urls can symlink or hardlink to file url's. */
-      /* TODO: allow linking to cygfile url's */
-      if (!to.casecompare ("file://", 7))
-       return io_stream_file::mklink (&from.cstr_oneuse()[7], &to.cstr_oneuse()[7], linktype);
-      log (LOG_TIMESTAMP) << "Attempt to link across url providers" << endLog;
-      return 1;
-    }
-  if (!from.casecompare ("cygfile://", 10))
-    {
-      /* cygfile urls can symlink or hardlink to cygfile urls's. */
-      /* TODO: allow -> file urls */
-      if (!to.casecompare ("cygfile://", 10))
-       return io_stream_cygfile::mklink (&from.cstr_oneuse()[10], &to.cstr_oneuse()[10], linktype);
-      log (LOG_TIMESTAMP) << "Attempt to link across url providers" << endLog;
-      return 1;
-    }
-#if 0
-  if (!strmcasecmp ("http://", from, 7))
-    {
-      /* http urls can symlink to http or ftp url's */
-    }
-#endif
-  log (LOG_TIMESTAMP) << "Unsupported url providers for " << from << endLog;
-  return 1;
+  IOStreamProvider const *fromp = findProvider (from);
+  IOStreamProvider const *top = findProvider (to);
+  if (!fromp || !top)
+    throw new invalid_argument ("URL Scheme not registered!");
+  if (fromp != top)
+    throw new invalid_argument ("Attempt to link across url providers.");
+  return fromp->mklink (&from.cstr_oneuse()[fromp->key.size()], 
+                       &to.cstr_oneuse()[top->key.size()], linktype);
 }
 
 int
@@ -203,35 +186,14 @@ ssize_t io_stream::copy (io_stream * in, io_stream * out)
 int
 io_stream::move (String const &from, String const &to)
 {
-  if (!from.size() || !to.size())
-    {
-      log (LOG_TIMESTAMP) << "invalid string in from or to parameters to move"
-       << endLog;
-      return 1;
-    }
-  /* iterate through the known url prefixes */
-  if (!from.casecompare ("file://", 7))
-    {
-      /* TODO: allow 'move' to cygfile url's */
-      if (to.casecompare ("file://", 7))
-       return io_stream::move_copy (from, to);
-      return io_stream_file::move (&from.cstr_oneuse()[7], &to.cstr_oneuse()[7]);
-    }
-  if (!from.casecompare ("cygfile://", 10))
-    {
-      /* TODO: allow -> file urls */
-      if (to.casecompare ("cygfile://", 10))
-       return io_stream::move_copy (from, to);
-      return io_stream_cygfile::move (&from.cstr_oneuse()[10], &to.cstr_oneuse()[10]);
-    }
-#if 0
-  if (!strmcasecmp ("http://", from, 7))
-    {
-      /* http urls can symlink to http or ftp url's */
-    }
-#endif
-  log (LOG_TIMESTAMP) << "Unsupported url providers for " << from << endLog;
-  return 1;
+  IOStreamProvider const *fromp = findProvider (from);
+  IOStreamProvider const *top = findProvider (to);
+  if (!fromp || !top)
+    throw new invalid_argument ("URL Scheme not registered!");
+  if (fromp != top)
+    return io_stream::move_copy (from, to);
+  return fromp->move (&from.cstr_oneuse()[fromp->key.size()],
+                     &to.cstr_oneuse()[top->key.size()]);
 }
 
 char *
@@ -261,14 +223,10 @@ io_stream::gets (char *buffer, size_t length)
 int
 io_stream::exists (String const &name)
 {
-  if (!name.size())
-    return 1;
-  /* iterate through the known url prefix's */
-  if (!name.casecompare ("file://", 7))
-    return io_stream_file::exists (&name.cstr_oneuse()[7]);
-  if (!name.casecompare ("cygfile://", 10))
-    return io_stream_cygfile::exists (&name.cstr_oneuse()[10]);
-  return 1;
+  IOStreamProvider const *p = findProvider (name);
+  if (!p)
+    throw new invalid_argument ("URL Scheme not registered!");
+  return p->exists (&name.cstr_oneuse()[p->key.size()]);
 }
 
 /* virtual members */
index c7d5da9792418c9d2f190bcd9c470d57a7bfdb9b..669ddd1d90c2edd218b1f311a8dd4b2d82c957af 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #include "String++.h"
+class IOStreamProvider;
 
 /* Some things don't fit cleanly just - TODO
  * make mkdir_p fit in the hierarchy
@@ -72,6 +73,8 @@ io_stream_seek_t;
 class io_stream
 {
 public:
+  /* Register a new io_stream provider */
+  static void registerProvider (IOStreamProvider &, String const &urlscheme);
   /* create a new stream from an existing one - used to get
    * decompressed data
    * or open archives.
index 34a9d836f286cd2189c2e84d536ebbc798575c9d..e1e078949b94a8a3dccfbe63cd414c42a57bf082 100644 (file)
@@ -32,6 +32,37 @@ static const char *cvsid =
 
 #include "io_stream.h"
 #include "io_stream_cygfile.h"
+#include "IOStreamProvider.h"
+
+/* completely private iostream registration class */
+class CygFileProvider : public IOStreamProvider
+{
+public:
+  int exists (String const &path) const
+    {return io_stream_cygfile::exists(path);}
+  int remove (String const &path) const
+    {return io_stream_cygfile::remove(path);}
+  int mklink (String const &a , String const &b, io_stream_link_t c) const
+    {return io_stream_cygfile::mklink(a,b,c);}
+  io_stream *open (String const &a,String const &b) const
+    {return new io_stream_cygfile (a, b);}
+  ~CygFileProvider (){}
+  int move (String const &a,String const &b) const
+    {return io_stream_cygfile::move (a, b);}
+  int mkdir_p (enum path_type_t isadir, String const &path) const
+    {return cygmkdir_p (isadir, path);}
+protected:
+  CygFileProvider() // no creating this
+    {
+      io_stream::registerProvider (theInstance, "cygfile://");
+    }
+  CygFileProvider(CygFileProvider const &); // no copying
+  CygFileProvider &operator=(CygFileProvider const &); // no assignment
+private:
+  static CygFileProvider theInstance;
+};
+CygFileProvider CygFileProvider::theInstance = CygFileProvider();
+
 
 /* For set mtime */
 #define FACTOR (0x19db1ded53ea710LL)
index ef7db81b1d2f7819c1f41f80197b91bde8063b72..f9018e38a2032740be2dccfd56d67b3a3d117cce 100644 (file)
@@ -24,10 +24,42 @@ static const char *cvsid =
 #include <errno.h>
 #include <unistd.h>
 #include "port.h"
+#include "mkdir.h"
 #include "mklink2.h"
 
 #include "io_stream.h"
 #include "io_stream_file.h"
+#include "IOStreamProvider.h"
+
+/* completely private iostream registration class */
+class FileProvider : public IOStreamProvider
+{
+public:
+  int exists (String const &path) const
+    {return io_stream_file::exists(path);}
+  int remove (String const &path) const
+    {return io_stream_file::remove(path);}
+  int mklink (String const &a , String const &b, io_stream_link_t c) const
+    {return io_stream_file::mklink(a,b,c);}
+  io_stream *open (String const &a,String const &b) const
+    {return new io_stream_file (a, b);}
+  ~FileProvider (){}
+  int move (String const &a,String const &b) const
+    {return io_stream_file::move (a, b);}
+  int mkdir_p (enum path_type_t isadir, String const &path) const
+    {return ::mkdir_p (isadir == PATH_TO_DIR ? 1 : 0, path.cstr_oneuse());}
+protected:
+  FileProvider() // no creating this
+    {
+      io_stream::registerProvider (theInstance, "file://");
+    }
+  FileProvider(FileProvider const &); // no copying
+  FileProvider &operator=(FileProvider const &); // no assignment
+private:
+  static FileProvider theInstance;
+};
+FileProvider FileProvider::theInstance = FileProvider();
+  
 
 /* for set_mtime */
 #define FACTOR (0x19db1ded53ea710LL)
This page took 0.069338 seconds and 5 git commands to generate.