Modules
ADT Database GTK2 GUI IP PiJAX Public Sql Stdio Subversion System Tools Xosd lua v4l2 wx
Recent Changes
Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0
Popular Downloads
Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48
|
Module Information
Public.Tools.Language.Hyphenate
Viewing contents of Public_Tools_Language_Hyphenate-1.0/hyphenate.c
/* Generated from "hyphenate.cmod" by precompile.pike
*
* Do NOT edit this file.
*/
#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 2
/*! @module Public
*/
/*! @module Tools
*/
/*! @module Language
*/
#line 10 "hyphenate.cmod"
#define _GNU_SOURCE
#include "hyphenate_config.h"
#include "util.h"
#include "altlinux/hyphen.h"
#include "altlinux/csutil.h"
/*! @class Hyphenate
*/
#undef class_Hyphenate_defined
#define class_Hyphenate_defined
struct program *Hyphenate_program=NULL;
static int Hyphenate_program_fun_num=-1;
#line 24 "hyphenate.cmod"
typedef struct
{
HyphenDict * dict;
} HYPHENATE_OBJECT_DATA;
#undef var_object_data_Hyphenate_defined
#define var_object_data_Hyphenate_defined
#undef THIS
#define THIS ((struct Hyphenate_struct *)(Pike_interpreter.frame_pointer->current_storage))
#undef THIS_HYPHENATE
#define THIS_HYPHENATE ((struct Hyphenate_struct *)(Pike_interpreter.frame_pointer->current_storage))
#undef OBJ2_HYPHENATE
#define OBJ2_HYPHENATE(o) ((struct Hyphenate_struct *)(o->storage+Hyphenate_storage_offset))
#undef GET_HYPHENATE_STORAGE
#define GET_HYPHENATE_STORAGE ((struct Hyphenate_struct *)(o->storage+Hyphenate_storage_offset)
static ptrdiff_t Hyphenate_storage_offset;
struct Hyphenate_struct {
#ifdef var_object_data_Hyphenate_defined
#line 29 "hyphenate.cmod"
HYPHENATE_OBJECT_DATA *object_data;
#endif /* var_object_data_Hyphenate_defined */
};
/*! @decl void create(string appname)
*! Creates a new Public.Sample.Sample object
*!
*/
#define f_Hyphenate_create_defined
ptrdiff_t f_Hyphenate_create_fun_num = 0;
void f_Hyphenate_create(INT32 args) {
#line 36 "hyphenate.cmod"
struct pike_string * dictionary;
#line 36 "hyphenate.cmod"
if(args != 1) wrong_number_of_args_error("create",args,1);
#line 36 "hyphenate.cmod"
if(Pike_sp[0-1].type != PIKE_T_STRING) SIMPLE_BAD_ARG_ERROR("create",1,"string");
#line 36 "hyphenate.cmod"
debug_malloc_pass(dictionary=Pike_sp[0-1].u.string);
{
HyphenDict * hd;
char * dn;
dn = strdup(dictionary->str);
hd = hnj_hyphen_load(dn);
if(!hd)
{
Pike_error("unable to load hyphenation dictionary.\n");
}
THIS->object_data->dict = hd;
pop_n_elems(args);
}
}
#define f_Hyphenate_hyphenate_defined
ptrdiff_t f_Hyphenate_hyphenate_fun_num = 0;
void f_Hyphenate_hyphenate(INT32 args) {
#line 53 "hyphenate.cmod"
struct pike_string * word;
#line 53 "hyphenate.cmod"
if(args != 1) wrong_number_of_args_error("hyphenate",args,1);
#line 53 "hyphenate.cmod"
if(Pike_sp[0-1].type != PIKE_T_STRING) SIMPLE_BAD_ARG_ERROR("hyphenate",1,"string");
#line 53 "hyphenate.cmod"
debug_malloc_pass(word=Pike_sp[0-1].u.string);
{
int k, n, i, j, c;
int nHyphCount;
char *hyphens;
char *lcword;
char *hyphword;
k = word->len;
/* *(word + k - 1) = '\0'; */
/* set aside some buffers to hold lower cased */
/* and hyphen information */
lcword = (char *) malloc(k+1);
hyphens = (char *)malloc(k+5);
enmkallsmall(lcword,word->str,THIS->object_data->dict->cset);
/*printf("hyphenating\n"); */
/* first remove any trailing periods */
n = k-1;
while((n >=0) && (lcword[n] == '.')) n--;
n++;
/* now actually try to hyphenate the word */
if (n > 0) {
if (hnj_hyphen_hyphenate(THIS->object_data->dict, lcword, n-1, hyphens))
{
free(hyphens);
free(lcword);
pop_n_elems(args);
Pike_error("hyphenation error\n");
}
/* now backfill hyphens[] for any removed periods */
for (c = n; c < k; c++) hyphens[c] = '0';
hyphens[k] = '\0';
/* now create a new char string showing hyphenation positions */
/* count the hyphens and allocate space for the new hypehanted string */
nHyphCount = 0;
for (i = 0; i < n; i++)
if (hyphens[i]&1)
nHyphCount++;
hyphword = (char *) malloc(k+1+nHyphCount);
j = 0;
for (i = 0; i < n; i++) {
hyphword[j++] = word->str[i];
if (hyphens[i]&1)
{
hyphword[j++] = '-';
}
}
hyphword[j] = '\0';
pop_n_elems(args);
push_text(hyphword);
/*printf("done\n"); */
free(hyphens);
free(lcword);
free(hyphword);
/* } */
}
}
}
#undef internal_init_Hyphenate_defined
#define internal_init_Hyphenate_defined
#undef Hyphenate_event_handler_defined
#define Hyphenate_event_handler_defined
static void init_Hyphenate_struct(void)
#line 120 "hyphenate.cmod"
{
HYPHENATE_OBJECT_DATA * dta =
(HYPHENATE_OBJECT_DATA*)malloc(sizeof(HYPHENATE_OBJECT_DATA));
if (!dta)
Pike_error("init_sample: Out of memory!\n");
THIS->object_data = dta;
}
#undef internal_exit_Hyphenate_defined
#define internal_exit_Hyphenate_defined
#undef Hyphenate_event_handler_defined
#define Hyphenate_event_handler_defined
static void exit_Hyphenate_struct(void)
#line 130 "hyphenate.cmod"
{
if(THIS->object_data)
{
free(THIS->object_data);
}
}
#ifdef Hyphenate_event_handler_defined
static void Hyphenate_event_handler(int ev) {
switch(ev) {
#ifdef internal_init_Hyphenate_defined
case PROG_EVENT_INIT: init_Hyphenate_struct(); break;
#endif /* internal_init_Hyphenate_defined */
#ifdef internal_exit_Hyphenate_defined
case PROG_EVENT_EXIT: exit_Hyphenate_struct(); break;
#endif /* internal_exit_Hyphenate_defined */
default: break;
}
}
#endif /* Hyphenate_event_handler_defined */
/*! @endclass
*/
/*! @endmodule
*/
/*! @endmodule
*/
/*! @endmodule
*/
PIKE_MODULE_INIT {
#ifdef class_Hyphenate_defined
#ifdef PROG_HYPHENATE_ID
#line 21 "hyphenate.cmod"
START_NEW_PROGRAM_ID(HYPHENATE);
#else
#line 21 "hyphenate.cmod"
start_new_program();
#endif /* PROG_HYPHENATE_ID */
#ifndef tObjImpl_HYPHENATE
#undef tObjImpl_HYPHENATE
#define tObjImpl_HYPHENATE tObj
#endif /* tObjImpl_HYPHENATE */
#ifdef THIS_HYPHENATE
Hyphenate_storage_offset = ADD_STORAGE(struct Hyphenate_struct);
#endif /* THIS_HYPHENATE */
#ifdef Hyphenate_event_handler_defined
pike_set_prog_event_callback(Hyphenate_event_handler);
#endif /* Hyphenate_event_handler_defined */
#ifdef f_Hyphenate_create_defined
f_Hyphenate_create_fun_num =
#line 36 "hyphenate.cmod"
ADD_FUNCTION2("create", f_Hyphenate_create, tFunc(tString,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);
#endif /* f_Hyphenate_create_defined */
#ifdef f_Hyphenate_hyphenate_defined
f_Hyphenate_hyphenate_fun_num =
#line 53 "hyphenate.cmod"
ADD_FUNCTION2("hyphenate", f_Hyphenate_hyphenate, tFunc(tString,tString), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);
#endif /* f_Hyphenate_hyphenate_defined */
#line 21 "hyphenate.cmod"
Hyphenate_program=end_program();
#line 21 "hyphenate.cmod"
Hyphenate_program_fun_num=add_program_constant("Hyphenate",Hyphenate_program,0);
#endif /* class_Hyphenate_defined */
}
PIKE_MODULE_EXIT {
#ifdef class_Hyphenate_defined
if(Hyphenate_program) {
#line 21 "hyphenate.cmod"
free_program(Hyphenate_program);
Hyphenate_program=0;
}
#endif /* class_Hyphenate_defined */
}
|
|
|