Permalink
Browse files

Initial import of rubyforge project

  • Loading branch information...
0 parents commit 4a8fa509b0671d02c1d0785161fd7d1639251203 @mmangino committed Dec 30, 2008
Showing with 4,241 additions and 0 deletions.
  1. +558 −0 Interface.html
  2. +498 −0 Interface.rd
  3. +46 −0 README.txt
  4. +49 −0 depend
  5. +7 −0 extconf.rb
  6. +80 −0 libtest.rb
  7. +97 −0 main.c
  8. +51 −0 ruby-shapelib.spec
  9. +284 −0 sfcode.h
  10. +21 −0 sflist.h
  11. +18 −0 shapelib.gemspec
  12. +583 −0 shpplus.c
  13. +86 −0 shpplus.h
  14. +704 −0 spcode.h
  15. +71 −0 splist.h
  16. +219 −0 spwkt.h
  17. +136 −0 style.css
  18. +312 −0 valconv.h
  19. +168 −0 zsample1.rb
  20. +253 −0 ztest1.rb
Oops, something went wrong.
Oops, something went wrong.
@@ -0,0 +1,46 @@
+ README for Ruby-ShapeLiB
+
+ prasinos@users.sourceforge.net
+
+This is a wrapper module of Shapefile C Library for Ruby.
+
+How to install
+==============
+
+* You must have ShapeLib and ruby.
+* It is expected to run on all ruby-running environments. But it is tested
+ only on RedHat Enterprise Linux 4.0 and Vine Linux 3.0.
+
+Quick directions
+----------------
+
+ $ tar xvfz ruby-shapelib.tar.gz (you did it if you see this file)
+ $ cd ruby-shapelib
+ $ ruby ./extconf.rb
+ $ make
+ # make install
+
+Troubleshooting
+---------------
+
+* I have ruby but can't run extconf.rb
+
+ Some Linux distributions divide Ruby into several packages such as
+ "ruby" and "ruby-devel". You may have to install additional packages.
+
+* I have shapelib installed but extconf.rb fails
+
+ Try --with-shapelib-include= and --with-shapelib-lib= options of extconf.rb.
+
+If above advice doesn't help, please visit
+http://sourceforge.net/projects/ruby-shapelib and post a message.
+
+How to use
+==========
+
+ Please see Interface.html.
+
+License issues
+==============
+
+Ruby-ShapeLib is provided under LGPL or ShapeLib's MIT-style default license.
@@ -0,0 +1,49 @@
+MYNAME = ruby-shapelib
+
+main.o:: sflist.h splist.h shpplus.h valconv.h sfcode.h spcode.h \
+ spwkt.h
+shpplus.o:: shpplus.h
+
+RD2 = rd2 -r rd/rd2html-lib --with-css=style.css
+
+doc: Interface.html
+Interface.html: Interface.rd
+ $(RD2) --html-title="$(MYNAME) API" $< > $@
+
+#rpm:
+# $(MAKE) -f build.mk rpm
+
+clean2: clean
+ -rm -f test*
+
+tags: main.c shpplus.c sfcode.h sflist.h shpplus.h spcode.h \
+ splist.h valconv.h spwkt.h
+ ctags *.h *.c
+
+test: shapelib.so
+ $(RUBY) $(RUBYOPT) ztest1.rb
+
+distcrean: clean
+ -rm -f mkmf.log Makefile
+
+TARDIR=..
+
+tar:
+ $(MAKE) tar.b VERSION=`awk '/Version:/ {print $$2}' $(MYNAME).spec`
+
+tar.b:
+ cvs export -r HEAD -d $(MYNAME)-$(VERSION) $(MYNAME)
+ tar -czf $(TARDIR)/$(MYNAME)-$(VERSION).tar.gz $(MYNAME)-$(VERSION)/*
+ rm -rf $(MYNAME)-$(VERSION)
+
+rpm:
+ $(MAKE) rpm.b VERSION=`awk '/Version:/ {print $$2}' $(MYNAME).spec`
+
+rpm.b:
+ test -d $(RPM)/../rpm/SPECS
+ test ! -d $(MYNAME)-$(VERSION) || rm -rf $(MYNAME)-$(VERSION)
+ cvs export -r HEAD -d $(MYNAME)-$(VERSION) $(MYNAME)
+ tar -czf $(RPM)/SOURCES/$(MYNAME).tar.gz $(MYNAME)-$(VERSION)/*
+ rm -rf $(MYNAME)-$(VERSION)
+ cp $(MYNAME).spec $(RPM)/SPECS
+ rpmbuild -ba $(RPM)/SPECS/$(MYNAME).spec
@@ -0,0 +1,7 @@
+#!/usr/bin/ruby
+require 'mkmf'
+
+dir_config('shapelib')
+have_header('shapefil.h') or raise 'shapefil.h not found'
+have_library('shp') or raise 'libshp not found'
+create_makefile('shapelib')
@@ -0,0 +1,80 @@
+class AssertFail < Exception
+end
+
+def assert(a, b)
+ caller = ""
+ begin
+ raise "no problem"
+ rescue RuntimeError => e
+ caller = e.backtrace[1]
+ end
+ if (b === a) then
+ val = b.inspect
+ val = "#{val}..." if val.size > 40
+ print "ok #{caller}: #{val}\n" if $VERBOSE
+ else
+ val = a.inspect
+ val = "#{val}..." if val.size > 200
+ raise AssertFail, val
+ end
+end
+
+def file_delete(*args)
+ for file in args
+ next unless File.exist?(file)
+ File.delete(file)
+ end
+end
+
+def fold_line(line)
+ buf = ""
+ while line
+ head = line[0..63]
+ buf << (head + "\n")
+ line = line[64..-1]
+ end
+ buf
+end
+
+def assert_file(filename, pat)
+ f = File.read(filename)
+ r = [pat.gsub(/\s+/, "")].pack('H*')
+
+ if (r === f) then
+ print "ok <#{filename}>\n" if $VERBOSE
+ else
+ for i in 0...(f.size)
+ next if (f[i] == r[i])
+ printf "ofs=%08x file=%02x expected=%02x\n", i, f[i], r[i]
+ break
+ end
+ print "#{filename} is longer than expected\n" if f.size > r.size
+ h = f.unpack('H*').first
+ File.open("#{filename}.hex", "w") { |fp| fp.write(fold_line(h)) }
+ print "hex dump of <#{filename}> is saved to <#{filename}.hex>.\n"
+ raise AssertFail
+ end
+end
+
+def testblock(title)
+ begin
+ yield
+ rescue Exception => e
+ print "#{title} failed: #{e.message} (#{e.class.to_s})\n"
+ print "| ", e.backtrace[1..-1].join("\n| "), "\n"
+ return 1
+ else
+ print "#{title} ok\n"
+ return 0
+ end
+end
+
+def tainttest(msg)
+ begin
+ yield
+ rescue SecurityError => e
+ assert(e.message, msg)
+ else
+ raise SecurityError, "<#{msg}> doesn't come" if $SAFE > 0
+ end
+end
@@ -0,0 +1,97 @@
+#include <ruby.h>
+#include <shapefil.h>
+#include "shpplus.h"
+
+typedef struct {
+ const char *mname;
+ VALUE (*func)();
+ int argc;
+} method_table_entry;
+
+typedef struct {
+ const char *name;
+ VALUE val;
+} const_table_entry;
+
+static VALUE mShapeLib;
+static VALUE cShapeFile;
+static VALUE cShape;
+static VALUE cPoint;
+static VALUE cPointM;
+static VALUE cPointZ;
+static VALUE cArc;
+static VALUE cArcM;
+static VALUE cArcZ;
+static VALUE cPolygon;
+static VALUE cPolygonM;
+static VALUE cPolygonZ;
+static VALUE cMultiPoint;
+static VALUE cMultiPointM;
+static VALUE cMultiPointZ;
+static VALUE cMultiPatch;
+
+/* code begins here */
+
+#include "valconv.h"
+#include "sfcode.h"
+#include "sflist.h"
+#include "spcode.h"
+#include "spwkt.h"
+#include "splist.h"
+
+static void register_consts(VALUE klass, const_table_entry *table)
+{
+ const_table_entry *p;
+ for (p = table; p->name; p++) {
+ rb_define_const(klass, p->name, p->val);
+ }
+}
+
+static void register_methods(VALUE klass, method_table_entry *table)
+{
+ method_table_entry *p;
+ for (p = table; p->mname; p++) {
+ rb_define_method(klass, p->mname, p->func, p->argc);
+ }
+}
+
+void Init_shapelib()
+{
+ mShapeLib = rb_define_module("ShapeLib");
+ cShapeFile = rb_define_class_under(mShapeLib, "ShapeFile", rb_cObject);
+ cShape = rb_define_class_under(mShapeLib, "Shape", rb_cObject);
+ cPoint = rb_define_class_under(mShapeLib, "Point", cShape);
+ cPointM = rb_define_class_under(mShapeLib, "PointM", cPoint);
+ cPointZ = rb_define_class_under(mShapeLib, "PointZ", cPointM);
+ cArc = rb_define_class_under(mShapeLib, "Arc", cShape);
+ cArcM = rb_define_class_under(mShapeLib, "ArcM", cArc);
+ cArcZ = rb_define_class_under(mShapeLib, "ArcZ", cArcM);
+ cPolygon = rb_define_class_under(mShapeLib, "Polygon", cShape);
+ cPolygonM = rb_define_class_under(mShapeLib, "PolygonM", cPolygon);
+ cPolygonZ = rb_define_class_under(mShapeLib, "PolygonZ", cPolygonM);
+ cMultiPoint = rb_define_class_under(mShapeLib, "MultiPoint", cShape);
+ cMultiPointM = rb_define_class_under(mShapeLib, "MultiPointM", cMultiPoint);
+ cMultiPointZ = rb_define_class_under(mShapeLib, "MultiPointZ", cMultiPointM);
+ cMultiPatch = rb_define_class_under(mShapeLib, "MultiPatch", cShape);
+ rb_define_module_function(mShapeLib, "new_point", sl_m_new_point, -1);
+ rb_define_singleton_method(cShapeFile, "new", sf_s_new, -1);
+ rb_define_singleton_method(cShapeFile, "open", sf_s_open, -1);
+ rb_define_singleton_method(cShape, "new", sp_s_new, 1);
+ rb_define_singleton_method(cPoint, "new", pt_s_new, -1);
+ rb_define_singleton_method(cPointM, "new", ptm_s_new, -1);
+ rb_define_singleton_method(cPointZ, "new", ptz_s_new, -1);
+ rb_define_singleton_method(cArc, "new", arc_s_new, -1);
+ rb_define_singleton_method(cArcM, "new", arcm_s_new, -1);
+ rb_define_singleton_method(cArcZ, "new", arcz_s_new, -1);
+ rb_define_singleton_method(cPolygon, "new", pl_s_new, -1);
+ rb_define_singleton_method(cPolygonM, "new", plm_s_new, -1);
+ rb_define_singleton_method(cPolygonZ, "new", plz_s_new, -1);
+ rb_define_singleton_method(cMultiPoint, "new", mp_s_new, -1);
+ rb_define_singleton_method(cMultiPointM, "new", mpm_s_new, -1);
+ rb_define_singleton_method(cMultiPointZ, "new", mpz_s_new, -1);
+ rb_define_singleton_method(cMultiPatch, "new", mpatch_s_new, -1);
+ register_consts(mShapeLib, sl_consts);
+ register_methods(cShapeFile, sf_methods);
+ register_methods(cShape, sp_methods);
+ register_methods(cPoint, pt_methods);
+}
@@ -0,0 +1,51 @@
+Name: ruby-shapelib
+Version: 0.6
+Release: 1p
+Summary: ruby binding for ShapeLib
+License: LGPL or MIT-like
+Group: Library/File_Format
+Source: %{name}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-root
+BuildPrereq: ruby, shapelib
+Prereq: ruby, shapelib
+
+%description
+ruby-shapelib is a Ruby binding of Shapefile C library.
+Users can read/write shapefile from Ruby script.
+
+%prep
+%setup
+./extconf.rb
+
+%build
+make
+
+%install
+make install DESTDIR=${RPM_BUILD_ROOT}
+
+%post
+
+%clean
+rm -rf ${RPM_BUILD_ROOT}
+
+%files
+%defattr(-,root,root)
+/usr/lib/site_ruby/1.8/i386-linux-gnu/shapelib.so
+
+%changelog
+* Tue Mar 07 2006 prasinos <prasinos@users.sourceforge.net> (0.6)
+- code style improvement:
+ - avoid prototype for static function
+ - avoid int/unsigned mixture
+
+* Fri Feb 17 2006 prasinos <prasinos@users.sourceforge.net> (0.4)
+- bugfix: name compare error
+- bugfix: nil was erroneously converted to NODATA for x/y/z
+- documentation refleshed
+
+* Thu Feb 16 2006 prasinos <prasinos@users.sourceforge.net> (0.3)
+- most of features implemented
+
+* Tue Feb 14 2006 prasinos <prasinos@users.sourceforge.net> (0.2)
+- initial RPM package
+
Oops, something went wrong.

0 comments on commit 4a8fa50

Please sign in to comment.