1. 程式人生 > 其它 >xib檔案轉NIb檔案

xib檔案轉NIb檔案

xib檔案轉NIb檔案

使用方法:sh ./nib.sh ./

#!/bin/bash

# --------------------------------------------------------------------------- #
# 獲取檔名字尾
# Parameter1: 檔名
# output: Yes
# return: None
# --------------------------------------------------------------------------- #
function FileSuffix() {
    local filename="$1"
    if [ -n "$filename" ]; then
        echo "${filename##*.}"
    fi
}

# --------------------------------------------------------------------------- #
# 獲取檔名字首
# Parameter1: 檔名
# output: Yes
# return: None
# --------------------------------------------------------------------------- #
function FilePrefix() {
    local filename="$1"
    if [ -n "$filename" ]; then
        echo "${filename%.*}"
    fi
}

# --------------------------------------------------------------------------- #
# 判斷檔案字尾是否是指定字尾
# Parameter1: 檔名
# parameter2: 字尾名
# output: None
# return: 0: 表示檔案字尾是指定字尾;1: 表示檔案字尾不是指定字尾
# --------------------------------------------------------------------------- #
function IsSuffix() {
    local filename="$1"
    local suffix="$2"
    if [ "$(FileSuffix ${filename})" = "$suffix" ]; then
        return 0
    else
        return 1
    fi
}

# --------------------------------------------------------------------------- #
# 將xib編譯成nib檔案
# --------------------------------------------------------------------------- #
function transitionToNib(){
    ibtool --errors --warnings --output-format human-readable-text --compile ibtool --errors --warnings --output-format human-readable-text --compile $1 $2

}

# --------------------------------------------------------------------------- #
#處理輸入的引數 並編譯成nib
# --------------------------------------------------------------------------- #
function handlFile(){
	ORIGIN=$1
	# echo $1

	XIBFILE=${ORIGIN##*/}
	# echo "$XIBFILE xib檔案"

	IsSuffix ${XIBFILE} "xib"
	ret=$?

	if [  $ret -eq 0 ]; then
    	echo "the suffix of the ${file} is xib"
    	FILENAME="${ORIGIN%.*}"
		NIBFILEDIR=$FILENAME".nib"
    	NIBFILE=${NIBFILEDIR##*/}

		echo "$FILENAME file名"
		echo "$NIBFILE nib檔案"

		transitionToNib $NIBFILE $XIBFILE
    else
    	echo "the suffix of the ${XIBFILE} is not xib"
	fi


}

#迴圈目錄,將每個xib編譯成nib
function scandir() {
    local cur_dir parent_dir workdir
    workdir=$1
    cd ${workdir}
    if [ ${workdir} = "/" ]
    then
        cur_dir=""
    else
        cur_dir=$(pwd)
    fi

    for dirlist in $(ls ${cur_dir})
    do
        if test -d ${dirlist};then
            cd ${dirlist}
            scandir ${cur_dir}/${dirlist}
            cd ..
        else
            echo "${cur_dir}/${dirlist} 子檔案"

            handlFile ${cur_dir}/${dirlist}

        fi
    done
}


echo `basename $0` is in `pwd`
#return

#判斷是否有輸入引數 需輸入一個xib檔案 或 一個只包含xib的檔案 注意,xib檔名不能為空,否則不會被編譯成nib
if [ ! -n "$1" ] ;then
    echo "you have not input a xibfile or directory of xibfile!"
    return
# else
    # echo "the word you input is $1"
fi



#判斷是檔案還是資料夾
if test -d $1
then

	# echo "you input  a directory"

    scandir $1

    exit 1

elif test -f $1
then
    # echo "you input a file "

    handlFile $1
    
    exit 1
else
    echo "the Directory isn't exist which you input,pls input a new one!!"
    exit 1
fi