git » fp-git.git » commit 79d9b63

moved awk scripts to a file

author ecalot
2004-10-15 21:17:57 UTC
committer ecalot
2004-10-15 21:17:57 UTC
parent f3e73d5aab7a0a01cfc9265dbb20261abc247fa5

moved awk scripts to a file

FP/src/conf/awk/res_conf_files.awk +1 -0
FP/src/conf/awk/res_conf_mods.awk +1 -0
FP/src/conf/awk/res_conf_parts.awk +10 -0
FP/src/conf/awk/res_conf_resources.awk +63 -0
FP/src/conf/awk/res_conf_types.awk +7 -0
FP/src/conf/awk/states_conf_static.awk +107 -0

diff --git a/FP/src/conf/awk/res_conf_files.awk b/FP/src/conf/awk/res_conf_files.awk
new file mode 100644
index 0000000..cc36a3b
--- /dev/null
+++ b/FP/src/conf/awk/res_conf_files.awk
@@ -0,0 +1 @@
+BEGIN {res=0} {printf "#define RES_FILE_%s %d\n",$1,res;for (i = 2; i <= NF; i++) {filelist=(filelist coma $i);coma="\",\\\n\t\"";res++}} END {print (" /* numbers */\n#define RES_FILES {\\\n\t\""filelist "\"\\\n}")}
diff --git a/FP/src/conf/awk/res_conf_mods.awk b/FP/src/conf/awk/res_conf_mods.awk
new file mode 100644
index 0000000..79bfeae
--- /dev/null
+++ b/FP/src/conf/awk/res_conf_mods.awk
@@ -0,0 +1 @@
+{printf "#define RES_MODS_%s %s\n",$1,$2}
diff --git a/FP/src/conf/awk/res_conf_parts.awk b/FP/src/conf/awk/res_conf_parts.awk
new file mode 100644
index 0000000..3eb6a67
--- /dev/null
+++ b/FP/src/conf/awk/res_conf_parts.awk
@@ -0,0 +1,10 @@
+BEGIN {
+	offset=0
+	printf("\n/* parts */\n")
+} 
+
+{
+	start=offset
+	offset=end=$2+offset
+	printf " /* %s, size=%d */\n#define res_get_part_%s(a) (((a)>>%d)&0x%08x)\n#define res_set_part_%s(a) (((a)&0x%08x)<<%d)\n",$1,$2,$1,start,(2^$2-1),$1,(2^$2-1),start
+}
diff --git a/FP/src/conf/awk/res_conf_resources.awk b/FP/src/conf/awk/res_conf_resources.awk
new file mode 100644
index 0000000..86f068f
--- /dev/null
+++ b/FP/src/conf/awk/res_conf_resources.awk
@@ -0,0 +1,63 @@
+BEGIN {
+	res=0
+	coma=""
+	filelist=""
+	items=0
+}
+
+{
+	oldres=res
+	if (substr($2,1,2)=="OF") {
+		if ((items!=0)&&(NF!=items)) {
+			print "ERROR: item numbers do not match between different OFFSETs\n"
+			exit -1;
+		}
+		if (items==0) items=NF
+		if (offsets!="") offsets=( offsets "|" )
+		offsets=( offsets "RES_MODS_HAS_" substr($2,3,1) )
+		inc=3
+		for (i=0;i<=((NF-3)/2);i++) {
+			one=$inc
+			inc++
+			two=$inc
+			inc++
+			res++
+			filelist=(filelist coma "(short)" ((two+64)*256+(one+64)) )
+			coma=","
+		}
+	} else {
+		for (i=3;i<=NF;i++) {
+			if (match($i,/^[A-Z]*$/)) {
+				filelist=(filelist coma "RES_FILE_" $i)
+				res++
+			} else if (match($i,/^[0-9]+-[0-9]*$/)) {
+				split($i,a,"-")
+				for (g=a[1];g<=a[2];g++) {
+					filelist=(filelist coma g)
+					res++
+					coma=","
+				}
+			} else {
+				res++
+				filelist=(filelist coma $i)
+			}
+			coma=","
+		}
+		if (items==0) {
+			extra="";
+		} else {
+			extra=( "|res_set_part_mods(" offsets ")" )
+			offsets=""
+		}
+		printf "#define RES_%s res_set_part_type(RES_TYPE_%s)|res_set_part_from(%d)|res_set_part_size(%d)%s\n",$1,$2,oldres,res-oldres,extra
+		if ((items!=0)&&(res-oldres!=items)) {
+			print "ERROR: item numbers do not match between OFFSETs and IMGs\n"
+			exit -1;
+		}
+		items=0
+	}
+}
+END {
+	print(" /* define codes */\n#define RES_LIST {" filelist "}\n")
+}
+
diff --git a/FP/src/conf/awk/res_conf_types.awk b/FP/src/conf/awk/res_conf_types.awk
new file mode 100644
index 0000000..f5f1c65
--- /dev/null
+++ b/FP/src/conf/awk/res_conf_types.awk
@@ -0,0 +1,7 @@
+BEGIN {
+	type=0
+}
+
+{
+	printf "#define RES_TYPE_%s %d\n",$1,type++
+}
diff --git a/FP/src/conf/awk/states_conf_static.awk b/FP/src/conf/awk/states_conf_static.awk
new file mode 100644
index 0000000..7a4bb34
--- /dev/null
+++ b/FP/src/conf/awk/states_conf_static.awk
@@ -0,0 +1,107 @@
+
+BEGIN {
+	currentCondition=-1
+	currentAction=0
+	printf("#define STATES_CONDITIONS={\\\n");
+	tmp="conf/statesproperties.conf"
+	while ((getline line < tmp) > 0) {
+		gsub(/[	 ]+/, "-",line)
+		m=index(line,"-")
+		if (m) {
+			word=substr(line,0,m)
+			number=substr(line,m+1)
+			defines[word]=number
+		}
+	}
+	close(tmp)
+	currentAnimation=0
+}
+
+{
+	if ( $1 == "-" ) {
+		if ($2=="-") {
+			if ($3=="-") {
+				if (listType == "next") {
+					nextState=tolower($4)
+				} else if (listType == "steps") {
+					steps=$4
+				} else if (listType == "conditions") {
+					if (oldType != listType ) {
+						oldType=listType
+						currentCondition++
+						printf("\t{esTrue,0}, /* condition number %d */\\\n",currentCondition)
+						conditions=currentCondition+1
+					}
+					currentCondition++;
+					result=$5
+					if (defines[$5]) result=defines[$5]
+					printf("\t{es%s,%d}, /* condition number %d */\\\n",$4,result,currentCondition)
+				} else if (listType == "animation") {
+					if (match($4,/^[0-9]+-[0-9]*$/)) {
+						split($4,a,"-")
+						for (g=a[1];g<=a[2];g++) {
+							arrayAnimation[currentAnimation]=g
+							currentAnimation++
+						}
+					} else {
+						arrayAnimation[currentAnimation]=$4
+						currentAnimation++
+					}
+				}
+			} else {
+				$3=tolower($3)
+				oldType=listType
+				listType=$3
+			}
+		} else {		
+			if (conditions) {
+				linkedState=currentState
+				currentState=""
+				stateList[linkedState]=currentAction
+				if (linkedState) {
+					linkedState=sprintf("State: %s (%d), ",linkedState,currentActions)
+				}
+				stateArray[currentAction]=sprintf("{/*initial condition*/ %d, /*next state*/ **replace*%s**, /*steps*/ %d},\\\n\t/* %sAction: %s, Animations: start=%d total=%d*/",conditions,nextState,steps,linkedState,rememberAction,startAnimation,currentAnimation-startAnimation)
+				currentAction++;
+			}
+
+			startAnimation=currentAnimation
+			listType=""
+			conditions=0
+			$2=tolower($2);
+			if ($2 != "action") {
+				print "Error! \"$0\" should be an action."
+			}
+			$2=$1=""
+			rememberAction=substr($0,3)
+		}
+	} else {
+		listType=""
+		currentState=tolower($1)
+	}
+
+}
+
+END {
+	printf("\t{esTrue,0} /* the end */\\\n};\n\n#define STATES_ACTIONS={\\\n");
+	linkedState=currentState
+	stateArray[currentAction]=sprintf("{/*initial condition*/ %d, /*next state*/ **replace*%s**, /*steps*/ %d} /* %sAction: %s */\n",conditions,nextState,steps,linkedState,rememberAction)
+	for (i=0;i<=currentAction;i++) {
+		replaceStart=match(stateArray[i],/\*\*replace\*(.*)\*\*/)
+		line=substr(stateArray[i],10+replaceStart)
+		replaceEnd=match(line,/\*\*/)
+		line=substr(line,0,replaceEnd)
+		stateNumber=stateList[line]
+		if (!stateNumber) stateNumber=0
+		printf "\t%s%d /* %s */%s\\\n", substr(stateArray[i],0,replaceStart),stateNumber,line,substr(stateArray[i],11+replaceEnd+replaceStart)
+	}
+	printf("};\n\n#define STATES_ANIMATIONS={\\\n\t");
+	coma=""
+	for (i=0;i<currentAnimation;i++) {
+		printf "%s%d",coma,arrayAnimation[i]
+		if (i%10==9) printf("\\\n\t");
+		coma=","
+	}
+	printf("\\\n};\n");
+}
+