home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / bitio / part02 < prev    next >
Encoding:
Text File  |  1993-03-02  |  58.1 KB  |  1,751 lines

  1. Newsgroups: comp.sources.misc
  2. From: pdh@netcom.com (Philip D. Howard)
  3. Subject: v35i106:  bitio - portable bit stream function library, Part02/03
  4. Message-ID: <1993Mar3.151915.14085@sparky.imd.sterling.com>
  5. X-Md4-Signature: b4870c0b6b0e6e9918f419a2cd605fa9
  6. Date: Wed, 3 Mar 1993 15:19:15 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: pdh@netcom.com (Philip D. Howard)
  10. Posting-number: Volume 35, Issue 106
  11. Archive-name: bitio/part02
  12. Environment: MS-DOS, UNIX, ANSI-C, BCC, GCC, MSC, PC, NeXT, Sparc, Sequent
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  bitio104/INSTALL bitio104/README bitio104/bit1get.c
  19. #   bitio104/bit1put.c bitio104/bitclose.c bitio104/bitflush.c
  20. #   bitio104/bithget.c bitio104/bitio.3 bitio104/bitio.h
  21. #   bitio104/bitopen.c bitio104/bitput.h bitio104/bituse.c
  22. #   bitio104/rand.h bitio104/randul.c bitio104/testio.h
  23. #   bitio104/testmi.c bitio104/testmo.c
  24. # Wrapped by kent@sparky on Wed Mar  3 09:07:10 1993
  25. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 2 (of 3)."'
  28. if test -f 'bitio104/INSTALL' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'bitio104/INSTALL'\"
  30. else
  31.   echo shar: Extracting \"'bitio104/INSTALL'\" \(3430 characters\)
  32.   sed "s/^X//" >'bitio104/INSTALL' <<'END_OF_FILE'
  33. X------------------------------------------------------------------------
  34. XFor UNIX with GNU C Compiler:
  35. X
  36. XJust type "gmake".  The library "libbitio.a" will be created.  You can
  37. Xthen "cp" or "mv" the library wherever you would like to have it for
  38. Xyour own program development.
  39. X
  40. XIf you are on a NeXT system, your "cc" compiler should already be the
  41. XGNU C Compiler.  Just link the name "gcc" to your compiler such as
  42. Xwith the command:  "ln -s gcc /bin/cc" or if you "cc" compiler is
  43. Xsomewhere else, but in your path, "ln -s gcc `which cc`".
  44. X
  45. XYou also have the command "gremake", "gclean", and "gvirgin".
  46. X------------------------------------------------------------------------
  47. XFor UNIX without GNU C Compiler:
  48. X
  49. XI have found that many compilers will not work well because BITIO is
  50. Xwritten in ANSI Standard C and a lot of UNIX system vendors have not
  51. Xkept up with software technology in the area of compiler and C language
  52. Xstandards.  However, a few do work.  I have not yet tested a make setup
  53. Xwith traditional and antique C compilers so I don't know what steps are
  54. Xbest.  Start from the g*.mf makefiles and change the commands internally
  55. Xas appropriate for your system.  Sorry about this not being easy.  These
  56. Xare among the problems that inspired standards like ANSI Standard C.
  57. X
  58. XGood luck!
  59. X------------------------------------------------------------------------
  60. XFor MS-DOS with Borland C++ 3.1 (or maybe some other versions):
  61. X
  62. XThe command "bmake" will do all the compiling for you.  You will need
  63. Xto edit and change the "bmake.bat" file to select a preferred memory
  64. Xmodel.  Or you may compile all the C/H/L/M/S models using "bmakeall".
  65. X
  66. XYou also have the commands "bremake", "bclean", and "bvirgin".
  67. X------------------------------------------------------------------------
  68. XFor MS-DOS with MicroSoft C 6.00 (or maybe some other versions):
  69. X
  70. XThe command "mmake" will do all the compiling for you.  You will need
  71. Xto edit and change the "mmake.bat" file to select a preferred memory
  72. Xmodel.  Or you may compile all the C/H/L/M/S models using "mmakeall".
  73. X
  74. XYou also have the commands "mremake", "mclean", and "mvirgin".
  75. X------------------------------------------------------------------------
  76. XAlso compiled are a set of test programs.  You can run the tests by
  77. Xdoing the command "test".  The first test verifies bit portability
  78. Xby reading in a supplied bit stream file called "test.bit" and comparing
  79. Xit to a random number sequence originally used to create the file.  The
  80. Xsecond test uses the various functions and macros to first write a file
  81. Xand then to read it back in.  A random number sequences controls the data
  82. Xbeing processed.  The third test writes and reads data using only the
  83. Xone bit macros for speed checking.  There is no actual timing included;
  84. Xit is just a demonstration.  If you want to time the performance, you
  85. Xwould need to deal with the particulars of you system.  For instance
  86. Xtiming results will vary greatly on multi-user timesharing systems.
  87. X------------------------------------------------------------------------
  88. XI would appreciate feedback on problems getting this library to compile,
  89. Xas well as problems using it.  Specific details are of course best and
  90. Xare likely the only things I will be able to deal with.  I can be reached
  91. Xby E-mail through Internet at pdh@netcom.com (CompuServe users will need
  92. Xto use the Internet mail gateway).
  93. X------------------------------------------------------------------------
  94. END_OF_FILE
  95.   if test 3430 -ne `wc -c <'bitio104/INSTALL'`; then
  96.     echo shar: \"'bitio104/INSTALL'\" unpacked with wrong size!
  97.   fi
  98.   # end of 'bitio104/INSTALL'
  99. fi
  100. if test -f 'bitio104/README' -a "${1}" != "-c" ; then 
  101.   echo shar: Will not clobber existing file \"'bitio104/README'\"
  102. else
  103.   echo shar: Extracting \"'bitio104/README'\" \(2465 characters\)
  104.   sed "s/^X//" >'bitio104/README' <<'END_OF_FILE'
  105. XVersion 1.04 of BITIO
  106. X
  107. XAuthor:        Philip D. Howard
  108. XEmail:        pdh@netcom.com
  109. X
  110. XBITIO is a function library package that implements a bit stream on top
  111. Xof a byte stream (8 bits per byte).  This bit stream is designed to be
  112. Xexchangeable between different platforms and retain the same bit order
  113. Xregardless of the endianness of the platforms.
  114. X
  115. XC programs may read and write 0 to 32 bits or more in each function
  116. Xcall.  Special functions and macros are implemented for doing exactly
  117. Xone bit at a time with less overhead.  The variable length functions
  118. Xcome in versions that pass the data justified on the low order end of
  119. Xthe unsigned long value, or on the high order end of the unsigned long
  120. Xvalue.  The single bit functions always use the low order end (i.e. have
  121. Xvalues 0 or 1).  Consistency is maintained through the use of all
  122. Xfunctions and macros executed in any sequence.
  123. X
  124. XFor UNIX platforms, I have tested this program with the GNU C Compiler.
  125. XThe makefiles are provided with this assumption.
  126. X
  127. XFor the MS-DOS platform, special makefiles are provided for Borland C
  128. Xand MicroSoft C.  I have tested this package with Borland C++ 3.1 and
  129. XMicroSoft C 6.00a.  Special BAT files are provided to make BITIO on
  130. Xthese compilers:
  131. X
  132. XBCLEAN   or MCLEAN   make clean
  133. XBMAKE    or MMAKE    make the library and test programs
  134. XBMAKEALL or MMAKEALL make all memory models (CHLMS) of the library
  135. XBREMAKE  or MREMAKE  make clean and make
  136. XBVIRGIN  or MVIRGIN  make clean and virgin (delete .EXE and .LIB files)
  137. X
  138. XUnlike versions prior to 1.02, this version includes its own random
  139. Xnumber generator for the test programs which is designed to produce
  140. Xthe same random sequence on any platform (this has not been quite as
  141. Xthoroughly tested as BITIO itself since some platforms were tested
  142. Xonly on previous versions).
  143. X
  144. XThree tests are performed.
  145. X
  146. XTest 1 compares a random sequence against a distributed random data
  147. Xfile (not the same in versions prior to 1.02) to ensure that
  148. Xportability works.
  149. X
  150. XTest 2 writes random data and reads it back in to compare in order to
  151. Xverify that the various operations are working consistently.  This test
  152. X(and test 1) uses a mixture of the function calls to write and read the
  153. Xdata, including the macros.  Alternative tests may be configured in the
  154. Xfile TESTIO.H.
  155. X
  156. XTest 3 tests the macros BIT1PUT and BIT1GET for speed.  This is only a
  157. Xdemostration test.  If you need actual timings, you will need to add
  158. Xthe capability to capture it in or around these programs.
  159. END_OF_FILE
  160.   if test 2465 -ne `wc -c <'bitio104/README'`; then
  161.     echo shar: \"'bitio104/README'\" unpacked with wrong size!
  162.   fi
  163.   # end of 'bitio104/README'
  164. fi
  165. if test -f 'bitio104/bit1get.c' -a "${1}" != "-c" ; then 
  166.   echo shar: Will not clobber existing file \"'bitio104/bit1get.c'\"
  167. else
  168.   echo shar: Extracting \"'bitio104/bit1get.c'\" \(2169 characters\)
  169.   sed "s/^X//" >'bitio104/bit1get.c' <<'END_OF_FILE'
  170. X/***********************************************************************\
  171. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  172. X|                                    |
  173. X|   This library is free software; you may redistribute it and/or    |
  174. X|   modify it under the terms of the GNU Library General Public        |
  175. X|   License as published by the Free Software Foundation; either    |
  176. X|   version 2 of the license, or (at your option) any later version.    |
  177. X|                                    |
  178. X|   This library is distributed in the hope that it will be useful,    |
  179. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  180. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  181. X|   GNU Library General Public License for more details.        |
  182. X|                                    |
  183. X|   You should have received a copy of the GNU Library General Public    |
  184. X|   License along with this library.  If not, write to the Free        |
  185. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  186. X|                                    |
  187. X|author:    Philip D. Howard (ka9wgn)                |
  188. X|email:        pdh@netcom.com                        |
  189. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  190. X|voice/fax:    217-384-4934                        |
  191. X\***********************************************************************/
  192. X/***********************************************************************\
  193. X|function:    bit1get                            |
  194. X|purpose:    to input one bit from a bit stream file            |
  195. X|                                    |
  196. X|argument:    (BITFILE *) bit stream file to be read from        |
  197. X|returns:    (int) data 0=0 1=1 -1=EOF -2=error            |
  198. X\***********************************************************************/
  199. X#include <bitio.h>
  200. X
  201. X#ifdef __STDC__
  202. X
  203. Xint bit1get(
  204. X    BITFILE *    bitstream
  205. X)
  206. X
  207. X#else
  208. X
  209. Xint bit1get( bitstream )
  210. X    BITFILE *    bitstream    ;
  211. X
  212. X#endif
  213. X
  214. X{
  215. X    if ( NULL == bitstream || 0 == ( BITIO_INPUT & bitstream->flags ) ) {
  216. X    return ( -2 );
  217. X    }
  218. X
  219. X    /*********************************\
  220. X    |if the buffer is empty, refill it|
  221. X    \*********************************/
  222. X    if ( 0 == bitstream->bits ) {
  223. X    bitstream->buf = getc( bitstream->cfile );
  224. X    if ( EOF == bitstream->buf ) return ( -1 );
  225. X    bitstream->bits = 8;
  226. X    }
  227. X
  228. X    /**************\
  229. X    |return one bit|
  230. X    \**************/
  231. X    return ( 1 & ( ( bitstream->buf ) >> ( --(bitstream->bits) ) ) );
  232. X
  233. X}
  234. END_OF_FILE
  235.   if test 2169 -ne `wc -c <'bitio104/bit1get.c'`; then
  236.     echo shar: \"'bitio104/bit1get.c'\" unpacked with wrong size!
  237.   fi
  238.   # end of 'bitio104/bit1get.c'
  239. fi
  240. if test -f 'bitio104/bit1put.c' -a "${1}" != "-c" ; then 
  241.   echo shar: Will not clobber existing file \"'bitio104/bit1put.c'\"
  242. else
  243.   echo shar: Extracting \"'bitio104/bit1put.c'\" \(2638 characters\)
  244.   sed "s/^X//" >'bitio104/bit1put.c' <<'END_OF_FILE'
  245. X/***********************************************************************\
  246. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  247. X|                                    |
  248. X|   This library is free software; you may redistribute it and/or    |
  249. X|   modify it under the terms of the GNU Library General Public        |
  250. X|   License as published by the Free Software Foundation; either    |
  251. X|   version 2 of the license, or (at your option) any later version.    |
  252. X|                                    |
  253. X|   This library is distributed in the hope that it will be useful,    |
  254. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  255. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  256. X|   GNU Library General Public License for more details.        |
  257. X|                                    |
  258. X|   You should have received a copy of the GNU Library General Public    |
  259. X|   License along with this library.  If not, write to the Free        |
  260. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  261. X|                                    |
  262. X|author:    Philip D. Howard (ka9wgn)                |
  263. X|email:        pdh@netcom.com                        |
  264. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  265. X|voice/fax:    217-384-4934                        |
  266. X\***********************************************************************/
  267. X/***********************************************************************\
  268. X|function:    bit1put                            |
  269. X|purpose:    to output one bit to a bit stream file            |
  270. X|                                    |
  271. X|arguments:    1 (BITFILE *) bit stream file to be written to        |
  272. X|        2 (int) one bit data (0 or 1) to be written        |
  273. X|returns:    (int) ==EOF: error  !=EOF: ok                |
  274. X\***********************************************************************/
  275. X#include <bitio.h>
  276. X
  277. X#ifdef __STDC__
  278. X
  279. Xint bit1put(
  280. X    BITFILE *    bitstream    ,
  281. X    int        data
  282. X)
  283. X
  284. X#else
  285. X
  286. Xint bit1put( bitstream , data )
  287. X    BITFILE *    bitstream    ;
  288. X    int        data        ;
  289. X
  290. X#endif
  291. X
  292. X{
  293. X    if ( NULL == bitstream ) return ( EOF );
  294. X    if ( 0 == ( BITIO_OUTPUT & bitstream->flags ) ) return ( EOF );
  295. X
  296. X    /**********************************************************\
  297. X    |if the buffer is full, flush it before we try to add to it|
  298. X    \**********************************************************/
  299. X    if ( bitstream->bits == 8 ) {
  300. X    putc( bitstream->buf , bitstream->cfile );
  301. X    bitstream->bits = 0;
  302. X    bitstream->buf = 0;
  303. X    }
  304. X
  305. X    /**************************\
  306. X    |add one bit to byte buffer|
  307. X    \**************************/
  308. X    ++(bitstream->bits);
  309. X    bitstream->buf |= ( ( 1 & data ) << 8 ) >> bitstream->bits;
  310. X
  311. X    /********************************\
  312. X    |if we filled up buffer, flush it|
  313. X    \********************************/
  314. X    if ( bitstream->bits == 8 ) {
  315. X    putc( bitstream->buf , bitstream->cfile );
  316. X    bitstream->bits = 0;
  317. X    bitstream->buf = 0;
  318. X    }
  319. X
  320. X    return ( 0 );
  321. X}
  322. END_OF_FILE
  323.   if test 2638 -ne `wc -c <'bitio104/bit1put.c'`; then
  324.     echo shar: \"'bitio104/bit1put.c'\" unpacked with wrong size!
  325.   fi
  326.   # end of 'bitio104/bit1put.c'
  327. fi
  328. if test -f 'bitio104/bitclose.c' -a "${1}" != "-c" ; then 
  329.   echo shar: Will not clobber existing file \"'bitio104/bitclose.c'\"
  330. else
  331.   echo shar: Extracting \"'bitio104/bitclose.c'\" \(2093 characters\)
  332.   sed "s/^X//" >'bitio104/bitclose.c' <<'END_OF_FILE'
  333. X/***********************************************************************\
  334. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  335. X|                                    |
  336. X|   This library is free software; you may redistribute it and/or    |
  337. X|   modify it under the terms of the GNU Library General Public        |
  338. X|   License as published by the Free Software Foundation; either    |
  339. X|   version 2 of the license, or (at your option) any later version.    |
  340. X|                                    |
  341. X|   This library is distributed in the hope that it will be useful,    |
  342. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  343. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  344. X|   GNU Library General Public License for more details.        |
  345. X|                                    |
  346. X|   You should have received a copy of the GNU Library General Public    |
  347. X|   License along with this library.  If not, write to the Free        |
  348. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  349. X|                                    |
  350. X|author:    Philip D. Howard (ka9wgn)                |
  351. X|email:        pdh@netcom.com                        |
  352. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  353. X|voice/fax:    217-384-4934                        |
  354. X\***********************************************************************/
  355. X/***********************************************************************\
  356. X|function:    bitclose                        |
  357. X|purpose:    to close a bit stream                    |
  358. X|                                    |
  359. X|note:        if the bit stream was opened with bituse() the file    |
  360. X|        originally used remains open and usable for regular i/o |
  361. X|                                    |
  362. X|note:        if the bit stream was opened with bitopen() the file    |
  363. X|        it uses is fully closed                    |
  364. X|                                    |
  365. X|argument:    (BITFILE *) bit stream to be closed            |
  366. X|returns:    (int) irrelevant                    |
  367. X\***********************************************************************/
  368. X#include <bitio.h>
  369. X
  370. X#ifdef __STDC__
  371. X
  372. Xint bitclose(
  373. X    BITFILE *    bitstream
  374. X)
  375. X
  376. X#else
  377. X
  378. Xint bitclose( bitstream )
  379. X    BITFILE *    bitstream    ;
  380. X
  381. X#endif
  382. X
  383. X{
  384. X    if ( NULL == bitstream ) {
  385. X    return ( -1 );
  386. X    }
  387. X
  388. X    if ( 0 == ( BITIO_USEFILE & bitstream->flags )
  389. X      && NULL != bitstream->cfile ) {
  390. X    fclose( bitstream->cfile );
  391. X    }
  392. X
  393. X    free( bitstream );
  394. X
  395. X    return ( 0 );
  396. X}
  397. END_OF_FILE
  398.   if test 2093 -ne `wc -c <'bitio104/bitclose.c'`; then
  399.     echo shar: \"'bitio104/bitclose.c'\" unpacked with wrong size!
  400.   fi
  401.   # end of 'bitio104/bitclose.c'
  402. fi
  403. if test -f 'bitio104/bitflush.c' -a "${1}" != "-c" ; then 
  404.   echo shar: Will not clobber existing file \"'bitio104/bitflush.c'\"
  405. else
  406.   echo shar: Extracting \"'bitio104/bitflush.c'\" \(1990 characters\)
  407.   sed "s/^X//" >'bitio104/bitflush.c' <<'END_OF_FILE'
  408. X/***********************************************************************\
  409. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  410. X|                                    |
  411. X|   This library is free software; you may redistribute it and/or    |
  412. X|   modify it under the terms of the GNU Library General Public        |
  413. X|   License as published by the Free Software Foundation; either    |
  414. X|   version 2 of the license, or (at your option) any later version.    |
  415. X|                                    |
  416. X|   This library is distributed in the hope that it will be useful,    |
  417. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  418. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  419. X|   GNU Library General Public License for more details.        |
  420. X|                                    |
  421. X|   You should have received a copy of the GNU Library General Public    |
  422. X|   License along with this library.  If not, write to the Free        |
  423. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  424. X|                                    |
  425. X|author:    Philip D. Howard (ka9wgn)                |
  426. X|email:        pdh@netcom.com                        |
  427. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  428. X|voice/fax:    217-384-4934                        |
  429. X\***********************************************************************/
  430. X/***********************************************************************\
  431. X|function:    bitflush                        |
  432. X|purpose:    to flush a bit stream, padding the last byte with 0s    |
  433. X|        this will also flush the associated character file    |
  434. X|                                    |
  435. X|argument:    (BITFILE *) bit stream to be flushed            |
  436. X|returns:    (int) irrelevant                    |
  437. X\***********************************************************************/
  438. X#include <bitio.h>
  439. X
  440. X#ifdef __STDC__
  441. X
  442. Xint bitflush(
  443. X    BITFILE *    bitstream
  444. X)
  445. X
  446. X#else
  447. X
  448. Xint bitflush( bitstream )
  449. X    BITFILE *    bitstream    ;
  450. X
  451. X#endif
  452. X
  453. X{
  454. X    if ( NULL == bitstream || 0 == ( BITIO_OUTPUT & bitstream->flags ) ) {
  455. X    return ( EOF );
  456. X    }
  457. X
  458. X    if ( bitstream->bits > 0 ) {
  459. X    putc( bitstream->buf , bitstream->cfile );
  460. X    bitstream->bits = 0;
  461. X    bitstream->buf = 0;
  462. X    }
  463. X
  464. X    fflush( bitstream->cfile );
  465. X
  466. X    return ( 0 );
  467. X}
  468. END_OF_FILE
  469.   if test 1990 -ne `wc -c <'bitio104/bitflush.c'`; then
  470.     echo shar: \"'bitio104/bitflush.c'\" unpacked with wrong size!
  471.   fi
  472.   # end of 'bitio104/bitflush.c'
  473. fi
  474. if test -f 'bitio104/bithget.c' -a "${1}" != "-c" ; then 
  475.   echo shar: Will not clobber existing file \"'bitio104/bithget.c'\"
  476. else
  477.   echo shar: Extracting \"'bitio104/bithget.c'\" \(1989 characters\)
  478.   sed "s/^X//" >'bitio104/bithget.c' <<'END_OF_FILE'
  479. X/***********************************************************************\
  480. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  481. X|                                    |
  482. X|   This library is free software; you may redistribute it and/or    |
  483. X|   modify it under the terms of the GNU Library General Public        |
  484. X|   License as published by the Free Software Foundation; either    |
  485. X|   version 2 of the license, or (at your option) any later version.    |
  486. X|                                    |
  487. X|   This library is distributed in the hope that it will be useful,    |
  488. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  489. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  490. X|   GNU Library General Public License for more details.        |
  491. X|                                    |
  492. X|   You should have received a copy of the GNU Library General Public    |
  493. X|   License along with this library.  If not, write to the Free        |
  494. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  495. X|                                    |
  496. X|author:    Philip D. Howard (ka9wgn)                |
  497. X|email:        pdh@netcom.com                        |
  498. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  499. X|voice/fax:    217-384-4934                        |
  500. X\***********************************************************************/
  501. X/***********************************************************************\
  502. X|function:    bithget                            |
  503. X|purpose:    to input bit data from a bit stream file        |
  504. X|        data is high order justified                |
  505. X|                                    |
  506. X|arguments:    1 (BITFILE *) bit stream file to be read from        |
  507. X|        2 (uint *) pointer to where actual count goes        |
  508. X|        3 (uint) count of bits to get                |
  509. X|returns:    (ulong) data from bit stream file            |
  510. X|                                    |
  511. X|note:        returned count is 0 for EOF, -1 for error        |
  512. X\***********************************************************************/
  513. X#include <bitio.h>
  514. X
  515. X#ifdef __STDC__
  516. X
  517. Xulong bithget(
  518. X    BITFILE *    bitstream    ,
  519. X    uint *        countptr    ,
  520. X    uint        count
  521. X)
  522. X
  523. X#else
  524. X
  525. Xulong bithget( bitstream , countptr , count )
  526. X    BITFILE *    bitstream    ;
  527. X    uint *        countptr    ;
  528. X    uint        count        ;
  529. X
  530. X#endif
  531. X
  532. X#define BITIO_HIGH
  533. X#include <bitget.h>
  534. END_OF_FILE
  535.   if test 1989 -ne `wc -c <'bitio104/bithget.c'`; then
  536.     echo shar: \"'bitio104/bithget.c'\" unpacked with wrong size!
  537.   fi
  538.   # end of 'bitio104/bithget.c'
  539. fi
  540. if test -f 'bitio104/bitio.3' -a "${1}" != "-c" ; then 
  541.   echo shar: Will not clobber existing file \"'bitio104/bitio.3'\"
  542. else
  543.   echo shar: Extracting \"'bitio104/bitio.3'\" \(3985 characters\)
  544.   sed "s/^X//" >'bitio104/bitio.3' <<'END_OF_FILE'
  545. X
  546. X
  547. XBITIO(3)        BIT I/O FUNCTIONS        BITIO(3)
  548. X
  549. X
  550. XNAME
  551. X    bitopen, bituse, bitflush, bitclose,
  552. X    bit1get, bithget, bitlget, bit1put, bithput, bitlput
  553. X
  554. X    do bit level file I/O
  555. X
  556. X
  557. XSYNOPSIS
  558. X    #include <bitio.h>
  559. X
  560. X    BITFILE * bitopen(onst char *name, const char *mode);
  561. X
  562. X    BITFILE * bituse(FILE *charstream, const char *mode);
  563. X
  564. X    int bitflush(BITFILE *bitstream);
  565. X
  566. X    int bitclose(BITFILE *bitstream);
  567. X
  568. X    int bit1get(BITFILE *bitstream );
  569. X
  570. X    unsigned long bithget(BITFILE *bitstream, unsigned int *countptr,
  571. X    unsigned int count);
  572. X
  573. X    unsigned long bitlget(BITFILE *bitstream, unsigned int *countptr,
  574. X    unsigned int count);
  575. X
  576. X    int bit1put(BITFILE *bitstream, int data);
  577. X
  578. X    int bithput(BITFILE *bitstream, unsigned long data,
  579. X    unsigned int count);
  580. X
  581. X    int bitlput(BITFILE *bitstream, unsigned long data,
  582. X    unsigned int count);
  583. X
  584. X    BIT1GET(bitstream);
  585. X
  586. X    BIT1PUT(bitstream,data);
  587. X
  588. X
  589. XDESCRIPTION
  590. X    bitopen() opens a named file for read, write, or append and returns
  591. X    a pointer to the bit stream.
  592. X
  593. X    bituse() uses an already open character stream file as the medium
  594. X    for a new bit stream, the pointer of which is returned.
  595. X
  596. X    bitflush() pads a partial character with 0 bits then flushes the
  597. X    associated character stream.
  598. X
  599. X    bitclose() closes a bit stream, leaving the associated character
  600. X    stream file open if bituse() created the bitstream.     No padding is
  601. X    done and partial characters will be lost.  Do bitflush() before
  602. X    doing bitclose() if the final bits are definitely needed.
  603. X
  604. X    bit1get() gets a single bit from a bit stream.  BIT1GET() is also
  605. X    available in macro implementation.
  606. X
  607. X    bithget() gets a specified number of bits from a bit stream and
  608. X    returns them as a high order justified unsigned long.
  609. X
  610. X    bitlget() gets a specified number of bits from a bit stream and
  611. X    returns them as a low order justified unsigned long.
  612. X
  613. X    bit1put() puts a single bit to a bit stream.  BIT1PUT() is also
  614. X    available in macro implementation.
  615. X
  616. X    bithput() puts a specified number of bits, given as a high order
  617. X    justified unsigned long, to a bit stream.
  618. X
  619. X    bitlput() puts a specified number of bits, given as a low order
  620. X    justified unsigned long, to a bit stream.
  621. X
  622. X
  623. X    Bits are written in "high order first" regardless of byte ordering
  624. X    of platform/architecture.  This allows portability of bit files
  625. X    between machines with unlike byte ordering which causes problems
  626. X    in other circumstances.
  627. X
  628. X    The "1", "h", and "l" functions may be fully interleaved as needed
  629. X    by the calling program since the buffering state is managed in a
  630. X    consistent way.
  631. X
  632. X
  633. XSEE ALSO
  634. X    Standard I/O library.
  635. X
  636. X
  637. XDIAGNOSTICS
  638. X    bithget() and bitlget() set an unsigned int (pointed to be countptr)
  639. X    to the number of bits actually gotten at EOF.   All subsequent calls
  640. X    will set the return count to 0 indicating EOF.
  641. X
  642. X    bit1get() returns 0 or 1 for 1 bit of data, -1 for EOF, or -2 for error.
  643. X
  644. X    bitopen() and bituse() return a NULL pointer of an error occurs trying
  645. X    to create the bitstream.
  646. X
  647. X
  648. XBUGS
  649. X    bitclose() does not flush partial characters.  However this allows
  650. X    such a choice since bitflush() be used for force such a flush before
  651. X    doing a bitclose().
  652. X
  653. X    BIT1GET() and BIT1PUT() are implemented as macros and have certain
  654. X    side effects on arguments, including multiple evaluation.
  655. X
  656. X    Bits written by successful bit*put() functions may actually not be
  657. X    written when later errors occur due to bit buffering (and asscociated
  658. X    character file buffering).
  659. X
  660. X    Bits are not necessarily written in the order that may be "natural"
  661. X    for certain particular platforms or architectures.    They are instead
  662. X    written in a way that allows like programs on different platforms
  663. X    to be able to read the bits in exactly the same order originally
  664. X    written.
  665. X
  666. X    There are no bit level equivalents to ungetc(), fgetpos(),    fseek(),
  667. X    fsetpos(), ftell(), or rewind().
  668. X
  669. X
  670. XAUTHOR
  671. X    Philip D. Howard, pdh@netcom.com
  672. X
  673. X
  674. END_OF_FILE
  675.   if test 3985 -ne `wc -c <'bitio104/bitio.3'`; then
  676.     echo shar: \"'bitio104/bitio.3'\" unpacked with wrong size!
  677.   fi
  678.   # end of 'bitio104/bitio.3'
  679. fi
  680. if test -f 'bitio104/bitio.h' -a "${1}" != "-c" ; then 
  681.   echo shar: Will not clobber existing file \"'bitio104/bitio.h'\"
  682. else
  683.   echo shar: Extracting \"'bitio104/bitio.h'\" \(5672 characters\)
  684.   sed "s/^X//" >'bitio104/bitio.h' <<'END_OF_FILE'
  685. X/***********************************************************************\
  686. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  687. X|                                    |
  688. X|   This library is free software; you may redistribute it and/or    |
  689. X|   modify it under the terms of the GNU Library General Public        |
  690. X|   License as published by the Free Software Foundation; either    |
  691. X|   version 2 of the license, or (at your option) any later version.    |
  692. X|                                    |
  693. X|   This library is distributed in the hope that it will be useful,    |
  694. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  695. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  696. X|   GNU Library General Public License for more details.        |
  697. X|                                    |
  698. X|   You should have received a copy of the GNU Library General Public    |
  699. X|   License along with this library.  If not, write to the Free        |
  700. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  701. X|                                    |
  702. X|author:    Philip D. Howard (ka9wgn)                |
  703. X|email:        pdh@netcom.com                        |
  704. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  705. X|voice/fax:    217-384-4934                        |
  706. X\***********************************************************************/
  707. X
  708. X/***********************************************************************\
  709. X|header:    bitio.h                            |
  710. X|purpose:    definitions and declarations for the bitio library    |
  711. X\***********************************************************************/
  712. X
  713. X/***********************************************************************\
  714. X|configure the compilation                        |
  715. X\***********************************************************************/
  716. X#define BITIO_CHECK_ERROR 1
  717. X
  718. X
  719. X/***********************************************************************\
  720. X|do library includes                            |
  721. X\***********************************************************************/
  722. X#include <limits.h>
  723. X#include <stdio.h>
  724. X#include <stdlib.h>
  725. X#include <errno.h>
  726. X
  727. X
  728. X/***********************************************************************\
  729. X|define the size of type long if not yet defined            |
  730. X\***********************************************************************/
  731. X#ifndef LONG_BIT
  732. X#define LONG_BIT ( CHAR_BIT * sizeof ( long ) )
  733. X#endif
  734. X
  735. X
  736. X/***********************************************************************\
  737. X|define abbreviated types                        |
  738. X\***********************************************************************/
  739. Xtypedef unsigned long ulong;
  740. Xtypedef unsigned int uint;
  741. X
  742. X
  743. X/***********************************************************************\
  744. X|define data structs                            |
  745. X\***********************************************************************/
  746. Xstruct BITFILE {
  747. X    FILE *        cfile    ;
  748. X    uint        flags    ;
  749. X    uint        bits    ;
  750. X    int            buf    ;
  751. X};
  752. X
  753. Xtypedef struct BITFILE BITFILE;
  754. X
  755. X
  756. X/***********************************************************************\
  757. X|define flags                                |
  758. X\***********************************************************************/
  759. X#define BITIO_INPUT    1    /* bit stream is input */
  760. X#define BITIO_OUTPUT    2    /* bit stream is output */
  761. X#define BITIO_USEFILE    4    /* bit stream created by bituse() */
  762. X
  763. X
  764. X/***********************************************************************\
  765. X|define macros                                |
  766. X\***********************************************************************/
  767. X
  768. X/***********************************************************************\
  769. X|macro:        BIT1GET                            |
  770. X|purpose:    to input one bit from a bit stream file            |
  771. X|                                    |
  772. X|argument:    (BITFILE *) bit stream file to be read from        |
  773. X|returns:    (int) data 0=0 1=1 -1=EOF                |
  774. X\***********************************************************************/
  775. X#define BIT1GET(bs)                            \
  776. X(                                    \
  777. X    (                                    \
  778. X    0 == (bs)->bits                            \
  779. X    &&                                \
  780. X    (                                \
  781. X        (bs)->bits = 8                        \
  782. X        ,                                \
  783. X        EOF == ( (bs)->buf = getc( (bs)->cfile ) )            \
  784. X    )                                \
  785. X    )                                    \
  786. X    ?                                    \
  787. X    (                                    \
  788. X    (bs)->bits = 0                            \
  789. X    ,                                \
  790. X    -1                                \
  791. X    )                                    \
  792. X    :                                    \
  793. X    (                                    \
  794. X    1 & ( (uint) (bs)->buf >> ( --( (bs)->bits ) ) )    \
  795. X    )                                    \
  796. X)
  797. X
  798. X
  799. X/***********************************************************************\
  800. X|macro:        BIT1PUT                            |
  801. X|purpose:    to output one bit to a bit stream file            |
  802. X|                                    |
  803. X|arguments:    1 (BITFILE *) bit stream file to be written to        |
  804. X|        2 (int) one bit data (0 or 1) to be written        |
  805. X|returns:    0                            |
  806. X\***********************************************************************/
  807. X#define BIT1PUT(bs,d)                            \
  808. X(                                    \
  809. X    (bs)->buf |= ( ( 1 & (d) ) << 8 ) >> ( ++( (bs)->bits ) )        \
  810. X    ,                                    \
  811. X    (                                    \
  812. X    ( 8 == (bs)->bits )                        \
  813. X    ?                                \
  814. X    (                                \
  815. X        putc( (bs)->buf , (bs)->cfile )                \
  816. X        ,                                \
  817. X        (bs)->buf = (bs)->bits = 0                    \
  818. X    )                                \
  819. X    :                                \
  820. X    0                                \
  821. X    )                                    \
  822. X)
  823. X
  824. X
  825. X/***********************************************************************\
  826. X|declare functions                            |
  827. X\***********************************************************************/
  828. Xint bit1get(
  829. X#ifdef __STDC__
  830. X    BITFILE *    bitstream
  831. X#endif
  832. X);
  833. X
  834. Xint bit1put(
  835. X#ifdef __STDC__
  836. X    BITFILE *    bitstream    ,
  837. X    int        data
  838. X#endif
  839. X);
  840. X
  841. Xint bitclose(
  842. X#ifdef __STDC__
  843. X    BITFILE *    bitstream
  844. X#endif
  845. X);
  846. X
  847. Xint bitflush(
  848. X#ifdef __STDC__
  849. X    BITFILE *    bitstream
  850. X#endif
  851. X);
  852. X
  853. Xulong bithget(
  854. X#ifdef __STDC__
  855. X    BITFILE *    bitstream    ,
  856. X    uint *        countptr    ,
  857. X    uint        count
  858. X#endif
  859. X);
  860. X
  861. Xint bithput(
  862. X#ifdef __STDC__
  863. X    BITFILE *    bitstream    ,
  864. X    ulong        data        ,
  865. X    uint        count
  866. X#endif
  867. X);
  868. X
  869. Xulong bitlget(
  870. X#ifdef __STDC__
  871. X    BITFILE *    bitstream    ,
  872. X    uint *        countptr    ,
  873. X    uint        count
  874. X#endif
  875. X);
  876. X
  877. Xint bitlput(
  878. X#ifdef __STDC__
  879. X    BITFILE *    bitstream    ,
  880. X    ulong        data        ,
  881. X    uint        count
  882. X#endif
  883. X);
  884. X
  885. XBITFILE * bitopen(
  886. X#ifdef __STDC__
  887. X    const char *    name        ,
  888. X    const char *    mode
  889. X#endif
  890. X);
  891. X
  892. XBITFILE * bituse(
  893. X#ifdef __STDC__
  894. X    FILE *        charstream    ,
  895. X    const char *    mode
  896. X#endif
  897. X);
  898. END_OF_FILE
  899.   if test 5672 -ne `wc -c <'bitio104/bitio.h'`; then
  900.     echo shar: \"'bitio104/bitio.h'\" unpacked with wrong size!
  901.   fi
  902.   # end of 'bitio104/bitio.h'
  903. fi
  904. if test -f 'bitio104/bitopen.c' -a "${1}" != "-c" ; then 
  905.   echo shar: Will not clobber existing file \"'bitio104/bitopen.c'\"
  906. else
  907.   echo shar: Extracting \"'bitio104/bitopen.c'\" \(2744 characters\)
  908.   sed "s/^X//" >'bitio104/bitopen.c' <<'END_OF_FILE'
  909. X/***********************************************************************\
  910. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  911. X|                                    |
  912. X|   This library is free software; you may redistribute it and/or    |
  913. X|   modify it under the terms of the GNU Library General Public        |
  914. X|   License as published by the Free Software Foundation; either    |
  915. X|   version 2 of the license, or (at your option) any later version.    |
  916. X|                                    |
  917. X|   This library is distributed in the hope that it will be useful,    |
  918. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  919. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  920. X|   GNU Library General Public License for more details.        |
  921. X|                                    |
  922. X|   You should have received a copy of the GNU Library General Public    |
  923. X|   License along with this library.  If not, write to the Free        |
  924. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  925. X|                                    |
  926. X|author:    Philip D. Howard (ka9wgn)                |
  927. X|email:        pdh@netcom.com                        |
  928. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  929. X|voice/fax:    217-384-4934                        |
  930. X\***********************************************************************/
  931. X/***********************************************************************\
  932. X|function:    bitopen                            |
  933. X|purpose:    to open a bit stream file                |
  934. X|                                    |
  935. X|note:        when the bit stream is closed by bitclose() the        |
  936. X|        stream file will also be closed                |
  937. X|                                    |
  938. X|arguments:    1 (char *) name of file to be opened            |
  939. X|        2 (char *) mode string                    |
  940. X|returns:    (BITFILE *) bit stream pointer                |
  941. X\***********************************************************************/
  942. X#include <bitio.h>
  943. X
  944. X#ifdef __STDC__
  945. X
  946. XBITFILE * bitopen(
  947. X    const char *    name        ,
  948. X    const char *    mode
  949. X)
  950. X
  951. X#else
  952. X
  953. XBITFILE * bitopen( name , mode )
  954. X    const char *    name        ;
  955. X    const char *    mode        ;
  956. X
  957. X#endif
  958. X
  959. X{
  960. X    BITFILE *        bitstream    ;
  961. X    FILE *        charstream    ;
  962. X    char *        bmode        ;
  963. X    uint        flags        ;
  964. X
  965. X    if ( NULL == name || '\0' == *name ) return ( NULL );
  966. X
  967. X    if ( '+' == mode[1] || '+' == mode[2] ) return ( NULL );
  968. X
  969. X    if ( 'r' == mode[0] ) {
  970. X    flags = BITIO_INPUT;
  971. X    bmode = "rb";
  972. X    } else if ( 'w' == mode[0] ) {
  973. X    flags = BITIO_OUTPUT;
  974. X    bmode = "wb";
  975. X    } else if ( 'a' == mode[0] ) {
  976. X    flags = BITIO_OUTPUT;
  977. X    bmode = "ab";
  978. X    } else {
  979. X    return ( NULL );
  980. X    }
  981. X
  982. X    bitstream = (BITFILE *) malloc( sizeof ( BITFILE ) );
  983. X    if ( NULL == bitstream ) return ( NULL );
  984. X
  985. X    charstream = fopen( name , bmode );
  986. X    if ( NULL == charstream ) {
  987. X    free( bitstream );
  988. X    return ( NULL );
  989. X    }
  990. X
  991. X#ifdef __MSDOS__
  992. X    setvbuf( charstream , NULL , _IOFBF , 4096 );
  993. X#endif
  994. X
  995. X    bitstream->flags = flags;
  996. X    bitstream->cfile = charstream;
  997. X    bitstream->bits = 0;
  998. X    bitstream->buf = 0;
  999. X
  1000. X    return ( bitstream );
  1001. X}
  1002. END_OF_FILE
  1003.   if test 2744 -ne `wc -c <'bitio104/bitopen.c'`; then
  1004.     echo shar: \"'bitio104/bitopen.c'\" unpacked with wrong size!
  1005.   fi
  1006.   # end of 'bitio104/bitopen.c'
  1007. fi
  1008. if test -f 'bitio104/bitput.h' -a "${1}" != "-c" ; then 
  1009.   echo shar: Will not clobber existing file \"'bitio104/bitput.h'\"
  1010. else
  1011.   echo shar: Extracting \"'bitio104/bitput.h'\" \(4193 characters\)
  1012.   sed "s/^X//" >'bitio104/bitput.h' <<'END_OF_FILE'
  1013. X/***********************************************************************\
  1014. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1015. X|                                    |
  1016. X|   This library is free software; you may redistribute it and/or    |
  1017. X|   modify it under the terms of the GNU Library General Public        |
  1018. X|   License as published by the Free Software Foundation; either    |
  1019. X|   version 2 of the license, or (at your option) any later version.    |
  1020. X|                                    |
  1021. X|   This library is distributed in the hope that it will be useful,    |
  1022. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1023. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1024. X|   GNU Library General Public License for more details.        |
  1025. X|                                    |
  1026. X|   You should have received a copy of the GNU Library General Public    |
  1027. X|   License along with this library.  If not, write to the Free        |
  1028. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1029. X|                                    |
  1030. X|author:    Philip D. Howard (ka9wgn)                |
  1031. X|email:        pdh@netcom.com                        |
  1032. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1033. X|voice/fax:    217-384-4934                        |
  1034. X\***********************************************************************/
  1035. X/***********************************************************************\
  1036. X|header:    bitput                            |
  1037. X|purpose:    to output bit data to a bit stream file            |
  1038. X|        generate code for bithget.c or bitlget.c        |
  1039. X|                                    |
  1040. X|arguments:    1 (BITFILE *) bit stream file to be written to        |
  1041. X|        2 (ulong) bit data to be written            |
  1042. X|        3 (uint) count of bits to be written            |
  1043. X|returns:    (int) ==EOF: error  !=EOF: ok                |
  1044. X\***********************************************************************/
  1045. X{
  1046. X    /********************************************\
  1047. X    |this is an array, indexed by n, of one byte |
  1048. X    |masks with n bits on from the high order end|
  1049. X    \********************************************/
  1050. X    static unsigned char mask[8] = {0,128,192,224,240,248,252,254};
  1051. X
  1052. X    /*************************************************\
  1053. X    |if the count is zero, then there is nothing to do|
  1054. X    \*************************************************/
  1055. X    if ( count == 0 ) return ( 0 );
  1056. X
  1057. X#ifdef BITIO_CHECK_ERROR
  1058. X    /***********************************************************\
  1059. X    |if the bit stream file pointer is NULL then return an error|
  1060. X    \***********************************************************/
  1061. X    if ( NULL == bitstream ) return ( EOF );
  1062. X
  1063. X    /******************************************************************\
  1064. X    |if the bit stream file is not open for output then return an error|
  1065. X    \******************************************************************/
  1066. X    if ( 0 == ( BITIO_OUTPUT & bitstream->flags ) ) return ( EOF );
  1067. X#endif
  1068. X
  1069. X#ifdef BITIO_LOW
  1070. X    /*************************************\
  1071. X    |put data into the high order position|
  1072. X    \*************************************/
  1073. X    data <<= LONG_BIT - count;
  1074. X#endif
  1075. X
  1076. X    /******************************\
  1077. X    |try to fill up the byte buffer|
  1078. X    \******************************/
  1079. X    bitstream->buf |= (uint) ( data >> ( LONG_BIT - 8 ) ) >> bitstream->bits;
  1080. X
  1081. X    /*****************************************\
  1082. X    |if it is not full yet, mask it and return|
  1083. X    \*****************************************/
  1084. X    if ( ( bitstream->bits + count ) < 8 ) {
  1085. X    bitstream->buf &= (uint) mask[ bitstream->bits += count ];
  1086. X    return ( 0 );
  1087. X    }
  1088. X
  1089. X    /************************************\
  1090. X    |output the full byte from the buffer|
  1091. X    \************************************/
  1092. X    putc( bitstream->buf , bitstream->cfile );
  1093. X
  1094. X    /**************************\
  1095. X    |realign the remaining data|
  1096. X    \**************************/
  1097. X    data <<= ( 8 - bitstream->bits );
  1098. X    count -= ( 8 - bitstream->bits );
  1099. X
  1100. X    /**************************\
  1101. X    |output all the whole bytes|
  1102. X    \**************************/
  1103. X    while ( count >= 8 ) {
  1104. X    putc( (uint) ( data >> ( LONG_BIT - 8 ) ), bitstream->cfile );
  1105. X    data <<= 8;
  1106. X    count -= 8;
  1107. X    }
  1108. X
  1109. X    /*****************************************\
  1110. X    |put any remaining portion into the buffer|
  1111. X    \*****************************************/
  1112. X    bitstream->bits = count;
  1113. X    bitstream->buf = (uint) ( ( data >> ( LONG_BIT - 8 ) ) & mask[ count ] );
  1114. X
  1115. X    return ( 0 );
  1116. X}
  1117. END_OF_FILE
  1118.   if test 4193 -ne `wc -c <'bitio104/bitput.h'`; then
  1119.     echo shar: \"'bitio104/bitput.h'\" unpacked with wrong size!
  1120.   fi
  1121.   # end of 'bitio104/bitput.h'
  1122. fi
  1123. if test -f 'bitio104/bituse.c' -a "${1}" != "-c" ; then 
  1124.   echo shar: Will not clobber existing file \"'bitio104/bituse.c'\"
  1125. else
  1126.   echo shar: Extracting \"'bitio104/bituse.c'\" \(2544 characters\)
  1127.   sed "s/^X//" >'bitio104/bituse.c' <<'END_OF_FILE'
  1128. X/***********************************************************************\
  1129. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1130. X|                                    |
  1131. X|   This library is free software; you may redistribute it and/or    |
  1132. X|   modify it under the terms of the GNU Library General Public        |
  1133. X|   License as published by the Free Software Foundation; either    |
  1134. X|   version 2 of the license, or (at your option) any later version.    |
  1135. X|                                    |
  1136. X|   This library is distributed in the hope that it will be useful,    |
  1137. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1138. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1139. X|   GNU Library General Public License for more details.        |
  1140. X|                                    |
  1141. X|   You should have received a copy of the GNU Library General Public    |
  1142. X|   License along with this library.  If not, write to the Free        |
  1143. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1144. X|                                    |
  1145. X|author:    Philip D. Howard (ka9wgn)                |
  1146. X|email:        pdh@netcom.com                        |
  1147. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1148. X|voice/fax:    217-384-4934                        |
  1149. X\***********************************************************************/
  1150. X/***********************************************************************\
  1151. X|function:    bituse                            |
  1152. X|purpose:    to use an open character stream file for bit stream i/o |
  1153. X|                                    |
  1154. X|note:        when the bit stream is closed by bitclose() the used    |
  1155. X|        stream file remains open and usable for regular i/o    |
  1156. X|                                    |
  1157. X|note:        the character stream should be opened for binary i/o    |
  1158. X|        this is generally not relevant on UNIX platforms    |
  1159. X|                                    |
  1160. X|arguments:    1 (FILE *) character stream file to be used        |
  1161. X|        2 (char *) mode string "r" or "w"            |
  1162. X|returns:    (BITFILE *) bit stream pointer                |
  1163. X\***********************************************************************/
  1164. X#include <bitio.h>
  1165. X
  1166. X#ifdef __STDC__
  1167. X
  1168. XBITFILE * bituse(
  1169. X    FILE *        charstream    ,
  1170. X    const char *    mode
  1171. X)
  1172. X
  1173. X#else
  1174. X
  1175. XBITFILE * bituse( charstream , mode )
  1176. X    FILE *        charstream    ;
  1177. X    char *        mode        ;
  1178. X
  1179. X#endif
  1180. X
  1181. X{
  1182. X    BITFILE *        bitstream        ;
  1183. X    uint        flags        ;
  1184. X
  1185. X    if ( NULL == charstream ) return ( NULL );
  1186. X
  1187. X    if ( 'r' == *mode ) flags = BITIO_INPUT;
  1188. X    else if ( 'w' == *mode || 'a' == *mode ) flags = BITIO_OUTPUT;
  1189. X
  1190. X    if ( 0 == flags ) return ( NULL );
  1191. X
  1192. X    bitstream = (BITFILE *) malloc( sizeof ( BITFILE ) );
  1193. X    if ( NULL == bitstream ) return ( NULL );
  1194. X
  1195. X    bitstream->flags = flags | BITIO_USEFILE;
  1196. X    bitstream->cfile = charstream;
  1197. X    bitstream->bits = 0;
  1198. X    bitstream->buf = 0;
  1199. X
  1200. X    return ( bitstream );
  1201. X}
  1202. END_OF_FILE
  1203.   if test 2544 -ne `wc -c <'bitio104/bituse.c'`; then
  1204.     echo shar: \"'bitio104/bituse.c'\" unpacked with wrong size!
  1205.   fi
  1206.   # end of 'bitio104/bituse.c'
  1207. fi
  1208. if test -f 'bitio104/rand.h' -a "${1}" != "-c" ; then 
  1209.   echo shar: Will not clobber existing file \"'bitio104/rand.h'\"
  1210. else
  1211.   echo shar: Extracting \"'bitio104/rand.h'\" \(2222 characters\)
  1212.   sed "s/^X//" >'bitio104/rand.h' <<'END_OF_FILE'
  1213. X/***********************************************************************\
  1214. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1215. X|                                    |
  1216. X|   This library is free software; you may redistribute it and/or    |
  1217. X|   modify it under the terms if the GNU Library General Public        |
  1218. X|   License as published by the Free Software Foundation; either    |
  1219. X|   version 2 of the license, or (at your option) any later version.    |
  1220. X|                                    |
  1221. X|   This library is distributed in the hope that it will be useful,    |
  1222. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1223. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1224. X|   GNU Library General Public License for more details.        |
  1225. X|                                    |
  1226. X|   You should have received a copy of the GNU Library General Public    |
  1227. X|   License along with this library.  If not, write to the Free        |
  1228. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1229. X|                                    |
  1230. X|author:    Philip D. Howard (ka9wgn)                |
  1231. X|email:        pdh@netcom.com                        |
  1232. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1233. X|voice/fax:    217-384-4934                        |
  1234. X\***********************************************************************/
  1235. X/***********************************************************************\
  1236. X|header:    rand.h                            |
  1237. X|purpose:    define compile configuration and declare functions for  |
  1238. X|        an extended state int/long random number generator    |
  1239. X\***********************************************************************/
  1240. X#include <limits.h>
  1241. X
  1242. X#define RANDI_MAX INT_MAX
  1243. X#define RANDUI_MAX UINT_MAX
  1244. X#define RANDL_MAX LONG_MAX
  1245. X#define RANDUL_MAX ULONG_MAX
  1246. X
  1247. X#define RANDI_SEED_CYCLE (sizeof(int)*CHAR_BIT)
  1248. X#define RANDUI_SEED_CYCLE (sizeof(unsigned int)*CHAR_BIT)
  1249. X#define RANDL_SEED_CYCLE (sizeof(long)*CHAR_BIT)
  1250. X#define RANDUL_SEED_CYCLE (sizeof(unsigned long)*CHAR_BIT)
  1251. X
  1252. X#define RANDI_SEED_INIT 1
  1253. X#define RANDUI_SEED_INIT 1
  1254. X#define RANDL_SEED_INIT 1
  1255. X#define RANDUL_SEED_INIT 1
  1256. X
  1257. X#define RANDI_STATE_SIZE 8
  1258. X#define RANDUI_STATE_SIZE 8
  1259. X#define RANDL_STATE_SIZE 8
  1260. X#define RANDUL_STATE_SIZE 8
  1261. X
  1262. Xint randi(void);
  1263. Xunsigned int randui(void);
  1264. Xlong randl(void);
  1265. Xunsigned long randul(void);
  1266. X
  1267. Xvoid srandi(int);
  1268. Xvoid srandui(unsigned int);
  1269. Xvoid srandl(long);
  1270. Xvoid srandul(unsigned long);
  1271. END_OF_FILE
  1272.   if test 2222 -ne `wc -c <'bitio104/rand.h'`; then
  1273.     echo shar: \"'bitio104/rand.h'\" unpacked with wrong size!
  1274.   fi
  1275.   # end of 'bitio104/rand.h'
  1276. fi
  1277. if test -f 'bitio104/randul.c' -a "${1}" != "-c" ; then 
  1278.   echo shar: Will not clobber existing file \"'bitio104/randul.c'\"
  1279. else
  1280.   echo shar: Extracting \"'bitio104/randul.c'\" \(2571 characters\)
  1281.   sed "s/^X//" >'bitio104/randul.c' <<'END_OF_FILE'
  1282. X/***********************************************************************\
  1283. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1284. X|                                    |
  1285. X|   This library is free software; you may redistribute it and/or    |
  1286. X|   modify it under the terms if the GNU Library General Public        |
  1287. X|   License as published by the Free Software Foundation; either    |
  1288. X|   version 2 of the license, or (at your option) any later version.    |
  1289. X|                                    |
  1290. X|   This library is distributed in the hope that it will be useful,    |
  1291. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1292. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1293. X|   GNU Library General Public License for more details.        |
  1294. X|                                    |
  1295. X|   You should have received a copy of the GNU Library General Public    |
  1296. X|   License along with this library.  If not, write to the Free        |
  1297. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1298. X|                                    |
  1299. X|author:    Philip D. Howard (ka9wgn)                |
  1300. X|email:        pdh@netcom.com                        |
  1301. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1302. X|voice/fax:    217-384-4934                        |
  1303. X\***********************************************************************/
  1304. X#include <rand.h>
  1305. X
  1306. Xstatic unsigned long    state    [ RANDUL_STATE_SIZE ] = { RANDUL_SEED_INIT };
  1307. Xstatic unsigned int    init    = 1;
  1308. X
  1309. X/***********************************************************************\
  1310. X|function:    randul                            |
  1311. X|purpose:    generate random number of type unsigned long        |
  1312. X|                                    |
  1313. X|arguments:    -none-                            |
  1314. X|returns:    (unsigned long) random number                |
  1315. X\***********************************************************************/
  1316. Xunsigned long randul()
  1317. X{
  1318. X    unsigned long l;
  1319. X    unsigned long n;
  1320. X    unsigned int i;
  1321. X    unsigned int k;
  1322. X
  1323. X    k = 1;
  1324. X    if ( init ) {
  1325. X    init = 0;
  1326. X    n = state[ 0 ];
  1327. X    for ( i = 1 ; i < RANDUL_STATE_SIZE ; ++i ) {
  1328. X        state[ i ] = n;
  1329. X    }
  1330. X    k = RANDUL_SEED_CYCLE;
  1331. X    }
  1332. X
  1333. X    while ( k ) {
  1334. X    n = 1;
  1335. X    for ( i = 0 ; i < RANDUL_STATE_SIZE ; ++i ) {
  1336. X        l = n;
  1337. X        l |= state[ i ];
  1338. X        n += state[ i ];
  1339. X        state[ i ] = n;
  1340. X        if ( n < l ) ++n;
  1341. X    }
  1342. X    state[ 0 ] = n;
  1343. X    --k;
  1344. X    }
  1345. X
  1346. X    return ( n );
  1347. X}
  1348. X
  1349. X/***********************************************************************\
  1350. X|function:    srandul                            |
  1351. X|purpose:    seed the random number generator            |
  1352. X|                                    |
  1353. X|argument:    (unsigned long) seed                    |
  1354. X|returns:    (void)                            |
  1355. X\***********************************************************************/
  1356. X#ifdef __STDC__
  1357. X
  1358. Xvoid srandul(
  1359. X    unsigned long    seed
  1360. X)
  1361. X
  1362. X#else
  1363. X
  1364. Xint srandul( seed )
  1365. X    unsigned long    seed    ;
  1366. X
  1367. X#endif
  1368. X
  1369. X{
  1370. X    state[ 0 ] = seed;
  1371. X    init = 1;
  1372. X    return;
  1373. X}
  1374. END_OF_FILE
  1375.   if test 2571 -ne `wc -c <'bitio104/randul.c'`; then
  1376.     echo shar: \"'bitio104/randul.c'\" unpacked with wrong size!
  1377.   fi
  1378.   # end of 'bitio104/randul.c'
  1379. fi
  1380. if test -f 'bitio104/testio.h' -a "${1}" != "-c" ; then 
  1381.   echo shar: Will not clobber existing file \"'bitio104/testio.h'\"
  1382. else
  1383.   echo shar: Extracting \"'bitio104/testio.h'\" \(4580 characters\)
  1384.   sed "s/^X//" >'bitio104/testio.h' <<'END_OF_FILE'
  1385. X/***********************************************************************\
  1386. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1387. X|                                    |
  1388. X|   This library is free software; you may redistribute it and/or    |
  1389. X|   modify it under the terms of the GNU Library General Public        |
  1390. X|   License as published by the Free Software Foundation; either    |
  1391. X|   version 2 of the license, or (at your option) any later version.    |
  1392. X|                                    |
  1393. X|   This library is distributed in the hope that it will be useful,    |
  1394. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1395. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1396. X|   GNU Library General Public License for more details.        |
  1397. X|                                    |
  1398. X|   You should have received a copy of the GNU Library General Public    |
  1399. X|   License along with this library.  If not, write to the Free        |
  1400. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1401. X|                                    |
  1402. X|author:    Philip D. Howard (ka9wgn)                |
  1403. X|email:        pdh@netcom.com                        |
  1404. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1405. X|voice/fax:    217-384-4934                        |
  1406. X\***********************************************************************/
  1407. X#define MAXERRS 10
  1408. X
  1409. X#define TEST1 1
  1410. X#define TESTH 1
  1411. X#define TESTL 1
  1412. X#define TESTM 1
  1413. X
  1414. X#include <bitio.h>
  1415. X
  1416. X#include <randul.c>
  1417. X
  1418. X#ifdef __STDC__
  1419. Xmain(int argc,char **argv)
  1420. X#else
  1421. Xmain(argc,argv)
  1422. Xint argc;
  1423. Xchar **argv;
  1424. X#endif
  1425. X{
  1426. X    BITFILE *        bitfile ;
  1427. X    unsigned long    nn    ;
  1428. X    unsigned long    data    ;
  1429. X    unsigned long    count    ;
  1430. X    unsigned long    total    ;
  1431. X#ifdef INPUT
  1432. X    unsigned long    cmp    ;
  1433. X    unsigned long    errs    ;
  1434. X    unsigned long    maxerrs ;
  1435. X    unsigned int    gotbits ;
  1436. X#endif
  1437. X    unsigned int    bits    ;
  1438. X
  1439. X    if ( argc < 3 ) {
  1440. X    fprintf(stderr,"arguments count seed\n");
  1441. X    exit(1);
  1442. X    }
  1443. X
  1444. X#ifdef OUTPUT
  1445. X    bitfile = bitopen( argv[1] , "w" );
  1446. X#endif
  1447. X#ifdef INPUT
  1448. X    bitfile = bitopen( argv[1] , "r" );
  1449. X    errs = 0;
  1450. X    maxerrs = MAXERRS;
  1451. X    if ( argc > 4 ) maxerrs = atol( argv[4] );
  1452. X#endif
  1453. X
  1454. X    count = atol( argv[2] );
  1455. X    srandul( atoi( argv[3] ) );
  1456. X    total = 0;
  1457. X    for ( nn = 0 ; nn < count ; ++nn ) {
  1458. X
  1459. X#if TESTM > 0
  1460. X    data = 1 & randul();
  1461. X#ifdef OUTPUT
  1462. X    BIT1PUT( bitfile , (unsigned int) data );
  1463. X#endif
  1464. X#ifdef INPUT
  1465. X    cmp = (unsigned long) BIT1GET( bitfile );
  1466. X    if ( cmp > 1 ) {
  1467. X        fprintf(stderr,"0 unexpected value %08lx at %lu\n",cmp,total+1);
  1468. X        exit(1);
  1469. X    }
  1470. X    if ( cmp != data ) {
  1471. X        fprintf(stderr,"0 expected %08lx  got %08lx     (one bit at %lu)\n",data,cmp,total);
  1472. X        if ( ++errs >= maxerrs ) exit(1);
  1473. X    }
  1474. X#endif
  1475. X    ++total;
  1476. X#endif
  1477. X
  1478. X#if TEST1 > 0
  1479. X    data = 1 & randul();
  1480. X#ifdef OUTPUT
  1481. X    bit1put( bitfile , (unsigned int) data );
  1482. X#endif
  1483. X#ifdef INPUT
  1484. X    cmp = (unsigned long) bit1get( bitfile );
  1485. X    if ( cmp > 1 ) {
  1486. X        fprintf(stderr,"1 unexpected value %08lx at %lu\n",cmp,total+1);
  1487. X        exit(1);
  1488. X    }
  1489. X    if ( cmp != data ) {
  1490. X        fprintf(stderr,"1 expected %08lx  got %08lx     (one bit at %lu)\n",data,cmp,total);
  1491. X        if ( ++errs >= maxerrs ) exit(1);
  1492. X    }
  1493. X#endif
  1494. X    ++total;
  1495. X#endif
  1496. X
  1497. X#if TESTL > 0
  1498. X    data = 255 & randul();
  1499. X    data <<= 8;
  1500. X    data |= 255 & randul();
  1501. X    data <<= 8;
  1502. X    data |= 255 & randul();
  1503. X    data <<= 8;
  1504. X    data |= 255 & randul();
  1505. X    bits = 1 + (unsigned int) ( 31 & randul() );
  1506. X    data &= 0xffffffffL >> (unsigned int) ( 32 - bits );
  1507. X
  1508. X#ifdef OUTPUT
  1509. X    bitlput( bitfile , data , bits );
  1510. X#endif
  1511. X#ifdef INPUT
  1512. X    cmp = bitlget( bitfile , & gotbits , bits );
  1513. X    if ( gotbits < bits ) {
  1514. X        fprintf(stderr,"unexpected EOF at %lu\n",total+gotbits);
  1515. X        exit(1);
  1516. X    }
  1517. X    if ( bits && cmp != data ) {
  1518. X        fprintf(stderr,"l expected %08lx  got %08lx     (%02u bits at %lu)\n",data,cmp,bits,total);
  1519. X        if ( ++errs >= maxerrs ) exit(1);
  1520. X    }
  1521. X#endif
  1522. X    total += bits;
  1523. X#endif
  1524. X
  1525. X#if TESTH > 0
  1526. X    data = 255 & randul();
  1527. X    data <<= 8;
  1528. X    data |= 255 & randul();
  1529. X    data <<= 8;
  1530. X    data |= 255 & randul();
  1531. X    data <<= 8;
  1532. X    data |= 255 & randul();
  1533. X    bits = 1 + (unsigned int) ( 0x1f & randul() );
  1534. X    data &= 0xffffffffL << ( 32 - bits );
  1535. X
  1536. X#ifdef OUTPUT
  1537. X    bithput( bitfile , data , bits );
  1538. X#endif
  1539. X#ifdef INPUT
  1540. X    cmp = bithget( bitfile , & gotbits , bits );
  1541. X    if ( gotbits < bits ) {
  1542. X        fprintf(stderr,"unexpected EOF at %lu\n",total+gotbits);
  1543. X        exit(1);
  1544. X    }
  1545. X    if ( bits && cmp != data ) {
  1546. X        fprintf(stderr,"h expected %08lx  got %08lx     (%02u bits at %lu)\n",data,cmp,bits,total);
  1547. X        if ( ++errs >= maxerrs ) exit(1);
  1548. X    }
  1549. X#endif
  1550. X    total += bits;
  1551. X#endif
  1552. X
  1553. X    }
  1554. X
  1555. X    bitflush( bitfile );
  1556. X    bitclose( bitfile );
  1557. X
  1558. X#ifdef OUTPUT
  1559. X    fprintf(stderr,"total bits out = %lu (%08lx)\n",total,total);
  1560. X#endif
  1561. X#ifdef INPUT
  1562. X    fprintf(stderr,"total bits in  = %lu (%08lx)\n",total,total);
  1563. X    fprintf(stderr,"total errors   = %u\n",errs);
  1564. X#endif
  1565. X
  1566. X    return ( 0 );
  1567. X}
  1568. END_OF_FILE
  1569.   if test 4580 -ne `wc -c <'bitio104/testio.h'`; then
  1570.     echo shar: \"'bitio104/testio.h'\" unpacked with wrong size!
  1571.   fi
  1572.   # end of 'bitio104/testio.h'
  1573. fi
  1574. if test -f 'bitio104/testmi.c' -a "${1}" != "-c" ; then 
  1575.   echo shar: Will not clobber existing file \"'bitio104/testmi.c'\"
  1576. else
  1577.   echo shar: Extracting \"'bitio104/testmi.c'\" \(2107 characters\)
  1578.   sed "s/^X//" >'bitio104/testmi.c' <<'END_OF_FILE'
  1579. X/***********************************************************************\
  1580. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1581. X|                                    |
  1582. X|   This library is free software; you may redistribute it and/or    |
  1583. X|   modify it under the terms of the GNU Library General Public        |
  1584. X|   License as published by the Free Software Foundation; either    |
  1585. X|   version 2 of the license, or (at your option) any later version.    |
  1586. X|                                    |
  1587. X|   This library is distributed in the hope that it will be useful,    |
  1588. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1589. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1590. X|   GNU Library General Public License for more details.        |
  1591. X|                                    |
  1592. X|   You should have received a copy of the GNU Library General Public    |
  1593. X|   License along with this library.  If not, write to the Free        |
  1594. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1595. X|                                    |
  1596. X|author:    Philip D. Howard (ka9wgn)                |
  1597. X|email:        pdh@netcom.com                        |
  1598. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1599. X|voice/fax:    217-384-4934                        |
  1600. X\***********************************************************************/
  1601. X#include <bitio.h>
  1602. X
  1603. X#ifdef __STDC__
  1604. Xmain(int argc,char **argv)
  1605. X#else
  1606. Xmain(argc,argv)
  1607. Xint argc;
  1608. Xchar **argv;
  1609. X#endif
  1610. X{
  1611. X    BITFILE *        bitfile ;
  1612. X    unsigned long    ii    ;
  1613. X    unsigned int    m,n    ;
  1614. X    int            b    ;
  1615. X    int            errs    ;
  1616. X    int            maxerrs = 20;
  1617. X
  1618. X    if ( argc <= 1 ) {
  1619. X    fprintf(stderr,"syntax: testmi filename\n");
  1620. X    exit(1);
  1621. X    }
  1622. X
  1623. X    bitfile = bitopen( argv[1] , "r" );
  1624. X    if ( NULL == bitfile ) {
  1625. X    fprintf(stderr,"unable to open file: %s\n",argv[1]);
  1626. X    exit(1);
  1627. X    }
  1628. X
  1629. X    errs = 0;
  1630. X    m = n = 0;
  1631. X    ii = 0;
  1632. X    for (;;) {
  1633. X    m += (unsigned int) ii;
  1634. X    n += m;
  1635. X    b = BIT1GET( bitfile );
  1636. X    if ( b < 0 ) break;
  1637. X    if ( b != ( 1 & n ) ) {
  1638. X        fprintf(stderr,"mismatch at %lu\n",ii);
  1639. X        if ( ++errs >= maxerrs ) {
  1640. X        fprintf(stderr,"abort\n");
  1641. X        bitclose( bitfile );
  1642. X        exit(1);
  1643. X        }
  1644. X    }
  1645. X    m += n >> 12;
  1646. X    ++ii;
  1647. X    }
  1648. X
  1649. X    if ( b < -1 ) {
  1650. X    fprintf(stderr,"error in input bit stream\n");
  1651. X    }
  1652. X
  1653. X    bitclose( bitfile );
  1654. X
  1655. X    return ( 0 );
  1656. X}
  1657. END_OF_FILE
  1658.   if test 2107 -ne `wc -c <'bitio104/testmi.c'`; then
  1659.     echo shar: \"'bitio104/testmi.c'\" unpacked with wrong size!
  1660.   fi
  1661.   # end of 'bitio104/testmi.c'
  1662. fi
  1663. if test -f 'bitio104/testmo.c' -a "${1}" != "-c" ; then 
  1664.   echo shar: Will not clobber existing file \"'bitio104/testmo.c'\"
  1665. else
  1666.   echo shar: Extracting \"'bitio104/testmo.c'\" \(1804 characters\)
  1667.   sed "s/^X//" >'bitio104/testmo.c' <<'END_OF_FILE'
  1668. X/***********************************************************************\
  1669. X|   Copyright (C) 1993 - by Philip David Howard - all rights reserved    |
  1670. X|                                    |
  1671. X|   This library is free software; you may redistribute it and/or    |
  1672. X|   modify it under the terms of the GNU Library General Public        |
  1673. X|   License as published by the Free Software Foundation; either    |
  1674. X|   version 2 of the license, or (at your option) any later version.    |
  1675. X|                                    |
  1676. X|   This library is distributed in the hope that it will be useful,    |
  1677. X|   but WITHOUT ANY WARRANTY; without even the implied warranty of    |
  1678. X|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    |
  1679. X|   GNU Library General Public License for more details.        |
  1680. X|                                    |
  1681. X|   You should have received a copy of the GNU Library General Public    |
  1682. X|   License along with this library.  If not, write to the Free        |
  1683. X|   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    |
  1684. X|                                    |
  1685. X|author:    Philip D. Howard (ka9wgn)                |
  1686. X|email:        pdh@netcom.com                        |
  1687. X|postal:    PO Box 5012;  Champaign, IL  61825-5012            |
  1688. X|voice/fax:    217-384-4934                        |
  1689. X\***********************************************************************/
  1690. X#include <bitio.h>
  1691. X
  1692. X#ifdef __STDC__
  1693. Xmain(int argc,char **argv)
  1694. X#else
  1695. Xmain(argc,argv)
  1696. Xint argc;
  1697. Xchar **argv;
  1698. X#endif
  1699. X{
  1700. X    BITFILE *        bitfile ;
  1701. X    unsigned long    ii,kk    ;
  1702. X    unsigned int    m,n    ;
  1703. X
  1704. X    if ( argc <= 2 ) {
  1705. X    fprintf(stderr,"syntax: testmo filename count\n");
  1706. X    exit(1);
  1707. X    }
  1708. X
  1709. X    kk = atol( argv[2] );
  1710. X    bitfile = bitopen( argv[1] , "w" );
  1711. X    if ( NULL == bitfile ) {
  1712. X    fprintf(stderr,"unable to open file: %s\n",argv[1]);
  1713. X    exit(1);
  1714. X    }
  1715. X
  1716. X    m = n = 0;
  1717. X    for ( ii = 0; ii < kk; ++ii ) {
  1718. X    m += (unsigned int) ii;
  1719. X    n += m;
  1720. X    BIT1PUT( bitfile , n );
  1721. X    m += n >> 12;
  1722. X    }
  1723. X
  1724. X    bitclose( bitfile );
  1725. X
  1726. X    return ( 0 );
  1727. X}
  1728. END_OF_FILE
  1729.   if test 1804 -ne `wc -c <'bitio104/testmo.c'`; then
  1730.     echo shar: \"'bitio104/testmo.c'\" unpacked with wrong size!
  1731.   fi
  1732.   # end of 'bitio104/testmo.c'
  1733. fi
  1734. echo shar: End of archive 2 \(of 3\).
  1735. cp /dev/null ark2isdone
  1736. MISSING=""
  1737. for I in 1 2 3 ; do
  1738.     if test ! -f ark${I}isdone ; then
  1739.     MISSING="${MISSING} ${I}"
  1740.     fi
  1741. done
  1742. if test "${MISSING}" = "" ; then
  1743.     echo You have unpacked all 3 archives.
  1744.     rm -f ark[1-9]isdone
  1745. else
  1746.     echo You still must unpack the following archives:
  1747.     echo "        " ${MISSING}
  1748. fi
  1749. exit 0
  1750. exit 0 # Just in case...
  1751.