###  ts7.bish  #############################################

#!/u/bin/bish

set -f

ifile=texts256.h
[ $# -ge 1 ] && ifile=$1

set Zen:.100
set Zde:.100
set Zsw:.100
set Zit:.100
set Zru:.100
set Zhu:.100
s=0
dnanu=.........................
dnanu0=.........................
set text:.50
set text_en:.50
set langs:32.25
langs=


AddLangs()  {
   [ s -eq 0 ] && return 1
   ifset langs || return 2
   ifset text_en && text="$text_en"
   ifset text || return 3
   local l=ll
   for l in  en de sw it ru hu
   do
      expr " $langs " :: " $l " && { catv Z$l /%n; continue; }
      catv '/#define ' dnanu0 l text /%n
   done
   s=0 langs= text=? text_en=?
   return 0
}


#< $ifile
while readl Z
do
   expr "$Z" :danam ' %(D_%W%{1,}_%D%D%D_%L%L%)  *"[^"]*" *$' || {
      [ s -eq 1 ] && AddLangs
      catv Z /%n
      continue
   }
   expr "$Z" :text '%(  *"[^"]*"%) *$'
   expr "$danam" :dnanu '^%(D_%W%{1,}_%D%D%D_%)%L%L$'
   expr "$danam" :lang '^D_%W%{1,}_%D%D%D_%(%L%L%)$'
   catv Z =Z$lang:
   [ $lang == en ] && text_en="$text"
   [ s -eq 0 ] && dnanu0=$dnanu
   cmpv dnanu dnanu0 || { AddLangs; dnanu0=$dnanu; }
   s=1 langs="$langs$lang "
done
#><

:





###  texts.bish  #############################################

#!/u/bin/bish


C=00000
set Z:.150 Z16:.300

>texts.h
<texts256.h
while readl Z
do
   base -b Z +16 Z16
   expr "$Z16" :: '[89abcdef][0-9a-f]' || { catv Z /%n; continue; }
   for C in $Z16
   do
      let "16#$C<=127" && { base -16 C +b; continue; }
      base -16 C +8 C
      prints ssf03- '\' $C
   done
   catv /%n
done
><<




###  t_exte.bish  #############################################




Files=*.[ch]
files=*base.txt
Files="$Files $files"
expr "$Files" :Files ' texts256.h' = ' '
expr "$Files" :Files ' texts.h' = ' '
expr "$Files" :Files ' text.h' = ' '
expr "$Files" :Files ' texte.h' = ' '
expr "$Files" :Files ' texte.c' = ' '
expr "$Files" :Files ' [tT]%Dh%D%{2,}.c' += ' '
t0=XXXXXXXXXXXXXXXX

: > __1__
: > __2__
< texts256.h
while readl Z
do
   ifset Z || continue
   expr "$Z" :t1 ' D_%(%W%{1,}%)_%D%D%D_en ' || continue
   expr "$Z" :t2 ' D_%W%{1,}_%(%D%D%D%)_en '
   expr "$t2" :t2 '^0%{1,2}' = ''
   [ "$t1" != "$t0" ] && catv /T_ t1 /%n >> __1__ ; t0=$t1
   catv /T_ t1 /' ' t2 /%n >> __2__
done
><


echo $Files

for t in  `cat __1__`
do
   catv /%n t
   grep -q '%<'"$t"'%>' $Files && continue
   catv /'  --'
done
catv /%n


for 2 t1 t2 in  `cat __2__`
do
   catv /%n t1 /+ t2
   [ t2 -eq 0 ] && grep -q '%<'"$t1"'%>' cfgdata.c mesdata.c && continue
   grep -q '%<'"$t1"'+'"$t2"'%>' cfgdata.c mesdata.c && continue
   catv /'  --'
done
catv /%n

remove -s __1__ __2__





###  t.bish  #############################################



set -f

Tout()  {
   local n=0000 e=0 l=000
   while :
   do
      e=0
      while readl ZS && readl -u3 ZR
      do
         expr "$ZS" :: '^ *//' && continue
         expr "$ZS" :Tnam ' %(T_%W%{1,}%) *= *{' || continue
         e=1 break
      done
      [ e -eq 0 ] && break
      n=0
      while readl ZS && readl -u3 ZR
      do
         expr "$ZS" :: '^ *}; *$' && break
         expr "$ZS" :: '^ *//' && continue
         expr "$ZS" :: ' "[^"]%{16%}",' || continue
         expr "$ZS" :S1 ' %("[^"]%{16%}"%)'
         expr "$ZS" :ZS ' "[^"]%{16%}"' = ' '
         expr "$ZS" :S2 ' %("[^"]%{16%}"%)'
         expr "$ZS" :ZS ' "[^"]%{16%}"' = ' '
         expr "$ZS" :S3 ' %("[^"]%{16%}"%)'
         expr "$ZS" :ZS ' "[^"]%{16%}"' = ' '
         expr "$ZS" :S4 ' %("[^"]%{16%}"%)'
         expr "$ZR" :ZR ' "[^"]%{16%}"' = ' '
         expr "$ZR" :ZR ' "[^"]%{16%}"' = ' '
         expr "$ZR" :S5 ' %("[^"]%{16%}"%)'
         prints vsf03 n $n
         let "l= ${#Tnam}+${#n}+14"
	 conv -TTD Tnam
         prints s-${l}ss40s '//' '"' '' '"'
         print -r "#define ${Tnam}_${n}_en  $S1"
         print -r "#define ${Tnam}_${n}_de  $S2"
         print -r "#define ${Tnam}_${n}_sw  $S3"
         print -r "#define ${Tnam}_${n}_it  $S4"
         print -r "#define ${Tnam}_${n}_ru  $S5"
         let ++n
      done
      echo
   done
   return 0
}

0< ../MU1000C/TXT2_STD.C
3< ../MU1000C/TXT2_RUS.C
1> T.OUT
Tout
><<<

0< ../MU1000C/TXT_STD.C
3< ../MU1000C/TXT_RUS.C
1>>T.OUT
Tout
><<<



###  build.bish  #############################################



(. texts.bish)
(. tpa.bish)
(. cfg.bish)




###  sj.bish  #############################################

#!/home/bin/bish

for j from 1970 to 2079 repeat
do
      (( nsj+= cjsj= !(j%4)&&j%100||!(j%400) ))
      echo "/*$j*/  { $cjsj, $nsj },"
done

for j from 1970 to 2079 repeat
do
      (( cjsj= !(j%4)&&j%100||!(j%400) ))
      (( corr+= 24*3600*(365+cjsj) ))
      prints ss13 "/*$j*/  " "${corr}ul,"
done



###  sed.bish  #############################################

#!/u/bin/bish


Wl='%<'
Wr='%>'
O=.........
[ $# -eq 0 -o $# -eq 2 -o $# -eq 3 ] || exit
[ $# -eq 3 ] && O="$1" old="$2" new="$3"
[ $# -eq 3 -a "$O" != '-a' ] && exit 1
[ $# -eq 3 -a "$O" == '-a' ] && unset Wl Wr
[ $# -eq 2 ] && old="$1" new="$2"
files=?*.[chCH]
files="$files cfgbase.txt mesbase.txt"
expr "$files" =:files '%<mb[0-9]%{2,}%.h%>' += ''
expr "$files" =:files '%<t[0-9]h[^ ]%{2,}%>' += ''
expr "$files" =:files '%<texts[^ ]*%.h%>' += ''
[ $# -eq 0 ] && read "old?ALT und NEU [aaa nnn]:  " new
ifset old || exit
ifset new || exit
expr "$old" :old '\s' += ' '
expr "$new" :new '\s' += ' '
print -r $files

for file in $files
do
   grep -qm -e "$Wl$old$Wr" "$file" || continue
   cat "$file" | {
      > "$file"
      while readl zeile
      do
         expr "$zeile" :zeile "$Wl$old$Wr" + "$new"
         print -r "$zeile"
      done
      ><
   }
done

exit 0

#read "-?$0: <Enter> "





###  oct.bish  #############################################

#!/home/bin/bish

for n from 0 to 255 repeat
do
   prints ssf03ssf03s "#define O" $n '  "\' $((8#, n)) '"'
done



###  ninc.bish  #############################################

#!/u/bin/bish

start=0
inc=1
muster='@'
width=2
fill=' '
neq=1

[ -t 0 ] &| expr "$1" :: '[^0-9-]' && {
   print -u2 ninc.bish: usage: start inc.neq muster width fillchar
   exit 0
}

[ $# -gt 0 ] && {
   [ -n "$1" ] && start="$1"
   [ -n "$2" ] && inc="$2"
   [ -n "$3" ] && muster="$3"
                  width="$4"
                  fill="$5"
}
#[ "$fill" == 'space' ] && fill=' '
ifset fill && fill="f$fill"
expr "$width" :width '^-' = '' && sign=-
expr "$inc" :neq '%D%.%(%D%{1,}%)'
expr "$inc" :inc '^%(%D%{1,}%)'
neqd=$neq

cat | {
   while readl Z
   do
      prints "vs$sign$fill"$width subst "$start"
      expr "$Z" :Z "$muster" = "$subst" &&  {
         let "--neqd==0" && let "start+=inc" "neqd=neq"
      }
      catv Z /%j
   done
}

exit 0




###  neuvb.bish  #############################################

#!/u/bin/bish

NL="
"
li=0
n=0

<$1
while read Z
do expr "$Z" :: 'BUILDs' && break; done

while read Z
do
  expr "$Z" :: '^//' || break
  ifset t && ifset Z || break
  expr "$Z" :: '^//-%{50,}' && {
     ifset t && { t="$t</li>$NL</ol>$NL"; T$n="$t"; let ++n; }
     t="<ol>$NL" li=
     continue
  }
  #print -r "$Z"
  expr "$Z" :b '^//--> %{1,}%([0-9, ]%{1,}%)' && { B$n="$b"; continue; }
  expr "$Z" :v '^//--> %{1,}V[^0-9]%{2,}%([0-9.]%{1,}%)' && { V$n="$v"; continue; }
  expr "$Z" :Z '^//%(.*%)$'
  expr "$Z" :Z '&' += '&amp;'
  expr "$Z" :Z '<' += '&lt;'
  expr "$Z" :Z '>' += '&gt;'
  if expr "$Z" :: '^[^ ]'
  then
     ifset li && t="$t</li>$NL"
     t="$t<li>" li=1
  else
     expr "$Z" :Z '^ %{1,}%(.*%)$'
  fi
  t="$t$Z<br>$NL"
done
><


v=
for t from 0 to $n repeat
do
   ifset T$t || continue
   ifset V$t && v="$V[t]"
   ifset V$t || V$t="$v" G$t=1
done


>__neu
catv '.<table width="100%" cellpadding="10" cellspacing="2"><tbody>' /%n
for n from $n by -1 to 0 repeat
do
   ifset T$n || continue
   h1='<h1>'
   ifset G$n && h1='<h1 style="color: rgb(160,160,0);">'
   catv '.<tr><td bgcolor="#a2b5cd" width="15%" valign="top" align="center">' %
        /%n h1 V$n '.</h1><h3>' B$n '.</h3></td>' /%n
   catv '.<td bgcolor="#fffff0" width="85%">' /%n T$n '.</td></tr>' /%n
done
catv '.</tbody></table>' /%n
><

:




###  mktxt.bish  #############################################

#!/u/bin/bish

set -f

N=-001

while readl Z
do
   let ++N; prints vsf03 N $N
   prints s-25s-27ss14 '//' '"' '<' '"'
   prints sssss '#define D_xxxxxx_' $N '_en  ' "%"$Z" '"'
done

:



###  link.bish  #############################################


cat | {
   while readl Z
   do
      expr "$Z" :: ' "\[0-9]%{3}[a-z?A-Z]' || { catv Z /%r%n; continue; }
      expr "$Z" :n '/*%(..%)*/'
      expr "$Z" :c '"\...%(.%)'
      expr "$cc" :: "$c" || cc="$cc$c" fst="$fst $c=$n"
      nn=0
      seek + 0 pos
      while readl Z2
      do
         expr "$Z2" :n2 '/*%(..%)*/' || continue
         expr "$n2" :: '^0.' && conv -D0 n2
         expr "$Z2" :c2 '"\...%(.%)' || continue
         [ $c2 == $c ] && nn=$n2 break
      done
      [ ${#nn} -eq 1 ] && nn=" $nn"
      expr "$Z" :Z ', ..,' = ", $nn,"
      catv Z /%r%n
      seek $pos 0
   done
}
catv './* ' fst '.*/' /%r%n



###  ebits.bish  #############################################

#!/u/bin/bish

set -f

N=-001

while readl Z
do
   expr "$Z" :txt ' %(%W%{1,}%) *: *%D' || continue
   let ++N; prints vsf03 N $N
   prints s-25s-27ss14 '//' '"' '<' '"'
   prints sssss '#define D_fehler_' $N '_en  ' "%"$txt" '"'
   #prints ssss-41s '#define D_fehler_' $N '_en  ' "%"$txt" '"'
done

:



###  cfg.bish  #############################################

#!/u/bin/bish

set -f

VonBis()  {
   local sd=0000 nam
   [ $# -gt 0 ] || return
   for nam in $*
   do
      ifset $nam || continue
      while expr "${{nam}}" :sd '##%(-%{0,1}[0-9]%{1,}%)'
      do
         let 'sd+=von*inc2'
         expr "${{nam}}" :$nam '##-%{0,1}[0-9]%{1,}' = "$sd"
      done
      while expr "${{nam}}" :sd '#%(-%{0,1}[0-9]%{1,}%)'
      do
         let 'sd+=von'
         expr "${{nam}}" :$nam '#-%{0,1}[0-9]%{1,}' = "$sd"
      done
   done
   return 0
}


MakeTexte()  {
   #0.0.000.00000
   _id=0000000000
   grp=0000000
   obj=0000000
   sk=000000
   skvb=000000
   adr=0032
   buf=..................................................................
   von=000
   bis=000
   inc=000
   inc2=000
   info1=000
   info2=000
   parbn=00
   idadd=0000
   3>d__1
   print -u3 '%n#                include "def.h"'
   print -u3 '#                include "var.h"'
   print -u3 '#                include "texte.h"%n%n%n'
   print -u3 '// id: 0.0.000.00000'
   print -u3 '//       d grp object'
   print -u3 '
   // struct cfgdata_t { const BYTE *grp, *sgrp;
   //                    UNS4 id;
   //                    UNS2 adr, len, nbit, bitpos;
   //                    UNS4 flags;
   //                    BYTE typ, darst, info1, info2;
   //                    UNS2 parbn, nelem, voffs;
   //                    const BYTE FAR *dfstr;
   //                    UNS4 dfmima[3];
   //                    UNS2 szname;
   //                    VOL void *name;
   //                    const BYTE FAR *einheit, *text, *info;
   //                    cfap_t Tinfo, Tgrp, Tsgrp, Tbit, Text;
   // };
   '

   [ -n "$4" ] && : >$4
    >d__2
   4>d__3
   print -u4 '%n%n%nconst struct cfgdata_t FAR '"$1"'data[]= {'
   <$2
   while seek + 0 sk; read id dd typ bytelen darst nbit bitpos %
              dflt1 min1 max1 %
              parbn flags einheit name Tinfo Tgrp Tsgrp Tbit Text text
   do
      info1=?
      expr "$id" :: '^%$' && break
      expr "$id" :: '^}$' && {
         [ von -ge bis ] && inc=0 continue
         seek $skvb 0; let 'von+=inc'; continue
      }
      expr "$id" :: '^{#$' && {
         von=$dd bis=$typ inc=$bytelen inc2=$darst
         ifset inc2 || inc2=1
         seek + 0 skvb; continue
      }
      expr "$id" :: '^:..*' && {
         idadd=0 psgrp=0 obj=0 let grp+=500000
         seek $sk 0; readl Z; conv -D: Z
         [ inc -gt 0 ] && VonBis Z
         prints vssf08 pgrp G$1 $grp
         prints su3ss '       const BYTE       ' $pgrp "[]= %"$Z%";"
         echo
         let "adr>32" && let "adr=[(adr/264)+1+(adr%%264>=264/2)]*264"
         continue
      }
      expr "$id" :: '^%...*' && {
         seek $sk 0; readl Z; conv -D. Z
         [ inc -gt 0 ] && VonBis Z
         prints vssf08 psgrp g$1 $grp
         prints su3ss '       const BYTE       ' $psgrp "[]= %"$Z%";"
         continue
      }
      expr "$id" :id '^@%([0-9]%{1,}%)' && {
         let "obj+=500+idadd" "_id=grp+obj" "adr=$adr" "bytelen=$bytelen" "id=$id"
         idadd=0
         let dd && let "_id+=dd*100000000"
         let id && _id=$id
         [ inc -gt 0 -a "$typ" != s ] && VonBis name text Tinfo Tgrp Tsgrp Tbit Text
         [ inc -gt 0 -a "$typ" == s ] && VonBis name text dflt1 Tinfo Tgrp Tsgrp Tbit Text
         conv '-t` ' name
         idname="$name"
         expr "$idname" :: '^[A-Za-z_]' || idname="$text"
         expr "$idname" :idname '^%([^\]%{1,}%)\000'
         conv '-d[d]' idname
         expr "$idname" :idname '[^A-Za-z_0-9]' += '_'
         [ -n "$4" ] && prints ss-24s12 '#define ID_' "$idname" "$_id" >> $4
         nelem=1 voffs=0
         expr "$flags" :nelem 'A%([0-9]%{1,}%)' && {
            voffs='sizeof('"$name"')'
            [ "$name" == 0 ] && voffs=$bytelen
         }
         expr "$flags" :nelem 'S%([0-9]%{1,}%)' && {
            #expr "$name" :idname '^%(.*[^.]%)%.[^.]%{1,}$'
            expr "$name" :idname ']%..%{1,}$' = ']'
            voffs='sizeof('"$idname"')'
            [ "$name" == 0 ] && voffs=$bytelen
         }
         pad=0 autopad=0
         expr "$flags" :pad 'p%([0-9]%{1,}%)' || {
            autopad=1 let 'pad=bytelen*nelem'
         }
         buf='"'
         while :
         do
            seek + 0 sk
            readl Z
            expr "$Z" :: '^@:.' || { seek $sk 0; break; }
            catv 2,,Z =0:,,buf
         done
         [ ${#buf} -le 1 ] && buf=0
         [ ${#buf} -gt 1 ] && buf="$buf%""
         conv '-t` ' dflt1 text
         [ "$darst" ==  1 ] && darst=/
         expr "$darst" :darst '%.%([0-9]%)'
         [ "$dflt1" == '"' ] && dflt1=0
         [ "$typ" == s -a "$dflt1" == '\000' ] && dflt1=
         if [ "$typ" == s ]
         then
            let "autopad&&pad>4" && let "pad>>=1"
            ptr='&'
            w1= w2= w3=
            min1='0'
            max1="$min1"
            expr "$flags" :: '#' && goend
            dflt1="%"$dflt1%""
         else
            ptr='&'
            w1=15 w2=15 w3=14
            [ "$min1" == '"' ] && min1=0
            [ "$max1" == '"' ] && max1=0
            [ "$typ" == s ] && goend
            l=4 u=u
            [ bytelen -eq 4 ] && l=8 u=ul
            for v in dflt1 min1 max1
            do
               case "$typ" in
                 b)  expr "${{v}}" :$v '^x%([0-9a-fA-F]%{1,}%)$' && goend
                     base -2 $v +16 $v ;;
                 x)  goend ;;
                 *)  continue ;;
               esac
               prints vssf0${l}s $v 0x ${{v}} $u ;;
            done
         fi
         flg=000000 info2=0
         expr "$flags" :info2 '=%([1-9][0-9]%{0,2}%)'
         expr "$flags" :: '[sz]' && let autopad && pad=0
         expr "$flags" :: 'a' && let "flg|=1<<30"
         expr "$flags" :: 'h' && let "flg|=1<<20"
         expr "$flags" :: 'u4' && let "flg|=1<<19"
         expr "$flags" :: 'u3' && let "flg|=1<<18"
         expr "$flags" :: 'u2' && let "flg|=1<<17"
         expr "$flags" :: 'u1' && let "flg|=1<<16"
         expr "$flags" :: 'd' && let "flg|=1<<15"
         expr "$flags" :: 'c' && let "flg|=1<<14"
         expr "$flags" :: 'I' && let "flg|=1<<13"
         expr "$flags" :: 't1' && let "flg|=1<<12"
         expr "$flags" :: 'l' && let "flg|=1<<11"
         expr "$flags" :: 't2' && let "flg|=1<<10"
         expr "$flags" :: 'B[AS][0-9]' && let "flg|=256"
         expr "$flags" :: '1%.' && let "flg|=128"
         expr "$flags" :: 'q' && let "flg|=64"
         expr "$flags" :: 'K[AS][0-9]' && let "flg|=32"
         expr "$flags" :: 'i' && let "flg|=16"
         expr "$flags" :: 's' && let "flg|=8"
         expr "$flags" :: 'n' && let "flg|=4"
         expr "$flags" :: 'b' && let "flg|=2"
         expr "$flags" :: 'r' && let "flg|=1"
         expr "$flags" :: '&' && ptr=
         ds=0000000000000000000
         vname=$name
         expr "$flags" :: 'v' && ds=v name=0
         [ "$name" == 0 -o "$name" == '"' ] && name=0 ptr= let "flg|=512"
         [ "$name" != 0 ] && print -u5 "$1%t$bytelen%t$name"
         prints vssf08s flags 0x $((16#, flg)) ul
         prints vsf010 pid $_id
         echo
         prints s-28sbs %
                "#define D${pid}grp" $pgrp, $psgrp
         echo "// id; adr, len, nbit, bitpos,"
         echo "// flags(_|abgl|_|_|_|_|_|_ | _|_|_|halten|u4cal|u3sys|u2hw|u1root)"
         echo "// flags(dfltcalc|access|IP|Telem|infovals|Tbbig|novar|batt | step10|mess|kamm|initcan|sig|nod|bak|ro);"
         echo "// typ, darst, info1, info2, parbn, nelem, voffs;"
         prints s-28s11bs6bs5bs5bs5bsbsbsbsbsbsbsbs %
                "#define D${pid}obj" %
                 $_id, $adr, $bytelen, $nbit, $bitpos, $flags, %
                 "'$typ'," "'$darst'," "'$info1'," "$info2," %
                 $parbn, "$nelem," "$voffs"
         if [ "$typ" == s ]
         then
            [ "$ds" == v ] && prints s "       const BYTE ${vname}[]= $dflt1;"
            prints s "       const BYTE FAR S${pid}[]= $dflt1;"
            ds=S${pid} dflt1=0 min1=0 max1=0
         else
            ds=0
         fi
         prints s-28s %
                "#define D${pid}str" "$ds"
         prints s-28s${w1}bs${w2}bs${w3} %
                "#define D${pid}dfmima" "$dflt1," "$min1," "$max1"
         prints s-28sbs %
                "#define D${pid}szname" "sizeof($name)," "$ptr$name"
         if [ "$einheit" != '"' ]
         then
            prints s "       const BYTE FAR E${pid}[]= %"$einheit%";"
            einheit=E${pid}
         else
            einheit=0
         fi
         prints s "       const BYTE FAR T${pid}[]= %"$text%";"
         text=T${pid}
         prints s-28s11sbs11 %
                "#define D${pid}einhtxt" "$einheit" , "$text"
         if [ "$buf" != 0 ]
         then
            prints s "       const BYTE FAR I${pid}[]= $buf;"
            buf=I${pid}
         else
            buf=0
         fi
         prints s-28s11 %
                "#define D${pid}info" "$buf"
         prints s-28sbsbsbsbs %
                "#define D${pid}Text"  $Tinfo, $Tgrp, $Tsgrp, $Tbit, $Text
         let "adr+=bytelen*nelem+pad"
         let "nelem>1" && idadd=500
         prints su4sbsbsbsbsbsbsbsbs '   { ' %
                D${pid}grp, D${pid}obj, D${pid}str, %
              "{D${pid}dfmima}," %
                D${pid}szname, D${pid}einhtxt, D${pid}info, D${pid}Text ' },'
         continue
      }
   done
   print -u4 '   { 0 }%n};%n%nconst unsigned '"$1"'data_ne= sizeof('"$1"'data)/sizeof(*'"$1"'data);%n%n'
   ><<<<
   cat d__1 d__2 d__3 > $3
   remove d__1 d__2 d__3
   return 0
}


5>vn.txt
MakeTexte CFG cfgbase.txt cfgdata.c cfg.h
MakeTexte MES mesbase.txt mesdata.c
><

#(cfg2.bish)

exit 0

#     prints s-33s${w1}bs${w2}bs${w3} %
#            "#define D${pid}dfltminmax10" "$dfltbm," "$minbm," "$maxbm"
#     prints s-33s${w1}bs${w2}bs${w3} %
#            "#define D${pid}dfltminmax11" "$dfltbm2," "$minbm2," "$maxbm2"
#            D${pid}dfltminmax10, "D${pid}dfltminmax11}," %



###  com.bish  #############################################

#!/u/bin/bish -p



# define MSK16  0x0810= 2064
# start= 0x1d0f= 7439
# CRC<--  Buf $offs $len
Crc16old()  {
   local n=00 crc_=000${{1} byte=000000 j=00000000
   let "crc_>16#ffff" && crc_=0007439
   for byte in $( catv $3,$4,$2 | base -b +10 )
   do
      for n from 0 to 7 repeat
      do
         if let "crc_&16#8000 ^^ byte&1<<n"
         then
            let 'j=((crc_^2064)&2064)<<1' %
                'crc_= (j|crc_<<1) & (j|~(2064<<1)) & 16#ffff | 1'
         else
            let 'j=((crc_^~2064)&2064)<<1' %
                'crc_= (j|crc_<<1) & (j|~(2064<<1)) & 16#fffe'
         fi
      done
   done
   $1=$crc_
   return 0
}


# cmd
Cmd()  {
   local cmd="@3!$1$NL"
   local len=${#cmd}
   com -cot40od10o$len cmd
   catv $len,cmd
   return 0
}

# cmd
Answ()  {
   local cmd="@3:$1$NL"
   local len=${#cmd}
   com -cot40od10o$len cmd
   catv $len,cmd
   return 0
}


# num|str [len]
IBDdata()  {
   local cks=000
   [ $# -eq 1 ] && {
      local dat=$1
      local l=${#dat}
   }
   [ $# -eq 2 ] && {
      local l=$2 dat=000$1
      [ l -eq 4 ] && base -10 dat +l dat
      [ l -eq 2 ] && base -10 dat +w dat
      [ l -eq 1 ] && base -10 dat +b dat
   }
   let ++l
   base -10 l +b l
   catv /: l dat =Out:
   catv 1,,Out | sum -b cks
   let 'cks=~cks&255'
   base -10 cks +b cks
   catv cks =0:,1,Out:
   com -cot40od10o${#Out} Out
   return 0
}


# id data
ParaData()  {
   local dp=:
   local id=$1 data="$2" l=0000 bl=0
   [ O -eq 0 ] && O=1 catv /: =0,1,Obuf
   if [ id -ne 0 ]
   then
      l=${#data}
      base -10 id +l id
      base -10 l +b bl
      catv id bl data =$O,,Obuf
      let "O+=4+1+l"
   else
      l=2
      base -10 id +l id
      base -10 l +b bl
      catv id bl =$O,,Obuf
      let "O+=4+1"
      CRC=100000
      Crc16 CRC Obuf 1 $((O-1))
      base -10 CRC +w data
      catv data =$O,,Obuf
      let "O+=2"
      catv $O,Obuf | base -b +10
      com -cot90od10o$O Obuf
   fi
   return 0
}

#       com -p || return 0
#       ring=128
#       base -10 ring +b ch
#       ring=@PC:
#       com -cot40od10o4 ring
#       com -it400id20i1 Ibuf
#       catv 1,Ibuf /%j
#       com -cot30od10o1 ch
#       com -it3500id20i2050 Ibuf
set NL:10.1
set Ibuf:0.4000
set Obuf:0.1000
set Out:080
O=00000
CRC=100000

#BSD: /dev/cuaa0, /dev/ttyd0
case "FreeBSD" in
  FreeBSD)   Sio='/dev/ttyd0' Tty='/dev/console';;
  OpenUnix)  Sio='/dev/term/00t' Tty='/dev/pts016';;
  *)         Sio='/dev/null' Tty='/dev/console';;
esac
#1>> $Tty
#2>> $Tty
com +L  $Sio || { print -u2 "TTY-Device '$Sio'" "open failed"; exit 0; }
com -B38400
com -s 1
com -H 0

Cmd PING

local L_z=a L_tmo=30 L_w=1 L_bn=0
[ $# -gt 0 ] && L_z=$1



while let "$SECONDS<L_tmo"
do
   sleep -m 20
   com -p && {
      com -it150id10i100 Ibuf
      catv /++ $.,Ibuf /--%n
      catv '/>>'
      catv $.,Ibuf | base -b +10
      catv '/<<%n'
      [ L_w -eq 2 ] && Answ OK
      let ++L_tmo
      L_w=0
   }
   [ L_w -ne 0 ] && continue
   sleep -m 50
   case $L_z in
     a)  Cmd CFG_PARA
         L_z=b
     ;;
     b)  Cmd RECV
         L_z=c
     ;;
     c)  O=0
         ParaData 200000 aaccbbdd
         ParaData 0 "crc"
         L_z=d
     ;;
     d)  Cmd STORE
         L_z=z
     ;;
     I)  Cmd ID
         L_z=Id
     ;;
     Id)  IBDdata 200511305 4
         L_z=B L_bn=0
     ;;
     B)  [ L_bn -ge 32 ] && L_z=z continue
         Cmd BIT
         L_z=Bn
     ;;
     Bn) IBDdata $L_bn 1
         let ++L_bn
         L_z=S
     ;;
     S)  Cmd SEND
         L_z=B
         L_w=2 continue
     ;;
     z)  continue ;;
   esac
   L_w=1
done


com -c
com -
exit 0





###  sedm.bish  #############################################



RA='
w REQ_MOU1 REQ_MOUE
w REQ_MOU2 REQ_MOUI
'
W=......
set O:.50
set N:.50

for 3 W O N in $RA
do
   [ "$W" == a ] && W=-a
   [ "$W" == w ] && W=
   print -u2 "%t$W: $O $N"
   bish ./sed.bish $W "$O" "$N"
done


exit 0

w uart1sovr uartmsovr
w uart1crc uartmcrc
w uart0hw uartehw
w uart0buf uartebuf
w uart1hw uartmhw
w uart1buf uartmbuf
w uart2hw uartihw
w uart2buf uartibuf
w uart3hw uartfhw
w uart3buf uartfbuf
w uart0recv uarterecv
w uart1recv uartmrecv
w uart2recv uartirecv
w uart3recv uartfrecv
w uart1tmo0 uartmtmo0
w uart1tmo1 uartmtmo1
w uart1tmo2 uartmtmo2
w uart1tmo uartmtmo
w uart1tmo0 uartmtmo0
a TXIRPT(0) TXIRPT(UNE)
a TXIRPT(1) TXIRPT(UNM)
a TXIRPT(2) TXIRPT(UNI)
a TXIRPT(3) TXIRPT(UNF)
a RXIRPT(0) RXIRPT(UNE)
a RXIRPT(1) RXIRPT(UNM)
a RXIRPT(2) RXIRPT(UNI)
a RXIRPT(3) RXIRPT(UNF)
a TXDATA(0) TXDATA(UNE)
a TXDATA(1) TXDATA(UNM)
a TXDATA(2) TXDATA(UNI)
a TXDATA(3) TXDATA(UNF)
a RXDATA(0) RXDATA(UNE)
a RXDATA(1) RXDATA(UNM)
a RXDATA(2) RXDATA(UNI)
a RXDATA(3) RXDATA(UNF)
a ISTXDATA(0) ISTXDATA(UNE)
a ISTXDATA(1) ISTXDATA(UNM)
a ISTXDATA(2) ISTXDATA(UNI)
a ISTXDATA(3) ISTXDATA(UNF)
a ISRXDATA(0) ISRXDATA(UNE)
a ISRXDATA(1) ISRXDATA(UNM)
a ISRXDATA(2) ISRXDATA(UNI)
a ISRXDATA(3) ISRXDATA(UNF)
a CLRRXERR(0) CLRRXERR(UNE)
a CLRRXERR(1) CLRRXERR(UNM)
a CLRRXERR(2) CLRRXERR(UNI)
a CLRRXERR(3) CLRRXERR(UNF)
a GETRXERR(0) GETRXERR(UNE)
a GETRXERR(1) GETRXERR(UNM)
a GETRXERR(2) GETRXERR(UNI)
a GETRXERR(3) GETRXERR(UNF)
a RXERR(0) RXERR(UNE)
a RXERR(1) RXERR(UNM)
a RXERR(2) RXERR(UNI)
a RXERR(3) RXERR(UNF)
w U0t Uet
w U1t Umt
w U2t Uit
w U3t Uft
w U0r Uer
w U1r Umr
w U2r Uir
w U3r Ufr
w Putc0 PutcE
w Putc1 PutcM
w Putc2 PutcI
w Putc0i PutcEi
w Putc1i PutcMi
w Putc2i PutcIi
w Write0 WriteE
w Write1 WriteM
w Write2 WriteI
w Write0s WriteEs
w Write1s WriteMs
w Write2s WriteIs


###  cfg2.bish  #############################################

#!/u/bin/bish


INCL='
#                include "def.h"
#                include "var.h"
#                include "texte.h"


'
HDR='
// id: 0.0.000.00000
//       d grp object

   // struct cfgdataT_t { cfap_t Tinfo, Tgrp, Tsgrp, Tbit, Text; };
   //
   // struct cfgdata_t { const BYTE *grp, *sgrp;
   //                    UNS4 id;
   //                    UNS2 adr, len, nbit, bitpos, flags;
   //                    BYTE typ, darst, info1, info2;
   //                    UNS2 parbn, nelem, voffs;
   //                    const BYTE FAR *dfstr;
   //                    UNS4 dfmima[2][3];
   //                    UNS2 szname;
   //                    VOL void *name;
   //                    const BYTE FAR *einheit, *text, *info;
   //                    const struct cfgdataT_t FAR *T;
   // };



'
i=000000
set Z:.200
set Ta:.100
set Tb:.100

CFG2()  {
   i=-1
   3>$1data0.c
   4>$1dataT.c
   catv HDR =3
   catv INCL HDR =4
   < $1data.c
   while readl Z
   do
      expr "$Z" :: '^#define D%D%{10}grp ' && {
	 let ++i; catv /%n =4; catv Z /%n =3; continue
      }
      expr "$Z" :Ta ' %(const BYTE FAR E[0-9]%{10}%[]%)= ' && {
         expr "$Z" :Tb '%[]= %(".%{1,}%);$' || echo $i:$Ta
         catv '.   extern ' Ta '.;  //' Tb /%n =3
         catv Z /%n =4
         continue
      }
      expr "$Z" :Ta ' %(const BYTE FAR T[0-9]%{10}%[]%)= ' && {
         expr "$Z" :Tb '%[]= %(".%{1,}%);$' || echo $i:$Ta
         catv '.   extern ' Ta '.;  //' Tb /%n =3
         catv Z /%n =4
         continue
      }
      expr "$Z" :Ta ' %(const BYTE FAR I[0-9]%{10}%[]%)= ' && {
         expr "$Z" :Tb '%[]= %(".%{1,}%);$' || echo $i:$Ta
         catv '.   extern ' Ta '.;  //' Tb /%n =3
         catv Z /%n =4
         continue
      }
      expr "$Z" :Ta '^%(#define D%D%{10}Text %{1,}%)' && {
         catv Ta "/&$2dataT[$i]%n" =3
         catv Z /%n =4
         continue
      }
      expr "$Z" :: 'const struct cfgdata_t FAR '"$2"'data%[]= {' && {
         catv '/%n%n%nconst struct cfgdataT_t FAR '"$2"'dataT[]= {%n' =4
      }
      expr "$Z" :Ta '^ %{1,}{ D.%{1,}%( D%D%{10}Text %)' && {
         catv '/   {' Ta '/},%n' =4
      }
      catv Z /%n =3
   done
   catv '/   { 0 }%n};%n%n%n%n' =4
   ><<<
   echo $i
   return 0
}


CFG2 cfg CFG
CFG2 mes MES





###  atp.bish  #############################################

#!/u/bin/bish_com
#!/u/cys/wms/cgi/bish_lxs_cgi -p_


set -f

MUanrufen()  {
   local telnu=$1 ch=00 offs=00000 cksum:010 ring="RING$RN.........."
   while :
   do
   case $AnrufZ in
     dialout)
        [ MOwahl -eq 0 ] && AnrufZ=getdata continue
        let "$SECONDS-DOtime<=40" && { sleep 2; continue; }
        WriteAT "$MOdialout" "$telnu" || DOtime=$SECONDS break
        AnrufZ=waitpass TOsec=$SECONDS DOtime=0
     ;;
     waitpass)
        let "$SECONDS-TOsec>10" && break
        com -p || return 0
        AnrufZ=pass
     ;;
     pass)
        com -it400id15i1000 Ibuf
        catv $.,Ibuf =Hbuf:
        catv Hbuf
        expr "$Hbuf" =:: 'PASSWORD:' || break
        ring="@YYTklqmopas"
        com -cot50od10o10 ring
        sleep -m 150
        com -ocot30od10o2 RN
        AnrufZ=waitpassok TOsec=$SECONDS
     ;;
     waitpassok)
        let "$SECONDS-TOsec>10" && break
        com -p || return 0
        AnrufZ=passok
     ;;
     passok)
        com -it300id15i1000 Ibuf
        catv $.,Ibuf =Hbuf:
        catv Hbuf
        expr "$Hbuf" =:: 'PASSWORD %{1,3}OK' || break
        AnrufZ=getdata
     ;;
     getdata)
        [ Status -eq 2 ] && AnrufZ=writecfg continue
        [ Status -eq 3 ] && AnrufZ=readcfg continue
        GetMUdata $Fmustatus Nn dk40 || {
           echo "$Nn Bytes"
           [ MOwahl -eq 0 ] && break
           ring=@EN:
           com -cot30od10o4 ring
           break
        }
        echo "$Nn Bytes"
        AnrufZ=data
     ;;
     data)
        MUkategorie_c $Fmustatus
        cat $Fmustatus > $MUdir/stat
        [ ! -e "$MUdir/lock" -o ! -s "$MUdir/eepr" ] && AnrufZ=readcfg continue
        [ MOwahl -eq 0 ] && AnrufZ=0 goend
        AnrufZ=mowrite continue
     ;;
     mowrite)
        ring=@EN:
        sleep -m 400
        com -cot50od10o4 ring
        echo @EN: = $.
        AnrufZ=waitmoend TOsec=$SECONDS
     ;;
     waitmoend)
        let "$SECONDS-TOsec>10" && break
        com -p || return 0
        AnrufZ=moend
     ;;
     moend)
        com -it300id15i1000 Ibuf
        catv $.,Ibuf =Hbuf:
        catv Hbuf
        expr "$Hbuf" =:: 'Connection %{1,3}aborted' || break
        AnrufZ=0
        #[ Status -eq 2 -o Status -eq 3 ] && AnrufZ=0
     ;;
     dialin)
        WriteAT "$MOabnehmen" || break
        AnrufZ=getokayfail
     ;;
     getokayfail)
        GetMUdata $Fokayfail Nn rdonly || break
        echo "$Nn Bytes"
        AnrufZ=okayfail
     ;;
     okayfail)
        #< $Fokayfail
        #><
        #MkTbl5data $Ftbl5 addmu "$mustat" "$muokfa" "$mudati"
        AnrufZ=0
     ;;
     writecfg)
        sum -w cksum < $MUdir/eepr
        let "cksum+=16#1d0f, cksum&=65535"
        base -10 cksum +w cksum
        ring=129
        base -10 ring +b ch
        ring=@PC:
        com -cot40od10o4 ring
        com -it400id20i1 Ibuf
        catv 1,Ibuf /%j
        com -cot30od10o1 ch
        com -it400id10i1 Ibuf
        catv 1,Ibuf /%j
        catv 2048,0 =Hbuf < $MUdir/eepr
        for offs from 0 by 32 to 2016 repeat
        do
           com -cot80od10oO${offs}o32 Hbuf
           com -it600id20i1 Ibuf
           catv 1,Ibuf
        done
        com -cot30od10o2 cksum
        com -it400id10i2 ring
        echo
        catv 2,cksum =cksum:
        catv 2,ring =ring:
        base -w cksum +16
        base -w ring +16
        cmpv cksum ring || break
        [ MOwahl -ne 0 ] && AnrufZ=mowrite continue
        AnrufZ=0
     ;;
     readcfg)
        ring=128
        base -10 ring +b ch
        ring=@PC:
        com -cot40od10o4 ring
        com -it400id20i1 Ibuf
        catv 1,Ibuf /%j
        com -cot30od10o1 ch
        com -it3500id20i2050 Ibuf
        echo $.
        catv 2048,Ibuf > ../tmp/eeprin
        sum -w cksum < ../tmp/eeprin
        let "cksum+=16#1d0f, cksum&=65535"
        base -10 cksum +w cksum
        com -cot30od10o2 cksum
        catv 2,cksum =cksum:
        catv 2048,2,Ibuf =ring:
        base -w cksum +16
        base -w ring +16
        cmpv cksum ring || break
        mucrc cksum Ibuf 2 1898 || break
        catv 0,2,Ibuf =ring:
        base -w ring +10 ring
        echo "$cksum : $ring"
        [ cksum -ne ring ] && break
        cat ../tmp/eeprin > $MUdir/eepr
        remove ../tmp/eeprin
        #base -W +w < $MUdir/eepr | catv 2048,0 =5000,2048,3  3<> C:\DATA.MUC
        #catv $(( 960<<1)),2,0 =ring:  < $MUdir/eepr
        #base -w ring +10 ring
        #MUspsw=0
        #let "ring==1" && MUspsw=1
        #catv $((1001<<1)),2,0 =ring:  < $MUdir/eepr
        #base -w ring +10 ring
        #let "ring==1" && MUspsw=2
        [ MOwahl -ne 0 ] && AnrufZ=mowrite continue
        AnrufZ=0
     ;;
   esac
   return 0
   done
   return 1
}


GetMUdata()  {
   local nrw=0000000000 sum=00000
   catv /@YYTklq: =6,Ibuf
   [ "$3" == dk40 ] && com -cot100od10o6 Ibuf
   until com -p
   do
      let "sum+=10, sum>3000" && break
      sleep -m 10
   done
   echo "InputWait: $sum ms"
   com -it500id20i4000 Ibuf
   nrw=$. $2=$. sum=0
   let "sum+=nrw, nrw==0" && return 1
   > $1
   while [ nrw -gt 0 ]
   do
      [ "$3" == dk40 ] && conv '-t `' Ibuf
      catv $nrw,Ibuf
      com -it500id20i4000 Ibuf
      let "nrw=$., sum+=nrw"
   done
   ><
   $2=$sum
   return 0
}


MAIN()  {
   sleep -m $Wait
   Sec=$SECONDS
   case $Status in
     0)
        [ MUcall -ge 30 -a MUcall -le 39 ] && { let "MUcall-=20"; Uvars MUcall; }
        com -p && {
           [ MOwahl -eq 0 ] && { com -ic; continue; }
           com -it60id10i1500 Ibuf
           catv $.,Ibuf =Hbuf:
           catv '/[' Hbuf '/]'
           GetMOmsgNr Hbuf && let "Hbuf&4" && MOri=1 MOrings=0 %
              MOritime=$Sec Wait=150 Status=9 MUcall=39 Uvars MUcall
           continue
        }
        fstat -mv Uv uvars.bish
        [ Uv -ne Uv0 ] && { Uv0=$Uv  . ./uvars.bish; }
        [ MOwahl -ne 0 -a MOisinit -ne 1 ] && {
           Status=7 MOinittime=-30
           [ MOisinit -eq 0 ] && MUcall=37 Uvars MUcall
           continue
        }
        [ MOwahl -eq 0 ] && MOisinit=0
        [ Sec -ge St ] && {
           let "St=Sec+10"; systime Stime
           [ ConnTest -gt 0 ] && [ -s $Fstation ] && {
              [ CTbuild -ne 0 ] && { BuildCT; continue; }
              let "Sec-DOtime<=90||Sec-CTwait<=150" && continue
              [ Stime -ge CTtime -a CTtime -ge 10 ] && {
                 SetVarsCT && MUcall=6; } ||
                 WrLog "Connect test" "SetVars failed: $CTgid/$CTaid"
           }
        }
        [ MUcall -eq  1 ] && Status=1
        [ MUcall -eq  2 ] && Status=2
        [ MUcall -eq  6 ] && Status=6 echo CT: $CTgid $CTaid $CTtime $CTday
        [ MUcall -lt  0 ] && MUcall=00 Uvars MUcall
        [ Status -ne 0 ] && { AnrufZ=dialout let "MUcall=Status+30"; Uvars MUcall; }
        continue
     ;;
     9)
        if com -p
        then
              MOri=0
              com -it60id10i1500 Ibuf
              catv $.,Ibuf =Hbuf:
              catv '/[' Hbuf '/]'
              GetMOmsgNr Hbuf && let "Hbuf&4" && MOri=1
        else  let "MOrings+=MOri, MOrings>=3" && {
                 Status=8 Wait=500 MUcall=38 Uvars MUcall
                 AnrufZ=dialin continue
              }
              MOri=0
        fi
        let "Sec-MOritime>20" && {
           Status=0 Wait=500 MUcall=29 Uvars MUcall
           WrLog "RING event" "less then 3 rings"
           continue
        }
        continue
     ;;
     1)
        MUanrufen $Telnu || { 
           MOisinit=2 Status=0 MUcall=21 Uvars MUcall
           WrLog "Call get data" "failed: $AnrufZ" $MUdir/log
        }
        [ $AnrufZ != 0 ] && continue
        MOisinit=2 Status=0 MUcall=11 Uvars MUcall
        continue
     ;;
     2)
        MUanrufen $Telnu || { 
           MOisinit=2 Status=0 MUcall=22 Uvars MUcall
           WrLog "Call configure" "failed: $AnrufZ" $MUdir/log
        }
        [ $AnrufZ != 0 ] && continue
        MOisinit=2 Status=0 MUcall=12 Uvars MUcall
        continue
     ;;
     6)
        MUanrufen $Telnu || { 
           WrLog "Connect test $MUdir" "failed: $AnrufZ"
           WrLog "Connect test" "failed: $AnrufZ" $MUdir/log
           GetTryCT Hbuf
           if [ Hbuf -ge CTtries ]
           then  FailCT; WriteCT full
           else  WriteCT try
           fi
           NextCT; CTwait=$Sec
           MOisinit=2 Status=0 MUcall=26 Uvars MUcall
        }
        [ $AnrufZ != 0 ] && continue
        WriteCT okay; NextCT; CTwait=$Sec
        MOisinit=2 Status=0
        continue
     ;;
     8)
        MUanrufen || { 
           MOisinit=2 Status=0 MUcall=28 Uvars MUcall
           WrLog "Incoming call" "failed: $AnrufZ"
        }
        [ $AnrufZ != 0 ] && continue
        OkayFail $Fokayfail || MUcall=28 Uvars MUcall
        MOisinit=2 Status=0
        continue
     ;;
     7)
        fstat -mv Uv uvars.bish
        [ Uv -ne Uv0 ] && { Uv0=$Uv  . ./uvars.bish; }
        [ MOwahl -eq 0 ] && Status=0 MOisinit=0 continue
        let "$Sec-MOinittime<30" && continue
        WriteAT "$MOauflegen"
        WriteAT "$MOinit" && Status=0 MOisinit=1
        [ MOisinit -eq 2 ] && Status=0 MOisinit=0
        MOinittime=$Sec
        continue
     ;;
   esac
}
#------------------------------------------------------------------------


WaitData()  {
   local dp=0 len=00000
   Ilen=0
   com -it400id20i1 dp
   if expr "$dp" :: '^:$'
   then
      com -it400id20i1 dp
      base -b dp +10 len
      com -it400id20i$len Ibuf
      Ilen=$.
      Mode=BIN
   else
      com -it400id20i1000 Ibuf
      Ilen=$.
      catv 1,dp $Ilen,Ibuf =Ibuf
      let "++Ilen"
      Mode=TXT
   fi
   return 0
}


WaitREADY()  {
   local ok:.20
   com -it700id20i10 Ibuf
   catv $.,Ibuf =20,ok:
   expr "$ok" :: '^@[0-9]:READY'"$RN" || return 1
   catv 10,Ibuf
   return 0
}


WaitOK()  {
   local ok:.20
   com -it400id20i7 Ibuf
   catv $.,Ibuf =20,ok:
   expr "$ok" :: '^@[0-9]:OK'"$RN" || return 1
   catv 7,Ibuf
   return 0
}


Kommando()  {
   echo $1
   return 0
}


ID()  {
   local n=0000000000 id=0000000000$1
   local len=5 cksum=00000 ilen=00000
   base -10 id +l id
   base -10 len +b len
   catv 1,len 4,id | sum -b cksum
   let "cksum=~cksum&255"
   base -10 cksum +b cksum
   catv /: 1,len 4,id 1,cksum =id:
   for n to $Lcnt repeat
   do
      [ Lcnt -gt 1 ] && echo %t$n
      while :
      do
         case $IdZ in
           IDsend)
             Obuf="@3!ID$RN"
             com -cot40od10o7 Obuf
             WaitOK || break 2
             com -cot40od10o7 id
             WaitOK || break 2
             Obuf="@3!SEND$RN"
             com -cot40od10o9 Obuf
             WaitOK || break 2
             IdZ=datarecv
             ;;
           datarecv)
             WaitData || break 2
             ilen=$Ilen
             [ $Mode == BIN ] && let --ilen
             catv $ilen,Ibuf /%j
             Obuf="@3:OK$RN"
             com -cot40od10o7 Obuf
             IdZ=IDsend
             WaitREADY || break 2
             #sleep -m 10
             break
             ;;
         esac
      done
   done
   IdZ=IDsend
   return 0
}
#------------------------------------------------------------------------


#8>&1

set Ibuf:0.2048
set Obuf:0.1024
IdZ=IDsend
Ilen=0000000000
Mode=BIN
Lcnt=0000000001
Lcnt=1
Ofile=stdout
catv /%r%n =RN:

#BSD: /dev/cuaa0, /dev/ttyd0
case "FreeBSD" in
  FreeBSD)   Sio='/dev/ttyd0' Tty='/dev/ttyp1';;
  OpenUnix)  Sio='/dev/term/00t' Tty='/dev/pts016';;
  *)         Sio='/dev/null' Tty='/dev/console';;
esac
#1>> $Tty
#2>> $Tty

com +L  $Sio || { print -u2 "TTY-Device '$Sio'" "open failed"; com -; exit 1; }
com -B57600
com -s 1
com -H comhandle
fstat -h 0 1 2 $comhandle
echo

Obuf="@3!START$RN"
com -cot40od10o10 Obuf
WaitOK || { print -u2 "START failed"; com -; exit 2; }


while print -u2 "
%tAusgabedatei  : o file  [$Ofile]
%tLoop count    : l #     [$Lcnt]
%tKommando      : Kommando
%tID+SEND       : #       (id)
%tBeenden       : E

%t              : _%b%c"
do
   read cmd opt
   com -p && { com -it700id20i1000 Ibuf; catv $.,Ibuf; }
   ifset cmd || continue
   case "$cmd" in
     o)  expr "$opt" :: '^[a-zA-Z_0-9/\]%{1,}$' || continue
         [ $Ofile == $opt ] && continue
         Ofile=$opt
         if [ $Ofile == stdout ]
         then  ><
         else  1>$Ofile
         fi
         ;;
     l)  expr "$opt" :: '^[1-9][0-9]*$' || continue
         Lcnt=$opt
         ;;
     [a-zA-Z][a-zA-Z_0-9]*)
         expr "$cmd" :: '^[a-zA-Z_0-9]%{2,15}$' || continue
         Kommando $cmd ;;
     [0-9]??*)
         expr "$cmd" :: '^[0-9][0-9]*$' || continue
         ID $cmd ;;
     E)  break;;
     *)  echo %a%c; continue;;
   esac
done


Obuf="@3!END$RN"
com -cot40od10o8 Obuf
WaitOK || print -u2 "END failed"

com -
#[ -t 1 -a -n "$Tty" -a -c "$Tty" ] && ><
#[ -t 2 -a -n "$Tty" -a -c "$Tty" ] && ><
exit 0





###  c256.bish  #############################################

#!/home/bin/bish

for C from 0 to 255 repeat
do
   base -10 C +b CB
   let "C<32" && CB=" "
   prints ss3ss4  "   /* " $C " '$CB' */  " $C,
done



###  btr.bish  #############################################

#!/u/bin/bish

# CAN BTR Bittimeregister

local mhz=000 bt=0000000000 BT=10000000 #picos
local picos=00000 rsj=00 ts1=00 ts2=00 psc=00
local tq=0000000000 rsjw=00000
local Ts1=0000000000 Ts2=0000000000 c=00

for 2 mhz picos in 32 31250 16 62500
do
   for rsj from 0 to 3 repeat
   do
      for ts1 from 0 to 15 repeat
      do
         for ts2 from 0 to 7 repeat
         do
            for psc from 1 to 63 repeat
            do
               (( tq= (psc+1)*picos,
                  bt= (3+ts1+ts2)*tq,
                  rsjw= (rsj+1)*tq,
                  Ts1= (ts1+1)*tq,
                  Ts2= (ts2+1)*tq,
                  bt!=BT
               )) && continue
               c=00
               let "Ts1>2*tq&&Ts1>rsjw&&Ts2>2*tq&&Ts2>rsjw+2*tq" && c='>> '
               [ $c == 00 ] &&
               let "Ts1>2*tq&&Ts1>rsjw&&Ts2>2*tq&&Ts2>rsjw" && c=' > '
               [ $c == 00 ] &&
               let "Ts1>=2*tq&&Ts1>=rsjw&&Ts2>=2*tq&&Ts2>=rsjw+2*tq" && c='>>='
               [ $c == 00 ] &&
               let "Ts1>=2*tq&&Ts1>=rsjw&&Ts2>=2*tq&&Ts2>=rsjw" && c=' >='
               [ $c == 00 ] && continue
               echo "// ${mhz}[MHz]" "$((bt/1000))[ns]" %
                    "$c" ts2=$ts2 ts1=$ts1 rsj=$rsj psc=$psc
               #Ts1=$Ts1 Ts2=$Ts2 rsjw=$rsjw tq=$tq
            done
         done
      done
   done
done

:




###  batt.bish  #############################################


[ $# -eq 0 ] && {
   Files=?*.[chCH]
   Files="$Files CFGBASE.TXT"
}
[ $# -gt 0 ] && Files=$*

for F in $Files
do
   m=0
   cat $F | {
      > $F
      while readl Z
      do
         expr "$Z" :Z 'Batt%.i1%[' += 'Batt.i[' && m=1
         expr "$Z" :Z 'Batt%.%(%W%{1,}%)%(%[[^]]%{1,}]%)' + 'Batt.B%2.%1' && m=1
	 catv Z /%r%n
      done
      ><
   }
   [ m -eq 1 ] && echo $F
done



###  fmtbase.bish  #############################################




ANAM='id dd typ bytelen darst nbit bitpos
dflt1 min1 max1
parbn flags einheit name Tinfo Tgrp Tsgrp Tbit Text text
'
set Z:.200
set feld:.50

[ -t 0 ] && exit 0


Print()  {
   seek + 0 sk
   while readl Z
   do
      expr "$Z" :: '^@[0-9]' && break
   done
   : $Z
   nf=$,
   print -u2 "Felder=$nf"
   n=000
   for n to $nf repeat
   do
      set l$n:08
   done
   seek $sk 0
   while readl Z
   do
      ifset Z || continue
      expr "$Z" :: '^@[0-9]' || continue
      : $Z
      [ $, -ne nf ] && { print -u2 "$, != $nf"; return 1; }
      n=0
      for feld in $Z
      do
         let ++n; let "${#feld}>l$n" && let "l$n=${#feld}"
      done
   done
   for n to $nf repeat
   do
      catv l$n '/ ' =2
   done
   print -u2
   w=00000
   seek $sk 0
   while readl Z
   do
      ifset Z || { catv /%n; continue; }
      expr "$Z" :: '^@[0-9]' || { catv Z /%n; continue; }
      n=0
      for feld in $Z
      do
	 let ++n
	 [ n -ge nf ] && { catv feld /%n; continue; }
         w=l$n; w=${{w}}; let ++w
	 [ n -eq 5 -o n -eq 7 -o n -eq 10 -o n -eq 14 -o n -eq 19 ] && let ++w
	 prints s-$w- $feld
      done
   done
   return 0
}


cat | Print


:




###  geta.bish  #############################################

#!/u/bin/bish


ANAM='id dd typ bytelen darst nbit bitpos
dflt1 min1 max1
parbn flags einheit name Tinfo Tgrp Tsgrp Tbit Text text
'
F=cfgbase.txt
RA='^[1-9][0-9]*$'
an=0000000
n=n

[ $# -lt 3 ] && { echo "file[.=$F] RA argnum [args]"; exit 0; }
#read "F_? file[.=$F] RA argnum [args]:  " RA an args
F_="$1"
RA="$2"
an="$3"
ifset F_ RA an || exit 0
shift 3
args="$*"
[ "$F_" != . ] && F="$F_"
tty=tty
[ ! -t 0 -o "$F" == - ] && tty=
base=00 base=
[ "$F" == cfgbase.txt -o "$F" == mesbase.txt ] && base=1


Print()  {
   ifset tty && <$F
   cat | {
   while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 %
              a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 %
              a21 a22 a23 a24 a25
   do
      ifset base || [ "$a1" == '#@BASE' ] && base=2
      ifset base && [ "$a1" == '$' ] && break
      a=a$an
      ifset base && expr "$a1" :: '^@[^:]' || continue
      expr "${{a}}" :: "$RA" || continue
      expr "${{a}}" :: '[^0-9]' && n=
      for aa in $an $args
      do
         catv /%t a$aa
      done
      echo
   done
   }
   ifset tty && ><
   return 0
}

Print # | sortl -f${n}1

:




###  updhtm.bish  #############################################

#!/u/bin/bish

set -f

ex=000000
LineA=000000
LineB=000000
DIRm='../mu2000'
DIRu='../upc3'
HTM="$DIRm/mu.htm"
BASE="
$DIRm/cfgbase.txt
$DIRm/mesbase.txt
$DIRu/cfgbase.txt
$DIRu/mesbase.txt
"
BASEm="$DIRm/cfgbase.txt $DIRm/mesbase.txt"
BASEu="$DIRu/cfgbase.txt $DIRu/mesbase.txt"
set Z:.16000


# <stdin >stdout
ToHtm()  {
   while readl Z
   do
      expr "$Z" :Z '&' += '&amp;'
      expr "$Z" :Z '<' += '&lt;'
      expr "$Z" :Z '>' += '&gt;'
      expr "$Z" :Z '"' += '&quot;'
      catv Z /%n
   done
   return 0
}


ToHtmTable()  {
   local z=0 F:.50 W:.100
   for F in $*
   do
      cat $F | {
         >$F
         echo '<table cellpadding="0" cellspacing="0"><tbody>'
         while readl Z
         do
            z=0 print -n '<tr>'
            for W in $Z
            do
               conv '-t` ' W; let ++z
               case "$z" in
                 1)  catv '.<td align="right"><tt><b>' W '.</b></tt></td>';;
                 2)  catv '.<td><tt>&nbsp;&nbsp;&nbsp;' W '.</tt></td>';;
                 *)  catv '.<td><tt>&nbsp;&nbsp;' W '.</tt></td>';;
               esac
            done
            print '</tr>'
         done
         echo '</tbody></table>'
         ><
      }
   done
   return 0
}


# RE file
GrepLines()  {
   local z=02 s=000000 e=000000
   grep -nh "$1" "$2" | {
      readl Z && expr "$Z" :s '%([0-9]%{1,6}%):' && z=1
      readl Z && expr "$Z" :e '%([0-9]%{1,6}%):' && z=0
      readl Z && z=-1
   }
   [ z -ne 0 ] && return $z
   LineA=$s
   LineB=$e
   return 0
}


# pattern file
Grep()  {
   GrepLines "<!--{$1}-->" "$2" || return
   local s=$LineA e=$LineB
   let ++s --e
   [ e -gt s ] && line -$s-$e "$2"
   return 0
}


# pattern ofile ifile
FillIn()  {
   local sk=0000000000
   GrepLines "<!--{$1}-->" "$2" || return
   cat "$2" | {
      seek + 0 sk
      >"$2"
      line -1-$LineA
      cat "$3"
      seek $sk 0
      line -$LineB-
      ><
   }
   return 0
}


# $HTM XXX __xxx ... ...
FillInMulti()  {
   local ofile="$1" patt:.20 ifile:.80
   shift
   for 2 patt ifile in $*
   do
      FillIn $patt $ofile $ifile
      echo "$patt: exit=$?"
   done
   return 0
}


Gvim()  {
   local if=- of=__gvim
   >__devnull
   gvim -n -f +'set nonu' +'set syntax=c' +TOhtml +"w! $of" +'q!' +'q!' $if
   ><
   <__gvim
   while readl Z
   do expr "$Z" :: '^ *<body%>' && break; done
   while readl Z
   do expr "$Z" :: '^ *</body%>' && break; catv Z /%n; done
   ><
   remove -s __gvim __devnull
   return 0
}


PreStyle()  {
   echo "<pre style=%"background-color:#$1; padding:10px;%">"
   return 0
}


ParBn()  {
   for F in $*
   do
      bish geta.bish $F '^[1-9][0-9]*$' 11 14 20
   done
   return 0
}

ParBn $BASE  | sortl -fn1 | uniq >__pbn
ParBn $BASEm | sortl -fn1        >__pbnm
ParBn $BASEu | sortl -fn1        >__pbnu

bish geta.bish $DIRm/cfgbase.txt 'd' 12 8 9 10 14 20 >__dcpm
bish geta.bish $DIRm/cfgbase.txt 'h' 12 14 20 >__hldm
bish geta.bish $DIRm/cfgbase.txt 'b' 12 14 20 >__bakm
bish geta.bish $DIRm/cfgbase.txt 'u[1234]' 12 14 20 >__usrm

bish geta.bish $DIRu/cfgbase.txt 'd' 12 8 9 10 14 20 >__dcpu
bish geta.bish $DIRu/cfgbase.txt 'h' 12 14 20 >__hldu
bish geta.bish $DIRu/cfgbase.txt 'b' 12 14 20 >__baku
bish geta.bish $DIRu/cfgbase.txt 'u[1234]' 12 14 20 >__usru

bish neuvb.bish $DIRm/def.h
copy __neu __nvbm
bish neuvb.bish $DIRu/def.h
copy __neu __nvbu


>__flg
PreStyle FFFFC0
grep '^ *# *define  *CFG_' $DIRm/def.h | ToHtm
echo '</pre>'
><

#>__dmm
#PreStyle F0FFF0
#Grep DMM $DIRm/cfg.c | { ex=$?; ToHtm; }
#print -u2 "DMM: exit=$ex"
#echo '</pre>'
#><
Grep DMM $DIRm/cfg.c | { ex=$?; Gvim >__dmm; }
echo "DMM: exit=$ex"
Grep KMP $DIRm/atp.c | { ex=$?; Gvim >__kmp; }
echo "KMP: exit=$ex"


ToHtm <$DIRm/def.txt | {
   >__def
   echo '<pre>'
   while readl Z
   do
      expr "$Z" :: '^=%{60,}' && echo '</pre>%n<pre>'
      catv Z /%n
   done
   echo '</pre>'
   ><
}

>>__def
PreStyle FFF0F0
grep '^ *# *define  *PA_[UP][SA][ES][RS]_' $DIRm/def.h
echo '</pre>'
PreStyle F0F8FF
grep '^ *# *define  *IDT_' $DIRm/def.h
echo '</pre>'
PreStyle F0F8FF
grep '^ *# *define  *IDR_' $DIRm/def.h
echo '</pre>'
PreStyle F0FFF0
Grep SEV $DIRm/maschine.c | { ex=$?; ToHtm; }
print -u2 "SEV: exit=$ex"
echo '</pre>'
PreStyle F0F0F0
grep '^ *# *define  *PU_' $DIRm/def.h
echo '</pre>'
PreStyle F0F0F0
grep '^ *# *define  *PUCK_' $DIRm/def.h
echo '</pre>'
PreStyle F0F0F0
grep '^ *# *define  *CMPBAK_' $DIRm/def.h
echo '</pre>'
><

ToHtmTable __pbn __pbnm __pbnu %
           __dcpm __hldm __bakm __usrm %
           __dcpu __hldu __baku __usru

FillInMulti $HTM PBN __pbn PBNm __pbnm PBNu __pbnu %
                 DCPm __dcpm HLDm __hldm BAKm __bakm USRm __usrm %
                 DCPu __dcpu HLDu __hldu BAKu __baku USRu __usru %
                 NVBm __nvbm NVBu __nvbu %
		 FLG __flg DMM __dmm KMP __kmp DEF __def

set +f
remove -s  __[a-z][a-z]*

:





###  tpa.bish  #############################################


set -f

ifile=texts256.h
[ -s "$1" ] && ifile="$1"
[ -s "$ifile" ] || exit 0

NLANG=7 Npa=0000 Na=00000

T1()  {
   local k=0 n=000000 len=00
   local tnam=.........................
   local dnam=.........................
   local tnam0=.........................
   local tanam=.........................
   local danam=.........................
   echo text.h texte.h texte.c tsizes.txt
   6> tall.tmp
   5> tpa.tmp
   4> text.h
   3> texte.h
   > texte.c
   < $ifile
   print -u3 'extern cfap_t const FAR T_All[];%n'
   print -u6 '%n%ncfap_t const FAR T_All[]= {'
   print '%n%n#%t%tinclude "def.h"'
   print '#%t%tinclude "text.h"%n%n'
   while readl Z
   do
      expr "$Z" :danam ' %(D_%W%{1,}_%D%D%D_%L%L%)  *["0]' || continue
      len=0
      expr "$Z" :: ' 0%{1,}[ %t]*$' ||
         expr "$Z" :Z '^[^"]%{1,} %(".*%)"[ %t]*$' && len=${#Z}
      tanam="$danam" conv -TDT tanam; let ++Na
      let len && print -ru4 "extern ta_t $tanam;"
      expr "$tanam" :tnam '^%(T_%W%{1,}%)_%D%D%D_%L%L$'
      let len || tanam=0
      cmpv tnam tnam0 && { echo "     $tanam,"; let n+=len; continue; }
      tnam0="$tnam"
      print -ru3 "extern tpa_t $tnam;"
      print -ru6 "   $tnam,"
      [ k -eq 1 ] && { echo "     0%n};%n"; print -u5 "$n $dnam"; n=0; }
      dnam="$tnam" conv -TTD dnam
      echo "tpa_t $tnam= {"; let ++Npa
      echo "     $tanam,"; let n+=len
      k=1
   done
   [ k -eq 1 ] && { echo '     0%n};%n'; print -u5 "$n $dnam"; n=0; }
   [ k -eq 1 ] && { print -u6 '   0%n};%n'; }
   ><<<<<<
   cat tall.tmp >> texte.c
   return 0
}


T1
echo PointerArrays=$Npa StringPointer=$Na
sortl -r -f1n,2r -otpa.tmp tpa.tmp
cat tpa.tmp > tsizes.txt


# tmpf sizemax(hex)
GetD()  {
   local k=1 size=000000 szmax=000000 sk=00000 sz=000000
   local dnam=.................................
   let "szmax=16#$2"
   <> $1
   while seek + 0 sk; read sz dnam
   do
      expr "$sz" :: '^-' && continue
      let "sz>=64*1024" && print -u2 "$sz ! $dnam"
      let "size+sz>=szmax && (size>0||szmax<64*1024)" && continue
      let "size+=sz"
      catv /- =$sk,1,0.
      echo $dnam
      k=0
   done
   ><
   return $k
}


# filenam dnam ...
WrFromDnam()  {
   [ $# -le 1 ] && return 1
   echo $* $Dnam
   local n64k=000000 sk64k=00000000 len=00
   local tnam=.........................
   local dnam=.........................
   local dnam0=.........................
   local tanam=.........................
   local danam=.........................
   > $1
   shift
   echo '%n%n#%t%tinclude "def.h"'
   echo '#%t%tinclude "texts.h"%n%n'
   < $ifile
   [ SK64k -gt 0 ] && { seek $SK64k 0; dnam0=$Dnam0 SK64k=0; }
   while seek + 0 sk64k; readl Z
   do
      expr "$Z" :danam ' %(D_%W%{1,}_%D%D%D_%L%L%)  *"' || continue
      expr "$danam" :dnam '^%(D_%W%{1,}%)_%D%D%D_%L%L$'
      expr " $* $Dnam " :: "[ %t]${dnam}[ %t]" || continue
      tanam="$danam" tnam="$dnam" conv -TDT tanam tnam

      len=0
      #expr "$Z" :: ' 0%{1,}[ %t]*$' ||
         expr "$Z" :Z '^[^"]%{1,} %(".*%)"[ %t]*$' && len=${#Z}
      let "n64k+=len" 'n64k>=64*1024' &&
         SK64k=$sk64k Dnam0=$dnam0 Dnam=$dnam break

      cmpv dnam0 dnam || dnam0=$dnam echo
      echo "ta_t $tanam= $danam;"
   done
   ><<
   [ SK64k -gt 0 ] && return 64
   Dnam=
   return 0
}


Dnam=.........................
Dnam0=.........................
SK64k=00000000
Dnam=
local HS=..... b=0 n=000 Cnam=...............

for HS in 8000 10000 10000 10000 4000 4000 4000
do
   let ++n
   Cnam=t${n}h$HS.c
   echo $Cnam -----------------------
   [ b -eq 0 ] && { WrFromDnam $Cnam $( GetD tpa.tmp $HS ) ; b=$?; }
   [ b -eq 2 ] && { WrFromDnam $Cnam  ' ' ; b=$?; }
   [ b -gt 2 ] && b=2
   [ b -eq 1 ] && echo remove $Cnam ...
   [ b -eq 1 ] && [ -e $Cnam ] && remove $Cnam
done


remove -s tpa.tmp tall.tmp
:





###  tapebak.bish  #############################################

#!/u/bin/bish

LDIR=/fat/cys/mc/c
RDIR=/home/schellong/cys/mc/c
DN=/
BN=
expr "$RDIR" :BN '%(/[^/]%{1,}%)$'
expr "$RDIR" :DN '^%(/.%{1,}%)/[^/]%{1,}$'
TDIR=/usr/tapeBAK
TMPL=$TDIR/_tbllist
TMPR=$TDIR/_tbrlist
TMPC=$TDIR/_tbclist
[ -d $TDIR ] && rm -r $TDIR
mkdir -p $TDIR$BN
: >$TMPC
N=0
set Z:.200


Copy()  {
   local d
   echo $LDIR/$1 >> $TMPC
   expr "$TDIR$BN/$1" :d '^%(.%{1,}%)/[^/]%{1,}$' || d=/
   [ -d $d ] || mkdir -p $d
   cp -pv $LDIR/$1 $d
   chmod 600 "$TDIR$BN/$1"
   N=1
   return 0
}

ssh -C -l root -p 7777 tape find $RDIR -type f -printf '%T@\ %P\\n' > $TMPR || exit 1
[ -s $TMPR ] || exit 1
cd $LDIR
list -Rf > $TMPL
cd -

< $TMPL
while readl Z
do
   expr "$Z" =:: '%.lst$' && continue
   expr "$Z" =:: '%.obj$' && continue
   expr "$Z" =:: '%.stk$' && continue
   expr "$Z" =:: '%.als$' && continue
   expr "$Z" =:: '%.bin$' && continue
   expr "$Z" =:: '%.abs$' && continue
   mtr=$( grep -m -e " $Z%$" $TMPR ) || { echo neu:; Copy $Z; continue; }
   fstat -mv mtl $LDIR/$Z
   expr "$mtr" :mtr '^%([0-9]%{1,}%)'
   let "mtl>mtr+5" && { print -r $((mtl-mtr))s:; Copy $Z; }
done
><

[ $# -eq 0 -a N -gt 0 ] && scp -rpC -P 7777 $TDIR$BN root@tape:$DN


#Achtung! ssh macht was mit Handle 0.
8< $TMPR
while readl -u8 Z
do
   expr "$Z" :Z '[0-9] %(.%{1,}%)$'
   expr "$Z" =:: '%.abs$' && {
      echo rm $RDIR/$Z ...
      ssh -l root -p 7777 tape rm "$RDIR/$Z" || echo $?
      continue
   }
   expr "$Z" =:: '%.mhx$' || continue
   grep -qm -e "^$Z%$" $TMPL && continue
   echo rm $RDIR/$Z ...
   ssh -l root -p 7777 tape rm "$RDIR/$Z" || echo $?
done
><

exit 0




###  tapemkzip.bish  #############################################

#!/u/bin/bish


DIR=/home/schellong/cys/mc/c/BUILDS
MKZIP=/home/schellong/cys/mc/c/BUILDS/tapemkzip.sh

cps=0
ssh -l root -p 7777 tape  "[ -x $MKZIP ]" || cps=1


[ cps -gt 0 -o $# -gt 0 ] && { 
   echo Kopiere Script ...
   [ -s /u/sh/bish/tapemkzip.sh ] || { echo Kein Script; exit 5; }
   ssh -l root -p 7777 tape  "mkdir -p $DIR; chmod 700 $DIR" || { echo Fail1; exit 1; }
   scp -rpC -P 7777 /u/sh/bish/tapemkzip.sh root@tape:$DIR || { echo Fail2; exit 2; }
   ssh -l root -p 7777 tape  "chmod 700 $MKZIP" || { echo Fail3; exit 3; }
}


ssh -l root -p 7777 tape  $MKZIP || { echo Fail4; exit 4; }

exit 0





###  chprint.bish  #############################################

#!c:\u\bin\bish32.exe


an=00000000000
ifs=_______________
Dir="$(prints s120-)"
F="$(prints s80-)"
liste="$(prints s150-)"
vorne="$(prints s80-)"
funam="$(prints s250-)"
reste="$(prints s80-)"
a1="$(prints s60-)"
a2="$(prints s60-)"
a3="$(prints s60-)"
a4="$(prints s60-)"
rest="$(prints s60-)"
Zeile="$(prints s300-)"
zeile="$(prints s300-)"


[ $# -lt 1 ] && Dir=.
[ $# -ge 1 ] && Dir="$1"
[ "$Dir" == . ] && Dir=$(pwd)
#expr "$Dir" =:: '[/\]lst$' || Dir="$Dir\lst"
conv -F/F\ Dir
[ -d "$Dir" ] || { echo "Keine Existenz: '$Dir'!"; exit 1; }
cd "$Dir"
echo Verzeichnis: $Dir
: *.c
[ $] -lt 1 ] && { echo "Keine *.c vorhanden!"; exit 1; }



local fmt=lu________________
funam=Print_Lan
read "funam?Funktionsname oder all: "
ifset funam || exit 0
[ "$funam" == all ] && funam="
        Print_Str Print_Wert Print_Ch Print_W Print_F Print_F_pm Print_F2 Print2num
        Printnum Printnum2 Printnr Printword Printfloat Printfloat_pm Printfloat2
        Print_Lan Convert_w_s Convert_w_ganz_s Convert_w_ganz3_s Convert_b_s"


Args()  {
   ifs="$IFS" IFS=, rest= an=0
   [ $1 -eq 1 ] && print -r "$liste" | read a1 rest
   [ $1 -eq 2 ] && print -r "$liste" | read a1 a2 rest
   [ $1 -eq 3 ] && print -r "$liste" | read a1 a2 a3 rest
   [ $1 -eq 4 ] && print -r "$liste" | read a1 a2 a3 a4 rest
   IFS="$ifs"
   ifset rest && return 1
   ifset a$1 || return 1
   expr "$a1" :a1 '^ *%([0-9]%{1,%}%) *$'  '%1' && let ++an
   expr "$a2" :a2 '^ *%([0-9]%{1,%}%) *$'  '%1' && let ++an
   return 0
}


for funam in  $funam
do
   echo "$funam"

for F in *.c
do
   grep -qm "$funam" "$F" || continue
   grep -qm "//.*$funam.*//F/" "$F" && continue
   echo "%t$F"
   #[ -f "obj\CHP$F" ] || cat "$F" > "obj\CHP$F"
   cat "$F" | {
   : > "$F"
   while readl Zeile zeile
   do
      while :
      do
         expr "$Zeile" :: '^[ %t]*/[*/]' && break
         expr "$Zeile" :: '[^a-zA-Z_0-9]'"$funam"'([^;]%{1,%});' || break
         expr "$Zeile" :vorne '^%(.*[^a-zA-Z_0-9]%)'"$funam(" || break
         expr "$Zeile" :Zeile '^.*[^a-zA-Z_0-9]%('"$funam"'(.*%)$'  '%1'
         expr "$Zeile" :liste "^$funam("'%(..*%)$'
         expr "$liste" :reste '^[^;]%{1,%}%();.*%)$'
         expr "$liste" :liste '^%([^;]%{1,%}%));.*$'
         expr "$liste" :liste '^  *' ''
         expr "$liste" :liste '  *$' ''
         case "$funam" in
           Print_Lan)
               Args 3 || break
               if [ an -eq 2 ]
               then
                  Zeile="${vorne}Print_lcd(%"%%$a1.${a2}K%%Fs%", MSG($a3)$reste"
               else
                  Zeile="${vorne}Print_lcd(%"%%K%%Fs%", $a1,$a2, MSG($a3)$reste"
               fi
               print -r "//$zeile//F/" >> "$F"
           ;;
           Print_Str|Print_Wert|Print_Ch|Print_W|Print_F|Print_F_pm|Print_F2|Print2num)
               case "$funam" in
                   Print_Str)   fmt=s ;;
                   Print_Wert)  fmt=3u ;;
                   Print_Ch)    fmt=c ;;
                   Print_W)     fmt=5u ;;
                   Print_F)     fmt=,4.1u ;;
                   Print_F2)    fmt=,4.2u ;;
                   Print_F_pm)  fmt=,4.1i ;;
                   Print2num)   fmt=2u ;;
               esac
               Args 3 || break
               if [ an -eq 2 ]
               then
                  Zeile="${vorne}Print_lcd(%"%%$a1.${a2}K%%$fmt%", $a3$reste"
               else
                  Zeile="${vorne}Print_lcd(%"%%K%%$fmt%", $a1,$a2, $a3$reste"
               fi
               print -r "//$zeile//F/" >> "$F"
           ;;
           Printnum|Printnum2|Printnr|Printword|Printfloat|Printfloat_pm|Printfloat2)
               case "$funam" in
                   Printnum)       fmt=3u ;;
                   Printnum2)      fmt=02u ;;
                   Printnr)        fmt=u ;;
                   Printword)      fmt=5u ;;
                   Printfloat)     fmt=,4.1u ;;
                   Printfloat2)    fmt=,4.2u ;;
                   Printfloat_pm)  fmt=,4.1i ;;
               esac
               Args 1 || break
               Zeile="${vorne}Print_lcd(%"%%$fmt%", $a1$reste"
               print -r "//$zeile//F/" >> "$F"
           ;;
           Convert_w_s|Convert_w_ganz_s|Convert_w_ganz3_s|Convert_b_s)
               case "$funam" in
                   Convert_w_s)        fmt=,6.1i ;;
                   Convert_w_ganz_s)   fmt=5i ;;
                   Convert_w_ganz3_s)  fmt=3u ;;
                   Convert_b_s)        fmt=02u ;;
               esac
               Args 2 || break
               Zeile="${vorne}sprintf_F($a2, %"%%$fmt%", $a1$reste"
               print -r "//$zeile//F/" >> "$F"
           ;;
           *)  print -ru2 "Unbekannt: '$funam'"; exit 0 ;;
         esac
         break
      done
      print -r "$Zeile" >> "$F"
   done
   }
done

done


read "-?bish:$0: <Enter> "





###  inc.bish  #############################################


num=0
cat "$1" | {
   > "$1"
   while readl zeile
   do
      let "num<100" && num=0$num
      let "num< 10" && num=0$num
      let "num== 0" && num=000
      expr "$zeile" :zeile '^/%*[0-9]%{3%}' = "/*$num" && let ++num
      print -r "$zeile"
   done
   ><
}



###  inc3.bish  #############################################


num=0 nv=0 nv0=0
cat "$1" | {
   > "$1"
   while readl zeile
   do
      [ ${#num} -eq 1 ] && num=0$num
      expr "$zeile" :nv ' %([0-9]%{1,2%}%)00 ' && let "nv!=nv0" && num=00 nv0=$nv
      expr "$zeile" :zeile ' %([0-9]%{1,2%}%)00 ' " %%1$num " && let ++num
      print -r "$zeile"
   done
   ><
}



###  inch.bish  #############################################


num=0
cat "$1" | {
   > "$1"
   while readl zeile
   do
      let "num<100" && num=" $num"
      let "num< 10" && num=" $num"
      let "num== 0" && num="  0"
      expr "$zeile" :zeile ' [0-9]%{1,3%} ' = " $num " && let ++num
      print -r "$zeile"
   done
   ><
}



###  num.bish  #############################################


num=000
cat texte.c | {
: > texte.c
while readl zeile
do
   expr "$zeile" :zeile '^/%*000' = "/*$num" && {
      let ++num
      let "num<100" && num=0$num
      let "num< 10" && num=0$num
   }
   print -r "$zeile" >> texte.c
done
}



###  proto.bish  #############################################

#!c:\u\bin\bish32.exe


Dir="$(prints s120-)"
F="$(prints s80-)"
liste="$(prints s150-)"
vorne="$(prints s80-)"
funam="$(prints s80-)"
Zeile="$(prints s500-)"


[ $# -lt 1 ] && Dir=.
[ $# -ge 1 ] && Dir="$1"
[ "$Dir" == . ] && Dir=$(pwd)
#expr "$Dir" =:: '[/\]lst$' || Dir="$Dir\lst"
conv -F/F\ Dir
[ -d "$Dir" ] || { echo "Keine Existenz: '$Dir'!"; exit 1; }
cd "$Dir"
echo Verzeichnis: $Dir
: *.c
[ $] -lt 1 ] && { echo "Keine *.c vorhanden!"; exit 1; }



echo "
#if !defined(PROTO_H)
# define PROTO_H
" > _prototypes.h

for F in *.c
do
   echo "%t$F"
   : > c.tmp
   < "$F"
   while readl Zeile
   do
      expr "$Zeile" :: '[ %t*][a-zA-Z_][a-zA-Z_0-9]*(.*)[ %t]*$' && {
         expr "$Zeile" :Zeile '%t' + ' '
         expr "$Zeile" :Zeile '^ *%(..*%)$'
         expr "$Zeile" :Zeile '^%(..*)%) *$'
         print -r "$Zeile" >> c.tmp
	 continue
      }
      expr "$Zeile" :: '[ %t*][a-zA-Z_][a-zA-Z_0-9]*(.*)[ %t]*/[*/].*$' && {
         expr "$Zeile" :Zeile '^%(.*[ %t*][a-zA-Z_][a-zA-Z_0-9]*(.*)%)[ %t]*/[*/].*$'
         expr "$Zeile" :Zeile '%t' + ' '
         expr "$Zeile" :Zeile '^ *%(..*%)$'
         expr "$Zeile" :Zeile '^%(..*)%) *$'
         print -r "$Zeile" >> c.tmp
      }
   done
   ><
   : > c2.tmp
   < c.tmp
   while readl Zeile
   do
      liste= funam= vorne=
      expr "$Zeile" :liste '[ *][a-zA-Z_][a-zA-Z_0-9]*(%(.*%))$' || continue
      expr "$Zeile" :Zeile '^%(.*[ *][a-zA-Z_][a-zA-Z_0-9]*%)(.*)$' || continue
      expr "$Zeile" :funam '[ *]%([a-zA-Z_][a-zA-Z_0-9]*%)$' || continue
      [ "$funam" == if -o %
        "$funam" == for -o %
        "$funam" == while -o %
        "$funam" == do -o %
        "$funam" == switch -o %
        "$funam" == else ] && continue
      expr "$Zeile" :vorne '^%(.*[ *]%)[a-zA-Z_][a-zA-Z_0-9]*$' || continue
      expr "$vorne" :: '[^* %t_a-zA-Z0-9]' && continue
      expr "$vorne" :: '__interrupt' && continue
      expr "$liste" :liste '^  *%(.*%)$'
      expr "$liste" :liste '^%(.*%)  *$'
      expr "$liste" :liste ' %{2,%}' + ' '
      expr "$liste" :liste ', ' + ','
      expr "$liste" :liste ' ,' + ','
      expr "$vorne" :vorne '^  *' ''
      expr "$vorne" :vorne '  *$' ''
      expr "$vorne" :vorne ' %{2,%}' + ' '
      expr "$liste" :liste '%*[][a-zA-Z_0-9]%{1,%}$' '*'
      expr "$liste" :liste ' [][a-zA-Z_0-9]%{1,%}$' ''
      expr "$liste" :liste '%*[][a-zA-Z_0-9]%{1,%},' + '*,'
      expr "$liste" :liste ' [][a-zA-Z_0-9]%{1,%},' + ','
      expr "$liste" :liste ',%([^ %t]%)' + ', %1'
      expr "$liste" :: '[^ %t]' || liste=void
      expr "$vorne" :vorne ' %(%*%{1,%}%)$'  '%1'
      Zeile="$vorne  $funam"
      expr "$Zeile" :Zeile '%*%*  '  '**'
      expr "$Zeile" :Zeile '%*  '  ' *'
      print "%textern $Zeile($liste);" >> c2.tmp
   done
   ><
   cat c2.tmp > c.tmp
   echo "//$F:" >> _prototypes.h
   cat c.tmp >> _prototypes.h
done

echo "
#endif
" >> _prototypes.h

remove c2.tmp c.tmp
read "-?bish:$0: <Enter> "





###  sed.bish  #############################################




cd "$1"
shift
[ $# -ne 0 ] && files="$@"
[ $# -eq 0 ] && files=?*.[ch]

while :
do

read "old?ALT und NEU [aaa nnn]:  " new
ifset old || exit
ifset new || exit
print -r $files
read "abf?Dateien/Aenderungen abfragen? [yn][yn]: "
nowd='[^a-zA-Z_0-9]'

for file in $files
do
   expr "$file" =:: 'mb[0-9]%{2,%}%.h$' && continue
   expr "$file" =:: '^tmp_..*' && continue
   is=1
   grep -q "$nowd$old$nowd" "$file" && is=
   ifset is && grep -q "^$old$nowd" "$file" && is=
   ifset is && grep -q "$nowd$old%$" "$file" && is=
   ifset is && grep -q "^$old%$" "$file" && is=
   ifset is && continue
   inp=y
   echo "$file:"
   [[ "$abf" == y? ]] && read "inp?'$file'? [y]: "
   [ "$inp" != y ] && continue
   cat "$file" > "tmp_$file"
   4<&0
   cat "$file" | {
      3> "$file"
      while readl zeile zeile2
      do
	 is=1
         expr "$zeile" :zeile "%%($nowd%%)$old%%($nowd%%)" + "%%1$new%%2" && is=
         ifset is && expr "$zeile" :zeile "^$old%%($nowd%%)"   "$new%%1" && is=
         ifset is && expr "$zeile" :zeile "%%($nowd%%)$old%$"   "%%1$new" && is=
         ifset is && expr "$zeile" :zeile "^$old%$"   "$new" && is=
         inp=y
         ifset is || [[ "$abf" == ?y ]] && {
	    print -r "$zeile2"
	    echo
	    print -r "$zeile"
	    read -u4 "inp??[y]: "
         }
	 [ "$inp" != y ] && zeile="$zeile2"
         print -ru3 "$zeile"
      done
      ><
   }
   ><
done

read "inp?Sicherheitskopien '$(print -rn tmp_*)' behalten?[y]: "
[ "$inp" != y ] && remove -v tmp_*

read "inp?$0: Beenden?[y]: "
[ "$inp" == y ] && break

done





###  var.bish  #############################################

#!c:\u\bin\bish32.exe


Dir="$(prints s80-)"
F="$(prints s80-)"
VF="$(prints s80-)"
isda="$(prints s80-)"
fnam="$(prints s80-)"
vfile="$(prints s80-)"
is=000000000
zeile="$(prints s300-)"
name="$(prints s300-)"


err()  {
   print -r "$0: ERROR: $1"
   read "-? <Enter> "
   exit 0
   return 0
}


[ $# -lt 1 ] && Dir=.
[ $# -ge 1 ] && Dir="$1"
[ "$Dir" == . ] && Dir=$(pwd)
[ -d "$Dir" ] || err "Keine Existenz: '$Dir'"
cd "$Dir"
echo Verzeichnis: $Dir
read "vfile?Datei eingeben [var.c==Enter]: "
ifset vfile || vfile=var.c
[ -s "$vfile" ] || err "Keine Existenz/Kein Inhalt: '$vfile'"


for VF  in  $vfile
do
   3< "$VF"
   while readl -u3 name
   do
      ifset name || continue
      expr "$name" :: '^ */[/*]' && continue
      #expr "$name" :: '^ *static ' && continue
      is=
      expr "$name" :name ' %([a-zA-Z_][a-zA-Z_0-9]*%) *[,;] *$' && is=1
      ifset is || expr "$name" :name ' %([a-zA-Z_][a-zA-Z_0-9]*%) *%[' && is=1
      ifset is || continue
      isda=0 fnam=
      for F  in  *.c
      do
         expr "$F" =:: "^$VF%$" && continue
         is=0
         grep -q "[^a-zA-Z_0-9]${name}[^a-zA-Z_0-9]" "$F" && let ++is
         let is==0 && grep -q "^${name}[^a-zA-Z_0-9]" "$F" && let ++is
         let is==0 && grep -q "[^a-zA-Z_0-9]${name}%$" "$F" && let ++is
         let is==0 && grep -q "^${name}%$" "$F" && let ++is
         let is==0 && continue
         let isda==0 && fnam="$F"
         let ++isda
      done
      let "isda==0" && print "$isda: $name"
      let "isda==1" && print "$isda: $fnam: $name"
   done
   ><
done


read "-? $0: <Enter> "





###  chpr.bish  #############################################

# !/u/bin/bish
# Print_xyz auf Print_lcd umbauen



set -f
File="\softune\sample\gfs_594\$1"
[ $# -lt 1 -o ! -s "$File" ] && { print -u2 "? $File ?"; exit; }

Zeile="$(prints s256-)"
Arg1="$(prints s25-)"
Arg2="$(prints s25-)"
Arg3="$(prints s25-)"
Arg4="$(prints s25-)"
ArgTyp=00000000
NArg=00000000
PfName=00000000
ZN=00000000



Args()  {
   local i=0 t=0 a
   expr "$1" :a 'Print[a-zA-Z_0-9]%{1,%}(%(..*%));'
   expr "$a" :: '^[ %t]*[^, %t]%{1,%}[ %t]%{1,%}[^, %t]' && return 1
   expr "$1" :PfName 'Print%([a-zA-Z_0-9]%{1,%}%)(..*);'
   ArgTyp=''
   while let "++i<=4"
   do
      t=0
      #echo "--$a--"
      while :
      do  t=1 expr "$a" :Arg$i '^[ %t]*%(".*[^\]"%)' &&
                 expr "$a" :a '^[ %t]*".*[^\]"%(.*%)$' && break
          t=2 expr "$a" :Arg$i '^[ %t]*%(""%)' &&
                 expr "$a" :a '^[ %t]*""%(.*%)$' && break
          t=3 expr "$a" :Arg$i '^[ %t]*%(''.''%)' &&
                 expr "$a" :a '^[ %t]*''.''%(.*%)$' && break
          t=4 expr "$a" :Arg$i '^[ %t]*%(''\.''%)' &&
                 expr "$a" :a '^[ %t]*''\.''%(.*%)$' && break
          t=5 expr "$a" :Arg$i '^[ %t]*%([0-9][0-9a-zA-Z]*%)' &&
                 expr "$a" :a '^[ %t]*[0-9][0-9a-zA-Z]*%(.*%)$' && break
          t=6 expr "$a" :Arg$i '^[ %t]*%([^, %t]*%)' &&
                 expr "$a" :a '^[ %t]*[^, %t]*%(.*%)$' && break
          print -u2 "Kein ArgTyp![$File:$ZN]" && exit
          break
      done
      catv t =$i,1,ArgTyp
      NArg=$i
      ifset a || break
      expr "$a" :a '^[ %t]*,%(.*%)$'
      expr "$a" :a '^[ %t]*%(.*%)$'
      ifset a || break
   done
   return 0
}



Skip()  {
   local skip=0 pr
   while ifset pr && print -r "$Zeile"
         pr=1 readl Zeile
   do
      let ++ZN
      ifset Zeile || continue
      [ $skip == 2 ] && expr "$Zeile" :: '^#endif' && { skip=0; continue; }
      [ $skip == 1 ] && expr "$Zeile" :: '%*/[ %t]*$' && { skip=0; continue; }
      [ $skip != 0 ] && continue
      expr "$Zeile" :: 'defined(OLDPRN)' && { skip=2; continue; }
      expr "$Zeile" :: '^[ %t]*//' && continue
      expr "$Zeile" :: '^[ %t]*/%*' && {
         expr "$Zeile" :: '%*/[ %t]*$' && continue
         skip=1
         continue
      }
      expr "$Zeile" :: 'Print[a-zA-Z_0-9]%{1,%}(' || continue
      expr "$Zeile" :: 'Print[a-zA-Z_0-9]%{1,%}(..*);' ||
         print -u2 "Mehrzeiler![$File:$ZN]" && continue
      Args "$Zeile" || continue
      pr=
      PrNewFu
      #PrA
   done
   let skip && print -u2 "Offenes Ende: $skip[$File:$ZN]"
   return 0
}



PrNewFu()  {
   local at=-------- na=0 fmt
   #print -rn "Print$PfName"
   case "Print$PfName" in
     Printf)        na=4 fmt='%?K%.16s' at=-kksu ;;
     Print2num)     na=3 fmt='%?K%.2u%?K' at=-kku ;;
     Printnum)      na=1 fmt='%3u' at=-u ;;
     Printnr)       na=1 fmt='%u' at=-u ;;
     Printword)     na=1 fmt='%5u' at=-u ;;
     Printfloat)    na=1 fmt='%,4.1u' at=-u ;;
     Printfloat2)   na=1 fmt='%,4.2u' at=-u ;;
     Printfloat3)   na=1 fmt='%,5.1u' at=-u ;;
     Print_Ch)      na=3 fmt='%?K%c' at=-kkc ;;
     Print_Str)     na=3 fmt='%?K%-16.16s' at=-kks ;;
     Print_Strc)    na=3 fmt='%?K%-16.16s' at=-kks ;;
     Print_Str_l)   na=3 fmt='%?K%.16s' at=-kks ;;
     Print_Wert)    na=3 fmt='%?K%3u' at=-kku ;;
     Print_W)       na=3 fmt='%?K%5u' at=-kku ;;
     Print_Bit8)    na=3 fmt='%?K%08b' at=-kku ;;
     Print_Bit16)   na=3 fmt='%?K%016b' at=-kku ;;
     Print_Hex)     na=3 fmt='%?K%#.4x' at=-kkx ;;
     Print_F)       na=3 fmt='%?K%,4.1u' at=-kku ;;
     Print_F2)      na=3 fmt='%?K%,4.2u' at=-kku ;;
     Print_F3)      na=3 fmt='%?K%,5.1u' at=-kku ;;
     PrintDate)     na=4 fmt='%?s %02u.%02u.%04u' at=-suuu ;;
     PrintDatum)    na=3 fmt='%02u.%02u.%04u' at=-uuu ;;
     PrintTime)     na=3 fmt='%02u:%02u:%02u' at=-uuu ;;
     PrintTime_os)  na=2 fmt='%02u:%02u' at=-uu ;;
     *)  print -u2 "? $PfName() ?" && exit ;;
   esac
   [ na -ne NArg ] && print -u2 "nArg: $NArg!=$na(soll)" && exit
   expr "$fmt" :: '^%%?K' && {
      :
   }
   local i=0
   while let "++i, --n>=0"
   do
      echo "%t${Arg[i]}"
   done
   return 0
}



PrA()  {
   local n=$NArg i=0
   echo "Print$PfName"
   while let "++i, --n>=0"
   do
      echo "%t${Arg[i]}"
   done
}



Skip < "$File"



# 


###  allprjzip.bish  #############################################


remove -s /u/all.zip
zip /u/all.zip %
   /fat/cys/mc/c/lib/*.* %
   /fat/cys/mc/c/mu1000c/*.* %
   /fat/cys/mc/c/mu1000c200/*.* %
   /fat/cys/mc/c/mu2000c/*.* %
   /fat/cys/mc/c/mu2000cFR/*.* %
   /fat/cys/mc/c/mu2doc/*.* %
   /fat/cys/mc/c/mu2siemens/*.* %
   /fat/cys/mc/c/pms300/*.* %
   /fat/cys/mc/c/tds/*.*
ls -l /u/*.zip



###  ru.bish  #############################################



<TDSru.htm
while readl Z
do
   #expr "$Z" :: '&[a-zA-Z0-9#]%{1,};' || continue
   while expr "$Z" :U '&%([a-zA-Z0-9#]%{2,}%);'
   do
      expr "$Z" :Z '&[a-zA-Z0-9#]%{1,};' = ''
      echo "$U"
   done
done
><




###  cpc.bish  #############################################


list -Rf \u |
while readl path
do
   conv -l path
   expr "$path" :dir '^%(..*%)\[^\][^\]*%.[ch]$' || continue
   [ ! -d "d:$dir" ] && mkdirs "d:$dir"
   copy -v "$path" "d:$path"
done



###  autoexec.bish  #############################################


global
alias MU="cd \u\mc\c\mu1000c"
alias CV="cd \u\c\mucv"



###  optis.bish  #############################################


array p %f %F %a %A %x %X %d %D %e %E
i=00000
echo $#
[ $# -lt 5 ] && i=6

for O in $@
do
   let ++i
   print -r "$O"
   #echo %t%c
   #print -r "$p[i] ==> $O"
done



###  segm.bish  #############################################

#!c:\u\bin\bish32.exe


sum=000000000000
Dir="$(prints s80-)"
F="$(prints s80-)"
vonbis="$(prints s80-)"
size="$(prints s80-)"
name="$(prints s80-)"
namen="$(prints s500-)"


[ $# -lt 1 ] && Dir=.
[ $# -ge 1 ] && Dir="$1"
[ "$Dir" == . ] && Dir=$(pwd)
expr "$Dir" =:: '[/\]lst$' || Dir="$Dir/lst"
conv -F/F\ Dir
[ -d "$Dir" ] || { echo "Keine Existenz: '$Dir'!"; exit 1; }
cd "$Dir"
echo Verzeichnis: $Dir
: *.mp1
[ $] -lt 1 ] && { echo "Keine *.mp1 vorhanden!"; exit 1; }

RamSZ=8 RomSZ=384
read "ramsz?RAM($RamSZ) und FLASH($RomSZ) [KB]: " romsz
expr "$ramsz" :: '^[0-9]%{1,}$' && RamSZ=$ramsz
expr "$romsz" :: '^[0-9]%{1,}$' && RomSZ=$romsz


namen=" "
for F in *.mp1
do
   echo "$F ..."
   5< "$F"
   while read -u5 vonbis size name - - - - -
   do
      expr "$vonbis" :: '^[0-9a-fA-F]%{8%}-[0-9a-fA-F.]%{8%}' || continue
      expr "$namen" :: " $name " || namen="$namen$name "
   done
   ><
   for Dir in $namen
   do
      sum=0
      5< "$F"
      while read -u5 vonbis size name - - - - snam
      do
         [ "$snam" == IOXTND -o "$snam" == INTVECT ] && continue
         expr "$vonbis" :: '^[0-9a-fA-F]%{8%}-[0-9a-fA-F.]%{8%}' || continue
         [ "$name" != "$Dir" ] && continue
         let "sum+=16#$size"
      done
      ><
      prints s20s13 "$Dir:" $sum
      case "$Dir" in
        IO)  IO=$sum;;
        DIR)  DIR=$sum;;
        DATA)  DATA=$sum;;
        STACK)  STACK=$sum;;
        CODE)  CODE=$sum;;
        CONST)  CONST=$sum;;
        DIRC)  DIRC=$sum;;
      esac
   done
done

echo
prints s20s13s13 RAM= $((DIR+DATA+STACK+DIRC)) $((RamSZ*1024-[DIR+DATA+STACK+DIRC]))
prints s20s13s13 FLASH= $((CODE+CONST)) $((RomSZ*1024-[CODE+CONST]))

read
:

#0000013E-........  00000000  DATA  P RW-- 02 REL  LIBINIT
#0000013E-........  00000000  DATA  P RW-- 02 REL  CINIT
#0000013E-0000015D  00000020  DATA  P RW-- 02 REL  INIT_lcd
#0000015E-00000177  0000001A  DATA  P RW-- 02 REL  DATA_uart
#00000178-00000179  00000002  STACK P RW-- 02 REL  USTACK
#00000180-0000018F  00000010  DATA  N RW-- 01 ABS  Register Bank No. 00





###  stack.bish  #############################################

#!/u/bin/bish


NB=00000000
nb=00000000
nb0=00000000
esl=SELI
s=111
Dir="$(prints s80-)"
nam="$(prints s80-)"
nam0="$(prints s80-)"
na="$(prints s80-)"
F="$(prints s80-)"
LibStk="$(prints s80-)"
zeile="$(prints s500-)"
Zeile="$(prints s500-)"
ASM_C="../../lib/calib.c"


[ $# -lt 1 ] && Dir=.
[ $# -ge 1 ] && Dir="$1"
[ "$Dir" == . ] && Dir=$(pwd)
expr "$Dir" =:: '[/\]obj$' || Dir="$Dir/obj"
conv -F/F\ Dir
[ -d "$Dir" ] || { echo "Keine Existenz: '$Dir'!"; exit 1; }
cd "$Dir"
echo Verzeichnis: $Dir
: *.stk
[ $] -lt 2 ] && { echo "Keine/zuwenig *.stk vorhanden!"; exit 1; }

for F in *.stk
do
   expr "$F" :: '[lL][iI][bB]9..[slmcSLMC]%....$' && {
      LibStk=$F; continue
   }
done

[ -s "$LibStk" ] || { echo "Keine lib9##x.stk vorhanden!"; exit 1; }

[ -s "$ASM_C" ] && grep '^[ %t]*FOO(%W%W*)' "$ASM_C" | {
   > asm_c_stk
   while readl Zeile
   do
      expr "$Zeile" :zeile 'FOO(%([^)]%{1,}%))' || continue
      catv '/ 4 E ' /_ zeile /%n
   done
   ><
   cat asm_c_stk >> calib.stk
}


GetStkLen()  {
   #local zeile
   #zeile="$( grep -m -e $2 $3 )" || return
   zeile="$( grep -m -e $2 $3 )" || zeile=8
   expr "$zeile" :$1 '^%([0-9]%{1,%}%)'
   return 0
}


GetStkLenLib()  {
   zeile="$( grep -m -e "[ %t]$2[ %t]*" $LibStk )" || return
   expr "$zeile" :$1 '%([0-9]%{1,%}%)'
   return 0
}



echo .stk-Dateien Konversion ...
> fuu.txt
for F in *.stk
do
   expr "$F" :: '[lL][iI][bB]9..[slmcSLMC]%....$' && {
      print -u2 "%t-- $F --"
      continue
   }
   print -u2 "%t$F"
   < $F
   while read nb esl nam a
   do
      ifset nb esl nam || continue
      expr "$esl" :esl '^%([ESILesil]%)' || continue
      [ "$a" == A -a "$nb" == 0 ] && nb=8
      expr "$nb" :nb '^%([0-9]%{1,%}%)' && print "$nb +$esl$nam+"
   done
   ><
done
><



echo .stk-Dateien Konversion2 und Bytes ...
> stack.txt
for F in *.stk
do
   expr "$F" :: '[lL][iI][bB]9..[slmcSLMC]%....$' && {
      print -u2 "%t-- $F --"
      continue
   }
   print -u2 "%t$F"
   < $F
   while read nb esl nam a
   do
      ifset nb esl nam || continue
      expr "$esl" :esl '^%([ESILesil]%)' || continue
      na="$nam"
      nam="$esl$nam"
      [ "$a" == A -a "$nb" == 0 ] && nb=8
      expr "$nb" :nb '^%([0-9]%{1,%}%)' && {
         nam0=$nam nb0=$nb
         print "$nam:$nb"
         continue
      }
      expr "$nb" :: '^->' && {
         GetStkLen NB "+$nam+" fuu.txt || GetStkLenLib NB "$na" || {
            print -u2 "'$nam' nicht gefunden!"
            ><< ; read "-?<Enter> "; exit 1
         }
         cmpv nam nam0 && print -u2 "Rekursiv!: $nam0:$nb0 $nam:$NB" && continue
         print "$nam0:$nb0 $nam:$NB"
      }
   done
   ><
done
><


fstat -s stack.txt
nb=0
echo Verschachtelter Scan ...%c
cat stack.txt > fuu.txt
while ifset s
do
   print -u2
   prints su210- $((++nb))
   s="" nb0=0
   #cat stack.txt > fuu.txt
   cat stack.txt | {
      > stack.txt
      while readl Zeile
      do
         print -u2 "%r%c"
         prints su210s10- $nb $((++nb0))
         ifset Zeile || continue
         expr "$Zeile" :nam ' %([^ %t]%{1,%}%)$' || { print -r "$Zeile"; continue; }
         grep -e "^$nam " fuu.txt > fuu2.txt || { print -r "$Zeile"; continue; }
         s=1
         3< fuu2.txt
         while read -u3 - zeile
         do
            print -r "$Zeile $zeile"
         done
         ><
      done
      ><
   }
done
print -u2



fstat -s stack.txt
echo Summenbildung ...
cat stack.txt | {
   > stack.txt
   while readl Zeile
   do
      NB=0
      for nam in $Zeile
      do
         expr "$nam" :nb ':%([0-9][0-9]*%)'
         let "NB+=nb"
      done
      prints s5s $NB "  $Zeile"
   done
   ><
}


fstat -s stack.txt
echo Sortierung ...
sortl -r -fn1 -ostack.txt stack.txt || echo -$?- Fehler bei sortl-Kommando!
fstat -s stack.txt
echo Interrupts ...
grep ' I' stack.txt > fuu2.txt
echo >> fuu2.txt
cat fuu2.txt stack.txt | cat > stack.txt

fstat -s stack.txt
echo ID-Buchstaben entfernen ...
cat stack.txt | {
   > stack.txt
   while readl Zeile
   do
      expr "$Zeile" :Zeile '%([ %t]%)[ISEL]' + '%1'
      expr "$Zeile" :Zeile '^[ISEL]' ''
      print -r "$Zeile"
   done
   ><
}


fstat -s stack.txt
remove fuu.txt fuu2.txt
read "-?bish:$0: <Enter> "