| 4216 | |
| 4217 | |
| 4218 | ResultType Script::ParseAndAddLine(LPTSTR aLineText, ActionTypeType aActionType, LPTSTR aLiteralMap, size_t aLiteralMapLength) |
| 4219 | // Returns OK or FAIL. |
| 4220 | // aLineText needs to be a string whose contents are modifiable (though the string won't be made any |
| 4221 | // longer than it is now, so it doesn't have to be of size LINE_SIZE). This helps performance by |
| 4222 | // allowing the string to be split into sections without having to make temporary copies. |
| 4223 | // aLineText must point to a buffer with room to append "()" if it may contain a function call statement |
| 4224 | // (which is only possible when aActionType is ACT_INVALID/omitted or an ACT with possible subaction). |
| 4225 | { |
| 4226 | #ifdef _DEBUG |
| 4227 | if (!aLineText || !*aLineText && !aActionType) |
| 4228 | return ScriptError(_T("DEBUG: ParseAndAddLine() called incorrectly.")); |
| 4229 | #endif |
| 4230 | size_t line_length = _tcslen(aLineText); // Length is needed in a couple of places. |
| 4231 | |
| 4232 | TCHAR action_name[MAX_VAR_NAME_LENGTH + 1], *end_marker; |
| 4233 | if (aActionType) // Currently can be ACT_EXPRESSION or ACT_HOTKEY_IF. |
| 4234 | { |
| 4235 | *action_name = '\0'; |
| 4236 | end_marker = NULL; // Indicate that there is no action to mark the end of. |
| 4237 | } |
| 4238 | else // We weren't called recursively from self, nor is it ACT_EXPRESSION, so set action_name and end_marker the normal way. |
| 4239 | { |
| 4240 | for (;;) // A loop with only one iteration so that "break" can be used instead of a lot of nested if's. |
| 4241 | { |
| 4242 | int declare_type; |
| 4243 | LPTSTR cp; |
| 4244 | if (!_tcsnicmp(aLineText, _T("Global"), 6)) |
| 4245 | { |
| 4246 | cp = aLineText + 6; // The character after the declaration word. |
| 4247 | declare_type = VAR_DECLARE_GLOBAL; |
| 4248 | } |
| 4249 | else |
| 4250 | { |
| 4251 | if (!_tcsnicmp(aLineText, _T("Local"), 5)) |
| 4252 | { |
| 4253 | cp = aLineText + 5; // The character after the declaration word. |
| 4254 | declare_type = VAR_DECLARE_LOCAL; |
| 4255 | } |
| 4256 | else if (!_tcsnicmp(aLineText, _T("Static"), 6)) // Static also implies local (for functions that default to global). |
| 4257 | { |
| 4258 | cp = aLineText + 6; // The character after the declaration word. |
| 4259 | declare_type = VAR_DECLARE_STATIC; |
| 4260 | } |
| 4261 | else // It's not the word "global", "local", or static, so no further checking is done. |
| 4262 | break; |
| 4263 | } |
| 4264 | |
| 4265 | if (*cp && !IS_SPACE_OR_TAB(*cp)) // There is a character following the word local but it's not a space or tab. |
| 4266 | break; // It doesn't qualify as being the global or local keyword because it's something like global2. |
| 4267 | if (*cp && *(cp = omit_leading_whitespace(cp))) // Second *cp is probably always non-null since caller rtrimmed it, but even if not it's handled correctly. |
| 4268 | { |
| 4269 | if (!IS_IDENTIFIER_CHAR(*cp)) |
| 4270 | break; |
| 4271 | } |
| 4272 | else // It's the word "global", "local", "static" by itself. |
| 4273 | { |
| 4274 | // Any combination of declarations is allowed here for simplicity, but only declarations can |
| 4275 | // appear above this line: |
nothing calls this directly
no test coverage detected