Browse Source

pastojs: added $i %EnvVar%

git-svn-id: trunk@40488 -
Mattias Gaertner 6 years ago
parent
commit
8d3c133caa
2 changed files with 23 additions and 3 deletions
  1. 16 2
      packages/pastojs/src/fppas2js.pp
  2. 7 1
      utils/pas2js/docs/translation.html

+ 16 - 2
packages/pastojs/src/fppas2js.pp

@@ -2097,6 +2097,20 @@ var
 begin
 begin
   if (Param<>'') and (Param[1]='%') then
   if (Param<>'') and (Param[1]='%') then
   begin
   begin
+    if (length(Param)<3) or (Param[length(Param)]<>'%') then
+      begin
+      SetStr('');
+      DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,SWarnIllegalCompilerDirectiveX,
+        ['$i '+Param]);
+      exit;
+      end;
+    if length(Param)>255 then
+      begin
+      SetStr('');
+      DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,SWarnIllegalCompilerDirectiveX,
+        ['$i '+copy(Param,1,255)+'...']);
+      exit;
+      end;
     case lowercase(Param) of
     case lowercase(Param) of
     '%date%':
     '%date%':
       begin
       begin
@@ -2160,8 +2174,8 @@ begin
         exit;
         exit;
       end;
       end;
     else
     else
-      DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,SWarnIllegalCompilerDirectiveX,
-        ['$i '+Param]);
+      SetStr(GetEnvironmentVariable(copy(Param,2,length(Param)-2)));
+      exit;
     end;
     end;
   end;
   end;
   Result:=inherited HandleInclude(Param);
   Result:=inherited HandleInclude(Param);

+ 7 - 1
utils/pas2js/docs/translation.html

@@ -2803,7 +2803,10 @@ End.
     <li>{$I %param%}:
     <li>{$I %param%}:
       <ul>
       <ul>
         <li>%date%: current date as string literal, '[yyyy/mm/dd]'</li>
         <li>%date%: current date as string literal, '[yyyy/mm/dd]'</li>
-        <li>%time%: current time as string literal, 'hh:mm:ss'</li>
+        <li>%time%: current time as string literal, 'hh:mm:ss'. Note that the
+          inclusion of %date% and %time% will not cause the compiler to
+          recompile the unit every time it is used:
+          the date and time will be the date and time when the unit was last compiled.</li>
         <li>%file%: current source filename as string literal, e.g. <i>'unit1.pas'</i></li>
         <li>%file%: current source filename as string literal, e.g. <i>'unit1.pas'</i></li>
         <li>%line%: current source line number as string literal, e.g. <i>'123'</i></li>
         <li>%line%: current source line number as string literal, e.g. <i>'123'</i></li>
         <li>%linenum%: current source line number as integer, e.g. <i>123</i></li>
         <li>%linenum%: current source line number as integer, e.g. <i>123</i></li>
@@ -2811,6 +2814,9 @@ End.
         <li>%pas2jstarget%, %pas2jstargetos%, %fpctarget%, %fpctargetos%: target os as string literal, e.g. 'Browser'</li>
         <li>%pas2jstarget%, %pas2jstargetos%, %fpctarget%, %fpctargetos%: target os as string literal, e.g. 'Browser'</li>
         <li>%pas2jstargetcpu%, %fpctargetcpu%: target cpu as string literal, e.g. 'ECMAScript5'</li>
         <li>%pas2jstargetcpu%, %fpctargetcpu%: target cpu as string literal, e.g. 'ECMAScript5'</li>
         <li>%pas2jsversion%, %fpcversion%: compiler version as strnig literal, e.g. '1.0.2'</li>
         <li>%pas2jsversion%, %fpcversion%: compiler version as strnig literal, e.g. '1.0.2'</li>
+        <li>If param is none of the above it will use the environment variable.
+        Keep in mind that depending on the platform the name may be case sensitive.
+        If there is no such variable an empty string <i>''</i> is inserted.</li>
       </ul>
       </ul>
     </li>
     </li>
     <li>{$Warnings on|off}</li>
     <li>{$Warnings on|off}</li>