How to know, libxslt support EXSLT or not - osx-snow-leopard

I am on MacOSX 10.7, and having libxml2 version as i can see from libxml2/xmlversion.h is
define LIBXML_DOTTED_VERSION "2.7.3"
that means 2.7.3
My application also using xslt, for so it has libxslt processor, which comes along with the libxml2
some of the file may contains math function, something like this,
<xsl:variable name="angle"
select="math:atan2(30, 30)
- math:atan2(30, 30)"/>
going through site http://www.exslt.org/howto.html it says, xslt processor should support EXSLT Function,
does anyone has any idea, how i can confirm it ?

Some how i got it fixed,below are steps,
1 -- I had to install libxml2 , and remove reference of libxml2 which was available through SDK,
2 -- Compile libxslt too , and don't include which is there in the SDK,
3 -- In the source code before applying style sheet call anyone of these function
EXSLTPUBFUN void EXSLTCALL exsltMathRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltSetsRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltFuncRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltStrRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltDateRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltSaxonRegister (void);
EXSLTPUBFUN void EXSLTCALL exsltDynRegister(void);
4 -- you might need to change the XSL file to include the Name space for math and to import it
xmlns:math="http://exslt.org/math"
xmlns:jDouble="java.lang.Double"
exclude-result-prefixes="v math"
xmlns="http://www.w3.org/2000/svg"
version="1.0">
<xsl:import href="math.xsl" />
Thanks for looking at it.

Related

Using Go code in an existing C project

Ever since Go 1.5 came out, I started taking another look at how I could integrate it into an existing project of mine.
The project's codebase is written entirely in C for low level access to to hardware and other fun stuff. However, some of the higher level things are tedious, and I would like to start writing them in a higher level language (Go)
Is there any way I can call Go code from a C program? I installed Go 1.5, which added -buildmode=c-archive (https://golang.org/s/execmodes) which I am trying to get working.
However, I can't seem to get Go to generate the appropriate header files to allow my project to actually compile. When I generate the archive, I see the function in the exported symbols (using objdump), but without the header files to include gcc complains about the function not existing (as expected)
I'm quite new to Go - however, I love the language and would like to make use of it. Is there any idiomatic way ("idiomatic" gets used a lot in the world of Go I see...) to get this to play nicely with each other?
The reason I asked this question and specifically mentioned Go 1.5 is that according to this document, https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelrAP0NqSS_00RgZQ/edit?pli=1#heading=h.1gw5ytjfcoke
Go 1.5 added support for non-Go programs to call Go code. Specifically, mentioned under the section "Go code linked into, and called from, a non-Go program"
To build an archive callable from C, you will need to mark them as exported CGo symbols.
For example, if I create a file foo.go with the following contents:
package main
import (
"C"
"fmt"
)
//export PrintInt
func PrintInt(x int) {
fmt.Println(x)
}
func main() {}
The important things to note are:
The package needs to be called main
You need to have a main function, although it can be empty.
You need to import the package C
You need special //export comments to mark the functions you want callable from C.
I can compile it as a C callable static library with the following command:
go build -buildmode=c-archive foo.go
The results will be an archive foo.a and a header foo.h. In the header, we get the following (eliding irrelevant parts):
...
typedef long long GoInt64;
...
typedef GoInt64 GoInt;
...
extern void PrintInt(GoInt p0);
...
So that's enough to call the exported function. We can write a simple C program that calls it like so:
#include "foo.h"
int main(int argc, char **argv) {
PrintInt(42);
return 0;
}
We can compile it with a command like:
gcc -pthread foo.c foo.a -o foo
The -pthread option is needed because the Go runtime makes use of threads. When I run the resulting executable it prints 42.
The code above work just fine, but gcc will complain about functions and headers.
The includes should be:
#define _GNU_SOURCE
#include <stdio.h>
#include "mygopkg.h"
If you forget the #define _GNU_SOURCE, the gcc will complain:
warning: implicit declaration of function 'asprintf'; did you mean 'vsprintf'? [-Wimplicit-function-declaration]
If you forget the #include "mygopkg.h", the gcc will complain:
warning: implicit declaration of function 'PrintString' [-Wimplicit-function-declaration]
The last but not less important. The build command line I recommend for production code is:
go build -ldflags "-s -w" -buildmode c-archive -o mygopkg.a
It'll save you 53% size of final mygopkg.a.

How to disable "curses.h" header (a part of "stdio.h in Xcode 6.3 OSX Yosemite) to avoid conflicting function declarations

I'm trying to build a project in Xcode but I get the following errors Implicit declaration of function 'clear' is invalid in C99 and Conflicting types for 'clear'.
Here's the code:
//main.c
#include <stdio.h>
#include "tree.h"
int main(){
clear(); // Implicit declaration of function 'clear' is invalid in C99
return 0;
}
//tree.c
#include <stdio.h>
#include "tree.h"
void clear(){ ///Conflicting types for 'clear'
printf("Command clear.\n");
}
//tree.h
#include <stdio.h>
void clear(); ///Conflicting types for 'clear'
Why do I get these errors and warnings? I've tried to search for the solution on StackOverflow, but all the related answers where about the case when there were no #include of some sort.
'clear' is not a keyword in C so it's not the case, is it? (source: http://aboutc.weebly.com/keywords.html)
Related topics (do not answer my question although they are actually related):
Implicit declaration of function 'sum' is invalid in C99
Implicit declaration of function is invalid in C99
Thanks for any help.
UPDATE!
It turns out that changing the name of the clear funtcion to a cleark function solved the problem. Nevertheless it does not make any sense to me yet.
UPDATE 2!
I based my project on the command line tool template from Xcode 6.3 on Mac OS 10.10. Because of that Xcode has automatically added some libraries and flags to the project's compiler. What's the most important here is that the curses.h header has been added and this header already contains the clear() function.
Here's the Conflicting types for 'clear' error log:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/curses.h:541:28: Previous declaration is here
I've tried to remove the -lcurses from the compiler's flags manually, but I couldn't locate such settings. Is there any another way to build the project? (All in all my goal is to be able to use the Xcode's debugger when the project expands)
UPDATE 3!
According to what Paul Griffiths discovered and published in the comment below the problem is following:
I can indeed replicate this problem with Xcode 6.3.1 with only the code presented. For some reason, stdio.h seems to be including curses.h (i.e. if you don't include stdio.h, this issue goes away), and I haven't been quickly able to find a way to stop it doing that. This seems to be problematic, since standard headers should not import random symbols into the global namespace without an easy and obvious way to turn it off.
Normally I run the C preprocessor to see what the compiler actually parses. However, following Xcode Preprocessor Output to examine the preprocessor output with Xcode does not achieve that - it is translating the #include to #import. Here is what the preprocessor view shows me:
// Preprocessed output for tree.c
// Generated at 9:24:57 PM on Friday, May 1, 2015
// Using Debug configuration, x86_64 architecture for curses-vs-stdio target of curses-vs-stdio project
# 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 322 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c" 2
# 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.h" 1
void clear(void);
#import Darwin.C.stdio; /* clang -E: implicit import for "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/stdio.h" */
# 5 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c" 2
void clear(void) {
printf("Command clear.\n");
}
Apparently the problem is Xcode's use of modules rather than stdio.h including curses.h. The "Darwin" module is where the problem lies.
In fact, if I disable modules (using the hint in Enable Clang Modules, Disable Auto Linking), the build problem goes away. This is
in Build Settings
section Apple LLVM 6.1 - Language - Modules
setting Enable Modules (C and Objective-C)
As a further hint to the problem, having rearranged the example slightly (putting the prototype before the include), I see a message complaining about overloading — but that is not C.
Perhaps Apple will fix this in the next release.
You are including "trie.h", not "tree.h".
But maybe that's just you being careless when posting the code...
I bet there is another function named clear () defined somewhere. Possibly in your version of stdio.h.

Is it possible to develop linux kernel module in CLion?

I want to develop some small linux kernel modules in CLion. For example, I want to compile these files:
stack.h:
#ifndef _LL_STACK_H
#define _LL_STACK_H
#include <linux/list.h>
typedef struct stack_entry {
struct list_head lh;
void *data;
} stack_entry_t;
stack_entry_t* create_stack_entry(void *data);
void delete_stack_entry(stack_entry_t *entry);
void stack_push(struct list_head *stack, stack_entry_t *entry);
stack_entry_t* stack_pop(struct list_head *stack);
#define stack_empty(stack) list_empty((stack))
#define STACK_DATA(stack_entry, data_ptr_type) \
((data_ptr_type)(stack_entry)->data)
#define STACK_DATA_RESET(stack_entry, new_data) \
do { \
(stack_entry)->data = new_data; \
} while(0)
#endif //_LL_STACK_H
main.c:
#include <stdio.h>
#include "stack.h"
int main() {
printf("hello");
return 0;
}
Is it possible to configure CMakeLists.txt to complete my task? I try to add some directories (linux, include, kernel), but I have no success.
Yes, It is. But you will need to write make file for building kernel module.
Update 1:
I recommend QtCreator for writing linux kernel module.
See my manual
Update 2:
I also recommend eclipse cdt.
See eclipse manual about how to prepare it for linux kernel.
The approach I use to spelunk the linux kernel via clion is:
create a compile_commands.json for the kernel using an intercepted build
use a ruby script to convert compile_commands.json into an clion friendly CMakeLists.txt
This allows for both code navigation and also a reasonable editing experience.
See for more details https://github.com/habemus-papadum/kernel-grok
If you are only talking about proper auto-suggestions but are fine with invoking "make" by yourself then check this demo setup: https://gitlab.com/phip1611/cmake-kernel-module
It's a simplified version of https://gitlab.com/christophacham/cmake-kernel-module/-/blob/master/CMakeLists.txt (I forked it).
I use it for both: out-of-tree kernel module development (standalone development) as well as in-tree development.
Always make sure to have latest kernel header files installed!
$ sudo apt install kernel-headers-$(uname -r)

Lua 5.2: Bindings andNative Extensions: lua_register() causes segfaults due to lack of LUA_GLOBALSINDEX

Lua tutorials all over the net show the use of lua_register() to expose the functions implemented in your extension DLL or so:
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static int pushlua3(lua_State *L)
{
lua_pushnumber(L, 3);
return 1;
}
int luaopen_lua3pushbinder(lua_State *L)
{
lua_register(L,"pushlua3", pushlua3);
return 0;
}
lua_register() is a macro and not a function, this is from the 5.2 manual:
http://www.lua.org/manual/5.2/manual.html#lua_register
[-0, +0, e]
void lua_register (lua_State *L,
const char *name,
lua_CFunction f);
Sets the C function f as the new value of global name. It is defined
as a macro:
#define lua_register(L,n,f) \
(lua_pushcfunction(L, f), lua_setglobal(L, n))
if you use the functions separately, lua_pushcfunction is fine, but lua_setglobal crashes because it's trying to reference LUA_GLOBALSINDEX and that fails at runtime, not compile time.
So what is the right way to implement lua_register() now?
I would sort of have expected that when Lua moved to 5.2 and redid the concepts manifested with LUA_GLOBALSINDEX and thus lua_register() it would have been reasonable to change lua_register() so that it did it the 'new' way.
So, is there a header update that Ubuntu didn't pick up for lua5.2? should i have an include path that points to /usr/include/lua5.2 and then I wouldn't face this problem? I only have a Lua 5.1 include directory on my box.
tnx for any help you can provide.
The answer is that on Ubuntu 13.04 the Ubuntu Software Center informed me of the existence of lua5.2 but did not inform me of the existence of liblua5.2-0-dev.
I used apt-get to find it based on the suggestion for lhf that I needed the 5.2 headers.
My lua script calling a native dll/so demo went off just fine as a result

How to change file permissions from Java 1.4.2?

I'm looking for a code fragment, using which I must be to change the file permissions on unix. My project runs on java 1.4.2 ..
just a sample code example or methods which needs to be used will do..
Regards,
Senny
You're not the only one:
How to change the file's permission and last modified in Java?
You could, in principle, use Runtime.exec("chmod ...") if the existing java.io.File methods aren't enough. But it wouldn't be portable.
You could also look at the Gnu ClassPath implementation of java.lang.File
They implemented the function based on JNI calls:
native/jni/java-io/java_io_VMFile.c:
set_file_permissions: new helper function.
Java_java_io_VMFile_setReadable: new native method to bakcup 1.6 methods
in VMFile.java.
VMFile.java declares the call:
/**
* Set the write permission of the file.
*/
public static synchronized native boolean setWritable(String path,
boolean writable,
boolean ownerOnly);
native/jni/java-io/java_io_VMFile.c does implement the desired function...
JNIEXPORT jboolean JNICALL
Java_java_io_VMFile_setWritable (JNIEnv *env,
jclass clazz __attribute__ ((__unused__)),
jstring name,
jboolean writable,
jboolean ownerOnly)
{
return set_file_permissions (env, name, writable, ownerOnly,
CPFILE_FLAG_WRITE);
}
[...]
result = cpio_chmod (filename, permissions);
So... if you really want it, it is possible to implement it, by looking at the source of cpio.c: it calls chmod from libc standard library (LibGW32C does port some of those functions to Windows)
Just to be extra clear: Java 1.6 introduces getters/setters like File.canExecute() and File.setExecutable(boolean) for file permissions. So one solution is to use the latest JDK instead of the 1.4 you mentioned. Otherwise, as suggested, you can try to backport, or call out to platform-specific commands.

Resources