lintdump.c revision 34c989574817eca41f72a5f02c848e51cfef32f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)lintdump.c 1.6 06/06/04 SMI (from meem)"
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Tool for dumping lint libraries.
*/
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lnstuff.h" /* silly header name from alint */
typedef struct lsu {
const char *name;
} lsu_t;
#define LSU_HASHSIZE 512
static int justpass = -1;
static int indentlevel = 9;
static const char *progname;
static void info(const char *, ...);
static void infohdr(const char *, const char *, ...);
static void warn(const char *, ...);
static void die(const char *, ...);
static void usage(void);
static void indent(void);
static void unindent(void);
static void print_pass(FILE *);
static void lsu_empty(void);
static lsu_t *lsu_lookup(unsigned long);
int
{
int i, c;
else
progname++;
switch (c) {
case 'i':
break;
case 'p':
usage();
break;
case 'r':
break;
default:
usage();
}
}
usage();
continue;
}
continue;
}
warn("%s: lint library version %d unsupported\n",
continue;
}
/*
* back to the start and print the lint library. Finally,
* empty the table out before dumping the next library.
*/
lsu_empty();
}
return (EXIT_SUCCESS);
}
/*
* Print a lint library.
*/
static void
{
psizes[0] = 0;
print_pass(fp);
}
}
}
/*
* Print out a PASS section of a lint library.
*/
static void
{
int nargs;
char name[1024];
for (;;) {
die("unexpected end of data stream\n");
break;
/*
* Check if this is a file record.
*/
if (wasfile || !justrelpaths)
continue;
}
/*
* Check if this is a function or variable record.
*/
if (nargs < 0)
info("static ");
info("extern ");
die("cannot allocate argument information");
die("unexpected end of data stream\n");
info(" <returns value>");
info(" <use: side-effects context>");
info(" <use: return value context>");
info(" <use: unspecified context>");
info(" { <definition> }");
info(" = <definition>");
info(";\n");
continue;
}
/*
* Check if this is a structure or union record.
*/
info("??? ");
if (showids)
info("{ \n");
indent();
die("unexpected end of data stream\n");
info(";\n");
}
unindent();
info("};\n");
continue;
}
}
}
/*
* Print the C datatype or function `atp' named `name'. If `name' is a
* function, then `nargs' indicates the number of C datatypes pointed to
* by `args'.
*/
static void
{
static const char *basetypes[] = { "",
"char", "unsigned char", "signed char",
"short", "unsigned short", "signed short",
"int", "unsigned int", "signed int",
"long", "unsigned long", "signed long",
"long long", "unsigned long long", "signed long long",
"enum", "float", "double",
"long double", "void", "struct",
"union", "_Bool", "<genchar>",
"<genshort>", "<genint>", "<genlong>",
"<genlonglong>"
};
info("const ");
info("volatile ");
info("integer const ");
if (basetype < 1 ||
switch (basetype) {
case LN_UNION:
case LN_STRUCT:
} else {
if (showids)
else
info(" <anon>");
}
break;
default:
};
}
/*
* Recursively print type modifiers.
*/
static void
{
int arg;
info(" ");
info("*");
}
info(" const ");
info(" volatile ");
if (pos != 0) {
info(" (");
info(")()");
return;
}
if (name[0] == '\0')
return;
info(" ");
info("[]");
info("(");
if (nargs < 0) {
}
if (nargs == 0) {
info("void");
} else {
info(", ");
else if (isvarargs)
info(", ...");
}
}
info(")");
}
}
/*
* Add an LSU entry to the LSU table.
*/
static int
{
return (ENOMEM);
return (ENOMEM);
}
return (0);
}
/*
* Lookup an LSU entry by ID.
*/
static lsu_t *
{
unsigned int i = ty % LSU_HASHSIZE;
return (lsup);
}
return (NULL);
}
/*
* Read all LSU (structure and union definition) records in order to
* build a structure and union name table, called the LSU table.
*/
static void
{
char name[1024];
int nargs;
for (;;) {
return;
break;
if (nargs < 0)
continue;
}
}
}
}
}
/*
* Empty the LSU table.
*/
static void
lsu_empty(void)
{
unsigned int i;
for (i = 0; i < LSU_HASHSIZE; i++) {
}
}
}
/*
* Read the NUL-terminated string at `fp' into `buf', which is at most
* `bufsize' bytes.
*/
static void
{
int c;
size_t i;
for (i = 0; i < bufsize - 1; i++) {
break;
buf[i] = (char)c;
}
buf[i] = '\0';
}
static void
indent(void)
{
indentlevel += 4;
}
static void
unindent(void)
{
indentlevel -= 4;
}
static void
usage(void)
{
" [ lintlib ... ]\n", progname);
}
/* PRINTFLIKE1 */
static void
{
static int complete = 1;
if (complete)
}
/* PRINTFLIKE2 */
static void
{
static int complete = 1;
if (complete)
}
/* PRINTFLIKE1 */
static void
{
}
/* PRINTFLIKE1 */
static void
{
}