/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1997-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "parser.h"
#include "trace.h"
#include "util.h"
#include "db.h"
#include "symtab.h"
#include "io.h"
#include "printfuncs.h"
#include "errlog.h"
static int prepare_printf_part(ENTRY *, char *, char *, int);
static char *space_to_uscore(char const *);
/*
* generate_printf -- make the cleanest possible printf for the
* ending in ") = ", or ) if its a void function we're doing.
*/
void
{
ENTRY *e;
char *p, *name;
int l, n;
p = &arglist[0];
l = (int)sizeof (arglist);
*p = NULL;
if (is_void(e)) {
/* This placeholder means there are no real args. */
break;
}
/* Insert punctuation. */
if (p != &arglist[0]) {
}
/* It's a varargs indicator instead */
} else {
n = prepare_printf_part(e, name, p, l);
l -= n;
p += n;
*(p+1) = NULL;
}
}
/* It is a function returning void, or a function */
/* which doesn't return. Close off args. */
} else {
/* Make some more printf for the return type. */
(void) prepare_printf_part(f, "_return", p, l);
}
}
/*
* for printing non-verbose parameter lists
*/
static int
{
char *bt;
int li;
bt = basetype_of(e);
/* It's a string, print the beginning of it. */
/*CSTYLED*/
",\n\tabi_strpsz, (%s) ? %s : nilstr",
} else {
/* Just print a hex value */
}
return (size);
}
/*
* generate_printfunc_calls -- generate print commands for primitive types
* and calls to print functions for composite types, cleanly.
* Needs to know about base types of primitives, difference
* between primitives and composite types: TBD.
*/
void
{
ENTRY *e;
char *name;
char *pf_str_name;
int li;
char *format;
if (is_void(e)) {
break;
}
"ABISTREAM);\n");
}
" fprintf(ABISTREAM, \" %s = \");\n",
name);
/*
* If we're dealing with a scalar (non-pointer) then
* we need to call the printer with a &
*/
if (li)
format = "\tspf_prtype(ABISTREAM, pf_%s_str, %d, "
"(void const *)%s);\n";
else
format = "\tspf_prtype(ABISTREAM, pf_%s_str, %d, "
"(void const *)&%s);\n";
}
if (is_void(f)) {
/*EMPTY*/;
} else {
if (li)
format = "\tspf_prtype(ABISTREAM, pf_%s_str, %d, "
"(void const *)_return);\n";
else
format = "\tspf_prtype(ABISTREAM, pf_%s_str, %d, "
"(void const *)&_return);\n";
}
}
/*
* Print Function Pointers -- definition, declaration and initialization.
* Use is above...
*/
/*
* generate_print_definitions -- generate variable definitions and
* initialize them to NULL.
* These will be set non-null by a lazy evaluation in the
* main.c file if and only if the print function will be used.
* All print functions which can be called must be defined.
*/
void
{
char *print_type,
*c_type,
for (print_type = db_get_first_print_type();
print_type != NULL;
print_type = db_get_next_print_type()) {
"char const *pf_%s_str = \"%s\";\n",
*--c_type = ',';
}
}
/*
* generate_print_declarations -- generate variable declarations
* for the strings that'll be used as arguments to the type
* printing function.
*/
void
{
char *print_type,
*c_type,
for (print_type = symtab_get_first_print_type();
print_type != NULL;
*--c_type = ',';
}
}
/*
* is_void -- see if a type is void.
*/
int
{
if ((e != NULL) &&
return (1);
else
return (0);
}
static char *
{
char *strp, *p;
for (p = strp; *p != '\0'; p++)
if (*p == ' ')
*p = '_';
return (strp);
}