summaryrefslogtreecommitdiff
path: root/lingucomponent/source/thesaurus/mythes/mythes.hxx
blob: 3eebeda36393f60ea4367b3fea99c05ce6b3ad4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _MYTHES_HXX_
#define _MYTHES_HXX_

// some maximum sizes for buffers
#define MAX_WD_LEN 200
#define MAX_LN_LEN 16384


// a meaning with definition, count of synonyms and synonym list
struct mentry {
  char*  defn;
  int  count;
  char** psyns;
};


class MyThes
{

       int  nw;                  /* number of entries in thesaurus */
       char**  list;               /* stores word list */
       unsigned int* offst;              /* stores offset list */
       char *  encoding;           /* stores text encoding; */

        FILE  *pdfile;

    // disallow copy-constructor and assignment-operator for now
    MyThes();
    MyThes(const MyThes &);
    MyThes & operator = (const MyThes &);

public:
    MyThes(const char* idxpath, const char* datpath);
    ~MyThes();

        // lookup text in index and return number of meanings
    // each meaning entry has a defintion, synonym count and pointer
        // when complete return the *original* meaning entry and count via
        // CleanUpAfterLookup to properly handle memory deallocation

        int Lookup(const char * pText, int len, mentry** pme);

        void CleanUpAfterLookup(mentry** pme, int nmean);

        char* get_th_encoding();

private:
        // Open index and dat files and load list array
        int thInitialize (const char* indxpath, const char* datpath);

        // internal close and cleanup dat and idx files
        int thCleanup ();

        // read a text line (\n terminated) stripping off line terminator
        int readLine(FILE * pf, char * buf, int nc);

        // binary search on null terminated character strings
        int binsearch(char * wrd, char* list[], int nlst);

};

#endif