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 u

⟦411187abe⟧ TextFile

    Length: 5715 (0x1653)
    Types: TextFile
    Names: »util.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/dsap/common/util.c« 

TextFile

/* util.c - General utility routines */

#ifndef lint
static char *rcsid = "$Header: /f/osi/dsap/common/RCS/util.c,v 6.0 89/03/18 23:27:55 mrose Rel $";
#endif

/*
 * $Header: /f/osi/dsap/common/RCS/util.c,v 6.0 89/03/18 23:27:55 mrose Rel $
 *
 *
 * $Log:	util.c,v $
 * Revision 6.0  89/03/18  23:27:55  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 "quipu/util.h"
#include "quipu/commonarg.h"
#include <varargs.h>

static  LLog    _ldsap_log =
{
	"dsap.log",
	NULLCP,
	NULLCP,
	LLOG_FATAL,
	LLOG_NONE,
	20,
	LLOGZER | LLOGCRT | LLOGCLS,
	NOTOK
};

LLog    *log_dsap = &_ldsap_log;

int     oidformat = 1;      /* oid format, 1=part, 2=full, 3=numeric */

char * SkipSpace (ptr)
register char * ptr;
{
	if (ptr == NULLCP)
		return (NULLCP);

	while ( isspace (*ptr))
		ptr++;
	return (ptr);
}

void StripSpace (b)
register char *b;
/* copy b to a less spaces and comments */
{
register char *a;

	if (*b == COMMENT ) {
		*b = 0;
		return;
	}

	while ((! isspace(*b)) && (*b))
		b++;

	if (!*b)
		return;         /* nothing needs doing */

	a = b;

	for (;;) {
		if (isspace (*b))
			b++;
		else if ( (!*b) || (*b == COMMENT))
			break;
		else
			*a++ = *b++;
		}

	*a = 0;
}

void StripSpace2 (b)
register char *b;
/* copy b to a less spaces and comments */
{
register char *a;

	while ((! isspace(*b)) && (*b))
		b++;

	if (!*b)
		return;         /* nothing needs doing */

	a = b;

	for (;;) {
		if (isspace (*b))
			b++;
		else if (!*b)
			break;
		else
			*a++ = *b++;
		}

	*a = 0;
}

char * TidyString (a)
register char * a;
{
register char * b;
char * c;
register int i = 0;

	if (!*a)
		return (a);

	/* remove white space from front of string */
	while (isspace (*a))
		a++;

	/* now continue removing multiple and trailing spaces */
	c = a, b = a;
	while (*a) {
		if (isspace (*a)) {
			*b = ' ';       /* make sure not a tab etc */
			while (isspace (*++a))
				i = 1;

			if (*a)
				b++;
			else
				break;
		}
		if (i == 1)
			*b = *a;

		a++, b++;
	}

	*b = 0;

	if (*--b == '\n')
		*b-- = 0;

	if (*b == ' ')
		*b = 0;

	return (c);
}

#ifndef lint
ps_printf (va_alist)
va_dcl
{
	PS ps;
	char buffer [8192]; 	/* How big should this go !!! */
	va_list ap;

	va_start (ap);

	ps = va_arg (ap, PS);

	_asprintf (buffer,NULLCP,ap);

	ps_print (ps,buffer)

	va_end (ap) ;
}
#else

/* VARARGS2 */
ps_printf (ps,fmt)
PS ps;
char * fmt;
{
(void) ps_printf (ps,fmt) ;
}

#endif


fatal (code,fmt)
int  code;
char *fmt;
{
static char buf [80] = "FATAL ERROR: ";

	(void) strcat (buf,fmt);
	LLOG (log_dsap,LLOG_FATAL,(fmt));
	(void) fflush (stdout);
	(void) fprintf (stderr,"%s\n",buf);
	stop_listeners ();
	exit (code);
}

pslog (lp,event,str,func,ptr)
LLog * lp;
int event;
char * str;
int (*func) ();         /* assumes func (PS ,dataptr,(int) format); */
caddr_t ptr;
{
	/* log info to pstream */
PS ps;
char buffer [LINESIZE];

    if (!(lp -> ll_events & event))
	return;

    if ((ps = ps_alloc (str_open)) == NULLPS) {
	LLOG (lp,LLOG_EXCEPTIONS,("pslog: can't allocate pstream"));
	return ;
    }
    if (str_setup (ps,buffer,LINESIZE,1) == NOTOK) {
	LLOG (lp,LLOG_EXCEPTIONS,("pslog: can't setup pstream"));
	return ;
    }

    (*func) (ps,ptr,EDBOUT);
    *ps->ps_ptr = 0;

    ps_free (ps);

    LLOG (lp,event,("%s: %s",str,buffer));
}


quipu_oid_cmp (p,q)
OID p,q;
{
register unsigned int *a,*b;
register int j,i;

	if (p == NULLOID)
		return ((q == NULLOID) ? 0 : -1);

	if (q == NULLOID)
		return (1);


	/* routine base on ISODE oid_cmp - but orders OID's */
	i = p->oid_nelem;
	j = q->oid_nelem;
	if ( i != j )
		if ( i<j )
			return (1);
		else
			return (-1);

	a = p->oid_elements + i - 1;
	b = q->oid_elements + j - 1;

	for (j=0; j<i ; j++) {
		if (*a != *b)
			if ( *a < *b )
				return (1);
			else
				return (-1);
		a--;
		b--;
		}

	return (0);
}

quipu_pe_cmp (a,b)
register PE a,b;
{
char *p,*q;
register int j,i;

	/* based on ISODE pe_cmp */

	if (a->pe_class != b->pe_class)
		if (a->pe_class >  b->pe_class)
			return (1) ;
		else
			return (-1);

	if (a->pe_form != b->pe_form)
		if (a->pe_form >  b->pe_form)
			return (1) ;
		else
			return (-1);

	if (a->pe_id != b->pe_id)
		if (a->pe_id >  b->pe_id)
			return (1) ;
		else
			return (-1);

	switch ( a->pe_form ) {
	    case PE_FORM_PRIM:
		if ( (i=a->pe_len) != b->pe_len)
			if (  i > b->pe_len )
				return (1);
			else
				return (-1);

		if (a->pe_id  == PE_DEFN_PRTS)
			return (lexnequ ((char *)a->pe_prim,(char *)b->pe_prim,i));

		p = (char *) a->pe_prim;
		q = (char *) b->pe_prim;

		for (j=0; j<i; j++) {
			if (*p != *q)
				if ( *p > *q )
					return (1);
				else
					return (-1);
			p++;
			q++;
		}
		return (0) ;

	    case PE_FORM_CONS:
		for (a=a->pe_cons,b=b->pe_cons; a; a=a->pe_next,b=b->pe_next)
			/* NOSTRICT */
			if ((i = quipu_pe_cmp (a,b) != 0))
				return (i);
		return (a ? 1 : 0);
	    default:
		return (1);

	}
}


ava_decode (purported)
ava *purported;
{
	AttrV_decode (purported->ava_type, purported->ava_value);
}


/* the next routines are stubs - the *real* routines
   are used for intense debugging.
   Calls to them sould be #define out, but just incase...
*/


#undef lmalloc
#undef lfree

#ifndef lint
char * lmalloc (a,b,c)
int a,b;
char *c;
{
return ((char *)smalloc (b));
}

lfree (a,b,c)
int a;
char * b, *c;
{
free (b);
}

#else
char * lmalloc (a,b,c)
int a,b;
char *c;
{
return (lmalloc (a,b,c));
}

lfree (a,b,c)
int a;
char *b, *c;
{
(void) lfree (a,b,c);
}
#endif