8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / cmd / svr4pkg / libinst / echo.c
blobadd6b2f29fcec9ff079298c3a0e079f479b40ea7
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
33 * System includes
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40 #include <sys/types.h>
41 #include <zone.h>
44 * consolidation pkg command library includes
47 #include "pkglib.h"
50 * internal global variables
53 static boolean_t debugFlag = B_FALSE; /* debug messages enabled? */
54 static boolean_t echoFlag = B_TRUE; /* interactive msgs enabled? */
57 * *****************************************************************************
58 * global external (public) functions
59 * *****************************************************************************
63 * Name: echo
64 * Synopsis: Output an interactive message if interaction is enabled
65 * Description: Main method for outputting an interactive message; call to
66 * output interactive message if interation has not been disabled
67 * by a previous call to echoSetFlag(0).
68 * Arguments: format - [RO, RO*] (char *)
69 * printf-style format for debugging message to be output
70 * VARG_LIST - [RO] (?)
71 * arguments as appropriate to 'format' specified
72 * Returns: void
75 /*PRINTFLIKE1*/
76 void
77 echo(char *fmt, ...)
79 va_list ap;
81 /* output message if echoing is enabled */
83 if (echoFlag == B_TRUE) {
84 va_start(ap, fmt);
86 (void) vfprintf(stderr, fmt, ap);
88 va_end(ap);
90 (void) putc('\n', stderr);
95 * Name: echoDebug
96 * Synopsis: Output a debugging message if debugging is enabled
97 * Description: Main method for outputting a debugging message; call to
98 * output debugging message if debugging has been enabled
99 * by a previous call to echoDebugSetFlag(1).
100 * Arguments: format - [RO, RO*] (char *)
101 * printf-style format for debugging message to be output
102 * VARG_LIST - [RO] (?)
103 * arguments as appropriate to 'format' specified
104 * Returns: void
105 * NOTE: format of message will be:
106 * # [ aaa bbb ccc ] message
107 * where: aaa - process i.d.
108 * bbb - zone i.d.
109 * ccc - name of program
110 * for example:
111 * # [ 25685 0 pkgadd ] unable to get package list
114 /*PRINTFLIKE1*/
115 void
116 echoDebug(char *a_fmt, ...)
118 va_list ap;
120 /* output debugging message if debugging is enabled */
122 if (debugFlag == B_TRUE) {
123 char *p = get_prog_name();
125 (void) fprintf(stderr, "# [%6d %3d", getpid(), getzoneid());
127 if ((p != (char *)NULL) && (*p != '\0')) {
128 fprintf(stderr, " %-11s", p);
131 (void) fprintf(stderr, "] ");
133 va_start(ap, a_fmt);
135 (void) vfprintf(stderr, a_fmt, ap);
137 va_end(ap);
139 (void) putc('\n', stderr);
144 * get the "interactive message enabled" flag
147 boolean_t
148 echoGetFlag(void) {
149 return (echoFlag);
153 * set the "interactive message enabled" flag
156 boolean_t
157 echoSetFlag(boolean_t a_echoFlag)
159 boolean_t oldvalue;
161 oldvalue = echoFlag;
162 echoFlag = a_echoFlag;
163 return (oldvalue);
167 * get the "debugging message enabled" flag
170 boolean_t
171 echoDebugGetFlag(void) {
172 return (debugFlag);
176 * set the "debugging message enabled" flag
179 boolean_t
180 echoDebugSetFlag(boolean_t a_debugFlag)
182 boolean_t oldvalue;
184 oldvalue = debugFlag;
185 debugFlag = a_debugFlag;
186 return (oldvalue);