Simply include the textfile as a resource, and load it from the resource? Afaik resources work with Linux too.
Or LazRes (using old style *.lrs resources)...
Is there a way that works with as-installed FPC on Linux of preloading a big block of raw text into a string? For the purpose of the question please assume that this is a multi-line script which includes arbitrary quote characters etc.
Simply include the textfile as a resource, and load it from the resource? Afaik resources work with Linux too.
https://wiki.freepascal.org/Lazarus_Resources says that doing so needs windres or GoRC, neither of which comes as standard. The current manual concurs, and the examples still have to be quoted.
Yes, until FPC 3.2.2 and fpcres.
The syntax is
fpcres -i logo.rc -of res -o logo.res
Yes, until FPC 3.2.2 and fpcres.
The syntax is
fpcres -i logo.rc -of res -o logo.res
So how does embedded text look? Because if it still has to be quoted there really isn't much point from my POV.
So how does embedded text look? Because if it still has to be quoted there really isn't much point from my POV.
Except that's not part of FPC.
You store the text in a textfile, and then make a .rc file containing this:
Defaults RCDATA defaults.xml
this makes the contents of the file "defaults.xml" binary (RCDATA is binary) available using the resource name "Defaults". You can include multi files using one .rc file. I do this e.g. with shader source files.
Thanks for that. So it's doable, but hardly painless.
I've reverted to defining it as a multiline constant, but either have to use the double-' escape or define a substitute and preprocess the text... the latter works out better but is still hardly ideal:
const qq= LineEnding; (* Prefix is same size as 8-spaces tab *) syntax='.QUOTE `' + qq + '`MetaScriptSyntax` <<EOF' + qq + '.SYNTAX MetaScriptSyntax' + qq + '' + qq + '(* This is the master representation of the syntax of the embedded *)' + qq + '(* script compiler. *)' ...
Thanks for that. So it's doable, but hardly painless.
That is a very opinionated and biassed statement. There are multiple sides to this, and if you have e.g. external editors or viewers for such included files, then suddenly the in-source view is extremely cumbersome and a poor man's solution.
But many languages actively limit themselves to the in source solution,, because they can't standardize tooling outside of the core language due to oppressive requirements for formal language definitions. Then doing it in source becomes the "my only tool is a hammer" kind of solution.
FPC and Delphi don't have that problem.
But I note that C++11 introduced inline text storage, which had never been implemented in older revisions or in C itself: whatever we think of the language there's smart people involved, and I'm sure that if they could see a better way they'd have used it.
There is a patch for FPC to add multi-line strings. Discussed here. (https://forum.lazarus.freepascal.org/index.php/topic,46050.0.html)
I don't know why I have to sign in to gitlab to view the bug report %)
[…] LCD displays. […]OMG. Did you just write “liquid crystal display displays”? :o
Is there a way that works with as-installed FPC on Linux of preloading a big block of raw text into a string? […]No, but since fp-compiler depends on binutils, that means there is an assembler as(1), you could also (ab)use objects files and the {$link} directive (https://freepascal.org/docs-html/current/prog/progsu43.html). First create a wrapper file:
Kays: bin2obj and data2inc are two pre resource ways for including data.Ah, of course! Why didn’t you mention it earlier? Although I hate typed pseudo-“constants”, data2inc(1) is the way to go.
Evidently that’s not a string constant, […]To make it effectively a constant, put everything in
loading pregenerated lookup tables etc. is obviously a fairly common requirement for embedded stuffWell, I have only shown arrays which are common with standard pascal. That embedded implementation also has tables, which are a specialized 1-dimensional version of arrays containing look-up tables. The table length is limited on power of 2, to allow a very, very fast access:
Simply include the textfile as a resource, and load it from the resource? Afaik resources work with Linux too.
https://wiki.freepascal.org/Lazarus_Resources says that doing so needs windres or GoRC, neither of which comes as standard. The current manual concurs, and the examples still have to be quoted.
I however load the data over windows unit functions, but it should be possible portably too (Lazarus uses it afaik)
Default RCDATA Defaults.ini
[test]
a=1
b=2
[foo]
c=3
@PascalDragon,
that was useful post, so I ask: is it (that info how to use TResourceStream with some text) in the Wiki?
windres is contained with the Windows distribution of FPC. On other platforms you need to make sure that your buildchain is set up correctly (just like you need to make sure that as and ld are available).
I habitually use Debian (mostly AMD64) and build both FPC and Lazarus from scratch. There is no windres on these systems, and Debian has no package of (some variant of) that name in their repositories.
I habitually use Debian (mostly AMD64) and build both FPC and Lazarus from scratch. There is no windres on these systems, and Debian has no package of (some variant of) that name in their repositories.
IIRC it is part of cross win32 binutils. But as said better use trunk or 3.2.2 fpcres.
The only other diff is that I used the Resource section on the Project Options(CTRL+SHIFT+F11) and in your case one needs to manually compile the linkable objects from the *.rc files.
So my question is: In the background, on my Ubuntu 21.04 64b, fpcupdeluxe installed Lazarus, what is it using to compile the resources that I added on the Project Options', Resources section?
I now ask this cuz, if you read my previous post with the example, I mention that I'm ignorant of the process that occurs in the background, performed by Lazarus and I'm now curious.
I habitually use Debian (mostly AMD64) and build both FPC and Lazarus from scratch. There is no windres on these systems, and Debian has no package of (some variant of) that name in their repositories.
I habitually use Debian (mostly AMD64) and build both FPC and Lazarus from scratch. There is no windres on these systems, and Debian has no package of (some variant of) that name in their repositories.
binutils-mingw-w64-i686 has i686-w64-mingw32-windres