int correct_errors_erasures (unsigned char codeword[], int csize, int nerasures, int erasures[]) { int r, i, j, err; /* If you want to take advantage of erasure correction, be sure to set NErasures and ErasureLocs[] with the locations of erasures. */ NErasures = nerasures; for (i = 0; i < NErasures; i++) ErasureLocs[i] = erasures[i]; Modified_Berlekamp_Massey(); Find_Roots(); if ((NErrors <= NPAR) && NErrors > 0) { /* first check for illegal error locs */ for (r = 0; r < NErrors; r++) { if (ErrorLocs[r] >= csize) { if (RS_DEBUG) fprintf(stderr, "Error loc i=%d outside of codeword length %d\n", i, csize); return(0); } } for (r = 0; r < NErrors; r++) { int num, denom; i = ErrorLocs[r]; /* evaluate Omega at alpha^(-i) */ num = 0; for (j = 0; j < MAXDEG; j++) num ^= gmult(Omega[j], gexp[((255-i)*j)%255]); /* evaluate Lambda' (derivative) at alpha^(-i) ; all odd powers disappear */ denom = 0; for (j = 1; j < MAXDEG; j += 2) { denom ^= gmult(Lambda[j], gexp[((255-i)*(j-1)) % 255]); } err = gmult(num, ginv(denom)); if (RS_DEBUG) fprintf(stderr, "Error magnitude %#x at loc %d\n", err, csize-i); codeword[csize-i-1] ^= err; } return(1); } else { if (RS_DEBUG && NErrors) fprintf(stderr, "Uncorrectable codeword\n"); return(0); } }
int CReedSolomon::correct_errors_erasures (unsigned char codeword [], int csize, int nerasures, int erasures []) { int i, err; m_NErasures = nerasures; for (i = 0; i < m_NErasures; i ++) { m_ErasureLocs [i] = erasures [i]; } Modified_Berlekamp_Massey (); Find_Roots (); if ((m_NErrors <= m_iCorrectCodeSize) && m_NErrors > 0) { /* first check for illegal error locs */ for (int r = 0; r < m_NErrors; r ++) { if (m_ErrorLocs [r] >= csize) { return(0); } } for (int r = 0; r < m_NErrors; r ++) { int num, denom; i = m_ErrorLocs [r]; /* evaluate m_Omega at alpha^(-i) */ num = 0; for (int j = 0; j < MAX_LENGTH; j ++) { num ^= gmult (m_Omega [j], byExpToInt [((255 - i) * j) % 255]); } /* evaluate m_Lambda' (derivative) at alpha^(-i) ; all odd powers disappear */ denom = 0; for (int j = 1; j < MAX_LENGTH; j += 2) { denom ^= gmult (m_Lambda [j], byExpToInt [((255 - i) * (j - 1)) % 255]); } err = gmult (num, ginv (denom)); codeword [csize - i - 1] ^= err; } return 1; } else { return 0; } }
/* * Find client window at pointer location * * root is the root window. * subwin is the subwindow reported by a ButtonPress event on root. * * If the WM uses virtual roots subwin may be a virtual root. * If so, we descend the window stack at the pointer location and assume the * child is the client or one of its WM frame windows. * This will of course work only if the virtual roots are children of the real * root. */ xcb_window_t Find_Client(xcb_connection_t * dpy, xcb_window_t root, xcb_window_t subwin) { xcb_window_t *roots; unsigned int i, n_roots; xcb_window_t win; /* Check if subwin is a virtual root */ roots = Find_Roots(dpy, root, &n_roots); for (i = 0; i < n_roots; i++) { if (subwin != roots[i]) continue; win = Find_Child_At_Pointer(dpy, subwin); if (win == XCB_WINDOW_NONE) return subwin; /* No child - Return virtual root. */ subwin = win; break; } free (roots); if (atom_wm_state == XCB_ATOM_NONE) { atom_wm_state = Get_Atom(dpy, "WM_STATE"); if (atom_wm_state == XCB_ATOM_NONE) return subwin; } /* Check if subwin has WM_STATE */ if (Window_Has_Property(dpy, subwin, atom_wm_state)) return subwin; /* Attempt to find a client window in subwin's children */ win = Find_Client_In_Children(dpy, subwin); if (win != XCB_WINDOW_NONE) return win; /* Found a client */ /* Did not find a client */ return subwin; }