; --------------------------------------------------------------------------------------------; Copyright (c) Fantaisie Software. All rights reserved.; Dual licensed under the GPL and Fantaisie Software licenses.; See LICENSE and LICENSE-FANTAISIE in the project root for license information.; --------------------------------------------------------------------------------------------CompilerIf #SpiderBasic#NbIntendKeywords = 49CompilerElse#NbIntendKeywords = 47CompilerEndIfStructure IntendKeywordsKeyword$NeutralizeKeyword$Intend.lNextIntend.lLineBefore.lLineAfter.lEndStructureGlobal Dim IntendKeywords.IntendKeywords(#NbIntendKeywords)Restore IntendKeywordsFor i = 1 To #NbIntendKeywordsRead.s IntendKeywords(i)\Keyword$Read.s IntendKeywords(i)\NeutralizeKeyword$Read.l IntendKeywords(i)\IntendRead.l IntendKeywords(i)\NextIntendRead.l IntendKeywords(i)\LineBeforeRead.l IntendKeywords(i)\LineAfterNext iProcedure MacroErrorWindowEvents(EventID)Protected Close = 0If EventID = #PB_Event_SizeWindowGetRequiredSize(#GADGET_MacroError_Close, @ButtonWidth, @ButtonHeight)ButtonWidth = Max(ButtonWidth, 80)ResizeGadget(#GADGET_MacroError_Scintilla, 5, 5, WindowWidth(#WINDOW_MacroError)-10, WindowHeight(#WINDOW_MacroError)-25-ButtonHeight)ResizeGadget(#GADGET_MacroError_Close, (WindowWidth(#WINDOW_MacroError)-ButtonWidth)/2, WindowHeight(#WINDOW_MacroError)-10-ButtonHeight, ButtonWidth, ButtonHeight)ElseIf EventID = #PB_Event_Gadget And EventGadget() = #GADGET_MacroError_CloseClose = 1ElseIf EventID = #PB_Event_Menu And EventMenu() = #MENU_MacroError_CloseClose = 1ElseIf EventID = #PB_Event_CloseWindowClose = 1EndIfIf CloseIf MemorizeWindowMacroErrorWindowWidth = WindowWidth(#WINDOW_MacroError)MacroErrorWindowHeight = WindowHeight(#WINDOW_MacroError)EndIfCloseWindow(#WINDOW_MacroError)EndIfEndProcedureProcedure DisplayMacroError(MacroErrorLine, List MacroLines.s())If IsWindow(#WINDOW_MacroError)CloseWindow(#WINDOW_MacroError)EndIfIf OpenWindow(#WINDOW_MacroError, 0, 0, MacroErrorWindowWidth, MacroErrorWindowHeight, Language("Misc", "MacroErrorTitle"), #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible, WindowID(#WINDOW_Main))CreateCodeViewer(#GADGET_MacroError_Scintilla, 0, 0, 0, 0, #False)ButtonGadget(#GADGET_MacroError_Close, 0, 0, 0, 0, Language("Misc", "Close"), #PB_Button_Default)AddKeyboardShortcut(#WINDOW_MacroError, #PB_Shortcut_Return, #MENU_MacroError_Close)AddKeyboardShortcut(#WINDOW_MacroError, #PB_Shortcut_Escape, #MENU_MacroError_Close); read the lines into an array;Count = ListSize(MacroLines())Protected Dim Lines.s(Count)index = 0ForEach MacroLines()Lines(index) = MacroLines()index + 1Next MacroLines(); format the linesProtected NewList Stack()Protected Dim AddLines(Count) ; nonzero for each line where an empty line is beforeIntend = 0For index = 0 To Count-1If Trim(Lines(index)) <> ""ClearList(Stack())*Cursor.Character = @Lines(index)While *Cursor\cIf *Cursor\c = '"' Or *Cursor\c = 39 ; '-char. no need to check comments as the macro parser cuts themEndChar.c = *Cursor\cRepeat*Cursor + #CharSizeUntil *Cursor\c = 0 Or *Cursor\c = EndCharIf *Cursor\c*Cursor + #CharSizeEndIfElseIf *Cursor\c = '~' And PeekC(*Cursor + 1) = '"'*Cursor + #CharSizeWhile *Cursor\c And *Cursor\c <> '"'If *Cursor\c = '\'*Cursor + #CharSizeIf *Cursor\c*Cursor + #CharSizeEndIfElse*Cursor + #CharSizeEndIfWendIf *Cursor\c*Cursor + #CharSizeEndIfElseIf *Cursor\c = ':' ; the macro parser cuts all space after a :, so we add one for readability*Cursor - @Lines(index) ; the string address changes here!Lines(index) = Left(Lines(index), *Cursor / #CharSize + 1)+" "+Right(Lines(index), Len(Lines(index)) - *Cursor / #CharSize - 1)*Cursor + @Lines(index) + 2 * #CharSizeElseIf ValidCharacters(*Cursor\c)*Start = *CursorWhile ValidCharacters(*Cursor\c)*Cursor + #CharSizeWend; Get the word for easier comparisonWord$ = PeekS(*Start, (*Cursor - *Start) / #CharSize)For i = 1 To #NbIntendKeywordsIf IntendKeywords(i)\Keyword$ = Word$ ; Note: CompareStringMemory() won't work here, as "For" and "ForEach" will be found as the same name (and indented 2 times)found = 0 ; look for another keyword that neutralizes this onefield = 1Repeatkeyword$ = StringField(IntendKeywords(i)\NeutralizeKeyword,ドル field, ",")If keyword$ <> ""ForEach Stack()If IntendKeywords(Stack())\Keyword$ = keyword$found = 1DeleteElement(Stack())Break 2EndIfNext Stack()EndIffield + 1Until keyword$ = ""If found = 0 ; not neutralized, so add to the stackAddElement(Stack())Stack() = i ; keyword indexEndIfBreakEndIfNext iElse*Cursor + #CharSizeEndIfWend; calculate intend for this lineForEach Stack()Intend + IntendKeywords(Stack())\IntendNext Stack()If Intend > 0If RealTabLines(index) = RSet(Chr(9), Intend, Chr(9)) + Lines(index)ElseLines(index) = Space(Intend * TabLength) + Lines(index)EndIfElseIntend = 0EndIf; calculate intend for next lineForEach Stack()Intend + IntendKeywords(Stack())\NextIntendNext Stack(); add new lines if needed (only if there is a single keyword on the lineIf ListSize(Stack()) = 1AddLines(index) + IntendKeywords(Stack())\LineBeforeAddLines(index+1) + IntendKeywords(Stack())\LineAfterEndIfEndIfNext index; write lines back to bufferFor i = 0 To Count-1Buffer$ + Lines(i) + #NewLineIf AddLines(i+1) > 0Buffer$ + #NewLineEndIfNext i*Buffer = Ascii(Buffer$) ; Needs to be freed with FreeMemory() !If *BufferSetCodeViewer(#GADGET_MacroError_Scintilla, *Buffer, *ActiveSource\Parser\Encoding)FreeMemory(*Buffer)EndIfMacroErrorWindowEvents(#PB_Event_SizeWindow)HideWindow(#WINDOW_MacroError, 0); mark the error line. (must calculate added lines first)Increase = 0For i = 1 To MacroErrorLine - 1If AddLines(i) > 0Increase + 1EndIfNext iMacroErrorLine + Increase - 1ScintillaSendMessage(#GADGET_MacroError_Scintilla, #SCI_LINESCROLL, 0, MacroErrorLine-4)ScintillaSendMessage(#GADGET_MacroError_Scintilla, #SCI_ENSUREVISIBLE, MacroErrorLine, 0)ScintillaSendMessage(#GADGET_MacroError_Scintilla, #SCI_SETSEL, ScintillaSendMessage(#GADGET_MacroError_Scintilla, #SCI_POSITIONFROMLINE, MacroErrorLine), ScintillaSendMessage(#GADGET_MacroError_Scintilla, #SCI_GETLINEENDPOSITION, MacroErrorLine))SetActiveWindow(#WINDOW_MacroError)SetActiveGadget(#GADGET_MacroError_Close)EndIfEndProcedureProcedure UpdateMacroErrorWindow()SetWindowTitle(#WINDOW_MacroError, Language("Misc", "MacroErrortitle"))SetGadgetText(#GADGET_MacroError_Close, Language("Misc", "Close"))UpdateCodeViewer(#GADGET_MacroError_Scintilla) ; update the coloringEndProcedureDataSection; Keywords that should produce a change in intendation.; Order does not matter.;; First the Keyword, then the keyword, that 'neutralized' it (for multiple, separate with ","); then the intend change For the line With the keyword,; then the change for the line after the keyword; then whether the command should be preceded by an empty line; then whether the command should be followed by an empty line;IntendKeywords:Data$ "If", "EnfIf" : Data.l 0, 1, 0, 0Data$ "Else", "" : Data.l -1, 1, 0, 0Data$ "ElseIf", "" : Data.l -1, 1, 0, 0Data$ "EndIf", "If" : Data.l -1, 0, 0, 0Data$ "Select", "EndSelect" : Data.l 0, 2, 0, 0Data$ "Case", "" : Data.l -1, 1, 0, 0Data$ "Default", "" : Data.l -1, 1, 0, 0Data$ "EndSelect", "Select" : Data.l -2, 0, 0, 0Data$ "CompilerIf", "CompilerEndIF" : Data.l 0, 1, 0, 0Data$ "CompilerElse", "" : Data.l -1, 1, 0, 0Data$ "CompilerElseIf", "" : Data.l -1, 1, 0, 0Data$ "CompilerEndIf", "CompilerIf" : Data.l -1, 0, 0, 0Data$ "CompilerSelect", "CompilerEndSelect": Data.l 0, 2, 0, 0Data$ "CompilerCase", "" : Data.l -1, 1, 0, 0Data$ "CompilerDefault", "" : Data.l -1, 1, 0, 0Data$ "CompilerEndSelect", "CompilerSelect": Data.l -2, 0, 0, 0Data$ "Macro", "EndMacro" : Data.l 0, 1, 1, 0Data$ "EndMacro", "Macro" : Data.l -1, 0, 0, 1Data$ "With", "EndWith" : Data.l 0, 1, 0, 0Data$ "EndWith", "With" : Data.l -1, 0, 0, 0Data$ "Import", "EndImport" : Data.l 0, 1, 1, 0Data$ "ImportC", "EndImport" : Data.l 0, 1, 1, 0Data$ "EndImport", "Import,ImportC" : Data.l -1, 0, 0, 1Data$ "Interface", "EndInterface" : Data.l 0, 1, 1, 0Data$ "EndInterface", "Interface" : Data.l -1, 0, 0, 1Data$ "Structure", "EndStructure" : Data.l 0, 1, 1, 0Data$ "EndStructure", "Structure" : Data.l -1, 0, 0, 1Data$ "Enumeration", "EndEnumeration" : Data.l 0, 1, 1, 0Data$ "EnumerationBinary", "EndEnumeration" : Data.l 0, 1, 1, 0Data$ "EndEnumeration", "Enumeration" : Data.l -1, 0, 0, 1Data$ "StructureUnion", "EndStructureUnion": Data.l 0, 1, 0, 0Data$ "EndStructureUnion", "StructureUnion": Data.l -1, 0 , 0, 0Data$ "DataSection", "EndDataSection" : Data.l 0, 1, 1, 0Data$ "EndDataSection", "DataSection" : Data.l -1, 0, 0, 1Data$ "For", "Next" : Data.l 0, 1, 0, 0Data$ "ForEach", "Next" : Data.l 0, 1, 0, 0Data$ "Next", "For,ForEach" : Data.l -1, 0, 0, 0Data$ "Repeat", "Until,ForEver" : Data.l 0, 1, 0, 0Data$ "Until", "Repeat" : Data.l -1, 0, 0, 0Data$ "ForEver", "Repeat" : Data.l -1, 0, 0, 0Data$ "While", "Wend" : Data.l 0, 1, 0, 0Data$ "Wend", "While" : Data.l -1, 0, 0, 0Data$ "Procedure", "EndProcedure" : Data.l 0, 1, 1, 0Data$ "ProcedureC", "EndProcedure" : Data.l 0, 1, 1, 0Data$ "ProcedureCDLL", "EndProcedure" : Data.l 0, 1, 1, 0Data$ "ProcedureDLL", "EndProcedure" : Data.l 0, 1, 1, 0Data$ "EndProcedure", "Procedure,ProcedureC,ProcedureDLL,ProcedureCDLL": Data.l -1, 0, 0, 1Data$ "HeaderSection", "EndHeaderSection" : Data.l 0, 1, 1, 0Data$ "EndHeaderSection", "HeaderSection" : Data.l -1, 0, 0, 1EndDataSection
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。