new-words

changeset 24:1318aa5898ee

minifix:getopts
author Igor Chubin <igor@chub.in>
date Mon May 17 12:14:44 2010 +0300 (2010-05-17)
parents 4b9d13c78de2
children d1eb7dc37feb
files new-words.sh
line diff
     1.1 --- a/new-words.sh	Sun May 16 22:16:31 2010 +0300
     1.2 +++ b/new-words.sh	Mon May 17 12:14:44 2010 +0300
     1.3 @@ -39,8 +39,7 @@
     1.4  export ORIGINAL_TEXT=`mktemp /tmp/new-words-XXXXXXXXXX-orig`
     1.5  editor=${EDITOR:-vim}
     1.6  
     1.7 -#----------------------------------------------------
     1.8 -# command line options processing
     1.9 +# language detection
    1.10  
    1.11  LANGUAGE=en
    1.12  my_name="`echo $0 | sed s@.*/@@ | sed s/-.*// `"
    1.13 @@ -52,43 +51,39 @@
    1.14      fi
    1.15  done
    1.16  [ "${my_name}" = "new" ] || LANGUAGE="$my_name"
    1.17 +
    1.18 +#----------------------------------------------------
    1.19 +# command line options processing
    1.20 +
    1.21 +STAT_ONLY=NO
    1.22 +NEED_TO_USE_VOCABULARY_WHEN_SORT=NO
    1.23 +DONT_ADD_MARKS=NO
    1.24 +NON_INTERACTIVE_MODE=NO
    1.25 +while getopts l:skmnp opt
    1.26 +do
    1.27 +    case "$opt" in
    1.28 +      s)  STAT_ONLY=YES;;
    1.29 +      k)  NEED_TO_USE_VOCABULARY_WHEN_SORT=YES;;
    1.30 +      l)  LANGUAGE="$OPTARG";;
    1.31 +      m)  DONT_ADD_MARKS=YES;;
    1.32 +      n)  NON_INTERACTIVE_MODE=YES;;
    1.33 +      p)  PAGES="$OPTARG";;
    1.34 +      \?)       # unknown flag
    1.35 +          show_usage
    1.36 +          exit 1;;
    1.37 +    esac
    1.38 +done
    1.39 +shift `expr $OPTIND - 1`
    1.40 +
    1.41  if [ "$1" = "-l" ]
    1.42  then
    1.43      LANGUAGE="$2"
    1.44 -    VOCABULARY="$LANGUAGE".txt
    1.45      shift 2
    1.46  fi
    1.47 +
    1.48  VOCABULARY=${LANGUAGE}.txt
    1.49  NOTES_FILE=notes-${LANGUAGE}.txt
    1.50  
    1.51 -STAT_ONLY=NO
    1.52 -if [ "$1" = "-s" ]
    1.53 -then
    1.54 -    STAT_ONLY=YES
    1.55 -    shift
    1.56 -fi
    1.57 -
    1.58 -NEED_TO_USE_VOCABULARY_WHEN_SORT=NO
    1.59 -if [ "$1" = "-k" ]
    1.60 -then
    1.61 -    NEED_TO_USE_VOCABULARY_WHEN_SORT=YES
    1.62 -    shift
    1.63 -fi
    1.64 -
    1.65 -DONT_ADD_MARKS=NO
    1.66 -if [ "$1" = "-m" ]
    1.67 -then
    1.68 -    DONT_ADD_MARKS=YES
    1.69 -    shift
    1.70 -fi
    1.71 -
    1.72 -NON_INTERACTIVE_MODE=NO
    1.73 -if [ "$1" = "-n" ]
    1.74 -then
    1.75 -    NON_INTERACTIVE_MODE=YES
    1.76 -    shift
    1.77 -fi
    1.78 -
    1.79  #----------------------------------------------------
    1.80  
    1.81  get_words()
    1.82 @@ -235,6 +230,7 @@
    1.83      @prefixes=qw(
    1.84          ab an auf aus bei dazwischen ein fest heraus her hinaus hin los mit nach voraus vorbei vor weg weiter zurück zusammen zu
    1.85          be emp ent er ge miss ver zer durch über um unter wieder);
    1.86 +    @prefixes=();
    1.87      for $pref (@prefixes) {
    1.88          s/^$pref//;
    1.89      }