diff options
Diffstat (limited to 'lib/cpluff/examples/cpfile')
25 files changed, 0 insertions, 1057 deletions
diff --git a/lib/cpluff/examples/cpfile/Makefile.am b/lib/cpluff/examples/cpfile/Makefile.am deleted file mode 100644 index 6db84d0717..0000000000 --- a/lib/cpluff/examples/cpfile/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -SUBDIRS = plugins - -EXTRA_DIST = README.txt cpfile.in cpfile.bat Makefile.nmake -bin_SCRIPTS = cpfile diff --git a/lib/cpluff/examples/cpfile/Makefile.nmake b/lib/cpluff/examples/cpfile/Makefile.nmake deleted file mode 100644 index c7e89abfcd..0000000000 --- a/lib/cpluff/examples/cpfile/Makefile.nmake +++ /dev/null @@ -1,13 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-SUBDIRS = plugins
-TOP = ..
-
-include ..\common.nmake
-
-install-local: all-local
- if not exist $(bindir) mkdir $(bindir)
- copy /y cpfile.bat $(bindir)
diff --git a/lib/cpluff/examples/cpfile/README.txt b/lib/cpluff/examples/cpfile/README.txt deleted file mode 100644 index d2fea09854..0000000000 --- a/lib/cpluff/examples/cpfile/README.txt +++ /dev/null @@ -1,138 +0,0 @@ -C-PLUFF FILE COMMAND EXAMPLE -============================ - -Overview --------- - -On UNIX systems the file(1) utility can be used to determine file type and -to get information about contents of a file. Here are couple of examples -of file usage in a Linux environment. - - $ file /sbin/init - /sbin/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), - for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for - GNU/Linux 2.4.1, stripped - - $ file COPYRIGHT.txt - COPYRIGHT.txt: ASCII English text - -This example shows how a simplistic file clone could be implemented as an -extensible application based on C-Pluff. We will call the resulting -utility cpfile. It can recognize some special files and some file types -based on file extension. But it could be further extended to recognize -files based on their content by deploying a suitable plug-in. Notice that -the focus here was on creating a straightforward example rather than an -efficient one. - - -Architecture ------------- - -This example uses the generic plug-in loader, cpluff-loader, as the main -program. The executable cpfile installed into the bin directory is just -a shell script invoking the cpluff-loader. All program logic is included -in plug-ins. - -The included plug-ins are: - - org.c-pluff.examples.cpfile.core - - This plug-in is the one initially started via cpluff-loader. It - contains the core application logic and provides an extension point - for file classifiers. The plug-in itself does not include any file - classifiers. Instead it uses file classifiers registered as - extensions by other plug-ins and then tries them one at a time in - order of decreasing priority until a matching classification is - found or no more classifiers are left. - - org.c-pluff.examples.cpfile.special - - This plug-in provides a file classifier which uses lstat(2) on the - file to be classified to see if it is a special file such as a - directory or a symbolic link. It also checks for the existence of - the file. - - org.c-pluff.examples.cpfile.extension - - This plug-in provides a file classifier which checks the file name - for known extensions. The plug-in provides an extension point for - file extensions. The file extensions registered as extensions are - then matched against the file name. The plug-in itself includes an - extension for text files. - - org.c-pluff.examples.cpfile.cext - - This plug-in does not include a runtime library at all. Instead, it - just registers some file types and file extensions related to - C program source files. - -Having build and installed the example, you can experiment with different -plug-in configurations by adding and removing plug-ins into cpfile/plugins -directory in the library directory. The core plug-in must be always -included for the application to work as intended. - -You can create a new plug-in for the example by creating a new -subdirectory in the plugins source directory and adding it to SUBDIRS -variable in Makefile.am in the plugins source directory. - - -Example runs ------------- - -Here are couple of examples of using the resulting cpfile application. - - $ cpfile /tmp/testdir - C-Pluff Loader, version 0.1.0 - C-Pluff Library, version 0.1.0 for i686-pc-linux-gnu - /tmp/testdir: directory - - $ cpfile /tmp/test.foo - C-Pluff Loader, version 0.1.0 - C-Pluff Library, version 0.1.0 for i686-pc-linux-gnu - /tmp/test.foo: unknown file type - - $ cpfile /tmp/test.c - C-Pluff Loader, version 0.1.0 - C-Pluff Library, version 0.1.0 for i686-pc-linux-gnu - /tmp/test.c: C source file - - $ cpfile /tmp/test.nonexisting - C-Pluff Loader, version 0.1.0 - C-Pluff Library, version 0.1.0 for i686-pc-linux-gnu - /tmp/test.nonexisting: stat failed: No such file or directory - -You can make cpfile more quiet by giving it -q option, or more verbose by -giving it -v option (repeated for more verbosity up to -vvv). Actually, -these options are processed by cpluff-loader which configures logging -accordingly. - - $ cpfile -q /tmp/test.c - /tmp/test.c: C source file - - $ cpfile -vv /tmp/test.c - C-Pluff Loader, version 0.1.0 - C-Pluff Library, version 0.1.0 for i686-pc-linux-gnu - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core has been installed. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.extension has been installed. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.cext has been installed. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.special has been installed. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core runtime has been loaded. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core is starting. - C-Pluff: INFO: [org.c-pluff.examples.cpfile.core] Plug-in org.c-pluff.examples.cpfile.extension runtime has been loaded. - C-Pluff: INFO: [org.c-pluff.examples.cpfile.core] Plug-in org.c-pluff.examples.cpfile.extension is starting. - C-Pluff: INFO: [org.c-pluff.examples.cpfile.core] Plug-in org.c-pluff.examples.cpfile.extension has been started. - C-Pluff: INFO: [org.c-pluff.examples.cpfile.core] Plug-in org.c-pluff.examples.cpfile.special runtime has been loaded. - C-Pluff: INFO: [org.c-pluff.examples.cpfile.core] Plug-in org.c-pluff.examples.cpfile.special has been started. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core has been started. - /tmp/test.c: C source file - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core is stopping. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core has been stopped. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.special has been stopped. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.extension has been stopped. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core runtime has been unloaded. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.core has been uninstalled. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.extension runtime has been unloaded. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.extension has been uninstalled. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.cext has been uninstalled. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.special runtime has been unloaded. - C-Pluff: INFO: [loader] Plug-in org.c-pluff.examples.cpfile.special has been uninstalled. diff --git a/lib/cpluff/examples/cpfile/cpfile.bat b/lib/cpluff/examples/cpfile/cpfile.bat deleted file mode 100644 index 7427550782..0000000000 --- a/lib/cpluff/examples/cpfile/cpfile.bat +++ /dev/null @@ -1,5 +0,0 @@ -@REM Copyright 2007 Johannes Lehtinen -@REM This script is free software; Johannes Lehtinen gives unlimited -@REM permission to copy, distribute and modify it. - -@cpluff-loader -c cpfile\plugins -s org.c-pluff.examples.cpfile.core %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/lib/cpluff/examples/cpfile/cpfile.in b/lib/cpluff/examples/cpfile/cpfile.in deleted file mode 100644 index 2e84047630..0000000000 --- a/lib/cpluff/examples/cpfile/cpfile.in +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh - -# Copyright 2007 Johannes Lehtinen -# This script is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -prefix="@prefix@" -exec_prefix="@exec_prefix@" -exec "@CPLUFF_LOADER@" -c "@libdir@/cpfile/plugins" -s org.c-pluff.examples.cpfile.core "$@" diff --git a/lib/cpluff/examples/cpfile/plugins/Makefile.am b/lib/cpluff/examples/cpfile/plugins/Makefile.am deleted file mode 100644 index e8f56d453d..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -SUBDIRS = core special extension cext - -EXTRA_DIST = Makefile.nmake diff --git a/lib/cpluff/examples/cpfile/plugins/Makefile.nmake b/lib/cpluff/examples/cpfile/plugins/Makefile.nmake deleted file mode 100644 index 2dda56e1ca..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/Makefile.nmake +++ /dev/null @@ -1,9 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-SUBDIRS = core special extension cext
-TOP = ..\..
-
-include ..\..\common.nmake
diff --git a/lib/cpluff/examples/cpfile/plugins/cext/Makefile.am b/lib/cpluff/examples/cpfile/plugins/cext/Makefile.am deleted file mode 100644 index f5f59be877..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/cext/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -EXTRA_DIST = plugin.xml Makefile.nmake - -pluginsdir = $(libdir)/cpfile/plugins -plugindir = $(pluginsdir)/cext -plugin_DATA = plugin.xml diff --git a/lib/cpluff/examples/cpfile/plugins/cext/Makefile.nmake b/lib/cpluff/examples/cpfile/plugins/cext/Makefile.nmake deleted file mode 100644 index 638be08244..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/cext/Makefile.nmake +++ /dev/null @@ -1,15 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-TOP = ..\..\..
-
-include ..\..\..\common.nmake
-
-pluginsdir = $(bindir)\cpfile\plugins
-plugindir = $(pluginsdir)\cext
-
-install-local: all-local
- if not exist $(plugindir) mkdir $(plugindir)
- for %f in (plugin.xml) do copy /y %f $(plugindir)
diff --git a/lib/cpluff/examples/cpfile/plugins/cext/plugin.xml b/lib/cpluff/examples/cpfile/plugins/cext/plugin.xml deleted file mode 100644 index ff6182c287..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/cext/plugin.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<plugin - id="org.c-pluff.examples.cpfile.cext" - version="0.1" - name="File extensions for C source files" - provider-name="Johannes Lehtinen"> - <requires> - <c-pluff version="0.1"/> - <import plugin="org.c-pluff.examples.cpfile.extension" version="0.1"/> - </requires> - <extension - point="org.c-pluff.examples.cpfile.extension.file-types" - name="C source file types"> - <file-type description="C source file"> - <file-extension ext=".c"/> - </file-type> - <file-type description="C header file"> - <file-extension ext=".h"/> - </file-type> - <file-type description="C++ source file"> - <file-extension ext=".cpp"/> - <file-extension ext=".cxx"/> - </file-type> - <file-type description="C++ header file"> - <file-extension ext=".hpp"/> - <file-extension ext=".H"/> - </file-type> - </extension> -</plugin> diff --git a/lib/cpluff/examples/cpfile/plugins/core/Makefile.am b/lib/cpluff/examples/cpfile/plugins/core/Makefile.am deleted file mode 100644 index 542f2a87e0..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -LIBS = @LIBS@ - -EXTRA_DIST = plugin.xml classifiers.xsd Makefile.nmake - -pluginsdir = $(libdir)/cpfile/plugins -plugindir = $(pluginsdir)/core - -plugin_LTLIBRARIES = libcore.la -plugin_DATA = plugin.xml classifiers.xsd -plugin_HEADERS = core.h - -libcore_la_SOURCES = core.c core.h -libcore_la_LDFLAGS = -no-undefined -module -avoid-version diff --git a/lib/cpluff/examples/cpfile/plugins/core/Makefile.nmake b/lib/cpluff/examples/cpfile/plugins/core/Makefile.nmake deleted file mode 100644 index dad5943c6a..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/Makefile.nmake +++ /dev/null @@ -1,25 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-TOP = ..\..\..
-
-include ..\..\..\common.nmake
-
-pluginsdir = $(bindir)\cpfile\plugins
-plugindir = $(pluginsdir)\core
-
-libcore_OBJS = core.obj
-
-all-local: libcore.dll
-
-install-local: all-local
- if not exist $(plugindir) mkdir $(plugindir)
- for %f in (plugin.xml classifiers.xsd libcore.dll) do copy /y %f $(plugindir)
-
-clean-local:
- for %f in ($(libcore_OBJS) libcore.*) do if exist %f del %f
-
-libcore.dll: $(libcore_OBJS)
- cl /nologo /LD /MD /Fe$@ $(libcore_OBJS) $(cplibdir)\libcpluff.lib
diff --git a/lib/cpluff/examples/cpfile/plugins/core/classifiers.xsd b/lib/cpluff/examples/cpfile/plugins/core/classifiers.xsd deleted file mode 100644 index 357e8c09d9..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/classifiers.xsd +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> - <xs:element name="extension"> - <xs:complexType> - <xs:attribute name="point" type="xs:string" use="required"/> - <xs:attribute name="id" type="simpleIdentifier"/> - <xs:attribute name="name" type="xs:string"/> - - <!-- - * The classifier is the name of a symbol pointing to - * classifier_t strucutre. Priority determines the order - * the file classifiers are tried. - --> - <xs:attribute name="classifier" type="xs:string" use="required"/> - <xs:attribute name="priority" type="xs:integer" use="required"/> - - </xs:complexType> - </xs:element> - <xs:simpleType name="simpleIdentifier"> - <xs:restriction base="xs:string"> - <xs:pattern value="[^.]+"/> - </xs:restriction> - </xs:simpleType> -</xs:schema> diff --git a/lib/cpluff/examples/cpfile/plugins/core/core.c b/lib/cpluff/examples/cpfile/plugins/core/core.c deleted file mode 100644 index 019e41cd88..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/core.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <cpluff.h> -#include "core.h" - - -/* ------------------------------------------------------------------------ - * Data types - * ----------------------------------------------------------------------*/ - -/** Type for plugin_data_t structure */ -typedef struct plugin_data_t plugin_data_t; - -/** Type for registered_classifier_t structure */ -typedef struct registered_classifier_t registered_classifier_t; - -/** Plug-in instance data */ -struct plugin_data_t { - - /** The plug-in context */ - cp_context_t *ctx; - - /** Number of registered classifiers */ - int num_classifiers; - - /** An array of registered classifiers */ - registered_classifier_t *classifiers; -}; - -/** Registered classifier information */ -struct registered_classifier_t { - - /** The priority of the classifier */ - int priority; - - /** The classifier data */ - classifier_t *classifier; -}; - - -/* ------------------------------------------------------------------------ - * Internal functions - * ----------------------------------------------------------------------*/ - -/** - * A run function for the core plug-in. In this case this function acts as - * the application main function so there is no need for us to split the - * execution into small steps. Rather, we execute the whole main loop at - * once to make it simpler. - */ -static int run(void *d) { - plugin_data_t *data = d; - char **argv; - int argc; - int i; - - // Read arguments and print usage, if no arguments given - argv = cp_get_context_args(data->ctx, &argc); - if (argc < 2) { - fputs("usage: cpfile <file> [<file>...]\n", stdout); - return 0; - } - - // Go through all files listed as command arguments - for (i = 1; argv[i] != NULL; i++) { - int j; - int classified = 0; - - // Print file name - printf("%s: ", argv[i]); - - // Try classifiers in order of descending priority - for (j = 0; !classified && j < data->num_classifiers; j++) { - classifier_t *cl - = data->classifiers[j].classifier; - - classified = cl->classify(cl->data, argv[i]); - } - - // Check if unknown file - if (!classified) { - fputs("unknown file type\n", stdout); - } - } - - // All done - return 0; -} - -/** - * Creates a new plug-in instance. - */ -static void *create(cp_context_t *ctx) { - plugin_data_t *data = malloc(sizeof(plugin_data_t)); - if (data != NULL) { - data->ctx = ctx; - data->num_classifiers = 0; - data->classifiers = NULL; - } else { - cp_log(ctx, CP_LOG_ERROR, - "Insufficient memory for plug-in data."); - } - return data; -} - -/** - * Compares two registered classifiers according to priority. - */ -static int comp_classifiers(const registered_classifier_t *c1, - const registered_classifier_t *c2) { - return c2->priority - c1->priority; -} - -/** - * Initializes and starts the plug-in. - */ -static int start(void *d) { - plugin_data_t *data = d; - cp_extension_t **cl_exts; - int num_cl_exts; - cp_status_t status; - int i; - - // Obtain list of registered classifiers - cl_exts = cp_get_extensions_info( - data->ctx, - "org.c-pluff.examples.cpfile.core.classifiers", - &status, - &num_cl_exts - ); - if (cl_exts == NULL) { - - // An error occurred and framework logged it - return status; - } - - // Allocate memory for classifier information, if any - if (num_cl_exts > 0) { - data->classifiers = malloc( - num_cl_exts * sizeof(registered_classifier_t) - ); - if (data->classifiers == NULL) { - - // Memory allocation failed - cp_log(data->ctx, CP_LOG_ERROR, - "Insufficient memory for classifier list."); - return CP_ERR_RESOURCE; - } - } - - /* Resolve classifier functions. This will implicitly start - * plug-ins providing the classifiers. */ - for (i = 0; i < num_cl_exts; i++) { - const char *str; - int pri; - classifier_t *cl; - - // Get the classifier function priority - str = cp_lookup_cfg_value( - cl_exts[i]->configuration, "@priority" - ); - if (str == NULL) { - - // Classifier is missing mandatory priority - cp_log(data->ctx, CP_LOG_ERROR, - "Ignoring classifier without priority."); - continue; - } - pri = atoi(str); - - // Resolve classifier data pointer - str = cp_lookup_cfg_value( - cl_exts[i]->configuration, "@classifier"); - if (str == NULL) { - - // Classifier symbol name is missing - cp_log(data->ctx, CP_LOG_ERROR, - "Ignoring classifier without symbol name."); - continue; - } - cl = cp_resolve_symbol( - data->ctx, - cl_exts[i]->plugin->identifier, - str, - NULL - ); - if (cl == NULL) { - - // Could not resolve classifier symbol - cp_log(data->ctx, CP_LOG_ERROR, - "Ignoring classifier which could not be resolved."); - continue; - } - - // Add classifier to the list of registered classifiers - data->classifiers[data->num_classifiers].priority = pri; - data->classifiers[data->num_classifiers].classifier = cl; - data->num_classifiers++; - } - - // Release extension information - cp_release_info(data->ctx, cl_exts); - - // Sort registered classifiers according to priority - if (data->num_classifiers > 1) { - qsort(data->classifiers, - data->num_classifiers, - sizeof(registered_classifier_t), - (int (*)(const void *, const void *)) comp_classifiers); - } - - // Register run function to do the real work - cp_run_function(data->ctx, run); - - // Successfully started - return CP_OK; -} - -/** - * Releases resources from other plug-ins. - */ -static void stop(void *d) { - plugin_data_t *data = d; - int i; - - // Release classifier data, if any - if (data->classifiers != NULL) { - - // Release classifier pointers - for (i = 0; i < data->num_classifiers; i++) { - cp_release_symbol( - data->ctx, data->classifiers[i].classifier - ); - } - - // Free local data - free(data->classifiers); - data->classifiers = NULL; - data->num_classifiers = 0; - } -} - -/** - * Destroys a plug-in instance. - */ -static void destroy(void *d) { - free(d); -} - - -/* ------------------------------------------------------------------------ - * Exported runtime information - * ----------------------------------------------------------------------*/ - -/** - * Plug-in runtime information for the framework. The name of this symbol - * is stored in the plug-in descriptor. - */ -CP_EXPORT cp_plugin_runtime_t cp_ex_cpfile_core_funcs = { - create, - start, - stop, - destroy -}; diff --git a/lib/cpluff/examples/cpfile/plugins/core/core.h b/lib/cpluff/examples/cpfile/plugins/core/core.h deleted file mode 100644 index dea108906d..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/core.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. - */ - -#ifndef CORE_H_ -#define CORE_H_ - -/** - * A function that classifies a file. If the classification succeeds then - * the function should print file description to standard output and - * return a non-zero value. Otherwise the function must return zero. - * - * @param data classified specific runtime data - * @param path the file path - * @return whether classification was successful - */ -typedef int (*classify_func_t)(void *data, const char *path); - -/** A short hand typedef for classifier_t structure */ -typedef struct classifier_t classifier_t; - -/** - * A container for classifier information. - */ -struct classifier_t { - - /** Classifier specific runtime data */ - void *data; - - /** The classifying function */ - classify_func_t classify; -}; - -#endif /*CORE_H_*/ diff --git a/lib/cpluff/examples/cpfile/plugins/core/plugin.xml b/lib/cpluff/examples/cpfile/plugins/core/plugin.xml deleted file mode 100644 index eb38bf4ef0..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/core/plugin.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<plugin - id="org.c-pluff.examples.cpfile.core" - version="0.1" - name="Core logic for cpfile" - provider-name="Johannes Lehtinen"> - <requires> - <c-pluff version="0.1"/> - </requires> - <runtime library="libcore" funcs="cp_ex_cpfile_core_funcs"/> - <extension-point - id="classifiers" - name="File classifiers" - schema="classifiers.xsd"/> -</plugin> diff --git a/lib/cpluff/examples/cpfile/plugins/extension/Makefile.am b/lib/cpluff/examples/cpfile/plugins/extension/Makefile.am deleted file mode 100644 index f9c7fc4257..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/extension/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -LIBS = @LIBS@ - -CPPFLAGS = -I$(srcdir)/../core @CPPFLAGS@ - -EXTRA_DIST = plugin.xml file_types.xsd Makefile.nmake - -pluginsdir = $(libdir)/cpfile/plugins -plugindir = $(pluginsdir)/extension - -plugin_LTLIBRARIES = libextension.la -plugin_DATA = plugin.xml file_types.xsd - -libextension_la_SOURCES = extension.c -libextension_la_LDFLAGS = -no-undefined -module -avoid-version diff --git a/lib/cpluff/examples/cpfile/plugins/extension/Makefile.nmake b/lib/cpluff/examples/cpfile/plugins/extension/Makefile.nmake deleted file mode 100644 index b6829b89f7..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/extension/Makefile.nmake +++ /dev/null @@ -1,27 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-TOP = ..\..\..
-
-include ..\..\..\common.nmake
-
-CFLAGS = /I..\core $(CFLAGS)
-
-pluginsdir = $(bindir)\cpfile\plugins
-plugindir = $(pluginsdir)\extension
-
-libextension_OBJS = extension.obj
-
-all-local: libextension.dll
-
-install-local: all-local
- if not exist $(plugindir) mkdir $(plugindir)
- for %f in (plugin.xml file_types.xsd libextension.dll) do copy /y %f $(plugindir)
-
-clean-local:
- for %f in ($(libextension_OBJS) libextension.*) do if exist %f del %f
-
-libextension.dll: $(libextension_OBJS)
- cl /nologo /LD /MD /Fe$@ $(libextension_OBJS) $(cplibdir)\libcpluff.lib
diff --git a/lib/cpluff/examples/cpfile/plugins/extension/extension.c b/lib/cpluff/examples/cpfile/plugins/extension/extension.c deleted file mode 100644 index e453fb8919..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/extension/extension.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <cpluff.h> -#include <core.h> - - -/* ------------------------------------------------------------------------ - * Internal functions - * ----------------------------------------------------------------------*/ - -static int is_of_type(const char *path, const cp_cfg_element_t *type); - -/** - * Classifies a file based on file extension. This classifier uses extensions - * installed at the file type extension point. Therefore we need pointer to - * the plug-in context to access the extensions. A plug-in instance initializes - * the classifier structure with the plug-in context pointer and registers a - * virtual symbol pointing to the classifier. - */ -static int classify(void *d, const char *path) { - cp_context_t *ctx = d; - cp_extension_t **exts; - const char *type = NULL; - int i; - - // Go through all extensions registered at the extension point - exts = cp_get_extensions_info(ctx, "org.c-pluff.examples.cpfile.extension.file-types", NULL, NULL); - if (exts == NULL) { - cp_log(ctx, CP_LOG_ERROR, "Could not resolve file type extensions."); - return 0; - } - for (i = 0; type == NULL && exts[i] != NULL; i++) { - int j; - - // Go through all file types provided by the extension - for (j = 0; type == NULL && j < exts[i]->configuration->num_children; j++) { - cp_cfg_element_t *elem = exts[i]->configuration->children + j; - const char *desc = NULL; - - if (strcmp(elem->name, "file-type") == 0 - && (desc = cp_lookup_cfg_value(elem, "@description")) != NULL - && (is_of_type(path, elem))) { - type = desc; - } - } - } - - // Release extension information - cp_release_info(ctx, exts); - - // Print file type if recognized, otherwise try other classifiers - if (type != NULL) { - fputs(type, stdout); - putchar('\n'); - return 1; - } else { - return 0; - } -} - -/** - * Returns whether the specified file is of the type matching the specified - * file-type element. - */ -static int is_of_type(const char *path, const cp_cfg_element_t *type) { - int i; - int iot = 0; - - /* Go through all extensions specified for the type */ - for (i = 0; !iot && i < type->num_children; i++) { - cp_cfg_element_t *ee = type->children + i; - const char *ext; - - iot = (strcmp(ee->name, "file-extension") == 0 - && (ext = cp_lookup_cfg_value(ee, "@ext")) != NULL - && strlen(path) >= strlen(ext) - && strcmp(path + (strlen(path) - strlen(ext)), ext) == 0); - } - - return iot; -} - -/** - * Creates a new plug-in instance. We use classifier instance as plug-in - * instance because it includes all the data our plug-in instance needs. - */ -static void *create(cp_context_t *ctx) { - classifier_t *cl; - - cl = malloc(sizeof(classifier_t)); - if (cl != NULL) { - cl->data = ctx; - cl->classify = classify; - } - return cl; -} - -/** - * Initializes and starts the plug-in. - */ -static int start(void *d) { - classifier_t *cl = d; - cp_context_t *ctx = cl->data; - - return cp_define_symbol(ctx, "cp_ex_cpfile_extension_classifier", cl); -} - -/** - * Destroys a plug-in instance. - */ -static void destroy(void *d) { - if (d != NULL) { - free(d); - } -} - - -/* ------------------------------------------------------------------------ - * Exported classifier information - * ----------------------------------------------------------------------*/ - -/** - * Plug-in runtime information for the framework. The name of this symbol - * is stored in the plug-in descriptor. - */ -CP_EXPORT cp_plugin_runtime_t cp_ex_cpfile_extension_funcs = { - create, - start, - NULL, - destroy -}; diff --git a/lib/cpluff/examples/cpfile/plugins/extension/file_types.xsd b/lib/cpluff/examples/cpfile/plugins/extension/file_types.xsd deleted file mode 100644 index c6ed1844f2..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/extension/file_types.xsd +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> - <xs:element name="extension"> - <xs:complexType> - <xs:sequence> - <xs:element maxOccurs="unbounded" ref="file-type"/> - </xs:sequence> - <xs:attribute name="point" type="xs:string" use="required"/> - <xs:attribute name="id" type="simpleIdentifier"/> - <xs:attribute name="name" type="xs:string"/> - </xs:complexType> - </xs:element> - <xs:element name="file-type"> - <xs:complexType> - <xs:sequence> - <xs:element maxOccurs="unbounded" ref="file-extension"/> - </xs:sequence> - <xs:attribute name="description" type="xs:string" use="required"/> - </xs:complexType> - </xs:element> - <xs:element name="file-extension"> - <xs:complexType> - <xs:attribute name="ext" type="xs:string" use="required"/> - </xs:complexType> - </xs:element> - <xs:simpleType name="simpleIdentifier"> - <xs:restriction base="xs:string"> - <xs:pattern value="[^.]+"/> - </xs:restriction> - </xs:simpleType> -</xs:schema> diff --git a/lib/cpluff/examples/cpfile/plugins/extension/plugin.xml b/lib/cpluff/examples/cpfile/plugins/extension/plugin.xml deleted file mode 100644 index 4bac8d0d16..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/extension/plugin.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<plugin - id="org.c-pluff.examples.cpfile.extension" - version="0.1" - name="File extension classification" - provider-name="Johannes Lehtinen"> - <requires> - <c-pluff version="0.1"/> - <import plugin="org.c-pluff.examples.cpfile.core" version="0.1"/> - </requires> - <runtime library="libextension" funcs="cp_ex_cpfile_extension_funcs"/> - <extension-point - id="file-types" - name="File types by extension" - schema="file_types.xsd"/> - <extension - point="org.c-pluff.examples.cpfile.core.classifiers" - name="File extension classifier" - priority="20" - classifier="cp_ex_cpfile_extension_classifier"/> - <extension - point="org.c-pluff.examples.cpfile.extension.file-types" - name="Base file types"> - <file-type description="text file"> - <file-extension ext=".txt"/> - <file-extension ext=".text"/> - </file-type> - </extension> -</plugin> diff --git a/lib/cpluff/examples/cpfile/plugins/special/Makefile.am b/lib/cpluff/examples/cpfile/plugins/special/Makefile.am deleted file mode 100644 index b65cc74581..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/special/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -# Copyright 2007 Johannes Lehtinen -# This Makefile is free software; Johannes Lehtinen gives unlimited -# permission to copy, distribute and modify it. - -LIBS = @LIBS@ - -CPPFLAGS = -I$(srcdir)/../core @CPPFLAGS@ - -EXTRA_DIST = plugin.xml Makefile.nmake - -pluginsdir = $(libdir)/cpfile/plugins -plugindir = $(pluginsdir)/special - -plugin_LTLIBRARIES = libspecial.la -plugin_DATA = plugin.xml - -libspecial_la_SOURCES = special.c -libspecial_la_LDFLAGS = -no-undefined -module -avoid-version diff --git a/lib/cpluff/examples/cpfile/plugins/special/Makefile.nmake b/lib/cpluff/examples/cpfile/plugins/special/Makefile.nmake deleted file mode 100644 index 39f3a46365..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/special/Makefile.nmake +++ /dev/null @@ -1,27 +0,0 @@ -# C-Pluff examples build system for MSVC
-# Copyright 2007 Johannes Lehtinen
-# This file is free software; Johannes Lehtinen gives unlimited permission
-# to copy, distribute and modify it.
-
-TOP = ..\..\..
-
-include ..\..\..\common.nmake
-
-CFLAGS = /I..\core $(CFLAGS)
-
-pluginsdir = $(bindir)\cpfile\plugins
-plugindir = $(pluginsdir)\special
-
-libspecial_OBJS = special.obj
-
-all-local: libspecial.dll
-
-install-local: all-local
- if not exist $(plugindir) mkdir $(plugindir)
- for %f in (plugin.xml libspecial.dll) do copy /y %f $(plugindir)
-
-clean-local:
- for %f in ($(libspecial_OBJS) libspecial.*) do if exist %f del %f
-
-libspecial.dll: $(libspecial_OBJS)
- cl /nologo /LD /MD /Fe$@ $(libspecial_OBJS) $(cplibdir)\libcpluff.lib
diff --git a/lib/cpluff/examples/cpfile/plugins/special/plugin.xml b/lib/cpluff/examples/cpfile/plugins/special/plugin.xml deleted file mode 100644 index a04f6b0eec..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/special/plugin.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. ---> -<plugin - id="org.c-pluff.examples.cpfile.special" - version="0.1" - name="Special file classification" - provider-name="Johannes Lehtinen"> - <requires> - <c-pluff version="0.1"/> - <import plugin="org.c-pluff.examples.cpfile.core" version="0.1"/> - </requires> - <runtime library="libspecial"/> - <extension - point="org.c-pluff.examples.cpfile.core.classifiers" - name="Special file classifier" - priority="100" - classifier="cp_ex_cpfile_special_classifier"/> -</plugin> diff --git a/lib/cpluff/examples/cpfile/plugins/special/special.c b/lib/cpluff/examples/cpfile/plugins/special/special.c deleted file mode 100644 index dc357c966b..0000000000 --- a/lib/cpluff/examples/cpfile/plugins/special/special.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2007 Johannes Lehtinen - * This file is free software; Johannes Lehtinen gives unlimited - * permission to copy, distribute and modify it. - */ - -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <cpluff.h> -#include <core.h> - -#if defined(HAVE_LSTAT) -#define STAT lstat -#elif defined(HAVE_STAT) -#define STAT stat -#endif - - -/* ------------------------------------------------------------------------ - * Internal functions - * ----------------------------------------------------------------------*/ - -/** - * Classifies a file by using stat(2). This classifier does not need - * any classifier data so we use NULL as dummy data pointer. Therefore - * we do not need a plug-in instance either as there is no data to be - * initialized. - */ -static int classify(void *dummy, const char *path) { -#ifdef STAT - struct stat s; - const char *type; - - // Stat the file - if (STAT(path, &s)) { - fflush(stdout); - perror("stat failed"); - - // No point for other classifiers to classify this - return 1; - } - - // Check if this is a special file - if ((s.st_mode & S_IFMT) == S_IFDIR) { - type = "directory"; -#ifdef S_IFCHR - } else if ((s.st_mode & S_IFMT) == S_IFCHR) { - type = "character device"; -#endif -#ifdef S_IFBLK - } else if ((s.st_mode & S_IFMT) == S_IFBLK) { - type = "block device"; -#endif -#ifdef S_IFLNK - } else if ((s.st_mode & S_IFMT) == S_IFLNK) { - type = "symbolic link"; -#endif - } else { - - // Did not recognize it, let other plug-ins try - return 0; - } - - // Print recognized file type - fputs(type, stdout); - putchar('\n'); - return 1; -#else - return 0; -#endif -} - - -/* ------------------------------------------------------------------------ - * Exported classifier information - * ----------------------------------------------------------------------*/ - -CP_EXPORT classifier_t cp_ex_cpfile_special_classifier = { NULL, classify }; |