Recent

Author Topic: [SOLVED] $Include part of the string (string content)  (Read 3528 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 678
    • My games in Pascal
[SOLVED] $Include part of the string (string content)
« on: October 27, 2017, 05:38:16 am »
Hi all!
Maybe it would sound absolutely absurd, but can I $Include a string content directly without syntax, i.e. now I do:
Code: Pascal  [Select][+][-]
  1. version.inc
  2. '171017-227'
and in the source code:
Code: Pascal  [Select][+][-]
  1. const Version = {$INCLUDE version.inc};
Is there any way I could do that the version.inc would contain only version number, without start/end of the string, i.e. something like:
Code: Pascal  [Select][+][-]
  1. version.inc
  2. 171017-227
and in the source code:
Code: Pascal  [Select][+][-]
  1. const Version = \'{$INCLUDE version.inc}\';
« Last Edit: October 29, 2017, 08:38:55 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Kays

  • Hero Member
  • *****
  • Posts: 578
  • Whasup!?
    • KaiBurghardt.de
Re: $Include part of the string (string content)
« Reply #1 on: October 28, 2017, 04:56:56 pm »
The problem is, quote, “[…] {$INCLUDE filename} directive tells the compiler to read further statements from the file filename.” It expects statements in your file.

I guess, we could only suggest workarounds, if your version string has to be in a separate file: Like you could use {$INCLUDE %VERSION%} and then
Code: [Select]
read VERSION < version.inc
export VERSION
fpc myProgram.pas
Yours Sincerely
Kai Burghardt

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: $Include part of the string (string content)
« Reply #2 on: October 28, 2017, 05:27:58 pm »
You can use data2inc or bin2obj to convert binary or text files to pascal sources defining a text or binary constant.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 678
    • My games in Pascal
Re: $Include part of the string (string content)
« Reply #3 on: October 28, 2017, 08:00:10 pm »
Well, there is actually no problem.
Version.inc just contains the "copy" of the folder name, e.g. '(program)-date-version' and is used only for logs (e.g. if someone would send me a log, I know exactly what game version he/she is talking about). Made "for git sake" so that just changing a version doesn't create a diff for main unit.
The inconvenience is that I have to accurately select the last variant and copy-paste the new one preserving apostrophe symbols (or write them fresh). Such procedure happens once a day (at most twice) and so it's not a problem, must a minor inconvenience.
Practically if it can't be done by pure FPC syntax (compile-time), then I don't think it is worth it, as it will just add more inconvenience (launching some pre-compilation commands, or reading files, or using external tools). So if there is no "native" way to do this, I'm perfectly fine with apostrophes in version.inc :)
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Kays

  • Hero Member
  • *****
  • Posts: 578
  • Whasup!?
    • KaiBurghardt.de
Re: $Include part of the string (string content)
« Reply #4 on: October 29, 2017, 01:13:12 am »
[…] Made "for git sake" so that just changing a version doesn't create a diff for main unit. […]
Why do you have to leave the git context then, and create some sort of a new symbol, when you already got something:
Code: [Select]
VERSION=`git log -1 --format=format:%h` fpc foobar.pas%h is the abbreviated commit hash. I think this is even more handy to have in user reported log files, than some date: You know where you have to rollback to, in order debug a specific release, without having the troubles of looking up till which commit we build a release.
Yours Sincerely
Kai Burghardt

Eugene Loza

  • Hero Member
  • *****
  • Posts: 678
    • My games in Pascal
Re: $Include part of the string (string content)
« Reply #5 on: October 29, 2017, 08:33:21 am »
Quote
git log -1 --format=format:%h
Sounds awesome... But that's running of external git app, right? I mean, I have to compile command-line, not from under Lazarus IDE (which I usually do, except for Android cross-compilation).
And it won't be explicitly available in git repository (e.g. if a user makes a fork/clone), right?
I mean
git log -1 --format=format:\'%h\' > src/version.inc
as a standalone script would do it better?
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 678
    • My games in Pascal
Re: $Include part of the string (string content)
« Reply #6 on: October 29, 2017, 08:38:38 am »
AWESOME!
A standalone version.sh script:
echo \'${PWD##*/}\' > src/version.inc
is everything I might ever need!
Thanks a lot!
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018