From 3910dfce1211d96ac5018673b05a0d4c5821027a Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sat, 24 Jul 2004 11:33:02 +0000 Subject: [PATCH] *** empty log message *** --- compiler/compile/compile.cfg | 38 +++++++ compiler/compile/compile.dof | 132 +++++++++++++++++++++++ compiler/compile/compile.dpr | 82 +++++++++++++++ compiler/compile/uFunc.pas | 196 +++++++++++++++++++++++++++++++++++ 4 files changed, 448 insertions(+) create mode 100755 compiler/compile/compile.cfg create mode 100755 compiler/compile/compile.dof create mode 100755 compiler/compile/compile.dpr create mode 100755 compiler/compile/uFunc.pas diff --git a/compiler/compile/compile.cfg b/compiler/compile/compile.cfg new file mode 100755 index 00000000..a0143117 --- /dev/null +++ b/compiler/compile/compile.cfg @@ -0,0 +1,38 @@ +-$A8 +-$B- +-$C+ +-$D+ +-$E- +-$F- +-$G+ +-$H+ +-$I+ +-$J- +-$K- +-$L+ +-$M- +-$N+ +-$O+ +-$P+ +-$Q- +-$R- +-$S- +-$T- +-$U- +-$V+ +-$W- +-$X+ +-$YD +-$Z1 +-cg +-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +-H+ +-W+ +-M +-$M16384,1048576 +-K$00400000 +-LE"..\Bpl" +-LN"..\Bpl" +-w-UNSAFE_TYPE +-w-UNSAFE_CODE +-w-UNSAFE_CAST diff --git a/compiler/compile/compile.dof b/compiler/compile/compile.dof new file mode 100755 index 00000000..47b416d0 --- /dev/null +++ b/compiler/compile/compile.dof @@ -0,0 +1,132 @@ +[FileVersion] +Version=7.0 +[Compiler] +A=8 +B=0 +C=1 +D=1 +E=0 +F=0 +G=1 +H=1 +I=1 +J=0 +K=0 +L=1 +M=0 +N=1 +O=1 +P=1 +Q=0 +R=0 +S=0 +T=0 +U=0 +V=1 +W=0 +X=1 +Y=1 +Z=1 +ShowHints=1 +ShowWarnings=1 +UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +NamespacePrefix= +SymbolDeprecated=1 +SymbolLibrary=1 +SymbolPlatform=1 +UnitLibrary=1 +UnitPlatform=1 +UnitDeprecated=1 +HResultCompat=1 +HidingMember=1 +HiddenVirtual=1 +Garbage=1 +BoundsError=1 +ZeroNilCompat=1 +StringConstTruncated=1 +ForLoopVarVarPar=1 +TypedConstVarPar=1 +AsgToTypedConst=1 +CaseLabelRange=1 +ForVariable=1 +ConstructingAbstract=1 +ComparisonFalse=1 +ComparisonTrue=1 +ComparingSignedUnsigned=1 +CombiningSignedUnsigned=1 +UnsupportedConstruct=1 +FileOpen=1 +FileOpenUnitSrc=1 +BadGlobalSymbol=1 +DuplicateConstructorDestructor=1 +InvalidDirective=1 +PackageNoLink=1 +PackageThreadVar=1 +ImplicitImport=1 +HPPEMITIgnored=1 +NoRetVal=1 +UseBeforeDef=1 +ForLoopVarUndef=1 +UnitNameMismatch=1 +NoCFGFileFound=1 +MessageDirective=1 +ImplicitVariants=1 +UnicodeToLocale=1 +LocaleToUnicode=1 +ImagebaseMultiple=1 +SuspiciousTypecast=1 +PrivatePropAccessor=1 +UnsafeType=0 +UnsafeCode=0 +UnsafeCast=0 +[Linker] +MapFile=0 +OutputObjs=0 +ConsoleApp=1 +DebugInfo=0 +RemoteSymbols=0 +MinStackSize=16384 +MaxStackSize=1048576 +ImageBase=4194304 +ExeDescription= +[Directories] +OutputDir= +UnitOutputDir= +PackageDLLOutputDir= +PackageDCPOutputDir= +SearchPath= +Packages= +Conditionals= +DebugSourceDirs= +UsePackages=0 +[Parameters] +RunParams= +HostApplication= +Launcher= +UseLauncher=0 +DebugCWD= +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1031 +CodePage=1252 +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= diff --git a/compiler/compile/compile.dpr b/compiler/compile/compile.dpr new file mode 100755 index 00000000..2fcc7059 --- /dev/null +++ b/compiler/compile/compile.dpr @@ -0,0 +1,82 @@ +(* AMX Mod X +* compile.exe +* +* by the AMX Mod X Development Team +* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +*) + +program compile; + +{$APPTYPE CONSOLE} + +uses + SysUtils, Classes, + uFunc in 'uFunc.pas'; + +var + sr: TSearchRec; + i: Word; +begin + if not FileExists(ExtractFilePath(ParamStr(0))+'amxxsc.exe') then + begin + WriteLn('Could not find amxxsc.exe'); + AppExit; + end; + + if not DirectoryExists(ExtractFilePath(ParamStr(0))+'compiled') then + CreateDir(ExtractFilePath(ParamStr(0))+'compiled'); + + if ( ParamCount > 0 ) then + begin + for i := 1 to ParamCount do + begin + if FileExists(ParamStr(i)) then + CompilePlugin(ParamStr(i)) + else + begin + WriteLn; + WriteLn('File not found.'); + end; + end; + end + else + begin + if ( FindFirst('*.sma',faAnyFile,sr) = 0 ) then + begin + repeat + CompilePlugin(sr.Name); + until ( FindNext(sr) <> 0 ); + end + else + begin + WriteLn('No file found.'); + end; + FindClose(sr); + end; + + AppExit; +end. diff --git a/compiler/compile/uFunc.pas b/compiler/compile/uFunc.pas new file mode 100755 index 00000000..9e69238d --- /dev/null +++ b/compiler/compile/uFunc.pas @@ -0,0 +1,196 @@ +(* AMX Mod X +* compile.exe +* +* by the AMX Mod X Development Team +* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +*) + +unit uFunc; + +interface + +uses + Windows, SysUtils, Classes, Math, IniFiles; + +procedure AppExit; +procedure CompilePlugin(const Name: String); +function GetAgeFromDat(const FileName: String): Integer; +procedure SetAgeToDat(const FileName: String; const Age: Integer); +function GetConsoleOutput(const Command: String; var Output: TStringList): Boolean; + +implementation + +procedure AppExit; +begin + WriteLn; + Write('Press enter to exit ...'); + ReadLn; + Halt; +end; + +procedure CompilePlugin(const Name: String); +var + Output: TStringList; + i: Word; + cStart,cEnd: Longword; + FileName, FilePath, Compiled: String; +begin + FileName := ExtractFileName(Name); + FilePath := ExtractFilePath(Name); + Compiled := FilePath+'compiled\'+ChangeFileExt(Filename,'.amxx'); + if (FilePath='') then + FilePath := ExtractFilePath(ParamStr(0)); + + if FileExists(Compiled) and ( GetAgeFromDat(FileName)=FileAge(Name) ) then + Exit; + + WriteLn; + WriteLn('//// '+ExtractFileName(FileName)); + Output := TStringList.Create; + + try + cStart := GetTickCount; + if not GetConsoleOutput(ExtractFilePath(ParamStr(0))+'amxxsc.exe "'+FilePath+FileName+'" "-o'+Compiled+'"',Output) then + begin + WriteLn('Internal error.'); + AppExit; + end; + cEnd := GetTickCount; + + for i := 2 to (Output.Count-1) do + begin + WriteLn('// '+Output.Strings[i]); + end; + + WriteLn('//'); + WriteLn('// Compilation Time: '+FloatToStr(SimpleRoundTo((cEnd-cStart) / 1000,-2))+' sec'); + WriteLn('// ----------------------------------------'); + Output.Free; + except + WriteLn('Internal error.'); + AppExit; + end; + + SetAgeToDat(FileName,FileAge(Name)); +end; + +function GetAgeFromDat(const FileName: String): Integer; +var + Ini: TIniFile; +begin + Ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'compile.dat'); + Result := Ini.ReadInteger(FileName,'Age',-1); + Ini.Free; +end; + +procedure SetAgeToDat(const FileName: String; const Age: Integer); +var + Ini: TIniFile; +begin + Ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'compile.dat'); + Ini.WriteInteger(FileName,'Age',Age); + Ini.UpdateFile; + Ini.Free; +end; + +function GetConsoleOutput(const Command: String; var Output: TStringList): Boolean; +var + StartupInfo: TStartupInfo; + ProcessInfo: TProcessInformation; + SecurityAttr: TSecurityAttributes; + PipeOutputRead: THandle; + PipeOutputWrite: THandle; + PipeErrorsRead: THandle; + PipeErrorsWrite: THandle; + Succeed: Boolean; + Buffer: array [0..255] of Char; + NumberOfBytesRead: DWORD; + Stream: TMemoryStream; +begin + FillChar(ProcessInfo, SizeOf(TProcessInformation), 0); + + FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0); + SecurityAttr.nLength := SizeOf(SecurityAttr); + SecurityAttr.bInheritHandle := true; + SecurityAttr.lpSecurityDescriptor := nil; + + CreatePipe(PipeOutputRead, PipeOutputWrite, @SecurityAttr, 0); + CreatePipe(PipeErrorsRead, PipeErrorsWrite, @SecurityAttr, 0); + + FillChar(StartupInfo, SizeOf(TStartupInfo), 0); + StartupInfo.cb:=SizeOf(StartupInfo); + StartupInfo.hStdInput := 0; + StartupInfo.hStdOutput := PipeOutputWrite; + StartupInfo.hStdError := PipeErrorsWrite; + StartupInfo.wShowWindow := SW_HIDE; + StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; + + if CreateProcess(nil, PChar(command), nil, nil, true, + CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, + StartupInfo, ProcessInfo) then begin + Result := True; + CloseHandle(PipeOutputWrite); + CloseHandle(PipeErrorsWrite); + + Stream := TMemoryStream.Create; + try + while true do begin + Succeed := ReadFile(PipeOutputRead, Buffer, 255, NumberOfBytesRead, nil); + if not Succeed then Break; + Stream.Write(Buffer, NumberOfBytesRead); + end; + Stream.Position := 0; + Output.LoadFromStream(Stream); + finally + Stream.Free; + end; + CloseHandle(PipeOutputRead); + + try + while True do + begin + Succeed := ReadFile(PipeErrorsRead, Buffer, 255, NumberOfBytesRead, nil); + if not Succeed then Break; + end; + finally + end; + CloseHandle(PipeErrorsRead); + + WaitForSingleObject(ProcessInfo.hProcess, INFINITE); + CloseHandle(ProcessInfo.hProcess); + end + else + begin + Result := False; + CloseHandle(PipeOutputRead); + CloseHandle(PipeOutputWrite); + CloseHandle(PipeErrorsRead); + CloseHandle(PipeErrorsWrite); + end; +end; + +end.