@@ -32,8 +32,8 @@ interface
3232 defaultAlias: THashedStringList;
3333 staticVars: THashedStringList; // these scripting variables are held for the whole run-time
3434
35- function tryApplyMacrosAndSymbols (fs: TFileServer; var txt: String ; var md: TmacroData; removeQuotings: Boolean=true): Boolean;
36- function runScript (fs: TFileServer; const script:string ; table:TstringDynArray=NIL ; tpl_:Ttpl=NIL ; f:Tfile=NIL ; folder:Tfile=NIL ; cd:TconnDataMain=NIL ): String ;
35+ function tryApplyMacrosAndSymbols (fs: TFileServer; var txt: UnicodeString ; var md: TmacroData; removeQuotings: Boolean=true): Boolean;
36+ function runScript (fs: TFileServer; const script: UnicodeString ; table:TstringDynArray=NIL ; tpl_:Ttpl=NIL ; f:Tfile=NIL ; folder:Tfile=NIL ; cd:TconnDataMain=NIL ): UnicodeString ;
3737function runEventScript (fs: TFileServer; const event: String; table: TStringDynArray=NIL ; cd: TconnDataMain=NIL ): String;
3838procedure resetLog ();
3939procedure runTimedEvents (fs: TFileServer);
@@ -115,23 +115,27 @@ function encodeMarkers(s:string):string;
115115result:=s;
116116end ; // encodeMarkers
117117
118- function noMacrosAllowed (s:string):string ;
118+ function noMacrosAllowed (s: UnicodeString): UnicodeString ;
119119// prevent hack attempts
120120var
121121 i: integer;
122122begin
123+ if s = ' ' then
124+ Exit(' ' );
123125 i:=1 ;
124126 enforceNUL(s);
125127 repeat
126- i:=findMacroMarker(s, i);
127- if i = 0 then break;
128- replace(s, ' &#' +intToStr(charToUnicode(s[i]))+' ;' , i,i);
128+ i:=findMacroMarker(s, i);
129+ if i = 0 then
130+ break;
131+ replace(s, ' &#' +intToStr(charToUnicode(s[i]))+' ;' , i,i);
129132 until false;
130- s:=reReplace(s,' %([-a-z0-9]+%)' ,' %$1' , ' mi' );
131- result:=s;
133+ // s := reReplace(s,'%([-a-z0-9]+%)','%$1', 'mi');
134+ // result:=s;
135+ Result := ReplaceStr(s, ' %' ,' %' );
132136end ; // noMacrosAllowed
133137
134- function cbMacros (fs: TFileServer; const fullMacro: String ; pars: TPars; cbData: Pointer): String ;
138+ function cbMacros (fs: TFileServer; const fullMacro: UnicodeString ; pars: TPars; cbData: Pointer): UnicodeString ;
135139var
136140 md: ^TmacroData;
137141 name , p: string;
@@ -306,6 +310,20 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
306310 result := pars.ContainsKey(name );
307311 end ; // parExist
308312
313+ function parExistVal (const name : String; var val: String; doTrim: boolean=TRUE): boolean;
314+ begin
315+ Result := false;
316+ val := ' ' ;
317+ if name > ' ' then
318+ begin
319+ Result := pars.TryGetValue(name , val);
320+ if Result then
321+ if doTrim then
322+ val := trim(val)
323+ end ;
324+ end ; // parExistVal
325+
326+
309327 procedure trueIf (condition:boolean);
310328 begin if condition then result:=' 1' else result:=' ' end ;
311329
@@ -340,15 +358,15 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
340358 begin result:=getVarSpace(varname).values[varname] end ;
341359
342360 // if par with name exists, then it's a var name, otherwise it's a constant value at specified index
343- function parVar (parname:string ; idx:integer):string ; overload;
361+ function parVar (const parname: String ; idx: Integer): String ; overload;
344362 begin
345363 if parExist(parname) then
346364 result:=getVar(par(parname))
347365 else
348366 result:=pars[idx];
349367 end ; // parVar
350368
351- function setVar (varname, value :string ; space:THashedStringList=NIL ):boolean ;
369+ function setVar (varname: String; const value : String ; space: THashedStringList=NIL ): Boolean ;
352370 var
353371 o: Tobject;
354372 i: integer;
@@ -612,7 +630,7 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
612630 result:=macroQuote(result);
613631 end ; // section
614632
615- function urlVar (k:string):string ;
633+ function urlVar (const k: String): String ;
616634 var
617635 s: string;
618636 begin
@@ -629,10 +647,12 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
629647 except end ;
630648 end ; // urlVar
631649
632- function maybeUrlvar (k:string):string ;
650+ function maybeUrlvar (const k: String): String ;
633651 begin
634- if (k = ' ' ) or (k[1 ] <> ' ?' ) then result:=k
635- else result:=urlvar(copy(k,2 ,MAXINT));
652+ if (k = ' ' ) or (k[1 ] <> ' ?' ) then
653+ result := k
654+ else
655+ result := urlvar(copy(k,2 ,MAXINT));
636656 end ; // maybeUrlvar
637657
638658 function compare (op,p1,p2:string):boolean;
@@ -669,7 +689,7 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
669689 end ;
670690 end ; // infixOperators
671691
672- procedure call (code:string ; ofs:integer =0 );
692+ procedure call (const code: String ; ofs: Integer =0 );
673693 var
674694 i: integer;
675695 begin
@@ -823,9 +843,10 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
823843
824844 if p = ' virtual' then
825845 begin
826- name :=par(1 );
827- if not validateAndExtractParent() then exit;
828- f:=Tfile.createVirtualFolder(fs.rootFile.mainTree, name );
846+ name :=par(1 );
847+ if not validateAndExtractParent() then
848+ exit;
849+ f := Tfile.createVirtualFolder(fs.rootFile.mainTree, name );
829850 end
830851 else
831852 begin
@@ -882,11 +903,13 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
882903 uniqueStrings(result);
883904 end ;
884905
885- procedure setAttr (a:TfileAttribute; parName:string);
906+ procedure setAttr (a: TfileAttribute; const parName: String);
907+ var
908+ v: String;
886909 begin
887- if parExist (parname) then
910+ if parExistVal (parname, v ) then
888911 try
889- if isTrue(parEx(parname) ) then
912+ if isTrue(v ) then
890913 include(f.flags, a)
891914 else
892915 exclude(f.flags, a);
@@ -903,7 +926,7 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
903926 f.setDynamicComment(LP, macroDequote(parEx(' comment' )))
904927 except end ;
905928 try
906- f.name := parEx(' name' );
929+ f.name := parEx(' name' );
907930 if assigned(f.node) then
908931 f.node.text:=f.name ;
909932 except end ;
@@ -1292,10 +1315,9 @@ function cbMacros(fs: TFileServer; const fullMacro: String; pars: TPars; cbData:
12921315 i: integer;
12931316 v: string;
12941317 begin
1295- if parExist (' var' ) then
1318+ if parExistVal (' var' , v ) then
12961319 try
1297- v := parEx(' var' );
1298- result:=getVar(v);
1320+ result := getVar(v);
12991321 except
13001322 result := pars[pars.count-1 ]
13011323 end
@@ -1349,8 +1371,8 @@ t_s2c = record s: String; val: byte; end;
13491371 if not icon and buttons then
13501372 inc(code, MB_ICONQUESTION);
13511373 case msgDlg(p, code, par(2 )) of
1352- MRYES, MROK: result:= if_(buttons, ' 1' ); // if only OK button is available, then return nothing
1353- MRCANCEL: result:= if_(code and MB_YESNOCANCEL = MB_YESNOCANCEL, ' cancel' ); // for the YESNOCANCEL, we return cancel to allow to tell NO from CANCEL
1374+ MRYES, MROK: result := if_(buttons, ' 1' ); // if only OK button is available, then return nothing
1375+ MRCANCEL: result := if_(code and MB_YESNOCANCEL = MB_YESNOCANCEL, ' cancel' ); // for the YESNOCANCEL, we return cancel to allow to tell NO from CANCEL
13541376 else result:=' ' ;
13551377 end ;
13561378 end ; // dialog
@@ -1658,8 +1680,9 @@ t_s2c = record s: String; val: byte; end;
16581680 end ; // getPairs
16591681
16601682 begin
1661- if not satisfied(md.cd) then exit;
1662- result:=' ' ;
1683+ if not satisfied(md.cd) then
1684+ exit;
1685+ result:=' ' ;
16631686 if parExist(' value' ) then
16641687 try md.cd.conn.setCookie(p, parEx(' value' ), getPairs());
16651688 except result:=noMacrosAllowed(md.cd.conn.getCookie(p)) end // there was no "value" to set, so just read
@@ -1699,11 +1722,12 @@ t_s2c = record s: String; val: byte; end;
16991722 setVar(parEx(' sub' ), s);
17001723 except end ;
17011724
1702- try
1703- result:=reReplace(subj, p, parEx(' replace' ), mods);
1704- setVar(parEx(' var' ), result); // we put the output where we got the input
1705- result:=' ' ;
1706- except end ;
1725+ try
1726+ result:=reReplace(subj, p, parEx(' replace' ), mods);
1727+ setVar(parEx(' var' ), result); // we put the output where we got the input
1728+ result:=' ' ;
1729+ except
1730+ end ;
17071731 end ; // regexp
17081732
17091733 procedure dir ();
@@ -1926,7 +1950,7 @@ t_s2c = record s: String; val: byte; end;
19261950 end ; // handleSymbol
19271951
19281952
1929- function stringTotrayMessageType (s:string ): TBalloonIconType;
1953+ function stringTotrayMessageType (const s: String ): TBalloonIconType;
19301954 begin
19311955 if compareText(s,' warning' ) = 0 then
19321956 result:= bitWarning
@@ -1938,18 +1962,18 @@ t_s2c = record s: String; val: byte; end;
19381962 result:= bitNone
19391963 end ; // stringTotrayMessageType
19401964
1941- function renameIt (src,dst:string):boolean ;
1965+ function renameIt (const src, dst: String): Boolean ;
19421966 var
19431967 srcReal, dstReal: string;
19441968 begin
1945- srcReal:=uri2diskMaybe(src,NIL ,FALSE);
1946- dstReal:=uri2diskMaybeFolder(dst);
1947- if isExtension(srcReal, ' .lnk' )
1948- and not isExtension(src, ' .lnk' ) then
1949- dstReal:=dstReal+' .lnk' ;
1950- if extractFilePath(dstReal)=' ' then
1951- dstReal:=extractFilePath(srcReal)+dstReal;
1952- result:= renameFile(srcReal, dstReal)
1969+ srcReal:=uri2diskMaybe(src,NIL ,FALSE);
1970+ dstReal:=uri2diskMaybeFolder(dst);
1971+ if isExtension(srcReal, ' .lnk' )
1972+ and not isExtension(src, ' .lnk' ) then
1973+ dstReal:=dstReal+' .lnk' ;
1974+ if extractFilePath(dstReal)=' ' then
1975+ dstReal:=extractFilePath(srcReal)+dstReal;
1976+ result := renameFile(srcReal, dstReal)
19531977 end ; // renameIt
19541978
19551979var
0 commit comments