|
|
1.1 root 1: /* vprint.c - pepy printer support */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/pepsy/RCS/vprint.c,v 7.1 90/07/27 08:49:12 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/pepsy/RCS/vprint.c,v 7.1 90/07/27 08:49:12 mrose Exp $
9: *
10: *
11: * $Log: vprint.c,v $
12: * Revision 7.1 90/07/27 08:49:12 mrose
13: * update
14: *
15: * Revision 7.0 90/07/01 19:54:34 mrose
16: * *** empty log message ***
17: *
18: * Revision 7.0 89/11/23 22:12:08 mrose
19: * Release 6.0
20: *
21: */
22:
23: /*
24: * NOTICE
25: *
26: * Acquisition, use, and distribution of this module and related
27: * materials are subject to the restrictions of a license agreement.
28: * Consult the Preface in the User's Manual for the full terms of
29: * this agreement.
30: *
31: */
32:
33:
34: /* LINTLIBRARY */
35:
36: #include <ctype.h>
37: #include <stdio.h>
38: #include <varargs.h>
39: #include "UNIV-types.h"
40: #include "psap.h"
41: #include "pepsy.h"
42: #include "logger.h"
43:
44:
45: int fprintf ();
46:
47: /* DATA */
48:
49: #define VPRINT(s) vprint1 (), vwrite ((s)), vprint2 ()
50:
51: static int vlevel = 0;
52:
53: static int didname = 0;
54: static int didvpop = 0;
55: static int didvpush = 0;
56: static int docomma = 0;
57:
58: static char *py_classlist[] = {
59: "UNIVERSAL", "APPLICATION", "", "PRIVATE"
60: };
61:
62: static char *vbp = NULL;
63: static char *vsp;
64:
65: IFP vfnx = fprintf;
66: FILE *vfp = stdout;
67: static PS vps = NULLPS;
68:
69: char *oct2str (), *newbuf ();
70:
71: /* VPUSH/VPOP */
72:
73: vpush () {
74: if (didvpush)
75: vwrite ("\n"), didvpush = 0;
76: else
77: if (!didname && docomma)
78: vwrite (",\n");
79:
80: if (didname)
81: vwrite (" ");
82: else
83: if (vfp && vlevel > 0)
84: (*vfnx) (vfp, "%*s", vlevel * 3, "");
85: vwrite ("{");
86: vlevel++;
87:
88: didname = didvpop = docomma = 0, didvpush = 1;
89: }
90:
91:
92: vpop () {
93: if (didname || docomma)
94: vwrite ("\n");
95:
96: vlevel--;
97: if (!didvpush && vfp && vlevel > 0)
98: (*vfnx) (vfp, "%*s", vlevel * 3, "");
99: vwrite ("}");
100: if (vlevel == 0)
101: vwrite ("\n");
102:
103: didname = didvpush = 0, didvpop = docomma = vlevel ? 1 : 0;
104: }
105:
106: /* VNAME/VTAG */
107:
108: vname (name)
109: char *name;
110: {
111: if (didvpush)
112: vwrite ("\n"), didvpush = 0;
113: else
114: if (docomma)
115: vwrite (",\n");
116:
117: if (vfp && vlevel > 0)
118: (*vfnx) (vfp, "%*s", vlevel * 3, "");
119: vwrite (name);
120:
121: didname = 1;
122: }
123:
124:
125: vtag (class, id)
126: int class,
127: id;
128: {
129: register char *bp;
130: static char buffer[BUFSIZ];
131:
132: if (didname)
133: return;
134:
135: bp = buffer;
136: *bp++ = '[';
137: switch (class) {
138: case PE_CLASS_UNIV:
139: case PE_CLASS_APPL:
140: case PE_CLASS_PRIV:
141: (void) sprintf (bp, "%s ", py_classlist[class]);
142: bp += strlen (bp);
143: break;
144:
145: case PE_CLASS_CONT:
146: default:
147: break;
148: }
149: (void) sprintf (bp, "%d]", id);
150:
151: vname (buffer);
152: }
153:
154: /* VPRINT */
155:
156: #ifndef lint
157: vprint (va_alist)
158: va_dcl
159: {
160: char buffer[BUFSIZ];
161: va_list ap;
162:
163: vprint1 ();
164:
165: va_start (ap);
166:
167: _asprintf (buffer, NULLCP, ap);
168:
169: va_end (ap);
170:
171: vwrite (buffer);
172:
173: vprint2 ();
174: }
175: #else
176: /* VARARGS */
177:
178: vprint (fmt)
179: char *fmt;
180: {
181: vprint (fmt);
182: }
183: #endif
184:
185:
186: static vprint1 ()
187: {
188: if (didvpush) {
189: vwrite ("\n"), didvpush = 0;
190: goto indent;
191: }
192: else
193: if (didname)
194: vwrite (" ");
195: else {
196: if (docomma)
197: vwrite (",\n");
198: indent: ;
199: if (vfp && vlevel > 0)
200: (*vfnx) (vfp, "%*s", vlevel * 3, "");
201: }
202: }
203:
204:
205: static vprint2 ()
206: {
207: if (vlevel == 0)
208: vwrite ("\n");
209:
210: didname = didvpop = 0, docomma = vlevel ? 1 : 0;
211: }
212:
213: /* */
214:
215: static vwrite (s)
216: char *s;
217: {
218: if (vfp)
219: (*vfnx) (vfp, "%s", s);
220: else {
221: register char c,
222: *cp;
223:
224: if (vps)
225: for (cp = s; *cp; cp++) {
226: if (*cp == '\n' )
227: (void) ps_write (vps, (PElementData) " ", 1);
228: else
229: (void) ps_write (vps, (PElementData) cp, 1);
230: }
231: else
232: for (cp = s; *cp; )
233: *vbp++ = (c = *cp++) != '\n' ? c : ' ';
234: }
235: }
236:
237: /* VSTRING */
238:
239: vstring (pe)
240: register PE pe;
241: {
242: register PE p;
243:
244: switch (pe -> pe_form) {
245: case PE_FORM_PRIM:
246: case PE_FORM_ICONS:
247: VPRINT (oct2str ((char *) pe -> pe_prim, (int) pe -> pe_len));
248: break;
249:
250: case PE_FORM_CONS:
251: vpush ();
252: for (p = pe -> pe_cons; p; p = p -> pe_next)
253: vstring (p);
254: vpop ();
255: break;
256: }
257: }
258:
259: /* */
260:
261: static char *oct2str (s, len)
262: register char *s;
263: register int len;
264: {
265: int ia5ok;
266: register int k;
267: register char *bp,
268: *cp,
269: *dp,
270: *zp;
271:
272: ia5ok = 1, k = 0;
273: for (dp = (cp = s) + len; cp < dp; cp++) {
274: switch (*cp) {
275: case ' ':
276: continue;
277:
278: case '"':
279: break;
280:
281: case '\b':
282: case '\f':
283: case '\n':
284: case '\r':
285: case '\t':
286: case '\\':
287: ia5ok = -1, k++;
288: continue;
289:
290: case '-':
291: if (cp > s && *(cp + 1) == '-')
292: break;
293: continue;
294:
295: default:
296: if (iscntrl (*cp) || isspace (*cp) || (*cp & 0x80))
297: break;
298: continue;
299: }
300: ia5ok = 0;
301: break;
302: }
303:
304: switch (ia5ok) {
305: case 1:
306: zp = newbuf (len + 2);
307: (void) sprintf (zp, "\"%*.*s\"", len, len, s);
308: break;
309:
310: case -1:
311: bp = zp = newbuf (len + k + 2);
312: *bp++ = '"';
313: for (cp = s; cp < dp; cp++)
314: if (*cp >= ' ' && *cp != '\\')
315: *bp++ = *cp;
316: else {
317: *bp++ = '\\';
318: switch (*cp) {
319: case '\b':
320: *bp++ = 'b';
321: break;
322: case '\f':
323: *bp++ = 'f';
324: break;
325: case '\n':
326: *bp++ = 'n';
327: break;
328: case '\r':
329: *bp++ = 'r';
330: break;
331: case '\t':
332: *bp++ = 't';
333: break;
334:
335: case '\\':
336: *bp++ = '\\';
337: break;
338: }
339: }
340: (void) sprintf (bp, "\"");
341: break;
342:
343: case 0:
344: default:
345: bp = zp = newbuf (len * 2 + 3);
346: *bp++ = '\'';
347: for (cp = s; cp < dp; cp++) {
348: (void) sprintf (bp, "%02x", *cp & 0xff);
349: bp += strlen (bp);
350: }
351: (void) sprintf (bp, "'H");
352: break;
353: }
354:
355: return zp;
356: }
357:
358: /* */
359:
360: char *bit2str (pe, s)
361: PE pe;
362: char *s;
363: {
364: int ia5ok;
365: register int hit,
366: i,
367: j,
368: k;
369: register char *bp,
370: *cp,
371: *zp;
372:
373: j = pe -> pe_nbits;
374: if ((cp = s) && *++cp) {
375: ia5ok = 1, hit = 0;
376: for (i = 0; i < j;)
377: if (bit_test (pe, i++) == 1) {
378: do {
379: if (!(k = *cp++ & 0xff))
380: break;
381: if (k == i) {
382: hit += hit ? 2 : 1;
383: for (; *cp > ' '; cp++)
384: hit++;
385: }
386: else
387: for (; *cp > ' '; cp++)
388: continue;
389: } while (k != 0 && k < i);
390: if (k == 0 || k > i) {
391: ia5ok = 0;
392: break;
393: }
394: }
395: }
396: else
397: ia5ok = 0;
398:
399: if (ia5ok) {
400: bp = zp = newbuf (hit + 3);
401: *bp++ = '{';
402:
403: cp = s, cp++;
404: for (i = hit = 0; i < j;)
405: if (bit_test (pe, i++) == 1) {
406: do {
407: if (!(k = *cp++ & 0xff))
408: break;
409: if (k == i) {
410: if (hit)
411: *bp++ = ',';
412: *bp++ = ' ';
413: for (; *cp > ' '; cp++)
414: *bp++ = *cp;
415: }
416: else
417: for (; *cp > ' '; cp++)
418: continue;
419: } while (k != 0 && k < i);
420: if (k == 0 || k > i)
421: break;
422: hit++;
423: }
424:
425: (void) sprintf (bp, "%s}", hit ? " " : "");
426: }
427: else {
428: bp = zp = newbuf (j + 3);
429: *bp++ = '\'';
430: for (i = 0; i < j; i++)
431: *bp++ = bit_test (pe, i) ? '1' : '0';
432: (void) sprintf (bp, "'B");
433: }
434:
435: return zp;
436: }
437:
438: /* */
439:
440: #ifdef vunknown
441: #undef vunknown
442: #endif
443:
444: vunknown (pe)
445: register PE pe;
446: {
447: int i;
448: #ifdef notyet /* could comment this in, but then all programs need -lm */
449: double j;
450: #endif
451: OID oid;
452: register PE p;
453:
454: switch (pe -> pe_form) {
455: case PE_FORM_PRIM:
456: switch (PE_ID (pe -> pe_class, pe -> pe_id)) {
457: case PE_ID (PE_CLASS_UNIV, PE_PRIM_BOOL):
458: if ((i = prim2flag (pe)) == NOTOK)
459: goto bad_pe;
460: VPRINT (i ? "TRUE" : "FALSE");
461: break;
462:
463: case PE_ID (PE_CLASS_UNIV, PE_PRIM_INT):
464: case PE_ID (PE_CLASS_UNIV, PE_PRIM_ENUM):
465: if ((i = prim2num (pe)) == NOTOK
466: && pe -> pe_errno != PE_ERR_NONE)
467: goto bad_pe;
468: vprint ("%d", i);
469: break;
470:
471: #ifdef notyet
472: case PE_ID (PE_CLASS_UNIV, PE_PRIM_REAL):
473: if ((j = prim2real (pe)) == NOTOK
474: && pe -> pe_errno != PE_ERR_NONE)
475: goto bad_pe;
476: vprint ("%g", j);
477: break;
478: #endif
479:
480: case PE_ID (PE_CLASS_UNIV, PE_PRIM_BITS):
481: if ((p = prim2bit (pe)) == NULLPE)
482: goto bad_pe;
483: VPRINT (bit2str (p, "\020"));
484: break;
485:
486: default:
487: bad_pe: ;
488: vtag ((int) pe -> pe_class, (int) pe -> pe_id);
489: /* fall */
490:
491: case PE_ID (PE_CLASS_UNIV, PE_PRIM_OCTS):
492: case PE_ID (PE_CLASS_UNIV, PE_DEFN_IA5S):
493: case PE_ID (PE_CLASS_UNIV, PE_DEFN_NUMS):
494: case PE_ID (PE_CLASS_UNIV, PE_DEFN_PRTS):
495: case PE_ID (PE_CLASS_UNIV, PE_DEFN_T61S):
496: case PE_ID (PE_CLASS_UNIV, PE_DEFN_VTXS):
497: case PE_ID (PE_CLASS_UNIV, PE_DEFN_GENT):
498: case PE_ID (PE_CLASS_UNIV, PE_DEFN_UTCT):
499: case PE_ID (PE_CLASS_UNIV, PE_DEFN_GFXS):
500: case PE_ID (PE_CLASS_UNIV, PE_DEFN_VISS):
501: case PE_ID (PE_CLASS_UNIV, PE_DEFN_GENS):
502: case PE_ID (PE_CLASS_UNIV, PE_DEFN_CHRS):
503: case PE_ID (PE_CLASS_UNIV, PE_PRIM_ODE):
504: vstring (pe);
505: break;
506:
507: case PE_ID (PE_CLASS_UNIV, PE_PRIM_NULL):
508: VPRINT ("NULL");
509: break;
510:
511: case PE_ID (PE_CLASS_UNIV, PE_PRIM_OID):
512: if ((oid = prim2oid (pe)) == NULLOID)
513: goto bad_pe;
514: VPRINT (oid2ode (oid));
515: break;
516: }
517: break;
518:
519: case PE_FORM_CONS:
520: switch (PE_ID (pe -> pe_class, pe -> pe_id)) {
521: case PE_ID (PE_CLASS_UNIV, PE_CONS_SEQ):
522: case PE_ID (PE_CLASS_UNIV, PE_CONS_SET):
523: break;
524:
525: case PE_ID (PE_CLASS_UNIV, PE_CONS_EXTN):
526: (void) print_UNIV_EXTERNAL (pe, 1, NULLIP, NULLVP,
527: NULLCP);
528: return;
529:
530: default:
531: vtag ((int) pe -> pe_class, (int) pe -> pe_id);
532: break;
533: }
534: vpush ();
535: for (p = pe -> pe_cons; p; p = p -> pe_next)
536: vunknown (p);
537: vpop ();
538: break;
539:
540: case PE_FORM_ICONS:
541: vtag ((int) pe -> pe_class, (int) pe -> pe_id);
542: vstring (pe);
543: break;
544: }
545: }
546:
547: /* VPUSHFP/VPOPFP */
548:
549: vpushfp (fp, pe, s, rw)
550: FILE *fp;
551: PE pe;
552: char *s;
553: int rw;
554: {
555: vpushpp ((caddr_t) fp, fprintf, pe, s, rw);
556: }
557:
558: vsetfp (fp, s)
559: FILE * fp;
560: char * s;
561: {
562: vfp = fp;
563: vfnx = fprintf;
564:
565: if(s != NULLCP)
566: (*vfnx) (vfp, "%s\n", s);
567:
568: vlevel = didname = didvpush = didvpop = docomma = 0;
569: }
570:
571: vpopfp ()
572: {
573: (*vfnx) (vfp, "-------\n");
574: (void) fflush (vfp);
575:
576: vpopp ();
577: }
578:
579: /* VPUSHSTR/VPOPSTR */
580:
581: vpushstr (cp)
582: char *cp;
583: {
584: vfp = NULL;
585: vbp = vsp = cp;
586:
587: vlevel = didname = didvpush = didvpop = docomma = 0;
588: }
589:
590:
591: vpopstr ()
592: {
593: while (--vbp >= vsp)
594: if (*vbp != ' ')
595: break;
596: *++vbp = NULL;
597:
598: vfp = stdout;
599: }
600:
601: /* VPUSHPP */
602:
603: vpushpp (pv, pfnx, pe, text, rw)
604: caddr_t pv;
605: IFP pfnx;
606: register PE pe;
607: char *text;
608: int rw;
609: {
610: vfp = (FILE *) pv, vfnx = pfnx;
611:
612: (*vfnx) (vfp, "%s %s", rw ? "read" : "wrote", text ? text : "pdu");
613: if (pe -> pe_context != PE_DFLT_CTX)
614: (*vfnx) (vfp, ", context %d", pe -> pe_context);
615: (*vfnx) (vfp, "\n");
616:
617: vlevel = didname = didvpush = didvpop = docomma = 0;
618: }
619:
620: vpopp ()
621: {
622: vfp = stdout, vfnx = fprintf;
623: }
624:
625:
626: vpushquipu (ps)
627: PS ps;
628: {
629: vps = ps;
630: vfp = NULL;
631:
632: vlevel = didname = didvpush = didvpop = docomma = 0;
633: }
634:
635:
636: vpopquipu ()
637: {
638: vpopp();
639: vps = NULLPS;
640: }
641:
642: /* PVPDU - for pepsy */
643:
644: pvpdu (lp, ind, mod, pe, text, rw)
645: register LLog *lp;
646: int ind; /* index into tables */
647: modtyp *mod; /* pointer to tables */
648: register PE pe;
649: char *text;
650: int rw;
651: {
652: register char *bp;
653: char buffer[BUFSIZ];
654:
655: vfp = (FILE *) lp, vfnx = ll_printf;
656:
657: bp = buffer;
658: (void) sprintf (bp, "%s %s", rw ? "read" : "wrote",
659: text ? text : "pdu");
660: bp += strlen (bp);
661: if (pe -> pe_context != PE_DFLT_CTX) {
662: (void) sprintf (bp, ", context %d", pe -> pe_context);
663: bp += strlen (bp);
664: }
665: LLOG (lp, LLOG_ALL, ("%s", buffer));
666:
667: vlevel = didname = didvpush = didvpop = docomma = 0;
668:
669: if (mod == NULL)
670: (void) vunknown (pe);
671: else
672: (void) prnt_f (ind, mod, pe, 1, NULLIP, NULLVP);
673:
674: (void) ll_printf (lp, "-------\n");
675:
676: (void) ll_sync (lp);
677:
678: vfp = stdout, vfnx = fprintf;
679: }
680:
681: /* MISC */
682:
683: static char *newbuf (i)
684: int i;
685: {
686: static unsigned int len = 0;
687: static char *bp = NULL;
688:
689: if (i++ < len)
690: return bp;
691:
692: if (bp)
693: free (bp);
694: if ((bp = malloc ((unsigned int) i)))
695: len = i;
696: else
697: len = 0;
698:
699: return bp;
700: }
701: /* VPDU - support for backwards compatibility */
702:
703: _vpdu (lp, fnx, pe, text, rw)
704: register LLog *lp;
705: IFP fnx;
706: register PE pe;
707: char *text;
708: int rw;
709: {
710: register char *bp;
711: char buffer[BUFSIZ];
712:
713: vfp = (FILE *) lp, vfnx = ll_printf;
714:
715: bp = buffer;
716: (void) sprintf (bp, "%s %s", rw ? "read" : "wrote",
717: text ? text : "pdu");
718: bp += strlen (bp);
719: if (pe -> pe_context != PE_DFLT_CTX) {
720: (void) sprintf (bp, ", context %d", pe -> pe_context);
721: bp += strlen (bp);
722: }
723: LLOG (lp, LLOG_ALL, ("%s", buffer));
724:
725: vlevel = didname = didvpush = didvpop = docomma = 0;
726:
727: (void) (*fnx) (pe, 1, NULLIP, NULLVP, NULLCP);
728:
729: (void) ll_printf (lp, "-------\n");
730:
731: (void) ll_sync (lp);
732:
733: vfp = stdout, vfnx = fprintf;
734: }
735:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.