Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

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.2/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
#define DEFAULT_CMOD_STORAGE

#include "hyphenate_config.h"
#include "util.h"
#include "hyphen-2.8.6/hyphen.h"


/*! @class Hyphenate
 */


#undef class_Hyphenate_defined
#define class_Hyphenate_defined
DEFAULT_CMOD_STORAGE struct program *Hyphenate_program=NULL;
static int Hyphenate_program_fun_num=-1;

#undef var_dict_Hyphenate_defined
#define var_dict_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_dict_Hyphenate_defined
#line 24 "hyphenate.cmod"
HyphenDict * dict;
#endif /* var_dict_Hyphenate_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct Hyphenate_struct *Hyphenate_gdb_dummy_ptr;
#endif
/*! @decl void create(string appname)
 *!   Creates a new Hyphenate object
 *!
 */
#define f_Hyphenate_create_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Hyphenate_create_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Hyphenate_create(INT32 args) {
#line 30 "hyphenate.cmod"
struct pike_string * dictionary;
#line 30 "hyphenate.cmod"
if(args != 1) wrong_number_of_args_error("create",args,1);
#line 30 "hyphenate.cmod"
if(Pike_sp[0-1].type != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 30 "hyphenate.cmod"
debug_malloc_pass(dictionary=Pike_sp[0-1].u.string);
{
  HyphenDict * hd;
  char * dn;
printf("create()\n");
  dn = strdup(dictionary->str);
  hd = hnj_hyphen_load(dn);

  if(!hd)
  {
    Pike_error("unable to load hyphenation dictionary.\n");
  }

  THIS->dict = hd;

  pop_n_elems(args);
}

}
#define f_Hyphenate_low_hyphenate_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Hyphenate_low_hyphenate_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Hyphenate_low_hyphenate(INT32 args) {
#line 48 "hyphenate.cmod"
struct pike_string * word;
#line 48 "hyphenate.cmod"
if(args != 1) wrong_number_of_args_error("low_hyphenate",args,1);
#line 48 "hyphenate.cmod"
if(Pike_sp[0-1].type != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_hyphenate",1,"string");
#line 48 "hyphenate.cmod"
debug_malloc_pass(word=Pike_sp[0-1].u.string);
{
  int k, n, i, j, c;

  char** rep;
  int* pos;
  int* cut;

  int  nHyphCount;
  char *hyphens;
  char *hyphword;

  rep = NULL; /* Will be allocated by the algorithm */
  pos = NULL; /* Idem */
  cut = NULL; /* Idem */

  k = word->len * (1 << word->size_shift);

  /* set aside some buffers to hold lower cased */
  /* and hyphen information */
  hyphens = (char *)malloc(k+5);

  if (k > 0) {
    if(hnj_hyphen_hyphenate2(THIS->dict, word->str, word->len, hyphens,
	NULL, &rep, &pos, &cut))
    {
        free(hyphens);
	pop_n_elems(args);
        Pike_error("hyphenation error\n");
    }

    /* now backfill hyphens[] for any removed periods */
    for (c = word->len; 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 < word->len; i++)
    {     
      if(hyphens[i]&1)
        nHyphCount++;
    }    

    hyphword = (char *) malloc(k+1+nHyphCount);
    j = 0;
    for (i = 0; i < word->len; i++) 
    {
      hyphword[j++] = word->str[i];
      if (hyphens[i]&1)
      {
        hyphword[j++] = '-';
      }
    } 

    hyphword[j] = '\0';
	
    pop_n_elems(args); 
    push_text(hyphword);
    free(hyphens);
    free(hyphword);
/*	    } */
  }
}

}
/*! @decl string hyphenate(string word)
 *!
 *! Break a word into its possible hyphenations.
 */
#define f_Hyphenate_hyphenate_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Hyphenate_hyphenate_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Hyphenate_hyphenate(INT32 args) {
#line 117 "hyphenate.cmod"
struct pike_string * word;
#line 117 "hyphenate.cmod"
if(args != 1) wrong_number_of_args_error("hyphenate",args,1);
#line 117 "hyphenate.cmod"
if(Pike_sp[0-1].type != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("hyphenate",1,"string");
#line 117 "hyphenate.cmod"
debug_malloc_pass(word=Pike_sp[0-1].u.string);
{
  f_lower_case(1);
  f_string_to_utf8(1);
  f_Hyphenate_low_hyphenate(1);
  if(Pike_sp[-1].type == T_STRING)
    f_utf8_to_string(1);
}

}

#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 127 "hyphenate.cmod"
{
    THIS->dict = NULL;
}


#undef Hyphenate_gc_live_obj
#define Hyphenate_gc_live_obj

#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 132 "hyphenate.cmod"
{
  HyphenDict * hd;
printf("end\n");
  if(THIS && THIS->dict != NULL)
  {
printf("freeing\n");    
    hd = THIS->dict;
printf("dict: %p\n", hd);
    hnj_hyphen_free(hd);
  }
}


#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);

#ifndef Hyphenate_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* Hyphenate_gc_live_obj */

#endif /* Hyphenate_event_handler_defined */

#ifdef f_Hyphenate_create_defined
  f_Hyphenate_create_fun_num =
#line 30 "hyphenate.cmod"
    ADD_FUNCTION2("create", f_Hyphenate_create, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Hyphenate_create_defined */

#ifdef f_Hyphenate_low_hyphenate_defined
  f_Hyphenate_low_hyphenate_fun_num =
#line 48 "hyphenate.cmod"
    ADD_FUNCTION2("low_hyphenate", f_Hyphenate_low_hyphenate, tFunc(tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Hyphenate_low_hyphenate_defined */

#ifdef f_Hyphenate_hyphenate_defined
  f_Hyphenate_hyphenate_fun_num =
#line 117 "hyphenate.cmod"
    ADD_FUNCTION2("hyphenate", f_Hyphenate_hyphenate, tFunc(tStr,tStr), 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 */
}


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University