# メニュー定義コンパイル BEGIN { token_init() if (match(FILENAME, /\..?.?.?$/)) outfile = substr(FILENAME, 1, RSTART-1) ".md" else outfile = FILENAME ".md" print "ARTemis メニュー定義コンパイル" print "(output to: " outfile ")" print "" >outfile do { t = token_get() if (t == "menubegin") { read_menu(); if (itemidnum > 0) { for (i=0; i> outfile } printf("\n") >> outfile } if (letnum > 0) { for (i=0; i>outfile } printf("\n") >>outfile } if (buttonnum > 0) { output_buttons(menuname "_buttons") printf("\n") >>outfile } if (barnum > 0) { output_scrollbars(menuname "_bars") printf("\n") >>outfile } if (selnum > 0) { for (i=0; i>outfile } printf("static MENU %s =\n",menuname) >>outfile printf("{\n") >>outfile printf("\t\"%s\",\n", menutitle) >>outfile printf("\t%s,%s,\n", menuxlen,menuylen) >>outfile if (buttonnum > 0) { printf("\t%s_buttons,\n", menuname) >>outfile} else { printf("\tNULL,\n") >>outfile } if (barnum > 0) { printf("\t%s_bars,\n", menuname) >>outfile } else { printf("\tNULL,\n") >>outfile } if (selnum > 0) { printf("\t%s_sels,\n", menuname) >>outfile } else { printf("\tNULL,\n") >>outfile } printf("\tNULL,NULL,NULL,\n") >>outfile printf("\t%s,\n", menudispfunc) >>outfile printf("\t%s,\n", menuerasefunc) >>outfile printf("\t0,0,0,0,NO,NO,NULL\n};\n\n") >>outfile if (letnum > 0) { for (i=0; i>outfile } printf("\n") >>outfile } } else if (t == "buttonbegin") { nam = token_get(); buttonnum = 0; while (token_checknext() != "buttonend") { read_button(buttonnum); buttonnum++; } token_get(); # skip "buttonend" output_buttons(nam) printf("\n") >>outfile } else if (t == "barbegin") { nam = token_get(); barnum = 0; while (token_checknext() != "barend") { read_scrollbar(barnum); barnum++; } token_get(); # skip "barend" output_scrollbars(nam); printf("\n") >>outfile } else if (t == "selelementbegin") { nam = token_get(); selenum[nam] = 0; while (token_checknext() != "selelementend") { read_selector_element(nam, selenum[nam]); selenum[nam]++; } token_get(); # skip "selelementend" output_selector_elements(nam, nam); printf("\n") >>outfile } else if (t == "selectorbegin") { nam = token_get() selnum = 0 while (token_checknext() != "selectorend") { read_selector(selnum); selnum++; } token_get(); for (i=0; i>outfile } } while (fileend == 0); exit } func error() { printf("error! near line:%d\n",NR); exit } #----------------------------------------------------- # メニュー単位での読み込み #----------------------------------------------------- func read_menu() # menubegin の次から、menuend までを読む { buttonnum = 0; barnum = 0; selnum = 0; letnum = 0; itemid = 1; itemidnum = 0; menuname = token_get(); menudispfunc = "NOFNC" menuerasefunc = "NOFNC" do { t = token_get(); if (t == "size") { menuxlen=token_get(); menuylen=token_get(); continue; } else if (t == "title") { menutitle=token_get(); continue; } else if (t == "let") { letstr[letnum] = token_get(); letcon[letnum] = token_get(); letnum++; } else if (t == "button") { if (token_checknext() != "[") { read_button(buttonnum); buttonnum++; } else { token_get(); # [ while (token_checknext() != "]") { read_button(buttonnum); buttonnum++; } token_get(); # ] } } else if (t == "scrollbar") { if (token_checknext() != "[") { read_scrollbar(barnum); barnum++; } else { token_get(); # [ while (token_checknext() != "]") { read_scrollbar(barnum); barnum++; } token_get(); # ] } } else if (t == "selector") { if (token_checknext() != "[") { read_selector(selnum); selnum++; } else { token_get(); # [ while (token_checknext() != "]") { read_selector(selnum); selnum++; } token_get(); # ] } } else if (t == "dispfunc") menudispfunc=token_get(); else if (t == "erasefunc") menuerasefunc=token_get(); else if (t == "menuend") break; else { print "near line " NR ": invalid menu definition" exit } } while (fileend == 0); } #----------------------------------------------------- # ボタン情報の読み込みと出力 #----------------------------------------------------- func read_button(n) # ボタン定義の [ から ] までを読む # 結果はボタン配列の要素 n に格納する { btnx[n] = "0" btny[n] = "0" btnxlen[n] = "0" btnylen[n] = "0" btntype[n] = "typeOTHER" btnarg[n] = "0" btndispfunc[n]= "NOFNC" btnavail[n] = "NO" btnid[n] = "0" if (token_checknext() != "[") return; token_get(); # [ while (1) { t = token_get(); if (t == "]") break; else if (t == "locate") { btnx[n] = token_get(); btny[n] = token_get(); } else if (t == "size") { btnxlen[n] = token_get(); btnylen[n] = token_get(); } else if (t == "pict") { btntype[n]="typePIC"; btnarg[n]=token_get(); } else if (t == "box") { btntype[n]="typeBOX"; btnarg[n]=token_get(); } else if (t == "buttons" || t == "button") { btntype[n]="typeBUTTONS"; btnarg[n]="(int)" token_get(); } else if (t == "dispfunc") { btndispfunc[n]=token_get(); } else if (t == "noselect") { btnavail[n] = "YES"; } else if (t == "id") { itemidstr[itemidnum] = token_get(); btnid[n] = itemidstr[itemidnum] itemidid[itemidnum] = itemid; itemidnum++; itemid++; } else if (t == "string") { btntype[n]="typeSTR"; s = token_get(); if (s=="boxed") { btntype[n]="typeSTRb"; s=token_get(); btnxlen[n]=length(s)*6+6; btnylen[n]=12+4; } else if (s=="emphasized" || s=="doubled") { btntype[n]="typeSTRe"; s=token_get(); } btnarg[n] = "(int)\"" s "\"" } else { print "near line " NR ": invalid button definition" exit } } } func output_buttons(name) { printf("static BUTTON %s[] =\n", name) >>outfile printf("{\n") >>outfile for (i=0; i>outfile printf("%s,%s,", btnxlen[i],btnylen[i]) >>outfile printf("%s,%s,",btntype[i],btnarg[i]) >>outfile printf("%s,%s,", btndispfunc[i],btnavail[i]) >>outfile printf("NULL,%s},\n", btnid[i]) >>outfile } printf("\t{-1}\n") >>outfile printf("};\n") >>outfile } #----------------------------------------------------- # スクロールバー情報の読み込みと出力 #----------------------------------------------------- func read_scrollbar(n) # from [ to ] { barx[n] = "0" bary[n] = "0" barlen[n] = "0" bartype[n] = "barHORI" barallsize[n] = "60"; bardspsize[n] = "5"; bardsppos[n] = "0"; barfunc[n]="NOFNC" barinv[n]="NO" bardispnum[n]="NO" baroffset[n]="0" barid[n] = "0" if (token_checknext() != "[") return; token_get(); # [ while (1) { t = token_get(); if (t == "]") break; else if (t == "locate") { barx[n] = token_get(); bary[n] = token_get(); } else if (t == "size") { barlen[n] = token_get(); } else if (t == "vert" || t == "vertical") { bartype[n]="barVERT" } else if (t == "hori" || t == "horisontal") { bartype[n]="barHORI" } else if (t == "allsize") { barallsize[n] = token_get(); } else if (t == "dspsize") { bardspsize[n] = token_get(); } else if (t == "dsppos") { bardsppos[n] = token_get(); } else if (t == "barfunc") { barfunc[n]=token_get(); } else if (t == "inverse") { barinv[n]="YES"; } else if (t == "dispnum") { bardispnum[n]="YES"; } else if (t == "offset") { baroffset[n]=token_get(); } else if (t == "id") { barid[n] = itemidstr[itemidnum] = token_get(); itemidid[itemidnum] = itemid; itemidnum++; itemid++; } else { print "near line " NR ": invalid scrollbar definition" exit } } } func output_scrollbars(name) { printf("static SCROLLBAR %s[] =\n", name) >>outfile printf("{\n") >>outfile for (i=0; i>outfile printf("%s,", bartype[i]) >>outfile printf("%s,", barlen[i]) >>outfile printf("%s,%s,%s,", barallsize[i],bardspsize[i],bardsppos[i]) >>outfile printf("%s,", barfunc[i]) >>outfile printf("%s,%s,",bardispnum[i],baroffset[i]) >>outfile printf("%s, NULL,%s},\n",barinv[i],barid[i]) >>outfile } printf("\t{-1}\n") >>outfile printf("};\n") >>outfile } #----------------------------------------------------- # 選択子情報の読み込みと出力 #----------------------------------------------------- func read_selector(n) # from [ to ] { selenum[n] = 0; selid[n] = "0" if (token_checknext() != "[") return; token_get(); # [ while (token_checknext() != "]") { t = token_checknext(); if (t == "id") { token_get(); selid[n] = itemidstr[itemidnum] = token_get(); itemidid[itemidnum] = itemid; itemidnum++; itemid++; } else if (t == "[") { read_selector_element(n, selenum[n]); selenum[n]++; } else { print "near line " NR ": invalid scrollbar definition" exit } } token_get(); # ] } func read_selector_element(n, m) # from [ to ] { selex[n,m] = "0"; seley[n,m] = "0"; selestr[n,m] = ""; seleid[n,m] = "0" if (token_checknext() != "[") return; token_get(); # [ while (1) { t = token_get(); if (t == "]") break; else if (t == "locate") { selex[n,m]=token_get(); seley[n,m]=token_get(); } else if (t == "string") selestr[n,m]=token_get(); else if (t == "id") { itemidstr[itemidnum] = token_get(); seleid[n,m] = itemidstr[itemidnum] itemidid[itemidnum] = itemid; itemidnum++; itemid++; } else { print "near line " NR ": invalid selector-element definition" exit } } } func output_selector_elements(id, name) { if (selenum[id] > 0) { printf("static SELECTOR_ELEMENT %s[] =\n", name) >>outfile printf("{\n") >>outfile for (j=0; j>outfile } printf("\t{-1}\n") >>outfile printf("};\n\n") >>outfile } } func output_selectors(name, enamebase) { printf("static SELECTOR %s[] =\n", name) >>outfile printf("{\n") >>outfile for (i=0; i 0) { printf("\t{0, %s%d,NULL, NULL,%s},\n",enamebase,i, selid[i]) >>outfile } else { printf("\t{0, NULL,NULL, NULL,%s},\n", selid[i]) >>outfile } } printf("\t{-1}\n};\n") >>outfile } #----------------------------------------------------- # 単語の切り出し処理 #----------------------------------------------------- func nextline() { do { if (getline != 1) { return -1; } sub(/#.*/, "") } while (match($0,/^[\t ]*$/)); tokptr = 1; return 0; } func token_init() { fileend = 0; nextline() nexttoken = $tokptr tokptr++ } func token_get() { __curt = _token_get(); if (match(__curt,/^".*[^"]$/)) { __curt = substr(__curt,2); while(1) { __tt = _token_get() if (match(__tt,/"$/)) { __curt = __curt " " substr(__tt,1,length(__tt)-1) break; } else __curt = __curt " " __tt; } } else if (match(__curt,/^".*"$/)) __curt = substr(__curt,2,length(__curt)-2); return __curt } func _token_get() { curtoken = nexttoken if (tokptr <= NF) nexttoken = $tokptr else { if (nextline() != 0) { fileend = 1; nexttoken=""; } else nexttoken = $tokptr } tokptr++ return curtoken } func token_checknext() { return nexttoken }