BRP(1) | General Commands Manual | BRP(1) |
~$ brp -s | tee src.sh.c ~$ sh src.sh.c -a #>>output 'hw' ~$ sh src.sh.c -a -b -a #>>hw, exec ls, hw
1: exec src as shell script. eg) ~$ sh src.sh.c -a 2: header code searches regex suitable line (dfl: //SH_OP, /*SH_OP etc) 3: read hitline and save as cmd string ($Ca, $Cb, $C... etc) 4: exec option code if you use -a >> eval "$Ca", -z >> eval "$Cz"
#inc... C='^[/][/*]SH_' ; ... ...#END
main code holds regex expression var C to get option code
line. this var is used as:
~$ cat src.sh.c | sed -ne "/$C/p" #BRE-reg.
and gather //SH_OP or //SH_??? etc.
main code holds predefined option code, -w, -m. see below for details.
//SH_OP b: z=100;echo "good-bye $2 $Ob $1 $z $R0" 1 2 3 4 5
Cb=$(cat<<'E' z=100;echo "good-bye $2 $Ob $1 $z $R0" E ) eval "$Cb" #if exec: ~$ src.sh.c -b
//SH_OP _ echo "preset AA";AA=1 //SH_OP a echo "$AA" #>>~$ sh src.sh.c -a ... disp "1"
//SH_OP a echo "hw" #>> ignored. sh src.sh.c -a -> disp "gw" //SH_OP a echo "gw"
//SH_OP a echo "$Rm" # ~$ sh brp.sh.c -a >> disp brp.tmp.c //SH_OP b printf "$Ca" # ~$ sh brp.sh.c -b >> disp echo "$Rm" //SH_OP c eval "$Ca" #.. -c works as equals to -a
~$ brp -S > src.sh.c #sample ~$ sh src.sh.c -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
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_'
--- copy & paste main script --- #include <iostream> int main(void){ std::cout << "hw" << std::endl; } //SH_OP b eval "$Cm";g++ "$Rm"; ./a.out
...save as src.brp.cpp and run ~$ sh src.brp.c -b >>> hw.
//SH_OP m sed -ne "/[E]ND/{n;b l};d;:l;p;n;b l"<"$R0">"$Rm";echo "$Rm" >> sed -ne '*see below*' < "$R0" > "$Rm" echo "$Rm" >> cat 'foo.sh.c' | sed -ne '...' > foo.tmp.c echo "foo.tmp.c"
sed command pseudocode is the follows:
------ sed -ne '/[E]ND/{n;b l};d;: l;p;n;b l' >> 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. b abc -> goto abc, needs space@posix) } del line (& read nextline & *goto top*) ...d (d cmd is hard worker) label l: ... : l (label. ':' + '1sp' + '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.
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' escape sh: ${str%123"*"*} ... "*" uses as literal. 0123*567 -> 0
see https://en.wikipedia.org/wiki/Glob_%28programming%29 ..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.