#//
#//	SplitDataAddr.awk
#//
#//	DumpXlsx.exe偺弌椡僼傽僀儖傪撉傒崬傓Awk僗僋儕僾僩偺悧宍
#//
#//	* Sat Aug 20 21:19:11 JST 2016 Naoyuki Sawa
#//	- 1st 儕儕乕僗丅
#//	* Sat Sep 24 21:37:23 JST 2016 Naoyuki Sawa
#//	- 摉僗僋儕僾僩傪尦偵偟偰丄/clip/tool/DeleteVerticalComment.awk傪幚憰偟傑偟偨丅
#//	  傛傝幚嵺偵懄偟偨椺偲偟偰丄忋婰偺僗僋儕僾僩傪嶲徠偟偰壓偝偄丅
#//
#//----------------------------------------------------------------------------
function die(s) {
	#//僄儔乕儊僢僙乕僕傪昞帵偟偰廔椆偟傑偡丅
	print "### " s > "/dev/stderr"
	exit (_die_exit = 1)
}
#//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
END {
	#//die()宱桼側傜偽丄END偺傾僋僔儑儞傪幚峴偣偢偵廔椆偝偣傑偡丅
	#//- Awk偺巇條: 堷悢晅偒偺exit暥傪嵟弶偵幚峴偟丄偦偺屻偱堷悢柍偟偺exit暥傪幚峴偡傞偲丄偦偺慜偵巊偭偨堷悢偑廔椆僗僥乕僞僗偲偟偰巊傢傟傞丅
	if(_die_exit) { exit }
}
#//END偼暋悢掕媊弌棃傑偡丅傾僾儕働乕僔儑儞摿桳偺END傪掕媊偡傞応崌偼丄偙偙傛傝傕壓偱掕媊偟偰壓偝偄丅
#//----------------------------------------------------------------------------
BEGIN {
	#//僼傿乕儖僪僙僷儗乕僞傪丄擖弌椡嫟丄僇儞儅偵曄峏偡傞丅
	FS = OFS = ","
}
#//----------------------------------------------------------------------------
#//僼傿乕儖僪暥帤楍偐傜丄僨乕僞暥帤楍偲丄(傕偟桳傟偽)傾僪儗僗暥帤楍傪庢摼偡傞丅
function SplitDataAddr(s, a) {
	#//寢壥傪奿擺偡傞攝楍傪妋幚偵嬻偵偟偰偍偔丅(昁恵偱偼側偄偑埨慡偺偨傔偱偡丅)
	delete a
	#//僼傿乕儖僪暥帤楍偐傜丄僨乕僞暥帤楍偲丄(傕偟桳傟偽)傾僪儗僗暥帤楍傪庢摼偡傞丅
	if(!match(s, /^([^"]+)( \".+\")?$/, a)) {
		die(FILENAME "(" FNR "," iCol "): 僼傿乕儖僪暥帤楍偑晄惓偱偡丅(" s ")")
	}
}
#//----------------------------------------------------------------------------
{
	#//奺僼傿乕儖僪偵偮偄偰乧
	for(iCol = 1; iCol <= NF; iCol++) {
		#//僼傿乕儖僪暥帤楍傪庢摼偡傞丅
		s = $iCol
		#//嬻僼傿乕儖僪偱側偗傟偽乧
		if(s != "") {
			#//僼傿乕儖僪暥帤楍偐傜丄僨乕僞暥帤楍偲丄(傕偟桳傟偽)傾僪儗僗暥帤楍傪庢摼偡傞丅
			SplitDataAddr(s, a)
			#//僨乕僞暥帤楍傪庢摼偡傞丅
			data = a[1]
			#//(傕偟桳傟偽)傾僪儗僗暥帤楍傪庢摼偡傞丅
			addr = a[2]
#//{{傾僾儕働乕僔儑儞屌桳偺張棟
			#//仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸
			#//仸偙偙偱丄僨乕僞暥帤楍偵懳偟偰丄傾僾儕働乕僔儑儞屌桳偺張棟傪峴偭偰壓偝偄丅仸
			#//仸摉僒儞僾儖偱偼丄"("乣")"偱埻偭偰傒傑偟偨丅丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂仸
			#//仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸仸
			data = "(" data ")"
#//}}傾僾儕働乕僔儑儞屌桳偺張棟
			#//僨乕僞暥帤楍偲丄(傕偟桳傟偽)傾僪儗僗暥帤楍傪楢寢偟偰丄僼傿乕儖僪暥帤楍偲偡傞丅
			s = data addr
			#//僼傿乕儖僪暥帤楍傪彂偒栠偡丅
			$iCol = s
		}
	}
	#//儗僐乕僪暥帤楍傪弌椡偡傞丅
	print
}
