experimental changes to topmenu api -- drawing/displaying is now properly abstracted
3 * =============================================================================
4 * SourceMod Sample Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
38 unsigned int obj_index;
42 int _SortObjectNamesDescending(const void *ptr1, const void *ptr2);
43 unsigned int strncopy(char *dest, const char *src, size_t count);
44 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
46 TopMenu::TopMenu(ITopMenuObjectCallbacks *callbacks)
53 if (playerhelpers->IsServerActivated())
55 CreatePlayers(playerhelpers->GetMaxClients());
61 /* Delete all categories */
62 while (m_Categories.size())
64 RemoveFromMenu(m_Categories[0]->obj->object_id);
67 /* Remove all objects */
68 for (size_t i = 0; i < m_Objects.size(); i++)
70 assert(m_Objects[i]->is_free == true);
74 m_pTitle->OnTopMenuObjectRemoved(this, 0);
76 /* Delete all cached config entries */
77 for (size_t i = 0; i < m_Config.cats.size(); i++)
79 delete m_Config.cats[i];
83 for (size_t i = 0; i <= (size_t)m_max_clients; i++)
85 TearDownClient(&m_clients[i]);
90 void TopMenu::OnClientConnected(int client)
92 if (m_clients == NULL)
97 topmenu_player_t *player = &m_clients[client];
98 TearDownClient(player);
101 void TopMenu::OnClientDisconnected(int client)
103 if (m_clients == NULL)
108 topmenu_player_t *player = &m_clients[client];
109 TearDownClient(player);
112 void TopMenu::OnServerActivated(int max_clients)
114 if (m_clients == NULL)
116 CreatePlayers(max_clients);
120 unsigned int TopMenu::AddToMenu(const char *name,
121 TopMenuObjectType type,
122 ITopMenuObjectCallbacks *callbacks,
123 IdentityToken_t *owner,
129 if (type == TopMenuObject_Category && parent != 0)
133 else if (type == TopMenuObject_Item && parent == 0)
137 else if (m_ObjLookup.retrieve(name) != NULL)
141 else if (type != TopMenuObject_Item && type != TopMenuObject_Category)
146 /* If we're adding an item, make sure the parent is valid,
147 * and that the parent is a category.
149 topmenu_object_t *parent_obj = NULL;
150 topmenu_category_t *parent_cat = NULL;
151 if (type == TopMenuObject_Item)
153 /* Check parent index. Note it will be >= 1 here. */
154 if (parent > m_Objects.size() || m_Objects[parent - 1]->is_free)
158 parent_obj = m_Objects[parent - 1];
160 /* Find an equivalent pointer in the category array. */
161 for (size_t i = 0; i < m_Categories.size(); i++)
163 if (m_Categories[i]->obj == parent_obj)
165 parent_cat = m_Categories[i];
170 /* If none was found, leave. */
171 if (parent_cat == NULL)
177 /* Re-use an old object pointer if we can. */
178 topmenu_object_t *obj = NULL;
179 for (size_t i = 0; i < m_Objects.size(); i++)
181 if (m_Objects[i]->is_free == true)
188 /* Otherwise, allocate a new one. */
191 obj = new topmenu_object_t;
192 obj->object_id = ((unsigned int)m_Objects.size()) + 1;
193 m_Objects.push_back(obj);
196 /* Initialize the object's properties. */
197 obj->callbacks = callbacks;
201 obj->is_free = false;
202 obj->parent = parent_obj;
203 strncopy(obj->name, name, sizeof(obj->name));
204 strncopy(obj->cmdname, cmdname ? cmdname : "", sizeof(obj->cmdname));
206 if (obj->type == TopMenuObject_Category)
208 /* Create a new category entry */
209 topmenu_category_t *cat = new topmenu_category_t;
211 cat->reorder = false;
214 /* Add it, then update our serial change number. */
215 m_Categories.push_back(cat);
218 /* Updating sorting info */
219 m_bCatsNeedResort = true;
221 else if (obj->type == TopMenuObject_Item)
223 /* Update the category, mark it as needing changes */
224 parent_cat->obj_list.push_back(obj);
225 parent_cat->reorder = true;
226 parent_cat->serial++;
228 /* If the category just went from 0 to 1 items, mark it as
229 * changed, so clients get the category drawn.
231 if (parent_cat->obj_list.size() == 1)
237 m_ObjLookup.insert(name, obj);
239 return obj->object_id;
242 void TopMenu::RemoveFromMenu(unsigned int object_id)
245 || object_id > m_Objects.size()
246 || m_Objects[object_id - 1]->is_free)
251 topmenu_object_t *obj = m_Objects[object_id - 1];
253 m_ObjLookup.remove(obj->name);
255 if (obj->type == TopMenuObject_Category)
257 /* Find it in the category list. */
258 for (size_t i = 0; i < m_Categories.size(); i++)
260 if (m_Categories[i]->obj == obj)
262 /* Mark all children as removed + free. Note we could
263 * call into RemoveMenuItem() for this, but it'd be very
266 topmenu_category_t *cat = m_Categories[i];
267 for (size_t j = 0; j < m_Categories[i]->obj_list.size(); j++)
269 cat->obj_list[j]->callbacks->OnTopMenuObjectRemoved(this, cat->obj_list[j]->object_id);
270 cat->obj_list[j]->is_free = true;
273 /* Remove the category from the list, then delete it. */
274 m_Categories.erase(m_Categories.iterAt(i));
280 /* Update the root as changed. */
282 m_bCatsNeedResort = true;
284 else if (obj->type == TopMenuObject_Item)
286 /* Find the category this item is in. */
287 topmenu_category_t *parent_cat = NULL;
288 for (size_t i = 0; i < m_Categories.size(); i++)
290 if (m_Categories[i]->obj == obj->parent)
292 parent_cat = m_Categories[i];
297 /* Erase it from the category's lists. */
300 for (size_t i = 0; i < parent_cat->obj_list.size(); i++)
302 if (parent_cat->obj_list[i] == obj)
304 parent_cat->obj_list.erase(parent_cat->obj_list.iterAt(i));
306 /* If this category now has no items, mark root as changed
307 * so clients won't get the category drawn anymore.
309 if (parent_cat->obj_list.size() == 0)
317 /* Update the category as changed. */
318 parent_cat->reorder = true;
319 parent_cat->serial++;
323 /* Finally, mark the object as free. */
326 /* The callbacks pointer is still valid, so fire away! */
327 obj->callbacks->OnTopMenuObjectRemoved(this, object_id);
330 bool TopMenu::DisplayMenu(int client, unsigned int hold_time, TopMenuPosition position)
332 if (m_clients == NULL)
337 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
338 if (!pPlayer->IsInGame())
343 UpdateClientRoot(client, pPlayer);
345 topmenu_player_t *pClient = &m_clients[client];
346 if (pClient->root == NULL)
351 bool return_value = false;
353 if (position == TopMenuPosition_LastCategory &&
354 pClient->last_category < m_Categories.size())
356 return_value = DisplayCategory(client, pClient->last_category, hold_time, true);
358 else if (position == TopMenuPosition_LastRoot)
360 pClient->root->DisplayAtItem(client, hold_time, pClient->last_root_pos);
362 else if (position == TopMenuPosition_Start)
364 pClient->last_position = 0;
365 pClient->last_category = 0;
366 return_value = pClient->root->Display(client, hold_time);
372 bool TopMenu::DisplayCategory(int client, unsigned int category, unsigned int hold_time, bool last_position)
374 UpdateClientCategory(client, category);
376 topmenu_player_t *pClient = &m_clients[client];
377 if (category >= pClient->cat_count
378 || pClient->cats[category].menu == NULL)
383 bool return_value = false;
385 topmenu_player_category_t *player_cat = &(pClient->cats[category]);
387 pClient->last_category = category;
390 return_value = player_cat->menu->DisplayAtItem(client, hold_time, pClient->last_position);
394 return_value = player_cat->menu->Display(client, hold_time);
400 void TopMenu::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page)
402 const char *item_name = menu->GetItemInfo(item, NULL);
408 topmenu_object_t *obj;
409 topmenu_player_t *pClient = &m_clients[client];
410 topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
418 /* We now have the object... what do we do with it? */
419 if (obj->type == TopMenuObject_Category)
421 /* If it's a category, the user wants to view it.. */
422 for (size_t i = 0; i < m_Categories.size(); i++)
424 if (m_Categories[i]->obj == obj)
426 pClient->last_root_pos = item_on_page;
427 DisplayCategory(client, (unsigned int)i, MENU_TIME_FOREVER, false);
434 pClient->last_position = item_on_page;
436 /* Re-check access in case this user had their credentials revoked */
437 if (obj->cmdname[0] != '\0' && !adminsys->CheckAccess(client, obj->cmdname, obj->flags, false))
439 DisplayMenu(client, 0, TopMenuPosition_LastCategory);
443 /* Pass the information on to the callback */
444 obj->callbacks->OnTopMenuSelectOption(this, client, obj->object_id);
448 void TopMenu::OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
450 const char *item_name = menu->GetItemInfo(item, NULL);
456 topmenu_object_t *obj;
457 topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
465 style = obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id);
466 if (style != ITEMDRAW_DEFAULT)
471 if (obj->cmdname[0] == '\0')
476 if (!adminsys->CheckAccess(client, obj->cmdname, obj->flags, false))
478 style = ITEMDRAW_IGNORE;
482 unsigned int TopMenu::OnMenuDisplayItem(IBaseMenu *menu,
486 const ItemDrawInfo &dr)
488 const char *item_name = menu->GetItemInfo(item, NULL);
494 topmenu_object_t *obj;
495 topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
503 /* Ask the object to render the text for this client */
505 obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, renderbuf, sizeof(renderbuf));
507 /* Build the new draw info */
508 ItemDrawInfo new_dr = dr;
509 new_dr.display = renderbuf;
511 /* Man I love the menu API. Ask the panel to draw the item and give the position
512 * back to Core's renderer. This way we don't have to worry about keeping the
513 * render buffer static!
515 return panel->DrawItem(new_dr);
518 void TopMenu::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
520 if (reason == MenuCancel_ExitBack)
522 /* If the client chose exit back, they were on a category menu, and we can
523 * now display the root menu from the last known position.
525 DisplayMenu(client, 0, TopMenuPosition_LastRoot);
529 void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer)
531 topmenu_player_t *pClient = &m_clients[client];
532 IGamePlayer *pPlayer = pGamePlayer ? pGamePlayer : playerhelpers->GetGamePlayer(client);
534 /* Determine if an update is necessary */
535 bool is_update_needed = false;
536 if (pClient->menu_serial != m_SerialNo)
538 is_update_needed = true;
540 else if (pPlayer->GetUserId() != pClient->user_id)
542 is_update_needed = true;
545 /* If no update is needed at the root level, just leave now */
546 if (!is_update_needed)
551 /* First we need to flush the cache... */
552 TearDownClient(pClient);
554 /* Now, rebuild the category list, but don't create menus */
555 if (m_Categories.size() == 0)
557 pClient->cat_count = 0;
558 pClient->cats = NULL;
562 pClient->cat_count = (unsigned int)m_Categories.size();
563 pClient->cats = new topmenu_player_category_t[pClient->cat_count];
564 memset(pClient->cats, 0, sizeof(topmenu_player_category_t) * pClient->cat_count);
567 /* Re-sort the root categories if needed */
568 SortCategoriesIfNeeded();
570 /* Build the root menu */
571 IBaseMenu *root_menu = menus->GetDefaultStyle()->CreateMenu(this, myself->GetIdentity());
573 /* Add the sorted items */
574 for (size_t i = 0; i < m_SortedCats.size(); i++)
576 if (m_Categories[m_SortedCats[i]]->obj_list.size() == 0)
580 root_menu->AppendItem(m_Categories[m_SortedCats[i]]->obj->name, ItemDrawInfo(""));
583 /* Now we need to handle un-sorted items. This is slightly trickier, as we need to
584 * pre-render each category name, and cache those names. Phew!
586 if (m_UnsortedCats.size())
588 obj_by_name_t *item_list = new obj_by_name_t[m_UnsortedCats.size()];
589 for (size_t i = 0; i < m_UnsortedCats.size(); i++)
591 obj_by_name_t *temp_obj = &item_list[i];
592 topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj;
593 obj->callbacks->OnTopMenuDisplayOption(this,
597 sizeof(temp_obj->name));
598 temp_obj->obj_index = m_UnsortedCats[i];
601 /* Sort our temp list */
602 qsort(item_list, m_UnsortedCats.size(), sizeof(obj_by_name_t), _SortObjectNamesDescending);
604 /* Add the new sorted categories */
605 for (size_t i = 0; i < m_UnsortedCats.size(); i++)
607 if (m_Categories[item_list[i].obj_index]->obj_list.size() == 0)
611 root_menu->AppendItem(m_Categories[item_list[i].obj_index]->obj->name, ItemDrawInfo(""));
617 /* Set the menu's title */
619 m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf));
620 root_menu->SetDefaultTitle(renderbuf);
622 /* The client is now fully updated */
623 pClient->root = root_menu;
624 pClient->user_id = pPlayer->GetUserId();
625 pClient->menu_serial = m_SerialNo;
626 pClient->last_position = 0;
627 pClient->last_category = 0;
628 pClient->last_root_pos = 0;
631 void TopMenu::UpdateClientCategory(int client, unsigned int category)
633 /* Update the client's root menu just in case it needs it. This
634 * will validate that we have both a valid client and a valid
635 * category structure for that client.
637 UpdateClientRoot(client);
639 /* Now it's guaranteed that our category tables will be usable */
640 topmenu_player_t *pClient = &m_clients[client];
641 topmenu_category_t *cat = m_Categories[category];
642 topmenu_player_category_t *player_cat = &(pClient->cats[category]);
644 /* Does the category actually need updating? */
645 if (player_cat->serial == cat->serial)
650 /* Destroy any existing menu */
651 if (player_cat->menu)
653 player_cat->menu->Destroy();
654 player_cat->menu = NULL;
657 if (pClient->last_category == category)
659 pClient->last_position = 0;
662 IBaseMenu *cat_menu = menus->GetDefaultStyle()->CreateMenu(this, myself->GetIdentity());
664 /* Categories get an "exit back" button */
665 cat_menu->SetMenuOptionFlags(cat_menu->GetMenuOptionFlags() | MENUFLAG_BUTTON_EXITBACK);
667 /* Re-sort the category if needed */
668 SortCategoryIfNeeded(category);
670 /* Build the menu with the sorted items first */
671 for (size_t i = 0; i < cat->sorted.size(); i++)
673 cat_menu->AppendItem(cat->sorted[i]->name, ItemDrawInfo(""));
676 /* Now handle unsorted items */
677 if (cat->unsorted.size())
679 /* Build a list of the item names */
680 obj_by_name_t *item_list = new obj_by_name_t[cat->unsorted.size()];
681 for (size_t i = 0; i < cat->unsorted.size(); i++)
683 obj_by_name_t *item = &item_list[i];
684 topmenu_object_t *obj = cat->unsorted[i];
685 obj->callbacks->OnTopMenuDisplayOption(this,
690 item->obj_index = (unsigned int)i;
694 qsort(item_list, cat->unsorted.size(), sizeof(obj_by_name_t), _SortObjectNamesDescending);
696 /* Add to the menu */
697 for (size_t i = 0; i < cat->unsorted.size(); i++)
699 cat_menu->AppendItem(cat->unsorted[item_list[i].obj_index]->name, ItemDrawInfo(""));
705 /* Set the menu's title */
707 cat->obj->callbacks->OnTopMenuDisplayTitle(this,
712 cat_menu->SetDefaultTitle(renderbuf);
715 player_cat->menu = cat_menu;
716 player_cat->serial = cat->serial;
719 void TopMenu::SortCategoryIfNeeded(unsigned int category)
721 topmenu_category_t *cat = m_Categories[category];
728 cat->unsorted.clear();
730 if (cat->obj_list.size() == 0)
732 cat->reorder = false;
736 CVector<unsigned int> to_sort;
737 for (size_t i = 0; i < cat->obj_list.size(); i++)
739 to_sort.push_back(i);
742 /* Find a matching category in the configs */
743 config_category_t *config_cat = NULL;
744 for (size_t i = 0; i < m_Config.cats.size(); i++)
746 if (strcmp(m_Config.strings.GetString(m_Config.cats[i]->name), cat->obj->name) == 0)
748 config_cat = m_Config.cats[i];
753 /* If there is a matching category, build a pre-sorted item list */
754 if (config_cat != NULL)
756 /* Find matching objects in this category */
757 for (size_t i = 0; i < config_cat->commands.size(); i++)
759 const char *config_name = m_Config.strings.GetString(config_cat->commands[i]);
760 for (size_t j = 0; j < to_sort.size(); j++)
762 if (strcmp(config_name, cat->obj_list[to_sort[j]]->name) == 0)
764 /* Place in the final list, then remove from the temporary list */
765 cat->sorted.push_back(cat->obj_list[to_sort[j]]);
766 to_sort.erase(to_sort.iterAt(j));
773 /* Push any remaining items onto the unsorted list */
774 for (size_t i = 0; i < to_sort.size(); i++)
776 cat->unsorted.push_back(cat->obj_list[to_sort[i]]);
779 cat->reorder = false;
782 void TopMenu::SortCategoriesIfNeeded()
784 if (!m_bCatsNeedResort)
789 /* Clear sort results */
790 m_SortedCats.clear();
791 m_UnsortedCats.clear();
793 if (m_Categories.size() == 0)
795 m_bCatsNeedResort = false;
799 CVector<unsigned int> to_sort;
800 for (unsigned int i = 0; i < (unsigned int)m_Categories.size(); i++)
802 to_sort.push_back(i);
805 /* If we have any predefined categories, add them in as they appear. */
806 for (size_t i= 0; i < m_Config.cats.size(); i++)
808 /* Find this category and map it in if we can */
809 for (size_t j = 0; j < to_sort.size(); j++)
811 if (strcmp(m_Config.strings.GetString(m_Config.cats[i]->name),
812 m_Categories[to_sort[j]]->obj->name) == 0)
814 /* Add to the real list and remove from the temporary */
815 m_SortedCats.push_back(to_sort[j]);
816 to_sort.erase(to_sort.iterAt(j));
822 /* Push any remaining items onto the unsorted list */
823 for (size_t i = 0; i < to_sort.size(); i++)
825 m_UnsortedCats.push_back(to_sort[i]);
828 m_bCatsNeedResort = false;
831 void TopMenu::CreatePlayers(int max_clients)
833 m_max_clients = max_clients;
834 m_clients = (topmenu_player_t *)malloc(sizeof(topmenu_player_t) * (max_clients + 1));
835 memset(m_clients, 0, sizeof(topmenu_player_t) * (max_clients + 1));
838 void TopMenu::TearDownClient(topmenu_player_t *player)
840 if (player->cats != NULL)
842 for (unsigned int i = 0; i < player->cat_count; i++)
844 topmenu_player_category_t *player_cat = &(player->cats[i]);
845 if (player_cat->menu != NULL)
847 player_cat->menu->Destroy();
850 delete [] player->cats;
853 if (player->root != NULL)
855 player->root->Destroy();
858 memset(player, 0, sizeof(topmenu_player_t));
861 bool TopMenu::LoadConfiguration(const char *file, char *error, size_t maxlength)
864 unsigned int line = 0, col = 0;
866 if ((err = textparsers->ParseFile_SMC(file, this, &line, &col))
869 const char *err_string = textparsers->GetSMCErrorString(err);
872 err_string = "Unknown";
875 UTIL_Format(error, maxlength, "%s", err_string);
883 bool TopMenu::OnIdentityRemoval(IdentityToken_t *owner)
885 /* First sweep the categories owned by us */
886 CVector<unsigned int> obj_list;
887 for (size_t i = 0; i < m_Categories.size(); i++)
889 if (m_Categories[i]->obj->owner == owner)
891 obj_list.push_back(m_Categories[i]->obj->object_id);
895 for (size_t i = 0; i < obj_list.size(); i++)
897 RemoveFromMenu(obj_list[i]);
900 /* Now we can look for actual items */
901 for (size_t i = 0; i < m_Objects.size(); i++)
903 if (m_Objects[i]->is_free)
907 if (m_Objects[i]->owner == owner)
909 assert(m_Objects[i]->type != TopMenuObject_Category);
910 RemoveFromMenu(m_Objects[i]->object_id);
917 #define PARSE_STATE_NONE 0
918 #define PARSE_STATE_CATEGORY 1
919 unsigned int ignore_parse_level = 0;
920 unsigned int current_parse_state = 0;
921 config_category_t *cur_cat = NULL;
923 void TopMenu::ReadSMC_ParseStart()
925 current_parse_state = PARSE_STATE_NONE;
926 ignore_parse_level = 0;
929 /* Reset the old config */
930 m_Config.strings.Reset();
931 for (size_t i = 0; i < m_Config.cats.size(); i++)
933 delete m_Config.cats[i];
935 m_Config.cats.clear();
938 SMCParseResult TopMenu::ReadSMC_NewSection(const char *name, bool opt_quotes)
940 if (ignore_parse_level)
942 ignore_parse_level++;
946 if (current_parse_state == PARSE_STATE_NONE)
948 cur_cat = new config_category_t;
949 cur_cat->name = m_Config.strings.AddString(name);
950 m_Config.cats.push_back(cur_cat);
951 current_parse_state = PARSE_STATE_CATEGORY;
955 ignore_parse_level = 1;
959 return SMCParse_Continue;
962 SMCParseResult TopMenu::ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
964 if (ignore_parse_level > 0
965 || current_parse_state != PARSE_STATE_CATEGORY
968 return SMCParse_Continue;
971 if (strcmp(key, "item") == 0)
973 cur_cat->commands.push_back(m_Config.strings.AddString(value));
976 return SMCParse_Continue;
979 SMCParseResult TopMenu::ReadSMC_LeavingSection()
981 if (ignore_parse_level)
983 ignore_parse_level--;
987 if (current_parse_state == PARSE_STATE_CATEGORY)
990 current_parse_state = PARSE_STATE_NONE;
994 return SMCParse_Continue;
997 unsigned int TopMenu::FindCategory(const char *name)
999 topmenu_object_t **p_obj = m_ObjLookup.retrieve(name);
1005 topmenu_object_t *obj = *p_obj;
1006 if (obj->type != TopMenuObject_Category)
1011 return obj->object_id;
1014 int _SortObjectNamesDescending(const void *ptr1, const void *ptr2)
1016 obj_by_name_t *obj1 = (obj_by_name_t *)ptr1;
1017 obj_by_name_t *obj2 = (obj_by_name_t *)ptr2;
1018 return strcmp(obj1->name, obj2->name);
1021 unsigned int strncopy(char *dest, const char *src, size_t count)
1029 while ((*src) && (--count))
1035 return (dest - start);
1038 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
1042 size_t len = vsnprintf(buffer, maxlength, fmt, ap);
1045 if (len >= maxlength)
1047 buffer[maxlength - 1] = '\0';
1048 return (maxlength - 1);