Sunday, November 18, 2012

TMLib软件开发库

TMLib软件开发库

【开发历程】
  跟大多数C++程序员一样,我们最早使用MFC开发,开发时间长了,觉得MFC包含的无用的东西过多,编写出来的程序不但体积大,而且速度慢。
  MFC当初是为了简化Windows开发而设计的,但是用它开发行业软件的时候,常常感觉不够专业化,有些MFC封装的太啰嗦,反而是降低了开发效率。
  而且在MFC项目中开发一些更底层的功能时,还得用API。MFC封装太死、封装太啰嗦、对于专业的编程还是不够专业,有些该隐藏的地方没有隐藏,不该隐藏的地方又隐藏了……
  这些理由足够放弃MFC,然后用了一段时间SDK,但是思想还不到用SDK的水平,开发力不从心,又转WTL、又转用别人的类库,用了1年左右用过QT、U++、SmartWin++、wxWidgets、VCF、JUCE、WINX、Win32GUI、Skin+,,感觉到头来还是MFC的另一个版本
  中间曾满怀激情的参与了金山公司的许式伟的国内著名的WinX开源项目,最后因为封装的思想于自己的冲突,再就是WTL存在与MFC相似的缺陷,还是放弃了。
  总结想想,学习了这么多又放弃了,说白了其实就是理想和现实冲突。我们理想的类库总结一下,其实就三点:1:开发简单易用,高开发效率,2,具备高效运行效率和最优部署,3:最终产品具备完美的用户体验。
  最后又回到SDK,这次我们有足够的经验和能力设计个自己开发库(不单是GUI界面库),定名为TMLib。完全用SDK/API开发,参考了不少优秀的类库,封装好,调用简单,代码小,效率高。SDK封装好了,确实比MFC简单直观。

Monday, November 12, 2012

unix - Using getopts in bash shell script to get long and short command line options - Stack Overflow

unix - Using getopts in bash shell script to get long and short command line options - Stack Overflow
** "getopts": with short options AND long options AND short/long arguments **
Works with all combinations, e.G.:
  • foobar -f --bar
  • foobar --foo -b
  • foobar -bf --bar --foobar
  • foobar -fbFBAshorty --bar -FB --arguments=longhorn
  • foobar -fA "text shorty" -B --arguments="text longhorn"
  • bash foobar -F --barfoo
  • sh foobar -B --foobar - ...
  • bash ./foobar -F --bar

#!/bin/bash
# foobar: getopts with short and long options AND arguments
###### some declarations for these example ######
Options=$@
Optnum=$#
sfoo='no '
sbar='no '
sfoobar='no '
sbarfoo='no '
sarguments='no '
sARG=empty
lfoo='no '
lbar='no '
lfoobar='no '
lbarfoo='no '
larguments='no '
lARG=empty

_usage() {
###### U S A G E : Help and ERROR ######
cat <<EOF
 foobar $Options
$*
        Usage: foobar <[options]>
        Options:
                -b   --bar            Set bar to yes    ($foo)
                -f   --foo            Set foo to yes    ($bart)
                -h   --help           Show this message
                -A   --arguments=...  Set arguments to yes ($arguments) AND get ARGUMENT ($ARG)
                -B   --barfoo         Set barfoo to yes ($barfoo)
                -F   --foobar         Set foobar to yes ($foobar)
EOF
}
if [ $# = 0 ]; then _usage "  >>>>>>>> no options given "; fi
##################################################################    
#######  "getopts" with: short options  AND  long options  #######
#######            AND  short/long arguments               #######
while getopts ':bfh-A:BF' OPTION ; do
  case "$OPTION" in
    b  ) sbar=yes                       ;;
    f  ) sfoo=yes                       ;;
    h  ) _usage                         ;;   
    A  ) sarguments=yes;sARG="$OPTARG"  ;;
    B  ) sbarfoo=yes                    ;;
    F  ) sfoobar=yes                    ;;
    -  ) [ $OPTIND -ge 1 ] && optind=$(expr $OPTIND - 1 ) || optind=$OPTIND
         eval OPTION="\$$optind"
         OPTARG=$(echo $OPTION | cut -d'=' -f2)
         OPTION=$(echo $OPTION | cut -d'=' -f1)
         case $OPTION in
             --foo       ) lfoo=yes                       ;;
             --bar       ) lbar=yes                       ;;
             --foobar    ) lfoobar=yes                    ;;
             --barfoo    ) lbarfoo=yes                    ;;
             --help      ) _usage                         ;;
             --arguments ) larguments=yes;lARG="$OPTARG"  ;; 
             * )  _usage " Long: >>>>>>>> invalide options (long) " ;;
         esac
       OPTIND=1
       shift
      ;;
    ? )  _usage "Short: >>>>>>>> invalide options (short) "  ;;
  esac
done
##################################################################
echo "----------------------------------------------------------"
echo "RESULT short-foo      : $sfoo                                 long-foo      : $lfoo"
echo "RESULT short-bar      : $sbar                                 long-bar      : $lbar"
echo "RESULT short-foobar   : $sfoobar                                 long-foobar   : $lfoobar"
echo "RESULT short-barfoo   : $sbarfoo                                 long-barfoo   : $lbarfoo"
echo "RESULT short-arguments: $sarguments  with Argument = \"$sARG\"        long-arguments: $larguments and $lARG"
share|edit
Was this post useful to you?