| 2361 | |
| 2362 | |
| 2363 | ResultType Hotstring::AddHotstring(LPTSTR aName, IObjectPtr aCallback, LPTSTR aOptions, LPTSTR aHotstring |
| 2364 | , LPTSTR aReplacement, bool aHasContinuationSection, UCHAR aSuspend) |
| 2365 | // Returns OK or FAIL. |
| 2366 | // Caller has ensured that aHotstringOptions is blank if there are no options. Otherwise, aHotstringOptions |
| 2367 | // should end in a colon, which marks the end of the options list. aHotstring is the hotstring itself |
| 2368 | // (e.g. "ahk"), which does not have to be unique, unlike aName, which was made unique by also including |
| 2369 | // any options (e.g. ::ahk:: has a different aName than :c:ahk::). |
| 2370 | // Caller has also ensured that aHotstring is not blank. |
| 2371 | { |
| 2372 | // The length is limited for performance reasons, notably so that the hook does not have to move |
| 2373 | // memory around in the buffer it uses to watch for hotstrings: |
| 2374 | if (_tcslen(aHotstring) > MAX_HOTSTRING_LENGTH) |
| 2375 | return ValueError(_T("Hotstring max abbreviation length is ") MAX_HOTSTRING_LENGTH_STR _T("."), aHotstring, FAIL); |
| 2376 | |
| 2377 | if (!shs) |
| 2378 | { |
| 2379 | if ( !(shs = (Hotstring **)malloc(HOTSTRING_BLOCK_SIZE * sizeof(Hotstring *))) ) |
| 2380 | return MemoryError(); // Short msg. since so rare. |
| 2381 | sHotstringCountMax = HOTSTRING_BLOCK_SIZE; |
| 2382 | } |
| 2383 | else if (sHotstringCount >= sHotstringCountMax) // Realloc to preserve contents and keep contiguous array. |
| 2384 | { |
| 2385 | // Expand the array by one block. Use a temp var. because realloc() returns NULL on failure |
| 2386 | // but leaves original block allocated. |
| 2387 | void *realloc_temp = realloc(shs, (sHotstringCountMax + HOTSTRING_BLOCK_SIZE) * sizeof(Hotstring *)); |
| 2388 | if (!realloc_temp) |
| 2389 | return MemoryError(); // Short msg. since so rare. |
| 2390 | shs = (Hotstring **)realloc_temp; |
| 2391 | sHotstringCountMax += HOTSTRING_BLOCK_SIZE; |
| 2392 | } |
| 2393 | |
| 2394 | if ( !(shs[sHotstringCount] = new Hotstring(aName, aCallback, aOptions, aHotstring, aReplacement, aHasContinuationSection, aSuspend)) ) |
| 2395 | return MemoryError(); // Short msg. since so rare. |
| 2396 | if (!shs[sHotstringCount]->mConstructedOK) |
| 2397 | { |
| 2398 | delete shs[sHotstringCount]; // SimpleHeap allows deletion of most recently added item. |
| 2399 | return FAIL; // The constructor already displayed the error. |
| 2400 | } |
| 2401 | |
| 2402 | ++sHotstringCount; |
| 2403 | if (!g_script.mIsReadyToExecute) // Caller is LoadIncludedFile(); allow BIF_Hotstring to manage this at runtime. |
| 2404 | ++sEnabledCount; // This works because the script can't be suspended during startup (aSuspend is always FALSE). |
| 2405 | return OK; |
| 2406 | } |
| 2407 | |
| 2408 | |
| 2409 |
nothing calls this directly
no test coverage detected