1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2001-03-21 23:22:16 +00:00
|
|
|
* Copyright (C) 1998-2000, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File rblist.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 06/01/99 stephen Creation.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rblist.h"
|
|
|
|
#include "ustr.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "cstring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2001-03-21 23:22:16 +00:00
|
|
|
struct SRBItem*
|
|
|
|
make_rbitem(const UChar *tag,
|
|
|
|
const struct SList *data,
|
2000-05-15 18:39:17 +00:00
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
struct SRBItem *item;
|
2000-05-15 18:39:17 +00:00
|
|
|
char *s;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
item = (struct SRBItem*) uprv_malloc(sizeof(struct SRBItem));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(item == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
//s = (UChar*) uprv_malloc(sizeof(UChar) * (u_strlen(tag) + 1));
|
|
|
|
s = (char*) uprv_malloc(sizeof(char) * (u_strlen(tag) + 1));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(s == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
u_UCharsToChars(tag, s, u_strlen(tag)+1);
|
|
|
|
//u_strcpy(s, tag);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
item->fTag = s;
|
|
|
|
item->fData = (struct SList*) data;
|
2000-05-15 18:39:17 +00:00
|
|
|
item->fNext = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SRBItemList*
|
|
|
|
rblist_open(UErrorCode *status)
|
|
|
|
{
|
|
|
|
struct SRBItemList *list;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
list = (struct SRBItemList*) uprv_malloc(sizeof(struct SRBItemList));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(list == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->fLocale = 0;
|
2000-05-15 18:39:17 +00:00
|
|
|
list->fFirst = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-21 23:22:16 +00:00
|
|
|
// list->fData = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
list->fCount = 0;
|
|
|
|
list->fCapacity = 32;
|
2000-05-15 18:39:17 +00:00
|
|
|
list->fKeys = (char *) uprv_malloc(sizeof(char) * 65532);
|
|
|
|
list->fKeyPoint = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rblist_close(struct SRBItemList *list,
|
2000-05-15 18:39:17 +00:00
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-15 18:39:17 +00:00
|
|
|
// int32_t i;
|
|
|
|
struct SRBItem *current;
|
|
|
|
struct SRBItem *prev = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
2000-05-15 18:39:17 +00:00
|
|
|
current = list->fFirst;
|
1999-08-16 21:50:52 +00:00
|
|
|
/* deallocate each list */
|
2000-05-15 18:39:17 +00:00
|
|
|
// for(i = 0; i < list->fCount; ++i) {
|
2001-03-21 23:22:16 +00:00
|
|
|
while(current != NULL) {
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
// switch(list->fData[i]->fData->fType) {
|
|
|
|
switch(current->fData->fType) {
|
|
|
|
case eStringList:
|
|
|
|
strlist_close(current->fData, status);
|
|
|
|
break;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
case eStringList2d:
|
|
|
|
strlist2d_close(current->fData, status);
|
|
|
|
break;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
case eTaggedList:
|
|
|
|
taglist_close(current->fData, status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
case eEmpty:
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
prev = current;
|
|
|
|
current=current->fNext;
|
|
|
|
uprv_free(prev);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
// uprv_free(list->fData);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_free(list->fLocale);
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_free(list->fKeys);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_free(list);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 23:22:16 +00:00
|
|
|
void rblist_setlocale(struct SRBItemList *list,
|
|
|
|
const UChar *locale,
|
2000-05-15 18:39:17 +00:00
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Allocate enough space */
|
2001-03-21 23:22:16 +00:00
|
|
|
list->fLocale = (UChar*) uprv_realloc(list->fLocale,
|
2000-05-15 18:39:17 +00:00
|
|
|
sizeof(UChar) * (u_strlen(locale) + 1));
|
1999-08-16 21:50:52 +00:00
|
|
|
if(list->fLocale == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_strcpy(list->fLocale, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rblist_add(struct SRBItemList *list,
|
2000-05-15 18:39:17 +00:00
|
|
|
struct SRBItem *s,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-15 18:39:17 +00:00
|
|
|
// int32_t index;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
struct SRBItem *current;
|
|
|
|
struct SRBItem *prev = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
2001-03-21 23:22:16 +00:00
|
|
|
/* here we need to traverse the list */
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
++(list->fCount);
|
|
|
|
|
|
|
|
s->fStrKey = list->fKeyPoint;
|
|
|
|
|
|
|
|
uprv_strcpy((list->fKeys)+list->fKeyPoint, s->fTag);
|
|
|
|
|
|
|
|
list->fKeyPoint += uprv_strlen(s->fTag)+1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* is list still empty? */
|
|
|
|
if(list->fFirst == NULL) {
|
|
|
|
list->fFirst = s;
|
|
|
|
s->fNext = NULL;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
current = list->fFirst;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(current != NULL) {
|
|
|
|
if(uprv_strcmp(current->fTag, s->fTag)<0) {
|
|
|
|
prev = current;
|
|
|
|
current = current->fNext;
|
|
|
|
} else { /*we're either in front of list, or in middle*/
|
|
|
|
if(prev == NULL) { /*front of the list*/
|
|
|
|
list->fFirst = s;
|
|
|
|
} else { /*middle of the list*/
|
|
|
|
prev->fNext = s;
|
|
|
|
}
|
|
|
|
s->fNext = current;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of list */
|
|
|
|
prev->fNext = s;
|
|
|
|
s->fNext = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|