#!/usr/bin/perl5 #takes one number argument (size of squares) # will generate code for symmetric squares $n=shift(@ARGV); print << 'END'; #include "dawg.h" #include "msq4.h" #include "aoften.c" END print "#define n $n\n"; print << 'END'; unsigned char logtab[129]; /* unsigned char logtab[] = { 0, 4, 8,24,12,44,28, 64, 16,56,48,84, 32,92, 68,104, 124,20,40,60,52,80,88,100,120,36,76,96,116,72,112,108}; */ unsigned int first_node; char *dawg; FILE *ho; TFeld *myfeld; END print "unsigned char fullstr[] = { "; for($i=0;$i<$n;$i++) { for($j=0;$j<$n;$j++) { if($i<$j) { $p=128+$j+$i*$n; } else { $p=128+$i+$j*$n; } print "$p,"; } print '\'\n\','; if($i<$n-1) { print "\n"; } } print "0} ;\n"; $p1=129+$n; #$p2=130+$n; #$p3=130+2*$n; print "unsigned char partstr[] = { 128,' ',129,$p1,' ',130,0 } ;\n"; print << 'END'; void do_line() { unsigned int mask,maske; unsigned int log; TFeld *feld; char *rdawg; feld=myfeld; rdawg=dawg; END $mc=0; for($i=0;$i<$n;$i++) { for($j=0;$j<=$i;$j++) { $p=$i+$j*$n; if($j==0) { print " feld[$p].mask=feld[$p].omask;\n"; } else { print " feld[$p].mask=mask;\n"; } print "m$mc:\nif((mask=feld[$p].mask)==0) "; if($mc==0) { print "return;\n"; } else { $p=$mc-1; print "goto m$p;\n"; } $p=$i+$j*$n; print " feld[$p].mask=maske=mask&(mask-1);\n"; print " maske^=mask;\n"; if($i!=$j || $i<$n-1) { # print " log=logtab[((maske*0x4653adf)>>27)&0x1f];\n" # or without logtab, on PowerPC # print " log=(31-__cntlzw(maske))<<2;\n"; print " log=0; if(maske&0xffff0000) { log=64;maske>>=16;}\n"; print " if(maske&0xff00) { log+=32; maske>>=8;}\n"; print " log+=logtab[maske];\n"; } if($i<$n-1) { $p1=$p+1; if($j==0) { print " mask=*(unsigned int *)(feld[$p1].wnode=rdawg+PTR(*(NODE *)(feld[$p].wnode+log)));\n"; print " if((feld[$p1].omask=(*(unsigned int *)(feld[$p1].snode))&mask)==0) { goto m$mc; }\n"; } else { print " if((feld[$p1].wnode=rdawg+PTR(*(NODE *)(feld[$p].wnode+log)))==0) { goto m$mc; }\n"; } } if($j<$i-1) { $p1=$p+$n; print " mask=*(unsigned int *)(feld[$p1].snode=rdawg+PTR(*(NODE *)(feld[$p].snode+log)));\n"; print " if((mask=(*(unsigned int *)(feld[$p1].wnode))&mask)==0) { goto m$mc; }\n"; } elsif($i==$j+1) { $p1=$p+$n; print " if((mask=*(unsigned int *)(feld[$p1].wnode=feld[$p1].snode=rdawg+PTR(*(NODE *)(feld[$p].snode+log))))==0) { goto m$mc; }\n"; } $mc++; if($mc==4) { print " ausgabe(feld,partstr);\n"; } } } print " ausgabe(feld,fullstr);\n"; $mc--; print " goto m$mc;\n"; print << 'END'; } void finish_word() { if(dawg!=NULL) free(dawg); cleanup_abc(); } /* --------------------------------------------- Main --------------------------------------------- */ main() { int i; myfeld=(TFeld *)malloc(n*n*sizeof(TFeld)); init_word(); for(i=0;i=128) { fp=&(feld[(*ctrl)-128]); mask=fp->mask^((*((NODE *)(fp->wnode)))&(*((NODE *)(fp->snode)))); log=0; if(mask&0xffff0000) { log=16; mask>>=16; } if(mask&0xff00) { log+=8; mask>>=8; } if(mask&0xf0) { log+=4; mask>>=4; } log+=logs[mask]; zp+=ch_scr2utf(log,zeile+zp); } else { zeile[zp++]=*ctrl; } ctrl++; } zeile[zp++]='\n'; zeile[zp]=0; if(octrl==fullstr) { fprintf(ho,"%s\n",zeile); } printf("%s",zeile); } END