44 #include <string.h> |
44 #include <string.h> |
45 #include "common.h" |
45 #include "common.h" |
46 #include "bots.h" |
46 #include "bots.h" |
47 #include "stringtable.h" |
47 #include "stringtable.h" |
48 |
48 |
|
49 // ============================================================================ |
|
50 // Initializes the string table |
49 void InitStringTable() { |
51 void InitStringTable() { |
50 // Zero out everything first. |
52 // Zero out everything first. |
51 for (unsigned int a = 0; a < MAX_LIST_STRINGS; a++) |
53 for (unsigned int a = 0; a < MAX_LIST_STRINGS; a++) |
52 for (unsigned int b = 0; b < MAX_STRING_LENGTH; b++) |
54 for (unsigned int b = 0; b < MAX_STRING_LENGTH; b++) |
53 g_StringTable[a][b] = 0; |
55 g_StringTable[a][b] = 0; |
54 } |
56 } |
55 |
57 |
|
58 // ============================================================================ |
|
59 // Potentially adds a string to the table and returns the index of it. |
56 unsigned int PushToStringTable (char* s) { |
60 unsigned int PushToStringTable (char* s) { |
57 // Find a free slot in the table. |
61 // Find a free slot in the table. |
58 unsigned int a; |
62 unsigned int a; |
59 for (a = 0; a < MAX_LIST_STRINGS; a++) { |
63 for (a = 0; a < MAX_LIST_STRINGS; a++) { |
|
64 // String is already in the table, thus return it. |
60 if (!strcmp (s, g_StringTable[a])) |
65 if (!strcmp (s, g_StringTable[a])) |
61 return a; |
66 return a; |
62 |
67 |
63 // String is empty, thus it's free. |
68 // String is empty, thus it's free. |
64 if (!strlen (g_StringTable[a])) |
69 if (!strlen (g_StringTable[a])) |
79 g_StringTable[a][len] = 0; |
84 g_StringTable[a][len] = 0; |
80 |
85 |
81 return a; |
86 return a; |
82 } |
87 } |
83 |
88 |
|
89 // ============================================================================ |
|
90 // Counts the amount of strings in the table. |
84 unsigned int CountStringTable () { |
91 unsigned int CountStringTable () { |
85 unsigned int count = 0; |
92 unsigned int count = 0; |
86 for (unsigned int a = 0; a < MAX_LIST_STRINGS; a++) { |
93 for (unsigned int a = 0; a < MAX_LIST_STRINGS; a++) { |
87 if (!strlen (g_StringTable[a])) |
94 if (!strlen (g_StringTable[a])) |
88 break; |
95 break; |