ntdll: Fix race in NtRead/WriteFile.
[wine/testsucceed.git] / dlls / infosoft / wordbreaker.c
blob514f868d95e6e450fdc54cd7eff45443cf456b05
1 /*
2 * Word splitter Implementation
4 * Copyright 2006 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "indexsrv.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(infosoft);
37 typedef struct tag_wordbreaker_impl
39 const IWordBreakerVtbl *lpVtbl;
40 LONG ref;
41 } wordbreaker_impl;
43 static HRESULT WINAPI wb_QueryInterface( IWordBreaker *iface,
44 REFIID riid, LPVOID *ppvObj)
46 wordbreaker_impl *This = (wordbreaker_impl *)iface;
48 TRACE("(%p)->(%s)\n",This,debugstr_guid(riid));
50 *ppvObj = NULL;
52 if (IsEqualIID(riid, &IID_IUnknown) ||
53 IsEqualIID(riid, &IID_IWordBreaker))
55 *ppvObj = This;
56 return S_OK;
59 TRACE("-- E_NOINTERFACE\n");
60 return E_NOINTERFACE;
63 static ULONG WINAPI wb_AddRef( IWordBreaker *iface )
65 wordbreaker_impl *This = (wordbreaker_impl *)iface;
66 return InterlockedIncrement(&This->ref);
69 static ULONG WINAPI wb_Release(IWordBreaker *iface)
71 wordbreaker_impl *This = (wordbreaker_impl *)iface;
72 LONG refcount;
74 refcount = InterlockedDecrement(&This->ref);
75 if (!refcount)
76 HeapFree(GetProcessHeap(), 0, This);
78 return refcount;
81 static HRESULT WINAPI wb_Init( IWordBreaker *iface,
82 BOOL fQuery, ULONG ulMaxTokenSize, BOOL *pfLicense )
84 TRACE("%d %u\n", fQuery, ulMaxTokenSize);
85 *pfLicense = FALSE;
86 return S_OK;
89 static HRESULT call_sink( IWordSink *pWordSink, TEXT_SOURCE *ts, UINT len )
91 HRESULT r;
93 if (!len)
94 return S_OK;
96 TRACE("%d %s\n", len, debugstr_w(&ts->awcBuffer[ts->iCur]));
98 r = IWordSink_PutWord( pWordSink, len, &ts->awcBuffer[ts->iCur], len, ts->iCur );
99 ts->iCur += len;
101 return r;
104 static HRESULT WINAPI wb_BreakText( IWordBreaker *iface,
105 TEXT_SOURCE *ts, IWordSink *pWordSink, IPhraseSink *pPhraseSink)
107 UINT len, state = 0;
108 WCHAR ch;
110 TRACE("%p %p %p\n", ts, pWordSink, pPhraseSink);
112 if (pPhraseSink)
113 FIXME("IPhraseSink won't be called\n");
117 len = 0;
118 while ((ts->iCur + len) < ts->iEnd)
120 ch = ts->awcBuffer[ts->iCur + len];
122 switch (state)
124 case 0: /* skip spaces and punctuation */
126 if (!ch || ispunctW(ch) || isspaceW(ch))
127 ts->iCur ++;
128 else
129 state = 1;
130 break;
132 case 1: /* find the end of the word */
134 if (ch && !ispunctW(ch) && !isspaceW(ch))
135 len++;
136 else
138 call_sink( pWordSink, ts, len );
139 len = 0;
140 state = 0;
142 break;
146 call_sink( pWordSink, ts, len );
148 } while (S_OK == ts->pfnFillTextBuffer( ts ));
150 return S_OK;
153 static HRESULT WINAPI wb_ComposePhrase( IWordBreaker *iface,
154 const WCHAR *pwcNoun, ULONG cwcNoun,
155 const WCHAR *pwcModifier, ULONG cwcModifier,
156 ULONG ulAttachmentType, WCHAR *pwcPhrase, ULONG *pcwcPhrase)
158 FIXME("%p %u %p %u %u %p %p\n", pwcNoun, cwcNoun,
159 pwcModifier, cwcModifier, ulAttachmentType, pwcPhrase, pcwcPhrase);
160 return S_OK;
163 static HRESULT WINAPI wb_GetLicenseToUse( IWordBreaker *iface, const WCHAR **ppwcsLicense )
165 FIXME("%p\n", ppwcsLicense);
166 *ppwcsLicense = NULL;
167 return S_OK;
170 static const IWordBreakerVtbl wordbreaker_vtbl =
172 wb_QueryInterface,
173 wb_AddRef,
174 wb_Release,
175 wb_Init,
176 wb_BreakText,
177 wb_ComposePhrase,
178 wb_GetLicenseToUse,
181 HRESULT WINAPI wb_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppvObject)
183 wordbreaker_impl *This;
184 IWordBreaker *wb;
186 TRACE("%p %s %p\n", pUnkOuter, debugstr_guid(riid), ppvObject);
188 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
189 if (!This)
190 return E_OUTOFMEMORY;
192 This->ref = 1;
193 This->lpVtbl = &wordbreaker_vtbl;
195 wb = (IWordBreaker*) This;
197 return IWordBreaker_QueryInterface(wb, riid, ppvObject);