| 808 | } |
| 809 | |
| 810 | ResultType Invoke(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 811 | { |
| 812 | aResultToken.symbol = SYM_INTEGER; // Set default return type -- the most common cases return integer. |
| 813 | |
| 814 | auto member = MemberID(aID); |
| 815 | switch (member) |
| 816 | { |
| 817 | case M_Read: |
| 818 | { |
| 819 | DWORD length; |
| 820 | if (aParamCount) |
| 821 | length = (DWORD)ParamIndexToInt64(0); |
| 822 | else |
| 823 | length = (DWORD)(mFile.Length() - mFile.Tell()); // We don't know the actual number of characters these bytes will translate to, but this should be sufficient. |
| 824 | if (length == -1) |
| 825 | break; // Fail. |
| 826 | if (!TokenSetResult(aResultToken, NULL, length)) // Only after checking length above: TokenSetResult requires non-NULL aResult if aResultLength == -1. |
| 827 | return FAIL; |
| 828 | length = mFile.Read(aResultToken.marker, length); |
| 829 | aResultToken.symbol = SYM_STRING; |
| 830 | aResultToken.marker[length] = '\0'; |
| 831 | aResultToken.marker_length = length; // Update marker_length to the actual number of characters read. |
| 832 | return OK; |
| 833 | } |
| 834 | break; |
| 835 | |
| 836 | case M_ReadLine: |
| 837 | { // See above for comments. |
| 838 | if (!TokenSetResult(aResultToken, NULL, READ_FILE_LINE_SIZE)) |
| 839 | return FAIL; |
| 840 | DWORD length = mFile.ReadLine(aResultToken.marker, READ_FILE_LINE_SIZE - 1); |
| 841 | aResultToken.symbol = SYM_STRING; |
| 842 | if (length && aResultToken.marker[length - 1] == '\n') |
| 843 | --length; |
| 844 | aResultToken.marker[length] = '\0'; |
| 845 | aResultToken.marker_length = length; |
| 846 | return OK; |
| 847 | } |
| 848 | break; |
| 849 | |
| 850 | case M_Write: |
| 851 | case M_WriteLine: |
| 852 | { |
| 853 | DWORD bytes_written = 0; |
| 854 | size_t chars_to_write = 0; |
| 855 | if (aParamCount) |
| 856 | { |
| 857 | LPTSTR param1 = ParamIndexToString(0, _f_number_buf, &chars_to_write); |
| 858 | bytes_written = mFile.Write(param1, (DWORD)chars_to_write); |
| 859 | } |
| 860 | if (member == M_WriteLine && (bytes_written || !chars_to_write)) // i.e. don't attempt it if above failed. |
| 861 | { |
| 862 | bytes_written += mFile.Write(_T("\n"), 1); |
| 863 | } |
| 864 | aResultToken.value_int64 = bytes_written; |
| 865 | return OK; |
| 866 | } |
| 867 | break; |
nothing calls this directly
no test coverage detected