~ubuntu-branches/ubuntu/quantal/ruby-ferret/quantal

« back to all changes in this revision

Viewing changes to ext/libstemmer.c

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2012-06-14 23:04:48 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120614230448-wd5se4ia1yz7dvms
Tags: 0.11.8.4+debian-1
* New upstream version from a new source
  + the new code fixes format security issues (Closes: #672069)
  + change homepage to https://github.com/jkraemer/ferret/
* Build for all Ruby versions (Closes: #655636)
  + change depends accordingly
  + do not set shebang of bin/ferret to ruby1.8
* Repack source to remove convenience copy of bzlib
  + build-dep on libbz2-dev
  + dversionmangle in debian/watch
  + add debian/README.source explaining how to clean the source
* debian/patches:
  + disable_load_path_manipulation.patch: do not override $LOAD_PATH
  + disable_test_causing_segfault.patch: temporarily disable a test known to
    cause segfaults
  + fix_compatibility_with_minitest.patch: fix a failing test with Ruby1.9
  + use_system_bzlib.patch: adapt the source to use system libbz2
  + fix_typos_in_source_code.patch: correct some spelling errors in the
    source code
  + block_variables_have_local_scopes.patch: fix syntax in
    bin/ferret-browser
* Override dh_auto_clean to remove test/temp when cleaning
* Bump Standards-Version to 3.9.3 (no changes needed)
* Set priority of transitional packages to extra
* Add myself to Uploaders:
* Update copyright to DEP-5 copyright-format/1.0
* Add TUTORIAL and debian/README.source to documents
* Override lintian warnings about duplicate descriptions of transitional
  packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include "libstemmer.h"
5
 
#include "api.h"
6
 
#include "modules.h"
7
 
 
8
 
struct sb_stemmer {
9
 
    struct SN_env * (*create)(void);
10
 
    void (*close)(struct SN_env *);
11
 
    int (*stem)(struct SN_env *);
12
 
 
13
 
    struct SN_env * env;
14
 
};
15
 
 
16
 
extern const char **
17
 
sb_stemmer_list(void)
18
 
{
19
 
    return algorithm_names;
20
 
}
21
 
 
22
 
static stemmer_encoding sb_getenc(const char * charenc)
23
 
{
24
 
    struct stemmer_encoding * encoding;
25
 
    if (charenc == NULL) return ENC_UTF_8;
26
 
    for (encoding = encodings; encoding->name != 0; encoding++) {
27
 
        if (strcmp(encoding->name, charenc) == 0) break;
28
 
    }
29
 
    if (encoding->name == NULL) return ENC_UNKNOWN;
30
 
    return encoding->enc;
31
 
}
32
 
 
33
 
extern struct sb_stemmer *
34
 
sb_stemmer_new(const char * algorithm, const char * charenc)
35
 
{
36
 
    stemmer_encoding enc;
37
 
    struct stemmer_modules * module;
38
 
    struct sb_stemmer * stemmer =
39
 
            (struct sb_stemmer *) malloc(sizeof(struct sb_stemmer));
40
 
    if (stemmer == NULL) return NULL;
41
 
    enc = sb_getenc(charenc);
42
 
    if (enc == ENC_UNKNOWN) return NULL;
43
 
 
44
 
    for (module = modules; module->name != 0; module++) {
45
 
        if (strcmp(module->name, algorithm) == 0 && module->enc == enc) break;
46
 
    }
47
 
    if (module->name == NULL) return NULL;
48
 
    
49
 
    stemmer->create = module->create;
50
 
    stemmer->close = module->close;
51
 
    stemmer->stem = module->stem;
52
 
 
53
 
    stemmer->env = stemmer->create();
54
 
    if (stemmer->env == NULL)
55
 
    {
56
 
        sb_stemmer_delete(stemmer);
57
 
        return NULL;
58
 
    }
59
 
 
60
 
    return stemmer;
61
 
}
62
 
 
63
 
void
64
 
sb_stemmer_delete(struct sb_stemmer * stemmer)
65
 
{
66
 
    if (stemmer == 0) return;
67
 
    if (stemmer->close == 0) return;
68
 
    stemmer->close(stemmer->env);
69
 
    stemmer->close = 0;
70
 
    free(stemmer);
71
 
}
72
 
 
73
 
const sb_symbol *
74
 
sb_stemmer_stem(struct sb_stemmer * stemmer, const sb_symbol * word, int size)
75
 
{
76
 
    int ret;
77
 
    if (SN_set_current(stemmer->env, size, (const symbol *)(word)))
78
 
    {
79
 
        stemmer->env->l = 0;
80
 
        return NULL;
81
 
    }
82
 
    ret = stemmer->stem(stemmer->env);
83
 
    if (ret < 0) return NULL;
84
 
    stemmer->env->p[stemmer->env->l] = 0;
85
 
    return (const sb_symbol *)(stemmer->env->p);
86
 
}
87
 
 
88
 
int
89
 
sb_stemmer_length(struct sb_stemmer * stemmer)
90
 
{
91
 
    return stemmer->env->l;
92
 
}