// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: report_pli_util.cc
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
* [This function is borrowed verbatim from Andrew Milia's pos_report implementation.]
* This function takes a string that
* is a regular expression and a target string
* 0 - if target string matches pattern
* 1 - if target string does not match string
* 2 - an error in compiling the regular expression
* has occurred and a reason for the error
* has been printed to stderr
* if the pattern is NULL then the pattern that was
* compiled the last time this function was called
int regex_match(const char *pattern
, const char *string
)
static regex_t compiled_regex
= {NULL
}; /* the compiled regex pattern
* (static so that it can be reused between calls)
int return_status
; /* return status from function calls */
if( (!initd
) && (! pattern
) ) {
tf_error("Report: Uninitialized regexp in regexp_match");
/* if pattern is not null then recompile a new pattern */
(return_status
= regcomp( &compiled_regex
, pattern
, REG_NOSUB
)) )
/* we got a regex compile error
* so we need a place to put the error message
char error_message
[1024];
regfree( &compiled_regex
);
regerror( return_status
, &compiled_regex
, error_message
, 1024);
"(%s) line: %d BAD REGULAR EXPRESSION:\"%s\"\n",
if( regexec(&compiled_regex
, string
, (size_t) 0, NULL
, 0) )
* Utility function to convert a format string to a fixed message string.
void parse_format_string(char* msg_str
, char* format_str
, int param
)
char* fmt_mark
= format_str
; // format string pointer
char* msg_mark
= msg_str
;
// Parse the next piece of the format string.
// This is the piece between the current point and the next '%'.
while (target
= (char*)strchr(fmt_mark
, '%'))
// Stash everything between the last '%' and the current '%' into msg_str.
*target
= (char)0; // add a terminating character
format_char
= *(target
+1);
strcpy(msg_mark
, fmt_mark
);
// Move the msg string pointer to the end of what was just copied.
msg_mark
+= (target
- fmt_mark
);
// Output the formatted argument, based on format_char.
count
= sprintf(msg_mark
, "%%");
else if (format_char
== 's')
// Use a special PLI routine to format a C character string.
count
= sprintf(msg_mark
, "%s", tf_getcstringp(param
++));
// Use a PLI routine to format the argument in the same way
count
= sprintf(msg_mark
, "%s", tf_strgetp(param
++, format_char
));
// Move the string pointers past what we just parsed.
// Copy the remainder of the format string.
strcpy(msg_mark
, fmt_mark
);
// Deal with any extra arguments.
while (param
< tf_nump())
if (tf_typep(param
) == tf_nullparam
)
// Print a space for null parameters
// Everything else just gets decimal format.
count
= sprintf(msg_mark
, "%s", tf_strgetp(param
, 'd'));