[fpc-pascal] InstantFPC and argv

Tomas Hajny XHajT03 at hajny.biz
Fri May 4 21:52:12 CEST 2012


On Fri, May 4, 2012 18:44, Darius Blaszyk wrote:
> On May 4, 2012, at 6:12 PM, Tomas Hajny wrote:
>> On Fri, May 4, 2012 17:44, dhkblaszyk at zeelandnet.nl wrote:
>>> On 4 mei '12, michael.vancanneyt at wisa.be wrote:
>>>> On Fri, 4 May
>>> 2012, michael.vancanneyt at wisa.be [3]wrote:
>>>>
>>>>> On Fri, 4 May 2012,
>>> dhkblaszyk at zeelandnet.nl [1]wrote:


Hi Darius,

>>>>>> I'm creating a script to be
>>> executed by instantfpc when I noticed that paramstr(0) does not reflect
>>> the location of the script but the location of the cached executable.
>>> Is
>>> there a way to alter this location programatically to the script
>>> location? Is there an alternative way?
 .
 .
>> There are two parts for a possible solution. The first part should be
>> feasible without major issues (with it still requires someone to do it,
>> e.g. provide a patch) - InstantFPC could add the name of the original
>> script (including full path) as a predefined constant into the Pascal
>> source while extracting it from the original script file.
 .
 .
>> adding
>> the local ParamStr on a single source line would even allow these
>> backtraces to refer to the correct line numbers from the original script
>> file ;-) ).
>>
> Hi Tomas,
> I think your first solution would be the nicest one. If all agree and the
> patch would be accepted then I would like to give it shot. I'm not sure
> though how to insert the code in the best way. Probably it will be using
> passrc, although I'm not sure it will work on scripts with a shebang line.

Not sure about passrc behaviour for shebang but I believe that it may be
quite easy to solve it without passrc too. I'd say that the pascal syntax
knowledge necessary for this task would be limited:

1) Find the first alphabetic character after the first line (which is
already processed/skipped by InstantFPC anyway) while ignoring all
whitespaces and possible comments (in all allowed formats, i.e. including
(* *) ) - the only small complexity here are nested comments, but even
that is not so difficult to handle.

2) If there is the 'program' keyword, find the semicolon and continue
searching for the next alphabetic character while still ignoring comments
and whitespaces (to skip possible global compiler directives).

3) Write down 'const InstantFPCScriptName = ...;' + LineEnding immediately
before the found alphabetic character (there should be no need to parse
it).

Tomas





More information about the fpc-pascal mailing list