diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
commit | 0292059f4a16434600564cfa3f0ad2309a508a54 (patch) | |
tree | d95953cd53011917c4df679b96aedca39401b54f /doc/sources | |
download | libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip |
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'doc/sources')
-rw-r--r-- | doc/sources/Makefile.am | 24 | ||||
-rw-r--r-- | doc/sources/c++/README | 3 | ||||
-rwxr-xr-x | doc/sources/c++/compile | 5 | ||||
-rw-r--r-- | doc/sources/c++/main.cpp | 44 | ||||
-rw-r--r-- | doc/sources/c++/polygon.hpp | 25 | ||||
-rw-r--r-- | doc/sources/c++/triangle.cpp | 22 | ||||
-rwxr-xr-x | doc/sources/c/compile | 5 | ||||
-rw-r--r-- | doc/sources/c/main.c | 56 | ||||
-rw-r--r-- | doc/sources/c/module.c | 4 | ||||
-rw-r--r-- | doc/sources/ttx/Makefile.am | 9 | ||||
-rw-r--r-- | doc/sources/ttx/README | 3 | ||||
-rwxr-xr-x | doc/sources/ttx/compile-c++ | 8 | ||||
-rw-r--r-- | doc/sources/ttx/fmt_codec_ttx.cpp | 116 | ||||
-rw-r--r-- | doc/sources/ttx/fmt_codec_ttx.h | 37 | ||||
-rw-r--r-- | doc/sources/ttx/fmt_codec_ttx_defs.h | 27 |
15 files changed, 388 insertions, 0 deletions
diff --git a/doc/sources/Makefile.am b/doc/sources/Makefile.am new file mode 100644 index 0000000..796800c --- /dev/null +++ b/doc/sources/Makefile.am @@ -0,0 +1,24 @@ +install-data-local: + $(mkinstalldirs) $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources + $(mkinstalldirs) $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c + $(mkinstalldirs) $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++ + $(mkinstalldirs) $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx + + $(INSTALL_DATA) c/module.c $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c/module.c + $(INSTALL_DATA) c/main.c $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c/main.c + $(INSTALL_SCRIPT) c/compile $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c/compile + + $(INSTALL_SCRIPT) c++/compile $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++/compile + $(INSTALL_DATA) c++/main.cpp $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++/main.cpp + $(INSTALL_DATA) c++/triangle.cpp $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++/triangle.cpp + $(INSTALL_DATA) c++/polygon.hpp $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++/polygon.hpp + $(INSTALL_DATA) c++/README $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/c++/README + + $(INSTALL_DATA) ttx/Makefile.am $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/Makefile.am + $(INSTALL_DATA) ttx/README $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/README + $(INSTALL_SCRIPT) ttx/compile-c++ $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/compile-c++ + $(INSTALL_DATA) ttx/fmt_codec_ttx_defs.h $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/fmt_codec_ttx_defs.h + $(INSTALL_DATA) ttx/fmt_codec_ttx.h $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/fmt_codec_ttx.h + $(INSTALL_DATA) ttx/fmt_codec_ttx.cpp $(DESTDIR)/usr/share/doc/ksquirrel-libs/$(PACKAGE_VERSION)/sources/ttx/fmt_codec_ttx.cpp + +EXTRA_DIST = c c++ ttx
\ No newline at end of file diff --git a/doc/sources/c++/README b/doc/sources/c++/README new file mode 100644 index 0000000..189ebab --- /dev/null +++ b/doc/sources/c++/README @@ -0,0 +1,3 @@ +Originally written by Aaron Isotton. +Look for article "C++ dlopen mini HOWTO" in internet or +visit http://ksquirrel.sf.net/ksquirrel-libs-olibs2.php
\ No newline at end of file diff --git a/doc/sources/c++/compile b/doc/sources/c++/compile new file mode 100755 index 0000000..64687fa --- /dev/null +++ b/doc/sources/c++/compile @@ -0,0 +1,5 @@ +#!/bin/sh + +g++ -O2 -Wall -fPIC -c triangle.cpp +g++ -shared -o triangle.so triangle.o +g++ -o test main.cpp -ldl
\ No newline at end of file diff --git a/doc/sources/c++/main.cpp b/doc/sources/c++/main.cpp new file mode 100644 index 0000000..b8fb8cd --- /dev/null +++ b/doc/sources/c++/main.cpp @@ -0,0 +1,44 @@ +#include "polygon.hpp" + +#include <iostream> +#include <dlfcn.h> + +int main() +{ + using std::cout; + using std::cerr; + + // load the triangle library + void* triangle = dlopen("./triangle.so", RTLD_LAZY); + + if (!triangle) + { + cerr << "Cannot load library: " << dlerror() << '\n'; + return 1; + } + + // load the symbols + create_t* create_triangle = (create_t*) dlsym(triangle, "create"); + destroy_t* destroy_triangle = (destroy_t*) dlsym(triangle, "destroy"); + + if (!create_triangle || !destroy_triangle) + { + cerr << "Cannot load symbols: " << dlerror() << '\n'; + return 1; + } + + // create an instance of the class + polygon* poly = create_triangle(); + + // use the class + poly->set_side_length(7); + cout << "The area is: " << poly->area() << '\n'; + + // destroy the class + destroy_triangle(poly); + + // unload the triangle library + dlclose(triangle); + + return 0; +} diff --git a/doc/sources/c++/polygon.hpp b/doc/sources/c++/polygon.hpp new file mode 100644 index 0000000..e3189bf --- /dev/null +++ b/doc/sources/c++/polygon.hpp @@ -0,0 +1,25 @@ +#ifndef POLYGON_HPP +#define POLYGON_HPP + +class polygon +{ + protected: + double side_length_; + + public: + polygon() : side_length_(0) + {} + + void set_side_length(double side_length) + { + side_length_ = side_length; + } + + virtual double area() const = 0; +}; + +// the types of the class factories +typedef polygon* create_t(); +typedef void destroy_t(polygon*); + +#endif diff --git a/doc/sources/c++/triangle.cpp b/doc/sources/c++/triangle.cpp new file mode 100644 index 0000000..96185d0 --- /dev/null +++ b/doc/sources/c++/triangle.cpp @@ -0,0 +1,22 @@ +#include "polygon.hpp" +#include <cmath> + +class triangle : public polygon +{ + public: + virtual double area() const + { + return side_length_ * side_length_ * sqrt(3) / 2; + } +}; + +// the class factories +extern "C" polygon* create() +{ + return new triangle; +} + +extern "C" void destroy(polygon* p) +{ + delete p; +} diff --git a/doc/sources/c/compile b/doc/sources/c/compile new file mode 100755 index 0000000..9be0fbb --- /dev/null +++ b/doc/sources/c/compile @@ -0,0 +1,5 @@ +#!/bin/sh + +gcc -Wall -O2 -fPIC -c module.c +gcc -shared -o module.so module.o +gcc -o test main.c -ldl
\ No newline at end of file diff --git a/doc/sources/c/main.c b/doc/sources/c/main.c new file mode 100644 index 0000000..96d60ad --- /dev/null +++ b/doc/sources/c/main.c @@ -0,0 +1,56 @@ +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <dlfcn.h> + +#define PATH_LENGTH 256 + +int main(int argc, char * argv[]) +{ + char path[PATH_LENGTH], *msg = NULL; + const char* (*fmt)(); + void *module; + + getcwd(path, PATH_LENGTH); + strcat(path, "/"); + strcat(path, "module.so"); + + /* Load module */ + module = dlopen(path, RTLD_NOW); + + /* Error ! */ + if(!module) + { + msg = dlerror(); + + if(msg != NULL) + { + dlclose(module); + exit(1); + } + } + + /* Try to resolve function "fmt_info()" */ + fmt = dlsym(module, "fmt_info"); + + msg = dlerror(); + + if(msg != NULL) + { + perror(msg); + dlclose(module); + exit(1); + } + + /* call fmt_info() through a pointer*/ + printf("%s\n", fmt()); + + /* close module */ + if(dlclose(module)) + { + perror("error"); + exit(1); + } + + return 0; +} diff --git a/doc/sources/c/module.c b/doc/sources/c/module.c new file mode 100644 index 0000000..36c5d2a --- /dev/null +++ b/doc/sources/c/module.c @@ -0,0 +1,4 @@ +const char* fmt_info() +{ + return "It is really cool format!"; +} diff --git a/doc/sources/ttx/Makefile.am b/doc/sources/ttx/Makefile.am new file mode 100644 index 0000000..4b3418e --- /dev/null +++ b/doc/sources/ttx/Makefile.am @@ -0,0 +1,9 @@ +INCLUDES = -I.. -I../include + +lib_LTLIBRARIES = libSQ_codec_ttx.la + +libSQ_codec_ttx_la_SOURCES = fmt_codec_ttx.cpp fmt_codec_ttx_defs.h + +libSQ_codec_ttx_la_LDFLAGS = -release 0.1.0 + +libSQ_codec_ttx_la_LIBADD = diff --git a/doc/sources/ttx/README b/doc/sources/ttx/README new file mode 100644 index 0000000..ce1269e --- /dev/null +++ b/doc/sources/ttx/README @@ -0,0 +1,3 @@ +this example should be compiled in ksquirrel-libs' tree. +Put this directory in ksquirrel-libs/kernel, then cd to "ttx" and +run ./compile-c++
\ No newline at end of file diff --git a/doc/sources/ttx/compile-c++ b/doc/sources/ttx/compile-c++ new file mode 100755 index 0000000..86d3acb --- /dev/null +++ b/doc/sources/ttx/compile-c++ @@ -0,0 +1,8 @@ +#!/bin/sh + +rm -f libkls_ttx.so + +g++ -I. -I../include -Wall -O2 -fPIC -c fmt_codec_ttx.cpp +g++ -I. -I../include -Wall -O2 -fPIC -c ../kls_lib/fileio.cpp +g++ -Wall -shared fileio.o fmt_codec_ttx.o -o libkls_ttx.so +rm -f fmt_codec_ttx.o fileio.o
\ No newline at end of file diff --git a/doc/sources/ttx/fmt_codec_ttx.cpp b/doc/sources/ttx/fmt_codec_ttx.cpp new file mode 100644 index 0000000..40c9f5d --- /dev/null +++ b/doc/sources/ttx/fmt_codec_ttx.cpp @@ -0,0 +1,116 @@ +/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net) + + Copyright (c) 2005 Dmitry Baryshev <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later + version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <iostream> + +#include "ksquirrel-libs/fmt_types.h" +#include "ksquirrel-libs/fileio.h" + +#include "fmt_codec_ttx_defs.h" +#include "fmt_codec_ttx.h" + +#include "ksquirrel-libs/error.h" + +fmt_codec::fmt_codec() : fmt_codec_base() +{} + +fmt_codec::~fmt_codec() +{} + +void fmt_codec::options(codec_options *o) +{ + o->version = "0.1.0"; + o->name = ""; + o->filter = "*. "; + o->mime = ""; + o->pixmap = ""; + o->config = ""; + o->readable = true; + o->writestatic = false; + o->writeanimated = false; + o->canbemultiple = false; + o->needtempfile = false; +} + +s32 fmt_codec::read_init(const std::string &file) +{ + frs.open(file.c_str(), ios::binary | ios::in); + + if(!frs.good()) + return SQE_R_NOFILE; + + currentImage = -1; + read_error = false; + + finfo.animated = false; + + return SQE_OK; +} + +s32 fmt_codec::read_next() +{ + currentImage++; + + if(currentImage) + return SQE_NOTOK; + + fmt_image image; + +/* + image.w = + image.h = + image.bpp = +*/ + + image.compression = ""; + image.colorspace = ""; + + finfo.image.push_back(image); + + return SQE_OK; +} + +s32 fmt_codec::read_next_pass() +{ + return SQE_OK; +} + +s32 fmt_codec::read_scanline(RGBA *scan) +{ + RGB rgb; + RGBA rgba; + fmt_image *im = image(currentImage); + + memset(scan, 255, im->w * sizeof(RGBA)); + + + return SQE_OK; +} + +void fmt_codec::read_close() +{ + frs.close(); + + finfo.meta.clear(); + finfo.image.clear(); +} + +#include "fmt_codec_cd_func.h" diff --git a/doc/sources/ttx/fmt_codec_ttx.h b/doc/sources/ttx/fmt_codec_ttx.h new file mode 100644 index 0000000..fd44432 --- /dev/null +++ b/doc/sources/ttx/fmt_codec_ttx.h @@ -0,0 +1,37 @@ +/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net) + + Copyright (c) 2005 Dmitry Baryshev <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later + version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KSQUIRREL_LIBS_CLASS_DEFINITION_ttx_H +#define KSQUIRREL_LIBS_CLASS_DEFINITION_ttx_H + +#include "ksquirrel-libs/fmt_codec_base.h" + +class fmt_codec : public fmt_codec_base +{ + public: + + BASE_CODEC_DECLARATIONS + + private: + // define variables you need here +}; + +#endif diff --git a/doc/sources/ttx/fmt_codec_ttx_defs.h b/doc/sources/ttx/fmt_codec_ttx_defs.h new file mode 100644 index 0000000..bd8bdcb --- /dev/null +++ b/doc/sources/ttx/fmt_codec_ttx_defs.h @@ -0,0 +1,27 @@ +/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net) + + Copyright (c) 2005 Dmitry Baryshev <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later + version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KSQUIRREL_CODEC_DEFS_ttx +#define KSQUIRREL_CODEC_DEFS_ttx + +// define constants here + +#endif |