1 /*
2 * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /**
17 * @file picokpr.c
18 *
19 * knowledge handling for text preprocessing
20 *
21 * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
22 * All rights reserved.
23 *
24 * History:
25 * - 2009-04-20 -- initial version
26 *
27 */
28 #include "picoos.h"
29 #include "picodbg.h"
30 #include "picodata.h"
31 #include "picoknow.h"
32 #include "picokpr.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 #if 0
38 }
39 #endif
40
41
42 /* ************************************************************/
43 /* preproc */
44 /* ************************************************************/
45
46 /*
47 overview:
48 */
49
50
51 /* ************************************************************/
52 /* preproc data defines */
53 /* ************************************************************/
54
55 #define KPR_STR_SIZE 1
56 #define KPR_LEXCAT_SIZE 2
57 #define KPR_ATTRVAL_SIZE 4
58 #define KPR_OUTITEM_SIZE 7
59 #define KPR_TOK_SIZE 16
60 #define KPR_PROD_SIZE 12
61 #define KPR_CTX_SIZE 12
62
63 #define KPR_NETNAME_OFFSET 0
64 #define KPR_STRARRLEN_OFFSET 4
65 #define KPR_LEXCATARRLEN_OFFSET 8
66 #define KPR_ATTRVALARRLEN_OFFSET 12
67 #define KPR_OUTITEMARRLEN_OFFSET 16
68 #define KPR_TOKARRLEN_OFFSET 20
69 #define KPR_PRODARRLEN_OFFSET 24
70 #define KPR_CTXARRLEN_OFFSET 28
71
72 #define KPR_ARRAY_START 32
73
74 #define KPR_MAX_INT32 2147483647
75
76 #define KPR_STR_OFS 0
77
78 #define KPR_LEXCAT_OFS 0
79
80 #define KPR_ATTRVAL_INT_OFS 0
81 #define KPR_ATTRVAL_STROFS_OFS 0
82 #define KPR_ATTRVAL_PRODOFS_OFS 0
83 #define KPR_ATTRVAL_OUTITMOFS_OFS 0
84 #define KPR_ATTRVAL_LEXCATOFS_OFS 0
85
86 #define KPR_OUTITEM_NEXTOFS_OFS 0
87 #define KPR_OUTITEM_TYPE_OFS 2
88 #define KPR_OUTITEM_STROFS_OFS 3
89 #define KPR_OUTITEM_VAL_OFS 3
90 #define KPR_OUTITEM_ARGOFS_OFS 3
91
92 #define KPR_TOK_SETWP_OFS 0
93 #define KPR_TOK_SETNP_OFS 4
94 #define KPR_TOK_NEXTOFS_OFS 8
95 #define KPR_TOK_ALTLOFS_OFS 10
96 #define KPR_TOK_ALTROFS_OFS 12
97 #define KPR_TOK_ATTRIBOFS_OFS 14
98
99 #define KPR_PROD_PRODPREFCOST_OFS 0
100 #define KPR_PROD_PRODNAMEOFS_OFS 4
101 #define KPR_PROD_ATOKOFS_OFS 8
102 #define KPR_PROD_ETOKOFS_OFS 10
103
104 #define KPR_CTX_CTXNAMEOFS_OFS 0
105 #define KPR_CTX_NETNAMEOFS_OFS 4
106 #define KPR_CTX_PRODNAMEOFS_OFS 8
107
108 /* ************************************************************/
109 /* preproc type and loading */
110 /* ************************************************************/
111
112 /* variable array element types */
113 typedef picoos_uint8 picokpr_Str[KPR_STR_SIZE];
114 typedef picoos_uint16 picokpr_LexCat2;
115 typedef picoos_uint8 picokpr_AttrVal[KPR_ATTRVAL_SIZE];
116 typedef picoos_uint8 picokpr_OutItem[KPR_OUTITEM_SIZE];
117 typedef picoos_uint8 picokpr_Tok[KPR_TOK_SIZE];
118 typedef picoos_uint8 picokpr_Prod[KPR_PROD_SIZE];
119 typedef picoos_uint8 picokpr_Ctx[KPR_CTX_SIZE];
120
121 /* variable array types */
122 typedef picokpr_Str * picokpr_VarStrArr;
123 typedef picokpr_LexCat2 * picokpr_VarLexCatArr;
124 typedef picokpr_AttrVal * picokpr_VarAttrValArr;
125 typedef picokpr_OutItem * picokpr_VarOutItemArr;
126 typedef picokpr_Tok * picokpr_VarTokArr;
127 typedef picokpr_Prod * picokpr_VarProdArr;
128 typedef picokpr_Ctx * picokpr_VarCtxArr;
129
130 /* ************************************************************/
131 /* preproc type and loading */
132 /* ************************************************************/
133
134 /** object : PreprocKnowledgeBase
135 * shortcut : kpr
136 * derived from : picoknow_KnowledgeBase
137 */
138
139 typedef struct kpr_subobj * kpr_SubObj;
140
141 typedef struct kpr_subobj
142 {
143 picoos_uchar * rNetName;
144
145 picoos_int32 rStrArrLen;
146 picoos_int32 rLexCatArrLen;
147 picoos_int32 rAttrValArrLen;
148 picoos_int32 rOutItemArrLen;
149 picoos_int32 rTokArrLen;
150 picoos_int32 rProdArrLen;
151 picoos_int32 rCtxArrLen;
152
153 picoos_uint8 * rStrArr;
154 picokpr_LexCat2 * rLexCatArr;
155 picokpr_AttrVal * rAttrValArr;
156 picokpr_OutItem * rOutItemArr;
157 picokpr_Tok * rTokArr;
158 picokpr_Prod * rProdArr;
159 picokpr_Ctx * rCtxArr;
160 } kpr_subobj_t;
161
162
kpr_getUInt32(picoos_uint8 * p)163 static picoos_uint32 kpr_getUInt32(picoos_uint8 * p)
164 {
165 return p[0] + 256*p[1] + 256*256*p[2] + 256*256*256*p[3];
166 }
167
168
kprInitialize(register picoknow_KnowledgeBase this,picoos_Common common)169 static pico_status_t kprInitialize(register picoknow_KnowledgeBase this,
170 picoos_Common common)
171 {
172 picoos_uint32 offset = 0;
173 kpr_subobj_t * kpr;
174
175 PICODBG_DEBUG(("start"));
176
177 if (NULL == this || NULL == this->subObj) {
178 return picoos_emRaiseException(common->em, PICO_EXC_KB_MISSING,
179 NULL, NULL);
180 }
181 kpr = (kpr_subobj_t *) this->subObj;
182
183 kpr->rStrArrLen = kpr_getUInt32(&(this->base[KPR_STRARRLEN_OFFSET]));
184 kpr->rLexCatArrLen = kpr_getUInt32(&(this->base[KPR_LEXCATARRLEN_OFFSET]));
185 kpr->rAttrValArrLen = kpr_getUInt32(&(this->base[KPR_ATTRVALARRLEN_OFFSET]));
186 kpr->rOutItemArrLen = kpr_getUInt32(&(this->base[KPR_OUTITEMARRLEN_OFFSET]));
187 kpr->rTokArrLen = kpr_getUInt32(&(this->base[KPR_TOKARRLEN_OFFSET]));
188 kpr->rProdArrLen = kpr_getUInt32(&(this->base[KPR_PRODARRLEN_OFFSET]));
189 kpr->rCtxArrLen = kpr_getUInt32(&(this->base[KPR_CTXARRLEN_OFFSET]));
190
191 offset = KPR_ARRAY_START;
192 kpr->rStrArr = &(this->base[offset]);
193 PICODBG_DEBUG(("rStrArr : cs: %i, ss: %i, offset: %i", sizeof(picokpr_Str), KPR_STR_SIZE, offset));
194 offset = offset + kpr->rStrArrLen * 1;
195
196 kpr->rLexCatArr = (picokpr_LexCat2 *)&(this->base[offset]);
197 PICODBG_DEBUG(("rLexCatArr : cs: %i, ss: %i, offset: %i", KPR_LEXCAT_SIZE, sizeof(picokpr_LexCat2), offset));
198 offset = offset + kpr->rLexCatArrLen * KPR_LEXCAT_SIZE;
199
200 kpr->rAttrValArr = (picokpr_AttrVal *)&(this->base[offset]);
201 PICODBG_DEBUG(("rAttrValArr : cs: %i, ss: %i, offset: %i", KPR_ATTRVAL_SIZE, sizeof(picokpr_AttrVal), offset));
202 offset = offset + kpr->rAttrValArrLen * KPR_ATTRVAL_SIZE;
203
204 kpr->rOutItemArr = (picokpr_OutItem *)&(this->base[offset]);
205 PICODBG_DEBUG(("rOutItemArr : cs: %i, ss: %i, offset: %i", KPR_OUTITEM_SIZE, sizeof(picokpr_OutItem), offset));
206 offset = offset + kpr->rOutItemArrLen * KPR_OUTITEM_SIZE;
207
208 kpr->rTokArr = (picokpr_Tok *)&(this->base[offset]);
209 PICODBG_DEBUG(("rTokArr : cs: %i, ss: %i, offset: %i", KPR_TOK_SIZE, sizeof(picokpr_Tok), offset));
210 offset = offset + kpr->rTokArrLen * KPR_TOK_SIZE;
211
212 kpr->rProdArr = (picokpr_Prod *)&(this->base[offset]);
213 PICODBG_DEBUG(("rProdArr : cs: %i, ss: %i, offset: %i", KPR_PROD_SIZE, sizeof(picokpr_Prod), offset));
214 offset = offset + kpr->rProdArrLen * KPR_PROD_SIZE;
215
216 kpr->rCtxArr = (picokpr_Ctx *)&(this->base[offset]);
217 PICODBG_DEBUG(("rCtxArr : cs: %i, ss: %i, offset: %i", KPR_CTX_SIZE, sizeof(picokpr_Ctx), offset));
218 offset = offset + kpr->rCtxArrLen * KPR_CTX_SIZE;
219
220 kpr->rNetName = &(kpr->rStrArr[kpr_getUInt32(&(this->base[KPR_NETNAME_OFFSET]))]);
221
222 return PICO_OK;
223 }
224
225
kprSubObjDeallocate(register picoknow_KnowledgeBase this,picoos_MemoryManager mm)226 static pico_status_t kprSubObjDeallocate(register picoknow_KnowledgeBase this,
227 picoos_MemoryManager mm)
228 {
229 if (NULL != this) {
230 picoos_deallocate(mm, (void *) &this->subObj);
231 }
232 return PICO_OK;
233 }
234
235
236 /* we don't offer a specialized constructor for a PreprocKnowledgeBase but
237 * instead a "specializer" of an allready existing generic
238 * picoknow_KnowledgeBase */
239
picokpr_specializePreprocKnowledgeBase(picoknow_KnowledgeBase this,picoos_Common common)240 pico_status_t picokpr_specializePreprocKnowledgeBase(picoknow_KnowledgeBase this,
241 picoos_Common common)
242 {
243 if (NULL == this) {
244 return picoos_emRaiseException(common->em, PICO_EXC_KB_MISSING,
245 NULL, NULL);
246 }
247 this->subDeallocate = kprSubObjDeallocate;
248 this->subObj = picoos_allocate(common->mm, sizeof(kpr_subobj_t));
249 if (NULL == this->subObj) {
250 return picoos_emRaiseException(common->em, PICO_EXC_OUT_OF_MEM,
251 NULL, NULL);
252 }
253 return kprInitialize(this, common);
254 }
255
256 /* ************************************************************/
257 /* preproc getPreproc */
258 /* ************************************************************/
259
picokpr_getPreproc(picoknow_KnowledgeBase this)260 picokpr_Preproc picokpr_getPreproc(picoknow_KnowledgeBase this)
261 {
262 if (NULL == this) {
263 return NULL;
264 } else {
265 return (picokpr_Preproc) this->subObj;
266 }
267 }
268
269
270 /* *****************************************************************************/
271 /* knowledge base access routines for strings in StrArr */
272 /* *****************************************************************************/
273
picokpr_getVarStrPtr(picokpr_Preproc preproc,picokpr_StrArrOffset ofs)274 extern picokpr_VarStrPtr picokpr_getVarStrPtr(picokpr_Preproc preproc, picokpr_StrArrOffset ofs)
275 {
276 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rStrArr[ofs]);
277
278 return p;
279 }
280
281 /* *****************************************************************************/
282
picokpr_isEqual(picokpr_Preproc preproc,picoos_uchar str[],picoos_int32 len__9,picokpr_StrArrOffset str2)283 extern picoos_bool picokpr_isEqual (picokpr_Preproc preproc, picoos_uchar str[], picoos_int32 len__9, picokpr_StrArrOffset str2)
284 {
285 picokpr_VarStrPtr lstrp;
286 len__9 = len__9; /*PP 13.10.08 : fix warning "var not used in this function"*/
287 lstrp = (picokpr_VarStrPtr)&((kpr_SubObj)preproc)->rStrArr[str2];
288 return picoos_strcmp((picoos_char*)lstrp,(picoos_char*)str) == 0;
289 }
290
291
292
picokpr_isEqualHead(picokpr_Preproc preproc,picoos_uchar str[],picoos_int32 len__10,picokpr_StrArrOffset head)293 extern picoos_bool picokpr_isEqualHead (picokpr_Preproc preproc, picoos_uchar str[], picoos_int32 len__10, picokpr_StrArrOffset head)
294 {
295 picokpr_VarStrPtr lstrp;
296 len__10 = len__10; /*PP 13.10.08 : fix warning "var not used in this function"*/
297 lstrp = (picokpr_VarStrPtr)&((kpr_SubObj)preproc)->rStrArr[head];
298 return (picoos_strstr((picoos_char*)str, (picoos_char*)lstrp) == (picoos_char*)str);
299 }
300
301
302
picokpr_isEqualMid(picokpr_Preproc preproc,picoos_uchar str[],picoos_int32 len__11,picokpr_StrArrOffset mid)303 extern picoos_bool picokpr_isEqualMid (picokpr_Preproc preproc, picoos_uchar str[], picoos_int32 len__11, picokpr_StrArrOffset mid)
304 {
305 picokpr_VarStrPtr lstrp;
306 len__11 = len__11; /*PP 13.10.08 : fix warning "var not used in this function"*/
307 lstrp = (picokpr_VarStrPtr)(void *) &((kpr_SubObj)preproc)->rStrArr[mid];
308 return (picoos_strstr((picoos_char*)str, (picoos_char*)lstrp) != NULL);
309 }
310
311
312
picokpr_isEqualTail(picokpr_Preproc preproc,picoos_uchar str[],picoos_int32 len__12,picokpr_StrArrOffset tail)313 extern picoos_bool picokpr_isEqualTail (picokpr_Preproc preproc, picoos_uchar str[], picoos_int32 len__12, picokpr_StrArrOffset tail)
314 {
315 picoos_int32 lstart;
316 picokpr_VarStrPtr lstrp;
317 len__12 = len__12; /* avoid warning "var not used in this function"*/
318 lstrp = (picokpr_VarStrPtr)&((kpr_SubObj)preproc)->rStrArr[tail];
319 lstart = picoos_strlen((picoos_char*)str) - picoos_strlen((picoos_char*)lstrp);
320 if (lstart >= 0) {
321 return (picoos_strstr((picoos_char*)&(str[lstart]), (picoos_char*)lstrp) != NULL);
322 } else {
323 return FALSE;
324 }
325 }
326
327 /* *****************************************************************************/
328 /* knowledge base access routines for lexical categories in LexCatArr */
329 /* *****************************************************************************/
330
picokpr_getLexCat(picokpr_Preproc preproc,picokpr_LexCatArrOffset ofs)331 extern picokpr_LexCat picokpr_getLexCat(picokpr_Preproc preproc, picokpr_LexCatArrOffset ofs)
332 {
333 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rLexCatArr[ofs]);
334
335 return p[0] + 256*p[1];
336 }
337
338 /* *****************************************************************************/
339 /* knowledge base access routines for AttrVal fields in AttrValArr */
340 /* *****************************************************************************/
341
picokpr_getAttrValArrInt32(picokpr_Preproc preproc,picokpr_AttrValArrOffset ofs)342 extern picoos_int32 picokpr_getAttrValArrInt32(picokpr_Preproc preproc, picokpr_AttrValArrOffset ofs)
343 {
344 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rAttrValArr[ofs]);
345 picoos_uint32 c = p[KPR_ATTRVAL_INT_OFS] +
346 256*p[KPR_ATTRVAL_INT_OFS+1] +
347 256*256*p[KPR_ATTRVAL_INT_OFS+2] +
348 256*256*256*p[KPR_ATTRVAL_INT_OFS+3];
349
350 if (c > KPR_MAX_INT32) {
351 return (c - KPR_MAX_INT32) - 1;
352 } else {
353 return (((int)c + (int) -(KPR_MAX_INT32)) - 1);
354 }
355 }
356
357 /* *****************************************************************************/
358 /* knowledge base access routines for AttrVal fields in AttrValArr */
359 /* *****************************************************************************/
360
picokpr_getOutItemNextOfs(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)361 extern picokpr_OutItemArrOffset picokpr_getOutItemNextOfs(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
362 {
363 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
364
365 return p[KPR_OUTITEM_NEXTOFS_OFS+0] + 256*p[KPR_OUTITEM_NEXTOFS_OFS+1];
366 }
367
368
picokpr_getOutItemType(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)369 extern picoos_int32 picokpr_getOutItemType(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
370 {
371 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
372
373 return p[KPR_OUTITEM_TYPE_OFS+0];
374 }
375
376
picokpr_getOutItemStrOfs(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)377 extern picokpr_StrArrOffset picokpr_getOutItemStrOfs(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
378 {
379 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
380
381 return p[KPR_OUTITEM_STROFS_OFS+0] +
382 256*p[KPR_OUTITEM_STROFS_OFS+1] +
383 256*256*p[KPR_OUTITEM_STROFS_OFS+2] +
384 256*256*256*p[KPR_OUTITEM_STROFS_OFS+3];
385 }
386
387
picokpr_getOutItemStr(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)388 extern picokpr_VarStrPtr picokpr_getOutItemStr(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
389 {
390 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
391 picoos_uint32 c = p[KPR_OUTITEM_STROFS_OFS+0] +
392 256*p[KPR_OUTITEM_STROFS_OFS+1] +
393 256*256*p[KPR_OUTITEM_STROFS_OFS+2] +
394 256*256*256*p[KPR_OUTITEM_STROFS_OFS+3];
395
396 return (picoos_uint8 *)&(((kpr_SubObj)preproc)->rStrArr[c]);
397 }
398
picokpr_getOutItemVal(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)399 extern picoos_int32 picokpr_getOutItemVal(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
400 {
401 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
402 picoos_uint32 c = p[KPR_OUTITEM_VAL_OFS+0] +
403 256*p[KPR_OUTITEM_VAL_OFS+1] +
404 256*256*p[KPR_OUTITEM_VAL_OFS+2] +
405 256*256*256*p[KPR_OUTITEM_VAL_OFS+3];
406
407 if (c > KPR_MAX_INT32) {
408 return (c - KPR_MAX_INT32) - 1;
409 } else {
410 return (((int)c + (int) -(KPR_MAX_INT32)) - 1);
411 }
412 }
413
414
picokpr_getOutItemArgOfs(picokpr_Preproc preproc,picokpr_OutItemArrOffset ofs)415 extern picokpr_OutItemArrOffset picokpr_getOutItemArgOfs(picokpr_Preproc preproc, picokpr_OutItemArrOffset ofs)
416 {
417 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rOutItemArr[ofs]);
418
419 return p[KPR_OUTITEM_ARGOFS_OFS+0] +
420 256*p[KPR_OUTITEM_ARGOFS_OFS+1] +
421 256*256*p[KPR_OUTITEM_ARGOFS_OFS+2] +
422 256*256*256*p[KPR_OUTITEM_ARGOFS_OFS+3];
423 }
424
425
426 /* *****************************************************************************/
427 /* knowledge base access routines for tokens in TokArr */
428 /* *****************************************************************************/
429
picokpr_getTokSetNP(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)430 extern picokpr_TokSetNP picokpr_getTokSetNP(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
431 {
432 picoos_uint32 c/*, b*/;
433 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]) + KPR_TOK_SETNP_OFS;
434 /*picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);*/
435 picoos_uint32 p0, p1, p2, p3;
436
437 p0 = *(p++);
438 p1 = *(p++);
439 p2 = *(p++);
440 p3 = *p;
441
442 c = p0 + (p1<<8) + (p2<<16) + (p3<<24);
443
444 return c;
445
446 /*
447 c = p[KPR_TOK_SETNP_OFS+0] +
448 256*p[KPR_TOK_SETNP_OFS+1] +
449 256*256*p[KPR_TOK_SETNP_OFS+2] +
450 256*256*256*p[KPR_TOK_SETNP_OFS+3];
451
452 b = 0;
453 i = 0;
454 while ((i <= 31) && (c > 0)) {
455 if (c % 2 == 1) {
456 b |= (1<<i);
457 }
458 c = c / 2;
459 i++;
460 }
461
462 return b;
463 */
464 }
465
466
picokpr_getTokSetWP(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)467 extern picokpr_TokSetWP picokpr_getTokSetWP(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
468 {
469 picoos_uint32 c/*, b*/;
470 /* picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);*/
471 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]) + KPR_TOK_SETWP_OFS;
472 picoos_uint32 p0, p1, p2, p3;
473
474 p0 = *(p++);
475 p1 = *(p++);
476 p2 = *(p++);
477 p3 = *p;
478
479 c = p0 + (p1<<8) + (p2<<16) + (p3<<24);
480 return c;
481
482 /*
483 c = p[KPR_TOK_SETWP_OFS+0] +
484 256*p[KPR_TOK_SETWP_OFS+1] +
485 256*256*p[KPR_TOK_SETWP_OFS+2] +
486 256*256*256*p[KPR_TOK_SETWP_OFS+3];
487
488 b = 0;
489 i = 0;
490 while ((i <= 31) && (c > 0)) {
491 if (c % 2 == 1) {
492 b |= (1<<i);
493 }
494 c = c / 2;
495 i++;
496 }
497
498 return b;
499 */
500 }
501
502
picokpr_getTokNextOfs(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)503 extern picokpr_TokArrOffset picokpr_getTokNextOfs(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
504 {
505 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);
506
507 return p[KPR_TOK_NEXTOFS_OFS+0] + 256*p[KPR_TOK_NEXTOFS_OFS+1];
508 }
509
510
picokpr_getTokAltLOfs(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)511 extern picokpr_TokArrOffset picokpr_getTokAltLOfs(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
512 {
513 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]) + KPR_TOK_ALTLOFS_OFS;
514 picokpr_TokArrOffset c = *p++;
515 return c + 256**p;
516
517 /*picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);
518
519 return p[KPR_TOK_ALTLOFS_OFS+0] + 256*p[KPR_TOK_ALTLOFS_OFS+1];
520 */
521 }
522
523
picokpr_getTokAltROfs(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)524 extern picokpr_TokArrOffset picokpr_getTokAltROfs(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
525 {
526 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]) + KPR_TOK_ALTROFS_OFS;
527 picokpr_TokArrOffset c = *p++;
528 return c + 256**p;
529
530 /*picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);
531
532 return p[KPR_TOK_ALTROFS_OFS+0] + 256*p[KPR_TOK_ALTROFS_OFS+1];*/
533 }
534
535
picokpr_getTokAttribOfs(picokpr_Preproc preproc,picokpr_TokArrOffset ofs)536 extern picokpr_AttrValArrOffset picokpr_getTokAttribOfs(picokpr_Preproc preproc, picokpr_TokArrOffset ofs)
537 {
538 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rTokArr[ofs]);
539
540 return p[KPR_TOK_ATTRIBOFS_OFS+0] + 256*p[KPR_TOK_ATTRIBOFS_OFS+1];
541 }
542
543 /* *****************************************************************************/
544 /* knowledge base access routines for productions in ProdArr */
545 /* *****************************************************************************/
546
picokpr_getProdArrLen(picokpr_Preproc preproc)547 extern picoos_int32 picokpr_getProdArrLen(picokpr_Preproc preproc)
548 {
549 return ((kpr_SubObj)preproc)->rProdArrLen;
550 }
551
picokpr_getProdPrefCost(picokpr_Preproc preproc,picokpr_ProdArrOffset ofs)552 extern picoos_int32 picokpr_getProdPrefCost(picokpr_Preproc preproc, picokpr_ProdArrOffset ofs)
553 {
554 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rProdArr[ofs]);
555 picoos_uint32 c = p[KPR_PROD_PRODPREFCOST_OFS+0] +
556 256*p[KPR_PROD_PRODPREFCOST_OFS+1] +
557 256*256*p[KPR_PROD_PRODPREFCOST_OFS+2] +
558 256*256*256*p[KPR_PROD_PRODPREFCOST_OFS+3];
559
560
561 if (c > KPR_MAX_INT32) {
562 return (c - KPR_MAX_INT32) - 1;
563 } else {
564 return (((int)c + (int) -(KPR_MAX_INT32)) - 1);
565 }
566 }
567
568
picokpr_getProdNameOfs(picokpr_Preproc preproc,picokpr_ProdArrOffset ofs)569 extern picokpr_StrArrOffset picokpr_getProdNameOfs(picokpr_Preproc preproc, picokpr_ProdArrOffset ofs)
570 {
571 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rProdArr[ofs]);
572
573 return p[KPR_PROD_PRODNAMEOFS_OFS+0] +
574 256*p[KPR_PROD_PRODNAMEOFS_OFS+1] +
575 256*256*p[KPR_PROD_PRODNAMEOFS_OFS+2] +
576 256*256*256*p[KPR_PROD_PRODNAMEOFS_OFS+3];
577
578 }
579
580
picokpr_getProdATokOfs(picokpr_Preproc preproc,picokpr_ProdArrOffset ofs)581 extern picokpr_TokArrOffset picokpr_getProdATokOfs(picokpr_Preproc preproc, picokpr_ProdArrOffset ofs)
582 {
583 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rProdArr[ofs]);
584
585 return p[KPR_PROD_ATOKOFS_OFS+0] + 256*p[KPR_PROD_ATOKOFS_OFS+1];
586 }
587
588
picokpr_getProdETokOfs(picokpr_Preproc preproc,picokpr_ProdArrOffset ofs)589 extern picokpr_TokArrOffset picokpr_getProdETokOfs(picokpr_Preproc preproc, picokpr_ProdArrOffset ofs)
590 {
591 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rProdArr[ofs]);
592
593 return p[KPR_PROD_ETOKOFS_OFS+0] + 256*p[KPR_PROD_ETOKOFS_OFS+1];
594 }
595
596 /* *****************************************************************************/
597 /* knowledge base access routines for contexts in CtxArr */
598 /* *****************************************************************************/
599
picokpr_getCtxArrLen(picokpr_Preproc preproc)600 extern picoos_int32 picokpr_getCtxArrLen(picokpr_Preproc preproc)
601 {
602 return ((kpr_SubObj)preproc)->rCtxArrLen;
603 }
604
picokpr_getCtxCtxNameOfs(picokpr_Preproc preproc,picokpr_CtxArrOffset ofs)605 extern picokpr_StrArrOffset picokpr_getCtxCtxNameOfs(picokpr_Preproc preproc, picokpr_CtxArrOffset ofs)
606 {
607 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rCtxArr[ofs]);
608
609 return p[KPR_CTX_CTXNAMEOFS_OFS+0] +
610 256*p[KPR_CTX_CTXNAMEOFS_OFS+1] +
611 256*256*p[KPR_CTX_CTXNAMEOFS_OFS+2] +
612 256*256*256*p[KPR_CTX_CTXNAMEOFS_OFS+3];
613 }
614
615
picokpr_getCtxNetNameOfs(picokpr_Preproc preproc,picokpr_CtxArrOffset ofs)616 extern picokpr_StrArrOffset picokpr_getCtxNetNameOfs(picokpr_Preproc preproc, picokpr_CtxArrOffset ofs)
617 {
618 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rCtxArr[ofs]);
619
620 return p[KPR_CTX_NETNAMEOFS_OFS+0] +
621 256*p[KPR_CTX_NETNAMEOFS_OFS+1] +
622 256*256*p[KPR_CTX_NETNAMEOFS_OFS+2] +
623 256*256*256*p[KPR_CTX_NETNAMEOFS_OFS+3];
624 }
625
626
picokpr_getCtxProdNameOfs(picokpr_Preproc preproc,picokpr_CtxArrOffset ofs)627 extern picokpr_StrArrOffset picokpr_getCtxProdNameOfs(picokpr_Preproc preproc, picokpr_CtxArrOffset ofs)
628 {
629 picoos_uint8 * p = (picoos_uint8 *)&(((kpr_SubObj)preproc)->rCtxArr[ofs]);
630
631 return p[KPR_CTX_PRODNAMEOFS_OFS+0] +
632 256*p[KPR_CTX_PRODNAMEOFS_OFS+1] +
633 256*256*p[KPR_CTX_PRODNAMEOFS_OFS+2] +
634 256*256*256*p[KPR_CTX_PRODNAMEOFS_OFS+3];
635 }
636
637 /* *****************************************************************************/
638 /* knowledge base access routines for networks */
639 /* *****************************************************************************/
640
picokpr_getPreprocNetName(picokpr_Preproc preproc)641 extern picokpr_VarStrPtr picokpr_getPreprocNetName(picokpr_Preproc preproc)
642 {
643 return ((kpr_SubObj)preproc)->rNetName;
644 }
645
646
647 #ifdef __cplusplus
648 }
649 #endif
650
651
652 /* end */
653