FreeCalypso > hg > fc-magnetite
comparison src/ui3/atb/ATBPbGI.c @ 420:e8ddbb0837ed
src/ui3: initial import of TCS3/LoCosto BMI & MFW code
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 21 Jan 2018 03:09:00 +0000 (2018-01-21) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
419:59143cd42ec7 | 420:e8ddbb0837ed |
---|---|
1 /* | |
2 +--------------------------------------------------------------------+ | |
3 | PROJECT: MMI-Framework (8417) $Workfile:: ATBPbGI.c $| | |
4 | | |
5 +--------------------------------------------------------------------+ | |
6 | |
7 MODULE : ATBPbGI | |
8 | |
9 PURPOSE : This modul contains phonebook management functions using ATB. | |
10 | |
11 HISTORY: | |
12 | |
13 Oct 27, 2005 REF: OMAPS 48881 b-nekkare | |
14 Description: PhoneBook: The modify option under phonebook doesn't | |
15 work as expected. | |
16 Solution : Change is needed when we initially store the PB entry with | |
17 a '+' and then we delete the '+' and resave the number again. | |
18 If this is not done we would always end up preserving the TON | |
19 as INTERNATIONAL type | |
20 */ | |
21 #if defined (NEW_FRAME) | |
22 | |
23 #include "typedefs.h" | |
24 #include "vsi.h" | |
25 #include "pei.h" | |
26 #include "custom.h" | |
27 #include "gsm.h" | |
28 | |
29 #else | |
30 | |
31 #include "STDDEFS.H" | |
32 #include "custom.h" | |
33 #include "gsm.h" | |
34 #include "vsi.h" | |
35 | |
36 #endif | |
37 | |
38 #include <stdio.h> | |
39 #include <string.h> | |
40 | |
41 #include "mfw_mfw.h" | |
42 #include "mfw_sys.h" | |
43 #include "mfw_phb.h" | |
44 #include "mfw_cm.h" | |
45 #include "mfw_ss.h" | |
46 | |
47 #include "cus_aci.h" | |
48 #include "prim.h" | |
49 #include "pcm.h" | |
50 | |
51 #include "ATBPb.h" | |
52 #include "ATBPbGI.h" | |
53 | |
54 | |
55 /******************************************************************************* | |
56 * LOCAL FUNCTION PROTOTYPES | |
57 * | |
58 ******************************************************************************/ | |
59 | |
60 void GI_alpha_AlphaToAscii(T_MFW_PHB_TEXT *ascii, T_PB_ALPHA *alpha, SHORT max_len); | |
61 void GI_alpha_AsciiToAlpha(T_PB_ALPHA *alpha, T_MFW_PHB_TEXT *ascii, SHORT max_len); | |
62 T_PB_INDEX GI_index_Convert(UBYTE mode); | |
63 | |
64 | |
65 /******************************************************************************* | |
66 | |
67 $Function: GI_pb_GetPhonebook | |
68 | |
69 $Description: Checks to see which file system is selected | |
70 | |
71 $Returns: MFW_PHB_OK Action completed OK. | |
72 MFW_PHB_FAIL File write encountered an error | |
73 | |
74 $Arguments: intphonebook Place to store type of phonebook selected | |
75 (TRUE for FFS) | |
76 | |
77 *******************************************************************************/ | |
78 | |
79 T_MFW GI_pb_GetPhonebook(UBYTE *intphonebook) | |
80 { | |
81 PB_RET result; | |
82 T_MFW ret; | |
83 T_PB_TYPE current_type; | |
84 | |
85 result = ATB_pb_GetPhonebook(PB_BOOK_DEFAULT, ¤t_type); | |
86 | |
87 if (current_type==PB_TYPE_FFS) | |
88 *intphonebook = TRUE; | |
89 else | |
90 *intphonebook = FALSE; | |
91 | |
92 if (result==PB_OK) | |
93 ret = MFW_PHB_OK; | |
94 else | |
95 ret = MFW_PHB_FAIL; | |
96 | |
97 return ret; | |
98 } | |
99 | |
100 | |
101 /******************************************************************************* | |
102 | |
103 $Function: GI_pb_SetPhonebook | |
104 | |
105 $Description: Selects file system | |
106 | |
107 $Returns: MFW_PHB_OK Action completed OK. | |
108 MFW_PHB_FAIL File write encountered an error | |
109 | |
110 $Arguments: intphonebook TRUE if FFS is to be used | |
111 | |
112 *******************************************************************************/ | |
113 | |
114 T_MFW GI_pb_SetPhonebook(UBYTE intphonebook) | |
115 { | |
116 PB_RET result; | |
117 T_MFW ret; | |
118 T_PB_TYPE current_type; | |
119 | |
120 if (intphonebook) | |
121 current_type = PB_TYPE_FFS; | |
122 else | |
123 current_type = PB_TYPE_SIM; | |
124 | |
125 result = ATB_pb_SetPhonebook((SHORT)PB_BOOK_DEFAULT, current_type); | |
126 | |
127 if (result==PB_OK) | |
128 ret = MFW_PHB_OK; | |
129 else | |
130 ret = MFW_PHB_FAIL; | |
131 | |
132 return ret; | |
133 } | |
134 | |
135 | |
136 /******************************************************************************* | |
137 | |
138 $Function: GI_pb_Initialise | |
139 | |
140 $Description: Initialise an instance of phonebook. Dynamically allocates a record | |
141 cache in RAM. Creates the necessary file(s) if they do not already exist. | |
142 Sorts the phonebook by name and by number, creating the appropriate | |
143 index tables. | |
144 | |
145 $Returns: MFW_PHB_OK | |
146 MFW_PHB_FAIL | |
147 | |
148 $Arguments: None | |
149 | |
150 *******************************************************************************/ | |
151 | |
152 T_MFW GI_pb_Initialise(void) | |
153 { | |
154 PB_RET result; | |
155 T_MFW ret=MFW_PHB_FAIL; | |
156 | |
157 tracefunction("GI_pb_Initialise"); | |
158 | |
159 result = ATB_pb_Initialise(PB_BOOK_DEFAULT, PB_TYPE_FFS, PB_RECORDS_MAX, | |
160 PB_CACHE_MAX, PB_ALPHATAG_MAX, PB_NUMBER_MAX, PB_EXT_MAX); | |
161 | |
162 switch(result) | |
163 { | |
164 case PB_OK: | |
165 ret = MFW_PHB_OK; | |
166 break; | |
167 case PB_EXCT: | |
168 ret = MFW_PHB_OK; | |
169 break; | |
170 case PB_BOOKALREADYEXISTS: | |
171 ret = MFW_PHB_FAIL; | |
172 break; | |
173 } | |
174 | |
175 return ret; | |
176 } | |
177 | |
178 | |
179 /******************************************************************************* | |
180 | |
181 $Function: GI_pb_Exit | |
182 | |
183 $Description: Frees memory associated with phonebook. To be called when the | |
184 phonebook is no longer required, or at shutdown. | |
185 | |
186 $Returns: MFW_PB_OK Action completed OK. | |
187 | |
188 $Arguments: None | |
189 | |
190 *******************************************************************************/ | |
191 | |
192 T_MFW GI_pb_Exit(void) | |
193 { | |
194 tracefunction("GI_pb_Exit"); | |
195 | |
196 ATB_pb_Exit(PB_BOOK_DEFAULT); | |
197 return MFW_PHB_OK; | |
198 } | |
199 | |
200 | |
201 /******************************************************************************* | |
202 | |
203 $Function: GI_pb_Info | |
204 | |
205 $Description: Returns information about the phonebook, which will be returned | |
206 in the data structure pointed to by status. The caller must | |
207 allocate the T_MFW_PHB_STATUS structure. | |
208 | |
209 $Returns: MFW_PB_OK Action completed OK. | |
210 | |
211 $Arguments: status Data structure to contain phonebook info | |
212 | |
213 *******************************************************************************/ | |
214 | |
215 void GI_pb_Info(T_MFW_PHB_STATUS *status) | |
216 { | |
217 T_PB_INFO info; | |
218 | |
219 tracefunction("GI_pb_Info"); | |
220 | |
221 ATB_pb_Info(PB_BOOK_DEFAULT, &info); | |
222 | |
223 status->book = PHB_IPB; | |
224 status->max_entries = (UBYTE)info.records_max; | |
225 status->used_entries = (UBYTE)info.records_used; | |
226 status->avail_entries = (UBYTE)info.records_free; | |
227 status->tag_len = PHB_MAX_LEN; | |
228 | |
229 return; | |
230 } | |
231 | |
232 | |
233 /******************************************************************************* | |
234 | |
235 $Function: GI_pb_Status | |
236 | |
237 $Description: Returns whether or not the phonebook is busy. If so, stat will contain | |
238 PHB_BUSY, otherwise PHB_READY. | |
239 | |
240 $Returns: None | |
241 | |
242 $Arguments: stat UBYTE to contain status information | |
243 | |
244 *******************************************************************************/ | |
245 | |
246 void GI_pb_Status(UBYTE *stat) | |
247 { | |
248 | |
249 | |
250 tracefunction("GI_pb_Status"); | |
251 | |
252 ATB_pb_Status(PB_BOOK_DEFAULT); | |
253 | |
254 return; | |
255 } | |
256 | |
257 | |
258 | |
259 /******************************************************************************* | |
260 | |
261 $Function: GI_pb_WriteRec | |
262 | |
263 $Description: Writes a record to the physical position index. If the index is | |
264 0, a new record is added, otherwise the previous | |
265 record at that position is overwritten. | |
266 | |
267 $Returns: MFW_PHB_OK | |
268 MFW_PHB_FAIL | |
269 MFW_PHB_FULL | |
270 | |
271 $Arguments: entry The phonebook entry to write | |
272 | |
273 *******************************************************************************/ | |
274 | |
275 T_MFW GI_pb_WriteRec(T_MFW_PHB_ENTRY *entry) | |
276 { | |
277 T_MFW ret; | |
278 PB_RET result; | |
279 SHORT index; | |
280 T_PB_RECORD *record; | |
281 UBYTE *number; | |
282 | |
283 tracefunction("GI_pb_WriteRec"); | |
284 | |
285 /* Allocate memory for record */ | |
286 | |
287 record = ATB_pb_AllocRec(PB_BOOK_DEFAULT); | |
288 | |
289 /* If the provided index is 0, we must add new record */ | |
290 | |
291 if (entry->index==0) | |
292 index = PB_NEW_RECORD; | |
293 else | |
294 index = (SHORT)(entry->index-1); /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
295 | |
296 /* Convert name to unicode*/ | |
297 | |
298 record->alpha.dcs = entry->name.dcs; | |
299 record->alpha.length = (UBYTE)entry->name.len; | |
300 GI_alpha_AsciiToAlpha(&record->alpha, &entry->name, PHB_MAX_LEN); | |
301 | |
302 /* Convert number to BCD */ | |
303 | |
304 record->ton_npi = entry->npi & 0x0F; | |
305 record->ton_npi |= (entry->ton<<4); | |
306 | |
307 number = entry->number; | |
308 | |
309 if (number[0]=='+') | |
310 { | |
311 record->ton_npi &= 0xF0; | |
312 record->ton_npi |= (MFW_TON_INTERNATIONAL<<4); | |
313 number++; | |
314 } | |
315 // Oct 27, 2005 REF: OMAPS OMAPS00048881 b-nekkare | |
316 else if(entry->ton == MFW_TON_INTERNATIONAL) | |
317 { | |
318 record->ton_npi = entry->npi & 0x0F; | |
319 record->ton_npi |= (MFW_TON_UNKNOWN<<4); | |
320 } | |
321 /* Anything else keep as is */ | |
322 | |
323 TRACE_EVENT_P1("ton_npi: %X", record->ton_npi); | |
324 | |
325 ATB_pb_CharToBCD(record->number, (char *)number, PB_NUMBER_MAX); | |
326 | |
327 /* Write the record */ | |
328 | |
329 result = ATB_pb_WriteRec(PB_BOOK_DEFAULT, INDEX_PHYSICAL, index, record); | |
330 | |
331 /* Free allocated record */ | |
332 | |
333 ATB_pb_FreeRec(PB_BOOK_DEFAULT, record); | |
334 | |
335 switch(result) | |
336 { | |
337 case PB_OK: | |
338 ret = MFW_PHB_OK; | |
339 break; | |
340 case PB_BOOKFULL: | |
341 ret = MFW_PHB_FULL; | |
342 break; | |
343 default: | |
344 ret = MFW_PHB_FAIL; | |
345 break; | |
346 } | |
347 | |
348 return ret; | |
349 } | |
350 | |
351 | |
352 /******************************************************************************* | |
353 | |
354 $Function: GI_pb_DeleteRec | |
355 | |
356 $Description: Deletes a record at a physical position index. | |
357 | |
358 $Returns: MFW_PHB_OK | |
359 MFW_PHB_FAIL | |
360 | |
361 $Arguments: index Physical index of the record to delete | |
362 | |
363 *******************************************************************************/ | |
364 | |
365 T_MFW GI_pb_DeleteRec(UBYTE index) | |
366 { | |
367 T_MFW ret; | |
368 PB_RET result; | |
369 | |
370 tracefunction("GI_pb_DeleteRec"); | |
371 | |
372 /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
373 | |
374 index--; | |
375 | |
376 /* Delete record */ | |
377 | |
378 result = ATB_pb_DeleteRec((SHORT)PB_BOOK_DEFAULT, INDEX_PHYSICAL, (SHORT)index); | |
379 | |
380 switch(result) | |
381 { | |
382 case PB_OK: | |
383 ret = MFW_PHB_OK; | |
384 break; | |
385 default: | |
386 ret = MFW_PHB_FAIL; | |
387 break; | |
388 } | |
389 | |
390 return ret; | |
391 } | |
392 | |
393 | |
394 /******************************************************************************* | |
395 | |
396 $Function: GI_pb_Find | |
397 | |
398 $Description: Find the nearest match to the supplied record. | |
399 | |
400 $Returns: MFW_PHB_OK | |
401 MFW_PHB_FAIL | |
402 | |
403 $Arguments: mode Specifies the sorting for the index list | |
404 index Place to store the index of the matching record | |
405 num_recs Number of records to read in | |
406 search_pattern The string or number to match | |
407 entries Place to store the resulting list of entries | |
408 | |
409 *******************************************************************************/ | |
410 | |
411 T_MFW GI_pb_Find(UBYTE mode, UBYTE *index, UBYTE num_recs, T_MFW_PHB_TEXT *search_pattern, T_MFW_PHB_LIST *entries) | |
412 { | |
413 PB_RET result; | |
414 T_MFW ret=MFW_PHB_FAIL; | |
415 T_PB_INDEX index_type = GI_index_Convert(mode); | |
416 T_PB_RECORD *record; | |
417 SHORT rec_index; | |
418 UBYTE *number; | |
419 | |
420 tracefunction("GI_pb_Find"); | |
421 | |
422 /* Allocate memory for record */ | |
423 | |
424 record = ATB_pb_AllocRec(PB_BOOK_DEFAULT); | |
425 | |
426 /* Convert name to unicode, or number to BCD */ | |
427 | |
428 if(index_type==INDEX_NAME) | |
429 { | |
430 GI_alpha_AsciiToAlpha(&record->alpha, search_pattern, PB_ALPHATAG_MAX); | |
431 } | |
432 else | |
433 { | |
434 /* Convert number to BCD */ | |
435 | |
436 number = search_pattern->data; | |
437 | |
438 if (number[0]=='+') | |
439 { | |
440 number++; | |
441 } | |
442 ATB_pb_CharToBCD(record->number, (char *)number, PB_NUMBER_MAX); | |
443 } | |
444 | |
445 result = ATB_pb_Find(PB_BOOK_DEFAULT, index_type, record, &rec_index, NULL); | |
446 | |
447 if (result==PB_OK) | |
448 { | |
449 *index = rec_index+1; /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
450 ret = GI_pb_ReadRecList(mode, (UBYTE)(*index), num_recs, entries);/*a0393213 warnings removal-result changed to ret*/ | |
451 } | |
452 | |
453 /* Free allocated record */ | |
454 | |
455 ATB_pb_FreeRec(PB_BOOK_DEFAULT, record); | |
456 | |
457 | |
458 switch(result) | |
459 { | |
460 case PB_OK: | |
461 /*ret = MFW_PHB_OK;*//*a0393213 warnings removal-commented because of last change for warning*/ | |
462 break; | |
463 default: | |
464 ret = MFW_PHB_FAIL; | |
465 break; | |
466 } | |
467 | |
468 return ret; | |
469 } | |
470 | |
471 /******************************************************************************* | |
472 | |
473 $Function: GI_pb_ReadRecList | |
474 | |
475 $Description: Read in a list of entries. | |
476 | |
477 $Returns: MFW_PHB_OK | |
478 MFW_PHB_FAIL | |
479 | |
480 $Arguments: mode Specifies the sorting for the index list | |
481 index Place to store the index of the matching record | |
482 num_recs Number of records to read in | |
483 entries Place to store the resulting list of entries | |
484 | |
485 *******************************************************************************/ | |
486 | |
487 T_MFW GI_pb_ReadRecList(UBYTE mode, UBYTE index, UBYTE num_recs, T_MFW_PHB_LIST *entries) | |
488 { | |
489 PB_RET result; | |
490 T_MFW ret; | |
491 T_PB_INDEX index_type = GI_index_Convert(mode); | |
492 T_PB_RECORD *record; | |
493 SHORT recs_count; | |
494 | |
495 tracefunction("GI_pb_ReadRecList"); | |
496 | |
497 /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
498 | |
499 index--; | |
500 | |
501 /* Allocate memory for record */ | |
502 | |
503 record = ATB_pb_AllocRec(PB_BOOK_DEFAULT); | |
504 | |
505 for (recs_count = 0; recs_count<(SHORT)num_recs; recs_count++) | |
506 { | |
507 result = ATB_pb_ReadRec(PB_BOOK_DEFAULT, index_type, (SHORT)(index+recs_count), record); | |
508 if (result!=PB_OK) | |
509 break; | |
510 | |
511 entries->entry[recs_count].book = PHB_IPB; | |
512 entries->entry[recs_count].index = GI_pb_ConvIndex(index_type, (UBYTE)(index+recs_count), INDEX_PHYSICAL); | |
513 entries->entry[recs_count].ton = (record->ton_npi & 0xF0)>>4; | |
514 entries->entry[recs_count].npi = record->ton_npi & 0x0F; | |
515 GI_alpha_AlphaToAscii(&entries->entry[recs_count].name, &record->alpha, PB_ALPHATAG_MAX); | |
516 ATB_pb_BCDToChar((char *)entries->entry[recs_count].number, record->number, PB_NUMBER_MAX); | |
517 } | |
518 | |
519 entries->book = PHB_IPB; | |
520 | |
521 if (recs_count) | |
522 { | |
523 entries->result = MFW_ENTRY_EXIST; | |
524 entries->num_entries = (UBYTE) recs_count; | |
525 /* SPR#1994 - SH - If at least one record is found, result is a success */ | |
526 result = PB_OK; | |
527 } | |
528 else | |
529 { | |
530 entries->result = MFW_NO_ENTRY; | |
531 } | |
532 | |
533 /* Free allocated record */ | |
534 | |
535 ATB_pb_FreeRec(PB_BOOK_DEFAULT, record); | |
536 | |
537 switch(result) | |
538 { | |
539 case PB_OK: | |
540 ret = MFW_PHB_OK; | |
541 break; | |
542 case PB_RECDOESNOTEXIST: | |
543 ret = MFW_PHB_FAIL; | |
544 break; | |
545 default: | |
546 ret = MFW_PHB_FAIL; | |
547 break; | |
548 } | |
549 | |
550 return ret; | |
551 } | |
552 | |
553 /******************************************************************************* | |
554 | |
555 $Function: GI_pb_ConvIndex | |
556 | |
557 $Description: Returns the index in table new_index_type corresponding to the index | |
558 in table index_type. | |
559 | |
560 $Returns: The new index | |
561 | |
562 $Arguments: index_type The index table of the original index. | |
563 index The original logical index. | |
564 new_index_type The index table required. | |
565 | |
566 *******************************************************************************/ | |
567 | |
568 UBYTE GI_pb_ConvIndex(T_PB_INDEX index_type, UBYTE index, T_PB_INDEX new_index_type) | |
569 { | |
570 SHORT new_index; | |
571 | |
572 tracefunction("GI_pb_ConvIndex"); | |
573 | |
574 ATB_pb_ConvIndex(PB_BOOK_DEFAULT, index_type, (SHORT)index, new_index_type, &new_index); | |
575 | |
576 /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
577 | |
578 if (new_index_type==INDEX_PHYSICAL) | |
579 { | |
580 new_index++; | |
581 } | |
582 | |
583 return (UBYTE)new_index; | |
584 } | |
585 | |
586 | |
587 /******************************** | |
588 * Functions called by the ATB PB * | |
589 ********************************/ | |
590 | |
591 /******************************************************************************* | |
592 | |
593 $Function: GI_pb_OK | |
594 | |
595 $Description: This function is called if the requested command executed successfully. | |
596 The param parameter is a pointer to command specific information, | |
597 when such information is required to be passed from the ATB to the GI. | |
598 See the individual functions for more details. | |
599 | |
600 $Returns: None. | |
601 | |
602 $Arguments: phonebook_id The phonebook identifier | |
603 command_id Identifies the command. | |
604 param Pointer to command-specific information | |
605 | |
606 *******************************************************************************/ | |
607 | |
608 void GI_pb_OK(SHORT phonebook_id, SHORT command_id, void *param) | |
609 { | |
610 trace("GI_pb_OK"); | |
611 | |
612 if (param!=NULL) | |
613 { | |
614 trace_P1("Param is: %d", *((SHORT *)param)); | |
615 } | |
616 } | |
617 | |
618 /******************************************************************************* | |
619 | |
620 $Function: GI_pb_Error | |
621 | |
622 $Description: This function is called if an error was returned while executing the | |
623 requested command. | |
624 | |
625 $Returns: None. | |
626 | |
627 $Arguments: phonebook_id The phonebook identifier | |
628 command_id Identifies the command. | |
629 error_id Identifies the error that occurred. | |
630 | |
631 *******************************************************************************/ | |
632 | |
633 void GI_pb_Error(SHORT phonebook_id, SHORT command_id, SHORT error_id) | |
634 { | |
635 trace("GI_pb_Error"); | |
636 trace_P2("***ERROR*** - command %d, error %d", command_id, error_id); | |
637 | |
638 return; | |
639 } | |
640 | |
641 | |
642 /******************************************************************************* | |
643 | |
644 $Function: GI_pb_MemAlloc | |
645 | |
646 $Description: Dynamically allocates memory for the phonebook. | |
647 | |
648 $Returns: The address of the block of allocated memory, or NULL if failed. | |
649 | |
650 $Arguments: size - Amount of memory to be allocated in bytes | |
651 | |
652 *******************************************************************************/ | |
653 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar | |
654 // Description: MFW memory size variable changed from U16 -> U32 | |
655 // Solution: The use of variable U16 has been replaced with U32 | |
656 | |
657 UBYTE *GI_pb_MemAlloc(U32 size) | |
658 { | |
659 return mfwAlloc((U32)size); | |
660 } | |
661 | |
662 | |
663 /******************************************************************************* | |
664 | |
665 $Function: GI_pb_MemFree | |
666 | |
667 $Description: Frees dynamically allocated memory. | |
668 | |
669 $Returns: None | |
670 | |
671 $Arguments: mem - Pointer to a block of allocated memory | |
672 size - Size of the block | |
673 | |
674 *******************************************************************************/ | |
675 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar | |
676 // Description: MFW memory size variable changed from U16 -> U32 | |
677 // Solution: The use of variable U16 has been replaced with U32 | |
678 | |
679 void GI_pb_MemFree(UBYTE *mem, U32 size) | |
680 { | |
681 mfwFree(mem, (U32)size); | |
682 return; | |
683 } | |
684 | |
685 | |
686 /******************************************************************************* | |
687 | |
688 $Function: GI_pb_Match | |
689 | |
690 $Description: This function allows the user to specify the way in which entries are | |
691 matched during searching. This provides the capability of searching | |
692 languages with non-Latin alphabets, or searching through special user | |
693 fields. | |
694 This function attempts a match between two records based on the | |
695 field appropriate for the index list, specified in index_type. It returns | |
696 a value indicating whether there is no match (MATCH_NONE), | |
697 a partial match (MAX_START), or an exact match (MATCH_EXACT). | |
698 Note that the contents of the records themselves should not be altered | |
699 by this function. The sole result should be a return value that specifies | |
700 how the first record matches the second. If it is preferred that the | |
701 default matching routine is used (i.e match from the start for alpha | |
702 tags, match from the end for phone numbers) then MATCH_DEFAULT | |
703 should be returned. | |
704 | |
705 $Returns: MATCH_DEFAULT, MATCH_EXACT, MATCH_START or MATCH_NONE | |
706 | |
707 $Arguments: record1 The first record to be compared | |
708 record2 The second record to be compared | |
709 index_type Indicator of the field which is to be compared | |
710 | |
711 *******************************************************************************/ | |
712 | |
713 T_PB_MATCH GI_pb_Match(T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type) | |
714 { | |
715 return MATCH_DEFAULT; | |
716 } | |
717 | |
718 | |
719 /******************************************************************************* | |
720 | |
721 $Function: GI_pb_Compare | |
722 | |
723 $Description: This function allows the user to specify the way in which entries are | |
724 compared during sorting. This provides the capability of sorting languages | |
725 with non-Latin alphabets, or sorting to alternative orders (for example, | |
726 reverse alphabetical). | |
727 This function compares two records based on the field appropriate for the | |
728 index list, specified in index_type. | |
729 It returns a value indicating whether the first record should come before | |
730 or after the second. | |
731 Note that the contents of the records themselves should not be altered by | |
732 this function. The sole result should be a return value that specifies | |
733 whether or not the positions of the records should be swapped. If it | |
734 is preferred that the default comparison routine is used (e.g.Latin | |
735 alphabetical ascending) then COMPARE_DEFAULT should be returned. | |
736 | |
737 | |
738 $Returns: COMPARE_DEFAULT No comparison made - use the default comparison method | |
739 COMPARE_FIRSTBEFORE The first record should come before the second record | |
740 COMPARE_FIRSTAFTER The first record should come after the second record | |
741 | |
742 $Arguments: record1 The first record to be compared | |
743 record2 The second record to be compared | |
744 index_type Index list to use | |
745 | |
746 *******************************************************************************/ | |
747 | |
748 T_PB_COMPARE GI_pb_Compare (T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type) | |
749 { | |
750 return COMPARE_DEFAULT; | |
751 } | |
752 | |
753 | |
754 /******************************************************************************* | |
755 | |
756 $Function: GI_pb_GetTable | |
757 | |
758 $Description: If fields other than name and number are required, then index tables | |
759 must be provided for each field. This function is called when access | |
760 to an index table is required for an unknown index type. | |
761 | |
762 The array provided must be a user-allocated array of type SHORT, | |
763 records_max in size, e.g. | |
764 | |
765 static SHORT user_table[RECORDS_MAX]; | |
766 return user_table; | |
767 | |
768 $Returns: A pointer to an array of SHORTs records_max in size. | |
769 | |
770 $Arguments: index_type Index list to use | |
771 | |
772 *******************************************************************************/ | |
773 | |
774 SHORT *GI_pb_GetTable (T_PB_INDEX index_type) | |
775 { | |
776 SHORT *user_table = NULL; /*DUMMY IMPLEMENTATION*/ | |
777 return user_table; | |
778 } | |
779 | |
780 | |
781 /******************************************************************************* | |
782 | |
783 $Function: GI_alpha_AlphaToAscii | |
784 | |
785 $Description: Convert an alpha tag to an ascii string | |
786 | |
787 $Returns: None | |
788 | |
789 $Arguments: ascii The ascii string | |
790 alpha The alpha tag | |
791 max_len The maximum length of the resulting string | |
792 | |
793 *******************************************************************************/ | |
794 | |
795 void GI_alpha_AlphaToAscii(T_MFW_PHB_TEXT *ascii, T_PB_ALPHA *alpha, SHORT max_len) | |
796 { | |
797 SHORT asciiIndex; | |
798 SHORT alphaIndex; | |
799 | |
800 /* Unicode entry - swap the low and high bytes, add in 0x80 at start*/ | |
801 | |
802 ascii->dcs = alpha->dcs; | |
803 | |
804 if (alpha->dcs == MFW_DCS_UCS2) | |
805 { | |
806 ascii->data[0] = 0x80; | |
807 asciiIndex = 1; | |
808 alphaIndex = 0; | |
809 | |
810 while (alphaIndex<alpha->length && asciiIndex<max_len) | |
811 { | |
812 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex]>>8); | |
813 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex] & 0xFF); | |
814 alphaIndex++; | |
815 } | |
816 | |
817 /* Put two NULLs at the end, if there is space */ | |
818 | |
819 if (asciiIndex<max_len) | |
820 ascii->data[asciiIndex++] = NULL; | |
821 if (asciiIndex<max_len) | |
822 ascii->data[asciiIndex] = NULL; | |
823 | |
824 ascii->len = asciiIndex; | |
825 } | |
826 | |
827 /* Ascii entry - convert from unicode */ | |
828 | |
829 else | |
830 { | |
831 asciiIndex = 0; | |
832 alphaIndex = 0; | |
833 | |
834 while (alphaIndex<alpha->length && asciiIndex<max_len) | |
835 { | |
836 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex++]); | |
837 } | |
838 | |
839 /* Put a NULL at the end, if there is space */ | |
840 | |
841 if (asciiIndex<max_len) | |
842 ascii->data[asciiIndex] = NULL; | |
843 | |
844 ascii->len = asciiIndex; | |
845 } | |
846 | |
847 return; | |
848 } | |
849 | |
850 | |
851 /******************************************************************************* | |
852 | |
853 $Function: GI_alpha_AsciiToAlpha | |
854 | |
855 $Description: Convert an ascii string to an alpha tag | |
856 | |
857 $Returns: None | |
858 | |
859 $Arguments: alpha The alpha tag | |
860 ascii The ascii string | |
861 max_len The maximum length of the resulting string | |
862 | |
863 *******************************************************************************/ | |
864 | |
865 void GI_alpha_AsciiToAlpha(T_PB_ALPHA *alpha, T_MFW_PHB_TEXT *ascii, SHORT max_len) | |
866 { | |
867 SHORT asciiIndex; | |
868 SHORT alphaIndex; | |
869 | |
870 alpha->dcs = ascii->dcs; | |
871 | |
872 /* Unicode entry - swap the low and high bytes, ignore first '0x80' character */ | |
873 | |
874 if (ascii->dcs == MFW_DCS_UCS2) | |
875 { | |
876 asciiIndex = 1; | |
877 alphaIndex = 0; | |
878 | |
879 while (asciiIndex<ascii->len && alphaIndex<max_len) | |
880 { | |
881 alpha->data[alphaIndex] = (USHORT) ((ascii->data[asciiIndex]<<8) | ascii->data[asciiIndex+1]); | |
882 alphaIndex=alphaIndex+1; | |
883 asciiIndex=asciiIndex+2; | |
884 } | |
885 | |
886 /* Put a NULL at the end, if there is space */ | |
887 | |
888 if (alphaIndex<max_len) | |
889 alpha->data[alphaIndex] = NULL; | |
890 } | |
891 | |
892 /* Ascii entry - convert to unicode */ | |
893 | |
894 else | |
895 { | |
896 asciiIndex = 0; | |
897 alphaIndex = 0; | |
898 | |
899 while (asciiIndex<ascii->len && alphaIndex<max_len) | |
900 { | |
901 alpha->data[alphaIndex++] = (USHORT)ascii->data[asciiIndex++]; | |
902 } | |
903 | |
904 /* Put a NULL at the end, if there is space */ | |
905 | |
906 if (alphaIndex<max_len) | |
907 alpha->data[alphaIndex] = NULL; | |
908 } | |
909 | |
910 alpha->length = alphaIndex; | |
911 | |
912 return; | |
913 } | |
914 | |
915 | |
916 /******************************************************************************* | |
917 | |
918 $Function: GI_index_Convert | |
919 | |
920 $Description: Convert indexing types from MFW to ATB. | |
921 | |
922 $Returns: The ATB indexing type | |
923 | |
924 $Arguments: mode The MFW sort mode | |
925 | |
926 *******************************************************************************/ | |
927 | |
928 T_PB_INDEX GI_index_Convert(UBYTE mode) | |
929 { | |
930 T_PB_INDEX index_type=INDEX_DEFAULT_MAX; | |
931 | |
932 switch(mode) | |
933 { | |
934 case MFW_PHB_ALPHA: | |
935 index_type = INDEX_NAME; | |
936 break; | |
937 case MFW_PHB_NUMBER: | |
938 index_type = INDEX_NUMBER; | |
939 break; | |
940 case MFW_PHB_INDEX: | |
941 index_type = INDEX_PHYSICAL; /* NOTE - may not work quite as intended */ | |
942 break; | |
943 case MFW_PHB_PHYSICAL: | |
944 index_type = INDEX_PHYSICAL; | |
945 break; | |
946 } | |
947 | |
948 return index_type; | |
949 } |