BRP(1) General Commands Manual BRP(1)

brp - line oriented universal preprocesser using posix-shell

brp [-hHQsS]

~$ brp -s | tee
~$ sh -a	#>>output 'hw'
~$ sh -a -b -a		#>>hw, exec ls, hw

usage, version
output corecode
output sample

brp is portable preprocesser. code is separated with 2 parts, main code(#inc...#END) and option code (//SH_OP ...). workflow is:
  1: exec src as shell script. ~$ sh -a   2: main code searches regex suitable line (dfl: //SH_OP, /*SH_OP etc)   3: read hitline and save string to vars ($Ca, $Cb, $C... etc)   4: exec option code if you use -a >> eval "$Ca", -z >> eval "$Cz"

brp exec the head 10 line code as shell script and exit.
#inc... C='^[/][/*]SH_'    ; ... ...#END
main code holds regex string var `C` to get option code line. this var is used as:
~$ cat | sed -ne "/$C/p" #BRE-reg. 
and gather //SH_OP or //SH_??? etc. linetop #include... is assert() for c/cpp (~$ cc #stop) so you can delete if you want.
main code holds predefined option code, -w, -m. see below for details.

you can expand the brp working with option code.
	//SH_OP  b: z=100;echo "good-bye $2 $Ob $1 $z $R0"
	  1  2 3 4                5
dfl opthead is "//SH_" or "/*SH_". see below $C.
option line suffix `OP` is fixed.
separate with blank char(spaces or tabs)
optchar is [a-zA-Z0-9] or `_`(see below). add colon if use optarg
write raw sh-script with ONE LINE. code is used as below.
z=100;echo "good-bye $2 $Ob $1 $z $R0"
eval "$Cb"		#if -b set
if you set special optchar `_`, it works only once at the script beginning.
//SH_OP _ echo "preset AA";AA=1
//SH_OP a echo "$AA"	#>>~$ sh -a ... disp "1"
adopt new one if overlap the option setting.
//SH_OP a echo "hw"	#>> ignored. sh -a  -> disp "gw"
//SH_OP a echo "gw"

1-2char var names R?, C?, O? are reserved (R,C,O,Ra,R7,Cg,O5 ...). optarg is set to $O? ( a: >> $Oa , v: >> $Ov etc)
orig/tMp/src/header fname. ($Rm -> src.tmp.c etc) fname uses topname + last suffix. eg) src.xx.yy.py3 -> ./src.py3
original fname should avoid tmp/src/header fname.
(sh src.c -w >> src.h / src.c ...orig destroyed)
$Ca/$Cb etc. code buffer.
//SH_OP a echo "$Rm"	# ~$ sh -a >> disp brp.tmp.c
//SH_OP b printf "$Ca"	# ~$ sh -b >> disp echo "$Rm"
//SH_OP c eval "$Ca"	#.. -c works as equals to -a
predefined -w option. uses for c-lang. you will make sense of the work by exec.
~$ brp -S > #sample ~$ sh -w
1. write SH_LS - SH_ED(LS_block) to both src.h($Rh)/src.c($Rs) 2. add HD_block to src.h, SC_block to src.c 3. disp filename to stdout.  (src.h src.c) -. suffixes(LS,HD,SC,ED) are fixed
predefined -m option. remove brp maincode(#inc...#END) and output to $Rm (XX.tmp.XX). you may uses for general perpose.
comment regex. dfl is C=`^[/][/*]SH_`, //SH_xx or /*SH_yy etc.
brp uses linecmt as directive. if you want to use other pg-lang(python etc), edit srctop `C=...` directly. use BRE-reg.
shell : C='^#ANYSTR_'; >>  #ANYSTR_LS, #ANYSTR_ED etc python: C='^["]["]["]MARKER_'; >> """MARKER_OP   etc basic : C="^[']SH_"; >> 'SH_OP etc
$C is used as follows. escape slash / plz.

sed -e "/${C}ED/"  ...  (bad)C='^/[/*]SH_' (good)C='^\/[/*]SH_' 
optargs. //SH_OP a: echo "$Oa"  .. ~$ sh -a 11 ..11
newline(\n). eg) //SH_OP a echo "a${O}b" >> disp a(\n)b
normal args. this pg uses getopts. checked opts are removed.
eg) //SH_OP a echo "$1" #~$ sh -a -c 11 >> output 11

--- copy & paste main script --- #include <iostream> int main(void){   std::cout << "hw" << std::endl; } //SH_OP b eval "$Cm";g++ "$Rm"; ./a.out as `src.brp.cpp` and run ~$ sh src.brp.c -b >>> hw.

this app frequency uses one liner. introduce some tips.
//SH_OP m sed -ne "/[E]ND/{n;bl};d;:l;p;n;bl"<"$R0">"$Rm";echo "$Rm" >> sed -ne '*see below*' < "$R0" > "$Rm" echo "$Rm" >> cat '' | sed -ne '...' > foo.tmp.c echo "foo.tmp.c"
sed command pseudocode is the follows:
------ sed -ne '/[E]ND/{n;bl};d;:l;p;n;bl' >> sed -n(o print. print only when requested) -e(xpression as script)
if (line==/END/){  .../[E]ND/   n(ext read) ...n (if not -n opt, print nowline & readnext)   goto label l ...b l (b=jump/goto. babc -> b abc -> goto abc) } del line (& read nextline & *goto top*) ...d (d cmd is hard worker) label l: ... :l (label. ':' + 'lbl name')  p(rint line) ... p n(extline read) ... n goto label l ... b l
...del lines until 1st hit 'END'. print all lines until EOF. -------
sed cmd is difficult but very powerful. Most requests can be solved by referring to the above.

sed cant use shortest match, but shell is possible(shotest+longest).
str="aa_bb_cc" echo "${str#*_}"  #>> bb_cc (match aa_ and del) echo "${str##*_}"  #>> cc (longet) echo "${str%_*}"  #>> aa_bb (from tail) echo "${str%%_*}"  #>> aa
shell pattern(glob pattern) is very similar to sed-regex:
	aa_bb_cc -> a_bb_cc
	reg: s/^.//g
	sh : ${str#?}	... any one char. reg:'.'    sh:'?'
	aa_bb_cc -> (del)
	reg: ^[.]*
	sh : ${str#*}	... all. sh can uses wild card.
	aa_bb_cc -> aa_
	reg: [^a_]*
	sh : ${str%%[!a_]*}	... not.  reg:'^'    sh:'!'
	...[], bracket works as same, 'one char'
	sh: ${str%123"*"*}  ... "*" uses as literal. 0123*567 -> 0
see ..or..
~$ man sh + input `/` + input `pattern` + enter + `n` + `shift_n`


--- concept
I wondered why to write dependencies or compile options to makefiles.
The source code should contain all the necessary information.
Because the programmer's will is written in it. I dont like writing
in separate files and increasing the workflow.
- avoid info fragmentation (script/src/header/gcc opt/ini/config etc) - small. avoid disturbing the main code. - (consider readability) - portable. avoid vender lockin, bashism etc. - low learning cost. good usage help, dont need installation etc - others ... see unix philosophy.


Copyright (C) 2021 Momi-g
License GPLv3+ <>

2021-09-14 v1.0.2