I really could do with a little help with this one.
This sub routine breaks up a line into words, it also detect delimiters as I need to know what delimiter it has found.
SUB ColourLineZ(INT id,INT LineNoIn,ISTRING LineToWords[255],INT Offset)
LineLen = LEN(LineToWords)
WordIn = ""
SENDMESSAGE(id,EM_SETSEL,1+Offset,LineLen + Offset)
cf.dwMask = CFM_COLOR
cf.crTextColor = RGB(0,0,0)
cf.cbSize = SIZEOF(cf)
SENDMESSAGE(id,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
FOR b1 = 1 TO LineLen '<----------- this
ThisPos = b1 + Offset
Letter = LineToWords[b1-1] '<------ and this
Del = INSTR(CheckLetter2,Letter)
SELECT Del
CASE 0 'Add character to our word
'aw = instr(KeyWordLetters,ucase$(Letter)) 'Only alphabet characters a to z plus $ _ and @ symbols
WordIn = WordIn + Letter
CASE 1 'Quotes
WordIn = ""
StartPos = b1 + (Offset-1)
DO
b1 ++
Letter = LineToWords[b1-1]
UNTIL Letter = CHR$(34) OR b1 = LineLen
EndPos = b1 + Offset
'EndPos = instr(LineToWords,chr$(34),StartPos+1) + Offset
SENDMESSAGE(id,EM_SETSEL,StartPos,EndPos)
cf.dwMask = CFM_COLOR
cf.crTextColor = Purple
cf.cbSize = SIZEOF(cf)
SENDMESSAGE(id,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
IF b1 = LineLen THEN RETURN
CASE 2 ' comment symbol
WordIn = ""
StartPos = b1 + (Offset-1)
SENDMESSAGE(id,EM_SETSEL,StartPos,LineLen + Offset)
cf.dwMask = CFM_COLOR
cf.crTextColor = Green
cf.cbSize = SIZEOF(cf)
SENDMESSAGE(id,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
RETURN
'case 7 'Local subroutine check
'if Subs[LineNoIn] 'Local subroutine
'StartPos = (ThisPos - len(WordIn))-1
'EndPos = ThisPos-1
'SendMessage(id,EM_HIDESELECTION,1,0)
'SendMessage(id,EM_SETSEL,StartPos,EndPos)
'cf.dwMask = CFM_COLOR
'cf.crTextColor = Claret
'cf.cbSize = sizeof(cf)
'SendMessage(id,EM_SETCHARFORMAT,SCF_SELECTION,&cf)
'SendMessage(id,EM_HIDESELECTION,0,0)
'breakfor
'endif
'SendMessage(id,EM_SETSEL,EndPos,EndPos)
'goto DoDefault
CASE 18 'Remove carriage return from last word on line
WordIn = MID$(WordIn,1,INSTR(WordIn,CHR$(13))-1)
IF LEN(WordIn)> 1
WordIn = ChangeWordEditorZ(id,WordIn,(ThisPos - LEN(WordIn))-1,(ThisPos)-1)
ENDIF
RETURN
DEFAULT 'Other delimiter - so we have our word
LABEL DoDefault
IF LEN(WordIn)> 1 'Key words are at least 2 characrers long
StartPos = (ThisPos - LEN(WordIn))-1
EndPos = ThisPos-1
WordIn = ChangeWordEditorZ(id,WordIn,StartPos,EndPos)
ENDIF
WordIn = ""
ENDSELECT
NEXT b1
RETURN
ENDSUB
Now I know INSTR can have an option start position for a string, so instead of using a FOR / NEXT loop to loop through each character in the string I was wondering how this sub routine could be changed.
I need to know the " character, the "'" character and the "(" ")" characters.
Anyone fancy a little challenge?
Would be appreciated!
Thanks,
Andy.
Perhaps the xinstr command from the Fletchie's control pak can help here ?
Thanks Hecktor, will have a look now I finally have a little time after a busy few days.
Thanks again,
Andy.
This can be a starting point. The code breaks up each part of a subroutine:
$INCLUDE "windowssdk.inc"
OPENCONSOLE
string indata = "SUB MyFunc(INT value, string text), INT"
string sep = "(),"
PRINT
PRINT indata
string stdata = indata ' indata copy
pointer pdata = &indata ' indata address
pointer token = strtok(indata, sep)
WHILE token
PRINT
PRINT "str: " + RTRIM$(LTRIM$(*<string>token))
PRINT "pos:" + STR$(token - pdata)
IF token - pdata THEN PRINT "sep: " + MID$(stdata, token - pdata, 1) ELSE PRINT "sep: no sep"
token = strtok(NULL, sep)
ENDWHILE
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
Thanks Fasecero,
You are always a very big help!
Will play around with this to see if it helps me.
Thanks again,
Andy.