e0f20230e666ff88b51dac643b9deaa5837bdc21
* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: interact.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 ============================================
* @(#)interact.c 1.1 02/05/02
* Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved
* Copyright Use is subject to license terms.
typedef struct ISTRUCT_T
{
WINDOW
*win
; /* main screen */
int info_line
; /* line# for information text */
int cmdnum
; /* command selected */
int lmargin
; /* left margin of selected command */
int col
; /* cursor position on cmd line */
int line
; /* which line we are on */
int error
; /* error status, status string contains msg */
char *status
; /* status message */
char *input_line
; /* input buffer, at least as wide as screen */
int ipoint
; /* insertion point */
int ilen
; /* current command length */
int matches
; /* number of matches found */
int start
; /* offset within matches */
int tag_mode
; /* tag_mode status */
int tagged
; /* number of things tagged */
search_t
*tags
; /* list of tagged matches */
search_t
*items
[9]; /* the 1-9 items on the screen */
search_t
*list
; /* current match list */
search_t
*displaying
; /* where we are displaying in the above list */
#define NUM_COMMANDS (sizeof (commands) / sizeof (command_t))
typedef struct COMMAND_T
{
void (*finder
)(extract_t
*info
, istruct_t
*w
);
#define CONTROL -('A'-1) +
#define DEBUGL(y, x) move(y, 0); clrtoeol(); printw x; refresh();
free_tag(istruct_t
*w
, search_t
*item
)
search_t
*tag
= item
->private;
tag_item(istruct_t
*w
, search_t
*item
)
if (item
->private == NULL
) {
cancel_tags(istruct_t
*w
)
free_tag(w
, ptr
->private);
find_exact_definition(extract_t
*info
, istruct_t
*w
)
info
->symbol
= w
->input_line
;
info
->flags
&= ~FLAG_REGEXP
;
w
->list
= build_searchlist(info
, NULL
,
(XREF_DEFINITION
| XREF_FORWARD
));
find_regexp_definition(extract_t
*info
, istruct_t
*w
)
info
->symbol
= w
->input_line
;
info
->flags
|= FLAG_REGEXP
;
w
->list
= build_searchlist(info
, NULL
,
(XREF_DEFINITION
| XREF_FORWARD
));
find_file(extract_t
*info
, istruct_t
*w
)
xref_file_t
*fptr
= info
->state
->sources
;
search_t
*new, *list
= NULL
;
info
->symbol
= w
->input_line
;
if (strstr(fptr
->name
, info
->symbol
) != NULL
) {
for (i
= 0; ((i
< 128) && (xref
== NULL
)); i
++) {
find_callers_of(extract_t
*info
, istruct_t
*w
)
info
->symbol
= w
->input_line
;
info
->flags
&= ~FLAG_REGEXP
;
item
= build_searchlist(info
, NULL
, XREF_DEFINITION
);
if (item
->next
!= NULL
) {
w
->status
= "more than one defintion, "
"refine your search using a tag";
ASSERT((item
!= NULL
), "tagged with item NULL??");
for (j
= 0; j
< rref
->insert
; j
++) {
callers
= new_search_t();
callers
->xref
= rref
->ptr
[j
];
find_text_string(extract_t
*info
, istruct_t
*w
)
info
->symbol
= w
->input_line
;
info
->flags
|= FLAG_REGEXP
;
w
->list
= build_searchlist(info
, NULL
,
(XREF_STRING
| XREF_DEFINITION
));
{ "Find definition:", 0, 0, find_exact_definition
},
{ "Find fuzzy definition:", 0, 1, find_regexp_definition
},
{ "Find callers of routine:", 0, 2, find_callers_of
},
{ "Find text string:", 0, 3, find_text_string
},
{ "Change text string:", 0, 4, NULL
},
{ "Change definition name:", 0, 5, NULL
},
{ "Find file:", 0, 6, find_file
},
draw_command(extract_t
*info
, istruct_t
*w
)
static int computed_pos
= 0;
for (i
= 0; i
< NUM_COMMANDS
; i
++) {
cptr
->cursor
= strlen(cptr
->id
)+1;
cptr
->line
+= (LINES
- NUM_COMMANDS
);
w
->info_line
= commands
[0].line
-1;
move(commands
[0].line
, 0);
for (i
= 0; i
< NUM_COMMANDS
; i
++) {
mvprintw(cptr
->line
, 0, cptr
->id
);
w
->col
= commands
[w
->cmdnum
].cursor
;
w
->line
= commands
[w
->cmdnum
].line
;
hit_counter(extract_t
*info
, search_t
*item
)
int *iptr
= info
->private;
run_search(extract_t
*info
, istruct_t
*w
)
if ((w
->ilen
== 0) && !w
->tag_mode
) {
return ("Nothing to Do");
if (commands
[w
->cmdnum
].finder
!= NULL
) {
commands
[w
->cmdnum
].finder(info
, w
);
info
->private = &w
->matches
;
iterate_list(info
, w
->list
, hit_counter
);
return ("Nothing Found");
return ("<unimplemented command>");
match_mode(extract_t
*info
, istruct_t
*w
, int c
)
for (i
= 0; i
< 9; i
++) {
while ((i
< 9) && (this != NULL
)) {
mvprintw(i
, 0, " %d%c[%c%c%c] %s:%d .. %s ..\n",
((this->private == NULL
) ? ' ' : '>'),
((this->xref
->flags
& XREF_FORWARD
) ? 'F' : '.'),
((this->xref
->flags
& XREF_DEFINITION
) ? 'D' : '.'),
((this->xref
->flags
& XREF_STRING
) ? 'S' : '.'),
expand_filename(info
, this->xref
),
if ((w
->start
+ i
) == w
->matches
) {
if ((c
> '0') && (c
<= '9')) {
selected
= w
->items
[c
-'1'];
if (((c
== '*') || (c
== '&')) && (w
->tag_mode
)) {
for (i
= 0; i
< 9; i
++) {
free_searchlist(w
->list
);
free_searchlist(w
->list
);
if (selected
&& !w
->tag_mode
) {
editor
= getenv("EDITOR");
file
= expand_filename(info
, selected
->xref
);
syscommand
= malloc(bytes
);
snprintf(syscommand
, bytes
, "%s +%d %s",
editor
, selected
->xref
->linenum
,
select_mode(extract_t
*info
, istruct_t
*w
, int c
)
if (0) move(w
->line
, w
->col
);
if (w
->ipoint
< w
->ilen
) {
if (0) move(w
->line
, w
->col
);
w
->cmdnum
= NUM_COMMANDS
-1;
if (w
->cmdnum
< (NUM_COMMANDS
-1))
w
->status
= run_search(info
, w
);
if (0) move(w
->line
, w
->col
);
char *here
= w
->input_line
+ w
->ipoint
;
memcpy(here
-1, here
, (w
->ilen
- w
->ipoint
)+1);
mvprintw(w
->line
, w
->lmargin
, w
->input_line
);
if (0) move(w
->line
, w
->col
);
if (w
->ipoint
< w
->ilen
) {
char *here
= w
->input_line
+ w
->ipoint
;
memcpy(here
, here
+1, (w
->ilen
- w
->ipoint
));
mvprintw(w
->line
, w
->lmargin
, w
->input_line
);
if (0) move(w
->line
, w
->col
);
w
->col
= w
->lmargin
+ w
->ilen
;
if (0) move(w
->line
, w
->col
);
w
->input_line
[w
->ipoint
] = 0;
mvprintw(w
->line
, w
->lmargin
, w
->input_line
);
if (0) move(w
->line
, w
->col
);
/* Escape, cancel all tags etc */
if ((c
>= ' ') && (c
<= 'z')) {
mvprintw(w
->line
, w
->col
, "%c", c
);
w
->input_line
[w
->ipoint
++] = c
;
if (w
->ipoint
> w
->ilen
) {
w
->input_line
[w
->ipoint
] = 0;
xref_interactive_mode(extract_t
*info
)
w
= malloc(sizeof (istruct_t
));
memset(w
, 0, sizeof (istruct_t
));
mvprintw(0, 0, "match window");
w
->input_line
= malloc(COLS
);
w
->input_line
[w
->ipoint
] = 0;
snprintf(add_status
, sizeof (add_status
),
"[Tagged:%d]", w
->tagged
);
rem
= w
->matches
- w
->start
;
mvprintw(w
->info_line
, 0,
"Status %s: displaying %d-%d"
add_status
, (w
->start
+1), upper
);
mvprintw(w
->info_line
, 0,
"Status %s: displaying %d-%d, %d more"
" [press SPACE for more, ESC to exit]",
add_status
, (w
->start
+1), upper
, rem
);
mvprintw(w
->info_line
, 0,
"Select %s mode: %s", add_status
, w
->status
);
c
= mvgetch(w
->line
, w
->col
);
tstatus
= select_mode(info
, w
, c
);