[fpc-pascal]How to define a string const with content of a file?

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Sat Sep 21 23:34:11 CEST 2002


On Sat, 21 Sep 2002, Tom Verhoeff wrote:

> I currently have the following line in a number of related programs:
>
> 	const TASK = '...'; { name of task }
>
> where ... is replaced by the name of the task.
>
> To simplify my life, I would like the ... to be taken from
> a file named TASKNAME.  In shell scripts, I do it like
>
> 	TASK = `cat TASKNAME`
>
> In make files, I do
>
> 	TASK = $(shell cat TASKNAME)
>
> How can I do it in FreePascal?
>
> Note that this file TASKNAME just has the name in it, no quotes etc.
> Thus, {$INCLUDE TASKNAME} will not work.
>
> Apparently, I need a mechanism related to {$INCLUDE %...%}, but
> then for the content of a file, rather than the date or so.

do a

set TASKNAME=`cat taskname`
export TASKNAME

before compiling and

Const
  Taskname = '{$INCLUDE %TASKNAME%}';

In the source. The compiler will look for environment variables if the
token between %..% is not one of the pre-defined variables.

Michael.






More information about the fpc-pascal mailing list