2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * trace.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All right reserved.
2N/A *
2N/A */
2N/A
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/trace.c 1.3 1995/06/12 20:24:05 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A#include <fcntl.h>
2N/A#include <string.h>
2N/A#include <stdarg.h>
2N/A#include <stdlib.h>
2N/A
2N/Astatic int __m_tracing = FALSE;
2N/A
2N/A/*f
2N/A * Write a formatted string into a trace file.
2N/A */
2N/Avoid
2N/A__m_trace(const char *fmt, ...)
2N/A{
2N/A va_list vp;
2N/A static FILE *fp;
2N/A static int initialized = FALSE;
2N/A
2N/A if (!__m_tracing)
2N/A return;
2N/A
2N/A if (!initialized) {
2N/A fp = fopen("trace.out", "wF");
2N/A if (fp == (FILE *) 0) {
2N/A fprintf(stderr, "Program cannot open \"trace.out\".\n");
2N/A exit(1);
2N/A }
2N/A initialized = TRUE;
2N/A }
2N/A
2N/A va_start(vp, fmt);
2N/A (void) vfprintf(fp, fmt, vp);
2N/A va_end(vp);
2N/A fputc('\n', fp);
2N/A}
2N/A
2N/Aint
2N/A(__m_return_code)(const char *s, int code)
2N/A{
2N/A switch (code) {
2N/A case OK:
2N/A __m_trace("%s returned OK.", s);
2N/A break;
2N/A case ERR:
2N/A __m_trace("%s returned ERR.", s);
2N/A break;
2N/A case KEY_CODE_YES:
2N/A __m_trace("%s returned KEY_CODE_YES.", s);
2N/A break;
2N/A default:
2N/A __m_trace("%s returned code %d", s, code);
2N/A }
2N/A
2N/A return code;
2N/A}
2N/A
2N/Aint
2N/A(__m_return_int)(const char *s, int value)
2N/A{
2N/A __m_trace("%s returned %d", s, value);
2N/A
2N/A return value;
2N/A}
2N/A
2N/Achtype
2N/A(__m_return_chtype)(const char *s, chtype ch)
2N/A{
2N/A __m_trace("%s returned %lx", s, ch);
2N/A
2N/A return ch;
2N/A}
2N/A
2N/Avoid *
2N/A(__m_return_pointer)(const char *s, const void *ptr)
2N/A{
2N/A if (ptr == (void *) 0)
2N/A __m_trace("%s returned NULL.", s);
2N/A else
2N/A __m_trace("%s returned %p.", s, ptr);
2N/A
2N/A return (void *) ptr;
2N/A}
2N/A
2N/A#undef __m_return_void
2N/A
2N/Avoid
2N/A__m_return_void(const char *s)
2N/A{
2N/A __m_trace("%s returns void.");
2N/A}
2N/A
2N/A/*f
2N/A * Turn tracing on
2N/A */
2N/Avoid
2N/Atraceon()
2N/A{
2N/A __m_tracing = TRUE;
2N/A __m_trace("traceon()\ntraceon() returns void.");
2N/A}
2N/A
2N/A/*f
2N/A * Turn tracing off
2N/A */
2N/Avoid
2N/Atraceoff()
2N/A{
2N/A __m_trace("traceoff()\ntraceoff() returns void.");
2N/A __m_tracing = FALSE;
2N/A}
2N/A