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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
|
/*----------------------------------------------------------------------*/
/* tclanalyzer.c --- The command-line commands to control the analyzer */
/* window. */
/* */
/* Written by Tim Edwards January 2005 */
/* */
/*----------------------------------------------------------------------*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tcl.h>
#include <tk.h>
#include "globals.h"
#include "ana.h"
#include "ana_glob.h"
#include "graphics.h"
#include "units.h"
extern Tcl_Interp *irsiminterp;
extern char **targv;
extern int targc;
extern int lookup();
extern Trptr get_trace();
extern void WritePSfile();
extern void SetTimeLeft(), SetTimeRight();
extern void TraceValue(), TraceInput(), TraceBits(), RemoveTrace();
extern void UpdateWinRemove(), GetNameLen();
extern void MoveToTimeValue(), ChangeTraceBase(), SetCursor();
extern void MoveCursorToTime(), MoveDeltaToTime(), MoveToT();
extern void MoveTraces(), SelectTrace();
extern int ValidTime();
extern int psBanner, psLegend, psTimes, psOutline;
extern int max_name_len, autoScroll;
/*------------------------------------------------------*/
/* The original Analyzer was driven by Xt callbacks, so */
/* there is no command syntax for it. We create one */
/* here. */
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/* base [trace] [value] */
/*------------------------------------------------------*/
int tclirsim_base()
{
int varg = 2, idx;
Trptr trace = selectedTrace;
char *bptr;
static char *baseTypes[] = {
"none", "binary", "quartile", "octal", "hexidecimal", "decimal",
"signed"
};
static char *baseOptions[] = {
"get", "set", NULL
};
enum baseopt {
BASE_GET, BASE_SET
};
if (targc == 1) {
lprintf(stderr, "Usage: base get [trace]\n");
lprintf(stderr, "Usage: base set [trace] type\n");
return 0;
}
idx = lookup(targv[1], baseOptions, FALSE);
if (idx < 0) return -1;
/* If there are 3 arguments, the second one should */
/* be a vector or node. Otherwise, trace is set to */
/* NULL, and ChangeTraceBase will use the */
/* currently selected trace, if there is one. */
if (((idx == BASE_GET) && (targc == 3))
|| ((idx == BASE_SET) && (targc == 4))) {
varg = 3;
trace = get_trace(targv[2]);
if (trace == NULL) {
lprintf(stderr, "No trace named \"%s\"!\n", targv[2]);
return -1;
}
}
if (idx == BASE_GET) {
Tcl_SetResult(irsiminterp, baseTypes[trace->bdigit], 0);
}
else if (targc <= varg) {
lprintf(stderr, "Trace types are: binary, decimal, octal, or hexidecimal.\n");
lprintf(stderr, "Trace type may begin with \"u\" to make it unsigned.\n");
return -1;
}
else {
bptr = targv[varg];
switch (*bptr) {
case 'b': case 'd': case 'o':
case 'h': case 'x': case 's':
ChangeTraceBase(trace, bptr);
break;
default:
lprintf(stderr, "Unknown/unhandled numeric base.\n");
return -1;
}
}
return 0;
}
/*------------------------------------------------------*/
/* marker [set|move|delta] */
/*------------------------------------------------------*/
int tclirsim_marker()
{
float rtime;
TimeType time; /* TimeType is "Ulong" in ana.h */
Trptr t;
int idx, which, argst;
double dt;
static char *markerOptions[] = {
"get", "move", "set", "off", NULL
};
enum markeropt {
MARKER_GET, MARKER_MOVE, MARKER_SET, MARKER_OFF
};
if (targc == 1) {
lprintf(stderr, "Usage: marker [1|2] <option>...\n");
return -1;
}
/* Assume primary cursor (1) unless indicated otherwise */
if (sscanf(targv[1], "%d", &which) == 1)
argst = 2;
else {
argst = 1;
which = 1;
}
if (which <= 0 || which > 2) {
lprintf(stderr, "Optional marker number must be 1 or 2\n");
return -1;
}
idx = lookup(targv[argst], markerOptions, FALSE);
if (idx < 0) return -1;
switch (idx) {
/* This duplicates "simtime marker" and "simtime delta" */
case MARKER_GET:
dt = (which == 1) ? analyzer_time_marker() : analyzer_time_delta();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
break;
case MARKER_SET:
if ((targc - argst + 1) != 4) {
lprintf(stderr, "Usage: marker set <trace> <time>.\n");
return -1;
}
else if (which == 2) {
lprintf(stderr, "Option not available for the delta marker\n");
return -1;
}
t = get_trace(targv[argst + 1]);
if (sscanf(targv[argst + 2], "%f", &rtime) != 1) {
lprintf(stderr, "Invalid time value.\n");
return -1;
}
time = (TimeType)(ns2d(rtime));
if (t != NULL) SetCursor(t, time);
MoveCursorToTime(time);
break;
case MARKER_MOVE:
if ((targc - argst + 1) == 2) {
lprintf(stderr, "Usage: marker move <time>.\n");
return -1;
}
else if (sscanf(targv[argst + 1], "%f", &rtime) != 1) {
lprintf(stderr, "Invalid time value.\n");
return -1;
}
time = (TimeType)(ns2d(rtime));
if (which == 2)
MoveDeltaToTime(time);
else
MoveCursorToTime(time);
break;
case MARKER_OFF:
if (which == 2)
MoveDeltaToTime((TimeType) -1);
else
MoveCursorToTime((TimeType) -1);
break;
}
return 0;
}
/*------------------------------------------------------*/
/* print <name> */
/*------------------------------------------------------*/
int tclirsim_print()
{
int idx, bidx, bval;
Tcl_Obj *robj;
static char *booleanOptions[] = {
"false", "no", "off", "0", "true", "yes", "on", "1"
};
static char *timeOptions[] = {
"banner", "legend", "times", "title", "outline", "file", NULL
};
enum timeopt {
PRINT_BANNER, PRINT_LEGEND, PRINT_TIMES, PRINT_TITLE,
PRINT_OUTLINE, PRINT_FILE
};
if (targc == 1) {
lprintf(stderr, "Usage: print <option>...\n");
return -1;
}
idx = lookup(targv[1], timeOptions, FALSE);
if (idx < 0) return -1;
if (targc == 2) {
switch (idx) {
case PRINT_BANNER:
robj = Tcl_NewBooleanObj(psBanner);
Tcl_SetObjResult(irsiminterp, robj);
break;
case PRINT_LEGEND:
robj = Tcl_NewBooleanObj(psLegend);
Tcl_SetObjResult(irsiminterp, robj);
break;
case PRINT_TIMES:
robj = Tcl_NewBooleanObj(psTimes);
Tcl_SetObjResult(irsiminterp, robj);
break;
case PRINT_TITLE:
if (banner) {
robj = Tcl_NewStringObj(banner, -1);
Tcl_SetObjResult(irsiminterp, robj);
}
break;
case PRINT_OUTLINE:
robj = Tcl_NewBooleanObj(psOutline);
Tcl_SetObjResult(irsiminterp, robj);
break;
case PRINT_FILE:
printPS("");
lprintf(stderr, "Filename required\n");
return -1;
}
}
else if (targc == 3) {
if ((idx != PRINT_FILE) && (idx != PRINT_TITLE)) {
bidx = lookup(targv[2], booleanOptions, FALSE);
if (bidx < 0) return -1;
bval = (bidx <= 3) ? 0 : 1;
}
switch (idx) {
case PRINT_BANNER:
psBanner = bval;
break;
case PRINT_LEGEND:
psLegend = bval;
break;
case PRINT_TIMES:
psTimes = bval;
break;
case PRINT_OUTLINE:
psOutline = bval;
break;
case PRINT_FILE:
printPS(targv[2]);
break;
case PRINT_TITLE:
if (banner) free(banner);
banner = strdup(targv[2]);
bannerLen = strlen(banner);
break;
}
}
return 0;
}
/*------------------------------------------------------*/
/* simtime <option> */
/*------------------------------------------------------*/
int tclirsim_simtime()
{
int idx, x;
double dt;
static char *booleanOptions[] = {
"false", "no", "off", "0", "true", "yes", "on", "1"
};
static char *timeOptions[] = {
"begin", "end", "left", "right", "delta", "marker", "cursor",
"move", "scroll", NULL
};
enum timeopt {
TIME_BEGIN, TIME_END, TIME_LEFT, TIME_RIGHT, TIME_DELTA,
TIME_MARKER, TIME_CURSOR, TIME_MOVE, TIME_SCROLL
};
if (targc == 1) {
lprintf(stderr, "Usage: simtime <option>");
return -1;
}
idx = lookup(targv[1], timeOptions, FALSE);
if (idx < 0) return -1;
switch (idx) {
case TIME_BEGIN:
if (targc == 2)
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(analyzer_time_start()));
break;
case TIME_END:
if (targc == 2) {
dt = analyzer_time_end();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
}
break;
case TIME_LEFT:
if (targc == 3) {
if (sscanf(targv[2], "%lg", &dt) != 1)
return -1;
else {
/* Set the zoom such that the time at the left edge */
/* is set to the specified time while the right */
/* edge remains constant. */
if (dt < 0.0) dt = 0.0;
SetTimeLeft((TimeType)(ns2d(dt)));
}
}
else if (targc == 2) {
dt = analyzer_time_left();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
}
break;
case TIME_RIGHT:
if (targc == 3) {
if (sscanf(targv[2], "%lg", &dt) != 1)
return -1;
else {
/* Set the zoom such that the time at the right */
/* edge is set to the specified time while the */
/* left edge remains constant. */
if (dt < 0.0) dt = 0.0;
SetTimeRight((TimeType)(ns2d(dt)));
}
}
else if (targc == 2) {
dt = analyzer_time_right();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
}
break;
case TIME_DELTA:
if (targc == 2) {
dt = analyzer_time_delta();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
}
break;
case TIME_MARKER:
if (targc == 2) {
dt = analyzer_time_marker();
if (dt >= 0.0) {
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
}
break;
case TIME_CURSOR:
x = -1;
if (targc == 3) {
if (sscanf(targv[2], "%d", &x) != 1)
return -1;
}
if (x >= 0) {
dt = (double)analyzer_time_cursor(x);
Tcl_SetObjResult(irsiminterp, Tcl_NewDoubleObj(dt));
}
else {
Tcl_SetResult(irsiminterp, "Bad position value", 0);
return TCL_ERROR;
}
break;
case TIME_MOVE:
if (targc == 3) {
if (sscanf(targv[2], "%lg", &dt) != 1)
return -1;
if (targv[2][0] == '+' || targv[2][0] == '-') {
/* Move relative, by the indicated value */
TimeType ltime;
double rt = analyzer_time_left();
if ((rt + dt) < 0.0) rt = dt = 0.0;
ltime = (TimeType)(ns2d(rt + dt));
MoveToTimeValue(ltime);
}
else {
MoveToT(targv[2]);
}
}
break;
case TIME_SCROLL:
if (targc == 2) {
if (autoScroll)
Tcl_SetResult(irsiminterp, "1", 0);
else
Tcl_SetResult(irsiminterp, "0", 0);
}
else if (targc == 3) {
idx = lookup(targv[2], booleanOptions, FALSE);
if (idx < 0) return -1;
autoScroll = (idx <= 3) ? 0 : 1;
}
break;
}
return 0;
}
/*------------------------------------------------------*/
/* trace <option> */
/*------------------------------------------------------*/
int tclirsim_trace()
{
Trptr t, s;
int result = 0, idx, tidx, y;
char *tracename;
static char *traceOptions[] = {
"top", "bottom", "order", "base", "class", "cursor", "input",
"list", "select", "value", "bits", "remove", "characters",
"move", (char *)NULL
};
enum traceopt {
TRACE_TOP, TRACE_BOTTOM, TRACE_ORDER, TRACE_BASE, TRACE_CLASS,
TRACE_CURSOR, TRACE_INPUT, TRACE_LIST, TRACE_SELECT, TRACE_VALUE,
TRACE_BITS, TRACE_REMOVE, TRACE_CHARS, TRACE_MOVE
};
static char *listOptions[] = {
"vectors", "nodes", "all", (char *)NULL
};
enum listopt {
LIST_VECTORS, LIST_NODES, LIST_ALL
};
if (targc == 1) {
lprintf(stderr, "Usage: trace <option>");
return -1;
}
idx = lookup(targv[1], traceOptions, FALSE);
if (idx < 0) return -1;
tracename = (targc >= 3) ? targv[2] : NULL;
switch (idx) {
case TRACE_MOVE:
if (targc != 4) {
lprintf(stderr, "Usage: trace move <trace1> <trace2>\n");
return -1;
}
t = get_trace(targv[2]);
s = get_trace(targv[3]);
if (t == NULL || s == NULL) {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
MoveTraces(t, s);
break;
case TRACE_TOP:
if (targc == 3)
Tcl_SetObjResult(irsiminterp,
Tcl_NewIntObj(analyzer_trace_top(tracename)));
break;
case TRACE_BOTTOM:
if (targc == 3)
Tcl_SetObjResult(irsiminterp,
Tcl_NewIntObj(analyzer_trace_bottom(tracename)));
break;
case TRACE_ORDER:
if (targc == 3)
Tcl_SetObjResult(irsiminterp,
Tcl_NewIntObj(analyzer_trace_order(tracename)));
break;
case TRACE_BASE:
if (targc == 3)
Tcl_SetObjResult(irsiminterp,
Tcl_NewIntObj(analyzer_trace_base(tracename)));
break;
case TRACE_CLASS:
if (targc == 3)
Tcl_SetResult(irsiminterp, analyzer_trace_class(tracename), NULL);
break;
case TRACE_CURSOR:
y = -1;
if (targc == 3) {
if (sscanf(targv[2], "%d", &y) != 1)
return -1;
}
tracename = analyzer_trace_cursor((TimeType)y);
if (tracename != NULL) {
Tcl_SetObjResult(irsiminterp, Tcl_NewStringObj(tracename, -1));
}
/* If no trace was found, simply return nothing. */
break;
case TRACE_LIST:
tidx = -1;
if (targc >= 3) tidx = lookup(targv[2], listOptions, FALSE);
if (tidx < 0) {
lprintf(stderr, "Usage: trace list [all|nodes|vectors]\n");
return -1;
}
switch(tidx) {
case LIST_VECTORS:
Tcl_SetObjResult(irsiminterp, analyzer_list_vectors(irsiminterp));
break;
case LIST_NODES:
Tcl_SetObjResult(irsiminterp, analyzer_list_nodes(irsiminterp));
break;
case LIST_ALL:
Tcl_SetObjResult(irsiminterp, analyzer_list_all(irsiminterp));
break;
}
break;
case TRACE_SELECT:
if (targc == 2) {
if (selectedTrace) {
SelectTrace(selectedTrace); /* prints stuff. . . */
}
else {
lprintf(stderr, "must select or specify a trace.\n");
return -1;
}
}
else {
t = get_trace(targv[2]);
if (t == NULL) {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
SelectTrace(t);
}
break;
case TRACE_VALUE:
if (targc != 3) {
lprintf(stderr, "Usage: trace value <trace>\n");
return -1;
}
t = get_trace(targv[2]);
if (t == NULL) {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
TraceValue(t, 0); /* Set 2nd arg. = 1 to force binary */
break;
case TRACE_INPUT:
if (targc != 3) {
lprintf(stderr, "Usage: trace input <trace>\n");
return -1;
}
t = get_trace(targv[2]);
if (t == NULL) {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
TraceInput(t);
break;
case TRACE_BITS:
if (targc != 3) {
lprintf(stderr, "Usage: trace input <trace>\n");
return -1;
}
t = get_trace(targv[2]);
if (t == NULL) {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
TraceBits(t);
break;
case TRACE_REMOVE:
if (targc != 3) {
lprintf(stderr, "Usage: trace remove [all|<trace>]\n");
return -1;
}
t = get_trace(targv[2]);
if (t == NULL) {
if (!strcmp(targv[2], "all"))
ClearTraces();
else {
lprintf(stderr, "invalid trace name.\n");
return -1;
}
}
else
RemoveTrace(t);
UpdateWinRemove();
break;
case TRACE_CHARS:
if (targc == 2) {
Tcl_SetObjResult(irsiminterp, Tcl_NewIntObj(max_name_len));
}
else if (targc == 3) {
GetNameLen(targv[2]);
}
break;
}
return result;
}
/*------------------------------------------------------*/
/* zoom [in|out] */
/*------------------------------------------------------*/
int tclirsim_zoom()
{
int idx;
static char *zoomOptions[] = {
"in", "out", NULL
};
enum zoomopt {
ZOOM_IN, ZOOM_OUT
};
if (targc == 1) {
/* To-do: return zoom factor */
return 0;
}
idx = lookup(targv[1], zoomOptions, FALSE);
if (idx < 0) return -1;
switch(idx) {
case ZOOM_IN:
Zoom("in");
break;
case ZOOM_OUT:
Zoom("out");
break;
}
return 0;
}
|