xref: /onnv-gate/usr/src/cmd/sgs/lex/common/allprint.c (revision 6951:59445bec7ef4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6951Sab196087  * Common Development and Distribution License (the "License").
6*6951Sab196087  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6951Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <stdio.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <sys/euc.h>
340Sstevel@tonic-gate #include <ctype.h>
350Sstevel@tonic-gate #include <widec.h>
360Sstevel@tonic-gate #include <wctype.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #pragma weak yyout
390Sstevel@tonic-gate extern FILE *yyout;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #ifndef JLSLEX
420Sstevel@tonic-gate #define	CHR    char
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef WOPTION
460Sstevel@tonic-gate #define	CHR	wchar_t
470Sstevel@tonic-gate #define	sprint	sprint_w
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #ifdef EOPTION
510Sstevel@tonic-gate #define	CHR	wchar_t
520Sstevel@tonic-gate #endif
530Sstevel@tonic-gate 
540Sstevel@tonic-gate void
allprint(CHR c)550Sstevel@tonic-gate allprint(CHR c)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate 	switch (c) {
580Sstevel@tonic-gate 	case '\n':
59*6951Sab196087 		(void) fprintf(yyout, "\\n");
600Sstevel@tonic-gate 		break;
610Sstevel@tonic-gate 	case '\t':
62*6951Sab196087 		(void) fprintf(yyout, "\\t");
630Sstevel@tonic-gate 		break;
640Sstevel@tonic-gate 	case '\b':
65*6951Sab196087 		(void) fprintf(yyout, "\\b");
660Sstevel@tonic-gate 		break;
670Sstevel@tonic-gate 	case ' ':
68*6951Sab196087 		(void) fprintf(yyout, "\\_");
690Sstevel@tonic-gate 		break;
700Sstevel@tonic-gate 	default:
710Sstevel@tonic-gate 		if (!iswprint(c))
72*6951Sab196087 			(void) fprintf(yyout, "\\x%-2x", c);
730Sstevel@tonic-gate 		else
74*6951Sab196087 			(void) putwc(c, yyout);
750Sstevel@tonic-gate 		break;
760Sstevel@tonic-gate 	}
770Sstevel@tonic-gate }
780Sstevel@tonic-gate 
790Sstevel@tonic-gate void
sprint(s)800Sstevel@tonic-gate sprint(s)
810Sstevel@tonic-gate CHR *s;
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	while (*s)
840Sstevel@tonic-gate 		allprint(*s++);
850Sstevel@tonic-gate }
86