1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: example.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_lingucomponent.hxx"
40 extern char * mystrdup(const char * s
);
45 main(int argc
, char** argv
)
53 /* first parse the command line options */
54 /* arg1 - index file, arg2 thesaurus data file, arg3 - file of words to check */
57 af
= mystrdup(argv
[1]);
59 fprintf(stderr
,"correct syntax is:\n");
60 fprintf(stderr
,"example index_file thesaurus_file file_of_words_to_check\n");
64 df
= mystrdup(argv
[2]);
66 fprintf(stderr
,"correct syntax is:\n");
67 fprintf(stderr
,"example index_file thesaurus_file file_of_words_to_check\n");
71 wtc
= mystrdup(argv
[3]);
73 fprintf(stderr
,"correct syntax is:\n");
74 fprintf(stderr
,"example index_file thesaurus_file file_of_words_to_check\n");
79 /* open the words to check list */
80 wtclst
= fopen(wtc
,"r");
82 fprintf(stderr
,"Error - could not open file of words to check\n");
86 // open a new thesaurus object
87 MyThes
* pMT
= new MyThes(af
,df
);
89 // get the encoding used for the thesaurus data
90 char * encoding
= pMT
->get_th_encoding();
91 fprintf(stdout
,"Thesaurus uses encoding %s\n\n",encoding
);
97 while(fgets(buf
,100,wtclst
)) {
99 *(buf
+ k
- 1) = '\0';
100 int len
= strlen(buf
);
101 int count
= pMT
->Lookup(buf
,len
,&pmean
);
102 // don't change value of pmean
103 // or count since needed for CleanUpAfterLookup routine
106 fprintf(stdout
,"%s has %d meanings\n",buf
,count
);
107 for (int i
=0; i
< count
; i
++) {
108 fprintf(stdout
," meaning %d: %s\n",i
,pm
->defn
);
109 for (int j
=0; j
< pm
->count
; j
++) {
110 fprintf(stdout
," %s\n",pm
->psyns
[j
]);
112 fprintf(stdout
,"\n");
115 fprintf(stdout
,"\n\n");
116 // now clean up all allocated memory
117 pMT
->CleanUpAfterLookup(&pmean
,count
);
119 fprintf(stdout
,"\"%s\" is not in thesaurus!\n",buf
);