Can a template "programmatically" run another template at an offset in the current file?

[After I originally posted this, I realized the complexity inherent in having one template run another, with the callee able to return to the caller. So I don’t expect a positive answer to my subject line’s question. But I’m leaving the question here because I think it might generate some useful discussion.]

The built-in help Running Templates At An Offset tells how to do this when a template is run interactively.

Is it possible programmatically to do the equivalent, as if there were a RunTemplateAtOffset() function?

Motivation (I hope this makes some kind of sense.)
I’m building a template, or a set of several templates, for an object file format that is created by an assembler.

I’m considering which it would be better to create:

  • One large template (perhaps using #include statements to pull in the code for each kind of record), or,
  • A “main template” that, based on the value of each record’s type byte, invokes the appropriate “sub-template” for that template.

Modules aren’t records themselves, but are a notionally higher-level “object” (not in any formal sense of the word) built from a series of records.

Each of these record types is identifiable by the value in its initial record type byte. (Specific values omitted here for simplicity.)

  • A Module is a:

    • Module Header Record, then,
    • Zero or more Definition Records, then,
    • Zero or more Data/Debug “Objects”, then
    • Module End record
  • A Definition Record can be either:

    • A Segment Definitions Record [details omitted], or,
    • A Public Definitions Record [details omitted]
  • A Data/Debug “Object” is either:

    • A Data Section “Object”, or,
    • A Debug Record [details omitted]
  • A Data Section “Object” is:

    • A Content Record [details omitted], followed by,
    • Zero or more Fixup Records [details omitted]

[Peripherally, I’d like to both:

  • See the usual template output, and,
  • Produce a formatted text file that’s easier to understand for the non-010 “initiate”.]

If, as I suspect, it’s not possible to do what this post’s Subject line asks, do any other ways of dealing with this kind of

Hello GLT. Right now one template cannot run another template. We have had a number of requests for this feature and we are going to be looking at adding it, although as you said it is complex.

One usage case is for very large templates where it would be nice to be able to split into different files. Right now Drive.bt contains a number of file systems and we are planning on making a system where each file system could be in it’s own file. We also have had a number of requests for dealing with compressed data, where a template would be able to decompress a block and run a template on the uncompressed data. That is something we’d like to handle but it’s just figuring out the best way to do it. We are going to be looking at this and we’ll try to let you know when we have something developed.

Right now it’s best to just develop as one large template, although you can write the template in separate files and then use #include to assemble them into one template. Let us know if you have any questions or feedback. Cheers!

Graeme
SweetScape Software

To expand upon what @sweetscape mentioned:

You can include one common file in multiple templates. As you can have functions you can effectively have a function that does most of the actual template generation and call that from another template.