* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
* mLib 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 Library General Public License for more details.
* mLib 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 Library General Public License for more details.
* You should have received a copy of the GNU Library General Public
* License along with mLib; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
* You should have received a copy of the GNU Library General Public
* License along with mLib; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: crc-mktab.c,v $
- * Revision 1.1 2000/07/21 19:01:33 mdw
- * Generate the CRC table rather than hardcoding it.
- *
- */
-
-p, --polynomial=POLY Use the POLY as the dividing polynomial.\n\
-r, --reverse Create a `reversed' CRC table.\n\
-g, --guard=GUARD Use GUARD as a multiple-inclusion guard constant.\n\
-p, --polynomial=POLY Use the POLY as the dividing polynomial.\n\
-r, --reverse Create a `reversed' CRC table.\n\
-g, --guard=GUARD Use GUARD as a multiple-inclusion guard constant.\n\
--s, --symbol=SYM Name the generated table SYM\n\
+-i, --include=HEADER Include HEADER at top of C source file.\n\
+-s, --symbol=SYM Name the generated table SYM.\n\
-t, --type=TYPE Give the table entries type TYPE in C source.\n\
-o, --output=FILE Write the output to FILE.\n\
", stdout);
-t, --type=TYPE Give the table entries type TYPE in C source.\n\
-o, --output=FILE Write the output to FILE.\n\
", stdout);
guard = p;
for (q = file; *q; p++, q++) {
if (isalnum((unsigned char)*q))
guard = p;
for (q = file; *q; p++, q++) {
if (isalnum((unsigned char)*q))
-
- x = reflect(i, chunk) << (bits - chunk);
- for (j = 0; j < chunk; j++)
- x = ((x << 1) ^ (x & (1 << (bits - 1)) ? poly : 0)) & mask;
- x = reflect(x, bits);
+ unsigned ni, nn;
+
+ x = reflect(i, chunk);
+ y = 0;
+ nn = chunk;
+ while (nn) {
+ ni = bits;
+ if (ni > nn)
+ ni = nn;
+ z = (x >> (nn - ni)) & (0xffffffff >> (32 - ni));
+ y ^= z << (bits - ni);
+ for (j = 0; j < ni; j++)
+ y = ((y << 1) ^ (y & (1 << (bits - 1)) ? poly : 0)) & mask;
+ nn -= ni;
+ }
+ x = reflect(y, bits);
fprintf(fp, " 0x%0*lx", nw, x);
if (i == max - 1) {
fprintf(fp, " 0x%0*lx", nw, x);
if (i == max - 1) {