#!/bin/sh
#] 
#] *********************
#] $ bash "$d_bin""txtDoc cmd.sh"  - run commands as file is being [read, assembled], eg video production
# www.BillHowell.ca  15Oct2019 initial

# run commands as file is being [read, assembled] 
# This includes augmenting a text file with text file inclusions, but can go far beyond that.
# originally for "formulae extract.sh" and the Lucas project

# do NOT run this script directly - set up a calling script that sets the environmental variables
# example - Lucas project, see "$d_bin""Lucas - formulae & augment.sh"


#******************************
#] txtDoc_cmd()  - 

	txtDoc_cmd()
{ 
p_inn="$d_inn$f_inn"
p_augmented="$d_temp$f_augmented"

# clear the augmented file to make sure that we are not piling new in the old.
echo "" >"$p_augmented"
IFS=''
while read -u 9 line; do
	flag_cmd=$( echo "$line"  |  grep  "^\/\*\\$" )
	if	 	[ -n "$flag_cmd" ]; then
		cmd=$( echo "$line"  |  sed  's#^\/\*\$\(.*\)#\1#' )
		echo "/*$line"   >>"$p_augmented"
		# insert an extra "/*" to de-activate command for subsequent iterations
		eval "$cmd"
	else
		echo  "$line" >>"$p_augmented"
	fi
done 9< "$p_inn" 
}  


#**********************
# command examples - see WWII video production for other progams I use

# file insertion:
# /*$ cat  >>"$p_augmented"  "$d_Lucas""context/waiver, copyright.txt"  

# datestamp 
# /*$ echo "version= $date_ddmmmyyyy, cos - 1 inclusion : $cos_inclusion"  >>"$p_augmented"

# Example : 
# Run command to see  $ eog  "$d_Lucas""images/Howell - Chapter 4 - POIo basic - cropped.png" & 
# Run command to see  $ eog  "$d_Lucas""images/Howell - Chapter 4 - POIo basic - cropped.png" & 
# Run command to see video_pgm  $ cvlc  "????"

# $ echo "/*$ bash  >>"$d_Lucas""documents/$f_augmented"" Table of Contents.txt"  "$d_bin""txtDoc extract headings.sh" "all""  |  grep  "\/\*\\$"


# enddoc
