/* package whatever; // don't place package name! */ /* This source code accompanies the article, "Using The Golay Error Detection And Correction Code", by Hank Wallace. This program demonstrates use of the Golay code. Usage: G DATA Encode/Correct/Verify/Test where DATA is the data to be encoded, codeword to be corrected, or codeword to be checked for errors. DATA is hexadecimal. Examples: G 555 E encodes information value 555 and prints a codeword G ABC123 C corrects codeword ABC123 G ABC123 V checks codeword ABC123 for errors G ABC123 T tests routines, ABC123 is a dummy parameter This program may be freely incorporated into your programs as needed. It compiles under Borland's Turbo C 2.0. No warranty of any kind is granted. */ #include "stdio.h" #include "conio.h" #define POLY 0xAE3 /* or use the other polynomial, 0xC75 */ /* ====================================================== */ unsigned long golay(unsigned long cw) /* This function calculates [23,12] Golay codewords. The format of the returned longint is [checkbits(11),data(12)]. */ { int i; unsigned long c; cw&=0xfffl; c=cw; /* save original codeword */ for (i=1; i<=12; i++) /* examine each data bit */ { if (cw & 1) /* test data bit */ cw^=POLY; /* XOR polynomial */ cw>>=1; /* shift intermediate result */ } return((cw<<12)|c); /* assemble codeword */ } /* ====================================================== */ int parity(unsigned long cw) /* This function checks the overall parity of codeword cw. If parity is even, 0 is returned, else 1. */ { unsigned char p; /* XOR the bytes of the codeword */ p=*(unsigned char*)&cw; p^=*((unsigned char*)&cw+1); p^=*((unsigned char*)&cw+2); /* XOR the halves of the intermediate result */ p=p ^ (p>>4); p=p ^ (p>>2); p=p ^ (p>>1); /* return the parity result */ return(p & 1); } /* ====================================================== */ unsigned long syndrome(unsigned long cw) /* This function calculates and returns the syndrome of a [23,12] Golay codeword. */ { int i; cw&=0x7fffffl; for (i=1; i<=12; i++) /* examine each data bit */ { if (cw & 1) /* test data bit */ cw^=POLY; /* XOR polynomial */ cw>>=1; /* shift intermediate result */ } return(cw<<12); /* value pairs with upper bits of cw */ } /* ====================================================== */ int weight(unsigned long cw) /* This function calculates the weight of 23 bit codeword cw. */ { int bits,k; /* nibble weight table */ const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; bits=0; /* bit counter */ k=0; /* do all bits, six nibbles max */ while ((k<6) && (cw)) { bits=bits+wgt[cw & 0xf]; cw>>=4; k++; } return(bits); } /* ====================================================== */ unsigned long rotate_left(unsigned long cw, int n) /* This function rotates 23 bit codeword cw left by n bits. */ { int i; if (n != 0) { for (i=1; i<=n; i++) { if ((cw & 0x400000l) != 0) cw=(cw << 1) | 1; else cw<<=1; } } return(cw & 0x7fffffl); } /* ====================================================== */ unsigned long rotate_right(unsigned long cw, int n) /* This function rotates 23 bit codeword cw right by n bits. */ { int i; if (n != 0) { for (i=1; i<=n; i++) { if ((cw & 1) != 0) cw=(cw >> 1) | 0x400000l; else cw>>=1; } } return(cw & 0x7fffffl); } /* ====================================================== */ unsigned long correct(unsigned long cw, int *errs) /* This function corrects Golay [23,12] codeword cw, returning the corrected codeword. This function will produce the corrected codeword for three or fewer errors. It will produce some other valid Golay codeword for four or more errors, possibly not the intended one. *errs is set to the number of bit errors corrected. */ { unsigned char w; /* current syndrome limit weight, 2 or 3 */ unsigned long mask; /* mask for bit flipping */ int i,j; /* index */ unsigned long s, /* calculated syndrome */ cwsaver; /* saves initial value of cw */ cwsaver=cw; /* save */ *errs=0; w=3; /* initial syndrome weight threshold */ j=-1; /* -1 = no trial bit flipping on first pass */ mask=1; while (j<23) /* flip each trial bit */ { if (j != -1) /* toggle a trial bit */ { if (j>0) /* restore last trial bit */ { cw=cwsaver ^ mask; mask+=mask; /* point to next bit */ } cw=cwsaver ^ mask; /* flip next trial bit */ w=2; /* lower the threshold while bit diddling */ } s=syndrome(cw); /* look for errors */ if (s) /* errors exist */ { for (i=0; i<23; i++) /* check syndrome of each cyclic shift */ { if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */ { cw=cw ^ s; /* remove errors */ cw=rotate_right(cw,i); /* unrotate data */ return(s=cw); } else { cw=rotate_left(cw,1); /* rotate to next pattern */ s=syndrome(cw); /* calc new syndrome */ } } j++; /* toggle next trial bit */ } else return(cw); /* return corrected codeword */ } return(cwsaver); /* return original if no corrections */ } /* correct */ /* ====================================================== */ int decode(int correct_mode, int *errs, unsigned long *cw) /* This function decodes codeword *cw in one of two modes. If correct_mode is nonzero, error correction is attempted, with *errs set to the number of bits corrected, and returning 0 if no errors exist, or 1 if parity errors exist. If correct_mode is zero, error detection is performed on *cw, returning 0 if no errors exist, 1 if an overall parity error exists, and 2 if a codeword error exists. */ { unsigned long parity_bit; if (correct_mode) /* correct errors */ { parity_bit=*cw & 0x800000l; /* save parity bit */ *cw&=~0x800000l; /* remove parity bit for correction */ *cw=correct(*cw, errs); /* correct up to three bits */ *cw|=parity_bit; /* restore parity bit */ /* check for 4 bit errors */ if (parity(*cw)) /* odd parity is an error */ return(1); return(0); /* no errors */ } else /* detect errors only */ { *errs=0; if (parity(*cw)) /* odd parity is an error */ { *errs=1; return(1); } if (syndrome(*cw)) { *errs=1; return(2); } else return(0); /* no errors */ } } /* decode */ /* ====================================================== */ void golay_test(void) /* This function tests the Golay routines for detection and correction of various patterns of error_limit bit errors. The error_mask cycles over all possible values, and error_limit selects the maximum number of induced errors. */ { unsigned long error_mask, /* bitwise mask for inducing errors */ trashed_codeword, /* the codeword for trial correction */ virgin_codeword; /* the original codeword without errors */ unsigned char pass=1, /* assume test passes */ error_limit=3; /* select number of induced bit errors here */ int error_count; /* receives number of errors corrected */ virgin_codeword=golay(0x555); /* make a test codeword */ if (parity(virgin_codeword)) virgin_codeword^=0x800000l; for (error_mask=0; error_mask<0x800000l; error_mask++) { /* filter the mask for the selected number of bit errors */ if (weight(error_mask) <= error_limit) /* you can make this faster! */ { trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */ decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */ if (trashed_codeword ^ virgin_codeword) { weight(error_mask),error_mask); pass=0; } if (kbhit()) /* look for user input */ { if (getch() == 27) return; /* escape exits */ /* other key prints status */ } } } } /* ====================================================== */ void main(int argument_count, char *argument[]) { int i,j; unsigned long l,g; const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n" " where DATA is the data to be encoded, codeword to be corrected,\n" " or codeword to be checked for errors. DATA is hexadecimal.\n\n" "Examples:\n\n" " G 555 E encodes information value 555 and prints a codeword\n" " G ABC123 C corrects codeword ABC123\n" " G ABC123 V checks codeword ABC123 for errors\n" " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n"; if (argument_count != 3) { } { } switch (toupper(*argument[2])) { case 'E': /* encode */ l&=0xfff; l=golay(l); if (parity(l)) l^=0x800000l; break; case 'V': /* verify */ if (decode(0,&i,&l)) else break; case 'C': /* correct */ g=l; /* save initial codeword */ j=decode(1,&i,&l); if ((j) && (i)) "resulting in codeword %lX with a parity error.\n",g,i,l); else if ((j == 0) && (i)) else if ((j) && (i == 0)) else if ((j == 0) && (i == 0)) break; case 'T': /* test */ golay_test(); break; default: } } /* end of G.C */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here } }
/* Original Patch by AoKMiKeY: http://w...content-available-to-author-only...s.com/forums/threads/gsc-menu-base-with-infinite-scroll.1341362/ Black Ops 1 Post by CabCon: http://w...content-available-to-author-only...g.com/ */ #include maps\mp\_utility; #include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connecting", player); player thread onPlayerSpawned(); } } onPlayerSpawned() { self endon("disconnect"); for(;;) { self waittill("spawned_player"); self iprintln("Ported by ^2CabCon"); if( !self.stopThreading ) { self playerSetup(); self.stopThreading = true; } } } playerSetup() { self defineVariables(); if( self == get_players()[0] && !isDefined(self.threaded) ) { self.playerSetting["hasMenu"] = true; self.playerSetting["verfication"] = "admin"; self thread menuBase(); self.threaded = true; } else { self.playerSetting["verfication"] = "unverified"; self thread menuBase(); } self runMenuIndex(); } defineVariables() { /* This is a good place to put any vars that that need to be defined as either an array or as a emety string or as a spawnstruct */ self.menu["curs"] = 0; self.menu["currentMenu"] = ""; self.menu["isLocked"] = false; self.playerSetting = []; self.playerSetting["verfication"] = ""; self.playerSetting["isInMenu"] = false; } menuBase() { while( true ) { if( !self getLocked() || self getVerfication() > 0 ) { if( !self getUserIn() ) { if( self adsButtonPressed() && self meleeButtonPressed() ) { self controlMenu("open", "main"); wait 0.2; } } else { if( self attackButtonPressed() || self adsButtonPressed() ) { self.menu["curs"] += self attackButtonPressed(); self.menu["curs"] -= self adsButtonPressed(); if( self.menu["curs"] > self.menu["items"][self getCurrent()].name.size-1 ) self.menu["curs"] = 0; if( self.menu["curs"] < 0 ) self.menu["curs"] = self.menu["items"][self getCurrent()].name.size-1; self thread scrollMenu(); wait 0.2; } if( self useButtonPressed() ) { self thread [[self.menu["items"][self getCurrent()].func[self getCursor()]]] ( self.menu["items"][self getCurrent()].input1[self getCursor()], self.menu["items"][self getCurrent()].input2[self getCursor()], self.menu["items"][self getCurrent()].input3[self getCursor()] ); wait 0.2; } if( self meleeButtonPressed() ) { if( isDefined(self.menu["items"][self getCurrent()].parent) ) self controlMenu("newMenu", self.menu["items"][self getCurrent()].parent); else self controlMenu("close"); wait 0.2; } } } wait .05; //frame } } //Thanks to mikeeeyy for the original code. //Thanks to me for changing the code to work with more things :) scrollMenu() { if(!isDefined(self.menu["items"][self getCurrent()].name[self getCursor()-3]) || self.menu["items"][self getCurrent()].name.size <= 7) { for(m = 0; m < 7; m++) self.menu["ui"]["text"][m] setText(self.menu["items"][self getCurrent()].name[m]); self.menu["ui"]["scroller"] affectElement("y", 0.18, self.menu["ui"]["text"][self getCursor()].y); for( a = 0; a < 7; a ++ ) { if( a != self getCursor() ) self.menu["ui"]["text"][a] affectElement("alpha", 0.18, .3); } self.menu["ui"]["text"][self getCursor()] affectElement("alpha", 0.18, 1); self iPrintLn("hud move"); } else { if(isDefined(self.menu["items"][self getCurrent()].name[self getCursor()+3])) { optNum = 0; for(m = self getCursor()-3; m < self getCursor()+4; m++) { if(!isDefined(self.menu["items"][self getCurrent()].name[m])) self.menu["ui"]["text"][optNum] setText(""); else self.menu["ui"]["text"][optNum] setText(self.menu["items"][self getCurrent()].name[m]); optNum++; } if( self.menu["ui"]["scroller"].y != self.menu["ui"]["text"][3].y ) self.menu["ui"]["scroller"] affectElement("y", 0.18, self.menu["ui"]["text"][3].y); if( self.menu["ui"]["text"][3].alpha != 1 ) { for( a = 0; a < 7; a ++ ) self.menu["ui"]["text"][a] affectElement("alpha", 0.18, .3); self.menu["ui"]["text"][3] affectElement("alpha", 0.18, 1); } } else { for(m = 0; m < 7; m++) self.menu["ui"]["text"][m] setText(self.menu["items"][self getCurrent()].name[self.menu["items"][self getCurrent()].name.size+(m-7)]); self.menu["ui"]["scroller"] affectElement("y", 0.18, self.menu["ui"]["text"][((self getCursor()-self.menu["items"][self getCurrent()].name.size)+7)].y); for( a = 0; a < 7; a ++ ) { if( a != ((self getCursor()-self.menu["items"][self getCurrent()].name.size)+7) ) self.menu["ui"]["text"][a] affectElement("alpha", 0.18, .3); } self.menu["ui"]["text"][((self getCursor()-self.menu["items"][self getCurrent()].name.size)+7)] affectElement("alpha", 0.18, 1); } } } controlMenu( type, par1 ) { if( type == "open" ) { self.menu["curs"] = 0; self.menu["ui"]["background"] = self createRectangle("CENTER", "CENTER", 0, 0, 210, 200, (0, 0, 0), 1, 0, "white"); self.menu["ui"]["scroller"] = self createRectangle("CENTER", "CENTER", 0, -40, 210, 20, (0, 0, .5), 2, 0, "white"); self.menu["ui"]["barTop"] = self createRectangle("CENTER", "CENTER", 0, -75, 0, 35, (0, 0, .5), 3, 0, "white"); self.menu["ui"]["background"] affectElement("alpha", .2, .5); self.menu["ui"]["scroller"] affectElement("alpha", .2, .9); self.menu["ui"]["barTop"] affectElement("alpha", .1, .9); self.menu["ui"]["barTop"] scaleOverTime(.3, 210, 35); wait .2; self buildTextOptions(par1); self.playerSetting["isInMenu"] = true; } if( type == "close" ) { self.menu["isLocked"] = true; self controlMenu("close_animation"); self.menu["ui"]["background"] scaleOverTime(.3, 210, 0); self.menu["ui"]["scroller"] scaleOverTime(.3, 0, 20); self.menu["ui"]["barTop"] scaleOverTime(.3, 0, 35); wait .2; self.menu["ui"]["background"] affectElement("alpha", .2, .1); self.menu["ui"]["scroller"] affectElement("alpha", .2, .1); self.menu["ui"]["barTop"] affectElement("alpha", .2, .1); wait .2; self.menu["ui"]["background"] destroy(); self.menu["ui"]["scroller"] destroy(); self.menu["ui"]["barTop"] destroy(); self.menu["curs"] = 0; self.menu["isLocked"] = false; self.playerSetting["isInMenu"] = false; } if( type == "newMenu") { self.menu["isLocked"] = true; self controlMenu("close_animation"); self.menu["curs"] = 0; self buildTextOptions(par1); self.menu["ui"]["scroller"] affectElement("y", 0.18, self.menu["ui"]["text"][self getCursor()].y); self.menu["isLocked"] = false; } if( type == "lock" ) { self controlMenu("close"); self.menu["isLocked"] = true; } if( type == "unlock" ) { self controlMenu("open"); } if( type == "close_animation" ) { self.menu["ui"]["title"] affectElement("alpha", .2, 0); for( a = 7; a >= 0; a-- ) { self.menu["ui"]["text"][a] affectElement("alpha", .2, 0); wait .05; } for( a = 7; a >= 0; a-- ) self.menu["ui"]["text"][a] destroy(); self.menu["ui"]["title"] destroy(); } } buildTextOptions(menu) { self.menu["currentMenu"] = menu; self.menu["ui"]["title"] = self createText(1.5, 5, self.menu["items"][menu].title, "CENTER", "CENTER", 0, -75, 0); self.menu["ui"]["title"] affectElement("alpha", .2, 1); for( a = 0; a < 7; a ++ ) { self.menu["ui"]["text"][a] = self createText(1.2, 5, self.menu["items"][menu].name[a], "CENTER", "CENTER", 0, -40+(a*20), 0); self.menu["ui"]["text"][a] affectElement("alpha", .2, .3); wait .05; } self.menu["ui"]["text"][0] affectElement("alpha", .2, 1); } //Menu utilities addMenu(menu, title, parent) { if( !isDefined(self.menu["items"][menu]) ) { self.menu["items"][menu] = spawnstruct(); self.menu["items"][menu].name = []; self.menu["items"][menu].func = []; self.menu["items"][menu].input1 = []; self.menu["items"][menu].input2 = []; self.menu["items"][menu].input3 = []; self.menu["items"][menu].title = title; if( isDefined( parent ) ) self.menu["items"][menu].parent = parent; else self.menu["items"][menu].parent = undefined; } self.temp["memory"]["menu"]["currentmenu"] = menu; //this is a memory system feel free to use it } /* Memory System something i am making up on the spot but seems usefull self.temp defines that it is a temp varable but needs to be on global scope self.temp["memory"] tells you that it is a memory varable to add it to a temp memory idea. self.temp["memory"]["menu"] means that it is for the menu self.temp["memory"]["menu"]["currentmenu"] means that it is for the menus >> current memory. so the use of this is self.temp[use][type][type for] enjoy :) */ //Par = paramatars < but i can not spell that so fuck it addMenuPar(name, func, input1, input2, input3) { menu = self.temp["memory"]["menu"]["currentmenu"]; count = self.menu["items"][menu].name.size; self.menu["items"][menu].name[count] = name; self.menu["items"][menu].func[count] = func; if( isDefined(input1) ) self.menu["items"][menu].input1[count] = input1; if( isDefined(input1) ) self.menu["items"][menu].input2[count] = input2; if( isDefined(input1) ) self.menu["items"][menu].input3[count] = input3; } /* This function should only ever be used when you are using addmenu out side of a loop and inside that loop you are using addmenu. You will see this in the verification. */ addAbnormalMenu(menu, title, parent, name, func, input1, input2, input3) { if( !isDefined(self.menu["items"][menu]) ) self addMenu(menu, title, parent); //title will never be changed after first menu is added. count = self.menu["items"][menu].name.size; self.menu["items"][menu].name[count] = name; self.menu["items"][menu].func[count] = func; if( isDefined(input1) ) self.menu["items"][menu].input1[count] = input1; if( isDefined(input1) ) self.menu["items"][menu].input2[count] = input2; if( isDefined(input1) ) self.menu["items"][menu].input3[count] = input3; } verificationOptions(par1, par2, par3) { player = get_players()[par1]; if( par2 == "changeVerification" ) { if( par1 == 0 ) return self iprintln( "You can not modify the host"); player setVerification(par3); self iPrintLn(getNameNotClan( player )+"'s verification has been changed to "+par3); player iPrintLn("Your verification has been changed to "+par3); } } setVerification( type ) { self.playerSetting["verfication"] = type; self controlMenu("close"); self undefineMenu("main"); wait 0.2; self runMenuIndex( true ); //this will only redefine the main menu wait 0.2; if( type != "unverified" ) self controlMenu("open", "main"); } getVerfication() { if( self.playerSetting["verfication"] == "admin" ) return 3; if( self.playerSetting["verfication"] == "co-host" ) return 2; if( self.playerSetting["verfication"] == "verified" ) return 1; if( self.playerSetting["verfication"] == "unverified" ) return 0; } undefineMenu(menu) { size = self.menu["items"][menu].name.size; for( a = 0; a < size; a++ ) { self.menu["items"][menu].name[a] = undefined; self.menu["items"][menu].func[a] = undefined; self.menu["items"][menu].input1[a] = undefined; self.menu["items"][menu].input2[a] = undefined; self.menu["items"][menu].input3[a] = undefined; } } getCurrent() { return self.menu["currentMenu"]; } getLocked() { return self.menu["isLocked"]; } getUserIn() { return self.playerSetting["isInMenu"]; } getCursor() { return self.menu["curs"]; } //UI utilities createText(fontSize, sorts, text, align, relative, x, y, alpha, color) { uiElement = self createfontstring("default", fontSize); uiElement setPoint(align, relative, x, y); uiElement settext(text); uiElement.sort = sorts; if( isDefined(alpha) ) uiElement.alpha = alpha; if( isDefined(color) ) uiElement.color = color; return uiElement; } createRectangle(align, relative, x, y, width, height, color, sort, alpha, shader) { uiElement = newClientHudElem( self ); uiElement.elemType = "bar"; uiElement.width = width; uiElement.height = height; uiElement.align = align; uiElement.relative = relative; uiElement.xOffset = 0; uiElement.yOffset = 0; uiElement.children = []; uiElement.sort = sort; uiElement.color = color; uiElement.alpha = alpha; uiElement setParent( level.uiParent ); uiElement setShader( shader, width , height ); uiElement.hidden = false; uiElement setPoint(align,relative,x,y); return uiElement; } affectElement(type, time, value) { if( type == "x" || type == "y" ) self moveOverTime( time ); else self fadeOverTime( time ); if( type == "x" ) self.x = value; if( type == "y" ) self.y = value; if( type == "alpha" ) self.alpha = value; if( type == "color" ) self.color = value; } runMenuIndex( menu ) { self addmenu("main", "Main Menu"); //if verified if( self getVerfication() > 0 ) { self addMenuPar("lews mods", ::controlMenu, "newMenu", "second"); self addMenuPar("main menu 2"); self addMenuPar("main menu 3"); } //if cohost if( self getVerfication() > 1 ) { self addMenuPar("main menu 4"); self addMenuPar("main menu 5"); self addMenuPar("main menu 6"); } //if host if( self getVerfication() > 2 ) { self addMenuPar("main menu 7"); self addMenuPar("main menu 8"); self addMenuPar("player Menu", ::controlMenu, "newMenu", "playerMenu"); } //any menus that work off of a verification change. //should go before the if statment. If you dont then //it shall not change when verification is changed. if( isDefined(menu) ) return; self addmenu("second", "second Menu", "main"); self addMenuPar("noclip"); self addMenuPar("second menu 2"); self addMenuPar("second menu 3"); self addMenuPar("second menu 4"); self addMenuPar("second menu 5"); self addMenuPar("second menu 6"); self addMenuPar("second menu 7"); self addMenuPar("second menu 8"); self addMenuPar("second menu 9"); self addMenuPar("second menu 10"); self addMenuPar("second menu 11"); self addMenuPar("second menu 7"); self addMenuPar("second menu 13"); self addMenuPar("second menu 14"); self addMenuPar("second menu 15"); self addMenuPar("second menu 16"); self addMenuPar("second menu 17"); self addMenuPar("second menu 18"); self addMenuPar("second menu 19"); for( a = 0; a < get_players().size; a++ ) { player = get_players()[a]; self addAbnormalMenu("playerMenu", "Player Menu", "main", getNameNotClan( player )+" Options", ::controlMenu, "newMenu", getNameNotClan( player )+"options"); self addAbnormalMenu(getNameNotClan( player )+"options", getNameNotClan( player )+" Options", "playerMenu", "unverified", ::verificationOptions, a, "changeVerification", "unverified"); self addAbnormalMenu(getNameNotClan( player )+"options", "", "", "verified", ::verificationOptions, a, "changeVerification", "verified"); self addAbnormalMenu(getNameNotClan( player )+"options", "", "", "co-host", ::verificationOptions, a, "changeVerification", "co-host"); self addAbnormalMenu(getNameNotClan( player )+"options", "", "", "admin", ::verificationOptions, a, "changeVerification", "admin"); } } getNameNotClan( player ) { for( a = 0; a < player.name.size; a++ ) { if( player.name[a] == "[" ) return getSubStr(player.name , 6, player.name.size); else return player.name; } } doNoclip() { if(!self.noclip) { self.noclip = true; thread noclipActivate(); self system_out(); self iPrintln("NoClip ^2ON^7"); } } noclipActivate() { self endon("disconnect"); self endon("death"); clipModel = spawn("script_origin",self.origin); self linkTo(clipModel); thread clipDeath(clipModel); while(self.noclip) { if(self useButtonPressed()) clipModel.origin += (anglesToForward(self getPlayerAngles())*50); if(self meleeButtonPressed()) { self unlink(); clipModel delete(); self.lockMenu = false; self.noclip = false; self iPrintln("NoClip ^1OFF^7"); } wait .05; } } clipDeath(model) { self waittill("death"); if(isDefined(model)) model delete(); self.noclip = false; }
/* package whatever; // don't place package name! */ /* This source code accompanies the article, "Using The Golay Error Detection And Correction Code", by Hank Wallace. This program demonstrates use of the Golay code. Usage: G DATA Encode/Correct/Verify/Test where DATA is the data to be encoded, codeword to be corrected, or codeword to be checked for errors. DATA is hexadecimal. Examples: G 555 E encodes information value 555 and prints a codeword G ABC123 C corrects codeword ABC123 G ABC123 V checks codeword ABC123 for errors G ABC123 T tests routines, ABC123 is a dummy parameter This program may be freely incorporated into your programs as needed. It compiles under Borland's Turbo C 2.0. No warranty of any kind is granted. */ #include "stdio.h" #include "conio.h" #define POLY 0xAE3 /* or use the other polynomial, 0xC75 */ /* ====================================================== */ unsigned long golay(unsigned long cw) /* This function calculates [23,12] Golay codewords. The format of the returned longint is [checkbits(11),data(12)]. */ { int i; unsigned long c; cw&=0xfffl; c=cw; /* save original codeword */ for (i=1; i<=12; i++) /* examine each data bit */ { if (cw & 1) /* test data bit */ cw^=POLY; /* XOR polynomial */ cw>>=1; /* shift intermediate result */ } return((cw<<12)|c); /* assemble codeword */ } /* ====================================================== */ int parity(unsigned long cw) /* This function checks the overall parity of codeword cw. If parity is even, 0 is returned, else 1. */ { unsigned char p; /* XOR the bytes of the codeword */ p=*(unsigned char*)&cw; p^=*((unsigned char*)&cw+1); p^=*((unsigned char*)&cw+2); /* XOR the halves of the intermediate result */ p=p ^ (p>>4); p=p ^ (p>>2); p=p ^ (p>>1); /* return the parity result */ return(p & 1); } /* ====================================================== */ unsigned long syndrome(unsigned long cw) /* This function calculates and returns the syndrome of a [23,12] Golay codeword. */ { int i; cw&=0x7fffffl; for (i=1; i<=12; i++) /* examine each data bit */ { if (cw & 1) /* test data bit */ cw^=POLY; /* XOR polynomial */ cw>>=1; /* shift intermediate result */ } return(cw<<12); /* value pairs with upper bits of cw */ } /* ====================================================== */ int weight(unsigned long cw) /* This function calculates the weight of 23 bit codeword cw. */ { int bits,k; /* nibble weight table */ const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; bits=0; /* bit counter */ k=0; /* do all bits, six nibbles max */ while ((k<6) && (cw)) { bits=bits+wgt[cw & 0xf]; cw>>=4; k++; } return(bits); } /* ====================================================== */ unsigned long rotate_left(unsigned long cw, int n) /* This function rotates 23 bit codeword cw left by n bits. */ { int i; if (n != 0) { for (i=1; i<=n; i++) { if ((cw & 0x400000l) != 0) cw=(cw << 1) | 1; else cw<<=1; } } return(cw & 0x7fffffl); } /* ====================================================== */ unsigned long rotate_right(unsigned long cw, int n) /* This function rotates 23 bit codeword cw right by n bits. */ { int i; if (n != 0) { for (i=1; i<=n; i++) { if ((cw & 1) != 0) cw=(cw >> 1) | 0x400000l; else cw>>=1; } } return(cw & 0x7fffffl); } /* ====================================================== */ unsigned long correct(unsigned long cw, int *errs) /* This function corrects Golay [23,12] codeword cw, returning the corrected codeword. This function will produce the corrected codeword for three or fewer errors. It will produce some other valid Golay codeword for four or more errors, possibly not the intended one. *errs is set to the number of bit errors corrected. */ { unsigned char w; /* current syndrome limit weight, 2 or 3 */ unsigned long mask; /* mask for bit flipping */ int i,j; /* index */ unsigned long s, /* calculated syndrome */ cwsaver; /* saves initial value of cw */ cwsaver=cw; /* save */ *errs=0; w=3; /* initial syndrome weight threshold */ j=-1; /* -1 = no trial bit flipping on first pass */ mask=1; while (j<23) /* flip each trial bit */ { if (j != -1) /* toggle a trial bit */ { if (j>0) /* restore last trial bit */ { cw=cwsaver ^ mask; mask+=mask; /* point to next bit */ } cw=cwsaver ^ mask; /* flip next trial bit */ w=2; /* lower the threshold while bit diddling */ } s=syndrome(cw); /* look for errors */ if (s) /* errors exist */ { for (i=0; i<23; i++) /* check syndrome of each cyclic shift */ { if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */ { cw=cw ^ s; /* remove errors */ cw=rotate_right(cw,i); /* unrotate data */ return(s=cw); } else { cw=rotate_left(cw,1); /* rotate to next pattern */ s=syndrome(cw); /* calc new syndrome */ } } j++; /* toggle next trial bit */ } else return(cw); /* return corrected codeword */ } return(cwsaver); /* return original if no corrections */ } /* correct */ /* ====================================================== */ int decode(int correct_mode, int *errs, unsigned long *cw) /* This function decodes codeword *cw in one of two modes. If correct_mode is nonzero, error correction is attempted, with *errs set to the number of bits corrected, and returning 0 if no errors exist, or 1 if parity errors exist. If correct_mode is zero, error detection is performed on *cw, returning 0 if no errors exist, 1 if an overall parity error exists, and 2 if a codeword error exists. */ { unsigned long parity_bit; if (correct_mode) /* correct errors */ { parity_bit=*cw & 0x800000l; /* save parity bit */ *cw&=~0x800000l; /* remove parity bit for correction */ *cw=correct(*cw, errs); /* correct up to three bits */ *cw|=parity_bit; /* restore parity bit */ /* check for 4 bit errors */ if (parity(*cw)) /* odd parity is an error */ return(1); return(0); /* no errors */ } else /* detect errors only */ { *errs=0; if (parity(*cw)) /* odd parity is an error */ { *errs=1; return(1); } if (syndrome(*cw)) { *errs=1; return(2); } else return(0); /* no errors */ } } /* decode */ /* ====================================================== */ void golay_test(void) /* This function tests the Golay routines for detection and correction of various patterns of error_limit bit errors. The error_mask cycles over all possible values, and error_limit selects the maximum number of induced errors. */ { unsigned long error_mask, /* bitwise mask for inducing errors */ trashed_codeword, /* the codeword for trial correction */ virgin_codeword; /* the original codeword without errors */ unsigned char pass=1, /* assume test passes */ error_limit=3; /* select number of induced bit errors here */ int error_count; /* receives number of errors corrected */ virgin_codeword=golay(0x555); /* make a test codeword */ if (parity(virgin_codeword)) virgin_codeword^=0x800000l; for (error_mask=0; error_mask<0x800000l; error_mask++) { /* filter the mask for the selected number of bit errors */ if (weight(error_mask) <= error_limit) /* you can make this faster! */ { trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */ decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */ if (trashed_codeword ^ virgin_codeword) { printf("Unable to correct %d errors induced with error mask = 0x%lX\n", weight(error_mask),error_mask); pass=0; } if (kbhit()) /* look for user input */ { if (getch() == 27) return; /* escape exits */ /* other key prints status */ printf("Current test count = %ld of %ld\n",error_mask,0x800000l); } } } printf("Golay test %s!\n",pass?"PASSED":"FAILED"); } /* ====================================================== */ void main(int argument_count, char *argument[]) { int i,j; unsigned long l,g; const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n" " where DATA is the data to be encoded, codeword to be corrected,\n" " or codeword to be checked for errors. DATA is hexadecimal.\n\n" "Examples:\n\n" " G 555 E encodes information value 555 and prints a codeword\n" " G ABC123 C corrects codeword ABC123\n" " G ABC123 V checks codeword ABC123 for errors\n" " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n"; if (argument_count != 3) { printf(errmsg); exit(0); } if (sscanf(argument[1],"%lx",&l) != 1) { printf(errmsg); exit(0); } switch (toupper(*argument[2])) { case 'E': /* encode */ l&=0xfff; l=golay(l); if (parity(l)) l^=0x800000l; printf("Codeword = %lX\n",l); break; case 'V': /* verify */ if (decode(0,&i,&l)) printf("Codeword %lX is not a Golay codeword.\n",l); else printf("Codeword %lX is a Golay codeword.\n",l); break; case 'C': /* correct */ g=l; /* save initial codeword */ j=decode(1,&i,&l); if ((j) && (i)) printf("Codeword %lX had %d bits corrected,\n" "resulting in codeword %lX with a parity error.\n",g,i,l); else if ((j == 0) && (i)) printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l); else if ((j) && (i == 0)) printf("Codeword %lX has a parity error. No bits were corrected.\n",g); else if ((j == 0) && (i == 0)) printf("Codeword %lX does not require correction.\n",g); break; case 'T': /* test */ printf("Press SPACE for status, ESC to exit test...\n"); golay_test(); break; default: printf(errmsg); exit(0); } } /* end of G.C */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here } }