From 6680df87dc92eb6f1b80a068296c42295460dd25 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 30 May 2016 11:58:50 +0200 Subject: Macros auch mit "%" beenden, kleinere Korrekturen --- .gitignore | 2 +- Make.1.in | 39 ++++++++---------- Make.lps | 104 ++++++++++++++++++++++++---------------------- dateibeziehungen.pas | 114 +++++++++++++++++++++++++++++---------------------- 4 files changed, 140 insertions(+), 119 deletions(-) diff --git a/.gitignore b/.gitignore index a448883..b8a42cb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ *.out Machdatei Make -Make.8 +Make.1 lib ewemake *~ diff --git a/Make.1.in b/Make.1.in index 766e8de..1060668 100644 --- a/Make.1.in +++ b/Make.1.in @@ -63,37 +63,34 @@ Commands on one line are concatenated with \fB&&\fP instead of \fB;\fP \- to use .SH SUBSTITUTIONS Some substitutions and macros are recognized. Obviously, substitutions marked with \fB(*)\fP are only available in COMMAND- and TARGET-DEFINITION lines. +Number parameters may be omitted from back to front and default to \fI0\fP unless otherwise noted. .TP -.B "%nurmit'filePart'" (*) -only execute command / generate target name from source file if name of source file contains \fIfilePart\fP +.B "%nurmit\fIn\fP'filePart'%" (*) +only execute command / generate target name from source file if name of \fIn\fP-th source file contains \fIfilePart\fP .TP -.B "%nurohne'filePart'" (*) -opposite of \fB%nurmit'filePart'\fP +.B "%nurohne\fIn\fP'filePart'%" (*) +opposite of \fB%nurmit'filePart'%\fP .TP -.B "%in" (*) -file name and path of source file +.B "%in\fIn\fP%" (*) +file name and path of \fIn\fP-th source file .TP -.B "%ifile" (*) -file name of source file +.B "%ifile\fIn\fP%" (*) +file name of \fIn\fP-th source file .TP -.B "%basename" (*) -file name of source file without extension(s) +.B "%basename\fIn\fP%" (*) +file name of \fIn\fP-th source file without extension(s) .TP -.B "%dirname(num1,num2)" (*) -components \fInum1\fP upto \fInum2\fP of path to source file. -Negative numbers are counted from the back - e.g. \fB-1\fP is the last path component, etc. -\fInum2\fP may be omitted, it defaults to \fB-1\fP. +.B "%dirname\fIn1\fP,\fIn2\fP,\fIn3\fP%" (*) +components \fIn1\fP upto \fIn2\fP of path to \fIn3\fP-th source file. +Negative numbers \fIn1\fP or \fIn2\fP are counted from the back - e.g. \fB-1\fP is the last path component, etc. +If omitted, \fIn2\fP defaults to \fI-1\fP. .TP -.B "%dirname" (*) -path so source file. -Identical to \fB%dirname(0)\fP. -.TP -.B "%DIRNAME" +.B "%DIRNAME%" path to \fIMachdatei\fP .TP -.B "%num'string'" +.B "%num'string'%" last decimal number in \fIstring\fP. -E.g. \fB%num'abc123def456ghi'\fP becomes \fB456\fP. +E.g. \fB%num'abc123def456ghi'%\fP becomes \fB456\fP. .SH AUTHOR .nf Erich Eckner diff --git a/Make.lps b/Make.lps index daa101f..746e678 100644 --- a/Make.lps +++ b/Make.lps @@ -3,30 +3,29 @@ - + - + - + - + - - - - - + + + + @@ -36,17 +35,18 @@ - + + - - - - + + + + @@ -123,125 +123,133 @@ + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + - - + + - - + + - + - + - + - + - + - + - + - - + + - - + + - - + + - + - + diff --git a/dateibeziehungen.pas b/dateibeziehungen.pas index c244a79..dbfa552 100644 --- a/dateibeziehungen.pas +++ b/dateibeziehungen.pas @@ -326,70 +326,86 @@ end; function tGenerischeAbhaengigkeit.quellersetzung(var worin: string; quellen: tDateienMitDaten; momentanePosition: longint): boolean; var - s,anfang,mitte: string; - i,li,re,qNum: longint; - tmpRE: tRegExpr; + s,anfang,mitte,numStr: string; + i,li,re,qNum: longint; + tmpRE: tRegExpr; begin result:=true; - for qNum:=0 to momentanePosition-1 do begin - ersetzeAlleVorkommen(worin,'%in('+inttostr(qNum)+')',quellen[qnum].name); - s:=extractfilename(quellen[qnum].name); - ersetzeAlleVorkommen(worin,'%ifile('+inttostr(qNum)+')',s); + for qNum:=-byte(momentanePosition>0) to momentanePosition-1 do begin + if qNum<0 then + numStr:='' + else + numStr:=inttostr(qnum); + s:=quellen[qnum+byte(qnum<0)].name; + ersetzeAlleVorkommen(worin,'%in'+numStr+'%',s); // %in% + s:=extractfilename(s); + ersetzeAlleVorkommen(worin,'%ifile'+numStr+'%',s); // %ifile% if pos('.',s)>0 then delete(s,pos('.',s),length(s)); - ersetzeAlleVorkommen(worin,'%basename('+inttostr(qNum)+')',s); - - while pos('%dirname('+inttostr(qNum)+',',worin)>0 do begin - anfang:=erstesArgument(worin,'%dirname('+inttostr(qNum)+',',false); - mitte:=erstesArgument(worin,')',false); - s:=extractfilepath(quellen[qnum].name); - if rightStr(s,1)='/' then - delete(s,length(s),1); - i:=anzCs('/',s)+1; - li:=strtoint(trim(erstesArgument(mitte,',',false))); - if li<0 then li:=li+i; - if mitte='' then - re:=0 - else - re:=strtoint(mitte); - if re<=0 then re:=re+i; - while li>0 do begin - dec(li); - dec(re); - erstesArgument(s,'/',false); - end; - mitte:=''; - while re>0 do begin - dec(re); - mitte:=mitte+'/'+erstesArgument(s,'/',false); - end; - delete(mitte,1,1); - worin:=anfang+mitte+worin; - end; + ersetzeAlleVorkommen(worin,'%basename'+numStr+'%',s); // %basename% + end; + + while pos('%dirname',worin)>0 do begin // %dirname% + anfang:=erstesArgument(worin,'%dirname',false); + mitte:=erstesArgument(worin,'%',false); + if mitte='' then + li:=0 + else + li:=strtoint(erstesArgument(mitte,',',true)); + if mitte='' then + re:=-1 + else + re:=strtoint(erstesArgument(mitte,',',true)); + if mitte='' then + qNum:=0 + else + qNum:=strtoint(erstesArgument(mitte,',',true)); + + if qNum>=momentanePosition then + fehler('Quellersetzung sieht ''%dirname%'' für Quelle Nummer '+inttostr(qNum)+' an Position '+inttostr(momentanePosition)+'.'); s:=extractfilepath(quellen[qnum].name); if rightStr(s,1)='/' then delete(s,length(s),1); - ersetzeAlleVorkommen(worin,'%dirname('+inttostr(qnum)+')',s); + i:=anzCs('/',s)+1; + if li<0 then li:=li+i; + if re<0 then re:=re+i; + while li>0 do begin + dec(li); + dec(re); + erstesArgument(s,'/',false); + end; + mitte:=''; + while re>=0 do begin + dec(re); + mitte:=mitte+'/'+erstesArgument(s,'/',false); + end; + delete(mitte,1,1); + worin:=anfang+mitte+worin; end; - allgemeineErsetzungen(worin,machDatei); + allgemeineErsetzungen(worin,machDatei); // %DIRNAME% %num'...'% result:=false; tmpRE:=tRegExpr.create; - for qNum:=0 to momentanePosition-1 do begin - while pos('%nurmit('+inttostr(qnum)+')''',worin)>0 do begin - anfang:=erstesArgument(worin,'%nurmit('+inttostr(qnum)+')''',false); - tmpRE.expression:=erstesArgument(worin,'''',false); - if not tmpRE.exec(quellen[qnum].name) then begin + for qNum:=-byte(momentanePosition>0) to momentanePosition-1 do begin + if qNum<0 then + numStr:='' + else + numStr:=inttostr(qnum); + s:=quellen[qnum+byte(qnum<0)].name; + while pos('%nurmit'+numStr+'''',worin)>0 do begin // %nurmit'...'% + anfang:=erstesArgument(worin,'%nurmit'+numStr+'''',false); + tmpRE.expression:=erstesArgument(worin,'''%',false); + if not tmpRE.exec(s) then begin tmpRE.free; exit; end; worin:=anfang+worin; end; - while pos('%nurohne('+inttostr(qnum)+')''',worin)>0 do begin - anfang:=erstesArgument(worin,'%nurohne('+inttostr(qnum)+')''',false); - tmpRE.expression:=erstesArgument(worin,'''',false); - if tmpRE.exec(quellen[qnum].name) then begin + while pos('%nurohne'+numStr+'''',worin)>0 do begin // %nurohne'...'% + anfang:=erstesArgument(worin,'%nurohne'+numStr+'''',false); + tmpRE.expression:=erstesArgument(worin,'''%',false); + if tmpRE.exec(s) then begin tmpRE.free; exit; end; @@ -1064,10 +1080,10 @@ begin s:=extractfilepath(machDatei); if rightStr(s,1)='/' then delete(s,length(s),1); - ersetzeAlleVorkommen(worin,'%DIRNAME',s); + ersetzeAlleVorkommen(worin,'%DIRNAME%',s); while pos('%num''',worin)>0 do begin anfang:=erstesArgument(worin,'%num'''); - mitte:=erstesArgument(worin,''''); + mitte:=erstesArgument(worin,'''%'); for i:=length(mitte) downto 1 do if mitte[i] in ['0'..'9'] then break -- cgit v1.2.3-54-g00ecf