xref: /titanic_41/usr/src/cmd/abi/spectrans/spec2trace/db.c (revision d5ace9454616652a717c9831d949dffa319381f9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * db.c -- the tiny database for trace.  Only stores
31  *	global things: see symtab for per-function data.
32  *
33  */
34 
35 #include <stdio.h>
36 #include <string.h>
37 #include <libgen.h>
38 #include <limits.h>
39 #include <sys/param.h>
40 #include "parser.h"
41 #include "trace.h"
42 #include "util.h"
43 #include "errlog.h"
44 #include "db.h"
45 
46 static int curr_print_type;
47 
48 static struct {
49 	char	Current_Library[PATH_MAX];
50 	char	Current_File[PATH_MAX];
51 	char	Output_File[PATH_MAX];
52 	char	Current_Interface[PATH_MAX];
53 	char	Source_Directory[PATH_MAX];
54 	char	Target_Directory[PATH_MAX];
55 	int	NFiles;
56 	int	Verbosity;
57 	char	Library_List[PATH_MAX];
58 	char	Translator[MAXNAMELEN];
59 	char	Test_Type[MAXNAMELEN];
60 	char	Kludge[PATH_MAX];
61 	int	Flags;
62 	char const *Arch;
63 	table_t	*Print_Types;
64 	table_t	*File;
65 	table_t	*Exclusions;
66 
67 } Database;
68 
69 
70 /* Generated by m4 -- character string values */
71 void
72 db_set_current_library(char const *p)
73 {
74 	errlog(BEGIN, "db_set_current_library() {");
75 	(void) strncpy(Database.Current_Library, p,
76 	    sizeof (Database.Current_Library));
77 	Database.Current_Library[sizeof (Database.Current_Library) - 1] = NULL;
78 	errlog(END, "}");
79 }
80 
81 char *
82 db_get_current_library(void)
83 {
84 	errlog(BEGIN, "db_get_current_library() {"); errlog(END, "}");
85 	return (Database.Current_Library);
86 }
87 
88 void
89 db_set_current_interface(char const *p)
90 {
91 	errlog(BEGIN, "db_set_current_interface() {");
92 	(void) strncpy(Database.Current_Interface, p,
93 	    sizeof (Database.Current_Interface));
94 	Database.Current_Interface[
95 		sizeof (Database.Current_Interface) - 1] = '\0';
96 	errlog(END, "}");
97 }
98 
99 char *
100 db_get_current_interface(void)
101 {
102 	errlog(BEGIN, "db_get_current_interface() {"); errlog(END, "}");
103 	return (Database.Current_Interface);
104 }
105 
106 
107 void
108 db_set_source_directory(char const *p)
109 {
110 	errlog(BEGIN, "db_set_source_directory() {");
111 	(void) strncpy(Database.Source_Directory, p,
112 	    sizeof (Database.Source_Directory));
113 	Database.Source_Directory[sizeof (Database.Source_Directory) - 1] =
114 	    '\0';
115 	errlog(END, "}");
116 }
117 
118 char *
119 db_get_source_directory(void)
120 {
121 	errlog(BEGIN, "db_get_source_directory() {"); errlog(END, "}");
122 	return (Database.Source_Directory);
123 }
124 
125 
126 void
127 db_set_target_directory(char const *p)
128 {
129 	errlog(BEGIN, "db_set_target_directory() {");
130 	(void) strncpy(Database.Target_Directory, p,
131 	    sizeof (Database.Target_Directory));
132 	Database.Target_Directory[sizeof (Database.Target_Directory) - 1] =
133 	    '\0';
134 	errlog(END, "}");
135 }
136 
137 char *
138 db_get_target_directory(void)
139 {
140 	errlog(BEGIN, "db_get_target_directory() {"); errlog(END, "}");
141 	return (Database.Target_Directory);
142 }
143 
144 void
145 db_set_current_file(char const *p)
146 {
147 	(void) strncpy(Database.Current_File, p,
148 		sizeof (Database.Current_File));
149 	Database.Current_File[sizeof (Database.Current_File) - 1] = '\0';
150 }
151 
152 char *
153 db_get_current_file(void)
154 {
155 	return (Database.Current_File);
156 }
157 
158 
159 /*
160  * Output File -- set from either -o option or file name.
161  */
162 void
163 db_set_output_file(char const *p)
164 {
165 	char	*q;
166 
167 	errlog(BEGIN, "db_set_output_file() {");
168 	if (p == NULL) {
169 		errlog(END, "}");
170 		return;
171 	}
172 
173 	(void) strncpy(Database.Output_File, p, sizeof (Database.Output_File));
174 	if ((q = strrchr(Database.Output_File, '.')) != NULL) {
175 		*q = '\0';
176 	} else {
177 		Database.Output_File[sizeof (Database.Output_File) - 1] = '\0';
178 	}
179 	errlog(VERBOSE, "output file = '%s'\n", Database.Output_File);
180 	errlog(END, "}");
181 }
182 
183 char *
184 db_get_output_file(void)
185 {
186 	static char buffer[MAXLINE];
187 	char	*p, *q;
188 
189 	errlog(BEGIN, "db_get_output_file() {");
190 	if (*Database.Output_File != NULL) {
191 		/* It was set with the -o option */
192 		errlog(VERBOSE, "output file from -o = '%s'\n",
193 			Database.Output_File);
194 		errlog(END, "}");
195 		return (Database.Output_File);
196 	} else {
197 		/* We generate it from the current input file. */
198 		(void) strncpy(buffer, Database.Current_File, sizeof (buffer));
199 		p = basename(buffer);
200 		if ((q = strrchr(p, '.')) != NULL) {
201 			*q = '\0';
202 		}
203 		errlog(VERBOSE, "output file from input = '%s'\n", p);
204 		errlog(END, "}");
205 		return (p);
206 	}
207 }
208 
209 /*
210  * Manually written table code.
211  */
212 
213 /*
214  * add_print_types -- add legal print types.  Check for void
215  *	moved here out of collect, as collect isn't good enough
216  *	quality of parser to have a single code path for
217  *	types. (Shudder)  Subsequently changed to use special-purpose
218  *	test for membership.  Also shudder!
219  */
220 
221 void
222 db_add_print_types(char *print_type, char *c_type)
223 {
224 	char    buffer[MAXLINE];
225 
226 	errlog(BEGIN, "db_add_print_types() {");
227 
228 	(void) snprintf(buffer, sizeof (buffer), "%s, %s", print_type, c_type);
229 	if (Database.Print_Types == NULL) {
230 		Database.Print_Types = create_string_table(50);
231 	}
232 	if (in_string_table(Database.Print_Types, print_type) == NO) {
233 		Database.Print_Types = add_string_table(Database.Print_Types,
234 		    &buffer[0]);
235 	}
236 
237 	errlog(END, "}");
238 }
239 
240 char *
241 db_get_first_print_type(void)
242 {
243 	curr_print_type = 1;
244 	return (get_string_table(Database.Print_Types, 0));
245 }
246 
247 char *
248 db_get_next_print_type(void)
249 {
250 
251 	return (get_string_table(Database.Print_Types, curr_print_type++));
252 }
253 
254 
255 void
256 db_sort_print_types(void)
257 {
258 	errlog(BEGIN, "db_sort_print_types() {");
259 	sort_string_table(Database.Print_Types);
260 	errlog(END, "}");
261 }
262 
263 void
264 db_set_arch(char const *arch)
265 {
266 	Database.Arch = arch;
267 }
268 
269 char const *
270 db_get_arch(void)
271 {
272 	return (Database.Arch);
273 }
274