* Fetch_String -- Fetches a string resource. * * * * Fetches a string resource and returns a pointer to its text. * * * * INPUT: i
| 809 | * 12/25/1996 JLB : Created. * |
| 810 | *=============================================================================================*/ |
| 811 | char const * Fetch_String(int id) |
| 812 | { |
| 813 | static SRecord _buffers[64]; |
| 814 | static int _time = 0; |
| 815 | |
| 816 | /* |
| 817 | ** Determine if the string ID requested is valid. If not then return an empty string pointer. |
| 818 | */ |
| 819 | if (id == -1 || id == TXT_NONE) return ""; |
| 820 | |
| 821 | /* |
| 822 | ** Adjust the 'time stamp' tracking value. This is an artificial value used merely to track |
| 823 | ** the relative age of the strings requested. |
| 824 | */ |
| 825 | _time = _time+1; |
| 826 | |
| 827 | /* |
| 828 | ** Check to see if the requested string has already been fetched into a buffer. If so, then |
| 829 | ** return a pointer to that string (update the time stamp as well). |
| 830 | */ |
| 831 | for (int index = 0; index < ARRAY_SIZE(_buffers); index++) { |
| 832 | if (_buffers[index].ID == id) { |
| 833 | _buffers[index].TimeStamp = _time; |
| 834 | return(_buffers[index].String); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /* |
| 839 | ** Find a suitable buffer to hold the string to be fetched. The buffer should either be |
| 840 | ** empty or have the oldest fetched string. |
| 841 | */ |
| 842 | int oldest = -1; |
| 843 | int oldtime = -1; |
| 844 | for (int text = 0; text < ARRAY_SIZE(_buffers); text++) { |
| 845 | if (oldest == -1 || oldtime > _buffers[text].TimeStamp) { |
| 846 | oldest = text; |
| 847 | oldtime = _buffers[text].TimeStamp; |
| 848 | if (oldtime == -1 || _buffers[text].ID == -1) break; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | ** A suitable buffer has been found so fetch the string resource and then return a pointer |
| 854 | ** to the string. |
| 855 | */ |
| 856 | char * stringptr = _buffers[oldest].String; |
| 857 | _buffers[oldest].ID = id; |
| 858 | _buffers[oldest].TimeStamp = _time; |
| 859 | |
| 860 | |
| 861 | if (LoadString(Global_instance, id, stringptr, sizeof(_buffers[oldest].String)) == 0) { |
| 862 | return ""; |
| 863 | } |
| 864 | |
| 865 | /****** |
| 866 | char resname[32]; |
| 867 | sprintf(resname,"#%d",id); |
| 868 | HMODULE hmod=GetModuleHandle(nullptr); |
no outgoing calls
no test coverage detected