File: tkana.c

package info (click to toggle)
irsim 9.7.75-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,596 kB
  • sloc: ansic: 24,733; sh: 6,803; makefile: 411; csh: 269; tcl: 76
file content (300 lines) | stat: -rw-r--r-- 6,050 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 */

/*
 * Procedures needing to be defined separately for the Tk version
 * of the analyzer window.
 */

#include <stdio.h>
#ifdef LINUX
#include <string.h>  /* for strcmp() */
#endif
#include "ana.h"
#include <X11/Xutil.h>
#include "graphics.h"
#include "ana_glob.h"
#include "ana_tk.h"

#ifdef TCL_IRSIM

/*
 * Procedures querying the state of the analyzer display.
 */

float analyzer_time_start()
{
    return (float)d2ns(tims.first);
}

float analyzer_time_end()
{
    if (tims.last >= TIME_BOUND)
	return -1.0;
    else
	return (float)d2ns(tims.last);
}

float analyzer_time_left()
{
    if (tims.start >= TIME_BOUND)
	return -1.0;
    else
	return (float)d2ns(tims.start);
}

float analyzer_time_right()
{
    if (tims.end >= TIME_BOUND)
	return -1.0;
    else
        return (float)d2ns(tims.end);
}

float analyzer_time_step()
{
    return (float)d2ns(tims.steps);
}

float analyzer_time_delta()
{
    if (tims.delta >= TIME_BOUND)
	return -1.0;
    else
        return (float)d2ns(tims.delta);
}

float analyzer_time_marker()
{
    if (tims.cursor >= TIME_BOUND)
	return -1.0;
    else
        return (float)d2ns(tims.cursor);
}

float analyzer_time_cursor(int x)
{
    float ctime = d2ns(XToTime(x));
    if (ctime >= TIME_BOUND)
	return -1.0;
    else
	return (float)ctime;
}

Trptr get_trace(char *tracename)
{
    Trptr t;

    for (t = traces.first; t != NULL; t = t->next)
       if (!strcmp(t->name, tracename))
	   return t;

    return (Trptr)NULL;
}

int analyzer_trace_top(char *tracename)
{
    Trptr t = get_trace(tracename);
    return (t != NULL) ? t->top : -1;
}

int analyzer_trace_bottom(char *tracename)
{
    Trptr t = get_trace(tracename);
    return (t != NULL) ? t->bot : -1;
}

int analyzer_trace_order(char *tracename)
{
    Trptr t;
    int i = 0;

    for (t = traces.first; t != NULL; t = t->next) {
       if (!strcmp(t->name, tracename))
	   return i;
       i++;
    }
    return -1;
}

int analyzer_trace_base(char *tracename)
{
    Trptr t = get_trace(tracename);
    if (t == NULL) return -1;
    else if (!t->vector) return -2;
    else return t->bdigit;
}

char *analyzer_trace_class(char *tracename)
{
    Trptr t = get_trace(tracename);
    if (t == NULL) return NULL;
    else if (t->vector) return "vector";
    else return "node";
}

char *analyzer_trace_cursor(int y)
{
    Trptr t;

    for (t = traces.first; t != NULL; t = t->next) {
       if (t && (t->bot >= y) && (t->top <= y))
	  return t->name;
    }
    return NULL;
}

Tcl_Obj *analyzer_list_all(interp)
    Tcl_Interp *interp;
{
    Tcl_Obj *tlist;
    Trptr t;

    tlist = Tcl_NewListObj(0, NULL);
    for (t = traces.first; t != NULL; t = t->next) {
       Tcl_ListObjAppendElement(interp, tlist, Tcl_NewStringObj(t->name, t->len));
    }
    return tlist;
}

Tcl_Obj *analyzer_list_vectors(interp)
    Tcl_Interp *interp;
{
    Tcl_Obj *tlist;
    Trptr t;

    tlist = Tcl_NewListObj(0, NULL);
    for (t = traces.first; t != NULL; t = t->next) {
       if (t->vector)
	  Tcl_ListObjAppendElement(interp, tlist, Tcl_NewStringObj(t->name, t->len));
    }
    return tlist;
}

Tcl_Obj *analyzer_list_nodes(interp)
    Tcl_Interp *interp;
{
    Tcl_Obj *tlist;
    Trptr t;

    tlist = Tcl_NewListObj(0, NULL);
    for (t = traces.first; t != NULL; t = t->next) {
       if (!(t->vector))
	  Tcl_ListObjAppendElement(interp, tlist, Tcl_NewStringObj(t->name, t->len));
    }
    return tlist;
}

/*
 * Handle various procedures that are different for the Tk window
 */

public void SendEventTo(f)
    Func  f; 
{
    /* Do Nothing --- events are handled by the Tk Event Handler */
}

public void UpdateScrollBar()
{
    /* Do Nothing (for now)---need to communicate w/the Tk scrollbar */
}

public void DrawScrollBar(b)
    int b;
{
    /* Do Nothing (for now)---need to communicate w/the Tk scrollbar */
}

public void RedrawBanner()
{
    /* Do Nothing */
}

public void RedrawTimes()
{
    /* Do Nothing */
}

public void UpdateTimes()
{
    /* Do Nothing */
}

public void GrabMouse(w, ev_mask, cursor)
    Window         w;
    unsigned long  ev_mask;
    Cursor         cursor;
{
    /* Do Nothing (?) */
}

public void EnableAnalyzer()
{
    /* Do Nothing (?) */
}

public void DisableAnalyzer()
{
    /* Do Nothing (?) */
}

public void TerminateAnalyzer()
{
    /* Do Nothing (?) */
}

public void EnableInput()
{
    /* Do Nothing (?) */
}

public void DisableInput()
{
    /* Do Nothing (?) */
}

/*
 * Tk initializes the X11 display.  This routine is called when
 * Tk maps the analyzer window, and we can query the Tk_Window
 * structure about the display.
 */

public int InitDisplay(fname, tkwind)
    char  *fname;
    Tk_Window tkwind;
{
    XFontStruct  *font;
    Tk_Window tktop = Tk_MainWindow(irsiminterp);

    if (tkwind == NULL)
	return FALSE;

    if (!Tk_IsMapped(tkwind))
	Tk_MapWindow(tkwind);

    /* In the Tcl version, the display should have been initialized. */
    display = Tk_Display(tktop);
    screen = Tk_Screen(tktop);
    window = Tk_WindowId(tkwind);

    XWINDOWSIZE = Tk_Width(tkwind);
    YWINDOWSIZE = Tk_Height(tkwind);

    /* Initialize the fonts and graphics contexts */
    return SetFont();
}

#endif /* (TCL_IRSIM) */