|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 5408 (0x1520)
Types: TextFile
Names: »util.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z«
└─⟦de7628f85⟧
└─⟦this⟧ »isode-6.0/dsap/common/util.c«
/* util.c - General utility routines */
#ifndef lint
static char *rcsid = "$Header: /f/osi/dsap/common/RCS/util.c,v 7.0 89/11/23 21:44:40 mrose Rel $";
#endif
/*
* $Header: /f/osi/dsap/common/RCS/util.c,v 7.0 89/11/23 21:44:40 mrose Rel $
*
*
* $Log: util.c,v $
* Revision 7.0 89/11/23 21:44:40 mrose
* Release 6.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 "quipu/malloc.h"
#include "tsap.h"
#include <varargs.h>
extern LLog * log_dsap;
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);
}
test_prim_pe (pe,class,id)
PE pe;
PElementClass class;
PElementID id;
{
if (pe == NULLPE)
return FALSE;
if (pe->pe_form != PE_FORM_PRIM) {
LLOG (log_dsap,LLOG_EXCEPTIONS,("Primative Attribute Value expected"));
return FALSE;
}
if ( PE_ID (pe -> pe_class, pe -> pe_id) != PE_ID (class, id) ) {
LLOG (log_dsap,LLOG_EXCEPTIONS,("Bad class/ID in Attribute Value"));
return FALSE;
}
return (TRUE);
}
#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));
}
stop_listeners ()
{
struct TSAPdisconnect td_s;
struct TSAPdisconnect * td = &(td_s);
/* close all listeners */
(void) TNetClose (NULLTA,td);
}
quipu_pe_cmp (a,b)
register PE a,b;
{
char *p,*q;
register int j,i;
/* based on ISODE pe_cmp */
if ( a == NULLPE) {
if ( b == NULLPE )
return (0);
else
return (1);
}
if ( b == NULLPE)
return (-1);
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_ICONS:
if (a->pe_ilen != a->pe_ilen)
return (a->pe_ilen > b->pe_ilen ? 1 : -1);
case PE_FORM_PRIM:
if ( (i=a->pe_len) != b->pe_len)
if ( i > b->pe_len )
return (1);
else
return (-1);
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)
if ((i = quipu_pe_cmp (a,b)) != 0)
return (i);
return (b ? 1 : 0);
default:
return (1);
}
}
ava_decode (purported)
ava *purported;
{
return (AttrV_decode (purported->ava_type, purported->ava_value));
}
IFP acl_fn = NULLIFP;
struct acl_info * acl_dflt ()
{
if (acl_fn == NULLIFP)
return ((struct acl_info *) NULL);
else
return ((struct acl_info *)(*acl_fn)());
}