/usr/share/doc/gtkwave/examples/transaction.c is in gtkwave 3.3.79-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (c) 2010 Tony Bybell.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* to compile: gcc -o transaction transaction.c -DHAVE_INTTYPES_H
* then in this directory run: gtkwave transaction.gtkw
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#define OPTIONAL_DEBUG if(1)
/*
* some structs we'll be using for event harvesting from the VCD that
* gtkwave sends via stdin into this executable
*/
struct tim_t
{
struct tim_t *next;
uint64_t tim;
int val;
int delta;
};
struct event_t
{
struct event_t *next;
uint64_t tim;
char *name;
};
int main(void)
{
uint64_t min_time = 0, max_time = 0;
uint64_t tim = 0;
int prevtim = 0;
int prevval = 255;
struct tim_t *t_head = NULL, *t_curr = NULL;
struct tim_t *t_tmp;
int hcnt;
uint64_t control_start = 0, control_end = 0;
int blks;
int my_arg = 0;
struct event_t *hdr_head = NULL, *hdr_curr = NULL;
struct event_t *data_head = NULL, *data_curr = NULL;
OPTIONAL_DEBUG { fprintf(stderr, "*** t_filter executable init ***\n"); }
top: /* main control loop */
hcnt = 0;
control_start = 0;
control_end = 0;
blks = 0;
while(1) /* reading input from stdin until data_end comment received */
{
char buf[1025];
char *pnt = NULL;
buf[0] = 0;
pnt = fgets(buf, 1024, stdin); /* CACHE (VIA puts()) THIS INPUT TO A FILE TO DEVELOP YOUR CLIENT OFFLINE FROM GTKWAVE! */
if(buf[0])
{
pnt = buf;
while(*pnt) /* strip off end of line character */
{
if(*pnt != '\n')
{
pnt++;
}
else
{
*pnt = 0;
break;
}
}
if(buf[0] == '#') /* look for and extract time value */
{
char *str = buf+1;
unsigned char ch;
tim=0;
while((ch=*(str++)))
{
if((ch>='0')&&(ch<='9'))
{
tim=(tim*10+(ch&15));
}
}
}
else
if(buf[0] == 'b') /* extract the binary value of the "val" symbol */
{
int collect = 0;
pnt = buf+1;
while(*pnt && (*pnt != ' '))
{
collect <<= 1;
collect |= ((*pnt) & 1);
pnt++;
}
if((prevval ^ collect) & 128)
{
t_tmp = calloc(1, sizeof(struct tim_t));
t_tmp->tim = tim;
t_tmp->val = collect;
t_tmp->delta = tim - prevtim;
prevtim = tim;
if(!t_curr)
{
t_head = t_curr = t_tmp;
}
else
{
t_curr = t_curr->next = t_tmp;
}
}
prevval = collect;
}
else
if(buf[0] == '$') /* directive processing */
{
if(strstr(buf, "$comment"))
{
if((pnt = strstr(buf, "args")))
{
char *lhq = strchr(pnt, '\"');
if(lhq) my_arg = atoi(lhq+1);
OPTIONAL_DEBUG { fprintf(stderr, "args: %s\n", buf); }
}
else
if((pnt = strstr(buf, "min_time")))
{
sscanf(pnt + 9, "%"SCNu64, &min_time);
OPTIONAL_DEBUG { fprintf(stderr, "min: %d\n", (int)min_time); }
}
else
if((pnt = strstr(buf, "max_time")))
{
sscanf(pnt + 9, "%"SCNu64, &max_time);
OPTIONAL_DEBUG { fprintf(stderr, "max: %d\n", (int)max_time); }
}
else
if(strstr(buf, "data_end"))
{
break;
}
}
}
}
if(feof(stdin)) /* broken pipe coming up */
{
OPTIONAL_DEBUG { fprintf(stderr, "*** Terminated t_filter executable\n"); }
exit(0);
}
}
printf("$name Decoded FSK\n"); /* 1st trace name */
printf("#0\n");
{
uint64_t p_tim = 0;
int state = 0;
int byte_remain = 0;
int bcnt = 0;
t_tmp = t_head;
while(t_tmp)
{
if(t_tmp->delta == 16)
{
int sync_cnt = 0;
uint64_t t_start = p_tim;
int i;
for(i=0;i<16;i++)
{
if(t_tmp->delta == 16) { sync_cnt++; p_tim = t_tmp->tim; t_tmp = t_tmp->next; } else { break; }
}
if(sync_cnt==16)
{
if(!my_arg)
{
printf("#%"PRIu64" ?darkblue?Sync\n", t_start); /* write out sync xact */
}
else
{
printf("#%"PRIu64" ?blue?Sync\n", t_start); /* write out sync xact */
}
printf("#%"PRIu64"\n", p_tim - 4); /* 'z' midline is no value after time */
printf("MA%"PRIu64" Start\n", t_start); /* set position/name for marker A */
control_start = t_start;
goto found_sync;
}
continue;
}
p_tim = t_tmp->tim;
t_tmp = t_tmp->next;
}
found_sync:
state = 0; byte_remain = 11;
/* printf("MB%"PRIu64" Num Blocks\n", p_tim); */
while(t_tmp)
{
int i;
int collect = 0;
uint64_t t_start = p_tim;
if((state == 0) && (byte_remain == 10))
{
struct event_t *evt = calloc(1, sizeof(struct event_t));
char buf[32];
evt->tim = p_tim;
sprintf(buf, "H%d", hcnt/2);
evt->name = strdup(buf);
if(!control_end) { control_end = p_tim; }
if(!hdr_head) { hdr_head = hdr_curr = evt; }
else { hdr_curr = hdr_curr->next = evt; }
/**/
if(data_curr)
{
evt = calloc(1, sizeof(struct event_t));
evt->tim = p_tim;
evt->name = NULL;
data_curr = data_curr->next = evt;
}
}
if((state == 1) && (byte_remain == 64))
{
struct event_t *evt = calloc(1, sizeof(struct event_t));
char buf[32];
evt->tim = p_tim;
sprintf(buf, "D%d:", hcnt/2);
evt->name = calloc(1, 74);
strcpy(evt->name, buf);
if(!data_head) { data_head = data_curr = evt; }
else { data_curr = data_curr->next = evt; }
/**/
if(hdr_curr)
{
evt = calloc(1, sizeof(struct event_t));
evt->tim = p_tim;
evt->name = NULL;
hdr_curr = hdr_curr->next = evt;
}
hcnt++;
}
for(i=0;(t_tmp) && (i<8);i++)
{
collect <<= 1;
if(t_tmp->delta == 16)
{
collect |= 1;
t_tmp = t_tmp->next;
}
else
{
}
p_tim = t_tmp->tim; t_tmp = t_tmp->next;
}
if(!bcnt)
{
printf("#%"PRIu64" ?gray24?%02X\n", t_start, collect);
blks = collect;
bcnt++;
}
else
{
if(state == 1)
{
char conv = ((collect < ' ') || (collect >= 127)) ? '.' : collect;
int slen = strlen(data_curr->name);
data_curr->name[slen] = conv;
if((collect >= ' ') && (collect < 127))
{
printf("#%"PRIu64" ?darkgreen?%c\n", t_start, (unsigned char)collect);
}
else
{
printf("#%"PRIu64" ?darkred?%02X\n", t_start, collect);
}
}
else
{
printf("#%"PRIu64" ?purple3?%02X\n", t_start, collect);
}
}
printf("#%"PRIu64"\n", p_tim - 4);
byte_remain--;
if(!byte_remain)
{
if(state == 0)
{
state = 1; byte_remain = 64;
}
else
{
state = 0; byte_remain = 10;
}
}
}
}
t_tmp = t_head; /* free up memory allocated */
while(t_tmp)
{
t_curr = t_tmp->next;
free(t_tmp);
t_tmp = t_curr;
}
t_head = t_curr = NULL;
printf("$next\n"); /* indicate there is a next trace */
printf("$name Control\n"); /* next trace name */
printf("#0\n");
if(!my_arg)
{
printf("#%"PRIu64" ?darkblue?%02X blks\n", control_start, blks);
}
else
{
printf("#%"PRIu64" ?blue?%02X blks\n", control_start, blks);
}
printf("#%"PRIu64"\n", control_end);
printf("$next\n"); /* indicate there is a next trace */
printf("$name Headers\n"); /* next trace name */
printf("#0\n");
while(hdr_head)
{
if(hdr_head->name)
{
printf("#%"PRIu64" ?purple3?%s\n", hdr_head->tim, hdr_head->name);
free(hdr_head->name);
}
else
{
printf("#%"PRIu64"\n", hdr_head->tim);
}
hdr_curr = hdr_head->next;
free(hdr_head);
hdr_head = hdr_curr;
}
printf("$next\n"); /* indicate there is a next trace */
printf("$name Data Payload\n"); /* next trace name */
printf("#0\n");
while(data_head)
{
if(data_head->name)
{
printf("#%"PRIu64" ?darkgreen?%s\n", data_head->tim, data_head->name);
free(data_head->name);
}
else
{
printf("#%"PRIu64"\n", data_head->tim);
}
data_curr = data_head->next;
free(data_head);
data_head = data_curr;
}
printf("$finish\n"); /* directive to return control to gtkwave */
fflush(stdout); /* ensure nothing is stuck in output buffers which could hang gtkwave */
OPTIONAL_DEBUG { fprintf(stderr, "back to gtkwave...\n"); }
goto top; /* loop forever in order to process next xact query */
return(0);
}
|