#// ogdfparse.awk #// the object generator definition file "parser" #// 13.03.2015 #// #// Copyright (C) 2015 Balthasar SzczepaƄski #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as #// published by the Free Software Foundation, either version 3 of the #// License, or (at your option) any later version. #// #// This program is distributed in the hope that it will be useful, #// but WITHOUT ANY WARRANTY; without even the implied warranty of #// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #// GNU Affero General Public License for more details. #// #// You should have received a copy of the GNU Affero General Public License #// along with this program. If not, see . BEGIN{ basepath="/eizm/mem/ong1" linenum=0 depth=0 nonstandard=0 external=0 toplevel=0 iflevel=0 limit=65536 if(int(q)<0) fail("fatal error.") } { ++linenum gsub(/[\r\n]/,"",$0) gsub(/(^[ \t]+)|([ \t]+$)/,"",$0) gsub(/#.*$/,"",$0) # print " "linenum "\t"$0 if($0 == "") next if($0 == "{") { ++depth next } if($0 == "}") { if(depth==0) fail("syntax error.") --depth next } if($0 ~ /^!/) { narg=split($0, aarg, /[ \t]+/) if(narg!=2) fail("syntax error.") if(aarg[1]=="!ifenabled") { ++iflevel } if(aarg[1]=="!endif") { if (iflevel==0) fail("unmatched endif.") --iflevel } if(aarg[1]=="!enable") { if (aarg[2]=="NONSTANDARD_1419") { nonstandard=1 limit=256 next } if (aarg[2]=="EXTERNAL_DEFINITIONS" && nonstandard!=0) { external=1 next } if (aarg[2]=="LIMIT_8BIT" && nonstandard!=0) { limit=256 next } fail(aarg[2]" undefined.") } if(aarg[1]=="!disable") { if (aarg[2]=="NONSTANDARD_1419") { nonstandard=0 limit=65536 external=0 next } if (aarg[2]=="EXTERNAL_DEFINITIONS" && nonstandard!=0) { external=0 next } if (aarg[2]=="LIMIT_8BIT" && nonstandard!=0) { limit=65536 next } fail(aarg[2]" undefined.") } fail(aarg[1]" undefined.") } if($0 ~ /^[A-Za-z][A-Za-z0-9_]*\([^\(\)]*\)$/) { narg=split($0, aarg, /[\(\)]/) if(aarg[narg]=="") --narg if(depth==0) fail(aarg[1]" not allowed here.") if(aarg[1]=="insertRelative"&&external!=0) fail(aarg[1]" not allowed here.") if(aarg[1]=="topLevelReplace"&&external!=0) { if(depth!=1) fail(aarg[1]" not allowed here.") nbarg=split(aarg[2],barg,/,/) if(nbarg!=2) fail(aarg[1]" wrong number of arguments.") if(barg[1] !~ /^[A-Za-z][A-Za-z0-9_]*$/ || barg[1] ~ /(NONSTANDARD_1419)|(EXTERNAL_DEFINITIONS)|(topLevelReplace)/) fail(barg[1]" wrong type.") if(barg[1] != "E") fail(barg[1]" undefined.") if(barg[2] !~ /^\"[^\"]*\"$/) #\"" fail(barg[2]" wrong type.") argpath=substr(barg[2],2,length(barg[2])-2) fullpath=basepath argpath if(getline line < fullpath) { close(fullpath) if(line=="") fail(argpath" cannot read.") if(line !~/^###generator&/) fail(argpath" 1: syntax error.") sub(/^###generator&/,"",line) obname=line toplevel=1 next } fail(argpath " cannot read.") } fail(aarg[1]" undefined.") } fail("syntax error.") } END{ if (ex!="") exit if(depth!=0) fail("syntax error.") if(iflevel!=0) fail("unmatched endif") if(toplevel==0) fail("top level undefined.") success(obname, int(q)) } function fail(error) { t=ogdf_name" "linenum": "error print t print " "t >> logf close(logf) ex=1 exit } function success(name, q) { t=q%limit " item(s) of: \""name"\" added to generation queue." print t print " "t >> logf close(logf) ex=1 exit }