localOnly restricts assignments to local variables.
| 2824 | |
| 2825 | // localOnly restricts assignments to local variables. |
| 2826 | bool GameState::PerformAssignment(bool localOnly) |
| 2827 | { |
| 2828 | // Handle `private _identifier = value` shorthand — declare the variable |
| 2829 | // as local before performing the assignment. |
| 2830 | bool declareLocal = false; |
| 2831 | // strncmp (not memcmp) so a buffer shorter than 7 bytes stops at the NUL. |
| 2832 | if (strncmp(_e->_pos, "private", 7) == 0 && !isalnumext(_e->_pos[7])) |
| 2833 | { |
| 2834 | declareLocal = true; |
| 2835 | _e->_pos += 7; |
| 2836 | vynech(); |
| 2837 | } |
| 2838 | |
| 2839 | char name[MAX_EXPR_LEN]; |
| 2840 | char* wName = name; |
| 2841 | if (isalphaext(*_e->_pos)) |
| 2842 | { |
| 2843 | int i = 0; |
| 2844 | while (isalnumext(*_e->_pos)) |
| 2845 | { |
| 2846 | if (i < MAX_EXPR_LEN - 1) |
| 2847 | { |
| 2848 | *wName++ = *_e->_pos, i++; |
| 2849 | } |
| 2850 | _e->_pos++; |
| 2851 | } |
| 2852 | } |
| 2853 | *wName = 0; |
| 2854 | if (!*name) |
| 2855 | { |
| 2856 | SetError(EvalBadVar); |
| 2857 | return false; |
| 2858 | } |
| 2859 | vynech(); |
| 2860 | if (*_e->_pos != '=') |
| 2861 | { |
| 2862 | SetError(EvalEqu); |
| 2863 | return false; |
| 2864 | } |
| 2865 | |
| 2866 | strlwr(name); |
| 2867 | |
| 2868 | if (declareLocal) |
| 2869 | { |
| 2870 | VarLocal(name); |
| 2871 | localOnly = true; |
| 2872 | } |
| 2873 | |
| 2874 | if (!LValueGoodName(name)) |
| 2875 | { |
| 2876 | SetError(EvalBadVar); |
| 2877 | return false; |
| 2878 | } |
| 2879 | |
| 2880 | _e->_pos++; |
| 2881 | vynech(); |
| 2882 | |
| 2883 | GameValue value = Vyhod(); |
no test coverage detected