================= String_Alloc ================= */
| 1297 | ================= |
| 1298 | */ |
| 1299 | const char *String_Alloc(const char *p) |
| 1300 | { |
| 1301 | int len; |
| 1302 | unsigned hash; |
| 1303 | stringDef_t *str, *last; |
| 1304 | static const char *staticNULL = ""; |
| 1305 | |
| 1306 | if (p == NULL) |
| 1307 | { |
| 1308 | return NULL; |
| 1309 | } |
| 1310 | |
| 1311 | if (*p == 0) |
| 1312 | { |
| 1313 | return staticNULL; |
| 1314 | } |
| 1315 | |
| 1316 | hash = hashForString(p); |
| 1317 | |
| 1318 | str = strHandle[hash]; |
| 1319 | while (str) |
| 1320 | { |
| 1321 | if (strcmp(p, str->str) == 0) |
| 1322 | { |
| 1323 | return str->str; |
| 1324 | } |
| 1325 | str = str->next; |
| 1326 | } |
| 1327 | |
| 1328 | len = strlen(p); |
| 1329 | if (len + strPoolIndex + 1 < STRING_POOL_SIZE) |
| 1330 | { |
| 1331 | int ph = strPoolIndex; |
| 1332 | strcpy(&strPool[strPoolIndex], p); |
| 1333 | strPoolIndex += len + 1; |
| 1334 | |
| 1335 | str = strHandle[hash]; |
| 1336 | last = str; |
| 1337 | while (last && last->next) |
| 1338 | { |
| 1339 | last = last->next; |
| 1340 | } |
| 1341 | |
| 1342 | str = (stringDef_s *) UI_Alloc( sizeof(stringDef_t)); |
| 1343 | str->next = NULL; |
| 1344 | str->str = &strPool[ph]; |
| 1345 | if (last) |
| 1346 | { |
| 1347 | last->next = str; |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| 1351 | strHandle[hash] = str; |
| 1352 | } |
| 1353 | |
| 1354 | return &strPool[ph]; |
| 1355 | } |
| 1356 | else |
no test coverage detected