MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / AddGroup

Method AddGroup

source/script.cpp:7386–7414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7384
7385
7386ResultType Script::AddGroup(LPTSTR aGroupName)
7387// Returns OK or FAIL.
7388// The caller must already have verified that this isn't a duplicate group.
7389// This function is not thread-safe because it adds an entry to the quasi-global list of window groups.
7390// In addition, if this function is being called by one thread while another thread is calling FindGroup(),
7391// the thread-safety notes in FindGroup() apply.
7392{
7393 size_t aGroupName_length = _tcslen(aGroupName);
7394 if (aGroupName_length > MAX_VAR_NAME_LENGTH)
7395 return ValueError(_T("Group name too long."), aGroupName, FAIL);
7396 if (!Var::ValidateName(aGroupName, DISPLAY_GROUP_ERROR)) // Seems best to use same validation as var names.
7397 return FAIL;
7398
7399 LPTSTR new_name = SimpleHeap::Malloc(aGroupName, aGroupName_length);
7400 if (!new_name)
7401 return FAIL; // It already displayed the error for us.
7402
7403 // The precise method by which the follows steps are done should be thread-safe even if
7404 // some other thread calls FindGroup() in the middle of the operation. But any changes
7405 // must be carefully reviewed:
7406 WinGroup *the_new_group = new WinGroup(new_name);
7407 if (mFirstGroup == NULL)
7408 mFirstGroup = the_new_group;
7409 else
7410 mLastGroup->mNextGroup = the_new_group;
7411 // This must be done after the above:
7412 mLastGroup = the_new_group;
7413 return OK;
7414}
7415
7416
7417

Callers

nothing calls this directly

Calls 1

ValueErrorFunction · 0.85

Tested by

no test coverage detected