Search code examples
shellextractexecuteliterate-programming

Literate programming: tool to extract and run a script from source in one pass?


I just started reading about literate programming and noweb - and I find it quite interesting. As far as I understand it, the 'notangle' step is the one that extracts (machine) source code (file), from the literal programming (source) file.

Here, I'm interested in one specific aspect: I would like to be able to extract multiple source files in one pass (in the notangle step) , including an execution script - and run the execution script in the same step!

An example in bash would look something like this:

#!/usr/bin/env bash
# file: test.c.gdb.sh 

# generate C source file
cat > test.c <<"EOF"
#include "stdio.h"

int main(void) {
  return 0;
}
EOF

# generate gdb script file
cat > test.gdb <<"EOF"
break main
run
EOF

# run the 'execution script'

gcc -g -Wall test.c -o test.exe
chmod +x test.exe
gdb -x test.gdb -se test.exe

The point in this, is that I can just call './test.c.gdb.sh' from the shell, and I'll have the source files generated, then compiled, and then have the debugger started automatically.

Is there a literate programming tool, that would allow something like this in the notangle step?

Thanks in advance for any answers,
Cheers!


Solution

  • extract multiple source files in one pass (in the notangle step), including an execution script - and run the execution script in the same step!

    Folks sometimes use make, ant, scons or maven for this kind of thing.

    A "single" magical command can't cover very many bases very well. So it's left to external tools to do this.

    Often, the final report or document requires complex, multi-step processing through various LaTeX tools. This, too, may require a simple build script or tool setup.