56 } |
56 } |
57 |
57 |
58 // ============================================================================ |
58 // ============================================================================ |
59 // Potentially adds a string to the table and returns the index of it. |
59 // Potentially adds a string to the table and returns the index of it. |
60 unsigned int PushToStringTable (char* s) { |
60 unsigned int PushToStringTable (char* s) { |
|
61 // Must not be too long. |
|
62 if (strlen (s) >= MAX_STRING_LENGTH) |
|
63 error ("string `%s` too long (%d characters max)\n", s, strlen (s)); |
|
64 |
61 // Find a free slot in the table. |
65 // Find a free slot in the table. |
62 unsigned int a; |
66 unsigned int a; |
63 for (a = 0; a < MAX_LIST_STRINGS; a++) { |
67 for (a = 0; a < MAX_LIST_STRINGS; a++) { |
64 // String is already in the table, thus return it. |
68 // String is already in the table, thus return it. |
65 if (!strcmp (s, g_StringTable[a])) |
69 if (!strcmp (s, g_StringTable[a])) |
70 break; |
74 break; |
71 } |
75 } |
72 |
76 |
73 // no free slots! |
77 // no free slots! |
74 if (a == MAX_LIST_STRINGS) |
78 if (a == MAX_LIST_STRINGS) |
75 error ("too many strings defined!"); |
79 error ("too many strings defined!\n"); |
76 |
80 |
77 // Determine the length |
81 // Determine the length |
78 size_t l1 = strlen (s); |
82 size_t l1 = strlen (s); |
79 size_t l2 = MAX_LIST_STRINGS - 1; |
83 size_t l2 = MAX_LIST_STRINGS - 1; |
80 size_t len = (l1 < l2) ? l1 : l2; |
84 size_t len = (l1 < l2) ? l1 : l2; |