Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-09

How to define a string const with content of a file?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tom Verhoeff

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.

Thanks for your suggestions,

Tom Verhoeff

Reply by email

Unknown author
to Tom Verhoeff
Tom Verhoeff wrote 22 lines
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.

Reply by email