FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/condat/ms/src/atb/ATBPbGI.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
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(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; | |
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 PB_RET result; | |
249 | |
250 tracefunction("GI_pb_Status"); | |
251 | |
252 result = 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(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; | |
415 T_PB_INDEX index_type = GI_index_Convert(mode); | |
416 T_PB_RECORD *record; | |
417 SHORT recs_count; | |
418 SHORT rec_index; | |
419 UBYTE *number; | |
420 | |
421 tracefunction("GI_pb_Find"); | |
422 | |
423 /* Allocate memory for record */ | |
424 | |
425 record = ATB_pb_AllocRec(PB_BOOK_DEFAULT); | |
426 | |
427 /* Convert name to unicode, or number to BCD */ | |
428 | |
429 if(index_type==INDEX_NAME) | |
430 { | |
431 GI_alpha_AsciiToAlpha(&record->alpha, search_pattern, PB_ALPHATAG_MAX); | |
432 } | |
433 else | |
434 { | |
435 /* Convert number to BCD */ | |
436 | |
437 number = search_pattern->data; | |
438 | |
439 if (number[0]=='+') | |
440 { | |
441 number++; | |
442 } | |
443 ATB_pb_CharToBCD(record->number, (char *)number, PB_NUMBER_MAX); | |
444 } | |
445 | |
446 result = ATB_pb_Find(PB_BOOK_DEFAULT, index_type, record, &rec_index, NULL); | |
447 | |
448 if (result==PB_OK) | |
449 { | |
450 *index = rec_index+1; /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
451 result = GI_pb_ReadRecList(mode, (UBYTE)(*index), num_recs, entries); | |
452 } | |
453 | |
454 /* Free allocated record */ | |
455 | |
456 ATB_pb_FreeRec(PB_BOOK_DEFAULT, record); | |
457 | |
458 | |
459 switch(result) | |
460 { | |
461 case PB_OK: | |
462 ret = MFW_PHB_OK; | |
463 break; | |
464 default: | |
465 ret = MFW_PHB_FAIL; | |
466 break; | |
467 } | |
468 | |
469 return ret; | |
470 } | |
471 | |
472 /******************************************************************************* | |
473 | |
474 $Function: GI_pb_ReadRecList | |
475 | |
476 $Description: Read in a list of entries. | |
477 | |
478 $Returns: MFW_PHB_OK | |
479 MFW_PHB_FAIL | |
480 | |
481 $Arguments: mode Specifies the sorting for the index list | |
482 index Place to store the index of the matching record | |
483 num_recs Number of records to read in | |
484 entries Place to store the resulting list of entries | |
485 | |
486 *******************************************************************************/ | |
487 | |
488 T_MFW GI_pb_ReadRecList(UBYTE mode, UBYTE index, UBYTE num_recs, T_MFW_PHB_LIST *entries) | |
489 { | |
490 PB_RET result; | |
491 T_MFW ret; | |
492 T_PB_INDEX index_type = GI_index_Convert(mode); | |
493 T_PB_RECORD *record; | |
494 SHORT recs_count; | |
495 | |
496 tracefunction("GI_pb_ReadRecList"); | |
497 | |
498 /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
499 | |
500 index--; | |
501 | |
502 /* Allocate memory for record */ | |
503 | |
504 record = ATB_pb_AllocRec(PB_BOOK_DEFAULT); | |
505 | |
506 for (recs_count = 0; recs_count<(SHORT)num_recs; recs_count++) | |
507 { | |
508 result = ATB_pb_ReadRec(PB_BOOK_DEFAULT, index_type, (SHORT)(index+recs_count), record); | |
509 if (result!=PB_OK) | |
510 break; | |
511 | |
512 entries->entry[recs_count].book = PHB_IPB; | |
513 entries->entry[recs_count].index = GI_pb_ConvIndex(index_type, (UBYTE)(index+recs_count), INDEX_PHYSICAL); | |
514 entries->entry[recs_count].ton = (record->ton_npi & 0xF0)>>4; | |
515 entries->entry[recs_count].npi = record->ton_npi & 0x0F; | |
516 GI_alpha_AlphaToAscii(&entries->entry[recs_count].name, &record->alpha, PB_ALPHATAG_MAX); | |
517 ATB_pb_BCDToChar((char *)entries->entry[recs_count].number, record->number, PB_NUMBER_MAX); | |
518 } | |
519 | |
520 entries->book = PHB_IPB; | |
521 | |
522 if (recs_count) | |
523 { | |
524 entries->result = MFW_ENTRY_EXIST; | |
525 entries->num_entries = (UBYTE) recs_count; | |
526 /* SPR#1994 - SH - If at least one record is found, result is a success */ | |
527 result = PB_OK; | |
528 } | |
529 else | |
530 { | |
531 entries->result = MFW_NO_ENTRY; | |
532 } | |
533 | |
534 /* Free allocated record */ | |
535 | |
536 ATB_pb_FreeRec(PB_BOOK_DEFAULT, record); | |
537 | |
538 switch(result) | |
539 { | |
540 case PB_OK: | |
541 ret = MFW_PHB_OK; | |
542 break; | |
543 case PB_RECDOESNOTEXIST: | |
544 ret = MFW_PHB_FAIL; | |
545 break; | |
546 default: | |
547 ret = MFW_PHB_FAIL; | |
548 break; | |
549 } | |
550 | |
551 return ret; | |
552 } | |
553 | |
554 /******************************************************************************* | |
555 | |
556 $Function: GI_pb_ConvIndex | |
557 | |
558 $Description: Returns the index in table new_index_type corresponding to the index | |
559 in table index_type. | |
560 | |
561 $Returns: The new index | |
562 | |
563 $Arguments: index_type The index table of the original index. | |
564 index The original logical index. | |
565 new_index_type The index table required. | |
566 | |
567 *******************************************************************************/ | |
568 | |
569 UBYTE GI_pb_ConvIndex(T_PB_INDEX index_type, UBYTE index, T_PB_INDEX new_index_type) | |
570 { | |
571 SHORT new_index; | |
572 | |
573 tracefunction("GI_pb_ConvIndex"); | |
574 | |
575 ATB_pb_ConvIndex(PB_BOOK_DEFAULT, index_type, (SHORT)index, new_index_type, &new_index); | |
576 | |
577 /* MFW/ACI indices start at 1, ATB indices start at 0 */ | |
578 | |
579 if (new_index_type==INDEX_PHYSICAL) | |
580 { | |
581 new_index++; | |
582 } | |
583 | |
584 return (UBYTE)new_index; | |
585 } | |
586 | |
587 | |
588 /******************************** | |
589 * Functions called by the ATB PB * | |
590 ********************************/ | |
591 | |
592 /******************************************************************************* | |
593 | |
594 $Function: GI_pb_OK | |
595 | |
596 $Description: This function is called if the requested command executed successfully. | |
597 The param parameter is a pointer to command specific information, | |
598 when such information is required to be passed from the ATB to the GI. | |
599 See the individual functions for more details. | |
600 | |
601 $Returns: None. | |
602 | |
603 $Arguments: phonebook_id The phonebook identifier | |
604 command_id Identifies the command. | |
605 param Pointer to command-specific information | |
606 | |
607 *******************************************************************************/ | |
608 | |
609 void GI_pb_OK(SHORT phonebook_id, SHORT command_id, void *param) | |
610 { | |
611 trace("GI_pb_OK"); | |
612 | |
613 if (param!=NULL) | |
614 { | |
615 trace_P1("Param is: %d", *((SHORT *)param)); | |
616 } | |
617 } | |
618 | |
619 /******************************************************************************* | |
620 | |
621 $Function: GI_pb_Error | |
622 | |
623 $Description: This function is called if an error was returned while executing the | |
624 requested command. | |
625 | |
626 $Returns: None. | |
627 | |
628 $Arguments: phonebook_id The phonebook identifier | |
629 command_id Identifies the command. | |
630 error_id Identifies the error that occurred. | |
631 | |
632 *******************************************************************************/ | |
633 | |
634 void GI_pb_Error(SHORT phonebook_id, SHORT command_id, SHORT error_id) | |
635 { | |
636 trace("GI_pb_Error"); | |
637 trace_P2("***ERROR*** - command %d, error %d", command_id, error_id); | |
638 | |
639 return; | |
640 } | |
641 | |
642 | |
643 /******************************************************************************* | |
644 | |
645 $Function: GI_pb_MemAlloc | |
646 | |
647 $Description: Dynamically allocates memory for the phonebook. | |
648 | |
649 $Returns: The address of the block of allocated memory, or NULL if failed. | |
650 | |
651 $Arguments: size - Amount of memory to be allocated in bytes | |
652 | |
653 *******************************************************************************/ | |
654 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar | |
655 // Description: MFW memory size variable changed from U16 -> U32 | |
656 // Solution: The use of variable U16 has been replaced with U32 | |
657 | |
658 UBYTE *GI_pb_MemAlloc(U32 size) | |
659 { | |
660 return mfwAlloc((U32)size); | |
661 } | |
662 | |
663 | |
664 /******************************************************************************* | |
665 | |
666 $Function: GI_pb_MemFree | |
667 | |
668 $Description: Frees dynamically allocated memory. | |
669 | |
670 $Returns: None | |
671 | |
672 $Arguments: mem - Pointer to a block of allocated memory | |
673 size - Size of the block | |
674 | |
675 *******************************************************************************/ | |
676 // Dec 22, 2004 REF: CRR MFW-SPR-27847 xnkulkar | |
677 // Description: MFW memory size variable changed from U16 -> U32 | |
678 // Solution: The use of variable U16 has been replaced with U32 | |
679 | |
680 void GI_pb_MemFree(UBYTE *mem, U32 size) | |
681 { | |
682 mfwFree(mem, (U32)size); | |
683 return; | |
684 } | |
685 | |
686 | |
687 /******************************************************************************* | |
688 | |
689 $Function: GI_pb_Match | |
690 | |
691 $Description: This function allows the user to specify the way in which entries are | |
692 matched during searching. This provides the capability of searching | |
693 languages with non-Latin alphabets, or searching through special user | |
694 fields. | |
695 This function attempts a match between two records based on the | |
696 field appropriate for the index list, specified in index_type. It returns | |
697 a value indicating whether there is no match (MATCH_NONE), | |
698 a partial match (MAX_START), or an exact match (MATCH_EXACT). | |
699 Note that the contents of the records themselves should not be altered | |
700 by this function. The sole result should be a return value that specifies | |
701 how the first record matches the second. If it is preferred that the | |
702 default matching routine is used (i.e match from the start for alpha | |
703 tags, match from the end for phone numbers) then MATCH_DEFAULT | |
704 should be returned. | |
705 | |
706 $Returns: MATCH_DEFAULT, MATCH_EXACT, MATCH_START or MATCH_NONE | |
707 | |
708 $Arguments: record1 The first record to be compared | |
709 record2 The second record to be compared | |
710 index_type Indicator of the field which is to be compared | |
711 | |
712 *******************************************************************************/ | |
713 | |
714 T_PB_MATCH GI_pb_Match(T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type) | |
715 { | |
716 return MATCH_DEFAULT; | |
717 } | |
718 | |
719 | |
720 /******************************************************************************* | |
721 | |
722 $Function: GI_pb_Compare | |
723 | |
724 $Description: This function allows the user to specify the way in which entries are | |
725 compared during sorting. This provides the capability of sorting languages | |
726 with non-Latin alphabets, or sorting to alternative orders (for example, | |
727 reverse alphabetical). | |
728 This function compares two records based on the field appropriate for the | |
729 index list, specified in index_type. | |
730 It returns a value indicating whether the first record should come before | |
731 or after the second. | |
732 Note that the contents of the records themselves should not be altered by | |
733 this function. The sole result should be a return value that specifies | |
734 whether or not the positions of the records should be swapped. If it | |
735 is preferred that the default comparison routine is used (e.g.Latin | |
736 alphabetical ascending) then COMPARE_DEFAULT should be returned. | |
737 | |
738 | |
739 $Returns: COMPARE_DEFAULT No comparison made - use the default comparison method | |
740 COMPARE_FIRSTBEFORE The first record should come before the second record | |
741 COMPARE_FIRSTAFTER The first record should come after the second record | |
742 | |
743 $Arguments: record1 The first record to be compared | |
744 record2 The second record to be compared | |
745 index_type Index list to use | |
746 | |
747 *******************************************************************************/ | |
748 | |
749 T_PB_COMPARE GI_pb_Compare (T_PB_RECORD *record1,T_PB_RECORD *record2, T_PB_INDEX index_type) | |
750 { | |
751 return COMPARE_DEFAULT; | |
752 } | |
753 | |
754 | |
755 /******************************************************************************* | |
756 | |
757 $Function: GI_pb_GetTable | |
758 | |
759 $Description: If fields other than name and number are required, then index tables | |
760 must be provided for each field. This function is called when access | |
761 to an index table is required for an unknown index type. | |
762 | |
763 The array provided must be a user-allocated array of type SHORT, | |
764 records_max in size, e.g. | |
765 | |
766 static SHORT user_table[RECORDS_MAX]; | |
767 return user_table; | |
768 | |
769 $Returns: A pointer to an array of SHORTs records_max in size. | |
770 | |
771 $Arguments: index_type Index list to use | |
772 | |
773 *******************************************************************************/ | |
774 | |
775 SHORT *GI_pb_GetTable (T_PB_INDEX index_type) | |
776 { | |
777 SHORT *user_table = NULL; /*DUMMY IMPLEMENTATION*/ | |
778 return user_table; | |
779 } | |
780 | |
781 | |
782 /******************************************************************************* | |
783 | |
784 $Function: GI_alpha_AlphaToAscii | |
785 | |
786 $Description: Convert an alpha tag to an ascii string | |
787 | |
788 $Returns: None | |
789 | |
790 $Arguments: ascii The ascii string | |
791 alpha The alpha tag | |
792 max_len The maximum length of the resulting string | |
793 | |
794 *******************************************************************************/ | |
795 | |
796 void GI_alpha_AlphaToAscii(T_MFW_PHB_TEXT *ascii, T_PB_ALPHA *alpha, SHORT max_len) | |
797 { | |
798 SHORT asciiIndex; | |
799 SHORT alphaIndex; | |
800 | |
801 /* Unicode entry - swap the low and high bytes, add in 0x80 at start*/ | |
802 | |
803 ascii->dcs = alpha->dcs; | |
804 | |
805 if (alpha->dcs == MFW_DCS_UCS2) | |
806 { | |
807 ascii->data[0] = 0x80; | |
808 asciiIndex = 1; | |
809 alphaIndex = 0; | |
810 | |
811 while (alphaIndex<alpha->length && asciiIndex<max_len) | |
812 { | |
813 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex]>>8); | |
814 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex] & 0xFF); | |
815 alphaIndex++; | |
816 } | |
817 | |
818 /* Put two NULLs at the end, if there is space */ | |
819 | |
820 if (asciiIndex<max_len) | |
821 ascii->data[asciiIndex++] = NULL; | |
822 if (asciiIndex<max_len) | |
823 ascii->data[asciiIndex] = NULL; | |
824 | |
825 ascii->len = asciiIndex; | |
826 } | |
827 | |
828 /* Ascii entry - convert from unicode */ | |
829 | |
830 else | |
831 { | |
832 asciiIndex = 0; | |
833 alphaIndex = 0; | |
834 | |
835 while (alphaIndex<alpha->length && asciiIndex<max_len) | |
836 { | |
837 ascii->data[asciiIndex++] = (char) (alpha->data[alphaIndex++]); | |
838 } | |
839 | |
840 /* Put a NULL at the end, if there is space */ | |
841 | |
842 if (asciiIndex<max_len) | |
843 ascii->data[asciiIndex] = NULL; | |
844 | |
845 ascii->len = asciiIndex; | |
846 } | |
847 | |
848 return; | |
849 } | |
850 | |
851 | |
852 /******************************************************************************* | |
853 | |
854 $Function: GI_alpha_AsciiToAlpha | |
855 | |
856 $Description: Convert an ascii string to an alpha tag | |
857 | |
858 $Returns: None | |
859 | |
860 $Arguments: alpha The alpha tag | |
861 ascii The ascii string | |
862 max_len The maximum length of the resulting string | |
863 | |
864 *******************************************************************************/ | |
865 | |
866 void GI_alpha_AsciiToAlpha(T_PB_ALPHA *alpha, T_MFW_PHB_TEXT *ascii, SHORT max_len) | |
867 { | |
868 SHORT asciiIndex; | |
869 SHORT alphaIndex; | |
870 | |
871 alpha->dcs = ascii->dcs; | |
872 | |
873 /* Unicode entry - swap the low and high bytes, ignore first '0x80' character */ | |
874 | |
875 if (ascii->dcs == MFW_DCS_UCS2) | |
876 { | |
877 asciiIndex = 1; | |
878 alphaIndex = 0; | |
879 | |
880 while (asciiIndex<ascii->len && alphaIndex<max_len) | |
881 { | |
882 alpha->data[alphaIndex++] = (USHORT) ((ascii->data[asciiIndex++]<<8) | ascii->data[asciiIndex++]); | |
883 } | |
884 | |
885 /* Put a NULL at the end, if there is space */ | |
886 | |
887 if (alphaIndex<max_len) | |
888 alpha->data[alphaIndex] = NULL; | |
889 } | |
890 | |
891 /* Ascii entry - convert to unicode */ | |
892 | |
893 else | |
894 { | |
895 asciiIndex = 0; | |
896 alphaIndex = 0; | |
897 | |
898 while (asciiIndex<ascii->len && alphaIndex<max_len) | |
899 { | |
900 alpha->data[alphaIndex++] = (USHORT)ascii->data[asciiIndex++]; | |
901 } | |
902 | |
903 /* Put a NULL at the end, if there is space */ | |
904 | |
905 if (alphaIndex<max_len) | |
906 alpha->data[alphaIndex] = NULL; | |
907 } | |
908 | |
909 alpha->length = alphaIndex; | |
910 | |
911 return; | |
912 } | |
913 | |
914 | |
915 /******************************************************************************* | |
916 | |
917 $Function: GI_index_Convert | |
918 | |
919 $Description: Convert indexing types from MFW to ATB. | |
920 | |
921 $Returns: The ATB indexing type | |
922 | |
923 $Arguments: mode The MFW sort mode | |
924 | |
925 *******************************************************************************/ | |
926 | |
927 T_PB_INDEX GI_index_Convert(UBYTE mode) | |
928 { | |
929 T_PB_INDEX index_type; | |
930 | |
931 switch(mode) | |
932 { | |
933 case MFW_PHB_ALPHA: | |
934 index_type = INDEX_NAME; | |
935 break; | |
936 case MFW_PHB_NUMBER: | |
937 index_type = INDEX_NUMBER; | |
938 break; | |
939 case MFW_PHB_INDEX: | |
940 index_type = INDEX_PHYSICAL; /* NOTE - may not work quite as intended */ | |
941 break; | |
942 case MFW_PHB_PHYSICAL: | |
943 index_type = INDEX_PHYSICAL; | |
944 break; | |
945 } | |
946 | |
947 return index_type; | |
948 } |