sync master with lastest vba changes
[ooovba.git] / lingucomponent / source / thesaurus / mythes / example.cxx
blob39791140bcd17fc14098171867d2ccdda5833fbb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: example.cxx,v $
10 * $Revision: 1.4 $
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"
34 #include <cstring>
35 #include <cstdlib>
36 #include <cstdio>
38 #include "mythes.hxx"
40 extern char * mystrdup(const char * s);
42 using namespace std;
44 int
45 main(int argc, char** argv)
48 char * af;
49 char * df;
50 char * wtc;
51 FILE* wtclst;
53 /* first parse the command line options */
54 /* arg1 - index file, arg2 thesaurus data file, arg3 - file of words to check */
56 if (argv[1]) {
57 af = mystrdup(argv[1]);
58 } else {
59 fprintf(stderr,"correct syntax is:\n");
60 fprintf(stderr,"example index_file thesaurus_file file_of_words_to_check\n");
61 exit(1);
63 if (argv[2]) {
64 df = mystrdup(argv[2]);
65 } else {
66 fprintf(stderr,"correct syntax is:\n");
67 fprintf(stderr,"example index_file thesaurus_file file_of_words_to_check\n");
68 exit(1);
70 if (argv[3]) {
71 wtc = mystrdup(argv[3]);
72 } else {
73 fprintf(stderr,"correct syntax is:\n");
74 fprintf(stderr,"example index_file thesaurus_file file_of_words_to_check\n");
75 exit(1);
79 /* open the words to check list */
80 wtclst = fopen(wtc,"r");
81 if (!wtclst) {
82 fprintf(stderr,"Error - could not open file of words to check\n");
83 exit(1);
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);
93 int k;
94 char buf[101];
95 mentry * pmean;
97 while(fgets(buf,100,wtclst)) {
98 k = strlen(buf);
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
104 mentry* pm = pmean;
105 if (count) {
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");
113 pm++;
115 fprintf(stdout,"\n\n");
116 // now clean up all allocated memory
117 pMT->CleanUpAfterLookup(&pmean,count);
118 } else {
119 fprintf(stdout,"\"%s\" is not in thesaurus!\n",buf);
123 delete pMT;
124 fclose(wtclst);
125 free(wtc);
126 free(df);
127 free(af);
129 return 0;