DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦e45a51205⟧ TextFile

    Length: 1647 (0x66f)
    Types: TextFile
    Names: »bitstr2strb.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦041b9c0f8⟧ »EurOpenD22/isode/pepsy.system-6.0.Z« 
        └─⟦d49939f05⟧ 
            └─⟦6a28ec38e⟧ »pepsy.tar« 
                └─⟦this⟧ »pepsy/bitstr2strb.c« 

TextFile

/* bitstr2strb.c - bit string to string of bits */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/psap/RCS/bitstr2strb.c,v 6.0 89/03/18 23:38:11 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/psap/RCS/bitstr2strb.c,v 6.0 89/03/18 23:38:11 mrose Rel $
 *
 *
 * $Log:	bitstr2strb.c,v $
 * Revision 6.0  89/03/18  23:38:11  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


/* LINTLIBRARY */

#include <stdio.h>
#include "psap.h"

/* \f

 */
#ifdef FAST
/* Attempt to speed up this really slow routine */
#define BIT_TEST(pe, bit)	(pe->pe_form == PE_FORM_PRIM && \
	pe->pe_nbits > bit ? pe->pe_prim[bit/8 + 1] & 1 << (7 - bit % 8) \
	: bit_test(pe, bit))
#else
#define BIT_TEST(pe, bit)	bit_test(pe, bit)
#endif
 

char   *bitstr2strb (pe, k)
register PE	pe;
int    *k;
{
    register int    i,
		    j,
		    len,
		    bit,
		    mask;
    register char   *dp;
    char   *cp;

    if (pe == NULLPE)
	return NULLCP;

    *k = len = pe -> pe_nbits;
    if ((cp = dp = calloc (1, (unsigned) (len / 8 + 2))) == NULLCP)
	return NULLCP;

#ifdef FAST
    if (pe->pe_form == PE_FORM_PRIM) {
	bcopy(pe->pe_prim + 1, dp, (len + 7) / 8);
	return (dp);
    }
#endif
    for (bit = i = 0, mask = 1 << (j = 7); i < len; i++) {
	if (BIT_TEST (pe, i))
	    bit |= mask;
	if (j-- == 0)
	    *dp++ = bit & 0xff, bit = 0, mask = 1 << (j = 7);
	else
	    mask >>= 1;
    }
    if (j != 7)
	*dp = bit & 0xff;

    return cp;
}