Remove carriage-return chars *ONLY*.
[mesa.git] / src / mesa / shader / slang / slang_utility.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file slang_utility.c
27 * slang utilities
28 * \author Michal Krol
29 */
30
31 #include "imports.h"
32 #include "slang_utility.h"
33
34 char *slang_string_concat (char *dst, const char *src)
35 {
36 return _mesa_strcpy (dst + _mesa_strlen (dst), src);
37 }
38
39 /* slang_atom_pool */
40
41 void slang_atom_pool_construct (slang_atom_pool *pool)
42 {
43 GLuint i;
44
45 for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)
46 pool->entries[i] = NULL;
47 }
48
49 void slang_atom_pool_destruct (slang_atom_pool *pool)
50 {
51 GLuint i;
52
53 for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)
54 {
55 slang_atom_entry *entry;
56
57 entry = pool->entries[i];
58 while (entry != NULL)
59 {
60 slang_atom_entry *next;
61
62 next = entry->next;
63 slang_alloc_free (entry->id);
64 slang_alloc_free (entry);
65 entry = next;
66 }
67 }
68 }
69
70 slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)
71 {
72 GLuint hash;
73 const char *p = id;
74 slang_atom_entry **entry;
75
76 hash = 0;
77 while (*p != '\0')
78 {
79 GLuint g;
80
81 hash = (hash << 4) + (GLuint) *p++;
82 g = hash & 0xf0000000;
83 if (g != 0)
84 hash ^= g >> 24;
85 hash &= ~g;
86 }
87 hash %= SLANG_ATOM_POOL_SIZE;
88
89 entry = &pool->entries[hash];
90 while (*entry != NULL)
91 {
92 if (slang_string_compare ((**entry).id, id) == 0)
93 return (slang_atom) (**entry).id;
94 entry = &(**entry).next;
95 }
96
97 *entry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));
98 if (*entry == NULL)
99 return SLANG_ATOM_NULL;
100
101 (**entry).next = NULL;
102 (**entry).id = slang_string_duplicate (id);
103 if ((**entry).id == NULL)
104 return SLANG_ATOM_NULL;
105 return (slang_atom) (**entry).id;
106 }
107
108 const char *slang_atom_pool_id (slang_atom_pool *pool, slang_atom atom)
109 {
110 return (const char *) atom;
111 }
112