- i create a 256 dword array, initialized to 0. each dword corresponds to a possible ascii character,named asmsyntaxarray. for example, the 21th dword represents the ascii 20h (space). i use them as a fast lookup table: for example, if i have the word "include", i'll extract the first character (i) from the word and look up the dword at the corresponding index. if that dword is 0, i know immediately that there is no words to be hilighted starting with "i". if the dword is non-zero, it contains the pointer to the linked list of the wordinfo structure which contains the information about the word to be hilighted.
- i read the words to be hilighted and create a wordinfo structure for each of them.
wordinfo struct wordlen dd ? ; the length of the word: used as a quick comparison pszword dd ? ; pointer to the word pcolor dd ? ; point to the dword that contains the color used to hilite the word nextlink dd ? ; point to the next wordinfo structure wordinfo ends
as you can see, i use the length of the word as the second quick comparison. if the first character of the word matches, we next compare its length to the available words. each dword in asmsyntaxarray contains a pointer to the head of the associated wordinfo array. for example, the dword that represents the character "i" will contain the pointer to the linked list of the words that begin with "i". pcolor member points to the dword that contains the color value used to hilight the word. pszword points to the word to be hilighted, in lowercase.
- the memory for the linked list is allocated from the default heap so it's fast and easy to clean up, ie, no cleaning up required at all.
the word list is stored in a file named "wordfile.txt" and i access it with getprivateprofilestring apis. i provide as many as 10 different syntax coloring, starting from c1 to c10. the color array is named asmcolorarray. pcolor member of each wordinfo structure points to one of the dwords in asmcolorarray. thus it is easy to change the syntax coloring on the fly: you just change the dword in asmcolorarray and all words using that color will use the new color immediately.