* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: fscope.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* @(#)fscope.c 1.1 02/05/02
* Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved
* Use is subject to license terms.
"fscope -f <index-file> [flags]\n"
" -f <file> : source index file, (default is fscope.idx)\n"
" -m <mode> : is the data format written to <output> or stdout\n"
" -o <output> : spacify the target for a extract (-e) operation\n"
" -t <text> : extract any reference matching <text>\n"
" -s <text> : extract only string references matching <text>\n"
" -d <symbol> : extract definitions matching <symbol>\n"
" -c <symbol> : extract the caller information for <symbol>\n"
" -C <symbol> : extract the symbols called by <symbol>\n"
" -l <value> : extract symbols with refcounts less than <value>\n"
" -g <value> : extract symbols with refcounts greater than <value>\n"
" -a : extract all symbols in <mode> format\n"
" -e : expand path using getenv()\n"
" -r : use regexp to do symbol matching\n"
" -R <root> : replace symbolic ${..} with <root>\n"
" -i : interactive mode\n"
" -O <file> : write current index file as <file>\n";
extract_noop(extract_t
*info
)
output_mode_t outputmodes
[] = {
{ "grep", extract_noop
, xref_grep_format
, extract_noop
},
{ "tag", xref_tag_init
, xref_tag_format
, xref_tag_fini
},
{ "etag", xref_tag_init
, xref_etag_format
, xref_tag_fini
},
output_mode_t
*mptr
= outputmodes
;
printf("\nSupported <modes> for -m are: ");
while (mptr
->name
!= NULL
) {
if (mptr
->name
[0] != '!') {
printf("%s ", mptr
->name
);
expand_filename(extract_t
*info
, xref_t
*cref
)
char *file
= cref
->file
->name
;
if (info
->flags
& FLAG_ABS_PATH
) {
if (info
->root_buf
!= NULL
) {
bp
= strstr(file
, bp_env
);
if (info
->root
== NULL
) {
file
= info
->root_buf
= malloc(strlen(base
) + strlen(bp
) + 1);
sprintf(file
, "%s%s", base
, bp
);
select_output_mode(char *type
)
output_mode_t
*mptr
= outputmodes
;
output_mode_t
*found
= NULL
;
while (mptr
->name
!= NULL
) {
if (strcmp(mptr
->name
, type
) == 0) {
limit_item(extract_t
*info
, search_t
*item
)
xref_t
*cref
= item
->xref
;
if ((cref
->called_by
.insert
< info
->lo
) &&
(cref
->called_by
.insert
> info
->hi
))
extract_item(extract_t
*info
, search_t
*item
)
info
->extract
->update(info
, item
->xref
);
dump_refs(extract_t
*info
, xref_t
*cref
, ref_t
*rref
)
for (j
= 0; j
< rref
->insert
; j
++) {
info
->extract
->update(info
, rref
->ptr
[j
]);
dump_callers(extract_t
*info
, search_t
*item
)
dump_refs(info
, cref
, &cref
->called_by
);
dump_calls(extract_t
*info
, search_t
*item
)
dump_refs(info
, cref
, &cref
->calls
);
main(int argc
, char *argv
[])
char *options
= "hf:m:d:c:C:o:il:g:as:erR:t:v";
info
.extract
= select_output_mode("grep");
while ((c
= getopt(argc
, argv
, options
)) != EOF
)
info
.extract
= select_output_mode(optarg
);
if (info
.extract
== NULL
) {
"Unsupported extract mode: %s\n",
info
.type
= TYPE_CALLERS
;
info
.outputfile
= optarg
;
info
.flags
|= FLAG_REGEXP
;
info
.type
= TYPE_INTERACT
;
info
.extract
= select_output_mode("!interact");
info
.flags
|= FLAG_ABS_PATH
;
info
.flags
|= FLAG_ABS_PATH
;
info
.flags
|= FLAG_VERBOSE
;
if (info
.indexfile
== NULL
) {
info
.indexfile
= "fscope.idx";
info
.state
= xref_load_file(info
.indexfile
,
(info
.flags
& FLAG_VERBOSE
));
if (info
.state
== NULL
) {
fprintf(stderr
, "%s: failed to load\n", info
.indexfile
);
if (info
.type
== TYPE_INTERACT
) {
xref_interactive_mode(&info
);
if (info
.outputfile
== NULL
) {
info
.outfd
= fopen(info
.outputfile
, "w");
if (info
.outfd
== NULL
) {
fprintf(stderr
, "Can create outputfile: %s\n",
info
.extract
->init(&info
);
if (info
.symbol
== NULL
) {
info
.flags
|= FLAG_REGEXP
;
list
= build_searchlist(&info
, NULL
, XREF_DEFINITION
);
list
= search_list(&info
, 1, list
, limit_item
);
iterate_list(&info
, list
, extract_item
);
list
= build_searchlist(&info
, NULL
, XREF_DEFINITION
);
iterate_list(&info
, list
, dump_calls
);
list
= build_searchlist(&info
, NULL
, XREF_DEFINITION
);
iterate_list(&info
, list
, dump_callers
);
list
= build_searchlist(&info
, NULL
, XREF_DEFINITION
);
iterate_list(&info
, list
, extract_item
);
list
= build_searchlist(&info
, NULL
, XREF_STRING
);
iterate_list(&info
, list
, extract_item
);
list
= build_searchlist(&info
, NULL
,
(XREF_STRING
| XREF_DEFINITION
));
iterate_list(&info
, list
, extract_item
);
info
.extract
->fini(&info
);
if (info
.outputfile
!= NULL
) {
xref_free_state(info
.state
);