shell脚本学习指南[五](Arnold Robbins & Nelson H.F. Beebe著)

2019-09-23 09:42:00王振洲

        if(ARGV[k] == "-strip"){
            ARGV[k] = ""
            Strip = 1
        }else if(ARGV[k] == "-verbose"){
            ARGV[k] = ""
            Verbose = 1
        }else if(ARGV[k] ~ /^=/){  #后缀文件
            NSuffixFiles++
            SuffixFiles[substr(ARGV[k], 2)]++
            ARGV[k] = ""
        }else if(ARGV[k] ~ /^[+]/){ #私有字典
            DictionaryFiles[substr(ARGV[k], 2)]++
            ARGV[k] = ""
        }
    }
    #删除结尾的空参数(for nawk)
    while ((ARGC > 0) && (ARGV[ARGC-1] == ""))
        ARGC--
}

function spell_check_line(k, word){
    gsub(NonWordChars, "")  #消除非单词字符
    for(k=1;k<=NF;k++){
        word = $k
        sub("^'+","",word)  #截去前置的撇号字符
        sub("'+$","",word)  #截去结尾的撇号字符
        if(word!="")
            spell_check_word(word)
    }
}

function spell_check_word(word, key, lc_word, location, w, wordlist){
    lc_word = tolower(word)
    if(lc_word in Dictionary)   #可接受的拼写
        return
        else{       #可能的异常
            if(Strip){
                strip_suffixes(lc_word, wordlist)
                for(w in wordlist)
                    if(w in Dictionary) return
            }
            location = Verbose ? (FILENAME ":" FNR ":") : ""
            if(lc_word in Exception)