3 # if source file direct nestly, the sub file source path is not correct.
4 # use this alias cmd to fix this problem.
5 # it stores $PWD, entering dir of include file.
9 # return if has been sourced before.
10 # this code is disabled, it should be putted in application program.
12 #alias include >/dev/null 2>&1
13 #[[ $? == 0 ]] && alias inc="include" return
16 # TBD: write value in tmp, it should be generated by _EVL
17 # SRCPKG_DIR_FULL=$PWD
20 shopt -s expand_aliases
21 alias include="diffinc "
26 echo "$1" | grep -E "inc_info" >/dev/null 2>&1
27 test "$?" != 0 && return
38 echo "$1" | grep -E "inc_info" >/dev/null 2>&1
39 test "$?" != 0 && return
42 while [[ $cnt -gt 0 ]]; do
51 echo "$1" | grep -E "inc_dbgout" >/dev/null 2>&1
52 test "$?" != 0 && return
63 [[ -z "$1" || ! -f "$1" ]] && return
69 vname=`echo "$vname" | tr [[:punct:]] '_' | tr '[[:lower:]]' '[[:upper:]]'`
70 eval test \"\$$vname\" = 1 && return
83 # get func list in current process.
94 # get var list in current process.
103 done < <(declare -p | grep -e "declare" | sed -e "s/^.*-f.*$//g")
106 # get alias list in current process.
113 done < <(alias | grep -e "^alias")
117 # syntax: var_list_diff <outputvarname> = <listvarname1> - <listvarname2>
118 # desc: it diff two variable data, and get the new appended info.
127 if test -n "$1" && test -n "$3" && test -n "$5" && test "$2" = '=' && test "$4" = '-' ; then
129 declare "$3=$(echo "${!3}" | tr ' ' $'\n')";
130 declare "$5=$(echo "${!5}" | tr ' ' $'\n')";
136 declare -g $1+="${data}"$'\n'
137 done < <(echo "${!5}" | diff --from-file=<(echo "${!3}") - | grep -e "<";)
138 declare -g $1+="${!1%$'\n'}"
146 vname=${vname//[^[:alnum:]_]/_}
149 # declare var before source, or it will be append to varlist_xxx.
151 declare funclist1_$vname=""
152 declare funclist2_$vname=""
153 declare varlist1_$vname=""
154 declare varlist2_$vname=""
155 declare aliaslist1_$vname=""
156 declare aliaslist2_$vname=""
159 # getting func/var/alias list before
161 eval funclist1_$vname=\"\$\(get_func_list\)\"
162 eval varlist1_$vname=\"\$\(get_var_list\)\"
163 eval aliaslist1_$vname=\"\$\(get_alias_list\)\"
172 # getting func/var/alias list after
174 eval funclist2_$vname=\"\$\(get_func_list\)\"
175 eval varlist2_$vname=\"\$\(get_var_list\)\"
176 eval aliaslist2_$vname=\"\$\(get_alias_list\)\"
179 # diff list between before and after.
181 listvar_diff funclist_$vname = funclist2_$vname - funclist1_$vname
182 listvar_diff varlist_$vname = varlist2_$vname - varlist1_$vname
183 listvar_diff aliaslist_$vname = aliaslist2_$vname - aliaslist1_$vname
185 # eval echo funclist_$vname=\${funclist_$vname} > 3.txt
186 # eval echo varlist_$vname=\${varlist_$vname} >> 3.txt
187 # eval echo aliaslist_$vname=\${aliaslist_$vname} >> 3.txt
191 # fsyntax: loadimi <imi-file-name>
202 local file=$(basename $1)
205 test -z "$1" || test ! -f "$1" && return
208 while test "$cnt" -gt 0 ; do
212 inc_info "loadimi ($@)\n"
216 # it's normal if file is not exist.
218 inc_dbgout "parameter file($1) is not exist.\n" &&
222 test "`echo "$1" | grep -o -P '([^\.]*)' | tail -n 1`" != "imi" &&
223 err "specified file $1 is not .imi file.\n" &&
229 if test -e "$file" ; then
230 # it need -r param to receive '\'.
231 while read -r data; do
233 [[ "${data}" =~ $'\r' ]] && data=$(echo ${data:0:-1})
234 # filter comment, and skip blank line.
235 [[ -z ${data//[[:space:]]/} ]] && continue
236 if [[ ${data} =~ '#' ]]; then
237 [[ ${data} =~ ^[[:space:]]*[#] ]] && continue
238 data="${data//[[:space:]]*[#].*/}"
241 [[ "${data}" =~ ^inc\ || "${data}" =~ ^loadimi\ || "${data}" =~ ^loadlist\ ]] && eval $data && continue;
243 if [[ "${data}" =~ '=(' ]]; then
246 # [[ ! "${data}" =~ ')' ]] && continue
249 if [[ "${flag}" == 'array' ]]; then
250 if [[ ! "${data}" =~ '=(' ]]; then
251 if [[ "${data}" =~ ')' ]]; then
252 tmp+="${data%%\)*})"$'\n'
259 if [[ "${data}" =~ ')' ]]; then
266 # ignore [xxx] section setting, use it as an ini file.
267 [[ ${data} =~ ^[[:space:]]*\[ ]] && continue
269 inc_dbgout "data=\"${data}\"\n"
271 if [[ ${data} =~ _EVL ]]; then
273 eval declare -g "${data}"
275 # define without _EVL
276 data="${data/_EVL=/=}"
278 # it can works with "" or '' in config file.
279 # multi-line paramter putted in a single line,
280 # and assign to the specified variable.
282 data="${data//\"/\\\"}"
283 # data="${data//\'/\\\'}"
284 # inc_dbgout "=== ${data}\n"
285 # \$\'\\\"\"\\\n\\\"\"\'
286 eval "$(eval echo \"${data}\")"
288 # append newline after every one.
289 # inc_dbgout "=== ${data}\n"
294 [[ ! "$data" =~ '=' ]] && echo -e "\033[1m\033[31m[error][$file:line$i]\033[0m: '$data' not a valid assign statement." && exit -1
301 while [[ "${tmp}" =~ '=' ]]; do
304 [[ ${bak: -1,1} == '+' ]] && bak="${bak:0:-1}"
307 # [[ "$abc" =~ (\=.*\=.*)*(\=.*) && $(($(expr length ${abc//[^=]/})%2)) == 1 ]] && echo bbb ${BASH_REMATCH[@]}
308 # [[ "${tmp##*=}" =~ '"'{1,3,2} ]] && tmp="$bak" && continue
313 charcnt="${bak2//[^\']/}"
314 qcnt=$((${#charcnt} + qcnt))
315 charcnt="${bak2//[^\"]/}"
316 dqcnt=$((${#charcnt} + dqcnt))
317 [[ "${bak2}" =~ (\'.*\'.*)*(\'.*) && $((qcnt%2)) == 1 ]] && continue
318 [[ "${bak2}" =~ (\".*\".*)*(\".*) && $((dqcnt%2)) == 1 ]] && continue
320 [[ "${tmp}" =~ '#' ]] && continue;
321 [[ "${tmp: -1:1}" == ':' ]] && continue;
326 # generate var in auto by _EVL suffix.
327 if [[ "${data}" =~ _EVL$ ]]; then
328 eval "${data}=${!data}"
331 vlist+="${data}"$'\n'
332 # inc_dbgout "vlist+=\"${data}$'\n'\""
335 # get var name, and delete redundent "\n".
336 # it need -r param to receive '\'.
337 while read -r data; do
338 [[ -z $data ]] && continue
340 while [[ "${!data: -1:1}" == $'\n' ]]; do
341 eval "$data=\"\${!data:0:-1}\""
346 err "list file '$1' is not exist.\n"
355 # fsyntax: loadlist <list-file-name>
356 # fdesc: load .list file. if not exist, load .lst file.
367 local file=$(basename $1)
370 [[ -z "$1" || ! -f "$1" ]] && return
373 while [[ $cnt -gt 0 ]]; do
377 inc_info -ne "loadlist ($1)\n"
382 # skip nestly loaded file.
384 name=${1//[^[:alnum:]_]/_}
385 if [[ -v ${name} && ${!name} == Y ]]; then
386 # echo "file $name loaded nestly."
392 [[ ${1##*\.} != "lst" && ${1##*\.} != "list" ]] && err "specified file '$1' is not .list or .lst file.\n" && unset $name && return 1
396 if [[ -e "$file" ]]; then
397 # it need -r param to receive '\'.
398 while read -r data; do
400 # filter comment, and skip blank line.
401 [[ -z ${data//[[:space:]|]/} ]] && continue
402 if [[ ${data} =~ '#' ]]; then
403 [[ ${data} =~ ^[[:space:]]*[#] ]] && continue
404 data="${data%%*([[:space:]])[#]*}"
405 [[ -z "${data}" ]] && continue
408 [[ "${data}" =~ '^inc ' || "${data}" =~ '^loadimi ' || "${data}" =~ '^loadlist ' ]] && eval $data && continue;
411 # append '\' for '\"'
413 data="${data//\\\"/\\\\\\\"}"
415 # append newline after every one.
416 inc_dbgout "list: ${data}\n"
417 # eval "${data}"$'"\n"'
418 eval declare -g "${data}"
419 [[ $? != 0 ]] && err "[$file:line$i]: '$data' failed.\n" && exit -1
426 while [[ "${tmp}" =~ '=' ]]; do
429 [[ ${bak: -1,1} == '+' ]] && bak="${bak:0:-1}"
432 # [[ "$abc" =~ (\=.*\=.*)*(\=.*) && $(($(expr length ${abc//[^=]/})%2)) == 1 ]] && echo bbb ${BASH_REMATCH[@]}
433 # [[ "${tmp##*=}" =~ '"'{1,3,2} ]] && tmp="$bak" && continue
438 charcnt="${bak2//[^\']/}"
439 qcnt=$((${#charcnt} + qcnt))
440 charcnt="${bak2//[^\"]/}"
441 dqcnt=$((${#charcnt} + dqcnt))
442 [[ "${bak2}" =~ (\'.*\'.*)*(\'.*) && $((qcnt%2)) == 1 ]] && continue
443 [[ "${bak2}" =~ (\".*\".*)*(\".*) && $((dqcnt%2)) == 1 ]] && continue
445 [[ "${tmp}" =~ '#' ]] && continue;
446 [[ "${tmp: -1:1}" == ':' ]] && continue;
453 # get var name, and delete redundent "\n".
455 [[ ${bak: -1:1} == '+' ]] && bak="${bak:0:-1}"
457 while [[ "${!bak: -1:1}" == $'\n' ]]; do
458 eval "$bak=\"\${!bak:0:-1}\""
462 # CFLAGS_DEF_LIST_Y+=" -DMACHTYPE=\"$MACHTYPE\" "
463 # disable '\"' to '\\\"'.
465 # declare -g "$bak=${!bak//\\\"/\\\\\\\"}"
467 # append blank to the end of string in auto.
468 [[ "${!bak: -1:1}" != ' ' || "${!bak: -1:1}" != $'\n' ]] && declare -g $bak+=$'\n'
472 # err "list file is not exist.\n"
476 # it can be loaded next time un-nestly.