|
|
1.1 root 1: /* util.c - General utility routines */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/util.c,v 7.1 90/07/09 14:35:23 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/dsap/common/RCS/util.c,v 7.1 90/07/09 14:35:23 mrose Exp $
9: *
10: *
11: * $Log: util.c,v $
12: * Revision 7.1 90/07/09 14:35:23 mrose
13: * sync
14: *
15: * Revision 7.0 89/11/23 21:44:40 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: /* LINTLIBRARY */
32:
33: #include "quipu/util.h"
34: #include "quipu/commonarg.h"
35: #include "quipu/malloc.h"
36: #include "tsap.h"
37: #include <varargs.h>
38:
39: extern LLog * log_dsap;
40:
41: char * SkipSpace (ptr)
42: register char * ptr;
43: {
44: if (ptr == NULLCP)
45: return (NULLCP);
46:
47: while ( isspace (*ptr))
48: ptr++;
49: return (ptr);
50: }
51:
52: void StripSpace (b)
53: register char *b;
54: /* copy b to a less spaces and comments */
55: {
56: register char *a;
57:
58: if (*b == COMMENT ) {
59: *b = 0;
60: return;
61: }
62:
63: while ((! isspace(*b)) && (*b))
64: b++;
65:
66: if (!*b)
67: return; /* nothing needs doing */
68:
69: a = b;
70:
71: for (;;) {
72: if (isspace (*b))
73: b++;
74: else if ( (!*b) || (*b == COMMENT))
75: break;
76: else
77: *a++ = *b++;
78: }
79:
80: *a = 0;
81: }
82:
83: void StripSpace2 (b)
84: register char *b;
85: /* copy b to a less spaces and comments */
86: {
87: register char *a;
88:
89: while (isascii(*b) && (! isspace(*b)) && (*b))
90: b++;
91:
92: if (!*b)
93: return; /* nothing needs doing */
94:
95: a = b;
96:
97: for (;;) {
98: if (isascii(*b) && isspace (*b))
99: b++;
100: else if (!*b)
101: break;
102: else
103: *a++ = *b++;
104: }
105:
106: *a = 0;
107: }
108:
109: char * TidyString2 (a)
110: register char * a;
111: {
112: register char * b;
113: char * c;
114: register int i = 0;
115:
116: /* removing multiple and trailing spaces */
117: c = a, b = a;
118: while (*a) {
119: if (isascii(*a) && isspace (*a)) {
120: *b = ' '; /* make sure not a tab etc */
121: while (isspace (*++a))
122: i = 1;
123:
124: if (*a)
125: b++;
126: else
127: break;
128: }
129: if (i)
130: *b = *a;
131:
132: a++, b++;
133: }
134:
135: *b = 0;
136:
137: if (*--b == '\n')
138: *b-- = 0;
139:
140: if (*b == ' ')
141: *b = 0;
142:
143: return (c);
144: }
145:
146: char * TidyString (a)
147: register char * a;
148: {
149: if (!*a)
150: return (a);
151:
152: /* remove white space from front of string */
153: while (isspace (*a))
154: a++;
155:
156: return (TidyString2(a));
157: }
158:
159: test_prim_pe (pe,class,id)
160: PE pe;
161: PElementClass class;
162: PElementID id;
163: {
164: if (pe == NULLPE)
165: return FALSE;
166:
167: if (pe->pe_form != PE_FORM_PRIM) {
168: LLOG (log_dsap,LLOG_EXCEPTIONS,("Primative Attribute Value expected"));
169: return FALSE;
170: }
171:
172: if ( PE_ID (pe -> pe_class, pe -> pe_id) != PE_ID (class, id) ) {
173: LLOG (log_dsap,LLOG_EXCEPTIONS,("Bad class/ID in Attribute Value"));
174: return FALSE;
175: }
176:
177: return (TRUE);
178:
179: }
180:
181: #ifndef lint
182: ps_printf (va_alist)
183: va_dcl
184: {
185: PS ps;
186: char buffer [8192]; /* How big should this go !!! */
187: va_list ap;
188:
189: va_start (ap);
190:
191: ps = va_arg (ap, PS);
192:
193: _asprintf (buffer,NULLCP,ap);
194:
195: ps_print (ps,buffer);
196:
197: va_end (ap) ;
198: }
199: #else
200:
201: /* VARARGS2 */
202: ps_printf (ps,fmt)
203: PS ps;
204: char * fmt;
205: {
206: (void) ps_printf (ps,fmt) ;
207: }
208:
209: #endif
210:
211:
212: fatal (code,fmt)
213: int code;
214: char *fmt;
215: {
216: static char buf [80] = "FATAL ERROR: ";
217:
218: (void) strcat (buf,fmt);
219: LLOG (log_dsap,LLOG_FATAL,(fmt));
220: (void) fflush (stdout);
221: (void) fprintf (stderr,"%s\n",buf);
222: stop_listeners ();
223: exit (code);
224: }
225:
226: pslog (lp,event,str,func,ptr)
227: LLog * lp;
228: int event;
229: char * str;
230: int (*func) (); /* assumes func (PS ,dataptr,(int) format); */
231: caddr_t ptr;
232: {
233: /* log info to pstream */
234: PS ps;
235: char buffer [LINESIZE];
236:
237: if (!(lp -> ll_events & event))
238: return;
239:
240: if ((ps = ps_alloc (str_open)) == NULLPS) {
241: LLOG (lp,LLOG_EXCEPTIONS,("pslog: can't allocate pstream"));
242: return ;
243: }
244: if (str_setup (ps,buffer,LINESIZE,1) == NOTOK) {
245: LLOG (lp,LLOG_EXCEPTIONS,("pslog: can't setup pstream"));
246: return ;
247: }
248:
249: (*func) (ps,ptr,EDBOUT);
250: *ps->ps_ptr = 0;
251:
252: ps_free (ps);
253:
254: LLOG (lp,event,("%s: %s",str,buffer));
255: }
256:
257: stop_listeners ()
258: {
259: struct TSAPdisconnect td_s;
260: struct TSAPdisconnect * td = &(td_s);
261:
262: /* close all listeners */
263: (void) TNetClose (NULLTA,td);
264: }
265:
266: quipu_pe_cmp (a,b)
267: register PE a,b;
268: {
269: char *p,*q;
270: register int j,i;
271:
272: /* based on ISODE pe_cmp */
273:
274: if ( a == NULLPE) {
275: if ( b == NULLPE )
276: return (0);
277: else
278: return (1);
279: }
280: if ( b == NULLPE)
281: return (-1);
282:
283: if (a->pe_class != b->pe_class)
284: if (a->pe_class > b->pe_class)
285: return (1) ;
286: else
287: return (-1);
288:
289: if (a->pe_form != b->pe_form)
290: if (a->pe_form > b->pe_form)
291: return (1) ;
292: else
293: return (-1);
294:
295: if (a->pe_id != b->pe_id)
296: if (a->pe_id > b->pe_id)
297: return (1) ;
298: else
299: return (-1);
300:
301: switch ( a->pe_form ) {
302: case PE_FORM_ICONS:
303: if (a->pe_ilen != a->pe_ilen)
304: return (a->pe_ilen > b->pe_ilen ? 1 : -1);
305: case PE_FORM_PRIM:
306: if ( (i=a->pe_len) != b->pe_len)
307: if ( i > b->pe_len )
308: return (1);
309: else
310: return (-1);
311:
312: p = (char *) a->pe_prim;
313: q = (char *) b->pe_prim;
314:
315: for (j=0; j<i; j++) {
316: if (*p != *q)
317: if ( *p > *q )
318: return (1);
319: else
320: return (-1);
321: p++;
322: q++;
323: }
324: return (0) ;
325:
326: case PE_FORM_CONS:
327: for (a=a->pe_cons,b=b->pe_cons; a; a=a->pe_next,b=b->pe_next)
328: if ((i = quipu_pe_cmp (a,b)) != 0)
329: return (i);
330: return (b ? 1 : 0);
331: default:
332: return (1);
333:
334: }
335: }
336:
337:
338: IFP acl_fn = NULLIFP;
339:
340: struct acl_info * acl_dflt ()
341: {
342: if (acl_fn == NULLIFP)
343: return ((struct acl_info *) NULL);
344: else
345: return ((struct acl_info *)(*acl_fn)());
346: }
347:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.