fbfrog header translator

User projects written in or related to FreeBASIC.
speedfixer
Posts: 389
Joined: Nov 28, 2012 1:27
Location: California

Re: fbfrog header translator

Postby speedfixer » Nov 29, 2017 6:41

I am going back over the source.

The original header had guards on all those error constants; fbfrog removed the guards creating the eventual duplicate declarations.

If a guard was on any line of code, why would fbfrog remove them?

original from nn.h in the source:

Code: Select all

#ifndef EINVAL
#define EINVAL (NN_HAUSNUMERO + 14)
#endif

translated by fbfrog to:

Code: Select all

const EINVAL = NN_HAUSNUMERO + 14

This produced:

Code: Select all

/rdkl/FB_net/nanomsg/target/nn.bi(62) error 14: Expected identifier in 'const EINVAL = NN_HAUSNUMERO + 14'

This error was only for the duplicates.

When I changed them to #defines, then the duplicates were flagged as duplicated definitions.

The implications of the guards in the original would be that just remartking them out in the resultant code would be the best choice (or better, laeving the guards in place.)

If fbfrog recursed over the includes, why wouldn't it pick them up before the changes?

fbfrog DID properly put the FB crt includes at the top of the resultant nn.bi file.


Food for thought.

Full source of the particular file (copyright removed), nn.h:

Code: Select all

#ifndef NN_H_INCLUDED
#define NN_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

#include <errno.h>
#include <stddef.h>
#include <stdint.h>

/*  Handle DSO symbol visibility. */
#if !defined(NN_EXPORT)
#    if defined(_WIN32) && !defined(NN_STATIC_LIB)
#        if defined NN_SHARED_LIB
#            define NN_EXPORT __declspec(dllexport)
#        else
#            define NN_EXPORT __declspec(dllimport)
#        endif
#    else
#        define NN_EXPORT extern
#    endif
#endif

/******************************************************************************/
/*  ABI versioning support.                                                   */
/******************************************************************************/

/*  Don't change this unless you know exactly what you're doing and have      */
/*  read and understand the following documents:                              */
/*  www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html     */
/*  www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html  */

/*  The current interface version. */
#define NN_VERSION_CURRENT 5

/*  The latest revision of the current interface. */
#define NN_VERSION_REVISION 1

/*  How many past interface versions are still supported. */
#define NN_VERSION_AGE 0

/******************************************************************************/
/*  Errors.                                                                   */
/******************************************************************************/

/*  A number random enough not to collide with different errno ranges on      */
/*  different OSes. The assumption is that error_t is at least 32-bit type.   */
#define NN_HAUSNUMERO 156384712

/*  On some platforms some standard POSIX errnos are not defined.    */
#ifndef ENOTSUP
#define ENOTSUP (NN_HAUSNUMERO + 1)
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT (NN_HAUSNUMERO + 2)
#endif
#ifndef ENOBUFS
#define ENOBUFS (NN_HAUSNUMERO + 3)
#endif
#ifndef ENETDOWN
#define ENETDOWN (NN_HAUSNUMERO + 4)
#endif
#ifndef EADDRINUSE
#define EADDRINUSE (NN_HAUSNUMERO + 5)
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL (NN_HAUSNUMERO + 6)
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED (NN_HAUSNUMERO + 7)
#endif
#ifndef EINPROGRESS
#define EINPROGRESS (NN_HAUSNUMERO + 8)
#endif
#ifndef ENOTSOCK
#define ENOTSOCK (NN_HAUSNUMERO + 9)
#endif
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT (NN_HAUSNUMERO + 10)
#endif
#ifndef EPROTO
#define EPROTO (NN_HAUSNUMERO + 11)
#endif
#ifndef EAGAIN
#define EAGAIN (NN_HAUSNUMERO + 12)
#endif
#ifndef EBADF
#define EBADF (NN_HAUSNUMERO + 13)
#endif
#ifndef EINVAL
#define EINVAL (NN_HAUSNUMERO + 14)
#endif
#ifndef EMFILE
#define EMFILE (NN_HAUSNUMERO + 15)
#endif
#ifndef EFAULT
#define EFAULT (NN_HAUSNUMERO + 16)
#endif
#ifndef EACCES
#define EACCES (NN_HAUSNUMERO + 17)
#endif
#ifndef EACCESS
#define EACCESS (EACCES)
#endif
#ifndef ENETRESET
#define ENETRESET (NN_HAUSNUMERO + 18)
#endif
#ifndef ENETUNREACH
#define ENETUNREACH (NN_HAUSNUMERO + 19)
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH (NN_HAUSNUMERO + 20)
#endif
#ifndef ENOTCONN
#define ENOTCONN (NN_HAUSNUMERO + 21)
#endif
#ifndef EMSGSIZE
#define EMSGSIZE (NN_HAUSNUMERO + 22)
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT (NN_HAUSNUMERO + 23)
#endif
#ifndef ECONNABORTED
#define ECONNABORTED (NN_HAUSNUMERO + 24)
#endif
#ifndef ECONNRESET
#define ECONNRESET (NN_HAUSNUMERO + 25)
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT (NN_HAUSNUMERO + 26)
#endif
#ifndef EISCONN
#define EISCONN (NN_HAUSNUMERO + 27)
#define NN_EISCONN_DEFINED
#endif
#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT (NN_HAUSNUMERO + 28)
#endif

/*  Native nanomsg error codes.                                               */
#ifndef ETERM
#define ETERM (NN_HAUSNUMERO + 53)
#endif
#ifndef EFSM
#define EFSM (NN_HAUSNUMERO + 54)
#endif

/*  This function retrieves the errno as it is known to the library.          */
/*  The goal of this function is to make the code 100% portable, including    */
/*  where the library is compiled with certain CRT library (on Windows) and   */
/*  linked to an application that uses different CRT library.                 */
NN_EXPORT int nn_errno (void);

/*  Resolves system errors and native errors to human-readable string.        */
NN_EXPORT const char *nn_strerror (int errnum);


/*  Returns the symbol name (e.g. "NN_REQ") and value at a specified index.   */
/*  If the index is out-of-range, returns NULL and sets errno to EINVAL       */
/*  General usage is to start at i=0 and iterate until NULL is returned.      */
NN_EXPORT const char *nn_symbol (int i, int *value);

/*  Constants that are returned in `ns` member of nn_symbol_properties        */
#define NN_NS_NAMESPACE 0
#define NN_NS_VERSION 1
#define NN_NS_DOMAIN 2
#define NN_NS_TRANSPORT 3
#define NN_NS_PROTOCOL 4
#define NN_NS_OPTION_LEVEL 5
#define NN_NS_SOCKET_OPTION 6
#define NN_NS_TRANSPORT_OPTION 7
#define NN_NS_OPTION_TYPE 8
#define NN_NS_OPTION_UNIT 9
#define NN_NS_FLAG 10
#define NN_NS_ERROR 11
#define NN_NS_LIMIT 12
#define NN_NS_EVENT 13
#define NN_NS_STATISTIC 14

/*  Constants that are returned in `type` member of nn_symbol_properties      */
#define NN_TYPE_NONE 0
#define NN_TYPE_INT 1
#define NN_TYPE_STR 2

/*  Constants that are returned in the `unit` member of nn_symbol_properties  */
#define NN_UNIT_NONE 0
#define NN_UNIT_BYTES 1
#define NN_UNIT_MILLISECONDS 2
#define NN_UNIT_PRIORITY 3
#define NN_UNIT_BOOLEAN 4
#define NN_UNIT_MESSAGES 5
#define NN_UNIT_COUNTER 6

/*  Structure that is returned from nn_symbol  */
struct nn_symbol_properties {

    /*  The constant value  */
    int value;

    /*  The constant name  */
    const char* name;

    /*  The constant namespace, or zero for namespaces themselves */
    int ns;

    /*  The option type for socket option constants  */
    int type;

    /*  The unit for the option value for socket option constants  */
    int unit;
};

/*  Fills in nn_symbol_properties structure and returns it's length           */
/*  If the index is out-of-range, returns 0                                   */
/*  General usage is to start at i=0 and iterate until zero is returned.      */
NN_EXPORT int nn_symbol_info (int i,
    struct nn_symbol_properties *buf, int buflen);

/******************************************************************************/
/*  Helper function for shutting down multi-threaded applications.            */
/******************************************************************************/

NN_EXPORT void nn_term (void);

/******************************************************************************/
/*  Zero-copy support.                                                        */
/******************************************************************************/

#define NN_MSG ((size_t) -1)

NN_EXPORT void *nn_allocmsg (size_t size, int type);
NN_EXPORT void *nn_reallocmsg (void *msg, size_t size);
NN_EXPORT int nn_freemsg (void *msg);

/******************************************************************************/
/*  Socket definition.                                                        */
/******************************************************************************/

struct nn_iovec {
    void *iov_base;
    size_t iov_len;
};

struct nn_msghdr {
    struct nn_iovec *msg_iov;
    int msg_iovlen;
    void *msg_control;
    size_t msg_controllen;
};

struct nn_cmsghdr {
    size_t cmsg_len;
    int cmsg_level;
    int cmsg_type;
};

/*  Internal stuff. Not to be used directly.                                  */
NN_EXPORT  struct nn_cmsghdr *nn_cmsg_nxthdr_ (
    const struct nn_msghdr *mhdr,
    const struct nn_cmsghdr *cmsg);
#define NN_CMSG_ALIGN_(len) \
    (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))

/* POSIX-defined msghdr manipulation. */

#define NN_CMSG_FIRSTHDR(mhdr) \
    nn_cmsg_nxthdr_ ((struct nn_msghdr*) (mhdr), NULL)

#define NN_CMSG_NXTHDR(mhdr, cmsg) \
    nn_cmsg_nxthdr_ ((struct nn_msghdr*) (mhdr), (struct nn_cmsghdr*) (cmsg))

#define NN_CMSG_DATA(cmsg) \
    ((unsigned char*) (((struct nn_cmsghdr*) (cmsg)) + 1))

/* Extensions to POSIX defined by RFC 3542.                                   */

#define NN_CMSG_SPACE(len) \
    (NN_CMSG_ALIGN_ (len) + NN_CMSG_ALIGN_ (sizeof (struct nn_cmsghdr)))

#define NN_CMSG_LEN(len) \
    (NN_CMSG_ALIGN_ (sizeof (struct nn_cmsghdr)) + (len))

/*  SP address families.                                                      */
#define AF_SP 1
#define AF_SP_RAW 2

/*  Max size of an SP address.                                                */
#define NN_SOCKADDR_MAX 128

/*  Socket option levels: Negative numbers are reserved for transports,
    positive for socket types. */
#define NN_SOL_SOCKET 0

/*  Generic socket options (NN_SOL_SOCKET level).                             */
#define NN_LINGER 1
#define NN_SNDBUF 2
#define NN_RCVBUF 3
#define NN_SNDTIMEO 4
#define NN_RCVTIMEO 5
#define NN_RECONNECT_IVL 6
#define NN_RECONNECT_IVL_MAX 7
#define NN_SNDPRIO 8
#define NN_RCVPRIO 9
#define NN_SNDFD 10
#define NN_RCVFD 11
#define NN_DOMAIN 12
#define NN_PROTOCOL 13
#define NN_IPV4ONLY 14
#define NN_SOCKET_NAME 15
#define NN_RCVMAXSIZE 16
#define NN_MAXTTL 17

/*  Send/recv options.                                                        */
#define NN_DONTWAIT 1

/*  Ancillary data.                                                           */
#define PROTO_SP 1
#define SP_HDR 1

NN_EXPORT int nn_socket (int domain, int protocol);
NN_EXPORT int nn_close (int s);
NN_EXPORT int nn_setsockopt (int s, int level, int option, const void *optval,
    size_t optvallen);
NN_EXPORT int nn_getsockopt (int s, int level, int option, void *optval,
    size_t *optvallen);
NN_EXPORT int nn_bind (int s, const char *addr);
NN_EXPORT int nn_connect (int s, const char *addr);
NN_EXPORT int nn_shutdown (int s, int how);
NN_EXPORT int nn_send (int s, const void *buf, size_t len, int flags);
NN_EXPORT int nn_recv (int s, void *buf, size_t len, int flags);
NN_EXPORT int nn_sendmsg (int s, const struct nn_msghdr *msghdr, int flags);
NN_EXPORT int nn_recvmsg (int s, struct nn_msghdr *msghdr, int flags);

/******************************************************************************/
/*  Socket mutliplexing support.                                              */
/******************************************************************************/

#define NN_POLLIN 1
#define NN_POLLOUT 2

struct nn_pollfd {
    int fd;
    short events;
    short revents;
};

NN_EXPORT int nn_poll (struct nn_pollfd *fds, int nfds, int timeout);

/******************************************************************************/
/*  Built-in support for devices.                                             */
/******************************************************************************/

NN_EXPORT int nn_device (int s1, int s2);

/******************************************************************************/
/*  Statistics.                                                               */
/******************************************************************************/

/*  Transport statistics  */
#define NN_STAT_ESTABLISHED_CONNECTIONS 101
#define NN_STAT_ACCEPTED_CONNECTIONS    102
#define NN_STAT_DROPPED_CONNECTIONS     103
#define NN_STAT_BROKEN_CONNECTIONS      104
#define NN_STAT_CONNECT_ERRORS          105
#define NN_STAT_BIND_ERRORS             106
#define NN_STAT_ACCEPT_ERRORS           107

#define NN_STAT_CURRENT_CONNECTIONS     201
#define NN_STAT_INPROGRESS_CONNECTIONS  202
#define NN_STAT_CURRENT_EP_ERRORS       203

/*  The socket-internal statistics  */
#define NN_STAT_MESSAGES_SENT           301
#define NN_STAT_MESSAGES_RECEIVED       302
#define NN_STAT_BYTES_SENT              303
#define NN_STAT_BYTES_RECEIVED          304
/*  Protocol statistics  */
#define   NN_STAT_CURRENT_SND_PRIORITY    401

NN_EXPORT uint64_t nn_get_statistic (int s, int stat);

#ifdef __cplusplus
}
#endif

#endif
speedfixer
Posts: 389
Joined: Nov 28, 2012 1:27
Location: California

Re: fbfrog header translator

Postby speedfixer » Nov 29, 2017 6:46

All the above notwithstanding,

fbfrog:

EXCELLENT

(I HAVE tried h_2_bi in the past.)

Just takes some practice and experience, like most everything else in this world.


David
D.J.Peters
Posts: 7838
Joined: May 28, 2005 3:28

Re: fbfrog header translator

Postby D.J.Peters » Nov 29, 2017 10:07

I use search and replace to create *.bi files
I rename reserved words e.g. len len_
I replace type casting with cast() or cptr()
And some more changes by hand

Joshy

Code: Select all

#ifndef NN_H_INCLUDED
#define NN_H_INCLUDED

#include once "crt.bi"
'#include "errno.bi"
'#include "stddef.bi"
'#include "stdint.bi"

extern "c"

/'****************************************************************************'/
/'  ABI versioning support.                                                   '/
/'****************************************************************************'/

/'  Don't change this unless you know exactly what you're doing and have      '/
/'  read and understand the following documents:                              '/
/'  www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html     '/
/'  www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html  '/

/'  The current interface version. '/
#define NN_VERSION_CURRENT 5

/'  The latest revision of the current interface. '/
#define NN_VERSION_REVISION 1

/'  How many past interface versions are still supported. '/
#define NN_VERSION_AGE 0

/'****************************************************************************'/
/'  Errors.                                                                   '/
/'****************************************************************************'/

/'  A number random enough not to collide with different errno ranges on      '/
/'  different OSes. The assumption is that error_t is at least 32-bit type.   '/
#define NN_HAUSNUMERO 156384712

/'  On some platforms some standard POSIX errnos are not defined.    '/
#ifndef ENOTSUP
#define ENOTSUP (NN_HAUSNUMERO + 1)
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT (NN_HAUSNUMERO + 2)
#endif
#ifndef ENOBUFS
#define ENOBUFS (NN_HAUSNUMERO + 3)
#endif
#ifndef ENETDOWN
#define ENETDOWN (NN_HAUSNUMERO + 4)
#endif
#ifndef EADDRINUSE
#define EADDRINUSE (NN_HAUSNUMERO + 5)
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL (NN_HAUSNUMERO + 6)
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED (NN_HAUSNUMERO + 7)
#endif
#ifndef EINPROGRESS
#define EINPROGRESS (NN_HAUSNUMERO + 8)
#endif
#ifndef ENOTSOCK
#define ENOTSOCK (NN_HAUSNUMERO + 9)
#endif
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT (NN_HAUSNUMERO + 10)
#endif
#ifndef EPROTO
#define EPROTO (NN_HAUSNUMERO + 11)
#endif
#ifndef EAGAIN
#define EAGAIN (NN_HAUSNUMERO + 12)
#endif
#ifndef EBADF
#define EBADF (NN_HAUSNUMERO + 13)
#endif
#ifndef EINVAL
#define EINVAL (NN_HAUSNUMERO + 14)
#endif
#ifndef EMFILE
#define EMFILE (NN_HAUSNUMERO + 15)
#endif
#ifndef EFAULT
#define EFAULT (NN_HAUSNUMERO + 16)
#endif
#ifndef EACCES
#define EACCES (NN_HAUSNUMERO + 17)
#endif
#ifndef EACCESS
#define EACCESS (EACCES)
#endif
#ifndef ENETRESET
#define ENETRESET (NN_HAUSNUMERO + 18)
#endif
#ifndef ENETUNREACH
#define ENETUNREACH (NN_HAUSNUMERO + 19)
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH (NN_HAUSNUMERO + 20)
#endif
#ifndef ENOTCONN
#define ENOTCONN (NN_HAUSNUMERO + 21)
#endif
#ifndef EMSGSIZE
#define EMSGSIZE (NN_HAUSNUMERO + 22)
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT (NN_HAUSNUMERO + 23)
#endif
#ifndef ECONNABORTED
#define ECONNABORTED (NN_HAUSNUMERO + 24)
#endif
#ifndef ECONNRESET
#define ECONNRESET (NN_HAUSNUMERO + 25)
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT (NN_HAUSNUMERO + 26)
#endif
#ifndef EISCONN
#define EISCONN (NN_HAUSNUMERO + 27)
#define NN_EISCONN_DEFINED
#endif
#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT (NN_HAUSNUMERO + 28)
#endif

/'  Native nanomsg error codes.                                               '/
#ifndef ETERM
#define ETERM (NN_HAUSNUMERO + 53)
#endif
#ifndef EFSM
#define EFSM (NN_HAUSNUMERO + 54)
#endif

/'  This function retrieves the errno as it is known to the library.          '/
/'  The goal of this function is to make the code 100% portable, including    '/
/'  where the library is compiled with certain CRT library (on Windows) and   '/
/'  linked to an application that uses different CRT library.                 '/
declare function nn_errno () as long

/'  Resolves system errors and native errors to human-readable string.        '/
declare function nn_strerror (errnum as long) as const zstring ptr


/'  Returns the symbol name (e.g. "NN_REQ") and value at a specified index.   '/
/'  If the index is out-of-range, returns NULL and sets errno to EINVAL       '/
/'  General usage is to start at i=0 and iterate until NULL is returned.      '/
declare function nn_symbol (i as long, value as long ptr) as const zstring ptr

/'  Constants that are returned in `ns` member of nn_symbol_properties        '/
#define NN_NS_NAMESPACE 0
#define NN_NS_VERSION 1
#define NN_NS_DOMAIN 2
#define NN_NS_TRANSPORT 3
#define NN_NS_PROTOCOL 4
#define NN_NS_OPTION_LEVEL 5
#define NN_NS_SOCKET_OPTION 6
#define NN_NS_TRANSPORT_OPTION 7
#define NN_NS_OPTION_TYPE 8
#define NN_NS_OPTION_UNIT 9
#define NN_NS_FLAG 10
#define NN_NS_ERROR 11
#define NN_NS_LIMIT 12
#define NN_NS_EVENT 13
#define NN_NS_STATISTIC 14

/'  Constants that are returned in `type` member of nn_symbol_properties      '/
#define NN_TYPE_NONE 0
#define NN_TYPE_INT 1
#define NN_TYPE_STR 2

/'  Constants that are returned in the `unit` member of nn_symbol_properties  '/
#define NN_UNIT_NONE 0
#define NN_UNIT_BYTES 1
#define NN_UNIT_MILLISECONDS 2
#define NN_UNIT_PRIORITY 3
#define NN_UNIT_BOOLEAN 4
#define NN_UNIT_MESSAGES 5
#define NN_UNIT_COUNTER 6

/'  Structure that is returned from nn_symbol  '/
type nn_symbol_properties
  /'  The constant value  '/
  as long value
  /'  The constant name  '/
  as const zstring ptr name
  /'  The constant namespace, or zero for namespaces themselves '/
  as long ns
  /'  The option type for socket option constants  '/
  as long type
  /'  The unit for the option value for socket option constants  '/
  as long unit
end type

/'  Fills in nn_symbol_properties structure and returns it's length           '/
/'  If the index is out-of-range, returns 0                                   '/
/'  General usage is to start at i=0 and iterate until zero is returned.      '/
declare function nn_symbol_info (i as long, buf as nn_symbol_properties ptr, buflen as long) as long

/'****************************************************************************'/
/'  Helper function for shutting down multi-threaded applications.            '/
/'****************************************************************************'/

declare sub nn_term()

/'****************************************************************************'/
/'  Zero-copy support.                                                        '/
/'****************************************************************************'/

#define NN_MSG cast(size_t,-1)

declare function nn_allocmsg (size as size_t, type as long) as any ptr
declare function nn_reallocmsg (msg as any ptr, size as size_t) as any ptr
declare function nn_freemsg (msg as any ptr) as long

/'****************************************************************************'/
/'  Socket definition.                                                        '/
/'****************************************************************************'/

type nn_iovec
  as any ptr iov_base
  as size_t iov_len
end type

type nn_msghdr
  as nn_iovec ptr msg_iov
  as long msg_iovlen
  as any ptr msg_control
  as size_t msg_controllen
end type

type  nn_cmsghdr
  as size_t cmsg_len
  as long cmsg_level
  as long cmsg_type
end type

/'  Internal stuff. Not to be used directly.                                  '/
declare function nn_cmsg_nxthdr_ (mhdr as const nn_msghdr ptr, cmsg as const nn_cmsghdr ptr) as  nn_cmsghdr  ptr
#define NN_CMSG_ALIGN_(len_) (((len_) + sizeof (size_t) - 1) AND (size_t) NOT (sizeof (size_t) - 1))

/' POSIX-defined msghdr manipulation. '/
#define NN_CMSG_FIRSTHDR(mhdr) nn_cmsg_nxthdr_ ( cptr(nn_msghdr ptr,mhdr), NULL)

#define NN_CMSG_NXTHDR(mhdr, cmsg) nn_cmsg_nxthdr_ ( cptr(nn_msghdr ptr,mhdr), cptr(nn_cmsghdr ptr,cmsg))

#define NN_CMSG_DATA(cmsg) cptr(ubyte ptr, cptr(nn_cmsghdr ptr,cmsg) + 1)

/' Extensions to POSIX defined by RFC 3542.                                   '/
#define NN_CMSG_SPACE(len_) (NN_CMSG_ALIGN_ (len_) + NN_CMSG_ALIGN_ (sizeof (nn_cmsghdr)))

#define NN_CMSG_LEN(len_) (NN_CMSG_ALIGN_ (sizeof(nn_cmsghdr)) + (len_))

/'  SP address families.                                                      '/
#define AF_SP 1
#define AF_SP_RAW 2

/'  Max size of an SP address.                                                '/
#define NN_SOCKADDR_MAX 128

/'  Socket option levels: Negative numbers are reserved for transports,
    positive for socket types. '/
#define NN_SOL_SOCKET 0

/'  Generic socket options (NN_SOL_SOCKET level).                             '/
#define NN_LINGER 1
#define NN_SNDBUF 2
#define NN_RCVBUF 3
#define NN_SNDTIMEO 4
#define NN_RCVTIMEO 5
#define NN_RECONNECT_IVL 6
#define NN_RECONNECT_IVL_MAX 7
#define NN_SNDPRIO 8
#define NN_RCVPRIO 9
#define NN_SNDFD 10
#define NN_RCVFD 11
#define NN_DOMAIN 12
#define NN_PROTOCOL 13
#define NN_IPV4ONLY 14
#define NN_SOCKET_NAME 15
#define NN_RCVMAXSIZE 16
#define NN_MAXTTL 17

/'  Send/recv options.                                                        '/
#define NN_DONTWAIT 1

/'  Ancillary data.                                                           '/
#define PROTO_SP 1
#define SP_HDR 1

declare function nn_socket (domain as long, protocol as long) as long
declare function nn_close (s as long) as long
declare function nn_setsockopt (s as long, level as long, option as long, optval as const any ptr, optvallen as size_t) as long
declare function nn_getsockopt (s as long, level as long, option as long, optval as any ptr, optvallen as size_t ptr) as long
declare function nn_bind (s as long, addr as const zstring ptr) as long
declare function nn_connect (s as long, adr as const zstring ptr) as long
declare function nn_shutdown (s as long, how as long) as long
declare function nn_send (s as long, buf as const any ptr, len as size_t, flags as long) as long
declare function nn_recv (s as long, buf as any ptr, len as size_t, flags as long) as long
declare function nn_sendmsg (s as long, msghdr as const nn_msghdr ptr, flags as long) as long
declare function nn_recvmsg (s as long, msghdr as nn_msghdr ptr, flags as long) as long

/'****************************************************************************'/
/'  Socket mutliplexing support.                                              '/
/'****************************************************************************'/

#define NN_POLLIN 1
#define NN_POLLOUT 2

type nn_pollfd
  as long fd
  as short events
  as short revents
end type

declare function nn_poll (fds as nn_pollfd ptr, nfds as long, timeout as long) as long

/'****************************************************************************'/
/'  Built-in support for devices.                                             '/
/'****************************************************************************'/
declare function nn_device (s1 as long, s2 as long) as long

/'****************************************************************************'/
/'  Statistics.                                                               '/
/'****************************************************************************'/

/'  Transport statistics  '/
#define NN_STAT_ESTABLISHED_CONNECTIONS 101
#define NN_STAT_ACCEPTED_CONNECTIONS    102
#define NN_STAT_DROPPED_CONNECTIONS     103
#define NN_STAT_BROKEN_CONNECTIONS      104
#define NN_STAT_CONNECT_ERRORS          105
#define NN_STAT_BIND_ERRORS             106
#define NN_STAT_ACCEPT_ERRORS           107

#define NN_STAT_CURRENT_CONNECTIONS     201
#define NN_STAT_INPROGRESS_CONNECTIONS  202
#define NN_STAT_CURRENT_EP_ERRORS       203

/'  The socket-internal statistics  '/
#define NN_STAT_MESSAGES_SENT           301
#define NN_STAT_MESSAGES_RECEIVED       302
#define NN_STAT_BYTES_SENT              303
#define NN_STAT_BYTES_RECEIVED          304
/'  Protocol statistics  '/
#define   NN_STAT_CURRENT_SND_PRIORITY    401

declare function nn_get_statistic (s as long, stat as long) as ulongint

end extern

#endif
speedfixer
Posts: 389
Joined: Nov 28, 2012 1:27
Location: California

Re: fbfrog header translator

Postby speedfixer » Nov 29, 2017 17:40

Thank you, Joshy.
I will try this when it is time.

David
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: fbfrog header translator

Postby dkl » Nov 29, 2017 18:49

Yea, fbfrog tries to parse all #includes, but currently it also ignores the ones that can't be found. It's somewhat useful for making .bi files for .h files that would normally use system headers, but without having the system headers.

So fbfrog also resolves #ifdefs and macros, but the result can be wrong if some #includes are not found, or if some other preprocessor condition (pre-define) wasn't set. Some things can be fixed by using -incdir to specify #include search directories for fbfrog, or -rename_ to rename conflicting symbols.
Iczer
Posts: 52
Joined: Jul 04, 2017 18:09

Re: fbfrog header translator

Postby Iczer » Mar 02, 2018 16:19

I wanted to make new *.bi file for fresh (7.58) version of libcurl with fbfrog, but it claim "error: could not find 'default.h'". But there a no "default.h" mentioned in any of *.h file in package. What can I do avoid this error?

As result I wanted to make curl load as static lib - v7.58 have CURL_STATICLIB in headers wich v7.44 curl.bi from FB 1.05 don't.

Code: Select all

#ifdef CURL_STATICLIB
#  define CURL_EXTERN
#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
#  if defined(BUILDING_LIBCURL)
#    define CURL_EXTERN  __declspec(dllexport)
#  else
#    define CURL_EXTERN  __declspec(dllimport)
#  endif
#elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS)
#  define CURL_EXTERN CURL_EXTERN_SYMBOL
#else
#  define CURL_EXTERN
#endif


with libpcre and libxml2

Code: Select all

#Define LIBXML_STATIC
#Define PCRE_STATIC


makes FB load them as static libs, so I hoped the same work in curl case...
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: fbfrog header translator

Postby dkl » Mar 02, 2018 17:40

default.h belongs to fbfrog itself, it exists at include/fbfrog/default.h in the fbfrog source code. The include/ directory (with fbfrog/default.h in it) should be next to fbfrog.exe so it can be found.

To support CURL_STATICLIB, you could try to save the following as curl.fbfrog:

Code: Select all

-declarebool CURL_STATICLIB
-ifdef CURL_STATICLIB
    -define CURL_STATICLIB 1
-endif

and then pass it on fbfrog command line in addition to the headers etc.

Here are some more options that might be useful: https://github.com/dkl/fbbindings/blob/ ... url.fbfrog
Iczer
Posts: 52
Joined: Jul 04, 2017 18:09

Re: fbfrog header translator

Postby Iczer » Mar 02, 2018 21:27

thanks, I got fresh baked curl.bi, using original curl.bi-file as hint corrected errors and it actually worked - my project runs OK. But - it show lib version as v7.57 - its curl.dll version instead of v7.58 (static lib libcurl.a)
it seems CURL_EXTERN not used after initial define, but in curl.h it preced function names:

Code: Select all

 * Returns a static ascii string of the libcurl version.
 */
CURL_EXTERN char *curl_version(void);


deleting curl.dll.a result in compile errors "...o:fake:(.text+0xacf1c): undefined reference to..."
TeeEmCee
Posts: 262
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: fbfrog header translator

Postby TeeEmCee » Mar 03, 2018 2:41

The GNU linker prefers to link .dlls over .a files. I would have thought that removing the .dll.a file would prevent that. Maybe you need to remove the .dll too?
Did the link errors you saw refer to the .dll or to the .a file?
Iczer
Posts: 52
Joined: Jul 04, 2017 18:09

Re: fbfrog header translator

Postby Iczer » Mar 03, 2018 16:12

Thanks! Now you mention this - errors refer to ssh2 library - it seems curl library was compiled with ssl/ssh support - so when it was used as dll - everything was ok as long as ssh was not used, but once I included curl as static library - those unused refer become errors. So i need ssh2.dll.a file...
speedfixer
Posts: 389
Joined: Nov 28, 2012 1:27
Location: California

Re: fbfrog header translator

Postby speedfixer » Mar 25, 2018 21:42

dkl: first post:

fbfrog itself is a command line tool, but there's a separate GUI program for it, take a look: <dead link>


Is that gone? available? too old to reconsider?


david
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: fbfrog header translator

Postby dkl » Apr 03, 2018 18:57

Nah, that's dead since fbfrog 1.0. It was fun to make, but there was just no point in having it...
Iczer
Posts: 52
Joined: Jul 04, 2017 18:09

Re: fbfrog header translator

Postby Iczer » Jan 07, 2019 23:02

i'm trying to make bindings for Mecab https://github.com/ikegami-yukino/mecab/releases/tag/v0.996 but they turn out not complete - come declarations are missing...
so = mecab.h file:

Code: Select all

/*
  MeCab -- Yet Another Part-of-Speech and Morphological Analyzer

  Copyright(C) 2001-2011 Taku Kudo <taku@chasen.org>
  Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
*/
#ifndef MECAB_MECAB_H_
#define MECAB_MECAB_H_

/* C/C++ common data structures  */

/**
 * DictionaryInfo structure
 */
struct mecab_dictionary_info_t {
  /**
   * filename of dictionary
   * On Windows, filename is stored in UTF-8 encoding
   */
  const char                     *filename;

  /**
   * character set of the dictionary. e.g., "SHIFT-JIS", "UTF-8"
   */
  const char                     *charset;

  /**
   * How many words are registered in this dictionary.
   */
  unsigned int                    size;

  /**
   * dictionary type
   * this value should be MECAB_USR_DIC, MECAB_SYS_DIC, or MECAB_UNK_DIC.
   */
  int                             type;

  /**
   * left attributes size
   */
  unsigned int                    lsize;

  /**
   * right attributes size
   */
  unsigned int                    rsize;

  /**
   * version of this dictionary
   */
  unsigned short                  version;

  /**
   * pointer to the next dictionary info.
   */
  struct mecab_dictionary_info_t *next;
};

/**
 * Path structure
 */
struct mecab_path_t {
  /**
   * pointer to the right node
   */
  struct mecab_node_t* rnode;

  /**
   * pointer to the next right path
   */
  struct mecab_path_t* rnext;

  /**
   * pointer to the left node
   */
  struct mecab_node_t* lnode;

  /**
   * pointer to the next left path
   */

  struct mecab_path_t* lnext;

  /**
   * local cost
   */
  int                  cost;

  /**
   * marginal probability
   */
  float                prob;
};

/**
 * Node structure
 */
struct mecab_node_t {
  /**
   * pointer to the previous node.
   */
  struct mecab_node_t  *prev;

  /**
   * pointer to the next node.
   */
  struct mecab_node_t  *next;

  /**
   * pointer to the node which ends at the same position.
   */
  struct mecab_node_t  *enext;

  /**
   * pointer to the node which starts at the same position.
   */
  struct mecab_node_t  *bnext;

  /**
   * pointer to the right path.
   * this value is NULL if MECAB_ONE_BEST mode.
   */
  struct mecab_path_t  *rpath;

  /**
   * pointer to the right path.
   * this value is NULL if MECAB_ONE_BEST mode.
   */
  struct mecab_path_t  *lpath;

  /**
   * surface string.
   * this value is not 0 terminated.
   * You can get the length with length/rlength members.
   */
  const char           *surface;

  /**
   * feature string
   */
  const char           *feature;

  /**
   * unique node id
   */
  unsigned int          id;

  /**
   * length of the surface form.
   */
  unsigned short        length;

  /**
   * length of the surface form including white space before the morph.
   */
  unsigned short        rlength;

  /**
   * right attribute id
   */
  unsigned short        rcAttr;

  /**
   * left attribute id
   */
  unsigned short        lcAttr;

  /**
   * unique part of speech id. This value is defined in "pos.def" file.
   */
  unsigned short        posid;

  /**
   * character type
   */
  unsigned char         char_type;

  /**
   * status of this model.
   * This value is MECAB_NOR_NODE, MECAB_UNK_NODE, MECAB_BOS_NODE, MECAB_EOS_NODE, or MECAB_EON_NODE.
   */
  unsigned char         stat;

  /**
   * set 1 if this node is best node.
   */
  unsigned char         isbest;

  /**
   * forward accumulative log summation.
   * This value is only available when MECAB_MARGINAL_PROB is passed.
   */
  float                 alpha;

  /**
   * backward accumulative log summation.
   * This value is only available when MECAB_MARGINAL_PROB is passed.
   */
  float                 beta;

  /**
   * marginal probability.
   * This value is only available when MECAB_MARGINAL_PROB is passed.
   */
  float                 prob;

  /**
   * word cost.
   */
  short                 wcost;

  /**
   * best accumulative cost from bos node to this node.
   */
  long                  cost;
};

/**
 * Parameters for MeCab::Node::stat
 */
enum {
  /**
   * Normal node defined in the dictionary.
   */
  MECAB_NOR_NODE = 0,
  /**
   * Unknown node not defined in the dictionary.
   */
  MECAB_UNK_NODE = 1,
  /**
   * Virtual node representing a beginning of the sentence.
   */
  MECAB_BOS_NODE = 2,
  /**
   * Virtual node representing a end of the sentence.
   */
  MECAB_EOS_NODE = 3,

  /**
   * Virtual node representing a end of the N-best enumeration.
   */
  MECAB_EON_NODE = 4
};

/**
 * Parameters for MeCab::DictionaryInfo::type
 */
enum {
  /**
   * This is a system dictionary.
   */
  MECAB_SYS_DIC = 0,

  /**
   * This is a user dictionary.
   */
  MECAB_USR_DIC = 1,

  /**
   * This is a unknown word dictionary.
   */
  MECAB_UNK_DIC = 2
};

/**
 * Parameters for MeCab::Lattice::request_type
 */
enum {
  /**
   * One best result is obtained (default mode)
   */
  MECAB_ONE_BEST          = 1,
  /**
   * Set this flag if you want to obtain N best results.
   */
  MECAB_NBEST             = 2,
  /**
   * Set this flag if you want to enable a partial parsing mode.
   * When this flag is set, the input |sentence| needs to be written
   * in partial parsing format.
   */
  MECAB_PARTIAL           = 4,
  /**
   * Set this flag if you want to obtain marginal probabilities.
   * Marginal probability is set in MeCab::Node::prob.
   * The parsing speed will get 3-5 times slower than the default mode.
   */
  MECAB_MARGINAL_PROB     = 8,
  /**
   * Set this flag if you want to obtain alternative results.
   * Not implemented.
   */
  MECAB_ALTERNATIVE       = 16,
  /**
   * When this flag is set, the result linked-list (Node::next/prev)
   * traverses all nodes in the lattice.
   */
  MECAB_ALL_MORPHS        = 32,

  /**
   * When this flag is set, tagger internally copies the body of passed
   * sentence into internal buffer.
   */
  MECAB_ALLOCATE_SENTENCE = 64
};

/**
 * Parameters for MeCab::Lattice::boundary_constraint_type
 */
enum {
  /**
   * The token boundary is not specified.
   */
  MECAB_ANY_BOUNDARY = 0,

  /**
   * The position is a strong token boundary.
   */
  MECAB_TOKEN_BOUNDARY = 1,

  /**
   * The position is not a token boundary.
   */
  MECAB_INSIDE_TOKEN = 2
};

/* C interface  */
#ifdef __cplusplus
#include <cstdio>
#else
#include <stdio.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
#include <windows.h>
#  ifdef DLL_EXPORT
#    define MECAB_DLL_EXTERN  __declspec(dllexport)
#    define MECAB_DLL_CLASS_EXTERN  __declspec(dllexport)
#  else
#    define MECAB_DLL_EXTERN  __declspec(dllimport)
#  endif
#endif

#ifndef MECAB_DLL_EXTERN
#  define MECAB_DLL_EXTERN extern
#endif

#ifndef MECAB_DLL_CLASS_EXTERN
#  define MECAB_DLL_CLASS_EXTERN
#endif

  typedef struct mecab_t                 mecab_t;
  typedef struct mecab_model_t           mecab_model_t;
  typedef struct mecab_lattice_t         mecab_lattice_t;
  typedef struct mecab_dictionary_info_t mecab_dictionary_info_t;
  typedef struct mecab_node_t            mecab_node_t;
  typedef struct mecab_path_t            mecab_path_t;

#ifndef SWIG
  /* C interface */

  /* old mecab interface */
  /**
   * C wrapper of MeCab::Tagger::create(argc, argv)
   */
  MECAB_DLL_EXTERN mecab_t*      mecab_new(int argc, char **argv);

  /**
   * C wrapper of MeCab::Tagger::create(arg)
   */
  MECAB_DLL_EXTERN mecab_t*      mecab_new2(const char *arg);

  /**
   * C wrapper of MeCab::Tagger::version()
   */
  MECAB_DLL_EXTERN const char*   mecab_version();

  /**
   * C wrapper of MeCab::getLastError()
   */
  MECAB_DLL_EXTERN const char*   mecab_strerror(mecab_t *mecab);

  /**
   * C wrapper of MeCab::deleteTagger(tagger)
   */
  MECAB_DLL_EXTERN void          mecab_destroy(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger:set_partial()
   */
  MECAB_DLL_EXTERN int           mecab_get_partial(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger::partial()
   */
  MECAB_DLL_EXTERN void          mecab_set_partial(mecab_t *mecab, int partial);

  /**
   * C wrapper of MeCab::Tagger::theta()
   */
  MECAB_DLL_EXTERN float         mecab_get_theta(mecab_t *mecab);

  /**
   * C wrapper of  MeCab::Tagger::set_theta()
   */
  MECAB_DLL_EXTERN void          mecab_set_theta(mecab_t *mecab, float theta);

  /**
   * C wrapper of MeCab::Tagger::lattice_level()
   */
  MECAB_DLL_EXTERN int           mecab_get_lattice_level(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger::set_lattice_level()
   */
  MECAB_DLL_EXTERN void          mecab_set_lattice_level(mecab_t *mecab, int level);

  /**
   * C wrapper of MeCab::Tagger::all_morphs()
   */
  MECAB_DLL_EXTERN int           mecab_get_all_morphs(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger::set_all_moprhs()
   */
  MECAB_DLL_EXTERN void          mecab_set_all_morphs(mecab_t *mecab, int all_morphs);

  /**
   * C wrapper of MeCab::Tagger::parse(MeCab::Lattice *lattice)
   */
  MECAB_DLL_EXTERN int           mecab_parse_lattice(mecab_t *mecab, mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Tagger::parse(const char *str)
   */
  MECAB_DLL_EXTERN const char*   mecab_sparse_tostr(mecab_t *mecab, const char *str);

  /**
   * C wrapper of MeCab::Tagger::parse(const char *str, size_t len)
   */
  MECAB_DLL_EXTERN const char*   mecab_sparse_tostr2(mecab_t *mecab, const char *str, size_t len);

  /**
   * C wrapper of MeCab::Tagger::parse(const char *str, char *ostr, size_t olen)
   */
  MECAB_DLL_EXTERN char*         mecab_sparse_tostr3(mecab_t *mecab, const char *str, size_t len,
                                                     char *ostr, size_t olen);

  /**
   * C wrapper of MeCab::Tagger::parseToNode(const char *str)
   */
  MECAB_DLL_EXTERN const mecab_node_t* mecab_sparse_tonode(mecab_t *mecab, const char*);

  /**
   * C wrapper of MeCab::Tagger::parseToNode(const char *str, size_t len)
   */
  MECAB_DLL_EXTERN const mecab_node_t* mecab_sparse_tonode2(mecab_t *mecab, const char*, size_t);

  /**
   * C wrapper of MeCab::Tagger::parseNBest(size_t N, const char *str)
   */
  MECAB_DLL_EXTERN const char*   mecab_nbest_sparse_tostr(mecab_t *mecab, size_t N, const char *str);

  /**
   * C wrapper of MeCab::Tagger::parseNBest(size_t N, const char *str, size_t len)
   */
  MECAB_DLL_EXTERN const char*   mecab_nbest_sparse_tostr2(mecab_t *mecab, size_t N,
                                                           const char *str, size_t len);

  /**
   * C wrapper of MeCab::Tagger::parseNBest(size_t N, const char *str, char *ostr, size_t olen)
   */
  MECAB_DLL_EXTERN char*         mecab_nbest_sparse_tostr3(mecab_t *mecab, size_t N,
                                                           const char *str, size_t len,
                                                           char *ostr, size_t olen);

  /**
   * C wrapper of MeCab::Tagger::parseNBestInit(const char *str)
   */
  MECAB_DLL_EXTERN int           mecab_nbest_init(mecab_t *mecab, const char *str);

  /**
   * C wrapper of MeCab::Tagger::parseNBestInit(const char *str, size_t len)
   */
  MECAB_DLL_EXTERN int           mecab_nbest_init2(mecab_t *mecab, const char *str, size_t len);

  /**
   * C wrapper of MeCab::Tagger::next()
   */
  MECAB_DLL_EXTERN const char*   mecab_nbest_next_tostr(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger::next(char *ostr, size_t olen)
   */
  MECAB_DLL_EXTERN char*         mecab_nbest_next_tostr2(mecab_t *mecab, char *ostr, size_t olen);

  /**
   * C wrapper of MeCab::Tagger::nextNode()
   */
  MECAB_DLL_EXTERN const mecab_node_t* mecab_nbest_next_tonode(mecab_t *mecab);

  /**
   * C wrapper of MeCab::Tagger::formatNode(const Node *node)
   */
  MECAB_DLL_EXTERN const char*   mecab_format_node(mecab_t *mecab, const mecab_node_t *node);

  /**
   * C wrapper of MeCab::Tagger::dictionary_info()
   */
  MECAB_DLL_EXTERN const mecab_dictionary_info_t* mecab_dictionary_info(mecab_t *mecab);

  /* lattice interface */
  /**
   * C wrapper of MeCab::createLattice()
   */
  MECAB_DLL_EXTERN mecab_lattice_t *mecab_lattice_new();

  /**
   * C wrapper of MeCab::deleteLattice(lattice)
   */
  MECAB_DLL_EXTERN void             mecab_lattice_destroy(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::clear()
   */
  MECAB_DLL_EXTERN void             mecab_lattice_clear(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::is_available()
   */

  MECAB_DLL_EXTERN int              mecab_lattice_is_available(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::bos_node()
   */
  MECAB_DLL_EXTERN mecab_node_t    *mecab_lattice_get_bos_node(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::eos_node()
   */
  MECAB_DLL_EXTERN mecab_node_t    *mecab_lattice_get_eos_node(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::begin_nodes()
   */

  MECAB_DLL_EXTERN mecab_node_t   **mecab_lattice_get_all_begin_nodes(mecab_lattice_t *lattice);
  /**
   * C wrapper of MeCab::Lattice::end_nodes()
   */
  MECAB_DLL_EXTERN mecab_node_t   **mecab_lattice_get_all_end_nodes(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::begin_nodes(pos)
   */
  MECAB_DLL_EXTERN mecab_node_t    *mecab_lattice_get_begin_nodes(mecab_lattice_t *lattice, size_t pos);

  /**
   * C wrapper of MeCab::Lattice::end_nodes(pos)
   */
  MECAB_DLL_EXTERN mecab_node_t    *mecab_lattice_get_end_nodes(mecab_lattice_t *lattice, size_t pos);

  /**
   * C wrapper of MeCab::Lattice::sentence()
   */
  MECAB_DLL_EXTERN const char      *mecab_lattice_get_sentence(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::set_sentence(sentence)
   */
  MECAB_DLL_EXTERN void             mecab_lattice_set_sentence(mecab_lattice_t *lattice, const char *sentence);

  /**
   * C wrapper of MeCab::Lattice::set_sentence(sentence, len)
   */

  MECAB_DLL_EXTERN void             mecab_lattice_set_sentence2(mecab_lattice_t *lattice, const char *sentence, size_t len);

  /**
   * C wrapper of MeCab::Lattice::size()
   */
  MECAB_DLL_EXTERN size_t           mecab_lattice_get_size(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::Z()
   */
  MECAB_DLL_EXTERN double           mecab_lattice_get_z(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::set_Z()
   */
  MECAB_DLL_EXTERN void             mecab_lattice_set_z(mecab_lattice_t *lattice, double Z);

  /**
   * C wrapper of MeCab::Lattice::theta()
   */
  MECAB_DLL_EXTERN double           mecab_lattice_get_theta(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::set_theta()
   */

  MECAB_DLL_EXTERN void             mecab_lattice_set_theta(mecab_lattice_t *lattice, double theta);

  /**
   * C wrapper of MeCab::Lattice::next()
   */
  MECAB_DLL_EXTERN int              mecab_lattice_next(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::request_type()
   */
  MECAB_DLL_EXTERN int              mecab_lattice_get_request_type(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::has_request_type()
   */
  MECAB_DLL_EXTERN int              mecab_lattice_has_request_type(mecab_lattice_t *lattice, int request_type);

  /**
   * C wrapper of MeCab::Lattice::set_request_type()
   */
  MECAB_DLL_EXTERN void             mecab_lattice_set_request_type(mecab_lattice_t *lattice, int request_type);

  /**
   * C wrapper of MeCab::Lattice::add_request_type()
   */

  MECAB_DLL_EXTERN void             mecab_lattice_add_request_type(mecab_lattice_t *lattice, int request_type);

  /**
   * C wrapper of MeCab::Lattice::remove_request_type()
   */
  MECAB_DLL_EXTERN void             mecab_lattice_remove_request_type(mecab_lattice_t *lattice, int request_type);

  /**
   * C wrapper of MeCab::Lattice::newNode();
   */
  MECAB_DLL_EXTERN mecab_node_t    *mecab_lattice_new_node(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::toString()
   */
  MECAB_DLL_EXTERN const char      *mecab_lattice_tostr(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::toString(buf, size)
   */
  MECAB_DLL_EXTERN const char      *mecab_lattice_tostr2(mecab_lattice_t *lattice, char *buf, size_t size);

  /**
   * C wrapper of MeCab::Lattice::enumNBestAsString(N)
   */
  MECAB_DLL_EXTERN const char      *mecab_lattice_nbest_tostr(mecab_lattice_t *lattice, size_t N);

  /**
   * C wrapper of MeCab::Lattice::enumNBestAsString(N, buf, size)
   */

  MECAB_DLL_EXTERN const char      *mecab_lattice_nbest_tostr2(mecab_lattice_t *lattice, size_t N, char *buf, size_t size);

  /**
   * C wrapper of MeCab::Lattice::has_constraint()
   */
  MECAB_DLL_EXTERN int             mecab_lattice_has_constraint(mecab_lattice_t *lattice);

  /**
   * C wrapper of MeCab::Lattice::boundary_constraint(pos)
   */
  MECAB_DLL_EXTERN int             mecab_lattice_get_boundary_constraint(mecab_lattice_t *lattice, size_t pos);


  /**
   * C wrapper of MeCab::Lattice::feature_constraint(pos)
   */
  MECAB_DLL_EXTERN const char     *mecab_lattice_get_feature_constraint(mecab_lattice_t *lattice, size_t pos);

  /**
   * C wrapper of MeCab::Lattice::boundary_constraint(pos, type)
   */
  MECAB_DLL_EXTERN void            mecab_lattice_set_boundary_constraint(mecab_lattice_t *lattice, size_t pos, int boundary_type);

  /**
   * C wrapper of MeCab::Lattice::set_feature_constraint(begin_pos, end_pos, feature)
   */
  MECAB_DLL_EXTERN void            mecab_lattice_set_feature_constraint(mecab_lattice_t *lattice, size_t begin_pos, size_t end_pos, const char *feature);

  /**
   * C wrapper of MeCab::Lattice::what()
   */
  MECAB_DLL_EXTERN const char      *mecab_lattice_strerror(mecab_lattice_t *lattice);


  /* model interface */
  /**
   * C wapper of MeCab::Model::create(argc, argv)
   */
  MECAB_DLL_EXTERN mecab_model_t   *mecab_model_new(int argc, char **argv);

  /**
   * C wapper of MeCab::Model::create(arg)
   */
  MECAB_DLL_EXTERN mecab_model_t   *mecab_model_new2(const char *arg);

  /**
   * C wapper of MeCab::deleteModel(model)
   */

  MECAB_DLL_EXTERN void             mecab_model_destroy(mecab_model_t *model);

  /**
   * C wapper of MeCab::Model::createTagger()
   */
  MECAB_DLL_EXTERN mecab_t         *mecab_model_new_tagger(mecab_model_t *model);

  /**
   * C wapper of MeCab::Model::createLattice()
   */
  MECAB_DLL_EXTERN mecab_lattice_t *mecab_model_new_lattice(mecab_model_t *model);

  /**
   * C wrapper of MeCab::Model::swap()
   */
  MECAB_DLL_EXTERN int mecab_model_swap(mecab_model_t *model, mecab_model_t *new_model);

  /**
   * C wapper of MeCab::Model::dictionary_info()
   */
  MECAB_DLL_EXTERN const mecab_dictionary_info_t* mecab_model_dictionary_info(mecab_model_t *model);

  /**
   * C wrapper of MeCab::Model::transition_cost()
   */
  MECAB_DLL_EXTERN int mecab_model_transition_cost(mecab_model_t *model,
                                                   unsigned short rcAttr,
                                                   unsigned short lcAttr);

  /**
   * C wrapper of MeCab::Model::lookup()
   */
  MECAB_DLL_EXTERN mecab_node_t *mecab_model_lookup(mecab_model_t *model,
                                                    const char *begin,
                                                    const char *end,
                                                    mecab_lattice_t *lattice);

  /* static functions */
  MECAB_DLL_EXTERN int           mecab_do(int argc, char **argv);
  MECAB_DLL_EXTERN int           mecab_dict_index(int argc, char **argv);
  MECAB_DLL_EXTERN int           mecab_dict_gen(int argc, char **argv);
  MECAB_DLL_EXTERN int           mecab_cost_train(int argc, char **argv);
  MECAB_DLL_EXTERN int           mecab_system_eval(int argc, char **argv);
  MECAB_DLL_EXTERN int           mecab_test_gen(int argc, char **argv);
#endif

#ifdef __cplusplus
}
#endif

/* C++ interface */
#ifdef __cplusplus

namespace MeCab {
typedef struct mecab_dictionary_info_t DictionaryInfo;
typedef struct mecab_path_t            Path;
typedef struct mecab_node_t            Node;

template <typename N, typename P> class Allocator;
class Tagger;

/**
 * Lattice class
 */
class MECAB_DLL_CLASS_EXTERN Lattice {
public:

  virtual void set_result(const char *str)        = 0;

  /**
   * Clear all internal lattice data.
   */
  virtual void clear()              = 0;

  /**
   * Return true if result object is available.
   * @return boolean
   */
  virtual bool is_available() const = 0;

  /**
   * Return bos (begin of sentence) node.
   * You can obtain all nodes via "for (const Node *node = lattice->bos_node(); node; node = node->next) {}"
   * @return bos node object
   */
  virtual Node *bos_node() const              = 0;

  /**
   * Return eos (end of sentence) node.
   * @return eos node object
   */
  virtual Node *eos_node() const              = 0;

#ifndef SWIG
  /**
   * This method is used internally.
   */
  virtual Node **begin_nodes() const          = 0;

  /**
   * This method is used internally.
   */
  virtual Node **end_nodes() const            = 0;
#endif

  /**
   * Return node linked list ending at |pos|.
   * You can obtain all nodes via "for (const Node *node = lattice->end_nodes(pos); node; node = node->enext) {}"
   * @param pos position of nodes. 0 <= pos < size()
   * @return node linked list
   */
  virtual Node *end_nodes(size_t pos) const   = 0;

  /**
   * Return node linked list starting at |pos|.
   * You can obtain all nodes via "for (const Node *node = lattice->begin_nodes(pos); node; node = node->bnext) {}"
   * @param pos position of nodes. 0 <= pos < size()
   * @return node linked list
   */
  virtual Node *begin_nodes(size_t pos) const = 0;

  /**
   * Return sentence.
   * If MECAB_NBEST or MECAB_PARTIAL mode is off, the returned poiner is the same as the one set by set_sentence().
   * @return sentence
   */
  virtual const char *sentence() const = 0;

  /**
   * Set sentence. This method does not take the ownership of the object.
   * @param sentence sentence
   */
  virtual void set_sentence(const char *sentence)             = 0;

#ifndef SWIG
  /**
   * Set sentence. This method does not take the ownership of the object.
   * @param sentence sentence
   * @param len length of the sentence
   */
  virtual void set_sentence(const char *sentence, size_t len) = 0;
#endif

  /**
   * Return sentence size.
   * @return sentence size
   */
  virtual size_t size() const                                 = 0;

  /**
   * Set normalization factor of CRF.
   * @param Z new normalization factor.
   */
  virtual void   set_Z(double Z) = 0;

  /**
   * return normalization factor of CRF.
   * @return normalization factor.
   */
  virtual double Z() const = 0;

  /**
   * Set temparature parameter theta.
   * @param theta temparature parameter.
   */
  virtual void  set_theta(float theta) = 0;

  /**
   * Return temparature parameter theta.
   * @return temparature parameter.
   */
  virtual float theta() const          = 0;

  /**
   * Obtain next-best result. The internal linked list structure is updated.
   * You should set MECAB_NBEST reques_type in advance.
   * Return false if no more results are available or request_type is invalid.
   * @return boolean
   */
  virtual bool next() = 0;

  /**
   * Return the current request type.
   * @return request type
   */
  virtual int request_type() const                = 0;

  /**
   * Return true if the object has a specified request type.
   * @return boolean
   */
  virtual bool has_request_type(int request_type) const = 0;

  /**
   * Set request type.
   * @param request_type new request type assigned
   */
  virtual void set_request_type(int request_type) = 0;

  /**
   * Add request type.
   * @param request_type new request type added
   */
  virtual void add_request_type(int request_type) = 0;

  /**
   * Remove request type.
   * @param request_type new request type removed
   */
  virtual void remove_request_type(int request_type) = 0;

#ifndef SWIG
  /**
   * This method is used internally.
   */
  virtual Allocator<Node, Path> *allocator() const = 0;
#endif

  /**
   * Return new node. Lattice objects has the ownership of the node.
   * @return new node object
   */
  virtual Node *newNode() = 0;

  /**
   * Return string representation of the lattice.
   * Returned object is managed by this instance. When clear/set_sentence() method
   * is called, the returned buffer is initialized.
   * @return string representation of the lattice
   */
  virtual const char *toString()                = 0;

  /**
   * Return string representation of the node.
   * Returned object is managed by this instance. When clear/set_sentence() method
   * is called, the returned buffer is initialized.
   * @return string representation of the node
   * @param node node object
   */
  virtual const char *toString(const Node *node) = 0;

  /**
   * Return string representation of the N-best results.
   * Returned object is managed by this instance. When clear/set_sentence() method
   * is called, the returned buffer is initialized.
   * @return string representation of the node
   * @param N how many results you want to obtain
   */
  virtual const char *enumNBestAsString(size_t N) = 0;

#ifndef SWIG
  /**
   * Return string representation of the lattice.
   * Result is saved in the specified buffer.
   * @param buf output buffer
   * @param size output buffer size
   * @return string representation of the lattice
   */
  virtual const char *toString(char *buf, size_t size) = 0;

  /**
   * Return string representation of the node.
   * Result is saved in the specified buffer.
   * @param node node object
   * @param buf output buffer
   * @param size output buffer size
   * @return string representation of the lattice
   */
  virtual const char *toString(const Node *node,
                               char *buf, size_t size) = 0;

  /**
   * Return string representation of the N-best result.
   * Result is saved in the specified.
   * @param N how many results you want to obtain
   * @param buf output buffer
   * @param size output buffer size
   * @return string representation of the lattice
   */
  virtual const char *enumNBestAsString(size_t N, char *buf, size_t size) = 0;
#endif

  /**
   * Returns true if any parsing constraint is set
   */
  virtual bool has_constraint() const = 0;

  /**
   * Returns the boundary constraint at the position.
   * @param pos the position of constraint
   * @return boundary constraint type
   */
  virtual int boundary_constraint(size_t pos) const = 0;

  /**
   * Returns the token constraint at the position.
   * @param pos the beginning position of constraint.
   * @return constrained node starting at the position.
   */
  virtual const char *feature_constraint(size_t pos) const = 0;

  /**
   * Set parsing constraint for partial parsing mode.
   * @param pos the position of the boundary
   * @param boundary_constraint_type the type of boundary
   */
  virtual void set_boundary_constraint(size_t pos,
                                       int boundary_constraint_type) = 0;

  /**
   * Set parsing constraint for partial parsing mode.
   * @param begin_pos the starting position of the constrained token.
   * @param end_pos the the ending position of the constrained token.
   * @param feature the feature of the constrained token.
   */
  virtual void set_feature_constraint(
      size_t begin_pos, size_t end_pos,
      const char *feature) = 0;

  /**
   * Return error string.
   * @return error string
   */
  virtual const char *what() const            = 0;

  /**
   * Set error string. given string is copied to the internal buffer.
   * @param str new error string
   */
  virtual void set_what(const char *str)        = 0;

#ifndef SWIG
  /**
   * Create new Lattice object
   * @return new Lattice object
   */
  static Lattice *create();
#endif

  virtual ~Lattice() {}
};

/**
 * Model class
 */
class MECAB_DLL_CLASS_EXTERN Model {
public:
  /**
   * Return DictionaryInfo linked list.
   * @return DictionaryInfo linked list
   */
  virtual const DictionaryInfo *dictionary_info() const = 0;

  /**
   * Return transtion cost from rcAttr to lcAttr.
   * @return transtion cost
   */
  virtual int transition_cost(unsigned short rcAttr,
                              unsigned short lcAttr) const = 0;

  /**
   * perform common prefix search from the range [begin, end).
   * |lattice| takes the ownership of return value.
   * @return node linked list.
   */
  virtual Node *lookup(const char *begin, const char *end,
                       Lattice *lattice) const = 0;

  /**
   * Create a new Tagger object.
   * All returned tagger object shares this model object as a parsing model.
   * Never delete this model object before deleting tagger object.
   * @return new Tagger object
   */
  virtual Tagger  *createTagger() const = 0;

  /**
   * Create a new Lattice object.
   * @return new Lattice object
   */
  virtual Lattice *createLattice() const = 0;

  /**
   * Swap the instance with |model|.
   * The ownership of |model| always moves to this instance,
   * meaning that passed |model| will no longer be accessible after calling this method.
   * return true if new model is swapped successfully.
   * This method is thread safe. All taggers created by
   * Model::createTagger() method will also be updated asynchronously.
   * No need to stop the parsing thread excplicitly before swapping model object.
   * @return boolean
   * @param model new model which is going to be swapped with the current model.
   */
  virtual bool swap(Model *model) = 0;

  /**
   * Return a version string
   * @return version string
   */
  static const char *version();

  virtual ~Model() {}

#ifndef SIWG
  /**
   * Factory method to create a new Model with a specified main's argc/argv-style parameters.
   * Return NULL if new model cannot be initialized. Use MeCab::getLastError() to obtain the
   * cause of the errors.
   * @return new Model object
   * @param argc number of parameters
   * @param argv parameter list
   */
  static Model* create(int argc, char **argv);

  /**
   * Factory method to create a new Model with a string parameter representation, i.e.,
   * "-d /user/local/mecab/dic/ipadic -Ochasen".
   * Return NULL if new model cannot be initialized. Use MeCab::getLastError() to obtain the
   * cause of the errors.
   * @return new Model object
   * @param arg single string representation of the argment.
   */
  static Model* create(const char *arg);
#endif
};

/**
 * Tagger class
 */
class MECAB_DLL_CLASS_EXTERN Tagger {
public:
  /**
   * Handy static method.
   * Return true if lattice is parsed successfully.
   * This function is equivalent to
   * {
   *   Tagger *tagger = model.createModel();
   *   cosnt bool result = tagger->parse(lattice);
   *   delete tagger;
   *   return result;
   * }
   * @return boolean
   */
  static bool  parse(const Model &model, Lattice *lattice);

  /**
   * Parse lattice object.
   * Return true if lattice is parsed successfully.
   * A sentence must be set to the lattice with Lattice:set_sentence object before calling this method.
   * Parsed node object can be obtained with Lattice:bos_node.
   * This method is thread safe.
   * @return lattice lattice object
   * @return boolean
   */
  virtual bool parse(Lattice *lattice) const                = 0;

  /**
   * Parse given sentence and return parsed result as string.
   * You should not delete the returned string. The returned buffer
   * is overwritten when parse method is called again.
   * This method is NOT thread safe.
   * @param str sentence
   * @return parsed result
   */
  virtual const char* parse(const char *str)                = 0;

  /**
   * Parse given sentence and return Node object.
   * You should not delete the returned node object. The returned buffer
   * is overwritten when parse method is called again.
   * You can traverse all nodes via Node::next member.
   * This method is NOT thread safe.
   * @param str sentence
   * @return bos node object
   */
  virtual const Node* parseToNode(const char *str)          = 0;

  /**
   * Parse given sentence and obtain N-best results as a string format.
   * Currently, N must be 1 <= N <= 512 due to the limitation of the buffer size.
   * You should not delete the returned string. The returned buffer
   * is overwritten when parse method is called again.
   * This method is DEPRECATED. Use Lattice class.
   * @param N how many results you want to obtain
   * @param str sentence
   * @return parsed result
   */
  virtual const char* parseNBest(size_t N, const char *str) = 0;

  /**
   * Initialize N-best enumeration with a sentence.
   * Return true if initialization finishes successfully.
   * N-best result is obtained by calling next() or nextNode() in sequence.
   * This method is NOT thread safe.
   * This method is DEPRECATED. Use Lattice class.
   * @param str sentence
   * @return boolean
   */
  virtual bool  parseNBestInit(const char *str)             = 0;

  /**
   * Return next-best parsed result. You must call parseNBestInit() in advance.
   * Return NULL if no more reuslt is available.
   * This method is NOT thread safe.
   * This method is DEPRECATED. Use Lattice class.
   * @return node object
   */
  virtual const Node* nextNode()                            = 0;

  /**
   * Return next-best parsed result. You must call parseNBestInit() in advance.
   * Return NULL if no more reuslt is available.
   * This method is NOT thread safe.
   * This method is DEPRECATED. Use Lattice class.
   * @return parsed result
   */
  virtual const char* next()                                = 0;

  /**
   * Return formatted node object. The format is specified with
   * --unk-format, --bos-format, --eos-format, and --eon-format respectively.
   * You should not delete the returned string. The returned buffer
   * is overwritten when parse method is called again.
   * This method is NOT thread safe.
   * This method is DEPRECATED. Use Lattice class.
   * @param node node object.
   * @return parsed result
   */
  virtual const char* formatNode(const Node *node)          = 0;

#ifndef SWIG
  /**
   * The same as parse() method, but input length and output buffer are passed.
   * Return parsed result as string. The result pointer is the same as |ostr|.
   * Return NULL, if parsed result string cannot be stored within |olen| bytes.
   * @param str sentence
   * @param len sentence length
   * @param ostr output buffer
   * @param olen output buffer length
   * @return parsed result
   */
  virtual const char* parse(const char *str, size_t len, char *ostr, size_t olen) = 0;

  /**
   * The same as parse() method, but input length can be passed.
   * @param str sentence
   * @param len sentence length
   * @return parsed result
   */
  virtual const char* parse(const char *str, size_t len)                          = 0;

  /**
   * The same as parseToNode(), but input lenth can be passed.
   * @param str sentence
   * @param len sentence length
   * @return node object
   */
  virtual const Node* parseToNode(const char *str, size_t len)                    = 0;

  /**
   * The same as parseNBest(), but input length can be passed.
   * @param N how many results you want to obtain
   * @param str sentence
   * @param len sentence length
   * @return parsed result
   */
  virtual const char* parseNBest(size_t N, const char *str, size_t len)           = 0;

  /**
   * The same as parseNBestInit(), but input length can be passed.
   * @param str sentence
   * @param len sentence length
   * @return boolean
   * @return parsed result
   */
  virtual bool  parseNBestInit(const char *str, size_t len)                  = 0;

  /**
   * The same as next(), but output buffer can be passed.
   * Return NULL if more than |olen| buffer is required to store output string.
   * @param ostr output buffer
   * @param olen output buffer length
   * @return parsed result
   */
  virtual const char* next(char *ostr , size_t olen)                        = 0;

  /**
   * The same as parseNBest(), but input length and output buffer can be passed.
   * Return NULL if more than |olen| buffer is required to store output string.
   * @param N how many results you want to obtain
   * @param str input sentence
   * @param len input sentence length
   * @param ostr output buffer
   * @param olen output buffer length
   * @return parsed result
   */
  virtual const char* parseNBest(size_t N, const char *str,
                                 size_t len, char *ostr, size_t olen)       = 0;

  /**
   * The same as formatNode(), but output buffer can be passed.
   * Return NULL if more than |olen| buffer is required to store output string.
   * @param node node object
   * @param ostr output buffer
   * @param olen output buffer length
   * @return parsed result
   */
  virtual const char* formatNode(const Node *node, char *ostr, size_t olen) = 0;
#endif

  /**
   * Set request type.
   * This method is DEPRECATED. Use Lattice::set_request_type(MECAB_PARTIAL).
   * @param request_type new request type assigned
   */
  virtual void set_request_type(int request_type) = 0;

  /**
   * Return the current request type.
   * This method is DEPRECATED. Use Lattice class.
   * @return request type
   */
  virtual int  request_type() const = 0;

  /**
   * Return true if partial parsing mode is on.
   * This method is DEPRECATED. Use Lattice::has_request_type(MECAB_PARTIAL).
   * @return boolean
   */
  virtual bool  partial() const                             = 0;

  /**
   * set partial parsing mode.
   * This method is DEPRECATED. Use Lattice::add_request_type(MECAB_PARTIAL) or Lattice::remove_request_type(MECAB_PARTIAL)
   * @param partial partial mode
   */
  virtual void  set_partial(bool partial)                   = 0;

  /**
   * Return lattice level.
   * This method is DEPRECATED. Use Lattice::*_request_type()
   * @return int lattice level
   */
  virtual int   lattice_level() const                       = 0;

  /**
   * Set lattice level.
   * This method is DEPRECATED. Use Lattice::*_request_type()
   * @param level lattice level
   */
  virtual void  set_lattice_level(int level)                = 0;

  /**
   * Return true if all morphs output mode is on.
   * This method is DEPRECATED. Use Lattice::has_request_type(MECAB_ALL_MORPHS).
   * @return boolean
   */
  virtual bool  all_morphs() const                          = 0;

  /**
   * set all-morphs output mode.
   * This method is DEPRECATED. Use Lattice::add_request_type(MECAB_ALL_MORPHS) or Lattice::remove_request_type(MECAB_ALL_MORPHS)
   * @param all_morphs
   */
  virtual void  set_all_morphs(bool all_morphs)             = 0;

  /**
   * Set temparature parameter theta.
   * @param theta temparature parameter.
   */
  virtual void  set_theta(float theta)                      = 0;

  /**
   * Return temparature parameter theta.
   * @return temparature parameter.
   */
  virtual float theta() const                               = 0;

  /**
   * Return DictionaryInfo linked list.
   * @return DictionaryInfo linked list
   */
  virtual const DictionaryInfo* dictionary_info() const = 0;

  /**
   * Return error string.
   * @return error string
   */
  virtual const char* what() const = 0;

  virtual ~Tagger() {}

#ifndef SIWG
  /**
   * Factory method to create a new Tagger with a specified main's argc/argv-style parameters.
   * Return NULL if new model cannot be initialized. Use MeCab::getLastError() to obtain the
   * cause of the errors.
   * @return new Tagger object
   * @param argc number of parameters
   * @param argv parameter list
   */
  static Tagger *create(int argc, char **argv);

  /**
   * Factory method to create a new Tagger with a string parameter representation, i.e.,
   * "-d /user/local/mecab/dic/ipadic -Ochasen".
   * Return NULL if new model cannot be initialized. Use MeCab::getLastError() to obtain the
   * cause of the errors.
   * @return new Model object
   * @param arg single string representation of the argment.
   */
  static Tagger *create(const char *arg);
#endif

  /**
   * Return a version string
   * @return version string
   */
  static const char *version();
};

#ifndef SWIG
/**
 * Alias of Lattice::create()
 */
MECAB_DLL_EXTERN Lattice     *createLattice();

/**
 * Alias of Mode::create(argc, argv)
 */
MECAB_DLL_EXTERN Model       *createModel(int argc, char **argv);

/**
 * Alias of Mode::create(arg)
 */
MECAB_DLL_EXTERN Model       *createModel(const char *arg);

/**
 * Alias of Tagger::create(argc, argv)
 */
MECAB_DLL_EXTERN Tagger      *createTagger(int argc, char **argv);

/**
 * Alias of Tagger::create(arg)
 */
MECAB_DLL_EXTERN Tagger      *createTagger(const char *arg);

/**
 * delete Lattice object.
 * This method calles "delete lattice".
 * In some environment, e.g., MS-Windows, an object allocated inside a DLL must be deleted in the same DLL too.
 * @param lattice lattice object
 */
MECAB_DLL_EXTERN void        deleteLattice(Lattice *lattice);


/**
 * delete Model object.
 * This method calles "delete model".
 * In some environment, e.g., MS-Windows, an object allocated inside a DLL must be deleted in the same DLL too.
 * @param model model object
 */
MECAB_DLL_EXTERN void        deleteModel(Model *model);

/**
 * delete Tagger object.
 * This method calles "delete tagger".
 * In some environment, e.g., MS-Windows, an object allocated inside a DLL must be deleted in the same DLL too.
 * @param tagger tagger object
 */
MECAB_DLL_EXTERN void        deleteTagger(Tagger *tagger);

/**
 * Return last error string.
 * @return error string
 */
MECAB_DLL_EXTERN const char*  getLastError();

/**
 * An alias of getLastError.
 * It is kept for backward compatibility.
 * @return error string
 */
MECAB_DLL_EXTERN const char*  getTaggerError();
#endif
}
#endif
#endif  /* MECAB_MECAB_H_ */


resulting mecab.bi file:

Code: Select all

#pragma once

#include once "crt/long.bi"
#include once "crt/stdio.bi"
#include once "windows.bi"

extern "C"

#define MECAB_MECAB_H_

type mecab_dictionary_info_t
   filename as const zstring ptr
   charset as const zstring ptr
   size as ulong
   as long type
   lsize as ulong
   rsize as ulong
   version as ushort
   next as mecab_dictionary_info_t ptr
end type

type mecab_node_t as mecab_node_t_

type mecab_path_t
   rnode as mecab_node_t ptr
   rnext as mecab_path_t ptr
   lnode as mecab_node_t ptr
   lnext as mecab_path_t ptr
   cost as long
   prob as single
end type

type mecab_node_t_
   prev as mecab_node_t ptr
   next as mecab_node_t ptr
   enext as mecab_node_t ptr
   bnext as mecab_node_t ptr
   rpath as mecab_path_t ptr
   lpath as mecab_path_t ptr
   surface as const zstring ptr
   feature as const zstring ptr
   id as ulong
   length as ushort
   rlength as ushort
   rcAttr as ushort
   lcAttr as ushort
   posid as ushort
   char_type as ubyte
   stat as ubyte
   isbest as ubyte
   alpha as single
   beta as single
   prob as single
   wcost as short
   cost as clong
end type

enum
   MECAB_NOR_NODE = 0
   MECAB_UNK_NODE = 1
   MECAB_BOS_NODE = 2
   MECAB_EOS_NODE = 3
   MECAB_EON_NODE = 4
end enum

enum
   MECAB_SYS_DIC = 0
   MECAB_USR_DIC = 1
   MECAB_UNK_DIC = 2
end enum

enum
   MECAB_ONE_BEST = 1
   MECAB_NBEST = 2
   MECAB_PARTIAL = 4
   MECAB_MARGINAL_PROB = 8
   MECAB_ALTERNATIVE = 16
   MECAB_ALL_MORPHS = 32
   MECAB_ALLOCATE_SENTENCE = 64
end enum

enum
   MECAB_ANY_BOUNDARY = 0
   MECAB_TOKEN_BOUNDARY = 1
   MECAB_INSIDE_TOKEN = 2
end enum

#define MECAB_DLL_EXTERN __declspec(dllimport)
#define MECAB_DLL_CLASS_EXTERN
declare function mecab_new(byval argc as long, byval argv as zstring ptr ptr) as mecab_t ptr
declare function mecab_new2(byval arg as const zstring ptr) as mecab_t ptr
declare function mecab_version() as const zstring ptr
declare function mecab_strerror(byval mecab as mecab_t ptr) as const zstring ptr
declare sub mecab_destroy(byval mecab as mecab_t ptr)
declare function mecab_get_partial(byval mecab as mecab_t ptr) as long
declare sub mecab_set_partial(byval mecab as mecab_t ptr, byval partial as long)
declare function mecab_get_theta(byval mecab as mecab_t ptr) as single
declare sub mecab_set_theta(byval mecab as mecab_t ptr, byval theta as single)
declare function mecab_get_lattice_level(byval mecab as mecab_t ptr) as long
declare sub mecab_set_lattice_level(byval mecab as mecab_t ptr, byval level as long)
declare function mecab_get_all_morphs(byval mecab as mecab_t ptr) as long
declare sub mecab_set_all_morphs(byval mecab as mecab_t ptr, byval all_morphs as long)
declare function mecab_parse_lattice(byval mecab as mecab_t ptr, byval lattice as mecab_lattice_t ptr) as long
declare function mecab_sparse_tostr(byval mecab as mecab_t ptr, byval str as const zstring ptr) as const zstring ptr
declare function mecab_sparse_tostr2(byval mecab as mecab_t ptr, byval str as const zstring ptr, byval len as uinteger) as const zstring ptr
declare function mecab_sparse_tostr3(byval mecab as mecab_t ptr, byval str as const zstring ptr, byval len as uinteger, byval ostr as zstring ptr, byval olen as uinteger) as zstring ptr
declare function mecab_sparse_tonode(byval mecab as mecab_t ptr, byval as const zstring ptr) as const mecab_node_t ptr
declare function mecab_sparse_tonode2(byval mecab as mecab_t ptr, byval as const zstring ptr, byval as uinteger) as const mecab_node_t ptr
declare function mecab_nbest_sparse_tostr(byval mecab as mecab_t ptr, byval N as uinteger, byval str as const zstring ptr) as const zstring ptr
declare function mecab_nbest_sparse_tostr2(byval mecab as mecab_t ptr, byval N as uinteger, byval str as const zstring ptr, byval len as uinteger) as const zstring ptr
declare function mecab_nbest_sparse_tostr3(byval mecab as mecab_t ptr, byval N as uinteger, byval str as const zstring ptr, byval len as uinteger, byval ostr as zstring ptr, byval olen as uinteger) as zstring ptr
declare function mecab_nbest_init(byval mecab as mecab_t ptr, byval str as const zstring ptr) as long
declare function mecab_nbest_init2(byval mecab as mecab_t ptr, byval str as const zstring ptr, byval len as uinteger) as long
declare function mecab_nbest_next_tostr(byval mecab as mecab_t ptr) as const zstring ptr
declare function mecab_nbest_next_tostr2(byval mecab as mecab_t ptr, byval ostr as zstring ptr, byval olen as uinteger) as zstring ptr
declare function mecab_nbest_next_tonode(byval mecab as mecab_t ptr) as const mecab_node_t ptr
declare function mecab_format_node(byval mecab as mecab_t ptr, byval node as const mecab_node_t ptr) as const zstring ptr
declare function mecab_dictionary_info(byval mecab as mecab_t ptr) as const mecab_dictionary_info_t ptr
declare function mecab_lattice_new() as mecab_lattice_t ptr
declare sub mecab_lattice_destroy(byval lattice as mecab_lattice_t ptr)
declare sub mecab_lattice_clear(byval lattice as mecab_lattice_t ptr)
declare function mecab_lattice_is_available(byval lattice as mecab_lattice_t ptr) as long
declare function mecab_lattice_get_bos_node(byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr
declare function mecab_lattice_get_eos_node(byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr
declare function mecab_lattice_get_all_begin_nodes(byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr ptr
declare function mecab_lattice_get_all_end_nodes(byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr ptr
declare function mecab_lattice_get_begin_nodes(byval lattice as mecab_lattice_t ptr, byval pos as uinteger) as mecab_node_t ptr
declare function mecab_lattice_get_end_nodes(byval lattice as mecab_lattice_t ptr, byval pos as uinteger) as mecab_node_t ptr
declare function mecab_lattice_get_sentence(byval lattice as mecab_lattice_t ptr) as const zstring ptr
declare sub mecab_lattice_set_sentence(byval lattice as mecab_lattice_t ptr, byval sentence as const zstring ptr)
declare sub mecab_lattice_set_sentence2(byval lattice as mecab_lattice_t ptr, byval sentence as const zstring ptr, byval len as uinteger)
declare function mecab_lattice_get_size(byval lattice as mecab_lattice_t ptr) as uinteger
declare function mecab_lattice_get_z(byval lattice as mecab_lattice_t ptr) as double
declare sub mecab_lattice_set_z(byval lattice as mecab_lattice_t ptr, byval Z as double)
declare function mecab_lattice_get_theta(byval lattice as mecab_lattice_t ptr) as double
declare sub mecab_lattice_set_theta(byval lattice as mecab_lattice_t ptr, byval theta as double)
declare function mecab_lattice_next(byval lattice as mecab_lattice_t ptr) as long
declare function mecab_lattice_get_request_type(byval lattice as mecab_lattice_t ptr) as long
declare function mecab_lattice_has_request_type(byval lattice as mecab_lattice_t ptr, byval request_type as long) as long
declare sub mecab_lattice_set_request_type(byval lattice as mecab_lattice_t ptr, byval request_type as long)
declare sub mecab_lattice_add_request_type(byval lattice as mecab_lattice_t ptr, byval request_type as long)
declare sub mecab_lattice_remove_request_type(byval lattice as mecab_lattice_t ptr, byval request_type as long)
declare function mecab_lattice_new_node(byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr
declare function mecab_lattice_tostr(byval lattice as mecab_lattice_t ptr) as const zstring ptr
declare function mecab_lattice_tostr2(byval lattice as mecab_lattice_t ptr, byval buf as zstring ptr, byval size as uinteger) as const zstring ptr
declare function mecab_lattice_nbest_tostr(byval lattice as mecab_lattice_t ptr, byval N as uinteger) as const zstring ptr
declare function mecab_lattice_nbest_tostr2(byval lattice as mecab_lattice_t ptr, byval N as uinteger, byval buf as zstring ptr, byval size as uinteger) as const zstring ptr
declare function mecab_lattice_has_constraint(byval lattice as mecab_lattice_t ptr) as long
declare function mecab_lattice_get_boundary_constraint(byval lattice as mecab_lattice_t ptr, byval pos as uinteger) as long
declare function mecab_lattice_get_feature_constraint(byval lattice as mecab_lattice_t ptr, byval pos as uinteger) as const zstring ptr
declare sub mecab_lattice_set_boundary_constraint(byval lattice as mecab_lattice_t ptr, byval pos as uinteger, byval boundary_type as long)
declare sub mecab_lattice_set_feature_constraint(byval lattice as mecab_lattice_t ptr, byval begin_pos as uinteger, byval end_pos as uinteger, byval feature as const zstring ptr)
declare function mecab_lattice_strerror(byval lattice as mecab_lattice_t ptr) as const zstring ptr
declare function mecab_model_new(byval argc as long, byval argv as zstring ptr ptr) as mecab_model_t ptr
declare function mecab_model_new2(byval arg as const zstring ptr) as mecab_model_t ptr
declare sub mecab_model_destroy(byval model as mecab_model_t ptr)
declare function mecab_model_new_tagger(byval model as mecab_model_t ptr) as mecab_t ptr
declare function mecab_model_new_lattice(byval model as mecab_model_t ptr) as mecab_lattice_t ptr
declare function mecab_model_swap(byval model as mecab_model_t ptr, byval new_model as mecab_model_t ptr) as long
declare function mecab_model_dictionary_info(byval model as mecab_model_t ptr) as const mecab_dictionary_info_t ptr
declare function mecab_model_transition_cost(byval model as mecab_model_t ptr, byval rcAttr as ushort, byval lcAttr as ushort) as long
declare function mecab_model_lookup(byval model as mecab_model_t ptr, byval begin as const zstring ptr, byval end as const zstring ptr, byval lattice as mecab_lattice_t ptr) as mecab_node_t ptr
declare function mecab_do(byval argc as long, byval argv as zstring ptr ptr) as long
declare function mecab_dict_index(byval argc as long, byval argv as zstring ptr ptr) as long
declare function mecab_dict_gen(byval argc as long, byval argv as zstring ptr ptr) as long
declare function mecab_cost_train(byval argc as long, byval argv as zstring ptr ptr) as long
declare function mecab_system_eval(byval argc as long, byval argv as zstring ptr ptr) as long
declare function mecab_test_gen(byval argc as long, byval argv as zstring ptr ptr) as long

end extern


but there a no definitions for "mecab_t" type - what can i do wth those variables?
St_W
Posts: 1477
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: fbfrog header translator

Postby St_W » Jan 08, 2019 9:45

You do not need to know the internal structure of mecab_t, all you get is a pointer to that structure. The library deals with that structure internally, but you shouldn't tamper with it and therefore the structure itself isn't made visible through the definition in the header. You can consider mecab_t as defined with "type mecab_t as any".
Iczer
Posts: 52
Joined: Jul 04, 2017 18:09

Re: fbfrog header translator

Postby Iczer » Jan 08, 2019 23:03

Thanks!

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests