~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/tools/genrb/rblist.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*******************************************************************************
3
 
*
4
 
*   Copyright (C) 1998-2000, International Business Machines
5
 
*   Corporation and others.  All Rights Reserved.
6
 
*
7
 
*******************************************************************************
8
 
*
9
 
* File rblist.c
10
 
*
11
 
* Modification History:
12
 
*
13
 
*   Date        Name        Description
14
 
*   06/01/99    stephen     Creation.
15
 
*******************************************************************************
16
 
*/
17
 
 
18
 
#include "rblist.h"
19
 
#include "ustr.h"
20
 
#include "unicode/ustring.h"
21
 
#include "cmemory.h"
22
 
#include "cstring.h"
23
 
 
24
 
 
25
 
struct SRBItem*
26
 
make_rbitem(const UChar *tag,
27
 
        const struct SList *data,
28
 
        UErrorCode *status)
29
 
{
30
 
  struct SRBItem *item;
31
 
  char *s;
32
 
 
33
 
  if(U_FAILURE(*status)) return 0;
34
 
 
35
 
  item = (struct SRBItem*) uprv_malloc(sizeof(struct SRBItem));
36
 
  if(item == 0) {
37
 
    *status = U_MEMORY_ALLOCATION_ERROR;
38
 
    return 0;
39
 
  }
40
 
 
41
 
  /* s = (UChar*) uprv_malloc(sizeof(UChar) * (u_strlen(tag) + 1)); */
42
 
  s = (char*) uprv_malloc(sizeof(char) * (u_strlen(tag) + 1));
43
 
  if(s == 0) {
44
 
    *status = U_MEMORY_ALLOCATION_ERROR;
45
 
    return 0;
46
 
  }
47
 
  u_UCharsToChars(tag, s, u_strlen(tag)+1);
48
 
  /* u_strcpy(s, tag); */
49
 
 
50
 
  item->fTag = s;
51
 
  item->fData = (struct SList*) data;
52
 
  item->fNext = NULL;
53
 
 
54
 
  return item;
55
 
}
56
 
 
57
 
struct SRBItemList*
58
 
rblist_open(UErrorCode *status)
59
 
{
60
 
  struct SRBItemList *list;
61
 
 
62
 
  if(U_FAILURE(*status)) return 0;
63
 
 
64
 
  list = (struct SRBItemList*) uprv_malloc(sizeof(struct SRBItemList));
65
 
  if(list == 0) {
66
 
    *status = U_MEMORY_ALLOCATION_ERROR;
67
 
    return 0;
68
 
  }
69
 
 
70
 
  list->fLocale = 0;
71
 
  list->fFirst = NULL;
72
 
 
73
 
/*  list->fData = 0; */
74
 
  list->fCount = 0;
75
 
  list->fCapacity = 32;
76
 
  list->fKeys = (char *) uprv_malloc(sizeof(char) * 65532);
77
 
  list->fKeyPoint = 0;
78
 
 
79
 
  return list;
80
 
}
81
 
 
82
 
void rblist_close(struct SRBItemList *list,
83
 
         UErrorCode *status)
84
 
{
85
 
/*  int32_t i; */
86
 
  struct SRBItem *current;
87
 
  struct SRBItem *prev = NULL;
88
 
 
89
 
  if(U_FAILURE(*status)) return;
90
 
  current = list->fFirst;
91
 
  /* deallocate each list */
92
 
/*  for(i = 0; i < list->fCount; ++i) { */
93
 
  while(current != NULL) {
94
 
 
95
 
/*    switch(list->fData[i]->fData->fType) { */
96
 
    switch(current->fData->fType) {
97
 
        case eStringList:
98
 
          strlist_close(current->fData, status);
99
 
          break;
100
 
 
101
 
        case eStringList2d:
102
 
          strlist2d_close(current->fData, status);
103
 
          break;
104
 
 
105
 
        case eTaggedList:
106
 
          taglist_close(current->fData, status);
107
 
          break;
108
 
 
109
 
        case eEmpty:
110
 
          break;
111
 
    }
112
 
    prev = current;
113
 
    current=current->fNext;
114
 
    uprv_free(prev);
115
 
  }
116
 
/*  uprv_free(list->fData); */
117
 
  uprv_free(list->fLocale);
118
 
  uprv_free(list->fKeys);
119
 
 
120
 
  uprv_free(list);
121
 
}
122
 
 
123
 
void rblist_setlocale(struct SRBItemList *list,
124
 
              const UChar *locale,
125
 
              UErrorCode *status)
126
 
{
127
 
  if(U_FAILURE(*status)) return;
128
 
 
129
 
  /* Allocate enough space */
130
 
  list->fLocale = (UChar*) uprv_realloc(list->fLocale,
131
 
                       sizeof(UChar) * (u_strlen(locale) + 1));
132
 
  if(list->fLocale == 0) {
133
 
    *status = U_MEMORY_ALLOCATION_ERROR;
134
 
    return;
135
 
  }
136
 
 
137
 
  u_strcpy(list->fLocale, locale);
138
 
}
139
 
 
140
 
void rblist_add(struct SRBItemList *list,
141
 
        struct SRBItem *s,
142
 
        UErrorCode *status)
143
 
{
144
 
/*  int32_t index; */
145
 
 
146
 
    struct SRBItem *current;
147
 
    struct SRBItem *prev = NULL;
148
 
 
149
 
    if(U_FAILURE(*status)) return;
150
 
    /* here we need to traverse the list */
151
 
 
152
 
    ++(list->fCount);
153
 
 
154
 
    s->fStrKey = list->fKeyPoint;
155
 
 
156
 
    uprv_strcpy((list->fKeys)+list->fKeyPoint, s->fTag);
157
 
 
158
 
    list->fKeyPoint += uprv_strlen(s->fTag)+1;
159
 
 
160
 
 
161
 
 
162
 
    /* is list still empty? */
163
 
    if(list->fFirst == NULL) {
164
 
        list->fFirst = s;
165
 
        s->fNext = NULL;
166
 
        return;
167
 
    } else {
168
 
        current = list->fFirst;
169
 
    }
170
 
 
171
 
    while(current != NULL) {
172
 
        if(uprv_strcmp(current->fTag, s->fTag)<0) {
173
 
            prev = current;
174
 
            current = current->fNext;
175
 
        } else { /*we're either in front of list, or in middle*/
176
 
            if(prev == NULL) { /*front of the list*/
177
 
                list->fFirst = s;
178
 
            } else { /*middle of the list*/
179
 
                prev->fNext = s;
180
 
            }
181
 
            s->fNext = current;
182
 
            return;
183
 
        }
184
 
    }
185
 
 
186
 
    /* end of list */
187
 
    prev->fNext = s;
188
 
    s->fNext = NULL;
189
 
}
190