#!/bin/sh

CW_DIR="cwFiles"
tmp="/tmp"
test -d $tmp || tmp="/home/debunne/.tmp"

test -d $CW_DIR || mkdir $CW_DIR

# for f in `ls -1 refManual/class*-members.html`
for f in `ls -1 refManual/classQGLViewer-members.html`
do
  grep "\[.*signal.*\]" $f | sed s:"<[^>]*>"::g | sed s:").*":")": | sed s:"=[^,) ]*"::g | sed s:"const "::g > $tmp/signals
  grep "\[.*slot.*\]" $f | grep -v "\[.*protected.*\]" | sed s:"<[^>]*>"::g | sed s:").*":")": | sed s:"=[^,) ]*"::g | sed s:"const "::g > $tmp/slots
  grep "\[.*protected.*slot.*\]" $f   | sed s:"<[^>]*>"::g | sed s:").*":")": | sed s:"=[^,) ]*"::g | sed s:"const "::g > $tmp/protected_slots
  for type in {bool,int,float,double,char,QString}
  do
    sed s:"$type [^,)]*\([,)]\)":"$type\1":g < $tmp/signals > $tmp/temp
    mv $tmp/temp $tmp/signals
    sed s:"$type [^,)]*\([,)]\)":"$type\1":g < $tmp/slots > $tmp/temp
    mv $tmp/temp $tmp/slots
  done   
  if [ -s $tmp/slots -o -s $tmp/signals ] 
  then
    name=`echo $f | sed s:"refManual/class\([^-]*\)-members.*":"\1": | sed s:"qglviewer_._."::`
    # output="$CW_DIR/$name.cw"
    output="qglviewer.cw"
    echo "<!DOCTYPE CW><CW>\n<customwidgets>\n  <customwidget>\n   <class>$name</class>" > $output

cat >> $output << EOF
    <header location="local">QGLViewer/qglviewer.h</header>
    <sizehint>
        <width>400</width>
        <height>300</height>
    </sizehint>
    <container>0</container>
    <sizepolicy>
        <hordata>7</hordata>
        <verdata>7</verdata>
    </sizepolicy>
    <pixmap>
        <data format="XPM.GZ" length="3320">789c5d56db521d3b0e7dcf5750d15b6a4aa7dbee76db35350f845b200142eec9a979902f1d20dcd9248153f3efe3ad65381ce82a6aaf962ccbd2d272fff162e5cbdbdd95177f3cbb5ec8e228ada443b95a79916f4e4f6ffffcef7ffe7af6bc1f577ab7d24ffd8a79feaf67cfa9baacec9d9f9525e0b547e060f108d075053497e5a39e4e71ae4f529c9ed873c3d543f1e513fb4ec3f54fe37f573c3fd8371bbeb70f0feb351ef19378570ff920dfdb8613f2a3aef9a739aa3ff693fa2896fb7ce22c8a4f1e30fcbfb478b19db7fb27a623c5d51bf9c9eb86fd3ca93fecd3ec1a7eafd8d4c7aaff4fc5beda9dda4f5b7e23b05cb6fd86e67fd8b0993bc5dfdb7a330fba7e577198ed3c2afefc705eaff9aeb5f399a2f56552dc9554709e77cdde15d4fb25f22f65eed5fff609de58e252ff66d00ae7b7f551cc1fdafe01f524ece74a2cda2fd1f3965c42db7fa7adefb15e2e14f7c537fb6fc5e37d3de8f001eb79e993c64b458af6934e9add36ff6fedbc5d417d6f14a75cb2d687355ee973869db75bbc5082fa47d43f878cf36a3fb3c95d413d0e1a0ee01369fdcb54e3c17ed3e2a70c7ebf512c7505f8c82d1f9bc0bff516cf16d453e731f749b2e6c3ca9f2cb96bf9607e724a0978bfe198b0ffa4fe293bf49767d4e7de4ebfd43ed5f3207ed0fc4ccd1ffd3b57ec92cb8877a6eb876423f8857e8ec924cce7b8c4359b82f3b2ce738c696af3b507bed60142bf71de2edaa8fce682798941307f3de62b26d178b20ffe45dfb0f2b30cd10af8bbd0fd72ac29a81dfc7771143d1f7dd4fc6ccc09fdd7fea62c11f9f01df6171f747e45f52ef6b5bda807f42e4a68f66df04b0660563ec612fbac98a057494cd0f351403fa58be0efd61207176cc35abf1acd04d4f35871aa58eda2fc4931580ffdd1f948bd4f1eebf7c09f1004fa68916f08cd1e9bddb57ab816df0af8a07c0d93cf09f97f407e7e065fe40af3eb2bc5353fd50f1f8389e897209e371e7cda6af15352bd22ad57f03e259d17be403f6bb9c1871fd037ef279d5f567d49a3b701eba10fd17b87793a6ef98e19fc79a5b8da23f800fe8877cd5fe387eca5f92b5f829966f08db4ff699ae680f93f83ff3478f41ff32355e0d10fc5719c6a0715eb3c85e2b2c3fa3bccdf641ce647edd1b83c819fb82fcc6446e887de3fd1bb2a80eaaffa95baa9f3e0d757b5d7ebc343afa0d79d0b03d6ebbc8b75cea37ee8ff746f67d54799c6ecd03f9d87d04f9270bfe8bc87610c13eaf316faeccc00fe1ee0fcae1fc007e55b2a63a5acdad7d19f2ac0c85ff91aede85b3cbfc4cbea45f46355ed53dd0ffaa07c9630dcd757fb53e6b1b3d037d53f378d5d443f946f7118eb878e62ad8fc421363ee9fd18dd602cea013deb86be87fe0af4617006fdc37d350e83c17eba5e64b00efecaafec6c825db4fec5d6f1017f36509fa1eb510fe58f94a177e89ff26faa84b3d08f0df0cf84b61ef5169b7accab07bfede0d01fad570ed6c02ed7b86f2ac6f9353f6b8d057f44f5ca75a61f70ffa9befacec808bc89fcccd4eb7cc916f4d14c1df47b15fa6e5287fe35fdb5a643fec7e05ffd3c01bf0cf8626d87fb017a3ed9bed3fd08765f31ecf8dea9e7013e583c7e98583872aabf32179e1f7bf0773ee4233ee61f7cc2a7159ff1395fc0832ff9aafebfe605dff04ffec5bff9b6e23b5ee5979ae51aaff3066ff216bfe26ddee1d7fc8677abc71eeff35bdcebfc8edff307fec89ff8337fe1affc8dbbead1b3613069e0911d4fec3910139150a49a29652ad4be75e9908ee8987ed0497d7f4a6774becc8d2ee892aed4e39a1674433fe917fda65bbaa3557a593dd7689d36681367a12d7a45dbb443afe90dedd2deb21ab44f6fe980de358ff7f4813ed227fa4c5fe82b7dab6f3aeac990e5745f311a68244713790a7c79b01096ca6a89078bbf6b2af523a37e46cdf2bdfe3e942339961f72f20f8f53399373b9a8bf2ee54aae652137cbf78ffb223fe597fc965bb9935579296b74fdd4a3faaccb866cca96bc926dd9c1bb271eafe58decca9eec2f33681efffbf7b3ff03e2d71717</data>
    </pixmap>
EOF

    sort $tmp/signals         | sed s:"^ ":"     <signal>": | sed s:"$":" </signal>": >> $output
    sort $tmp/slots           | sed s:"^ ":"     <slot access=\"public\">":    | sed s:"$":" </slot>": >> $output
    sort $tmp/protected_slots | sed s:"^ ":"     <slot access=\"protected\">": | sed s:"$":" </slot>": >> $output
    if [ $# -gt 0 ]
    then
      echo "  " `cat $tmp/signals | wc -l` "signals"
      more $tmp/signals
      echo "  " `cat $tmp/slots $tmp/protected_slots | wc -l` "slots (" `cat $tmp/protected_slots| wc -l` " protected)"
      more $tmp/slots 
      more $tmp/protected_slots 
    #else
      #echo "   = Class $name," `cat $tmp/signals | wc -l` "signals and" `cat $tmp/slots $tmp/protected_slots | wc -l` "slots, protected" `cat $tmp/protected_slots | wc -l`
    fi
    echo "  </customwidget>\n</customwidgets>\n</CW>" >> $output
  fi  
done

rm -rf $CW_DIR
