17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * db.c -- the tiny database for trace.  Only stores
297c478bd9Sstevel@tonic-gate  *	global things: see symtab for per-function data.
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <libgen.h>
367c478bd9Sstevel@tonic-gate #include <limits.h>
377c478bd9Sstevel@tonic-gate #include <sys/param.h>
387c478bd9Sstevel@tonic-gate #include "parser.h"
397c478bd9Sstevel@tonic-gate #include "trace.h"
407c478bd9Sstevel@tonic-gate #include "util.h"
417c478bd9Sstevel@tonic-gate #include "errlog.h"
427c478bd9Sstevel@tonic-gate #include "db.h"
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate static int curr_print_type;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate static struct {
477c478bd9Sstevel@tonic-gate 	char	Current_Library[PATH_MAX];
487c478bd9Sstevel@tonic-gate 	char	Current_File[PATH_MAX];
497c478bd9Sstevel@tonic-gate 	char	Output_File[PATH_MAX];
507c478bd9Sstevel@tonic-gate 	char	Current_Interface[PATH_MAX];
517c478bd9Sstevel@tonic-gate 	char	Source_Directory[PATH_MAX];
527c478bd9Sstevel@tonic-gate 	char	Target_Directory[PATH_MAX];
537c478bd9Sstevel@tonic-gate 	int	NFiles;
547c478bd9Sstevel@tonic-gate 	int	Verbosity;
557c478bd9Sstevel@tonic-gate 	char	Library_List[PATH_MAX];
567c478bd9Sstevel@tonic-gate 	char	Translator[MAXNAMELEN];
577c478bd9Sstevel@tonic-gate 	char	Test_Type[MAXNAMELEN];
587c478bd9Sstevel@tonic-gate 	char	Kludge[PATH_MAX];
597c478bd9Sstevel@tonic-gate 	int	Flags;
607c478bd9Sstevel@tonic-gate 	char const *Arch;
617c478bd9Sstevel@tonic-gate 	table_t	*Print_Types;
627c478bd9Sstevel@tonic-gate 	table_t	*File;
637c478bd9Sstevel@tonic-gate 	table_t	*Exclusions;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate } Database;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* Generated by m4 -- character string values */
697c478bd9Sstevel@tonic-gate void
db_set_current_library(char const * p)707c478bd9Sstevel@tonic-gate db_set_current_library(char const *p)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_set_current_library() {");
737c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Current_Library, p,
747c478bd9Sstevel@tonic-gate 	    sizeof (Database.Current_Library));
75*07c94cbfSToomas Soome 	Database.Current_Library[sizeof (Database.Current_Library) - 1] = '\0';
767c478bd9Sstevel@tonic-gate 	errlog(END, "}");
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate char *
db_get_current_library(void)807c478bd9Sstevel@tonic-gate db_get_current_library(void)
817c478bd9Sstevel@tonic-gate {
827c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_get_current_library() {"); errlog(END, "}");
837c478bd9Sstevel@tonic-gate 	return (Database.Current_Library);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate void
db_set_current_interface(char const * p)877c478bd9Sstevel@tonic-gate db_set_current_interface(char const *p)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_set_current_interface() {");
907c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Current_Interface, p,
917c478bd9Sstevel@tonic-gate 	    sizeof (Database.Current_Interface));
927c478bd9Sstevel@tonic-gate 	Database.Current_Interface[
937c478bd9Sstevel@tonic-gate 		sizeof (Database.Current_Interface) - 1] = '\0';
947c478bd9Sstevel@tonic-gate 	errlog(END, "}");
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate char *
db_get_current_interface(void)987c478bd9Sstevel@tonic-gate db_get_current_interface(void)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_get_current_interface() {"); errlog(END, "}");
1017c478bd9Sstevel@tonic-gate 	return (Database.Current_Interface);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate void
db_set_source_directory(char const * p)1067c478bd9Sstevel@tonic-gate db_set_source_directory(char const *p)
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_set_source_directory() {");
1097c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Source_Directory, p,
1107c478bd9Sstevel@tonic-gate 	    sizeof (Database.Source_Directory));
1117c478bd9Sstevel@tonic-gate 	Database.Source_Directory[sizeof (Database.Source_Directory) - 1] =
1127c478bd9Sstevel@tonic-gate 	    '\0';
1137c478bd9Sstevel@tonic-gate 	errlog(END, "}");
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate char *
db_get_source_directory(void)1177c478bd9Sstevel@tonic-gate db_get_source_directory(void)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_get_source_directory() {"); errlog(END, "}");
1207c478bd9Sstevel@tonic-gate 	return (Database.Source_Directory);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate void
db_set_target_directory(char const * p)1257c478bd9Sstevel@tonic-gate db_set_target_directory(char const *p)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_set_target_directory() {");
1287c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Target_Directory, p,
1297c478bd9Sstevel@tonic-gate 	    sizeof (Database.Target_Directory));
1307c478bd9Sstevel@tonic-gate 	Database.Target_Directory[sizeof (Database.Target_Directory) - 1] =
1317c478bd9Sstevel@tonic-gate 	    '\0';
1327c478bd9Sstevel@tonic-gate 	errlog(END, "}");
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate char *
db_get_target_directory(void)1367c478bd9Sstevel@tonic-gate db_get_target_directory(void)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_get_target_directory() {"); errlog(END, "}");
1397c478bd9Sstevel@tonic-gate 	return (Database.Target_Directory);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate void
db_set_current_file(char const * p)1437c478bd9Sstevel@tonic-gate db_set_current_file(char const *p)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Current_File, p,
1467c478bd9Sstevel@tonic-gate 		sizeof (Database.Current_File));
1477c478bd9Sstevel@tonic-gate 	Database.Current_File[sizeof (Database.Current_File) - 1] = '\0';
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate char *
db_get_current_file(void)1517c478bd9Sstevel@tonic-gate db_get_current_file(void)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	return (Database.Current_File);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * Output File -- set from either -o option or file name.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate void
db_set_output_file(char const * p)1617c478bd9Sstevel@tonic-gate db_set_output_file(char const *p)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate 	char	*q;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_set_output_file() {");
1667c478bd9Sstevel@tonic-gate 	if (p == NULL) {
1677c478bd9Sstevel@tonic-gate 		errlog(END, "}");
1687c478bd9Sstevel@tonic-gate 		return;
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	(void) strncpy(Database.Output_File, p, sizeof (Database.Output_File));
1727c478bd9Sstevel@tonic-gate 	if ((q = strrchr(Database.Output_File, '.')) != NULL) {
1737c478bd9Sstevel@tonic-gate 		*q = '\0';
1747c478bd9Sstevel@tonic-gate 	} else {
1757c478bd9Sstevel@tonic-gate 		Database.Output_File[sizeof (Database.Output_File) - 1] = '\0';
1767c478bd9Sstevel@tonic-gate 	}
1777c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "output file = '%s'\n", Database.Output_File);
1787c478bd9Sstevel@tonic-gate 	errlog(END, "}");
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate char *
db_get_output_file(void)1827c478bd9Sstevel@tonic-gate db_get_output_file(void)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	static char buffer[MAXLINE];
1857c478bd9Sstevel@tonic-gate 	char	*p, *q;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_get_output_file() {");
188*07c94cbfSToomas Soome 	if (*Database.Output_File != '\0') {
1897c478bd9Sstevel@tonic-gate 		/* It was set with the -o option */
1907c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "output file from -o = '%s'\n",
1917c478bd9Sstevel@tonic-gate 			Database.Output_File);
1927c478bd9Sstevel@tonic-gate 		errlog(END, "}");
1937c478bd9Sstevel@tonic-gate 		return (Database.Output_File);
1947c478bd9Sstevel@tonic-gate 	} else {
1957c478bd9Sstevel@tonic-gate 		/* We generate it from the current input file. */
1967c478bd9Sstevel@tonic-gate 		(void) strncpy(buffer, Database.Current_File, sizeof (buffer));
1977c478bd9Sstevel@tonic-gate 		p = basename(buffer);
1987c478bd9Sstevel@tonic-gate 		if ((q = strrchr(p, '.')) != NULL) {
1997c478bd9Sstevel@tonic-gate 			*q = '\0';
2007c478bd9Sstevel@tonic-gate 		}
2017c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "output file from input = '%s'\n", p);
2027c478bd9Sstevel@tonic-gate 		errlog(END, "}");
2037c478bd9Sstevel@tonic-gate 		return (p);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Manually written table code.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * add_print_types -- add legal print types.  Check for void
2137c478bd9Sstevel@tonic-gate  *	moved here out of collect, as collect isn't good enough
2147c478bd9Sstevel@tonic-gate  *	quality of parser to have a single code path for
2157c478bd9Sstevel@tonic-gate  *	types. (Shudder)  Subsequently changed to use special-purpose
2167c478bd9Sstevel@tonic-gate  *	test for membership.  Also shudder!
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate void
db_add_print_types(char * print_type,char * c_type)2207c478bd9Sstevel@tonic-gate db_add_print_types(char *print_type, char *c_type)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate 	char    buffer[MAXLINE];
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_add_print_types() {");
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	(void) snprintf(buffer, sizeof (buffer), "%s, %s", print_type, c_type);
2277c478bd9Sstevel@tonic-gate 	if (Database.Print_Types == NULL) {
2287c478bd9Sstevel@tonic-gate 		Database.Print_Types = create_string_table(50);
2297c478bd9Sstevel@tonic-gate 	}
2307c478bd9Sstevel@tonic-gate 	if (in_string_table(Database.Print_Types, print_type) == NO) {
2317c478bd9Sstevel@tonic-gate 		Database.Print_Types = add_string_table(Database.Print_Types,
2327c478bd9Sstevel@tonic-gate 		    &buffer[0]);
2337c478bd9Sstevel@tonic-gate 	}
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	errlog(END, "}");
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate char *
db_get_first_print_type(void)2397c478bd9Sstevel@tonic-gate db_get_first_print_type(void)
2407c478bd9Sstevel@tonic-gate {
2417c478bd9Sstevel@tonic-gate 	curr_print_type = 1;
2427c478bd9Sstevel@tonic-gate 	return (get_string_table(Database.Print_Types, 0));
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate char *
db_get_next_print_type(void)2467c478bd9Sstevel@tonic-gate db_get_next_print_type(void)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	return (get_string_table(Database.Print_Types, curr_print_type++));
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate void
db_sort_print_types(void)2547c478bd9Sstevel@tonic-gate db_sort_print_types(void)
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "db_sort_print_types() {");
2577c478bd9Sstevel@tonic-gate 	sort_string_table(Database.Print_Types);
2587c478bd9Sstevel@tonic-gate 	errlog(END, "}");
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate void
db_set_arch(char const * arch)2627c478bd9Sstevel@tonic-gate db_set_arch(char const *arch)
2637c478bd9Sstevel@tonic-gate {
2647c478bd9Sstevel@tonic-gate 	Database.Arch = arch;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate char const *
db_get_arch(void)2687c478bd9Sstevel@tonic-gate db_get_arch(void)
2697c478bd9Sstevel@tonic-gate {
2707c478bd9Sstevel@tonic-gate 	return (Database.Arch);
2717c478bd9Sstevel@tonic-gate }
272