diff options
author | Erich Eckner <git@eckner.net> | 2017-07-18 09:26:29 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-07-20 12:11:16 +0200 |
commit | 2798b395bc067293d3a7d338a792224da17854e3 (patch) | |
tree | 2f2edf0b5944a0e01b77029516b3236695cd92be /lowlevelunit.pas | |
parent | 1d177b0eb1bcbea486318d5a68dc5f7c1b0e39df (diff) | |
download | units-2798b395bc067293d3a7d338a792224da17854e3.tar.xz |
homogenisiere Grosz-Klein-Schreibung
Diffstat (limited to 'lowlevelunit.pas')
-rw-r--r-- | lowlevelunit.pas | 203 |
1 files changed, 102 insertions, 101 deletions
diff --git a/lowlevelunit.pas b/lowlevelunit.pas index a9fdb1e..1198fdd 100644 --- a/lowlevelunit.pas +++ b/lowlevelunit.pas @@ -8,7 +8,7 @@ uses math, Classes, SysUtils, RegExpr, process, FPimage, Graphics; type - generic tArray<T> = array of T; + generic tArray<t> = array of t; tInt64Array = specialize tArray<int64>; tLongintArray = specialize tArray<longint>; pTLongintArray = ^tLongintArray; @@ -34,10 +34,11 @@ type rgbGreen: byte; rgbRed : byte; end; - tRgbArray = specialize tArray<tRGB>; + tRGBArray = specialize tArray<tRGB>; tKodierung = (kUnbekannt,k32BitSignedInteger); tWarnstufe = (wsStreng,wsLasch); tGenauigkeit = (gSingle,gDouble,gExtended); + tKantenFilterTyp = (kfTiefpass,kfHochpass); operator = (x1,x2: t2x2Extended): boolean; operator = (x1,x2: tInt64Point): boolean; @@ -56,7 +57,7 @@ function myIntToStr(i,dg: longint; fill: string): string; overload; function max(g1,g2: tGenauigkeit): tGenauigkeit; inline; overload; function wertGroesze(g: tGenauigkeit): longint; -function floattostrtrunc(f: extended; dig: longint; laessig: boolean): string; +function floatToStrTrunc(f: extended; dig: longint; laessig: boolean): string; function binOpPos(op: char; s: string): integer; function fktPos(fkt,s: string): integer; procedure gibAus(s: string; ausgaben: byte); @@ -73,16 +74,16 @@ function rgb(r,g,b: byte): tRGB; inline; function strToTRGB(s: string; out rgb: tRGB): boolean; procedure myDebugLnThreadLog(s: string); procedure cleanupLogs; -procedure cleanupLog(tid: PtrUInt); +procedure cleanupLog(tid: ptrUInt); procedure raiseAndDumpExceptionCallStack(msg: string); -procedure dumpExceptionCallStack(E: Exception); +procedure dumpExceptionCallStack(e: exception); function startetMit(start: string; var s: string): boolean; function endetMit(ende: string; var s: string): boolean; function trimAll(s: string): string; -function erstesArgument(var s: string; Trenner: string = ' '; trimmen: boolean = true): string; inline; +function erstesArgument(var s: string; trenner: string = ' '; trimmen: boolean = true): string; inline; function umbrechen(s,trenner: string; klammernBeachten: boolean = false; zeilenanfang: string = ''): string; inline; function unEscape(s: string): string; -function mydatetimetostr(t: tDateTime): string; +function myDateTimeToStr(t: tDateTime): string; function t2x2ExtendedToStr(p: t2x2Extended): string; function t2x2LongintToStr(p: t2x2Longint): string; function tExtPointToStr(p: tExtPoint): string; @@ -104,7 +105,7 @@ function mirrorBits(lw: longword): longword; overload; function mirrorBits(w: word): word; overload; function mirrorBits(b: byte): byte; overload; -function zusammenfassen(s1,s2: string): string; +function zusammenFassen(s1,s2: string): string; function intervallAusrollen(s: string): string; function myUtf8Encode(s: string): string; function permutation(len: longint): tLongintArray; overload; @@ -180,31 +181,31 @@ var tim: int64; begin tim:=floor(t*24*60*60); - result:=inttostr(tim mod 10)+'s'; + result:=intToStr(tim mod 10)+'s'; tim:=tim div 10; if tim=0 then exit; - result:=inttostr(tim mod 6)+result; + result:=intToStr(tim mod 6)+result; tim:=tim div 6; if tim=0 then exit; - result:=inttostr(tim mod 10)+'min '+result; + result:=intToStr(tim mod 10)+'min '+result; tim:=tim div 10; if tim=0 then exit; - result:=inttostr(tim mod 6)+result; + result:=intToStr(tim mod 6)+result; tim:=tim div 6; if tim=0 then exit; - result:=inttostr(tim mod 24)+'h '+result; + result:=intToStr(tim mod 24)+'h '+result; tim:=tim div 24; if tim=0 then exit; result:=' '+result; if (tim mod 7)<>1 then result:='e'+result; - result:=inttostr(tim mod 7)+'Tag'+result; + result:=intToStr(tim mod 7)+'Tag'+result; tim:=tim div 7; if tim=0 then exit; result:=' '+result; if tim<>1 then result:='n'+result; - result:=inttostr(tim)+'Woche'+result; + result:=intToStr(tim)+'Woche'+result; end; function cmpStr(s1,s2: string): longint; @@ -228,7 +229,7 @@ var i: longint; w,nw: word; begin - setlength(result,max(length(s1),length(s2))); + setLength(result,max(length(s1),length(s2))); w:=0; for i:=length(result) downto 1 do begin // result:= "s1+s2"; if i<=length(s1) then @@ -256,7 +257,7 @@ end; function myFloatToStr(x: extended): string; begin - result:=myFloatToStr(x,'E'); + result:=myFloatToStr(x,'e'); end; function myFloatToStr(x: extended; ex: string): string; @@ -288,7 +289,7 @@ begin result:=result+char(ord('0')+floor(x)); end; if e<>0 then - result:=result+ex+inttostr(e); + result:=result+ex+intToStr(e); end; function myStrToFloat(s: string): extended; @@ -296,13 +297,13 @@ var i,e: longint; neg: boolean; begin - if pos('E',s)>0 then begin - e:=strtoint(rightStr(s,length(s)-pos('E',s))); - delete(s,pos('E',s),length(s)); + if pos('e',s)>0 then begin + e:=strToInt(rightStr(s,length(s)-pos('e',s))); + delete(s,pos('e',s),length(s)); end else e:=0; if pos('.',s)=0 then begin - result:=strtoint(s)*power(10,e); + result:=strToInt(s)*power(10,e); exit; end; neg:=leftStr(s,1)='-'; @@ -327,7 +328,7 @@ end; function myIntToStr(i,dg: longint; fill: string): string; begin - result:=inttostr(i); + result:=intToStr(i); while length(result)<dg do result:=fill+result; end; @@ -341,9 +342,9 @@ end; function wertGroesze(g: tGenauigkeit): longint; begin case g of - gSingle: result:=sizeof(single); - gDouble: result:=sizeof(double); - gExtended: result:=sizeof(extended); + gSingle: result:=sizeOf(single); + gDouble: result:=sizeOf(double); + gExtended: result:=sizeOf(extended); else fehler('Unbekannter Genauigkeitstyp!'); end; @@ -351,9 +352,9 @@ end; // allgemeine Funktionen ******************************************************* -function floattostrtrunc(f: extended; dig: longint; laessig: boolean): string; +function floatToStrTrunc(f: extended; dig: longint; laessig: boolean): string; begin - result:=inttostr(round(f*power(10,dig))); + result:=intToStr(round(f*power(10,dig))); result:=copy(result,1,length(result)-dig)+'.'+copy(result,length(result)-dig+1,dig); if laessig then while result[length(result)]='0' do @@ -362,30 +363,30 @@ begin delete(result,length(result),1); end; -function ZeitDarstellen(t: extended): string; +function zeitDarstellen(t: extended): string; var schreibe: boolean; begin result:='('; schreibe:=t>=1; if schreibe then begin - result:=result+inttostr(floor(t))+' Tage '; + result:=result+intToStr(floor(t))+' Tage '; t:=t-floor(t); end; t:=t*24; schreibe:=schreibe or (t>=1); if schreibe then begin - result:=inttostr(floor(t))+':'; + result:=intToStr(floor(t))+':'; t:=t-floor(t); end; t:=t*60; schreibe:=schreibe or (t>=1); if schreibe then begin - result:=inttostr(floor(t))+':'; + result:=intToStr(floor(t))+':'; t:=t-floor(t); end; t:=t*60; - result:=result+inttostr(round(t))+' s)'; + result:=result+intToStr(round(t))+' s)'; end; function binOpPos(op: char; s: string): integer; @@ -393,7 +394,7 @@ begin result:=0; repeat result:=result+max(1,pos(op,copy(s,result+1,length(s)-result))); - until ((result>1) and not (s[result-1] in ['+','-','*','/','(','E','e','^'])) or (result>length(s)) or (s[result]<>op); + until ((result>1) and not (s[result-1] in ['+','-','*','/','(','e','E','^'])) or (result>length(s)) or (s[result]<>op); if (result>length(s)) or (s[result]<>op) then result:=0; end; @@ -534,45 +535,45 @@ end; procedure myDebugLnThreadLog(s: string); var - f: textfile; - id: PtrUInt; + f: textFile; + id: ptrUInt; begin id:=getThreadID; - assignfile(f,'Log'+inttostr(id)); + assignFile(f,'Log'+intToStr(id)); try - if fileexists('Log'+inttostr(id)) then append(f) + if fileExists('Log'+intToStr(id)) then append(f) else rewrite(f); except exit; end; - writeln(f,inttostr(id)+': '+s); - closefile(f); + writeln(f,intToStr(id)+': '+s); + closeFile(f); end; procedure cleanupLogs; var - sr: tSearchRec; + sR: tSearchRec; err: longint; begin - err:=findfirst('Log*',$3f,sr); + err:=findFirst('Log*',$3f,sR); while err=0 do begin - deletefile(sr.name); - err:=findnext(sr); + deleteFile(sR.name); + err:=findnext(sR); end; - findclose(sr); + findclose(sR); end; -procedure cleanupLog(tid: PtrUInt); +procedure cleanupLog(tid: ptrUInt); var s: string; - Zeit: extended; + zeit: extended; begin - s:='Log'+inttostr(tid); - Zeit:=now+1/24/60/60; - while (not fileexists(s)) and (Zeit>now) do + s:='Log'+intToStr(tid); + zeit:=now+1/24/60/60; + while (not fileExists(s)) and (zeit>now) do sleep(100); - if fileexists(s) then - deletefile(s) + if fileExists(s) then + deleteFile(s) else fehler('Datei '''+s+''' kann nicht gelöscht werden, da sie nicht existiert!'); end; @@ -588,21 +589,21 @@ end; procedure dumpExceptionCallStack(e: exception); var - I: integer; - Frames: pPointer; - Report: string; -begin - Report := 'Program exception! ' + LineEnding + - 'Stacktrace:' + LineEnding + LineEnding; - if E <> nil then begin - Report := Report + 'Exception class: ' + E.ClassName + LineEnding + - 'Message: ' + E.Message + LineEnding; + i: integer; + frames: pPointer; + report: string; +begin + report := 'Program exception! ' + lineEnding + + 'Stacktrace:' + lineEnding + lineEnding; + if e <> nil then begin + report := report + 'Exception class: ' + e.className + lineEnding + + 'Message: ' + e.message + lineEnding; end; - Report := Report + BackTraceStrFunc(ExceptAddr); - Frames := ExceptFrames; - for I := 0 to ExceptFrameCount - 1 do - Report := Report + LineEnding + BackTraceStrFunc(Frames[I]); - gibAus(Report,3); + report := report + backTraceStrFunc(exceptAddr); + frames := exceptFrames; + for i := 0 to exceptFrameCount - 1 do + report := report + lineEnding + backTraceStrFunc(frames[i]); + gibAus(report,3); end; function startetMit(start: string; var s: string): boolean; @@ -626,10 +627,10 @@ begin delete(result,pos(' ',result),1); end; -function erstesArgument(var s: string; Trenner: string; trimmen: boolean): string; +function erstesArgument(var s: string; trenner: string; trimmen: boolean): string; begin - result:=copy(s,1,pos(Trenner,s+Trenner)-1); - delete(s,1,length(result)+length(Trenner)); + result:=copy(s,1,pos(trenner,s+trenner)-1); + delete(s,1,length(result)+length(trenner)); if not trimmen then exit; s:=trim(s); result:=trim(result); @@ -682,7 +683,7 @@ begin fehler(''''+s+''' endet auf einen aktiven Deaktivierer!'); end; -function mydatetimetostr(t: tDateTime): string; +function myDateTimeToStr(t: tDateTime): string; begin result:=formatDateTime('YYYY.MM.DD_hh.mm.ss',t); end; @@ -697,8 +698,8 @@ end; function t2x2LongintToStr(p: t2x2Longint): string; begin result:= - inttostr(p['x','x'])+' .. '+inttostr(p['x','y'])+' x '+ - inttostr(p['y','x'])+' .. '+inttostr(p['y','y']); + intToStr(p['x','x'])+' .. '+intToStr(p['x','y'])+' x '+ + intToStr(p['y','x'])+' .. '+intToStr(p['y','y']); end; function tExtPointToStr(p: tExtPoint): string; @@ -708,7 +709,7 @@ end; function tIntPointToStr(p: tIntPoint): string; begin - result:=inttostr(p['x'])+';'+inttostr(p['y']); + result:=intToStr(p['x'])+';'+intToStr(p['y']); end; procedure fehler(s: string); @@ -751,7 +752,7 @@ var begin result:=''; for i:=cnt-1 downto 0 do - result:=result+inttohex((pByte(p)+i)^,2); + result:=result+intToHex((pByte(p)+i)^,2); end; function base64ToBin(var s: string): boolean; @@ -800,7 +801,7 @@ end; function base64Encode(i: longword): string; begin - result:=base64Encode(i,(8*sizeof(i)+7) div 6); + result:=base64Encode(i,(8*sizeOf(i)+7) div 6); end; function base64Encode(i,siz: longword): string; @@ -848,13 +849,13 @@ begin (byte(odd(b)) shl 7); end; -function zusammenfassen(s1,s2: string): string; +function zusammenFassen(s1,s2: string): string; var i: longint; begin if istGanzZahl(s1) and istGanzZahl(s2) then begin - i:=strtoint(s1)+strtoint(s2); - result:=inttostr(i); + i:=strToInt(s1)+strToInt(s2); + result:=intToStr(i); if (startetMit('+',s1) or startetMit('+',s2)) and (i>=0) then result:='+'+result; end @@ -866,10 +867,10 @@ function intervallAusrollen(s: string): string; var i: longint; begin - i:=strtoint(erstesArgument(s,'..')); + i:=strToInt(erstesArgument(s,'..')); result:=''; - while i<=strtoint(s) do begin - result:=result+' '+myinttostr(i,length(s),'0'); + while i<=strToInt(s) do begin + result:=result+' '+myIntToStr(i,length(s),'0'); inc(i); end; result:=trim(result); @@ -897,12 +898,12 @@ const begin rest:=len; ilen:=len; - setlength(basen,0); + setLength(basen,0); repeat for i:=maxBasis downto 2 do while ((rest mod i) = 0) and (rest>maxBasis) do begin - setlength(basen,length(basen)+1); + setLength(basen,length(basen)+1); basen[length(basen)-1]:=i; rest:=rest div i; end; @@ -930,7 +931,7 @@ begin result[i]:=result[i+off]; inc(i); end; - setlength(result,len); + setLength(result,len); end; end; @@ -942,14 +943,14 @@ var aWerte: boolean; begin for aWerte:=false to true do - setlength(werte[aWerte],len); + setLength(werte[aWerte],len); aWerte:=false; for block:=0 to (len div rest)-1 do // Initialisierung der $\prod_i basis[i]$ Blöcke zu je $rest$ permutierten Zahlen llPermutation(rest,block*rest,werte[aWerte]); - setlength(mergePerm,maxBasis); + setLength(mergePerm,maxBasis); for i:=0 to length(basen)-1 do begin for block:=0 to (len div (rest*basen[i]))-1 do begin @@ -965,14 +966,14 @@ begin rest:=rest*basen[i]; end; - setlength(mergePerm,0); + setLength(mergePerm,0); - setlength(result,length(werte[aWerte])); + setLength(result,length(werte[aWerte])); if length(result)>0 then - move(werte[aWerte][0],result[0],length(result)*sizeof(result[0])); + move(werte[aWerte][0],result[0],length(result)*sizeOf(result[0])); for aWerte:=false to true do - setlength(werte[aWerte],0); + setLength(werte[aWerte],0); end; procedure llPermutation(len,offset: longint; var ar: tLongintArray); @@ -992,7 +993,7 @@ begin end; for i:=0 to len-1 do if ar[i+offset]=-1 then - fehler('permutation: '+inttostr(i)+' wurde nicht verteilt!'); + fehler('permutation: '+intToStr(i)+' wurde nicht verteilt!'); end; procedure fuegeSortiertHinzu(x: extended; var xa: tExtendedArray); @@ -1011,8 +1012,8 @@ begin exit; end; if mi<>ma+1 then - fehler('Bisektion fehlgeschlagen! ('+inttostr(mi)+' = mi <> ma+1 = '+inttostr(ma+1)+')'); - setlength(xa,length(xa)+1); + fehler('Bisektion fehlgeschlagen! ('+intToStr(mi)+' = mi <> ma+1 = '+intToStr(ma+1)+')'); + setLength(xa,length(xa)+1); for i:=length(xa)-1 downto mi+1 do xa[i]:=xa[i-1]; xa[mi]:=x; @@ -1028,26 +1029,26 @@ begin s:=''; while (pos(#10,s)=0) and (rLen+fPos<fSize) do begin rLen:=min(rLen+1024,fSize-fPos); - setlength(s,rLen); - blockread(f,s[1],rLen); + setLength(s,rLen); + blockRead(f,s[1],rLen); seek(f,fPos); end; if pos(#10,s)<>0 then begin rLen:=pos(#10,s); - setlength(s,rLen-1); + setLength(s,rLen-1); end; seek(f,fPos+rLen); end; procedure readAnAndorString(var f: file; out s: string; const len: int64; checkEOL: boolean); begin - setlength(s,len+2*byte(checkEOL)); + setLength(s,len+2*byte(checkEOL)); if length(s)>0 then - blockread(f,s[1],length(s)); + blockRead(f,s[1],length(s)); if checkEOL then begin if rightStr(s,2)<>' '#10 then raise exception.create('readAnAndorString: EOL check failed: '''+s+'''!'); - setlength(s,length(s)-2); + setLength(s,length(s)-2); end; end; @@ -1059,9 +1060,9 @@ end; procedure splitStrToInt(s: string; out ia: tLongintArray); begin - setlength(ia,0); + setLength(ia,0); while s<>'' do begin - setlength(ia,length(ia)+1); + setLength(ia,length(ia)+1); ia[length(ia)-1]:=strToInt(erstesArgument(s,' ',false)); end; end; |