//TH-Header //***************************************************************************************** // Copyright (c) 2014 KURANT Project // All rights reserved. // // $FileName : CodeArt.pkg // $ProjectName : The Hammer 2.0 // $Authors : Wil van Antwerpen, Michael Kurz, Sergey V. Natarov, Bernhard Ponemayr // $Created : 01.25.2014 01:08 // $Type : LGPL // // Contents: // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd // CodeArt.pkg Define CODEART_TAG_START For ("/"+"/") Define CODEART_TAG_END For ("") Define CODEART_WARNING For ("/"+"/CA-Warning/") Class cCodeArt Is an Array //Insert your Properties here. Procedure Construct_Object Forward Send Construct_Object // Failed to load info, so disabled Property Integer CodeArt_Disabled_State False // Current Language Scope: Property String CodeArt_Scope_Start "" Property String CodeArt_Scope_End "" Property String CodeArt_Keywords "" Property String CodeArt_Comment "" Property Integer CodeArt_TrackVars False // Property String psOutFile "codeart.txt" // Property Integer piErrorCount 0 Property Integer piCurrentScope 0 Property Integer piTabSize 4 Property Integer piEmptyLine False Property Integer piCommentLine False Property Integer piLineCount 0 Property Integer piHeaderState False // Object oLP1 Is a cLineParser Set piLanguageTokens To True End_Object // Object oScope Is a Array End_Object // Object oErrors Is a Array End_Object // End_Procedure // Procedure LoadKeywords String sSt String sEn String sKw Set CodeArt_Scope_Start To (Uppercase("|"+(Trim(Replaces("\n",sSt,"|")))+"|")) Set CodeArt_Scope_End To (Uppercase("|"+(Trim(Replaces("\n",sEn,"|")))+"|")) Set CodeArt_Keywords To (Uppercase("|"+(Trim(Replaces("\n",sKw,"|")))+"|")) End_Procedure // Procedure LoadEntries String sName sScopeStart sScopeEnd sKeyWords Integer iC iRet Get psLanguage Of ghoEditorProperties To sName If (sName<>"") Begin Get FindLanguage Of ghoEditorProperties sName To iC If (iC>=0) Begin Set CodeArt_Comment To (psLanguages.szSingleLineComments(ghoEditorProperties,iC)) Move (psLanguages.szScopeKeywords1(ghoEditorProperties,iC)) To sScopeStart Move (psLanguages.szScopeKeywords2(ghoEditorProperties,iC)) To sScopeEnd Move (psLanguages.szKeywords(ghoEditorProperties,iC)) To sKeyWords Send LoadKeywords (Trim(sScopeStart)) (Trim(sScopeEnd)) (Trim(sKeyWords)) End Else Set CodeArt_Disabled_State To True End End_Procedure // Function Tab_String Integer iScope Returns String String sRet sSpace Integer iTab If (iScope=0) Function_Return "" Get piTabSize To iTab If (iTab=0) Move 4 To iTab Move (Repeat(" ", iTab)) To sSpace If (iScope=1) Function_Return sSpace Move (Repeat(sSpace, iScope)) To sRet Function_Return sRet End_Function // Procedure Output_Line String sTab String sLine If (Trim(sLine)="") Begin Writeln If (Not(piCommentLine(Self))) Set piEmptyLine To True End Else Begin Writeln sTab sLine If (Not(piCommentLine(Self))) Set piEmptyLine To False End End_Procedure // Procedure Write_E If (Not(piEmptyLine(Self))) Begin Writeln Set piEmptyLine To True End Else Set piEmptyLine To False End_Procedure // Function FormatExpression String sExp Returns String Move (Replaces(",", sExp, ", ")) To sExp While " " In sExp Move (Replaces(" ", sExp, " ")) To sExp Loop While "( " In sExp Move (Replaces("( ", sExp, "(")) To sExp Loop While " )" In sExp Move (Replaces(" )", sExp, ")")) To sExp Loop // Function_Return sExp End_Function // Procedure Process_Line String sLine String sLineNo sScope sTab sWd sCom sComLn sCmd sLnCmnt sErr String sProcessed Integer iScope iLineNo iStart iEnd iBegin iOk iType iComment Get piCurrentScope To iScope Get CodeArt_Comment To sCom Move (Trim(sLine)) To sLine // If (sLine="") Begin Send Write_E Procedure_Return End // If sCom In sLine Begin Move sLine To sComLn Move (Trim(Left(sLine, (Pos(sCom,sLine)-1) ))) To sLine Move (Trim(Replace(sLine,sComLn,""))) To sComLn End // Send ParseLine To (oLP1(Self)) sLine Get Value Of (oLP1(Self)) Item 0 To sScope Get Value Of (oType(oLP1(Self))) Item 0 To iType Get Value Of (oLP1(Self)) Item (Item_Count(oLP1(Self))-1) To sCmd //////////////////////////// Integer iC iT String sE sEF For iC From 1 To (Item_Count(oLP1(Self))-1) Get Value Of (oType(oLP1(Self))) Item iC To iT If (iT=CLINEPARSER_EXPRESSION) Begin Get Value Of (oLP1(Self)) Item iC To sE Get FormatExpression sE To sEF Move (Replace(sE, sLine, sEF)) To sLine End Loop //////////////////////////// If (Uppercase(sCmd)="BEGIN") Move 1 To iBegin Move (Trim(sLine+" "+sComLn)) To sLine If ((Trim(sComLn)<>"")And(Trim(sLine)=Trim(sComLn))) Begin If (Not(piCommentLine(Self))) Begin Set piCommentLine To True If (piLineCount(Self)) Begin Send Write_E Set piEmptyLine To True End Else Set piHeaderState To True End End Else Begin Set piCommentLine To False If (piHeaderState(Self)) Begin Date dToday String sHr sMin sSec Sysdate4 dToday sHr sMin sSec If (Length(sHr)=1) Move ("0"+sHr) To sHr If (Length(sMin)=1) Move ("0"+sMin) To sMin If (Length(sSec)=1) Move ("0"+sSec) To sSec If (pbCodeArtInsertDateTime(ghoEditorProperties)) Begin Writeln #IFDEF TH_TRANSLATION Move (Replace("%1", gILanguage[1535], dToday)) to sProcessed Move (Replace("%2", sProcessed, sHr+":"+sMin+":"+sSec)) to sProcessed Writeln CODEART_TAG_START " " sProcessed " -- (C) 2017, KURANT Project" #ELSE Writeln CODEART_TAG_START " Processed on " dToday " @ " sHr ":" sMin ":" sSec " by TheHammer CodeArt Utility -- (C) 2017, KURANT Project" #ENDIF Writeln End End Set piHeaderState To False End Move (Uppercase("|"+sScope+"|")) To sWd Move 0 To iStart Move 0 To iEnd If (iBegin) Move 1 To iStart Move 0 To iOk If sWd In (CodeArt_Scope_Start(Self)) Begin Move 1 To iStart Move 1 To iOk End If sWd In (CodeArt_Scope_End(Self)) Begin Move 1 To iEnd Move 1 To iOk End If sWd In (CodeArt_Keywords(Self)) Begin Move 1 To iOk End If ((Not(iOk))And(iType<>CLINEPARSER_COMMENT)And(sScope<>"")And(iType<>CLINEPARSER_INDICATOR)) Begin // Generate Error Set piErrorCount to (piErrorCount(Self)+1) #IFDEF TH_TRANSLATION Move (Replace("%1", gILanguage[1536], String(piLineCount(Self)+1))) to sErr Move (Replace("%2", sErr, sScope)) to sErr #ELSE Move ("ON LINE: "+String(piLineCount(Self)+1)+" Command ["+sScope+"] not defined in Editor options.") to sErr #ENDIF If (pbCodeArtInsertErrors(ghoEditorProperties)) Writeln CODEART_WARNING " " sErr Set Value Of (oErrors(Self)) Item (Item_Count(oErrors(Self))) To sErr End If ((iStart)And(iEnd)) Begin Decrement iScope Get Tab_String iScope To sTab Send Output_Line sTab sLine Move "" To sLine Increment iScope End Else If iStart Begin Send Write_E Get Tab_String iScope To sTab Send Output_Line sTab sLine Move "" To sLine Increment iScope Set Value Of (oScope(Self)) Item iScope To ( (Value(oLP1(Self),0)) + " " + (Value(oLP1(Self),1)) ) End Else If iEnd Begin Get Value Of (oScope(Self)) Item iScope To sLnCmnt Decrement iScope Get Tab_String iScope To sTab If ((Trim(sLnCmnt<>""))And(sComLn="")And(pbCodeArtInsertComments(ghoEditorProperties))) Move (sLine+" "+CODEART_TAG_START+" "+sLnCmnt+" "+CODEART_TAG_END) To sLine Send Output_Line sTab sLine Move "" To sLine Send Write_E End // If (sLine<>"") Begin Get Tab_String iScope To sTab Send Output_Line sTab sLine End // Set piCurrentScope To iScope Set piLineCount To (piLineCount(Self)+1) End_Procedure // Procedure Init_CodeArt Set piErrorCount To 0 Set piCurrentScope To 0 Set piLineCount To 0 Set piEmptyLine To False Set piCommentLine To False Set piHeaderState To False Send Delete_Data To (oScope(Self)) Send Delete_Data To (oErrors(Self)) End_Procedure // // Returns name of out file or nothing Function CodeArt String sFile Returns String String sInFile sOutFile sLine sLineNo sScope sTab sWd sErr sErrDesc String sStatus Integer iScope iLineNo iErr iCnt If (Trim(sFile)="") Function_Return (_T("ERROR: No Source File Specified", 1537)) If (CodeArt_Disabled_State(Self)) Function_Return (_T("ERROR: CodeArt Can't Load Current Language Keywords!", 1538)) Send Init_CodeArt // Move sFile To sInFile Send SetTitle To ghoStatusPanel sInFile Move (sFile+".CA") To sOutFile Set psOutFile To sOutFile Direct_Input sInFile Direct_Output sOutFile Repeat Readln sLine [not SeqEof] Send Process_Line sLine #IFDEF TH_TRANSLATION Move (Replace("%1", gILanguage[1539], String(piLineCount(Self)))) to sStatus Send ShowInfo to ghoStatusPanel sStatus #ELSE Send ShowInfo to ghoStatusPanel ("Processing line "+String(piLineCount(Self))+" ...") #ENDIF Until [seqeof] Close_Input Close_Output Send HideInfo To ghoStatusPanel If (piErrorCount(Self)>0) Begin Get piErrorCount to sErr #IFDEF TH_TRANSLATION Move (Replace("%1", gILanguage[1540], sErr)) to sErr #ELSE Move ("\n\n"+sErr+" warnings found during file processing! File may be converted improperly: \n\n") to sErr #ENDIF Move (Item_Count(oErrors(Self))-1) To iCnt If (iCnt>4) Move 4 To iCnt // Output first 5 errors... For iErr From 0 To iCnt Get Value Of (oErrors(Self)) Item iErr To sErrDesc Move (sErr+sErrDesc+"\n") To sErr Loop If (pbCodeArtInsertErrors(ghoEditorProperties)) Begin #IFDEF TH_TRANSLATION Move ( sErr + Replace("%1", gILanguage[1541], CODEART_WARNING) ) to sErr #ELSE Move (sErr+"...\n\nSee Converted file for details. All errors marked as '"+CODEART_WARNING+"'") to sErr #ENDIF End End If (piCurrentScope(Self)) Function_Return (_T("ERROR: Scope count mismatch!\n\n", 1542)+sErr) Function_Return (_T("Converted file is", 1543) * sOutFile+sErr) End_Function // Procedure End_Construct_Object Forward Send End_Construct_Object Send LoadEntries End_Procedure End_Class Global_Variable Integer ghoCodeArt Object oCodeArt Is a cCodeArt Move Self To ghoCodeArt End_Object