Codebase list gtkwave / 8b7625e
Merge tag 'upstream/3.3.61' Upstream version 3.3.61 أحمد المحمودي (Ahmed El-Mahmoudy) 9 years ago
83 changed file(s) with 7173 addition(s) and 4961 deletion(s). Raw diff Collapse all Expand all
14731473 3.3.60 14may14 Fix MinGW tmpfile_open() patch from previous release as it
14741474 was using the wrong filename.
14751475 Harden fsdb reader against xtags that move backward in time.
1476 3.3.61 27jun14 Parameterized number of named markers, so that
1477 --enable-manymarkers at configure time allows up to 702
1478 named markers instead of 26 (disabled by default).
1479 Updated LZ4 for version r118.
1480 Fixed broken VCD/TIM export in Windows (broken by new file
1481 requester).
00 ##########################################################################
11
2 GTKWave 3.3.59 Wave Viewer is Copyright (C) 1999-2014 Tony Bybell.
2 GTKWave 3.3.61 Wave Viewer is Copyright (C) 1999-2014 Tony Bybell.
33 Portions of GTKWave are Copyright (C) 1999-2014 Udi Finkelstein.
44 Context support is Copyright (C) 2007-2014 Kermin Elliott Fleming.
55 Trace group support is Copyright (C) 2009-2014 Donald Baltus.
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for gtkwave 3.3.60.
2 # Generated by GNU Autoconf 2.69 for gtkwave 3.3.61.
33 #
44 # Report bugs to <bybell@rocketmail.com>.
55 #
579579 # Identity of this package.
580580 PACKAGE_NAME='gtkwave'
581581 PACKAGE_TARNAME='gtkwave'
582 PACKAGE_VERSION='3.3.60'
583 PACKAGE_STRING='gtkwave 3.3.60'
582 PACKAGE_VERSION='3.3.61'
583 PACKAGE_STRING='gtkwave 3.3.61'
584584 PACKAGE_BUGREPORT='bybell@rocketmail.com'
585585 PACKAGE_URL=''
586586
810810 enable_stubify
811811 enable_gtk1
812812 enable_fatlines
813 enable_manymarkers
813814 enable_ae2
814815 enable_fsdb
815816 enable_dependency_tracking
13811382 # Omit some internal or obsolete options to make the list less imposing.
13821383 # This message is too long to be a string in the A/UX 3.1 sh.
13831384 cat <<_ACEOF
1384 \`configure' configures gtkwave 3.3.60 to adapt to many kinds of systems.
1385 \`configure' configures gtkwave 3.3.61 to adapt to many kinds of systems.
13851386
13861387 Usage: $0 [OPTION]... [VAR=VALUE]...
13871388
14471448
14481449 if test -n "$ac_init_help"; then
14491450 case $ac_init_help in
1450 short | recursive ) echo "Configuration of gtkwave 3.3.60:";;
1451 short | recursive ) echo "Configuration of gtkwave 3.3.61:";;
14511452 esac
14521453 cat <<\_ACEOF
14531454
14711472 --enable-gtk1 Causes the GTK+ frontend to be built with gtk1
14721473 instead of gtk2.
14731474 --enable-fatlines Renders lines as double width in gtkwave.
1475 --enable-manymarkers Expands named marker count from 26 to 702.
14741476 --enable-ae2 Compiles in AE2 from env var SIMARAMA_BASE location.
14751477 --enable-fsdb Compiles in FsdbReader from env vars FSDBREADER_HDRS
14761478 header and FSDBREADER_LIBS library directories.
15921594 test -n "$ac_init_help" && exit $ac_status
15931595 if $ac_init_version; then
15941596 cat <<\_ACEOF
1595 gtkwave configure 3.3.60
1597 gtkwave configure 3.3.61
15961598 generated by GNU Autoconf 2.69
15971599
15981600 Copyright (C) 2012 Free Software Foundation, Inc.
22362238 This file contains any messages produced by compilers while
22372239 running configure, to aid debugging if configure makes a mistake.
22382240
2239 It was created by gtkwave $as_me 3.3.60, which was
2241 It was created by gtkwave $as_me 3.3.61, which was
22402242 generated by GNU Autoconf 2.69. Invocation command line was
22412243
22422244 $ $0 $@
31033105
31043106 # Define the identity of the package.
31053107 PACKAGE='gtkwave'
3106 VERSION='3.3.60'
3108 VERSION='3.3.61'
31073109
31083110
31093111 cat >>confdefs.h <<_ACEOF
38913893 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
38923894 $as_echo "yes" >&6; }
38933895 CPPFLAGS="-DWAVE_DOUBLE_LINE_WIDTH_MODE $CPPFLAGS"
3896 fi
3897
3898
3899 # check for massive amounts of named markers enabled
3900 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if manymarkers should be used" >&5
3901 $as_echo_n "checking if manymarkers should be used... " >&6; }
3902
3903 MMC=no
3904 # Check whether --enable-manymarkers was given.
3905 if test "${enable_manymarkers+set}" = set; then :
3906 enableval=$enable_manymarkers;
3907 if test "X$enable_manymarkers" = "Xno" ; then
3908 MMC=no
3909 else
3910 MMC=yes
3911 fi
3912
3913 else
3914
3915 MMC=no
3916
3917 fi
3918
3919
3920 if test "X$MMC" = "Xno" ; then
3921 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
3922 $as_echo "no" >&6; }
3923 else
3924 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3925 $as_echo "yes" >&6; }
3926 CPPFLAGS="-DWAVE_MANYMARKERS_MODE $CPPFLAGS"
38943927 fi
38953928
38963929
1095810991 # report actual input values of CONFIG_FILES etc. instead of their
1095910992 # values after options handling.
1096010993 ac_log="
10961 This file was extended by gtkwave $as_me 3.3.60, which was
10994 This file was extended by gtkwave $as_me 3.3.61, which was
1096210995 generated by GNU Autoconf 2.69. Invocation command line was
1096310996
1096410997 CONFIG_FILES = $CONFIG_FILES
1102411057 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1102511058 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
1102611059 ac_cs_version="\\
11027 gtkwave config.status 3.3.60
11060 gtkwave config.status 3.3.61
1102811061 configured by $0, generated by GNU Autoconf 2.69,
1102911062 with options \\"\$ac_cs_config\\"
1103011063
11 # Process this file with autoconf to produce a configure script.
22
33 AC_PREREQ(2.59)
4 AC_INIT(gtkwave, 3.3.60, bybell@rocketmail.com)
4 AC_INIT(gtkwave, 3.3.61, bybell@rocketmail.com)
55 AC_CONFIG_SRCDIR([src/vcd.c])
66 AM_INIT_AUTOMAKE
77 AC_CONFIG_HEADER([config.h])
225225 else
226226 AC_MSG_RESULT([yes])
227227 CPPFLAGS="-DWAVE_DOUBLE_LINE_WIDTH_MODE $CPPFLAGS"
228 fi
229
230
231 # check for massive amounts of named markers enabled
232 AC_MSG_CHECKING([if manymarkers should be used])
233
234 MMC=no
235 AC_ARG_ENABLE([manymarkers],
236 [ --enable-manymarkers Expands named marker count from 26 to 702.],
237 [
238 if test "X$enable_manymarkers" = "Xno" ; then
239 MMC=no
240 else
241 MMC=yes
242 fi
243 ],
244 [
245 MMC=no
246 ])
247
248 if test "X$MMC" = "Xno" ; then
249 AC_MSG_RESULT([no])
250 else
251 AC_MSG_RESULT([yes])
252 CPPFLAGS="-DWAVE_MANYMARKERS_MODE $CPPFLAGS"
228253 fi
229254
230255
117117
118118 static gint expose_event_local(GtkWidget *widget, GdkEventExpose *event)
119119 {
120 (void)event;
121
120122 struct text_find_t *tr = text_root;
121123
122124 while(tr)
447449
448450 static void search_backward(GtkWidget *widget, gpointer data)
449451 {
452 (void)widget;
453 (void)data;
454
450455 tr_search_backward(search_string);
451456 }
452457
453458 static gboolean forward_noskip = FALSE;
454459 static void search_forward(GtkWidget *widget, gpointer data)
455460 {
461 (void)widget;
462 (void)data;
463
456464 tr_search_forward(search_string, forward_noskip);
457465 }
458466
461469 static
462470 gboolean find_edit_cb (GtkWidget *widget, GdkEventKey *ev, gpointer *data)
463471 {
472 (void)data;
473
464474 /* Maybe this test is too strong ? */
465475 if (ev->keyval == GDK_Return)
466476 {
482492
483493 static void toggle_callback(GtkWidget *widget, GtkWidget *nothing)
484494 {
495 (void)nothing;
496
485497 matchcase_active = (GTK_TOGGLE_BUTTON(widget)->active != 0);
486498 tr_search_forward(search_string, TRUE);
487499 }
581593 return(tmpnam(s));
582594
583595 #else
596 (void)s;
584597
585598 char *backpath = "gtkwaveXXXXXX";
586599 char *tmpspace;
765778 GtkWidget *widget, GdkDragContext *dc, gpointer data
766779 )
767780 {
781 (void)widget;
782 (void)dc;
783 (void)data;
784
768785 /* nothing */
769786 }
770787
772789 GtkWidget *widget, GdkDragContext *dc, gpointer data
773790 )
774791 {
792 (void)widget;
793 (void)dc;
794 (void)data;
795
775796 /* nothing */
776797 }
777798
779800 GtkWidget *widget, GdkDragContext *dc, gpointer data
780801 )
781802 {
803 (void)widget;
804 (void)dc;
805 (void)data;
806
782807 /* nothing */
783808 }
784809
788813 gpointer data
789814 )
790815 {
816 (void)dc;
817 (void)t;
818 (void)info;
819
791820 struct logfile_context_t *ctx = (struct logfile_context_t *)data;
792821 GtkWidget *text = (GtkWidget *)widget;
793822 gchar *sel = NULL;
10151044 void log_text(GtkWidget *text, GdkFont *font, char *str)
10161045 {
10171046 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
1047 (void)font;
1048
10181049 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &iterx,
10191050 str, -1, mono_tag, size_tag, NULL);
10201051 #else
10251056 void log_text_bold(GtkWidget *text, GdkFont *font, char *str)
10261057 {
10271058 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
1059 (void)font;
1060
10281061 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &iterx,
10291062 str, -1, bold_tag, mono_tag, size_tag, fwht_tag, blue_tag, NULL);
10301063 #else
10351068 void log_text_active(GtkWidget *text, GdkFont *font, char *str)
10361069 {
10371070 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
1071 (void)font;
1072
10381073 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &iterx,
10391074 str, -1, dgray_tag, mono_tag, size_tag, NULL);
10401075 #else
10451080 void log_text_prelight(GtkWidget *text, GdkFont *font, char *str)
10461081 {
10471082 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
1083 (void)font;
1084
10481085 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &iterx,
10491086 str, -1, lgray_tag, mono_tag, size_tag, NULL);
10501087 #else
10551092 static void
10561093 log_realize_text (GtkWidget *text, gpointer data)
10571094 {
1095 (void)text;
1096 (void)data;
1097
10581098 /* nothing for now */
10591099 }
10601100
10641104
10651105 static void lx2_iter_fn(struct lxt2_rd_trace **lt, lxtint64_t *pnt_time, lxtint32_t *pnt_facidx, char **pnt_value)
10661106 {
1067 if(*pnt_time <= anno_ctx->marker)
1107 (void)lt;
1108
1109 if(*pnt_time <= (lxtint64_t)anno_ctx->marker)
10681110 {
10691111 JRB node = jrb_find_int(lx2vals, *pnt_facidx);
10701112 Jval jv;
11221164 static gboolean
11231165 button_release_event (GtkWidget *text, GdkEventButton *event)
11241166 {
1167 (void)event;
1168
11251169 gchar *sel;
11261170
11271171 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
12711315 static gint
12721316 scroll_event( GtkWidget * widget, GdkEventScroll * event, gpointer text)
12731317 {
1318 (void)widget;
1319
12741320 GtkTextView *text_view = GTK_TEXT_VIEW(text);
12751321 /* GtkAdjustment *hadj = text_view->hadjustment; */
12761322 GtkAdjustment *vadj = text_view->vadjustment;
13931439
13941440 static void ok_callback(GtkWidget *widget, struct logfile_context_t *ctx)
13951441 {
1442 (void)widget;
1443
13961444 bwlogbox(ctx->which->fullname, ctx->width, ctx->which, (ctx->display_mode == 0));
13971445 }
13981446
14991547
15001548 static void destroy_callback(GtkWidget *widget, gpointer dummy)
15011549 {
1550 (void)dummy;
1551
15021552 struct text_find_t *t = text_root, *tprev = NULL;
15031553 struct logfile_context_t *ctx = NULL;
15041554 int which = (notebook != NULL);
429429
430430 static void free_fn(void* ptr, size_t size)
431431 {
432 (void)size;
433
432434 free(ptr);
433435 }
434436
642642 gpointer data
643643 )
644644 {
645 (void)widget;
646 (void)xx;
647 (void)yy;
648 (void)data;
645649 #ifdef WAVE_USE_GTK2
646650 GdkDragAction suggested_action;
647651
668672 /* All else respond with 0. */
669673 else
670674 gdk_drag_status(dc, 0, tt);
675 #else
676 (void)dc;
677 (void)tt;
671678 #endif
672679
673680 return(FALSE);
677684 GtkWidget *widget, GdkDragContext *dc, gpointer data
678685 )
679686 {
687 (void)widget;
688 (void)dc;
689 (void)data;
680690 }
681691
682692 static void DNDEndCB(
683693 GtkWidget *widget, GdkDragContext *dc, gpointer data
684694 )
685695 {
696 (void)widget;
697 (void)dc;
698 (void)data;
686699 }
687700
688701 /*
698711 GtkWidget *widget, GdkDragContext *dc,
699712 gint x, gint y, GtkSelectionData *selection_data,
700713 guint info, guint t, gpointer data) {
714 (void)x;
715 (void)y;
716 (void)t;
717
701718 gboolean same;
702719 GtkWidget *source_widget;
703720
3131 static void select_row_callback(GtkWidget *widget, gint row, gint column,
3232 GdkEventButton *event, gpointer data)
3333 {
34 (void)widget;
35 (void)column;
36 (void)event;
37 (void)data;
38
3439 ds_Tree *t=(ds_Tree *)gtk_clist_get_row_data(GTK_CLIST(ctree_main), row);
3540 selectedtree=t;
3641
5560 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
5661 GdkEventButton *event, gpointer data)
5762 {
63 (void)widget;
64 (void)row;
65 (void)column;
66 (void)event;
67 (void)data;
68
5869 /* ds_Tree *t=(ds_Tree *)gtk_clist_get_row_data(GTK_CLIST(ctree_main), row); */
5970 selectedtree=NULL;
6071 }
7485
7586 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
7687 {
88 (void)widget;
89 (void)nothing;
90
7791 is_active=0;
7892 gtk_widget_destroy(window);
7993 gtk_main_quit();
86100 */
87101 void treebox(char *title, GtkSignalFunc func, GtkWidget *old_window)
88102 {
103 (void)old_window;
104
89105 GtkWidget *scrolled_win;
90106 GtkWidget *frame2;
91107 GtkWidget *table;
3737
3838 TimeType ae2_main(char *fname, char *skip_start, char *skip_end)
3939 {
40 (void)fname;
41 (void)skip_start;
42 (void)skip_end;
43
4044 fprintf(stderr, "%s", ae2_loader_fail_msg);
4145 exit(255);
4246
5761 */
5862 int aet2_rd_get_fac_process_mask(unsigned int facidx)
5963 {
60 if(facidx<GLOBALS->numfacs)
64 if((int)facidx<GLOBALS->numfacs)
6165 {
6266 int process_idx = facidx/8;
6367 int process_bit = facidx&7;
7175
7276 void aet2_rd_set_fac_process_mask(unsigned int facidx)
7377 {
74 if(facidx<GLOBALS->numfacs)
78 if((int)facidx<GLOBALS->numfacs)
7579 {
7680 int idx = facidx/8;
7781 int bitpos = facidx&7;
8387
8488 void aet2_rd_clr_fac_process_mask(unsigned int facidx)
8589 {
86 if(facidx<GLOBALS->numfacs)
90 if((int)facidx<GLOBALS->numfacs)
8791 {
8892 int idx = facidx/8;
8993 int bitpos = facidx&7;
132136
133137 static unsigned long symbol_fn (cchar *name, void *udata)
134138 {
139 (void)udata;
140
135141 AE2_FACREF f2;
136142 return(ae2_read_find_symbol(GLOBALS->ae2, name, &f2));
137143 }
148154
149155 static void free_fn(void* ptr, size_t size)
150156 {
157 (void)size;
158
151159 if(ptr)
152160 {
153161 free_2(ptr);
422430 */
423431 TimeType ae2_main(char *fname, char *skip_start, char *skip_end)
424432 {
425 int i;
433 unsigned int i;
426434 int match_idx;
427435 struct Node *n;
428436 struct symbol *s;
527535 for(i=0;i<GLOBALS->ae2_num_aliases;i++)
528536 {
529537 unsigned long numTerms;
530 int idx = i+1;
531 int ii;
538 unsigned int idx = i+1;
539 unsigned int ii;
532540 int midx, mbit;
533541 int mcnt;
534542
631639 }
632640
633641 match_idx = 0;
634 for(i=0;i<GLOBALS->numfacs;i++)
642 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
635643 {
636644 char *str;
637645 int idx;
638646 int typ;
639 unsigned long len, clen;
647 long len, clen;
640648 int row_iter, mx_row, mx_row_adjusted;
641649
642650 #ifdef AET2_ALIASDB_IS_PRESENT
779787
780788 if(GLOBALS->fast_tree_sort)
781789 {
782 for(i=0;i<GLOBALS->numfacs;i++)
790 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
783791 {
784792 GLOBALS->facs[i]=&monolithic_sym[i];
785793 }
789797
790798 init_tree();
791799
792 for(i=0;i<GLOBALS->numfacs;i++)
800 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
793801 {
794802 int was_packed = HIER_DEPACK_STATIC; /* no need to free_2() afterward then */
795803 char *sb = hier_decompress_flagged(GLOBALS->facs[i]->name, &was_packed);
808816 }
809817 else
810818 {
811 for(i=0;i<GLOBALS->numfacs;i++)
819 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
812820 {
813821 #ifdef WAVE_HIERFIX
814822 char *subst;
848856 fprintf(stderr, AET2_RDLOAD"Building facility hierarchy tree.\n");
849857
850858 init_tree();
851 for(i=0;i<GLOBALS->numfacs;i++)
859 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
852860 {
853861 build_tree_from_name(GLOBALS->facs[i]->name, i);
854862 }
10001008
10011009 autofacs = calloc_2(GLOBALS->numfacs, sizeof(struct ae2_ncycle_autosort));
10021010
1003 for(i=0;i<GLOBALS->numfacs;i++)
1011 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
10041012 {
10051013 if(aet2_rd_get_fac_process_mask(i))
10061014 {
1007 int nr = ae2_read_symbol_rows_2(GLOBALS->ae2,GLOBALS->ae2_fr[i].s);
1015 unsigned int nr = ae2_read_symbol_rows_2(GLOBALS->ae2,GLOBALS->ae2_fr[i].s);
10081016 if(!nr) nr = 1;
10091017 for(r=0;r<nr;r++)
10101018 {
10301038
10311039 autosort = calloc_2(ecyc - cyc + 1, sizeof(struct ae2_ncycle_autosort *));
10321040
1033 for(i=0;i<GLOBALS->numfacs;i++)
1041 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
10341042 {
10351043 if(aet2_rd_get_fac_process_mask(i))
10361044 {
10521060 unsigned long sf = ae2_read_symbol_sparse_flag(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
10531061 if(sf)
10541062 {
1055 int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, cyc);
1063 unsigned int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, cyc);
10561064 if(rows)
10571065 {
10581066 for(r=1;r<rows+1;r++)
10741082 }
10751083 else
10761084 {
1077 int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
1085 unsigned int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
10781086 if(rows)
10791087 {
10801088 for(r=0;r<rows;r++)
11001108
11011109 deadlist=NULL;
11021110
1103 for(i=0;i<GLOBALS->numfacs;i++)
1111 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
11041112 {
11051113 uint64_t ncyc;
11061114 nptr np;
11191127 unsigned long sf = ae2_read_symbol_sparse_flag(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
11201128 if(sf)
11211129 {
1122 int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, cyc);
1130 unsigned int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, cyc);
11231131 uint64_t mxcyc = end_cycle+1;
11241132
11251133 for(r=1;r<rows+1;r++)
11451153 }
11461154 else
11471155 {
1148 int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
1156 unsigned int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
11491157 uint64_t mxcyc = end_cycle+1;
11501158
11511159 for(r=0;r<rows;r++)
12191227 unsigned long sf = ae2_read_symbol_sparse_flag(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
12201228 if(sf)
12211229 {
1222 int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, step_cyc);
1230 unsigned int rows = ae2_read_num_sparse_rows(GLOBALS->ae2, GLOBALS->ae2_fr[i].s, step_cyc);
12231231 uint64_t mxcyc = end_cycle+1;
12241232
12251233 for(r=1;r<rows+1;r++)
12521260 }
12531261 else
12541262 {
1255 int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
1263 unsigned int rows = ae2_read_symbol_rows_2(GLOBALS->ae2, GLOBALS->ae2_fr[i].s);
12561264 uint64_t mxcyc = end_cycle+1;
12571265
12581266 for(r=0;r<rows;r++)
13081316 }
13091317
13101318
1311 for(i=0;i<GLOBALS->numfacs;i++)
1319 for(i=0;i<(unsigned int)GLOBALS->numfacs;i++)
13121320 {
13131321 if(aet2_rd_get_fac_process_mask(i))
13141322 {
1315 int nr = ae2_read_symbol_rows_2(GLOBALS->ae2,GLOBALS->ae2_fr[i].s);
1323 unsigned int nr = ae2_read_symbol_rows_2(GLOBALS->ae2,GLOBALS->ae2_fr[i].s);
13161324 if(!nr) nr = 1;
13171325 for(r=0;r<nr;r++)
13181326 {
577577 #ifdef WAVE_ARRAY_SUPPORT
578578 else
579579 {
580 int i;
580 unsigned int i;
581581 int rc = 1;
582582
583583 for(i=0;i<nd->array_height;i++)
149149 #endif
150150
151151
152 #define MAX_HISTENT_TIME (~( (ULLDescriptor(-1)) << (sizeof(TimeType) * 8 - 1)))
152 #define MAX_HISTENT_TIME ((TimeType)(~( (ULLDescriptor(-1)) << (sizeof(TimeType) * 8 - 1))))
153153
154154
155155 typedef struct ExpandInfo /* only used when expanding atomic vex.. */
15261526 static void heapify(int i, int heap_size)
15271527 {
15281528 int l, r;
1529 unsigned int largest;
1529 int largest;
15301530 struct symbol *t;
15311531 int maxele=heap_size/2-1; /* points to where heapswaps don't matter anymore */
15321532
3535
3636 static void GuiDoEvent(GdkEvent *event, gpointer data)
3737 {
38 (void)data;
39
3840 if(!GLOBALS->busy_busy_c_1)
3941 {
4042 gtk_main_do_event(event);
127129
128130 void set_window_busy_no_refresh(GtkWidget *w)
129131 {
130 int i;
132 unsigned int i;
131133
132134 /* if(GLOBALS->tree_dnd_begin) return; */
133135
154156
155157 void set_window_idle(GtkWidget *w)
156158 {
157 int i;
159 unsigned int i;
158160
159161 /* if(GLOBALS->tree_dnd_begin) return; */
160162
543543
544544 char *tmpnam_2(char *s, int *fd)
545545 {
546 (void)s;
547
546548 #if defined _MSC_VER || defined __MINGW32__
547549 char *fname = NULL;
548550 TCHAR szTempFileName[MAX_PATH];
699701 FILE *f = fopen(path, "rb");
700702 if(f)
701703 {
702 unsigned int hdr[2] = { 0, 0 };
704 int hdr[2] = { 0, 0 };
703705 unsigned int magic_word;
704706
705707 hdr[0] = fgetc(f);
511511 void
512512 service_left_edge(GtkWidget *text, gpointer data)
513513 {
514 (void)text;
515 (void)data;
516
514517 if(GLOBALS->helpbox_is_active)
515518 {
516519 help_text_bold("\n\nFind Previous Edge");
529532 void
530533 service_right_edge(GtkWidget *text, gpointer data)
531534 {
535 (void)text;
536 (void)data;
537
532538 if(GLOBALS->helpbox_is_active)
533539 {
534540 help_text_bold("\n\nFind Next Edge");
1212 #include "gtk12compat.h"
1313 #include "menu.h"
1414 #include "debug.h"
15 #include <cocoa_misc.h>
1516 #include <string.h>
1617
1718 #ifdef MAC_INTEGRATION
2223 #ifndef WAVE_MAC_USE_ENTRY
2324 static gint keypress_local(GtkWidget *widget, GdkEventKey *event, gpointer data)
2425 {
26 (void)widget;
27 (void)event;
28 (void)data;
29
2530 if(GLOBALS->window_entry_c_1)
2631 {
2732 gdk_window_raise(GLOBALS->window_entry_c_1->window);
3439 #ifndef WAVE_MAC_USE_ENTRY
3540 static void enter_callback(GtkWidget *widget, GtkWidget *nothing)
3641 {
42 (void)widget;
43 (void)nothing;
44
3745 G_CONST_RETURN gchar *entry_text;
3846 int len;
3947 entry_text = gtk_entry_get_text(GTK_ENTRY(GLOBALS->entry_entry_c_1));
5159
5260 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
5361 {
62 (void)widget;
63 (void)nothing;
64
5465 DEBUG(printf("Entry Cancel\n"));
5566 GLOBALS->entrybox_text=NULL;
5667 wave_gtk_grab_remove(GLOBALS->window_entry_c_1);
6172
6273 void entrybox(char *title, int width, char *dflt_text, char *comment, int maxch, GtkSignalFunc func)
6374 {
75 #ifndef WAVE_MAC_USE_ENTRY
6476 GtkWidget *vbox, *hbox;
6577 GtkWidget *button1, *button2;
6678 int height = (comment) ? 75 : 60;
79 #endif
6780
6881 GLOBALS->cleanup_entry_c_1=func;
6982
92105 #ifdef WAVE_MAC_USE_ENTRY
93106 {
94107 char *out_text_entry = NULL;
95 int rc = entrybox_req_bridge(title, width, dflt_text, comment, maxch, &out_text_entry);
108 entrybox_req_bridge(title, width, dflt_text, comment, maxch, &out_text_entry);
96109 if(out_text_entry)
97110 {
98111 int len=strlen(out_text_entry);
3737
3838 TimeType extload_main(char *fname, char *skip_start, char *skip_end)
3939 {
40 (void)fname;
41 (void)skip_start;
42 (void)skip_end;
43
4044 fprintf(stderr, "%s", extload_loader_fail_msg);
4145 exit(255);
4246
4549
4650 void import_extload_trace(nptr np)
4751 {
52 (void)np;
53
4854 fprintf(stderr, "%s", extload_loader_fail_msg);
4955 exit(255);
5056 }
5763
5864 void fsdb_set_fac_process_mask(nptr np)
5965 {
66 (void)np;
67
6068 fprintf(stderr, "%s", extload_loader_fail_msg);
6169 exit(255);
6270 }
12651273 struct fac *f;
12661274 int txidx, txidx_in_trace;
12671275 nptr nold = np;
1268 #ifdef WAVE_FSDB_READER_IS_PRESENT
1269 void *trans_info;
1270 #endif
12711276
12721277 if(!(f=np->mv.mvlfac)) return; /* already imported */
12731278
15211526
15221527 fsdbReaderAddToSignalList(GLOBALS->extload_ffr_ctx, txidx_in_trace);
15231528 }
1524 #endif
1525 }
1526
1527 #endif
1529 #else
1530 (void)np;
1531 #endif
1532 }
1533
1534 #endif
1616 void
1717 fetch_left(GtkWidget *text, gpointer data)
1818 {
19 (void)text;
20 (void)data;
21
1922 TimeType newlo;
2023 char fromstr[32];
2124
5457 void
5558 fetch_right(GtkWidget *text, gpointer data)
5659 {
60 (void)text;
61 (void)data;
62
5763 TimeType newhi;
5864 char tostr[32];
5965
9096 void
9197 discard_left(GtkWidget *text, gpointer data)
9298 {
99 (void)text;
100 (void)data;
101
93102 TimeType newlo;
94103 char tostr[32];
95104
121130 void
122131 discard_right(GtkWidget *text, gpointer data)
123132 {
133 (void)text;
134 (void)data;
135
124136 TimeType newhi;
125137 char tostr[32];
126138
2929 #ifndef MAC_INTEGRATION
3030 static gboolean ffunc (const GtkFileFilterInfo *filter_info, gpointer data)
3131 {
32 (void)data;
33
3234 const char *rms = strrchr(filter_info->filename, '\\');
3335 const char *rms2;
3436
5658 static
5759 void filter_edit_cb (GtkWidget *widget, GdkEventKey *ev, gpointer *data)
5860 {
61 (void)ev;
62
5963 const char *t;
6064 gchar *folder_filename;
6165
104108
105109 static void enter_callback(GtkWidget *widget, GtkFileSelection *fw)
106110 {
111 (void)widget;
112 (void)fw;
113
107114 G_CONST_RETURN char *allocbuf;
108115 int alloclen;
109116
125132
126133 static void cancel_callback(GtkWidget *widget, GtkWidget *nothing)
127134 {
135 (void)widget;
136 (void)nothing;
137
128138 DEBUG(printf("Filesel Entry Cancel\n"));
129139 wave_gtk_grab_remove(GLOBALS->fs_file_c_1);
130140 gtk_widget_destroy(GLOBALS->fs_file_c_1);
134144
135145 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
136146 {
147 (void)widget;
148 (void)nothing;
149
137150 DEBUG(printf("Filesel Destroy\n"));
138151 gtkwave_main_iteration();
139152 if(GLOBALS->bad_cleanup_file_c_1) GLOBALS->bad_cleanup_file_c_1();
147160 char szPath[260]; /* buffer for path name */
148161 char lpstrFilter[260]; /* more than enough room for some patterns */
149162 BOOL rc;
163 #else
164 (void)pattn;
165 (void)is_writemode;
150166 #endif
151167
152168 GLOBALS->fileselbox_text=filesel_path;
206222 {
207223 GLOBALS->filesel_ok=1;
208224 if(*GLOBALS->fileselbox_text) free_2(*GLOBALS->fileselbox_text);
209 *GLOBALS->fileselbox_text=(char *)strdup_2(szFile);
225 if(!is_writemode)
226 {
227 *GLOBALS->fileselbox_text=(char *)strdup_2(szFile);
228 }
229 else
230 {
231 char *suf_str = NULL;
232 int suf_add = 0;
233 int szlen = 0;
234 int suflen = 0;
235
236 if(pattn)
237 {
238 suf_str = strstr(pattn, "*.");
239 if(suf_str) suf_str++;
240 }
241
242 if(suf_str)
243 {
244 szlen = strlen(szFile);
245 suflen = strlen(suf_str);
246 if(suflen > szlen)
247 {
248 suf_add = 1;
249 }
250 else
251 {
252 if(strcasecmp(szFile + (szlen - suflen), suf_str))
253 {
254 suf_add = 1;
255 }
256 }
257 }
258
259 if(suf_str && suf_add)
260 {
261 *GLOBALS->fileselbox_text=(char *)malloc_2(szlen + suflen + 1);
262 strcpy(*GLOBALS->fileselbox_text, szFile);
263 strcpy(*GLOBALS->fileselbox_text + szlen, suf_str);
264 }
265 else
266 {
267 *GLOBALS->fileselbox_text=(char *)strdup_2(szFile);
268 }
269 }
270
210271 GLOBALS->cleanup_file_c_2();
211272 }
212273 else
143143 /******************************************************************/
144144
145145
146 static struct fstHier *extractNextVar(void *xc, int *msb, int *lsb, char **nam, int *namlen, int *nnam_max)
146 static struct fstHier *extractNextVar(void *xc, int *msb, int *lsb, char **nam, int *namlen, unsigned int *nnam_max)
147147 {
148148 struct fstHier *h;
149149 const char *pnts;
478478 struct Node *n;
479479 struct symbol *s, *prevsymroot=NULL, *prevsym=NULL;
480480 signed char scale;
481 unsigned int numalias = 0;
482 unsigned int numvars = 0;
481 int numalias = 0;
482 int numvars = 0;
483483 struct symbol *sym_block = NULL;
484484 struct Node *node_block = NULL;
485485 struct fstHier *h = NULL;
490490 char **f_name = NULL;
491491 int *f_name_len = NULL, *f_name_max_len = NULL;
492492 int allowed_to_autocoalesce;
493 int nnam_max = 0;
493 unsigned int nnam_max = 0;
494494
495495 int f_name_build_buf_len = 128;
496496 char *f_name_build_buf = malloc_2(f_name_build_buf_len + 1);
12321232 */
12331233 static void fst_callback2(void *user_callback_data_pointer, uint64_t tim, fstHandle txidx, const unsigned char *value, uint32_t plen)
12341234 {
1235 (void)user_callback_data_pointer;
1236
12351237 fstHandle facidx = GLOBALS->mvlfacs_fst_rvs_alias[--txidx];
12361238 struct HistEnt *htemp;
12371239 struct lx2_entry *l2e = GLOBALS->fst_table_fst_c_1+facidx;
16251627
16261628 void fst_import_masked(void)
16271629 {
1628 int txidxi, i, cnt;
1630 unsigned int txidxi;
1631 int i, cnt;
16291632 hptr htempx = NULL;
16301633
16311634 cnt = 0;
2525 GConfEntry *entry,
2626 gpointer user_data)
2727 {
28 (void)gclient;
29 (void)cnxn_id;
30 (void)user_data;
31
2832 if (gconf_entry_get_value (entry) == NULL)
2933 {
3034 /* value is unset */
5256 GConfEntry *entry,
5357 gpointer user_data)
5458 {
59 (void)gclient;
60 (void)cnxn_id;
61 (void)user_data;
62
5563 if (gconf_entry_get_value (entry) == NULL)
5664 {
5765 /* value is unset */
8088 GConfEntry *entry,
8189 gpointer user_data)
8290 {
91 (void)gclient;
92 (void)cnxn_id;
93 (void)user_data;
94
8395 if (gconf_entry_get_value (entry) == NULL)
8496 {
8597 /* value is unset */
106118 GConfEntry *entry,
107119 gpointer user_data)
108120 {
121 (void)gclient;
122 (void)cnxn_id;
123 (void)user_data;
124
109125 if (gconf_entry_get_value (entry) == NULL)
110126 {
111127 /* value is unset */
266282
267283 void wave_gconf_init(int argc, char **argv)
268284 {
285 (void)argc;
286 (void)argv;
269287 }
270288
271289 gboolean wave_gconf_client_set_string(const gchar *key, const gchar *val)
272290 {
291 (void)key;
292 (void)val;
293
273294 return(FALSE);
274295 }
275296
276297 void wave_gconf_restore(char **dumpfile, char **savefile, char **rcfile, char **wave_pwd, int *opt_vcd)
277298 {
299 (void)dumpfile;
300 (void)savefile;
301 (void)rcfile;
302 (void)wave_pwd;
303 (void)opt_vcd;
304
278305 /* nothing */
279306 }
280307
567567 ph->nbr_units = 0;
568568 else
569569 {
570 int ix;
570 unsigned int ix;
571571
572572 if (ghw_read_uleb128 (h, &ph->nbr_units) != 0)
573573 {
728728 void
729729 ghw_disp_typename (struct ghw_handler *h, union ghw_type *t)
730730 {
731 (void) h;
732
731733 printf ("%s", t->common.name);
732734 }
733735
747749 if (ghw_read_uleb128 (h, &sig_el) < 0)
748750 return -1;
749751 *sigs = sig_el;
750 if (sig_el >= h->nbr_sigs)
752 if (((int)sig_el) >= h->nbr_sigs)
751753 abort ();
752754 if (h->sigs[sig_el].type == NULL)
753755 h->sigs[sig_el].type = ghw_get_base_type (t);
11351137 int
11361138 ghw_read_eoh (struct ghw_handler *h)
11371139 {
1140 (void) h;
1141
11381142 return 0;
11391143 }
11401144
16511655 ghw_read_section (struct ghw_handler *h)
16521656 {
16531657 unsigned char hdr[4];
1654 int i;
1658 unsigned int i;
16551659
16561660 if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)
16571661 {
17481752 case ghdl_rtik_type_p32:
17491753 case ghdl_rtik_type_p64:
17501754 {
1751 int i;
1755 unsigned int i;
17521756
17531757 struct ghw_type_physical *p = &t->ph;
17541758 printf ("type %s is range <> units\n", p->name);
588588 * markerbox.c
589589 */
590590 NULL, /* window_markerbox_c_4 231 */
591 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* entries_markerbox_c_1 232 */
591 {0}, /* entries_markerbox_c_1 232 */
592592 NULL, /* cleanup_markerbox_c_4 233 */
593593 0, /* dirty_markerbox_c_1 234 */
594 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* shadow_markers_markerbox_c_1 235 */
595 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, /* marker_names */
596 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, /* shadow_marker_names */
594 {0}, /* shadow_markers_markerbox_c_1 235 */
595 {NULL}, /* marker_names */
596 {NULL}, /* shadow_marker_names */
597597
598598
599599 /*
13271327 NULL, /* wavepixmap_wavewindow_c_1 621 */
13281328 NULL, /* wave_vslider 622 */
13291329 NULL, /* wave_hslider */
1330 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* named_markers 623 */
1330 {0}, /* named_markers 623 */
13311331 -1, /* named_marker_lock_idx */
13321332 0, /* made_gc_contexts_wavewindow_c_1 624 */
13331333 0, /* which_t_color */
585585 * markerbox.c
586586 */
587587 GtkWidget *window_markerbox_c_4; /* from markerbox.c 248 */
588 GtkWidget *entries_markerbox_c_1[26]; /* from markerbox.c 249 */
588 GtkWidget *entries_markerbox_c_1[WAVE_NUM_NAMED_MARKERS]; /* from markerbox.c 249 */
589589 void (*cleanup_markerbox_c_4)(void); /* from markerbox.c 250 */
590590 int dirty_markerbox_c_1; /* from markerbox.c 251 */
591 TimeType shadow_markers_markerbox_c_1[26]; /* from markerbox.c 252 */
592 char *marker_names[26]; /* from markerbox.c */
593 char *shadow_marker_names[26]; /* from markerbox.c */
591 TimeType shadow_markers_markerbox_c_1[WAVE_NUM_NAMED_MARKERS]; /* from markerbox.c 252 */
592 char *marker_names[WAVE_NUM_NAMED_MARKERS]; /* from markerbox.c */
593 char *shadow_marker_names[WAVE_NUM_NAMED_MARKERS]; /* from markerbox.c */
594594
595595 /*
596596 * menu.c
12801280 char show_base; /* from wavewindow.c 653 */
12811281 char wave_scrolling; /* from wavewindow.c 654 */
12821282 int vector_padding; /* from wavewindow.c 655 */
1283 int in_button_press_wavewindow_c_1; /* from wavewindow.c 656 */
1283 unsigned int in_button_press_wavewindow_c_1; /* from wavewindow.c 656 */
12841284 char left_justify_sigs; /* from wavewindow.c 657 */
12851285 char zoom_pow10_snap; /* from wavewindow.c 658 */
12861286 char zoom_dyn; /* from menu.c */
13091309 GdkDrawable *wavepixmap_wavewindow_c_1; /* from wavewindow.c 680 */
13101310 GtkObject *wave_vslider; /* from wavewindow.c 681 */
13111311 GtkObject *wave_hslider; /* from wavewindow.c 682 */
1312 TimeType named_markers[26]; /* from wavewindow.c 683 */
1312 TimeType named_markers[WAVE_NUM_NAMED_MARKERS]; /* from wavewindow.c 683 */
13131313 int named_marker_lock_idx; /* from menu.c */
13141314 char made_gc_contexts_wavewindow_c_1; /* from wavewindow.c 684 */
13151315 int which_t_color;
4646 static void
4747 help_realize_text (GtkWidget *text, gpointer data)
4848 {
49 (void)text;
50 (void)data;
51
4952 if(GLOBALS->loaded_file_type == MISSING_FILE)
5053 {
5154 help_text("To load a dumpfile into the viewer, either drag the icon"
119122
120123 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
121124 {
125 (void)widget;
126 (void)nothing;
127
122128 GLOBALS->helpbox_is_active=0;
123129 DEBUG(printf("OK\n"));
124130 gtk_widget_destroy(GLOBALS->window_help_c_2);
3636 #endif
3737 #include <unistd.h>
3838
39 size_t getline_replace(char **buf, size_t *len, FILE *f)
39 ssize_t getline_replace(char **buf, size_t *len, FILE *f)
4040 {
4141 char *fgets_rc;
4242
140140 char *buf = NULL;
141141 size_t glen;
142142 int line = 0;
143 size_t ss;
143 ssize_t ss;
144144 JRB node;
145145 char bin_fixbuff[32769];
146146 char bin_fixbuff2[32769];
2525 * FST_DYNAMIC_ALIAS_DISABLE : dynamic aliases are not processed
2626 * FST_DYNAMIC_ALIAS2_DISABLE : new encoding for dynamic aliases is not generated
2727 * FST_WRITEX_DISABLE : fast write I/O routines are disabled
28 * FST_DISABLE_DUFFS_DEVICE : only if indirect branches are incredibly bad on host arch
2928 *
3029 * possible enables:
3130 *
8180 #include <Judy.h>
8281 #else
8382 /* should be more than enough for fstWriterSetSourceStem() */
84 #define FST_PATH_HASHMASK ((1UL << 16) - 1)
83 #define FST_PATH_HASHMASK ((1UL << 16) - 1)
8584 typedef const void *Pcvoid_t;
8685 typedef void *Pvoid_t;
8786 typedef void **PPvoid_t;
9392
9493
9594 #ifndef FST_WRITEX_DISABLE
96 #define FST_WRITEX_MAX (64 * 1024)
95 #define FST_WRITEX_MAX (64 * 1024)
9796 #else
9897 #define fstWritex(a,b,c) fstFwrite((b), (c), 1, fv)
9998 #endif
102101 /* these defines have a large impact on writer speed when a model has a */
103102 /* huge number of symbols. as a default, use 128MB and increment when */
104103 /* every 1M signals are defined. */
105 #define FST_BREAK_SIZE (1UL << 27)
106 #define FST_BREAK_ADD_SIZE (1UL << 22)
107 #define FST_BREAK_SIZE_MAX (1UL << 31)
108 #define FST_ACTIVATE_HUGE_BREAK (1000000)
109 #define FST_ACTIVATE_HUGE_INC (1000000)
110
111 #define FST_WRITER_STR "fstWriter"
112 #define FST_ID_NAM_SIZ (512)
113 #define FST_ID_NAM_ATTR_SIZ (65536+4096)
114 #define FST_DOUBLE_ENDTEST (2.7182818284590452354)
115 #define FST_HDR_SIM_VERSION_SIZE (128)
116 #define FST_HDR_DATE_SIZE (119)
117 #define FST_HDR_FILETYPE_SIZE (1)
118 #define FST_HDR_TIMEZERO_SIZE (8)
119 #define FST_GZIO_LEN (32768)
120 #define FST_HDR_FOURPACK_DUO_SIZE (4*1024*1024)
104 #define FST_BREAK_SIZE (1UL << 27)
105 #define FST_BREAK_ADD_SIZE (1UL << 22)
106 #define FST_BREAK_SIZE_MAX (1UL << 31)
107 #define FST_ACTIVATE_HUGE_BREAK (1000000)
108 #define FST_ACTIVATE_HUGE_INC (1000000)
109
110 #define FST_WRITER_STR "fstWriter"
111 #define FST_ID_NAM_SIZ (512)
112 #define FST_ID_NAM_ATTR_SIZ (65536+4096)
113 #define FST_DOUBLE_ENDTEST (2.7182818284590452354)
114 #define FST_HDR_SIM_VERSION_SIZE (128)
115 #define FST_HDR_DATE_SIZE (119)
116 #define FST_HDR_FILETYPE_SIZE (1)
117 #define FST_HDR_TIMEZERO_SIZE (8)
118 #define FST_GZIO_LEN (32768)
119 #define FST_HDR_FOURPACK_DUO_SIZE (4*1024*1024)
121120
122121 #if defined(__i386__) || defined(__x86_64__) || defined(_AIX)
123122 #define FST_DO_MISALIGNED_OPS
189188 FILE *fh = NULL;
190189
191190 if(nam) /* cppcheck warning fix: nam is always defined, so this is not needed */
192 {
193 dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
194 if((dwRetVal > MAX_PATH) || (dwRetVal == 0))
195 {
196 fprintf(stderr, "GetTempPath() failed in "__FILE__" line %d, exiting.\n", __LINE__);
197 exit(255);
198 }
199 else
200 {
201 uRetVal = GetTempFileName(lpTempPathBuffer, TEXT("FSTW"), 0, szTempFileName);
202 if (uRetVal == 0)
203 {
204 fprintf(stderr, "GetTempFileName() failed in "__FILE__" line %d, exiting.\n", __LINE__);
205 exit(255);
206 }
207 else
208 {
209 fname = strdup(szTempFileName);
210 }
211 }
212
213 if(fname)
214 {
215 *nam = fname;
216 fh = unlink_fopen(fname, "w+b");
217 }
218 }
191 {
192 dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
193 if((dwRetVal > MAX_PATH) || (dwRetVal == 0))
194 {
195 fprintf(stderr, "GetTempPath() failed in "__FILE__" line %d, exiting.\n", __LINE__);
196 exit(255);
197 }
198 else
199 {
200 uRetVal = GetTempFileName(lpTempPathBuffer, TEXT("FSTW"), 0, szTempFileName);
201 if (uRetVal == 0)
202 {
203 fprintf(stderr, "GetTempFileName() failed in "__FILE__" line %d, exiting.\n", __LINE__);
204 exit(255);
205 }
206 else
207 {
208 fname = strdup(szTempFileName);
209 }
210 }
211
212 if(fname)
213 {
214 *nam = fname;
215 fh = unlink_fopen(fname, "w+b");
216 }
217 }
219218
220219 return(fh);
221220 }
235234 static void tmpfile_close(FILE **f, char **nam)
236235 {
237236 if(f)
238 {
239 if(*f) { fclose(*f); *f = NULL; }
240 }
237 {
238 if(*f) { fclose(*f); *f = NULL; }
239 }
241240
242241 if(nam)
243 {
244 if(*nam)
245 {
246 unlink(*nam);
247 free(*nam);
248 *nam = NULL;
249 }
250 }
242 {
243 if(*nam)
244 {
245 unlink(*nam);
246 free(*nam);
247 *nam = NULL;
248 }
249 }
251250 }
252251
253252 /*****************************************/
309308 #if defined __CYGWIN__ || defined __MINGW32__
310309 #include <limits.h>
311310 #define fstMmap(__addr,__len,__prot,__flags,__fd,__off) fstMmap2((__len), (__fd), (__off))
312 #define fstMunmap(__addr,__len) free(__addr)
311 #define fstMunmap(__addr,__len) free(__addr)
313312
314313 static void *fstMmap2(size_t __len, int __fd, off_t __off)
315314 {
315 (void)__off;
316
316317 unsigned char *pnt = malloc(__len);
317318 off_t cur_offs = lseek(__fd, 0, SEEK_CUR);
318319 size_t i;
319320
320321 lseek(__fd, 0, SEEK_SET);
321322 for(i=0;i<__len;i+=SSIZE_MAX)
322 {
323 read(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i));
324 }
323 {
324 read(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i));
325 }
325326 lseek(__fd, cur_offs, SEEK_SET);
326327 return(pnt);
327328 }
333334 #define FST_CADDR_T_CAST
334335 #endif
335336 #define fstMmap(__addr,__len,__prot,__flags,__fd,__off) (void*)mmap(FST_CADDR_T_CAST (__addr),(__len),(__prot),(__flags),(__fd),(__off))
336 #define fstMunmap(__addr,__len) { if(__addr) munmap(FST_CADDR_T_CAST (__addr),(__len)); }
337 #define fstMunmap(__addr,__len) { if(__addr) munmap(FST_CADDR_T_CAST (__addr),(__len)); }
337338 #endif
338339
339340
364365 int i;
365366
366367 for(i=7;i>=0;i--)
367 {
368 buf[i] = v & 0xff;
369 v >>= 8;
370 }
368 {
369 buf[i] = v & 0xff;
370 v >>= 8;
371 }
371372
372373 fstFwrite(buf, 8, 1, handle);
373374 return(8);
378379 {
379380 uint64_t val = 0;
380381 unsigned char buf[sizeof(uint64_t)];
381 int i;
382 unsigned int i;
382383
383384 fstFread(buf, sizeof(uint64_t), 1, f);
384385 for(i=0;i<sizeof(uint64_t);i++)
385 {
386 val <<= 8;
387 val |= buf[i];
388 }
386 {
387 val <<= 8;
388 val |= buf[i];
389 }
389390
390391 return(val);
391392 }
396397 unsigned char *mem_orig = mem;
397398 uint32_t rc = 0;
398399 while(*mem & 0x80)
399 {
400 mem++;
401 }
400 {
401 mem++;
402 }
402403
403404 *skiplen = mem - mem_orig + 1;
404405 for(;;)
405 {
406 rc <<= 7;
407 rc |= (uint32_t)(*mem & 0x7f);
408 if(mem == mem_orig)
409 {
410 break;
411 }
412 mem--;
413 }
406 {
407 rc <<= 7;
408 rc |= (uint32_t)(*mem & 0x7f);
409 if(mem == mem_orig)
410 {
411 break;
412 }
413 mem--;
414 }
414415
415416 return(rc);
416417 }
421422 unsigned char *mem_orig = mem;
422423
423424 while(*mem & 0x80)
424 {
425 mem++;
426 }
425 {
426 mem++;
427 }
427428
428429 return(mem - mem_orig + 1);
429430 }
462463
463464 while((nxt = nxt>>7)) /* determine len to avoid temp buffer copying to cut down on load-hit-store */
464465 {
465 cnt++;
466 cnt++;
466467 }
467468
468469 pnt -= cnt;
471472
472473 for(i=0;i<cnt;i++) /* now generate left to right as normal */
473474 {
474 nxt = v>>7;
475 nxt = v>>7;
475476 *(spnt++) = ((unsigned char)v) | 0x80;
476477 v = nxt;
477478 }
529530 int ch;
530531
531532 do
532 {
533 ch = fgetc(f);
534 *(mem++) = ch;
535 } while(ch & 0x80);
533 {
534 ch = fgetc(f);
535 *(mem++) = ch;
536 } while(ch & 0x80);
536537 mem--;
537538
538539 for(;;)
558559 int ch;
559560
560561 do
561 {
562 ch = fgetc(f);
563 *(mem++) = ch;
564 } while(ch & 0x80);
562 {
563 ch = fgetc(f);
564 *(mem++) = ch;
565 } while(ch & 0x80);
565566 *skiplen = mem - buf;
566567 mem--;
567568
588589 int ch;
589590
590591 do
591 {
592 ch = fgetc(f);
593 *(mem++) = ch;
594 } while(ch & 0x80);
592 {
593 ch = fgetc(f);
594 *(mem++) = ch;
595 } while(ch & 0x80);
595596 mem--;
596597
597598 for(;;)
797798 int rc = fseeko(stream, offset, whence);
798799
799800 if(rc<0)
800 {
801 xc->fseek_failed = 1;
801 {
802 xc->fseek_failed = 1;
802803 #ifdef FST_DEBUG
803 fprintf(stderr, "Seek to #%"PRId64" (whence = %d) failed!\n", offset, whence);
804 perror("Why");
805 #endif
806 }
804 fprintf(stderr, "Seek to #%"PRId64" (whence = %d) failed!\n", offset, whence);
805 perror("Why");
806 #endif
807 }
807808
808809 return(rc);
809810 }
883884 double endtest = FST_DOUBLE_ENDTEST;
884885 time_t walltime;
885886
886 #define FST_HDR_OFFS_TAG (0)
887 fputc(FST_BL_HDR, xc->handle); /* +0 tag */
888
889 #define FST_HDR_OFFS_SECLEN (FST_HDR_OFFS_TAG + 1)
890 fstWriterUint64(xc->handle, 329); /* +1 section length */
891
892 #define FST_HDR_OFFS_START_TIME (FST_HDR_OFFS_SECLEN + 8)
893 fstWriterUint64(xc->handle, 0); /* +9 start time */
894
895 #define FST_HDR_OFFS_END_TIME (FST_HDR_OFFS_START_TIME + 8)
896 fstWriterUint64(xc->handle, 0); /* +17 end time */
897
898 #define FST_HDR_OFFS_ENDIAN_TEST (FST_HDR_OFFS_END_TIME + 8)
899 fstFwrite(&endtest, 8, 1, xc->handle); /* +25 endian test for reals */
900
901 #define FST_HDR_OFFS_MEM_USED (FST_HDR_OFFS_ENDIAN_TEST + 8)
887 #define FST_HDR_OFFS_TAG (0)
888 fputc(FST_BL_HDR, xc->handle); /* +0 tag */
889
890 #define FST_HDR_OFFS_SECLEN (FST_HDR_OFFS_TAG + 1)
891 fstWriterUint64(xc->handle, 329); /* +1 section length */
892
893 #define FST_HDR_OFFS_START_TIME (FST_HDR_OFFS_SECLEN + 8)
894 fstWriterUint64(xc->handle, 0); /* +9 start time */
895
896 #define FST_HDR_OFFS_END_TIME (FST_HDR_OFFS_START_TIME + 8)
897 fstWriterUint64(xc->handle, 0); /* +17 end time */
898
899 #define FST_HDR_OFFS_ENDIAN_TEST (FST_HDR_OFFS_END_TIME + 8)
900 fstFwrite(&endtest, 8, 1, xc->handle); /* +25 endian test for reals */
901
902 #define FST_HDR_OFFS_MEM_USED (FST_HDR_OFFS_ENDIAN_TEST + 8)
902903 fstWriterUint64(xc->handle, xc->fst_break_size);/* +33 memory used by writer */
903904
904 #define FST_HDR_OFFS_NUM_SCOPES (FST_HDR_OFFS_MEM_USED + 8)
905 fstWriterUint64(xc->handle, 0); /* +41 scope creation count */
906
907 #define FST_HDR_OFFS_NUM_VARS (FST_HDR_OFFS_NUM_SCOPES + 8)
908 fstWriterUint64(xc->handle, 0); /* +49 var creation count */
909
910 #define FST_HDR_OFFS_MAXHANDLE (FST_HDR_OFFS_NUM_VARS + 8)
911 fstWriterUint64(xc->handle, 0); /* +57 max var idcode */
912
913 #define FST_HDR_OFFS_SECTION_CNT (FST_HDR_OFFS_MAXHANDLE + 8)
914 fstWriterUint64(xc->handle, 0); /* +65 vc section count */
915
916 #define FST_HDR_OFFS_TIMESCALE (FST_HDR_OFFS_SECTION_CNT + 8)
917 fputc((-9)&255, xc->handle); /* +73 timescale 1ns */
918
919 #define FST_HDR_OFFS_SIM_VERSION (FST_HDR_OFFS_TIMESCALE + 1)
905 #define FST_HDR_OFFS_NUM_SCOPES (FST_HDR_OFFS_MEM_USED + 8)
906 fstWriterUint64(xc->handle, 0); /* +41 scope creation count */
907
908 #define FST_HDR_OFFS_NUM_VARS (FST_HDR_OFFS_NUM_SCOPES + 8)
909 fstWriterUint64(xc->handle, 0); /* +49 var creation count */
910
911 #define FST_HDR_OFFS_MAXHANDLE (FST_HDR_OFFS_NUM_VARS + 8)
912 fstWriterUint64(xc->handle, 0); /* +57 max var idcode */
913
914 #define FST_HDR_OFFS_SECTION_CNT (FST_HDR_OFFS_MAXHANDLE + 8)
915 fstWriterUint64(xc->handle, 0); /* +65 vc section count */
916
917 #define FST_HDR_OFFS_TIMESCALE (FST_HDR_OFFS_SECTION_CNT + 8)
918 fputc((-9)&255, xc->handle); /* +73 timescale 1ns */
919
920 #define FST_HDR_OFFS_SIM_VERSION (FST_HDR_OFFS_TIMESCALE + 1)
920921 memset(vbuf, 0, FST_HDR_SIM_VERSION_SIZE);
921922 strcpy(vbuf, FST_WRITER_STR);
922923 fstFwrite(vbuf, FST_HDR_SIM_VERSION_SIZE, 1, xc->handle); /* +74 version */
923924
924 #define FST_HDR_OFFS_DATE (FST_HDR_OFFS_SIM_VERSION + FST_HDR_SIM_VERSION_SIZE)
925 #define FST_HDR_OFFS_DATE (FST_HDR_OFFS_SIM_VERSION + FST_HDR_SIM_VERSION_SIZE)
925926 memset(dbuf, 0, FST_HDR_DATE_SIZE);
926927 time(&walltime);
927928 strcpy(dbuf, asctime(localtime(&walltime)));
928 fstFwrite(dbuf, FST_HDR_DATE_SIZE, 1, xc->handle); /* +202 date */
929 fstFwrite(dbuf, FST_HDR_DATE_SIZE, 1, xc->handle); /* +202 date */
929930
930931 /* date size is deliberately overspecified at 119 bytes (originally 128) in order to provide backfill for new args */
931932
932 #define FST_HDR_OFFS_FILETYPE (FST_HDR_OFFS_DATE + FST_HDR_DATE_SIZE)
933 fputc(xc->filetype, xc->handle); /* +321 filetype */
934
935 #define FST_HDR_OFFS_TIMEZERO (FST_HDR_OFFS_FILETYPE + FST_HDR_FILETYPE_SIZE)
936 fstWriterUint64(xc->handle, xc->timezero); /* +322 timezero */
937
938 #define FST_HDR_LENGTH (FST_HDR_OFFS_TIMEZERO + FST_HDR_TIMEZERO_SIZE)
939 /* +330 next section starts here */
933 #define FST_HDR_OFFS_FILETYPE (FST_HDR_OFFS_DATE + FST_HDR_DATE_SIZE)
934 fputc(xc->filetype, xc->handle); /* +321 filetype */
935
936 #define FST_HDR_OFFS_TIMEZERO (FST_HDR_OFFS_FILETYPE + FST_HDR_FILETYPE_SIZE)
937 fstWriterUint64(xc->handle, xc->timezero); /* +322 timezero */
938
939 #define FST_HDR_LENGTH (FST_HDR_OFFS_TIMEZERO + FST_HDR_TIMEZERO_SIZE)
940 /* +330 next section starts here */
940941 fflush(xc->handle);
941942 }
942943
964965
965966 /* do mappings */
966967 if(!xc->valpos_mem)
967 {
968 fflush(xc->valpos_handle);
969 xc->valpos_mem = fstMmap(NULL, xc->maxhandle * 4 * sizeof(uint32_t), PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->valpos_handle), 0);
970 }
968 {
969 fflush(xc->valpos_handle);
970 xc->valpos_mem = fstMmap(NULL, xc->maxhandle * 4 * sizeof(uint32_t), PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->valpos_handle), 0);
971 }
971972 if(!xc->curval_mem)
972 {
973 fflush(xc->curval_handle);
974 xc->curval_mem = fstMmap(NULL, xc->maxvalpos, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->curval_handle), 0);
975 }
973 {
974 fflush(xc->curval_handle);
975 xc->curval_mem = fstMmap(NULL, xc->maxvalpos, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->curval_handle), 0);
976 }
976977 }
977978
978979
979980 static void fstDestroyMmaps(struct fstWriterContext *xc, int is_closing)
980981 {
982 (void)is_closing;
983
981984 fstMunmap(xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t));
982985 xc->valpos_mem = NULL;
983986
984987 #if defined __CYGWIN__ || defined __MINGW32__
985988 if(xc->curval_mem)
986 {
987 if(!is_closing) /* need to flush out for next emulated mmap() read */
988 {
989 unsigned char *pnt = xc->curval_mem;
990 int __fd = fileno(xc->curval_handle);
991 off_t cur_offs = lseek(__fd, 0, SEEK_CUR);
992 size_t i;
993 size_t __len = xc->maxvalpos;
994
995 lseek(__fd, 0, SEEK_SET);
996 for(i=0;i<__len;i+=SSIZE_MAX)
997 {
998 write(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i));
999 }
1000 lseek(__fd, cur_offs, SEEK_SET);
1001 }
1002 }
989 {
990 if(!is_closing) /* need to flush out for next emulated mmap() read */
991 {
992 unsigned char *pnt = xc->curval_mem;
993 int __fd = fileno(xc->curval_handle);
994 off_t cur_offs = lseek(__fd, 0, SEEK_CUR);
995 size_t i;
996 size_t __len = xc->maxvalpos;
997
998 lseek(__fd, 0, SEEK_SET);
999 for(i=0;i<__len;i+=SSIZE_MAX)
1000 {
1001 write(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i));
1002 }
1003 lseek(__fd, cur_offs, SEEK_SET);
1004 }
1005 }
10031006 #endif
10041007
10051008 fstMunmap(xc->curval_mem, xc->maxvalpos);
10201023 FILE *f = fopen("/proc/meminfo", "rb");
10211024
10221025 if(f)
1023 {
1024 char buf[257];
1025 char *s;
1026 while(!feof(f))
1027 {
1028 buf[0] = 0;
1029 s = fgets(buf, 256, f);
1030 if(s && *s)
1031 {
1032 if(!strncmp(s, "MemTotal:", 9))
1033 {
1034 size_t v = atol(s+10);
1035 v *= 1024; /* convert to bytes */
1036 v /= 8; /* chop down to 1/8 physical memory */
1037 if(v > FST_BREAK_SIZE)
1038 {
1039 if(v > FST_BREAK_SIZE_MAX)
1040 {
1041 v = FST_BREAK_SIZE_MAX;
1042 }
1043
1044 xc->fst_huge_break_size = v;
1045 was_set = 1;
1046 break;
1047 }
1048 }
1049 }
1050 }
1051
1052 fclose(f);
1053 }
1026 {
1027 char buf[257];
1028 char *s;
1029 while(!feof(f))
1030 {
1031 buf[0] = 0;
1032 s = fgets(buf, 256, f);
1033 if(s && *s)
1034 {
1035 if(!strncmp(s, "MemTotal:", 9))
1036 {
1037 size_t v = atol(s+10);
1038 v *= 1024; /* convert to bytes */
1039 v /= 8; /* chop down to 1/8 physical memory */
1040 if(v > FST_BREAK_SIZE)
1041 {
1042 if(v > FST_BREAK_SIZE_MAX)
1043 {
1044 v = FST_BREAK_SIZE_MAX;
1045 }
1046
1047 xc->fst_huge_break_size = v;
1048 was_set = 1;
1049 break;
1050 }
1051 }
1052 }
1053 }
1054
1055 fclose(f);
1056 }
10541057
10551058 if(!was_set)
1056 {
1057 xc->fst_huge_break_size = FST_BREAK_SIZE;
1058 }
1059 {
1060 xc->fst_huge_break_size = FST_BREAK_SIZE;
1061 }
10591062 #else
10601063 int mib[2];
10611064 int64_t v;
10651068 mib[1] = HW_MEMSIZE;
10661069 length = sizeof(int64_t);
10671070 if(!sysctl(mib, 2, &v, &length, NULL, 0))
1068 {
1069 v /= 8;
1070
1071 if(v > FST_BREAK_SIZE)
1072 {
1073 if(v > FST_BREAK_SIZE_MAX)
1074 {
1075 v = FST_BREAK_SIZE_MAX;
1076 }
1077
1078 xc->fst_huge_break_size = v;
1079 was_set = 1;
1080 }
1081 }
1071 {
1072 v /= 8;
1073
1074 if(v > (int64_t)FST_BREAK_SIZE)
1075 {
1076 if(v > (int64_t)FST_BREAK_SIZE_MAX)
1077 {
1078 v = FST_BREAK_SIZE_MAX;
1079 }
1080
1081 xc->fst_huge_break_size = v;
1082 was_set = 1;
1083 }
1084 }
10821085
10831086 if(!was_set)
1084 {
1085 xc->fst_huge_break_size = FST_BREAK_SIZE;
1086 }
1087 {
1088 xc->fst_huge_break_size = FST_BREAK_SIZE;
1089 }
10871090 #endif
10881091 #else
10891092 xc->fst_huge_break_size = FST_BREAK_SIZE;
11061109 fstDetermineBreakSize(xc);
11071110
11081111 if((!nam)||
1109 (!(xc->handle=unlink_fopen(nam, "w+b"))))
1112 (!(xc->handle=unlink_fopen(nam, "w+b"))))
11101113 {
11111114 free(xc);
11121115 xc=NULL;
11131116 }
11141117 else
11151118 {
1116 int flen = strlen(nam);
1117 char *hf = calloc(1, flen + 6);
1118
1119 memcpy(hf, nam, flen);
1120 strcpy(hf + flen, ".hier");
1121 xc->hier_handle = unlink_fopen(hf, "w+b");
1122
1123 xc->geom_handle = tmpfile_open(&xc->geom_handle_nam); /* .geom */
1124 xc->valpos_handle = tmpfile_open(&xc->valpos_handle_nam); /* .offs */
1125 xc->curval_handle = tmpfile_open(&xc->curval_handle_nam); /* .bits */
1126 xc->tchn_handle = tmpfile_open(&xc->tchn_handle_nam); /* .tchn */
1127 xc->vchg_alloc_siz = xc->fst_break_size + xc->fst_break_add_size;
1128 xc->vchg_mem = malloc(xc->vchg_alloc_siz);
1129
1130 if(xc->hier_handle && xc->geom_handle && xc->valpos_handle && xc->curval_handle && xc->vchg_mem && xc->tchn_handle)
1131 {
1132 xc->filename = strdup(nam);
1133 xc->is_initial_time = 1;
1134
1135 fstWriterEmitHdrBytes(xc);
1136 xc->nan = strtod("NaN", NULL);
1119 int flen = strlen(nam);
1120 char *hf = calloc(1, flen + 6);
1121
1122 memcpy(hf, nam, flen);
1123 strcpy(hf + flen, ".hier");
1124 xc->hier_handle = unlink_fopen(hf, "w+b");
1125
1126 xc->geom_handle = tmpfile_open(&xc->geom_handle_nam); /* .geom */
1127 xc->valpos_handle = tmpfile_open(&xc->valpos_handle_nam); /* .offs */
1128 xc->curval_handle = tmpfile_open(&xc->curval_handle_nam); /* .bits */
1129 xc->tchn_handle = tmpfile_open(&xc->tchn_handle_nam); /* .tchn */
1130 xc->vchg_alloc_siz = xc->fst_break_size + xc->fst_break_add_size;
1131 xc->vchg_mem = malloc(xc->vchg_alloc_siz);
1132
1133 if(xc->hier_handle && xc->geom_handle && xc->valpos_handle && xc->curval_handle && xc->vchg_mem && xc->tchn_handle)
1134 {
1135 xc->filename = strdup(nam);
1136 xc->is_initial_time = 1;
1137
1138 fstWriterEmitHdrBytes(xc);
1139 xc->nan = strtod("NaN", NULL);
11371140 #ifdef FST_WRITER_PARALLEL
1138 pthread_mutex_init(&xc->mutex, NULL);
1139 pthread_attr_init(&xc->thread_attr);
1140 pthread_attr_setdetachstate(&xc->thread_attr, PTHREAD_CREATE_DETACHED);
1141 #endif
1142 }
1143 else
1144 {
1145 fclose(xc->handle);
1146 if(xc->hier_handle) { fclose(xc->hier_handle); unlink(hf); }
1147 tmpfile_close(&xc->geom_handle, &xc->geom_handle_nam);
1148 tmpfile_close(&xc->valpos_handle, &xc->valpos_handle_nam);
1149 tmpfile_close(&xc->curval_handle, &xc->curval_handle_nam);
1150 tmpfile_close(&xc->tchn_handle, &xc->tchn_handle_nam);
1151 free(xc->vchg_mem);
1152 free(xc);
1153 xc=NULL;
1154 }
1155
1156 free(hf);
1157 }
1141 pthread_mutex_init(&xc->mutex, NULL);
1142 pthread_attr_init(&xc->thread_attr);
1143 pthread_attr_setdetachstate(&xc->thread_attr, PTHREAD_CREATE_DETACHED);
1144 #endif
1145 }
1146 else
1147 {
1148 fclose(xc->handle);
1149 if(xc->hier_handle) { fclose(xc->hier_handle); unlink(hf); }
1150 tmpfile_close(&xc->geom_handle, &xc->geom_handle_nam);
1151 tmpfile_close(&xc->valpos_handle, &xc->valpos_handle_nam);
1152 tmpfile_close(&xc->curval_handle, &xc->curval_handle_nam);
1153 tmpfile_close(&xc->tchn_handle, &xc->tchn_handle_nam);
1154 free(xc->vchg_mem);
1155 free(xc);
1156 xc=NULL;
1157 }
1158
1159 free(hf);
1160 }
11581161
11591162 return(xc);
11601163 }
11681171 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
11691172
11701173 if(xc)
1171 {
1172 unsigned long destlen;
1173 unsigned char *dmem;
1174 {
1175 unsigned long destlen;
1176 unsigned char *dmem;
11741177 int rc;
11751178
1176 destlen = xc->maxvalpos;
1177 dmem = malloc(compressBound(destlen));
1179 destlen = xc->maxvalpos;
1180 dmem = malloc(compressBound(destlen));
11781181 rc = compress2(dmem, &destlen, xc->curval_mem, xc->maxvalpos, 4); /* was 9...which caused performance drag on traces with many signals */
11791182
1180 fputc(FST_BL_SKIP, xc->handle); /* temporarily tag the section, use FST_BL_VCDATA on finalize */
1181 xc->section_start = ftello(xc->handle);
1183 fputc(FST_BL_SKIP, xc->handle); /* temporarily tag the section, use FST_BL_VCDATA on finalize */
1184 xc->section_start = ftello(xc->handle);
11821185 #ifdef FST_WRITER_PARALLEL
1183 if(xc->xc_parent) xc->xc_parent->section_start = xc->section_start;
1184 #endif
1185 xc->section_header_only = 1; /* indicates truncate might be needed */
1186 fstWriterUint64(xc->handle, 0); /* placeholder = section length */
1187 fstWriterUint64(xc->handle, xc->is_initial_time ? xc->firsttime : xc->curtime); /* begin time of section */
1188 fstWriterUint64(xc->handle, xc->curtime); /* end time of section (placeholder) */
1189 fstWriterUint64(xc->handle, 0); /* placeholder = amount of buffer memory required in reader for full vc traversal */
1190 fstWriterVarint(xc->handle, xc->maxvalpos); /* maxvalpos = length of uncompressed data */
1191
1192 if((rc == Z_OK) && (destlen < xc->maxvalpos))
1193 {
1194 fstWriterVarint(xc->handle, destlen); /* length of compressed data */
1195 }
1196 else
1197 {
1198 fstWriterVarint(xc->handle, xc->maxvalpos); /* length of (unable to be) compressed data */
1199 }
1200 fstWriterVarint(xc->handle, xc->maxhandle); /* max handle associated with this data (in case of dynamic facility adds) */
1201
1202 if((rc == Z_OK) && (destlen < xc->maxvalpos))
1203 {
1204 fstFwrite(dmem, destlen, 1, xc->handle);
1205 }
1206 else /* comparison between compressed / decompressed len tells if compressed */
1207 {
1208 fstFwrite(xc->curval_mem, xc->maxvalpos, 1, xc->handle);
1209 }
1210
1211 free(dmem);
1212 }
1186 if(xc->xc_parent) xc->xc_parent->section_start = xc->section_start;
1187 #endif
1188 xc->section_header_only = 1; /* indicates truncate might be needed */
1189 fstWriterUint64(xc->handle, 0); /* placeholder = section length */
1190 fstWriterUint64(xc->handle, xc->is_initial_time ? xc->firsttime : xc->curtime); /* begin time of section */
1191 fstWriterUint64(xc->handle, xc->curtime); /* end time of section (placeholder) */
1192 fstWriterUint64(xc->handle, 0); /* placeholder = amount of buffer memory required in reader for full vc traversal */
1193 fstWriterVarint(xc->handle, xc->maxvalpos); /* maxvalpos = length of uncompressed data */
1194
1195 if((rc == Z_OK) && (destlen < xc->maxvalpos))
1196 {
1197 fstWriterVarint(xc->handle, destlen); /* length of compressed data */
1198 }
1199 else
1200 {
1201 fstWriterVarint(xc->handle, xc->maxvalpos); /* length of (unable to be) compressed data */
1202 }
1203 fstWriterVarint(xc->handle, xc->maxhandle); /* max handle associated with this data (in case of dynamic facility adds) */
1204
1205 if((rc == Z_OK) && (destlen < xc->maxvalpos))
1206 {
1207 fstFwrite(dmem, destlen, 1, xc->handle);
1208 }
1209 else /* comparison between compressed / decompressed len tells if compressed */
1210 {
1211 fstFwrite(xc->curval_mem, xc->maxvalpos, 1, xc->handle);
1212 }
1213
1214 free(dmem);
1215 }
12131216 }
12141217
12151218
12261229 #ifdef FST_DEBUG
12271230 int cnt = 0;
12281231 #endif
1229 int i;
1232 unsigned int i;
12301233 unsigned char *vchg_mem;
12311234 FILE *f;
12321235 off_t fpos, indxpos, endpos;
12681271 vchg_mem = xc->vchg_mem;
12691272
12701273 f = xc->handle;
1271 fstWriterVarint(f, xc->maxhandle); /* emit current number of handles */
1274 fstWriterVarint(f, xc->maxhandle); /* emit current number of handles */
12721275 fputc(xc->fourpack ? '4' : (xc->fastpack ? 'F' : 'Z'), f);
12731276 fpos = 1;
12741277
1275 packmemlen = 1024; /* maintain a running "longest" allocation to */
1276 packmem = malloc(packmemlen); /* prevent continual malloc...free every loop iter */
1278 packmemlen = 1024; /* maintain a running "longest" allocation to */
1279 packmem = malloc(packmemlen); /* prevent continual malloc...free every loop iter */
12771280
12781281 for(i=0;i<xc->maxhandle;i++)
1279 {
1280 vm4ip = &(xc->valpos_mem[4*i]);
1281
1282 if(vm4ip[2])
1283 {
1284 uint32_t offs = vm4ip[2];
1285 uint32_t next_offs;
1286 int wrlen;
1287
1288 vm4ip[2] = fpos;
1289
1290 scratchpnt = scratchpad + xc->vchg_siz; /* build this buffer backwards */
1291 if(vm4ip[1] <= 1)
1292 {
1293 if(vm4ip[1] == 1)
1294 {
1295 wrlen = fstGetVarint32Length(vchg_mem + offs + 4); /* used to advance and determine wrlen */
1282 {
1283 vm4ip = &(xc->valpos_mem[4*i]);
1284
1285 if(vm4ip[2])
1286 {
1287 uint32_t offs = vm4ip[2];
1288 uint32_t next_offs;
1289 unsigned int wrlen;
1290
1291 vm4ip[2] = fpos;
1292
1293 scratchpnt = scratchpad + xc->vchg_siz; /* build this buffer backwards */
1294 if(vm4ip[1] <= 1)
1295 {
1296 if(vm4ip[1] == 1)
1297 {
1298 wrlen = fstGetVarint32Length(vchg_mem + offs + 4); /* used to advance and determine wrlen */
12961299 #ifndef FST_REMOVE_DUPLICATE_VC
1297 xc->curval_mem[vm4ip[0]] = vchg_mem[offs + 4 + wrlen]; /* checkpoint variable */
1298 #endif
1299 while(offs)
1300 {
1301 unsigned char val;
1302 uint32_t time_delta, rcv;
1303 next_offs = fstGetUint32(vchg_mem + offs);
1304 offs += 4;
1305
1306 time_delta = fstGetVarint32(vchg_mem + offs, &wrlen);
1307 val = vchg_mem[offs+wrlen];
1308 offs = next_offs;
1309
1310 switch(val)
1311 {
1312 case '0':
1313 case '1': rcv = ((val&1)<<1) | (time_delta<<2);
1314 break; /* pack more delta bits in for 0/1 vchs */
1315
1316 case 'x': case 'X': rcv = FST_RCV_X | (time_delta<<4); break;
1317 case 'z': case 'Z': rcv = FST_RCV_Z | (time_delta<<4); break;
1318 case 'h': case 'H': rcv = FST_RCV_H | (time_delta<<4); break;
1319 case 'u': case 'U': rcv = FST_RCV_U | (time_delta<<4); break;
1320 case 'w': case 'W': rcv = FST_RCV_W | (time_delta<<4); break;
1321 case 'l': case 'L': rcv = FST_RCV_L | (time_delta<<4); break;
1322 default: rcv = FST_RCV_D | (time_delta<<4); break;
1323 }
1324
1325 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, rcv);
1326 }
1327 }
1328 else
1329 {
1330 /* variable length */
1331 /* fstGetUint32 (next_offs) + fstGetVarint32 (time_delta) + fstGetVarint32 (len) + payload */
1332 unsigned char *pnt;
1333 uint32_t record_len;
1334 uint32_t time_delta;
1335
1336 while(offs)
1337 {
1338 next_offs = fstGetUint32(vchg_mem + offs);
1339 offs += 4;
1340 pnt = vchg_mem + offs;
1341 offs = next_offs;
1342 time_delta = fstGetVarint32(pnt, &wrlen);
1343 pnt += wrlen;
1344 record_len = fstGetVarint32(pnt, &wrlen);
1345 pnt += wrlen;
1346
1347 scratchpnt -= record_len;
1348 memcpy(scratchpnt, pnt, record_len);
1349
1350 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, record_len);
1351 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1)); /* reserve | 1 case for future expansion */
1352 }
1353 }
1354 }
1355 else
1356 {
1357 wrlen = fstGetVarint32Length(vchg_mem + offs + 4); /* used to advance and determine wrlen */
1300 xc->curval_mem[vm4ip[0]] = vchg_mem[offs + 4 + wrlen]; /* checkpoint variable */
1301 #endif
1302 while(offs)
1303 {
1304 unsigned char val;
1305 uint32_t time_delta, rcv;
1306 next_offs = fstGetUint32(vchg_mem + offs);
1307 offs += 4;
1308
1309 time_delta = fstGetVarint32(vchg_mem + offs, (int *)&wrlen);
1310 val = vchg_mem[offs+wrlen];
1311 offs = next_offs;
1312
1313 switch(val)
1314 {
1315 case '0':
1316 case '1': rcv = ((val&1)<<1) | (time_delta<<2);
1317 break; /* pack more delta bits in for 0/1 vchs */
1318
1319 case 'x': case 'X': rcv = FST_RCV_X | (time_delta<<4); break;
1320 case 'z': case 'Z': rcv = FST_RCV_Z | (time_delta<<4); break;
1321 case 'h': case 'H': rcv = FST_RCV_H | (time_delta<<4); break;
1322 case 'u': case 'U': rcv = FST_RCV_U | (time_delta<<4); break;
1323 case 'w': case 'W': rcv = FST_RCV_W | (time_delta<<4); break;
1324 case 'l': case 'L': rcv = FST_RCV_L | (time_delta<<4); break;
1325 default: rcv = FST_RCV_D | (time_delta<<4); break;
1326 }
1327
1328 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, rcv);
1329 }
1330 }
1331 else
1332 {
1333 /* variable length */
1334 /* fstGetUint32 (next_offs) + fstGetVarint32 (time_delta) + fstGetVarint32 (len) + payload */
1335 unsigned char *pnt;
1336 uint32_t record_len;
1337 uint32_t time_delta;
1338
1339 while(offs)
1340 {
1341 next_offs = fstGetUint32(vchg_mem + offs);
1342 offs += 4;
1343 pnt = vchg_mem + offs;
1344 offs = next_offs;
1345 time_delta = fstGetVarint32(pnt, (int *)&wrlen);
1346 pnt += wrlen;
1347 record_len = fstGetVarint32(pnt, (int *)&wrlen);
1348 pnt += wrlen;
1349
1350 scratchpnt -= record_len;
1351 memcpy(scratchpnt, pnt, record_len);
1352
1353 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, record_len);
1354 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1)); /* reserve | 1 case for future expansion */
1355 }
1356 }
1357 }
1358 else
1359 {
1360 wrlen = fstGetVarint32Length(vchg_mem + offs + 4); /* used to advance and determine wrlen */
13581361 #ifndef FST_REMOVE_DUPLICATE_VC
1359 memcpy(xc->curval_mem + vm4ip[0], vchg_mem + offs + 4 + wrlen, vm4ip[1]); /* checkpoint variable */
1360 #endif
1361 while(offs)
1362 {
1363 int idx;
1364 char is_binary = 1;
1365 unsigned char *pnt;
1366 uint32_t time_delta;
1367
1368 next_offs = fstGetUint32(vchg_mem + offs);
1369 offs += 4;
1370
1371 time_delta = fstGetVarint32(vchg_mem + offs, &wrlen);
1372
1373 pnt = vchg_mem+offs+wrlen;
1374 offs = next_offs;
1375
1376 for(idx=0;idx<vm4ip[1];idx++)
1377 {
1378 if((pnt[idx] == '0') || (pnt[idx] == '1'))
1379 {
1380 continue;
1381 }
1382 else
1383 {
1384 is_binary = 0;
1385 break;
1386 }
1387 }
1388
1389 if(is_binary)
1390 {
1391 unsigned char acc = 0;
1392 #ifdef FST_DISABLE_DUFFS_DEVICE
1393 /* old algorithm */
1394 int shift = 7 - ((vm4ip[1]-1) & 7);
1395 for(idx=vm4ip[1]-1;idx>=0;idx--)
1396 {
1397 acc |= (pnt[idx] & 1) << shift;
1398 shift++;
1399 if(shift == 8)
1400 {
1401 *(--scratchpnt) = acc;
1402 shift = 0;
1403 acc = 0;
1404 }
1405 }
1406 #else
1362 memcpy(xc->curval_mem + vm4ip[0], vchg_mem + offs + 4 + wrlen, vm4ip[1]); /* checkpoint variable */
1363 #endif
1364 while(offs)
1365 {
1366 unsigned int idx;
1367 char is_binary = 1;
1368 unsigned char *pnt;
1369 uint32_t time_delta;
1370
1371 next_offs = fstGetUint32(vchg_mem + offs);
1372 offs += 4;
1373
1374 time_delta = fstGetVarint32(vchg_mem + offs, (int *)&wrlen);
1375
1376 pnt = vchg_mem+offs+wrlen;
1377 offs = next_offs;
1378
1379 for(idx=0;idx<vm4ip[1];idx++)
1380 {
1381 if((pnt[idx] == '0') || (pnt[idx] == '1'))
1382 {
1383 continue;
1384 }
1385 else
1386 {
1387 is_binary = 0;
1388 break;
1389 }
1390 }
1391
1392 if(is_binary)
1393 {
1394 unsigned char acc = 0;
14071395 /* new algorithm */
14081396 idx = ((vm4ip[1]+7) & ~7);
14091397 switch(vm4ip[1] & 7)
14201408 idx -= 8;
14211409 } while(idx);
14221410 }
1423 #endif
1424
1425 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1));
1426 }
1427 else
1428 {
1429 scratchpnt -= vm4ip[1];
1430 memcpy(scratchpnt, pnt, vm4ip[1]);
1431
1432 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1) | 1);
1433 }
1434 }
1435 }
1436
1437 wrlen = scratchpad + xc->vchg_siz - scratchpnt;
1438 unc_memreq += wrlen;
1439 if(wrlen > 32)
1440 {
1441 unsigned long destlen = wrlen;
1442 unsigned char *dmem;
1443 int rc;
1444
1445 if(!xc->fastpack)
1446 {
1447 if(wrlen <= packmemlen)
1448 {
1449 dmem = packmem;
1450 }
1451 else
1452 {
1453 free(packmem);
1454 dmem = packmem = malloc(compressBound(packmemlen = wrlen));
1455 }
1456
1457 rc = compress2(dmem, &destlen, scratchpnt, wrlen, 4);
1458 if(rc == Z_OK)
1459 {
1411
1412 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1));
1413 }
1414 else
1415 {
1416 scratchpnt -= vm4ip[1];
1417 memcpy(scratchpnt, pnt, vm4ip[1]);
1418
1419 scratchpnt = fstCopyVarint32ToLeft(scratchpnt, (time_delta << 1) | 1);
1420 }
1421 }
1422 }
1423
1424 wrlen = scratchpad + xc->vchg_siz - scratchpnt;
1425 unc_memreq += wrlen;
1426 if(wrlen > 32)
1427 {
1428 unsigned long destlen = wrlen;
1429 unsigned char *dmem;
1430 unsigned int rc;
1431
1432 if(!xc->fastpack)
1433 {
1434 if(wrlen <= packmemlen)
1435 {
1436 dmem = packmem;
1437 }
1438 else
1439 {
1440 free(packmem);
1441 dmem = packmem = malloc(compressBound(packmemlen = wrlen));
1442 }
1443
1444 rc = compress2(dmem, &destlen, scratchpnt, wrlen, 4);
1445 if(rc == Z_OK)
1446 {
14601447 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1461 PPvoid_t pv = JudyHSIns(&PJHSArray, dmem, destlen, NULL);
1462 if(*pv)
1463 {
1464 uint32_t pvi = (long)(*pv);
1465 vm4ip[2] = -pvi;
1466 }
1467 else
1468 {
1469 *pv = (void *)(long)(i+1);
1470 #endif
1471 fpos += fstWriterVarint(f, wrlen);
1472 fpos += destlen;
1473 fstFwrite(dmem, destlen, 1, f);
1448 PPvoid_t pv = JudyHSIns(&PJHSArray, dmem, destlen, NULL);
1449 if(*pv)
1450 {
1451 uint32_t pvi = (long)(*pv);
1452 vm4ip[2] = -pvi;
1453 }
1454 else
1455 {
1456 *pv = (void *)(long)(i+1);
1457 #endif
1458 fpos += fstWriterVarint(f, wrlen);
1459 fpos += destlen;
1460 fstFwrite(dmem, destlen, 1, f);
14741461 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1475 }
1476 #endif
1477 }
1478 else
1479 {
1462 }
1463 #endif
1464 }
1465 else
1466 {
14801467 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1481 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1482 if(*pv)
1483 {
1484 uint32_t pvi = (long)(*pv);
1485 vm4ip[2] = -pvi;
1486 }
1487 else
1488 {
1489 *pv = (void *)(long)(i+1);
1490 #endif
1491 fpos += fstWriterVarint(f, 0);
1492 fpos += wrlen;
1493 fstFwrite(scratchpnt, wrlen, 1, f);
1468 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1469 if(*pv)
1470 {
1471 uint32_t pvi = (long)(*pv);
1472 vm4ip[2] = -pvi;
1473 }
1474 else
1475 {
1476 *pv = (void *)(long)(i+1);
1477 #endif
1478 fpos += fstWriterVarint(f, 0);
1479 fpos += wrlen;
1480 fstFwrite(scratchpnt, wrlen, 1, f);
14941481 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1495 }
1496 #endif
1497 }
1498 }
1499 else
1500 {
1501 /* this is extremely conservative: fastlz needs +5% for worst case, lz4 needs siz+(siz/255)+16 */
1502 if(((wrlen * 2) + 2) <= packmemlen)
1503 {
1504 dmem = packmem;
1505 }
1506 else
1507 {
1508 free(packmem);
1509 dmem = packmem = malloc(packmemlen = (wrlen * 2) + 2);
1510 }
1511
1512 rc = (xc->fourpack) ? LZ4_compress((char *)scratchpnt, (char *)dmem, wrlen) : fastlz_compress(scratchpnt, wrlen, dmem);
1513 if(rc < destlen)
1514 {
1482 }
1483 #endif
1484 }
1485 }
1486 else
1487 {
1488 /* this is extremely conservative: fastlz needs +5% for worst case, lz4 needs siz+(siz/255)+16 */
1489 if(((wrlen * 2) + 2) <= packmemlen)
1490 {
1491 dmem = packmem;
1492 }
1493 else
1494 {
1495 free(packmem);
1496 dmem = packmem = malloc(packmemlen = (wrlen * 2) + 2);
1497 }
1498
1499 rc = (xc->fourpack) ? LZ4_compress((char *)scratchpnt, (char *)dmem, wrlen) : fastlz_compress(scratchpnt, wrlen, dmem);
1500 if(rc < destlen)
1501 {
15151502 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1516 PPvoid_t pv = JudyHSIns(&PJHSArray, dmem, rc, NULL);
1517 if(*pv)
1518 {
1519 uint32_t pvi = (long)(*pv);
1520 vm4ip[2] = -pvi;
1521 }
1522 else
1523 {
1524 *pv = (void *)(long)(i+1);
1525 #endif
1526 fpos += fstWriterVarint(f, wrlen);
1527 fpos += rc;
1528 fstFwrite(dmem, rc, 1, f);
1503 PPvoid_t pv = JudyHSIns(&PJHSArray, dmem, rc, NULL);
1504 if(*pv)
1505 {
1506 uint32_t pvi = (long)(*pv);
1507 vm4ip[2] = -pvi;
1508 }
1509 else
1510 {
1511 *pv = (void *)(long)(i+1);
1512 #endif
1513 fpos += fstWriterVarint(f, wrlen);
1514 fpos += rc;
1515 fstFwrite(dmem, rc, 1, f);
15291516 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1530 }
1531 #endif
1532 }
1533 else
1534 {
1517 }
1518 #endif
1519 }
1520 else
1521 {
15351522 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1536 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1537 if(*pv)
1538 {
1539 uint32_t pvi = (long)(*pv);
1540 vm4ip[2] = -pvi;
1541 }
1542 else
1543 {
1544 *pv = (void *)(long)(i+1);
1545 #endif
1546 fpos += fstWriterVarint(f, 0);
1547 fpos += wrlen;
1548 fstFwrite(scratchpnt, wrlen, 1, f);
1523 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1524 if(*pv)
1525 {
1526 uint32_t pvi = (long)(*pv);
1527 vm4ip[2] = -pvi;
1528 }
1529 else
1530 {
1531 *pv = (void *)(long)(i+1);
1532 #endif
1533 fpos += fstWriterVarint(f, 0);
1534 fpos += wrlen;
1535 fstFwrite(scratchpnt, wrlen, 1, f);
15491536 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1550 }
1551 #endif
1552 }
1553 }
1554 }
1555 else
1556 {
1537 }
1538 #endif
1539 }
1540 }
1541 }
1542 else
1543 {
15571544 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1558 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1559 if(*pv)
1560 {
1561 uint32_t pvi = (long)(*pv);
1562 vm4ip[2] = -pvi;
1563 }
1564 else
1565 {
1566 *pv = (void *)(long)(i+1);
1567 #endif
1568 fpos += fstWriterVarint(f, 0);
1569 fpos += wrlen;
1570 fstFwrite(scratchpnt, wrlen, 1, f);
1545 PPvoid_t pv = JudyHSIns(&PJHSArray, scratchpnt, wrlen, NULL);
1546 if(*pv)
1547 {
1548 uint32_t pvi = (long)(*pv);
1549 vm4ip[2] = -pvi;
1550 }
1551 else
1552 {
1553 *pv = (void *)(long)(i+1);
1554 #endif
1555 fpos += fstWriterVarint(f, 0);
1556 fpos += wrlen;
1557 fstFwrite(scratchpnt, wrlen, 1, f);
15711558 #ifndef FST_DYNAMIC_ALIAS_DISABLE
1572 }
1573 #endif
1574 }
1575
1576 /* vm4ip[3] = 0; ...redundant with clearing below */
1559 }
1560 #endif
1561 }
1562
1563 /* vm4ip[3] = 0; ...redundant with clearing below */
15771564 #ifdef FST_DEBUG
1578 cnt++;
1579 #endif
1580 }
1581 }
1565 cnt++;
1566 #endif
1567 }
1568 }
15821569
15831570 #ifndef FST_DYNAMIC_ALIAS_DISABLE
15841571 JudyHSFreeArray(&PJHSArray, NULL);
15941581
15951582 #ifndef FST_DYNAMIC_ALIAS2_DISABLE
15961583 if(1)
1597 {
1598 uint32_t prev_alias = 0;
1599
1600 for(i=0;i<xc->maxhandle;i++)
1601 {
1602 vm4ip = &(xc->valpos_mem[4*i]);
1603
1604 if(vm4ip[2])
1605 {
1606 if(zerocnt)
1607 {
1608 fpos += fstWriterVarint(f, (zerocnt << 1));
1609 zerocnt = 0;
1610 }
1611
1612 if(vm4ip[2] & 0x80000000)
1613 {
1614 if(vm4ip[2] != prev_alias)
1615 {
1616 fpos += fstWriterSVarint(f, (((int64_t)((int32_t)(prev_alias = vm4ip[2]))) << 1) | 1);
1617 }
1618 else
1619 {
1620 fpos += fstWriterSVarint(f, (0 << 1) | 1);
1621 }
1622 }
1623 else
1624 {
1625 fpos += fstWriterSVarint(f, ((vm4ip[2] - prevpos) << 1) | 1);
1626 prevpos = vm4ip[2];
1627 }
1628 vm4ip[2] = 0;
1629 vm4ip[3] = 0; /* clear out tchn idx */
1630 }
1631 else
1632 {
1633 zerocnt++;
1634 }
1635 }
1636 }
1637 else
1638 #endif
1639 {
1640 for(i=0;i<xc->maxhandle;i++)
1641 {
1642 vm4ip = &(xc->valpos_mem[4*i]);
1643
1644 if(vm4ip[2])
1645 {
1646 if(zerocnt)
1647 {
1648 fpos += fstWriterVarint(f, (zerocnt << 1));
1649 zerocnt = 0;
1650 }
1651
1652 if(vm4ip[2] & 0x80000000)
1653 {
1654 fpos += fstWriterVarint(f, 0); /* signal, note that using a *signed* varint would be more efficient than this byte escape! */
1655 fpos += fstWriterVarint(f, (-(int32_t)vm4ip[2]));
1656 }
1657 else
1658 {
1659 fpos += fstWriterVarint(f, ((vm4ip[2] - prevpos) << 1) | 1);
1660 prevpos = vm4ip[2];
1661 }
1662 vm4ip[2] = 0;
1663 vm4ip[3] = 0; /* clear out tchn idx */
1664 }
1665 else
1666 {
1667 zerocnt++;
1668 }
1669 }
1670 }
1584 {
1585 uint32_t prev_alias = 0;
1586
1587 for(i=0;i<xc->maxhandle;i++)
1588 {
1589 vm4ip = &(xc->valpos_mem[4*i]);
1590
1591 if(vm4ip[2])
1592 {
1593 if(zerocnt)
1594 {
1595 fpos += fstWriterVarint(f, (zerocnt << 1));
1596 zerocnt = 0;
1597 }
1598
1599 if(vm4ip[2] & 0x80000000)
1600 {
1601 if(vm4ip[2] != prev_alias)
1602 {
1603 fpos += fstWriterSVarint(f, (((int64_t)((int32_t)(prev_alias = vm4ip[2]))) << 1) | 1);
1604 }
1605 else
1606 {
1607 fpos += fstWriterSVarint(f, (0 << 1) | 1);
1608 }
1609 }
1610 else
1611 {
1612 fpos += fstWriterSVarint(f, ((vm4ip[2] - prevpos) << 1) | 1);
1613 prevpos = vm4ip[2];
1614 }
1615 vm4ip[2] = 0;
1616 vm4ip[3] = 0; /* clear out tchn idx */
1617 }
1618 else
1619 {
1620 zerocnt++;
1621 }
1622 }
1623 }
1624 else
1625 #endif
1626 {
1627 for(i=0;i<xc->maxhandle;i++)
1628 {
1629 vm4ip = &(xc->valpos_mem[4*i]);
1630
1631 if(vm4ip[2])
1632 {
1633 if(zerocnt)
1634 {
1635 fpos += fstWriterVarint(f, (zerocnt << 1));
1636 zerocnt = 0;
1637 }
1638
1639 if(vm4ip[2] & 0x80000000)
1640 {
1641 fpos += fstWriterVarint(f, 0); /* signal, note that using a *signed* varint would be more efficient than this byte escape! */
1642 fpos += fstWriterVarint(f, (-(int32_t)vm4ip[2]));
1643 }
1644 else
1645 {
1646 fpos += fstWriterVarint(f, ((vm4ip[2] - prevpos) << 1) | 1);
1647 prevpos = vm4ip[2];
1648 }
1649 vm4ip[2] = 0;
1650 vm4ip[3] = 0; /* clear out tchn idx */
1651 }
1652 else
1653 {
1654 zerocnt++;
1655 }
1656 }
1657 }
16711658
16721659 if(zerocnt)
1673 {
1674 /* fpos += */ fstWriterVarint(f, (zerocnt << 1)); /* scan-build */
1675 }
1660 {
1661 /* fpos += */ fstWriterVarint(f, (zerocnt << 1)); /* scan-build */
1662 }
16761663 #ifdef FST_DEBUG
16771664 fprintf(stderr, "value chains: %d\n", cnt);
16781665 #endif
16811668 xc->vchg_siz = 1;
16821669
16831670 endpos = ftello(xc->handle);
1684 fstWriterUint64(xc->handle, endpos-indxpos); /* write delta index position at very end of block */
1671 fstWriterUint64(xc->handle, endpos-indxpos); /* write delta index position at very end of block */
16851672
16861673 /*emit time changes for block */
16871674 fflush(xc->tchn_handle);
16901677
16911678 tmem = fstMmap(NULL, tlen, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->tchn_handle), 0);
16921679 if(tmem)
1693 {
1694 unsigned long destlen = tlen;
1695 unsigned char *dmem = malloc(compressBound(destlen));
1680 {
1681 unsigned long destlen = tlen;
1682 unsigned char *dmem = malloc(compressBound(destlen));
16961683 int rc = compress2(dmem, &destlen, tmem, tlen, 9);
16971684
1698 if((rc == Z_OK) && (destlen < tlen))
1699 {
1700 fstFwrite(dmem, destlen, 1, xc->handle);
1701 }
1702 else /* comparison between compressed / decompressed len tells if compressed */
1703 {
1704 fstFwrite(tmem, tlen, 1, xc->handle);
1705 destlen = tlen;
1706 }
1707 free(dmem);
1708 fstMunmap(tmem, tlen);
1709 fstWriterUint64(xc->handle, tlen); /* uncompressed */
1710 fstWriterUint64(xc->handle, destlen); /* compressed */
1711 fstWriterUint64(xc->handle, xc->tchn_cnt); /* number of time items */
1712 }
1685 if((rc == Z_OK) && (((off_t)destlen) < tlen))
1686 {
1687 fstFwrite(dmem, destlen, 1, xc->handle);
1688 }
1689 else /* comparison between compressed / decompressed len tells if compressed */
1690 {
1691 fstFwrite(tmem, tlen, 1, xc->handle);
1692 destlen = tlen;
1693 }
1694 free(dmem);
1695 fstMunmap(tmem, tlen);
1696 fstWriterUint64(xc->handle, tlen); /* uncompressed */
1697 fstWriterUint64(xc->handle, destlen); /* compressed */
1698 fstWriterUint64(xc->handle, xc->tchn_cnt); /* number of time items */
1699 }
17131700
17141701 xc->tchn_cnt = xc->tchn_idx = 0;
17151702 fstWriterFseeko(xc, xc->tchn_handle, 0, SEEK_SET);
17181705 /* write block trailer */
17191706 endpos = ftello(xc->handle);
17201707 fstWriterFseeko(xc, xc->handle, xc->section_start, SEEK_SET);
1721 fstWriterUint64(xc->handle, endpos - xc->section_start); /* write block length */
1722 fstWriterFseeko(xc, xc->handle, 8, SEEK_CUR); /* skip begin time */
1723 fstWriterUint64(xc->handle, xc->curtime); /* write end time for section */
1724 fstWriterUint64(xc->handle, unc_memreq); /* amount of buffer memory required in reader for full traversal */
1708 fstWriterUint64(xc->handle, endpos - xc->section_start); /* write block length */
1709 fstWriterFseeko(xc, xc->handle, 8, SEEK_CUR); /* skip begin time */
1710 fstWriterUint64(xc->handle, xc->curtime); /* write end time for section */
1711 fstWriterUint64(xc->handle, unc_memreq); /* amount of buffer memory required in reader for full traversal */
17251712 fflush(xc->handle);
17261713
1727 fstWriterFseeko(xc, xc->handle, xc->section_start-1, SEEK_SET); /* write out FST_BL_VCDATA over FST_BL_SKIP */
1714 fstWriterFseeko(xc, xc->handle, xc->section_start-1, SEEK_SET); /* write out FST_BL_VCDATA over FST_BL_SKIP */
17281715
17291716 #ifndef FST_DYNAMIC_ALIAS_DISABLE
17301717 #ifndef FST_DYNAMIC_ALIAS2_DISABLE
17381725
17391726 fflush(xc->handle);
17401727
1741 fstWriterFseeko(xc, xc->handle, endpos, SEEK_SET); /* seek to end of file */
1742
1743 xc2->section_header_truncpos = endpos; /* cache in case of need to truncate */
1728 fstWriterFseeko(xc, xc->handle, endpos, SEEK_SET); /* seek to end of file */
1729
1730 xc2->section_header_truncpos = endpos; /* cache in case of need to truncate */
17441731 if(xc->dump_size_limit)
1745 {
1746 if(endpos >= xc->dump_size_limit)
1747 {
1748 xc2->skip_writing_section_hdr = 1;
1749 xc2->size_limit_locked = 1;
1750 xc2->is_initial_time = 1; /* to trick emit value and emit time change */
1732 {
1733 if(endpos >= ((off_t)xc->dump_size_limit))
1734 {
1735 xc2->skip_writing_section_hdr = 1;
1736 xc2->size_limit_locked = 1;
1737 xc2->is_initial_time = 1; /* to trick emit value and emit time change */
17511738 #ifdef FST_DEBUG
1752 fprintf(stderr, "<< dump file size limit reached, stopping dumping >>\n");
1753 #endif
1754 }
1755 }
1739 fprintf(stderr, "<< dump file size limit reached, stopping dumping >>\n");
1740 #endif
1741 }
1742 }
17561743
17571744 if(!xc2->skip_writing_section_hdr)
1758 {
1759 fstWriterEmitSectionHeader(xc); /* emit next section header */
1760 }
1745 {
1746 fstWriterEmitSectionHeader(xc); /* emit next section header */
1747 }
17611748 fflush(xc->handle);
17621749
17631750 xc->already_in_flush = 0;
17901777 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
17911778
17921779 if(xc->parallel_enabled)
1793 {
1794 struct fstWriterContext *xc2 = malloc(sizeof(struct fstWriterContext));
1795 int i;
1796
1797 pthread_mutex_lock(&xc->mutex);
1798 pthread_mutex_unlock(&xc->mutex);
1799
1800 xc->xc_parent = xc;
1801 memcpy(xc2, xc, sizeof(struct fstWriterContext));
1802
1803 xc2->valpos_mem = malloc(xc->maxhandle * 4 * sizeof(uint32_t));
1804 memcpy(xc2->valpos_mem, xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t));
1805
1806 /* curval mem is updated in the thread */
1780 {
1781 struct fstWriterContext *xc2 = malloc(sizeof(struct fstWriterContext));
1782 unsigned int i;
1783
1784 pthread_mutex_lock(&xc->mutex);
1785 pthread_mutex_unlock(&xc->mutex);
1786
1787 xc->xc_parent = xc;
1788 memcpy(xc2, xc, sizeof(struct fstWriterContext));
1789
1790 xc2->valpos_mem = malloc(xc->maxhandle * 4 * sizeof(uint32_t));
1791 memcpy(xc2->valpos_mem, xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t));
1792
1793 /* curval mem is updated in the thread */
18071794 #ifdef FST_REMOVE_DUPLICATE_VC
1808 xc2->curval_mem = malloc(xc->maxvalpos);
1809 memcpy(xc2->curval_mem, xc->curval_mem, xc->maxvalpos);
1810 #endif
1811
1812 xc->vchg_mem = malloc(xc->vchg_alloc_siz);
1813 xc->vchg_mem[0] = '!';
1814 xc->vchg_siz = 1;
1815
1816 for(i=0;i<xc->maxhandle;i++)
1817 {
1818 uint32_t *vm4ip = &(xc->valpos_mem[4*i]);
1819 vm4ip[2] = 0; /* zero out offset val */
1820 vm4ip[3] = 0; /* zero out last time change val */
1821 }
1822
1823 xc->tchn_cnt = xc->tchn_idx = 0;
1824 xc->tchn_handle = tmpfile_open(&xc->tchn_handle_nam); /* child thread will deallocate file/name */
1825 fstWriterFseeko(xc, xc->tchn_handle, 0, SEEK_SET);
1826 fstFtruncate(fileno(xc->tchn_handle), 0);
1827
1828 xc->section_header_only = 0;
1829 xc->secnum++;
1830
1831 pthread_mutex_lock(&xc->mutex);
1832
1833 pthread_create(&xc->thread, &xc->thread_attr, fstWriterFlushContextPrivate1, xc2);
1834 }
1835 else
1836 {
1837 if(xc->parallel_was_enabled) /* conservatively block */
1838 {
1839 pthread_mutex_lock(&xc->mutex);
1840 pthread_mutex_unlock(&xc->mutex);
1841 }
1842
1843 xc->xc_parent = xc;
1844 fstWriterFlushContextPrivate2(xc);
1845 }
1795 xc2->curval_mem = malloc(xc->maxvalpos);
1796 memcpy(xc2->curval_mem, xc->curval_mem, xc->maxvalpos);
1797 #endif
1798
1799 xc->vchg_mem = malloc(xc->vchg_alloc_siz);
1800 xc->vchg_mem[0] = '!';
1801 xc->vchg_siz = 1;
1802
1803 for(i=0;i<xc->maxhandle;i++)
1804 {
1805 uint32_t *vm4ip = &(xc->valpos_mem[4*i]);
1806 vm4ip[2] = 0; /* zero out offset val */
1807 vm4ip[3] = 0; /* zero out last time change val */
1808 }
1809
1810 xc->tchn_cnt = xc->tchn_idx = 0;
1811 xc->tchn_handle = tmpfile_open(&xc->tchn_handle_nam); /* child thread will deallocate file/name */
1812 fstWriterFseeko(xc, xc->tchn_handle, 0, SEEK_SET);
1813 fstFtruncate(fileno(xc->tchn_handle), 0);
1814
1815 xc->section_header_only = 0;
1816 xc->secnum++;
1817
1818 pthread_mutex_lock(&xc->mutex);
1819
1820 pthread_create(&xc->thread, &xc->thread_attr, fstWriterFlushContextPrivate1, xc2);
1821 }
1822 else
1823 {
1824 if(xc->parallel_was_enabled) /* conservatively block */
1825 {
1826 pthread_mutex_lock(&xc->mutex);
1827 pthread_mutex_unlock(&xc->mutex);
1828 }
1829
1830 xc->xc_parent = xc;
1831 fstWriterFlushContextPrivate2(xc);
1832 }
18461833 }
18471834 #endif
18481835
18551842 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
18561843 if(xc)
18571844 {
1858 if(xc->tchn_idx > 1)
1859 {
1860 xc->flush_context_pending = 1;
1861 }
1862 }
1845 if(xc->tchn_idx > 1)
1846 {
1847 xc->flush_context_pending = 1;
1848 }
1849 }
18631850 }
18641851
18651852
18721859
18731860 #ifdef FST_WRITER_PARALLEL
18741861 if(xc)
1875 {
1876 pthread_mutex_lock(&xc->mutex);
1877 pthread_mutex_unlock(&xc->mutex);
1878 }
1862 {
1863 pthread_mutex_lock(&xc->mutex);
1864 pthread_mutex_unlock(&xc->mutex);
1865 }
18791866 #endif
18801867
18811868 if(xc && !xc->already_in_close && !xc->already_in_flush)
1882 {
1883 unsigned char *tmem;
1884 off_t fixup_offs, tlen, hlen;
1885
1886 xc->already_in_close = 1; /* never need to zero this out as it is freed at bottom */
1887
1888 if(xc->section_header_only && xc->section_header_truncpos && (xc->vchg_siz <= 1) && (!xc->is_initial_time))
1889 {
1890 fstFtruncate(fileno(xc->handle), xc->section_header_truncpos);
1891 fstWriterFseeko(xc, xc->handle, xc->section_header_truncpos, SEEK_SET);
1892 xc->section_header_only = 0;
1893 }
1894 else
1895 {
1896 xc->skip_writing_section_hdr = 1;
1897 if(!xc->size_limit_locked)
1898 {
1899 if(xc->is_initial_time) /* simulation time never advanced so mock up the changes as time zero ones */
1900 {
1901 fstHandle dupe_idx;
1902
1903 fstWriterEmitTimeChange(xc, 0); /* emit some time change just to have one */
1904 for(dupe_idx = 0; dupe_idx < xc->maxhandle; dupe_idx++) /* now clone the values */
1905 {
1906 fstWriterEmitValueChange(xc, dupe_idx+1, xc->curval_mem + xc->valpos_mem[4*dupe_idx]);
1907 }
1908 }
1909 fstWriterFlushContextPrivate(xc);
1869 {
1870 unsigned char *tmem;
1871 off_t fixup_offs, tlen, hlen;
1872
1873 xc->already_in_close = 1; /* never need to zero this out as it is freed at bottom */
1874
1875 if(xc->section_header_only && xc->section_header_truncpos && (xc->vchg_siz <= 1) && (!xc->is_initial_time))
1876 {
1877 fstFtruncate(fileno(xc->handle), xc->section_header_truncpos);
1878 fstWriterFseeko(xc, xc->handle, xc->section_header_truncpos, SEEK_SET);
1879 xc->section_header_only = 0;
1880 }
1881 else
1882 {
1883 xc->skip_writing_section_hdr = 1;
1884 if(!xc->size_limit_locked)
1885 {
1886 if(xc->is_initial_time) /* simulation time never advanced so mock up the changes as time zero ones */
1887 {
1888 fstHandle dupe_idx;
1889
1890 fstWriterEmitTimeChange(xc, 0); /* emit some time change just to have one */
1891 for(dupe_idx = 0; dupe_idx < xc->maxhandle; dupe_idx++) /* now clone the values */
1892 {
1893 fstWriterEmitValueChange(xc, dupe_idx+1, xc->curval_mem + xc->valpos_mem[4*dupe_idx]);
1894 }
1895 }
1896 fstWriterFlushContextPrivate(xc);
19101897 #ifdef FST_WRITER_PARALLEL
1911 pthread_mutex_lock(&xc->mutex);
1912 pthread_mutex_unlock(&xc->mutex);
1913 #endif
1914 }
1915 }
1916 fstDestroyMmaps(xc, 1);
1917
1918 /* write out geom section */
1919 fflush(xc->geom_handle);
1920 tlen = ftello(xc->geom_handle);
1921 tmem = fstMmap(NULL, tlen, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->geom_handle), 0);
1922 if(tmem)
1923 {
1924 unsigned long destlen = tlen;
1925 unsigned char *dmem = malloc(compressBound(destlen));
1926 int rc = compress2(dmem, &destlen, tmem, tlen, 9);
1927
1928 if((rc != Z_OK) || (destlen > tlen))
1929 {
1930 destlen = tlen;
1931 }
1932
1933 fixup_offs = ftello(xc->handle);
1934 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1935 fstWriterUint64(xc->handle, destlen + 24); /* section length */
1936 fstWriterUint64(xc->handle, tlen); /* uncompressed */
1937 /* compressed len is section length - 24 */
1938 fstWriterUint64(xc->handle, xc->maxhandle); /* maxhandle */
1939 fstFwrite((destlen != tlen) ? dmem : tmem, destlen, 1, xc->handle);
1940 fflush(xc->handle);
1941
1942 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
1943 fputc(FST_BL_GEOM, xc->handle); /* actual tag */
1944
1945 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
1946 fflush(xc->handle);
1947
1948 free(dmem);
1949 fstMunmap(tmem, tlen);
1950 }
1951
1952 if(xc->num_blackouts)
1953 {
1954 uint64_t cur_bl = 0;
1955 off_t bpos, eos;
1956 uint32_t i;
1957
1958 fixup_offs = ftello(xc->handle);
1959 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1960 bpos = fixup_offs + 1;
1961 fstWriterUint64(xc->handle, 0); /* section length */
1962 fstWriterVarint(xc->handle, xc->num_blackouts);
1963
1964 for(i=0;i<xc->num_blackouts;i++)
1965 {
1966 fputc(xc->blackout_head->active, xc->handle);
1967 fstWriterVarint(xc->handle, xc->blackout_head->tim - cur_bl);
1968 cur_bl = xc->blackout_head->tim;
1969 xc->blackout_curr = xc->blackout_head->next;
1970 free(xc->blackout_head);
1971 xc->blackout_head = xc->blackout_curr;
1972 }
1973
1974 eos = ftello(xc->handle);
1975 fstWriterFseeko(xc, xc->handle, bpos, SEEK_SET);
1976 fstWriterUint64(xc->handle, eos - bpos);
1977 fflush(xc->handle);
1978
1979 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
1980 fputc(FST_BL_BLACKOUT, xc->handle); /* actual tag */
1981
1982 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
1983 fflush(xc->handle);
1984 }
1985
1986 if(xc->compress_hier)
1987 {
1988 off_t hl, eos;
1989 gzFile zhandle;
1990 int zfd;
1991 int fourpack_duo = 0;
1898 pthread_mutex_lock(&xc->mutex);
1899 pthread_mutex_unlock(&xc->mutex);
1900 #endif
1901 }
1902 }
1903 fstDestroyMmaps(xc, 1);
1904
1905 /* write out geom section */
1906 fflush(xc->geom_handle);
1907 tlen = ftello(xc->geom_handle);
1908 tmem = fstMmap(NULL, tlen, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->geom_handle), 0);
1909 if(tmem)
1910 {
1911 unsigned long destlen = tlen;
1912 unsigned char *dmem = malloc(compressBound(destlen));
1913 int rc = compress2(dmem, &destlen, tmem, tlen, 9);
1914
1915 if((rc != Z_OK) || (((off_t)destlen) > tlen))
1916 {
1917 destlen = tlen;
1918 }
1919
1920 fixup_offs = ftello(xc->handle);
1921 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1922 fstWriterUint64(xc->handle, destlen + 24); /* section length */
1923 fstWriterUint64(xc->handle, tlen); /* uncompressed */
1924 /* compressed len is section length - 24 */
1925 fstWriterUint64(xc->handle, xc->maxhandle); /* maxhandle */
1926 fstFwrite((((off_t)destlen) != tlen) ? dmem : tmem, destlen, 1, xc->handle);
1927 fflush(xc->handle);
1928
1929 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
1930 fputc(FST_BL_GEOM, xc->handle); /* actual tag */
1931
1932 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
1933 fflush(xc->handle);
1934
1935 free(dmem);
1936 fstMunmap(tmem, tlen);
1937 }
1938
1939 if(xc->num_blackouts)
1940 {
1941 uint64_t cur_bl = 0;
1942 off_t bpos, eos;
1943 uint32_t i;
1944
1945 fixup_offs = ftello(xc->handle);
1946 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1947 bpos = fixup_offs + 1;
1948 fstWriterUint64(xc->handle, 0); /* section length */
1949 fstWriterVarint(xc->handle, xc->num_blackouts);
1950
1951 for(i=0;i<xc->num_blackouts;i++)
1952 {
1953 fputc(xc->blackout_head->active, xc->handle);
1954 fstWriterVarint(xc->handle, xc->blackout_head->tim - cur_bl);
1955 cur_bl = xc->blackout_head->tim;
1956 xc->blackout_curr = xc->blackout_head->next;
1957 free(xc->blackout_head);
1958 xc->blackout_head = xc->blackout_curr;
1959 }
1960
1961 eos = ftello(xc->handle);
1962 fstWriterFseeko(xc, xc->handle, bpos, SEEK_SET);
1963 fstWriterUint64(xc->handle, eos - bpos);
1964 fflush(xc->handle);
1965
1966 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
1967 fputc(FST_BL_BLACKOUT, xc->handle); /* actual tag */
1968
1969 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
1970 fflush(xc->handle);
1971 }
1972
1973 if(xc->compress_hier)
1974 {
1975 off_t hl, eos;
1976 gzFile zhandle;
1977 int zfd;
1978 int fourpack_duo = 0;
19921979 #ifndef __MINGW32__
1993 char *fnam = malloc(strlen(xc->filename) + 5 + 1);
1994 #endif
1995
1996 fixup_offs = ftello(xc->handle);
1997 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1998 hlen = ftello(xc->handle);
1999 fstWriterUint64(xc->handle, 0); /* section length */
2000 fstWriterUint64(xc->handle, xc->hier_file_len); /* uncompressed length */
2001
2002 if(!xc->fourpack)
2003 {
2004 unsigned char *mem = malloc(FST_GZIO_LEN);
2005 zfd = dup(fileno(xc->handle));
2006 fflush(xc->handle);
2007 zhandle = gzdopen(zfd, "wb4");
2008 if(zhandle)
2009 {
2010 fstWriterFseeko(xc, xc->hier_handle, 0, SEEK_SET);
2011 for(hl = 0; hl < xc->hier_file_len; hl += FST_GZIO_LEN)
2012 {
2013 unsigned len = ((xc->hier_file_len - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (xc->hier_file_len - hl);
2014 fstFread(mem, len, 1, xc->hier_handle);
2015 gzwrite(zhandle, mem, len);
2016 }
2017 gzclose(zhandle);
2018 }
2019 else
2020 {
2021 close(zfd);
2022 }
2023 free(mem);
2024 }
2025 else
2026 {
2027 int lz4_maxlen;
2028 unsigned char *mem;
2029 unsigned char *hmem;
2030 int packed_len;
2031
2032 fflush(xc->handle);
2033
2034 lz4_maxlen = LZ4_compressBound(xc->hier_file_len);
2035 mem = malloc(lz4_maxlen);
2036 hmem = fstMmap(NULL, xc->hier_file_len, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->hier_handle), 0);
2037 packed_len = LZ4_compress((char *)hmem, (char *)mem, xc->hier_file_len);
2038 fstMunmap(hmem, xc->hier_file_len);
2039
2040 fourpack_duo = (!xc->repack_on_close) && (xc->hier_file_len > FST_HDR_FOURPACK_DUO_SIZE); /* double pack when hierarchy is large */
2041
2042 if(fourpack_duo) /* double packing with LZ4 is faster than gzip */
2043 {
2044 unsigned char *mem_duo;
2045 int lz4_maxlen_duo;
2046 int packed_len_duo;
2047
2048 lz4_maxlen_duo = LZ4_compressBound(packed_len);
2049 mem_duo = malloc(lz4_maxlen_duo);
2050 packed_len_duo = LZ4_compress((char *)mem, (char *)mem_duo, packed_len);
2051
2052 fstWriterVarint(xc->handle, packed_len); /* 1st round compressed length */
2053 fstFwrite(mem_duo, packed_len_duo, 1, xc->handle);
2054 free(mem_duo);
2055 }
2056 else
2057 {
2058 fstFwrite(mem, packed_len, 1, xc->handle);
2059 }
2060
2061 free(mem);
2062 }
2063
2064 fstWriterFseeko(xc, xc->handle, 0, SEEK_END);
2065 eos = ftello(xc->handle);
2066 fstWriterFseeko(xc, xc->handle, hlen, SEEK_SET);
2067 fstWriterUint64(xc->handle, eos - hlen);
2068 fflush(xc->handle);
2069
2070 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
2071 fputc(xc->fourpack ?
2072 ( fourpack_duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4) :
2073 FST_BL_HIER, xc->handle); /* actual tag now also == compression type */
2074
2075 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
2076 fflush(xc->handle);
1980 char *fnam = malloc(strlen(xc->filename) + 5 + 1);
1981 #endif
1982
1983 fixup_offs = ftello(xc->handle);
1984 fputc(FST_BL_SKIP, xc->handle); /* temporary tag */
1985 hlen = ftello(xc->handle);
1986 fstWriterUint64(xc->handle, 0); /* section length */
1987 fstWriterUint64(xc->handle, xc->hier_file_len); /* uncompressed length */
1988
1989 if(!xc->fourpack)
1990 {
1991 unsigned char *mem = malloc(FST_GZIO_LEN);
1992 zfd = dup(fileno(xc->handle));
1993 fflush(xc->handle);
1994 zhandle = gzdopen(zfd, "wb4");
1995 if(zhandle)
1996 {
1997 fstWriterFseeko(xc, xc->hier_handle, 0, SEEK_SET);
1998 for(hl = 0; hl < xc->hier_file_len; hl += FST_GZIO_LEN)
1999 {
2000 unsigned len = ((xc->hier_file_len - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (xc->hier_file_len - hl);
2001 fstFread(mem, len, 1, xc->hier_handle);
2002 gzwrite(zhandle, mem, len);
2003 }
2004 gzclose(zhandle);
2005 }
2006 else
2007 {
2008 close(zfd);
2009 }
2010 free(mem);
2011 }
2012 else
2013 {
2014 int lz4_maxlen;
2015 unsigned char *mem;
2016 unsigned char *hmem;
2017 int packed_len;
2018
2019 fflush(xc->handle);
2020
2021 lz4_maxlen = LZ4_compressBound(xc->hier_file_len);
2022 mem = malloc(lz4_maxlen);
2023 hmem = fstMmap(NULL, xc->hier_file_len, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->hier_handle), 0);
2024 packed_len = LZ4_compress((char *)hmem, (char *)mem, xc->hier_file_len);
2025 fstMunmap(hmem, xc->hier_file_len);
2026
2027 fourpack_duo = (!xc->repack_on_close) && (xc->hier_file_len > FST_HDR_FOURPACK_DUO_SIZE); /* double pack when hierarchy is large */
2028
2029 if(fourpack_duo) /* double packing with LZ4 is faster than gzip */
2030 {
2031 unsigned char *mem_duo;
2032 int lz4_maxlen_duo;
2033 int packed_len_duo;
2034
2035 lz4_maxlen_duo = LZ4_compressBound(packed_len);
2036 mem_duo = malloc(lz4_maxlen_duo);
2037 packed_len_duo = LZ4_compress((char *)mem, (char *)mem_duo, packed_len);
2038
2039 fstWriterVarint(xc->handle, packed_len); /* 1st round compressed length */
2040 fstFwrite(mem_duo, packed_len_duo, 1, xc->handle);
2041 free(mem_duo);
2042 }
2043 else
2044 {
2045 fstFwrite(mem, packed_len, 1, xc->handle);
2046 }
2047
2048 free(mem);
2049 }
2050
2051 fstWriterFseeko(xc, xc->handle, 0, SEEK_END);
2052 eos = ftello(xc->handle);
2053 fstWriterFseeko(xc, xc->handle, hlen, SEEK_SET);
2054 fstWriterUint64(xc->handle, eos - hlen);
2055 fflush(xc->handle);
2056
2057 fstWriterFseeko(xc, xc->handle, fixup_offs, SEEK_SET);
2058 fputc(xc->fourpack ?
2059 ( fourpack_duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4) :
2060 FST_BL_HIER, xc->handle); /* actual tag now also == compression type */
2061
2062 fstWriterFseeko(xc, xc->handle, 0, SEEK_END); /* move file pointer to end for any section adds */
2063 fflush(xc->handle);
20772064
20782065 #ifndef __MINGW32__
2079 sprintf(fnam, "%s.hier", xc->filename);
2080 unlink(fnam);
2081 free(fnam);
2082 #endif
2083 }
2084
2085 /* finalize out header */
2086 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_START_TIME, SEEK_SET);
2087 fstWriterUint64(xc->handle, xc->firsttime);
2088 fstWriterUint64(xc->handle, xc->curtime);
2089 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_NUM_SCOPES, SEEK_SET);
2090 fstWriterUint64(xc->handle, xc->numscopes);
2091 fstWriterUint64(xc->handle, xc->numsigs);
2092 fstWriterUint64(xc->handle, xc->maxhandle);
2093 fstWriterUint64(xc->handle, xc->secnum);
2094 fflush(xc->handle);
2095
2096 tmpfile_close(&xc->tchn_handle, &xc->tchn_handle_nam);
2097 free(xc->vchg_mem); xc->vchg_mem = NULL;
2098 tmpfile_close(&xc->curval_handle, &xc->curval_handle_nam);
2099 tmpfile_close(&xc->valpos_handle, &xc->valpos_handle_nam);
2100 tmpfile_close(&xc->geom_handle, &xc->geom_handle_nam);
2101 if(xc->hier_handle) { fclose(xc->hier_handle); xc->hier_handle = NULL; }
2102 if(xc->handle)
2103 {
2104 if(xc->repack_on_close)
2105 {
2106 FILE *fp;
2107 off_t offpnt, uclen;
2108 int flen = strlen(xc->filename);
2109 char *hf = calloc(1, flen + 5);
2110
2111 strcpy(hf, xc->filename);
2112 strcpy(hf+flen, ".pak");
2113 fp = fopen(hf, "wb");
2114
2115 if(fp)
2116 {
2117 void *dsth;
2118 int zfd;
2119 char gz_membuf[FST_GZIO_LEN];
2120
2121 fstWriterFseeko(xc, xc->handle, 0, SEEK_END);
2122 uclen = ftello(xc->handle);
2123
2124 fputc(FST_BL_ZWRAPPER, fp);
2125 fstWriterUint64(fp, 0);
2126 fstWriterUint64(fp, uclen);
2127 fflush(fp);
2128
2129 fstWriterFseeko(xc, xc->handle, 0, SEEK_SET);
2130 zfd = dup(fileno(fp));
2131 dsth = gzdopen(zfd, "wb4");
2132 if(dsth)
2133 {
2134 for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN)
2135 {
2136 size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt);
2137 fstFread(gz_membuf, this_len, 1, xc->handle);
2138 gzwrite(dsth, gz_membuf, this_len);
2139 }
2140 gzclose(dsth);
2141 }
2142 else
2143 {
2144 close(zfd);
2145 }
2146 fstWriterFseeko(xc, fp, 0, SEEK_END);
2147 offpnt = ftello(fp);
2148 fstWriterFseeko(xc, fp, 1, SEEK_SET);
2149 fstWriterUint64(fp, offpnt - 1);
2150 fclose(fp);
2151 fclose(xc->handle); xc->handle = NULL;
2152
2153 unlink(xc->filename);
2154 rename(hf, xc->filename);
2155 }
2156 else
2157 {
2158 xc->repack_on_close = 0;
2159 fclose(xc->handle); xc->handle = NULL;
2160 }
2161
2162 free(hf);
2163 }
2164 else
2165 {
2166 fclose(xc->handle); xc->handle = NULL;
2167 }
2168 }
2066 sprintf(fnam, "%s.hier", xc->filename);
2067 unlink(fnam);
2068 free(fnam);
2069 #endif
2070 }
2071
2072 /* finalize out header */
2073 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_START_TIME, SEEK_SET);
2074 fstWriterUint64(xc->handle, xc->firsttime);
2075 fstWriterUint64(xc->handle, xc->curtime);
2076 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_NUM_SCOPES, SEEK_SET);
2077 fstWriterUint64(xc->handle, xc->numscopes);
2078 fstWriterUint64(xc->handle, xc->numsigs);
2079 fstWriterUint64(xc->handle, xc->maxhandle);
2080 fstWriterUint64(xc->handle, xc->secnum);
2081 fflush(xc->handle);
2082
2083 tmpfile_close(&xc->tchn_handle, &xc->tchn_handle_nam);
2084 free(xc->vchg_mem); xc->vchg_mem = NULL;
2085 tmpfile_close(&xc->curval_handle, &xc->curval_handle_nam);
2086 tmpfile_close(&xc->valpos_handle, &xc->valpos_handle_nam);
2087 tmpfile_close(&xc->geom_handle, &xc->geom_handle_nam);
2088 if(xc->hier_handle) { fclose(xc->hier_handle); xc->hier_handle = NULL; }
2089 if(xc->handle)
2090 {
2091 if(xc->repack_on_close)
2092 {
2093 FILE *fp;
2094 off_t offpnt, uclen;
2095 int flen = strlen(xc->filename);
2096 char *hf = calloc(1, flen + 5);
2097
2098 strcpy(hf, xc->filename);
2099 strcpy(hf+flen, ".pak");
2100 fp = fopen(hf, "wb");
2101
2102 if(fp)
2103 {
2104 void *dsth;
2105 int zfd;
2106 char gz_membuf[FST_GZIO_LEN];
2107
2108 fstWriterFseeko(xc, xc->handle, 0, SEEK_END);
2109 uclen = ftello(xc->handle);
2110
2111 fputc(FST_BL_ZWRAPPER, fp);
2112 fstWriterUint64(fp, 0);
2113 fstWriterUint64(fp, uclen);
2114 fflush(fp);
2115
2116 fstWriterFseeko(xc, xc->handle, 0, SEEK_SET);
2117 zfd = dup(fileno(fp));
2118 dsth = gzdopen(zfd, "wb4");
2119 if(dsth)
2120 {
2121 for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN)
2122 {
2123 size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt);
2124 fstFread(gz_membuf, this_len, 1, xc->handle);
2125 gzwrite(dsth, gz_membuf, this_len);
2126 }
2127 gzclose(dsth);
2128 }
2129 else
2130 {
2131 close(zfd);
2132 }
2133 fstWriterFseeko(xc, fp, 0, SEEK_END);
2134 offpnt = ftello(fp);
2135 fstWriterFseeko(xc, fp, 1, SEEK_SET);
2136 fstWriterUint64(fp, offpnt - 1);
2137 fclose(fp);
2138 fclose(xc->handle); xc->handle = NULL;
2139
2140 unlink(xc->filename);
2141 rename(hf, xc->filename);
2142 }
2143 else
2144 {
2145 xc->repack_on_close = 0;
2146 fclose(xc->handle); xc->handle = NULL;
2147 }
2148
2149 free(hf);
2150 }
2151 else
2152 {
2153 fclose(xc->handle); xc->handle = NULL;
2154 }
2155 }
21692156
21702157 #ifdef __MINGW32__
2171 {
2172 int flen = strlen(xc->filename);
2173 char *hf = calloc(1, flen + 6);
2174 strcpy(hf, xc->filename);
2175
2176 if(xc->compress_hier)
2177 {
2178 strcpy(hf + flen, ".hier");
2179 unlink(hf); /* no longer needed as a section now exists for this */
2180 }
2181
2182 free(hf);
2183 }
2158 {
2159 int flen = strlen(xc->filename);
2160 char *hf = calloc(1, flen + 6);
2161 strcpy(hf, xc->filename);
2162
2163 if(xc->compress_hier)
2164 {
2165 strcpy(hf + flen, ".hier");
2166 unlink(hf); /* no longer needed as a section now exists for this */
2167 }
2168
2169 free(hf);
2170 }
21842171 #endif
21852172
21862173 #ifdef FST_WRITER_PARALLEL
2187 pthread_mutex_destroy(&xc->mutex);
2188 pthread_attr_destroy(&xc->thread_attr);
2189 #endif
2190
2191 if(xc->path_array)
2192 {
2174 pthread_mutex_destroy(&xc->mutex);
2175 pthread_attr_destroy(&xc->thread_attr);
2176 #endif
2177
2178 if(xc->path_array)
2179 {
21932180 #ifndef _WAVE_HAVE_JUDY
2194 const uint32_t hashmask = FST_PATH_HASHMASK;
2195 #endif
2196 JudyHSFreeArray(&(xc->path_array), NULL);
2197 }
2198
2199 free(xc->filename); xc->filename = NULL;
2200 free(xc);
2201 }
2181 const uint32_t hashmask = FST_PATH_HASHMASK;
2182 #endif
2183 JudyHSFreeArray(&(xc->path_array), NULL);
2184 }
2185
2186 free(xc->filename); xc->filename = NULL;
2187 free(xc);
2188 }
22022189 }
22032190
22042191
22102197 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
22112198 if(xc)
22122199 {
2213 char s[FST_HDR_DATE_SIZE];
2214 off_t fpos = ftello(xc->handle);
2215 int len = strlen(dat);
2216
2217 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_DATE, SEEK_SET);
2218 memset(s, 0, FST_HDR_DATE_SIZE);
2219 memcpy(s, dat, (len < FST_HDR_DATE_SIZE) ? len : FST_HDR_DATE_SIZE);
2220 fstFwrite(s, FST_HDR_DATE_SIZE, 1, xc->handle);
2221 fflush(xc->handle);
2222 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2223 }
2200 char s[FST_HDR_DATE_SIZE];
2201 off_t fpos = ftello(xc->handle);
2202 int len = strlen(dat);
2203
2204 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_DATE, SEEK_SET);
2205 memset(s, 0, FST_HDR_DATE_SIZE);
2206 memcpy(s, dat, (len < FST_HDR_DATE_SIZE) ? len : FST_HDR_DATE_SIZE);
2207 fstFwrite(s, FST_HDR_DATE_SIZE, 1, xc->handle);
2208 fflush(xc->handle);
2209 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2210 }
22242211 }
22252212
22262213
22292216 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
22302217 if(xc && vers)
22312218 {
2232 char s[FST_HDR_SIM_VERSION_SIZE];
2233 off_t fpos = ftello(xc->handle);
2234 int len = strlen(vers);
2235
2236 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_SIM_VERSION, SEEK_SET);
2237 memset(s, 0, FST_HDR_SIM_VERSION_SIZE);
2238 memcpy(s, vers, (len < FST_HDR_SIM_VERSION_SIZE) ? len : FST_HDR_SIM_VERSION_SIZE);
2239 fstFwrite(s, FST_HDR_SIM_VERSION_SIZE, 1, xc->handle);
2240 fflush(xc->handle);
2241 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2242 }
2219 char s[FST_HDR_SIM_VERSION_SIZE];
2220 off_t fpos = ftello(xc->handle);
2221 int len = strlen(vers);
2222
2223 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_SIM_VERSION, SEEK_SET);
2224 memset(s, 0, FST_HDR_SIM_VERSION_SIZE);
2225 memcpy(s, vers, (len < FST_HDR_SIM_VERSION_SIZE) ? len : FST_HDR_SIM_VERSION_SIZE);
2226 fstFwrite(s, FST_HDR_SIM_VERSION_SIZE, 1, xc->handle);
2227 fflush(xc->handle);
2228 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2229 }
22432230 }
22442231
22452232
22482235 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
22492236 if(xc)
22502237 {
2251 if((filetype >= FST_FT_MIN) && (filetype <= FST_FT_MAX))
2252 {
2253 off_t fpos = ftello(xc->handle);
2254
2255 xc->filetype = filetype;
2256
2257 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_FILETYPE, SEEK_SET);
2258 fputc(xc->filetype, xc->handle);
2259 fflush(xc->handle);
2260 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2261 }
2262 }
2238 if(/*(filetype >= FST_FT_MIN) &&*/ (filetype <= FST_FT_MAX))
2239 {
2240 off_t fpos = ftello(xc->handle);
2241
2242 xc->filetype = filetype;
2243
2244 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_FILETYPE, SEEK_SET);
2245 fputc(xc->filetype, xc->handle);
2246 fflush(xc->handle);
2247 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2248 }
2249 }
22632250 }
22642251
22652252
22682255 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
22692256 if(xc)
22702257 {
2271 unsigned char buf[11]; /* ceil(64/7) = 10 + null term */
2272 unsigned char *pnt = fstCopyVarint64ToRight(buf, arg1);
2273 if(arg1)
2274 {
2275 *pnt = 0; /* this converts any *nonzero* arg1 when made a varint into a null-term string */
2276 }
2277
2278 fstWriterSetAttrBegin(xc, FST_AT_MISC, typ, (char *)buf, arg2);
2279 }
2258 unsigned char buf[11]; /* ceil(64/7) = 10 + null term */
2259 unsigned char *pnt = fstCopyVarint64ToRight(buf, arg1);
2260 if(arg1)
2261 {
2262 *pnt = 0; /* this converts any *nonzero* arg1 when made a varint into a null-term string */
2263 }
2264
2265 fstWriterSetAttrBegin(xc, FST_AT_MISC, typ, (char *)buf, arg2);
2266 }
22802267 }
22812268
22822269
22852272 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
22862273 if(xc && comm)
22872274 {
2288 char *s = strdup(comm);
2289 char *sf = s;
2290
2291 while(*s)
2292 {
2293 if((*s == '\n') || (*s == '\r')) *s = ' ';
2294 s++;
2295 }
2296
2297 fstWriterSetAttrBegin(xc, FST_AT_MISC, typ, sf, arg);
2298 free(sf);
2299 }
2275 char *s = strdup(comm);
2276 char *sf = s;
2277
2278 while(*s)
2279 {
2280 if((*s == '\n') || (*s == '\r')) *s = ' ';
2281 s++;
2282 }
2283
2284 fstWriterSetAttrBegin(xc, FST_AT_MISC, typ, sf, arg);
2285 free(sf);
2286 }
23002287 }
23012288
23022289
23052292 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
23062293
23072294 if(xc && path && path[0])
2308 {
2309 uint64_t sidx = 0;
2310 int slen = strlen(path);
2295 {
2296 uint64_t sidx = 0;
2297 int slen = strlen(path);
23112298 #ifndef _WAVE_HAVE_JUDY
2312 const uint32_t hashmask = FST_PATH_HASHMASK;
2313 const unsigned char *path2 = (const unsigned char *)path;
2299 const uint32_t hashmask = FST_PATH_HASHMASK;
2300 const unsigned char *path2 = (const unsigned char *)path;
23142301 #else
2315 char *path2 = alloca(slen + 1); /* judy lacks const qualifier in its JudyHSIns definition */
2316 strcpy(path2, path);
2317 #endif
2318
2319 PPvoid_t pv = JudyHSIns(&(xc->path_array), path2, slen, NULL);
2302 char *path2 = alloca(slen + 1); /* judy lacks const qualifier in its JudyHSIns definition */
2303 strcpy(path2, path);
2304 #endif
2305
2306 PPvoid_t pv = JudyHSIns(&(xc->path_array), path2, slen, NULL);
23202307 if(*pv)
2321 {
2308 {
23222309 sidx = (long)(*pv);
23232310 }
23242311 else
2325 {
2326 char *rp = NULL;
2327
2328 sidx = ++xc->path_array_count;
2329 *pv = (void *)(long)(xc->path_array_count);
2330
2331 if(use_realpath)
2332 {
2333 rp = fstRealpath(
2312 {
2313 char *rp = NULL;
2314
2315 sidx = ++xc->path_array_count;
2316 *pv = (void *)(long)(xc->path_array_count);
2317
2318 if(use_realpath)
2319 {
2320 rp = fstRealpath(
23342321 #ifndef _WAVE_HAVE_JUDY
2335 (const char *)
2336 #endif
2337 path2, NULL);
2338 }
2339
2340 fstWriterSetAttrGeneric(xc, rp ? rp :
2322 (const char *)
2323 #endif
2324 path2, NULL);
2325 }
2326
2327 fstWriterSetAttrGeneric(xc, rp ? rp :
23412328 #ifndef _WAVE_HAVE_JUDY
2342 (const char *)
2343 #endif
2344 path2, FST_MT_PATHNAME, sidx);
2345
2346 if(rp)
2347 {
2348 free(rp);
2349 }
2350 }
2351
2352 fstWriterSetAttrDoubleArgGeneric(xc, typ, sidx, line);
2353 }
2329 (const char *)
2330 #endif
2331 path2, FST_MT_PATHNAME, sidx);
2332
2333 if(rp)
2334 {
2335 free(rp);
2336 }
2337 }
2338
2339 fstWriterSetAttrDoubleArgGeneric(xc, typ, sidx, line);
2340 }
23542341 }
23552342
23562343
23832370 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
23842371 if(xc)
23852372 {
2386 off_t fpos = ftello(xc->handle);
2387 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_TIMESCALE, SEEK_SET);
2388 fputc(ts & 255, xc->handle);
2389 fflush(xc->handle);
2390 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2391 }
2373 off_t fpos = ftello(xc->handle);
2374 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_TIMESCALE, SEEK_SET);
2375 fputc(ts & 255, xc->handle);
2376 fflush(xc->handle);
2377 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2378 }
23922379 }
23932380
23942381
23982385 if(xc && s)
23992386 {
24002387 int mat = 0;
2401 int seconds_exp = -9;
2402 int tv = atoi(s);
2403 const char *pnt = s;
2404
2405 while(*pnt)
2406 {
2388 int seconds_exp = -9;
2389 int tv = atoi(s);
2390 const char *pnt = s;
2391
2392 while(*pnt)
2393 {
24072394 switch(*pnt)
2408 {
2395 {
24092396 case 'm': seconds_exp = -3; mat = 1; break;
24102397 case 'u': seconds_exp = -6; mat = 1; break;
24112398 case 'n': seconds_exp = -9; mat = 1; break;
24172404 default: break;
24182405 }
24192406
2420 if(mat) break;
2407 if(mat) break;
24212408 pnt++;
24222409 }
24232410
2424 if(tv == 10)
2425 {
2411 if(tv == 10)
2412 {
24262413 seconds_exp++;
24272414 }
24282415 else
24292416 if(tv == 100)
2430 {
2417 {
24312418 seconds_exp+=2;
24322419 }
24332420
2434 fstWriterSetTimescale(ctx, seconds_exp);
2421 fstWriterSetTimescale(ctx, seconds_exp);
24352422 }
24362423 }
24372424
24412428 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
24422429 if(xc)
24432430 {
2444 off_t fpos = ftello(xc->handle);
2445 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_TIMEZERO, SEEK_SET);
2446 fstWriterUint64(xc->handle, (xc->timezero = tim));
2447 fflush(xc->handle);
2448 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2449 }
2431 off_t fpos = ftello(xc->handle);
2432 fstWriterFseeko(xc, xc->handle, FST_HDR_OFFS_TIMEZERO, SEEK_SET);
2433 fstWriterUint64(xc->handle, (xc->timezero = tim));
2434 fflush(xc->handle);
2435 fstWriterFseeko(xc, xc->handle, fpos, SEEK_SET);
2436 }
24502437 }
24512438
24522439
24542441 {
24552442 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
24562443 if(xc)
2457 {
2458 xc->fastpack = (typ != FST_WR_PT_ZLIB);
2459 xc->fourpack = (typ == FST_WR_PT_LZ4);
2460 }
2444 {
2445 xc->fastpack = (typ != FST_WR_PT_ZLIB);
2446 xc->fourpack = (typ == FST_WR_PT_LZ4);
2447 }
24612448 }
24622449
24632450
24652452 {
24662453 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
24672454 if(xc)
2468 {
2469 xc->repack_on_close = (enable != 0);
2470 }
2455 {
2456 xc->repack_on_close = (enable != 0);
2457 }
24712458 }
24722459
24732460
24752462 {
24762463 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
24772464 if(xc)
2478 {
2479 xc->parallel_was_enabled |= xc->parallel_enabled; /* make sticky */
2480 xc->parallel_enabled = (enable != 0);
2465 {
2466 xc->parallel_was_enabled |= xc->parallel_enabled; /* make sticky */
2467 xc->parallel_enabled = (enable != 0);
24812468 #ifndef FST_WRITER_PARALLEL
2482 if(xc->parallel_enabled)
2483 {
2484 fprintf(stderr, "ERROR: fstWriterSetParallelMode(), FST_WRITER_PARALLEL not enabled during compile, exiting.\n");
2485 exit(255);
2486 }
2487 #endif
2488 }
2469 if(xc->parallel_enabled)
2470 {
2471 fprintf(stderr, "ERROR: fstWriterSetParallelMode(), FST_WRITER_PARALLEL not enabled during compile, exiting.\n");
2472 exit(255);
2473 }
2474 #endif
2475 }
24892476 }
24902477
24912478
24932480 {
24942481 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
24952482 if(xc)
2496 {
2497 xc->dump_size_limit = numbytes;
2498 }
2483 {
2484 xc->dump_size_limit = numbytes;
2485 }
24992486 }
25002487
25012488
25412528 uint32_t len, const char *nam, fstHandle aliasHandle)
25422529 {
25432530 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
2544 int i, nlen, is_real;
2531 unsigned int i;
2532 int nlen, is_real;
25452533
25462534 if(xc && nam)
25472535 {
2548 if(xc->valpos_mem)
2549 {
2550 fstDestroyMmaps(xc, 0);
2551 }
2552
2553 fputc(vt, xc->hier_handle);
2554 fputc(vd, xc->hier_handle);
2555 nlen = strlen(nam);
2556 fstFwrite(nam, nlen, 1, xc->hier_handle);
2557 fputc(0, xc->hier_handle);
2558 xc->hier_file_len += (nlen+3);
2559
2560 if((vt == FST_VT_VCD_REAL) || (vt == FST_VT_VCD_REAL_PARAMETER) || (vt == FST_VT_VCD_REALTIME) || (vt == FST_VT_SV_SHORTREAL))
2561 {
2562 is_real = 1;
2563 len = 8; /* recast number of bytes to that of what a double is */
2564 }
2565 else
2566 {
2567 is_real = 0;
2568 if(vt == FST_VT_GEN_STRING)
2569 {
2570 len = 0;
2571 }
2572 }
2573
2574 xc->hier_file_len += fstWriterVarint(xc->hier_handle, len);
2575
2576 if(aliasHandle > xc->maxhandle) aliasHandle = 0;
2577 xc->hier_file_len += fstWriterVarint(xc->hier_handle, aliasHandle);
2578 xc->numsigs++;
2579 if(xc->numsigs == xc->next_huge_break)
2580 {
2581 if(xc->fst_break_size < xc->fst_huge_break_size)
2582 {
2583 xc->next_huge_break += FST_ACTIVATE_HUGE_INC;
2584 xc->fst_break_size += xc->fst_orig_break_size;
2585 xc->fst_break_add_size += xc->fst_orig_break_add_size;
2586
2587 xc->vchg_alloc_siz = xc->fst_break_size + xc->fst_break_add_size;
2588 if(xc->vchg_mem)
2589 {
2590 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2591 }
2592 }
2593 }
2594
2595 if(!aliasHandle)
2596 {
2597 uint32_t zero = 0;
2598
2599 if(len)
2600 {
2601 fstWriterVarint(xc->geom_handle, !is_real ? len : 0); /* geom section encodes reals as zero byte */
2602 }
2603 else
2604 {
2605 fstWriterVarint(xc->geom_handle, 0xFFFFFFFF); /* geom section encodes zero len as 32b -1 */
2606 }
2607
2608 fstFwrite(&xc->maxvalpos, sizeof(uint32_t), 1, xc->valpos_handle);
2609 fstFwrite(&len, sizeof(uint32_t), 1, xc->valpos_handle);
2610 fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);
2611 fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);
2612
2613 if(!is_real)
2614 {
2615 for(i=0;i<len;i++)
2616 {
2617 fputc('x', xc->curval_handle);
2618 }
2619 }
2620 else
2621 {
2622 fstFwrite(&xc->nan, 8, 1, xc->curval_handle); /* initialize doubles to NaN rather than x */
2623 }
2624
2625 xc->maxvalpos+=len;
2626 xc->maxhandle++;
2627 return(xc->maxhandle);
2628 }
2629 else
2630 {
2631 return(aliasHandle);
2632 }
2633 }
2536 if(xc->valpos_mem)
2537 {
2538 fstDestroyMmaps(xc, 0);
2539 }
2540
2541 fputc(vt, xc->hier_handle);
2542 fputc(vd, xc->hier_handle);
2543 nlen = strlen(nam);
2544 fstFwrite(nam, nlen, 1, xc->hier_handle);
2545 fputc(0, xc->hier_handle);
2546 xc->hier_file_len += (nlen+3);
2547
2548 if((vt == FST_VT_VCD_REAL) || (vt == FST_VT_VCD_REAL_PARAMETER) || (vt == FST_VT_VCD_REALTIME) || (vt == FST_VT_SV_SHORTREAL))
2549 {
2550 is_real = 1;
2551 len = 8; /* recast number of bytes to that of what a double is */
2552 }
2553 else
2554 {
2555 is_real = 0;
2556 if(vt == FST_VT_GEN_STRING)
2557 {
2558 len = 0;
2559 }
2560 }
2561
2562 xc->hier_file_len += fstWriterVarint(xc->hier_handle, len);
2563
2564 if(aliasHandle > xc->maxhandle) aliasHandle = 0;
2565 xc->hier_file_len += fstWriterVarint(xc->hier_handle, aliasHandle);
2566 xc->numsigs++;
2567 if(xc->numsigs == xc->next_huge_break)
2568 {
2569 if(xc->fst_break_size < xc->fst_huge_break_size)
2570 {
2571 xc->next_huge_break += FST_ACTIVATE_HUGE_INC;
2572 xc->fst_break_size += xc->fst_orig_break_size;
2573 xc->fst_break_add_size += xc->fst_orig_break_add_size;
2574
2575 xc->vchg_alloc_siz = xc->fst_break_size + xc->fst_break_add_size;
2576 if(xc->vchg_mem)
2577 {
2578 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2579 }
2580 }
2581 }
2582
2583 if(!aliasHandle)
2584 {
2585 uint32_t zero = 0;
2586
2587 if(len)
2588 {
2589 fstWriterVarint(xc->geom_handle, !is_real ? len : 0); /* geom section encodes reals as zero byte */
2590 }
2591 else
2592 {
2593 fstWriterVarint(xc->geom_handle, 0xFFFFFFFF); /* geom section encodes zero len as 32b -1 */
2594 }
2595
2596 fstFwrite(&xc->maxvalpos, sizeof(uint32_t), 1, xc->valpos_handle);
2597 fstFwrite(&len, sizeof(uint32_t), 1, xc->valpos_handle);
2598 fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);
2599 fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);
2600
2601 if(!is_real)
2602 {
2603 for(i=0;i<len;i++)
2604 {
2605 fputc('x', xc->curval_handle);
2606 }
2607 }
2608 else
2609 {
2610 fstFwrite(&xc->nan, 8, 1, xc->curval_handle); /* initialize doubles to NaN rather than x */
2611 }
2612
2613 xc->maxvalpos+=len;
2614 xc->maxhandle++;
2615 return(xc->maxhandle);
2616 }
2617 else
2618 {
2619 return(aliasHandle);
2620 }
2621 }
26342622
26352623 return(0);
26362624 }
26422630 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
26432631
26442632 if(xc)
2645 {
2646 fputc(FST_ST_VCD_SCOPE, xc->hier_handle);
2647 if((scopetype < FST_ST_VCD_MODULE) || (scopetype > FST_ST_MAX)) { scopetype = FST_ST_VCD_MODULE; }
2648 fputc(scopetype, xc->hier_handle);
2649 fprintf(xc->hier_handle, "%s%c%s%c",
2650 scopename ? scopename : "", 0,
2651 scopecomp ? scopecomp : "", 0);
2652
2653 if(scopename)
2654 {
2655 xc->hier_file_len += strlen(scopename);
2656 }
2657 if(scopecomp)
2658 {
2659 xc->hier_file_len += strlen(scopecomp);
2660 }
2661
2662 xc->hier_file_len += 4; /* FST_ST_VCD_SCOPE + scopetype + two string terminating zeros */
2663 xc->numscopes++;
2664 }
2633 {
2634 fputc(FST_ST_VCD_SCOPE, xc->hier_handle);
2635 if(/*(scopetype < FST_ST_VCD_MODULE) ||*/ (scopetype > FST_ST_MAX)) { scopetype = FST_ST_VCD_MODULE; }
2636 fputc(scopetype, xc->hier_handle);
2637 fprintf(xc->hier_handle, "%s%c%s%c",
2638 scopename ? scopename : "", 0,
2639 scopecomp ? scopecomp : "", 0);
2640
2641 if(scopename)
2642 {
2643 xc->hier_file_len += strlen(scopename);
2644 }
2645 if(scopecomp)
2646 {
2647 xc->hier_file_len += strlen(scopecomp);
2648 }
2649
2650 xc->hier_file_len += 4; /* FST_ST_VCD_SCOPE + scopetype + two string terminating zeros */
2651 xc->numscopes++;
2652 }
26652653 }
26662654
26672655
26702658 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
26712659
26722660 if(xc)
2673 {
2674 fputc(FST_ST_VCD_UPSCOPE, xc->hier_handle);
2675 xc->hier_file_len++;
2676 }
2661 {
2662 fputc(FST_ST_VCD_UPSCOPE, xc->hier_handle);
2663 xc->hier_file_len++;
2664 }
26772665 }
26782666
26792667
26832671 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
26842672
26852673 if(xc)
2686 {
2687 fputc(FST_ST_GEN_ATTRBEGIN, xc->hier_handle);
2688 if((attrtype < FST_AT_MISC) || (attrtype > FST_AT_MAX)) { attrtype = FST_AT_MISC; subtype = FST_MT_UNKNOWN; }
2689 fputc(attrtype, xc->hier_handle);
2690
2691 switch(attrtype)
2692 {
2693 case FST_AT_ARRAY: if((subtype < FST_AR_NONE) || (subtype > FST_AR_MAX)) subtype = FST_AR_NONE; break;
2694 case FST_AT_ENUM: if((subtype < FST_EV_SV_INTEGER) || (subtype > FST_EV_MAX)) subtype = FST_EV_SV_INTEGER; break;
2695 case FST_AT_PACK: if((subtype < FST_PT_NONE) || (subtype > FST_PT_MAX)) subtype = FST_PT_NONE; break;
2696
2697 case FST_AT_MISC:
2698 default: break;
2699 }
2700
2701 fputc(subtype, xc->hier_handle);
2702 fprintf(xc->hier_handle, "%s%c",
2703 attrname ? attrname : "", 0);
2704
2705 if(attrname)
2706 {
2707 xc->hier_file_len += strlen(attrname);
2708 }
2709
2710 xc->hier_file_len += 4; /* FST_ST_GEN_ATTRBEGIN + type + subtype + string terminating zero */
2711 xc->hier_file_len += fstWriterVarint(xc->hier_handle, arg);
2712 }
2674 {
2675 fputc(FST_ST_GEN_ATTRBEGIN, xc->hier_handle);
2676 if(/*(attrtype < FST_AT_MISC) ||*/ (attrtype > FST_AT_MAX)) { attrtype = FST_AT_MISC; subtype = FST_MT_UNKNOWN; }
2677 fputc(attrtype, xc->hier_handle);
2678
2679 switch(attrtype)
2680 {
2681 case FST_AT_ARRAY: if((subtype < FST_AR_NONE) || (subtype > FST_AR_MAX)) subtype = FST_AR_NONE; break;
2682 case FST_AT_ENUM: if((subtype < FST_EV_SV_INTEGER) || (subtype > FST_EV_MAX)) subtype = FST_EV_SV_INTEGER; break;
2683 case FST_AT_PACK: if((subtype < FST_PT_NONE) || (subtype > FST_PT_MAX)) subtype = FST_PT_NONE; break;
2684
2685 case FST_AT_MISC:
2686 default: break;
2687 }
2688
2689 fputc(subtype, xc->hier_handle);
2690 fprintf(xc->hier_handle, "%s%c",
2691 attrname ? attrname : "", 0);
2692
2693 if(attrname)
2694 {
2695 xc->hier_file_len += strlen(attrname);
2696 }
2697
2698 xc->hier_file_len += 4; /* FST_ST_GEN_ATTRBEGIN + type + subtype + string terminating zero */
2699 xc->hier_file_len += fstWriterVarint(xc->hier_handle, arg);
2700 }
27132701 }
27142702
27152703
27182706 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
27192707
27202708 if(xc)
2721 {
2722 fputc(FST_ST_GEN_ATTREND, xc->hier_handle);
2723 xc->hier_file_len++;
2724 }
2709 {
2710 fputc(FST_ST_GEN_ATTREND, xc->hier_handle);
2711 xc->hier_file_len++;
2712 }
27252713 }
27262714
27272715
27362724 int len;
27372725
27382726 if((xc) && (handle <= xc->maxhandle))
2739 {
2740 uint32_t fpos;
2741 uint32_t *vm4ip;
2742
2743 if(!xc->valpos_mem)
2744 {
2745 xc->vc_emitted = 1;
2746 fstWriterCreateMmaps(xc);
2747 }
2748
2749 handle--; /* move starting at 1 index to starting at 0 */
2750 vm4ip = &(xc->valpos_mem[4*handle]);
2751
2752 len = vm4ip[1];
2753 if(len) /* len of zero = variable length, use fstWriterEmitVariableLengthValueChange */
2754 {
2755 if(!xc->is_initial_time)
2756 {
2757 fpos = xc->vchg_siz;
2758
2759 if((fpos + len + 10) > xc->vchg_alloc_siz)
2760 {
2761 xc->vchg_alloc_siz += (xc->fst_break_add_size + len); /* +len added in the case of extremely long vectors and small break add sizes */
2762 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2763 if(!xc->vchg_mem)
2764 {
2765 fprintf(stderr, "FATAL ERROR, could not realloc() in fstWriterEmitValueChange, exiting.\n");
2766 exit(255);
2767 }
2768 }
2727 {
2728 uint32_t fpos;
2729 uint32_t *vm4ip;
2730
2731 if(!xc->valpos_mem)
2732 {
2733 xc->vc_emitted = 1;
2734 fstWriterCreateMmaps(xc);
2735 }
2736
2737 handle--; /* move starting at 1 index to starting at 0 */
2738 vm4ip = &(xc->valpos_mem[4*handle]);
2739
2740 len = vm4ip[1];
2741 if(len) /* len of zero = variable length, use fstWriterEmitVariableLengthValueChange */
2742 {
2743 if(!xc->is_initial_time)
2744 {
2745 fpos = xc->vchg_siz;
2746
2747 if((fpos + len + 10) > xc->vchg_alloc_siz)
2748 {
2749 xc->vchg_alloc_siz += (xc->fst_break_add_size + len); /* +len added in the case of extremely long vectors and small break add sizes */
2750 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2751 if(!xc->vchg_mem)
2752 {
2753 fprintf(stderr, "FATAL ERROR, could not realloc() in fstWriterEmitValueChange, exiting.\n");
2754 exit(255);
2755 }
2756 }
27692757 #ifdef FST_REMOVE_DUPLICATE_VC
2770 offs = vm4ip[0];
2771
2772 if(len != 1)
2773 {
2774 if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
2775 {
2776 unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
2777 while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
2778 memcpy(old_value, buf, len); /* overlay new value */
2779
2780 memcpy(xc->curval_mem + offs, buf, len);
2781 return;
2782 }
2783 else
2784 {
2785 if(!memcmp(xc->curval_mem + offs, buf, len))
2786 {
2787 if(!xc->curtime)
2788 {
2789 int i;
2790 for(i=0;i<len;i++)
2791 {
2792 if(buf[i]!='x') break;
2793 }
2794
2795 if(i<len) return;
2796 }
2797 else
2798 {
2799 return;
2800 }
2801 }
2802 }
2803
2804 memcpy(xc->curval_mem + offs, buf, len);
2805 }
2806 else
2807 {
2808 if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
2809 {
2810 unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
2811 while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
2812 *old_value = *buf; /* overlay new value */
2813
2814 *(xc->curval_mem + offs) = *buf;
2815 return;
2816 }
2817 else
2818 {
2819 if((*(xc->curval_mem + offs)) == (*buf))
2820 {
2821 if(!xc->curtime)
2822 {
2823 if(*buf != 'x') return;
2824 }
2825 else
2826 {
2827 return;
2828 }
2829 }
2830 }
2831
2832 *(xc->curval_mem + offs) = *buf;
2833 }
2834 #endif
2835 xc->vchg_siz += fstWriterUint32WithVarint32(xc, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */
2836 vm4ip[3] = xc->tchn_idx;
2837 vm4ip[2] = fpos;
2838 }
2839 else
2840 {
2841 offs = vm4ip[0];
2842 memcpy(xc->curval_mem + offs, buf, len);
2843 }
2844 }
2845 }
2758 offs = vm4ip[0];
2759
2760 if(len != 1)
2761 {
2762 if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
2763 {
2764 unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
2765 while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
2766 memcpy(old_value, buf, len); /* overlay new value */
2767
2768 memcpy(xc->curval_mem + offs, buf, len);
2769 return;
2770 }
2771 else
2772 {
2773 if(!memcmp(xc->curval_mem + offs, buf, len))
2774 {
2775 if(!xc->curtime)
2776 {
2777 int i;
2778 for(i=0;i<len;i++)
2779 {
2780 if(buf[i]!='x') break;
2781 }
2782
2783 if(i<len) return;
2784 }
2785 else
2786 {
2787 return;
2788 }
2789 }
2790 }
2791
2792 memcpy(xc->curval_mem + offs, buf, len);
2793 }
2794 else
2795 {
2796 if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
2797 {
2798 unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
2799 while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
2800 *old_value = *buf; /* overlay new value */
2801
2802 *(xc->curval_mem + offs) = *buf;
2803 return;
2804 }
2805 else
2806 {
2807 if((*(xc->curval_mem + offs)) == (*buf))
2808 {
2809 if(!xc->curtime)
2810 {
2811 if(*buf != 'x') return;
2812 }
2813 else
2814 {
2815 return;
2816 }
2817 }
2818 }
2819
2820 *(xc->curval_mem + offs) = *buf;
2821 }
2822 #endif
2823 xc->vchg_siz += fstWriterUint32WithVarint32(xc, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */
2824 vm4ip[3] = xc->tchn_idx;
2825 vm4ip[2] = fpos;
2826 }
2827 else
2828 {
2829 offs = vm4ip[0];
2830 memcpy(xc->curval_mem + offs, buf, len);
2831 }
2832 }
2833 }
28462834 }
28472835
28482836
28522840 const unsigned char *buf = (const unsigned char *)val;
28532841
28542842 if((xc) && (handle <= xc->maxhandle))
2855 {
2856 uint32_t fpos;
2857 uint32_t *vm4ip;
2858
2859 if(!xc->valpos_mem)
2860 {
2861 xc->vc_emitted = 1;
2862 fstWriterCreateMmaps(xc);
2863 }
2864
2865 handle--; /* move starting at 1 index to starting at 0 */
2866 vm4ip = &(xc->valpos_mem[4*handle]);
2867
2868 /* there is no initial time dump for variable length value changes */
2869 if(!vm4ip[1]) /* len of zero = variable length */
2870 {
2871 fpos = xc->vchg_siz;
2872
2873 if((fpos + len + 10 + 5) > xc->vchg_alloc_siz)
2874 {
2875 xc->vchg_alloc_siz += (xc->fst_break_add_size + len + 5); /* +len added in the case of extremely long vectors and small break add sizes */
2876 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2877 if(!xc->vchg_mem)
2878 {
2879 fprintf(stderr, "FATAL ERROR, could not realloc() in fstWriterEmitVariableLengthValueChange, exiting.\n");
2880 exit(255);
2881 }
2882 }
2883
2884 xc->vchg_siz += fstWriterUint32WithVarint32AndLength(xc, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */
2885 vm4ip[3] = xc->tchn_idx;
2886 vm4ip[2] = fpos;
2887 }
2888 }
2843 {
2844 uint32_t fpos;
2845 uint32_t *vm4ip;
2846
2847 if(!xc->valpos_mem)
2848 {
2849 xc->vc_emitted = 1;
2850 fstWriterCreateMmaps(xc);
2851 }
2852
2853 handle--; /* move starting at 1 index to starting at 0 */
2854 vm4ip = &(xc->valpos_mem[4*handle]);
2855
2856 /* there is no initial time dump for variable length value changes */
2857 if(!vm4ip[1]) /* len of zero = variable length */
2858 {
2859 fpos = xc->vchg_siz;
2860
2861 if((fpos + len + 10 + 5) > xc->vchg_alloc_siz)
2862 {
2863 xc->vchg_alloc_siz += (xc->fst_break_add_size + len + 5); /* +len added in the case of extremely long vectors and small break add sizes */
2864 xc->vchg_mem = realloc(xc->vchg_mem, xc->vchg_alloc_siz);
2865 if(!xc->vchg_mem)
2866 {
2867 fprintf(stderr, "FATAL ERROR, could not realloc() in fstWriterEmitVariableLengthValueChange, exiting.\n");
2868 exit(255);
2869 }
2870 }
2871
2872 xc->vchg_siz += fstWriterUint32WithVarint32AndLength(xc, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */
2873 vm4ip[3] = xc->tchn_idx;
2874 vm4ip[2] = fpos;
2875 }
2876 }
28892877 }
28902878
28912879
28922880 void fstWriterEmitTimeChange(void *ctx, uint64_t tim)
28932881 {
28942882 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
2895 int i;
2883 unsigned int i;
28962884 int skip = 0;
28972885 if(xc)
2898 {
2899 if(xc->is_initial_time)
2900 {
2901 if(xc->size_limit_locked) /* this resets xc->is_initial_time to one */
2902 {
2903 return;
2904 }
2905
2906 if(!xc->valpos_mem)
2907 {
2908 fstWriterCreateMmaps(xc);
2909 }
2910
2911 skip = 1;
2912
2913 xc->firsttime = (xc->vc_emitted) ? 0: tim;
2914 xc->curtime = 0;
2915 xc->vchg_mem[0] = '!';
2916 xc->vchg_siz = 1;
2917 fstWriterEmitSectionHeader(xc);
2918 for(i=0;i<xc->maxhandle;i++)
2919 {
2920 xc->valpos_mem[4*i+2] = 0; /* zero out offset val */
2921 xc->valpos_mem[4*i+3] = 0; /* zero out last time change val */
2922 }
2923 xc->is_initial_time = 0;
2924 }
2925 else
2926 {
2927 if((xc->vchg_siz >= xc->fst_break_size) || (xc->flush_context_pending))
2928 {
2929 xc->flush_context_pending = 0;
2930 fstWriterFlushContextPrivate(xc);
2931 xc->tchn_cnt++;
2932 fstWriterVarint(xc->tchn_handle, xc->curtime);
2933 }
2934 }
2935
2936 if(!skip)
2937 {
2938 xc->tchn_idx++;
2939 }
2940 fstWriterVarint(xc->tchn_handle, tim - xc->curtime);
2941 xc->tchn_cnt++;
2942 xc->curtime = tim;
2943 }
2886 {
2887 if(xc->is_initial_time)
2888 {
2889 if(xc->size_limit_locked) /* this resets xc->is_initial_time to one */
2890 {
2891 return;
2892 }
2893
2894 if(!xc->valpos_mem)
2895 {
2896 fstWriterCreateMmaps(xc);
2897 }
2898
2899 skip = 1;
2900
2901 xc->firsttime = (xc->vc_emitted) ? 0: tim;
2902 xc->curtime = 0;
2903 xc->vchg_mem[0] = '!';
2904 xc->vchg_siz = 1;
2905 fstWriterEmitSectionHeader(xc);
2906 for(i=0;i<xc->maxhandle;i++)
2907 {
2908 xc->valpos_mem[4*i+2] = 0; /* zero out offset val */
2909 xc->valpos_mem[4*i+3] = 0; /* zero out last time change val */
2910 }
2911 xc->is_initial_time = 0;
2912 }
2913 else
2914 {
2915 if((xc->vchg_siz >= xc->fst_break_size) || (xc->flush_context_pending))
2916 {
2917 xc->flush_context_pending = 0;
2918 fstWriterFlushContextPrivate(xc);
2919 xc->tchn_cnt++;
2920 fstWriterVarint(xc->tchn_handle, xc->curtime);
2921 }
2922 }
2923
2924 if(!skip)
2925 {
2926 xc->tchn_idx++;
2927 }
2928 fstWriterVarint(xc->tchn_handle, tim - xc->curtime);
2929 xc->tchn_cnt++;
2930 xc->curtime = tim;
2931 }
29442932 }
29452933
29462934
29492937 struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
29502938
29512939 if(xc)
2952 {
2953 struct fstBlackoutChain *b = calloc(1, sizeof(struct fstBlackoutChain));
2954
2955 b->tim = xc->curtime;
2956 b->active = (enable != 0);
2957
2958 xc->num_blackouts++;
2959 if(xc->blackout_curr)
2960 {
2961 xc->blackout_curr->next = b;
2962 xc->blackout_curr = b;
2963 }
2964 else
2965 {
2966 xc->blackout_head = b;
2967 xc->blackout_curr = b;
2968 }
2969 }
2940 {
2941 struct fstBlackoutChain *b = calloc(1, sizeof(struct fstBlackoutChain));
2942
2943 b->tim = xc->curtime;
2944 b->active = (enable != 0);
2945
2946 xc->num_blackouts++;
2947 if(xc->blackout_curr)
2948 {
2949 xc->blackout_curr->next = b;
2950 xc->blackout_curr = b;
2951 }
2952 else
2953 {
2954 xc->blackout_head = b;
2955 xc->blackout_curr = b;
2956 }
2957 }
29702958 }
29712959
29722960
29802968 * private structs
29812969 */
29822970 static const char *vartypes[] = {
2983 "event", "integer", "parameter", "real", "real_parameter",
2984 "reg", "supply0", "supply1", "time", "tri",
2985 "triand", "trior", "trireg", "tri0", "tri1",
2986 "wand", "wire", "wor", "port", "sparray", "realtime",
2987 "string",
2988 "bit", "logic", "int", "shortint", "longint", "byte", "enum", "shortreal"
2989 };
2971 "event", "integer", "parameter", "real", "real_parameter",
2972 "reg", "supply0", "supply1", "time", "tri",
2973 "triand", "trior", "trireg", "tri0", "tri1",
2974 "wand", "wire", "wor", "port", "sparray", "realtime",
2975 "string",
2976 "bit", "logic", "int", "shortint", "longint", "byte", "enum", "shortreal"
2977 };
29902978
29912979 static const char *modtypes[] = {
2992 "module", "task", "function", "begin", "fork", "generate", "struct", "union", "class", "interface", "package", "program",
2980 "module", "task", "function", "begin", "fork", "generate", "struct", "union", "class", "interface", "package", "program",
29932981 "vhdl_architecture", "vhdl_procedure", "vhdl_function", "vhdl_record", "vhdl_process", "vhdl_block", "vhdl_for_generate", "vhdl_if_generate", "vhdl_generate", "vhdl_package"
2994 };
2982 };
29952983
29962984 static const char *attrtypes[] = {
2997 "misc", "array", "enum", "class"
2998 };
2985 "misc", "array", "enum", "class"
2986 };
29992987
30002988 static const char *arraytypes[] = {
3001 "none", "unpacked", "packed", "sparse"
3002 };
2989 "none", "unpacked", "packed", "sparse"
2990 };
30032991
30042992 static const char *enumvaluetypes[] = {
3005 "integer", "bit", "logic", "int", "shortint", "longint", "byte",
3006 "unsigned_integer", "unsigned_bit", "unsigned_logic", "unsigned_int", "unsigned_shortint", "unsigned_longint", "unsigned_byte"
3007 };
2993 "integer", "bit", "logic", "int", "shortint", "longint", "byte",
2994 "unsigned_integer", "unsigned_bit", "unsigned_logic", "unsigned_int", "unsigned_shortint", "unsigned_longint", "unsigned_byte"
2995 };
30082996
30092997 static const char *packtypes[] = {
3010 "none", "unpacked", "packed", "tagged_packed"
3011 };
2998 "none", "unpacked", "packed", "tagged_packed"
2999 };
30123000
30133001
30143002 struct fstCurrHier
30333021 uint64_t num_alias;
30343022 uint64_t vc_section_count;
30353023
3036 uint32_t *signal_lens; /* maxhandle sized */
3037 unsigned char *signal_typs; /* maxhandle sized */
3038 unsigned char *process_mask; /* maxhandle-based, bitwise sized */
3039 uint32_t longest_signal_value_len; /* longest len value encountered */
3040 unsigned char *temp_signal_value_buf; /* malloced for len in longest_signal_value_len */
3024 uint32_t *signal_lens; /* maxhandle sized */
3025 unsigned char *signal_typs; /* maxhandle sized */
3026 unsigned char *process_mask; /* maxhandle-based, bitwise sized */
3027 uint32_t longest_signal_value_len; /* longest len value encountered */
3028 unsigned char *temp_signal_value_buf; /* malloced for len in longest_signal_value_len */
30413029
30423030 signed char timescale;
30433031 unsigned char filetype;
30463034 unsigned double_endian_match : 1;
30473035 unsigned native_doubles_for_cb : 1;
30483036 unsigned contains_geom_section : 1;
3049 unsigned contains_hier_section : 1; /* valid for hier_pos */
3037 unsigned contains_hier_section : 1; /* valid for hier_pos */
30503038 unsigned contains_hier_section_lz4duo : 1; /* valid for hier_pos (contains_hier_section_lz4 always also set) */
3051 unsigned contains_hier_section_lz4 : 1; /* valid for hier_pos */
3052 unsigned limit_range_valid : 1; /* valid for limit_range_start, limit_range_end */
3039 unsigned contains_hier_section_lz4 : 1; /* valid for hier_pos */
3040 unsigned limit_range_valid : 1; /* valid for limit_range_start, limit_range_end */
30533041
30543042 char version[FST_HDR_SIM_VERSION_SIZE + 1];
30553043 char date[FST_HDR_DATE_SIZE + 1];
31173105 int rc = fseeko(stream, offset, whence);
31183106
31193107 if(rc<0)
3120 {
3121 xc->fseek_failed = 1;
3108 {
3109 xc->fseek_failed = 1;
31223110 #ifdef FST_DEBUG
3123 fprintf(stderr, "Seek to #%"PRId64" (whence = %d) failed!\n", offset, whence);
3124 perror("Why");
3125 #endif
3126 }
3111 fprintf(stderr, "Seek to #%"PRId64" (whence = %d) failed!\n", offset, whence);
3112 perror("Why");
3113 #endif
3114 }
31273115
31283116 return(rc);
31293117 }
31353123 unsigned char *s = (unsigned char *)v;
31363124
31373125 if(len)
3138 {
3139 if(len < FST_WRITEX_MAX)
3140 {
3141 if(xc->writex_pos + len >= FST_WRITEX_MAX)
3142 {
3143 fstWritex(xc, NULL, 0);
3144 }
3145
3146 memcpy(xc->writex_buf + xc->writex_pos, s, len);
3147 xc->writex_pos += len;
3148 }
3149 else
3150 {
3151 fstWritex(xc, NULL, 0);
3152 if (write(xc->writex_fd, s, len)) { };
3153 }
3154 }
3155 else
3156 {
3157 if(xc->writex_pos)
3158 {
3159 if(write(xc->writex_fd, xc->writex_buf, xc->writex_pos)) { };
3160 xc->writex_pos = 0;
3161 }
3162 }
3126 {
3127 if(len < FST_WRITEX_MAX)
3128 {
3129 if(xc->writex_pos + len >= FST_WRITEX_MAX)
3130 {
3131 fstWritex(xc, NULL, 0);
3132 }
3133
3134 memcpy(xc->writex_buf + xc->writex_pos, s, len);
3135 xc->writex_pos += len;
3136 }
3137 else
3138 {
3139 fstWritex(xc, NULL, 0);
3140 if (write(xc->writex_fd, s, len)) { };
3141 }
3142 }
3143 else
3144 {
3145 if(xc->writex_pos)
3146 {
3147 if(write(xc->writex_fd, xc->writex_buf, xc->writex_pos)) { };
3148 xc->writex_pos = 0;
3149 }
3150 }
31633151 }
31643152 #endif
31653153
31733161
31743162 free(xc->curr_flat_hier_nam); xc->curr_flat_hier_nam = NULL;
31753163 while(xc->curr_hier)
3176 {
3177 chp = xc->curr_hier->prev;
3178 free(xc->curr_hier);
3179 xc->curr_hier = chp;
3180 }
3164 {
3165 chp = xc->curr_hier->prev;
3166 free(xc->curr_hier);
3167 xc->curr_hier = chp;
3168 }
31813169 }
31823170
31833171
31853173 {
31863174 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
31873175 if(xc)
3188 {
3189 return(xc->curr_flat_hier_nam ? xc->curr_flat_hier_nam : "");
3190 }
3191 else
3192 {
3193 return(NULL);
3194 }
3176 {
3177 return(xc->curr_flat_hier_nam ? xc->curr_flat_hier_nam : "");
3178 }
3179 else
3180 {
3181 return(NULL);
3182 }
31953183 }
31963184
31973185
31993187 {
32003188 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
32013189 if(xc)
3202 {
3203 return(xc->curr_hier ? xc->curr_hier->user_info : NULL);
3204 }
3205 else
3206 {
3207 return(NULL);
3208 }
3190 {
3191 return(xc->curr_hier ? xc->curr_hier->user_info : NULL);
3192 }
3193 else
3194 {
3195 return(NULL);
3196 }
32093197 }
32103198
32113199
32143202 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
32153203 if(xc && xc->curr_hier)
32163204 {
3217 struct fstCurrHier *ch = xc->curr_hier;
3218 if(xc->curr_hier->prev)
3219 {
3220 xc->curr_flat_hier_nam[xc->curr_hier->prev->len] = 0;
3221 }
3222 else
3223 {
3224 *xc->curr_flat_hier_nam = 0;
3225 }
3226 xc->curr_hier = xc->curr_hier->prev;
3227 free(ch);
3228 return(xc->curr_flat_hier_nam ? xc->curr_flat_hier_nam : "");
3229 }
3205 struct fstCurrHier *ch = xc->curr_hier;
3206 if(xc->curr_hier->prev)
3207 {
3208 xc->curr_flat_hier_nam[xc->curr_hier->prev->len] = 0;
3209 }
3210 else
3211 {
3212 *xc->curr_flat_hier_nam = 0;
3213 }
3214 xc->curr_hier = xc->curr_hier->prev;
3215 free(ch);
3216 return(xc->curr_flat_hier_nam ? xc->curr_flat_hier_nam : "");
3217 }
32303218
32313219 return(NULL);
32323220 }
32373225 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
32383226
32393227 if(xc)
3240 {
3241 while(fstReaderPopScope(xc)); /* remove any already-built scoping info */
3242 }
3228 {
3229 while(fstReaderPopScope(xc)); /* remove any already-built scoping info */
3230 }
32433231 }
32443232
32453233
32473235 {
32483236 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
32493237 if(xc)
3250 {
3251 struct fstCurrHier *ch = malloc(sizeof(struct fstCurrHier));
3252 int chl = xc->curr_hier ? xc->curr_hier->len : 0;
3253 int len = chl + 1 + strlen(nam);
3254 if(len >= xc->flat_hier_alloc_len)
3255 {
3256 xc->curr_flat_hier_nam = xc->curr_flat_hier_nam ? realloc(xc->curr_flat_hier_nam, len+1) : malloc(len+1);
3257 }
3258
3259 if(chl)
3260 {
3261 xc->curr_flat_hier_nam[chl] = '.';
3262 strcpy(xc->curr_flat_hier_nam + chl + 1, nam);
3263 }
3264 else
3265 {
3266 strcpy(xc->curr_flat_hier_nam, nam);
3267 len--;
3268 }
3269
3270 ch->len = len;
3271 ch->prev = xc->curr_hier;
3272 ch->user_info = user_info;
3273 xc->curr_hier = ch;
3274 return(xc->curr_flat_hier_nam);
3275 }
3238 {
3239 struct fstCurrHier *ch = malloc(sizeof(struct fstCurrHier));
3240 int chl = xc->curr_hier ? xc->curr_hier->len : 0;
3241 int len = chl + 1 + strlen(nam);
3242 if(len >= xc->flat_hier_alloc_len)
3243 {
3244 xc->curr_flat_hier_nam = xc->curr_flat_hier_nam ? realloc(xc->curr_flat_hier_nam, len+1) : malloc(len+1);
3245 }
3246
3247 if(chl)
3248 {
3249 xc->curr_flat_hier_nam[chl] = '.';
3250 strcpy(xc->curr_flat_hier_nam + chl + 1, nam);
3251 }
3252 else
3253 {
3254 strcpy(xc->curr_flat_hier_nam, nam);
3255 len--;
3256 }
3257
3258 ch->len = len;
3259 ch->prev = xc->curr_hier;
3260 ch->user_info = user_info;
3261 xc->curr_hier = ch;
3262 return(xc->curr_flat_hier_nam);
3263 }
32763264
32773265 return(NULL);
32783266 }
32833271 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
32843272
32853273 if(xc && xc->curr_hier)
3286 {
3287 return(xc->curr_hier->len);
3288 }
3274 {
3275 return(xc->curr_hier->len);
3276 }
32893277
32903278 return(0);
32913279 }
33123300
33133301 if(xc)
33143302 {
3315 facidx--;
3316 if(facidx<xc->maxhandle)
3317 {
3318 int process_idx = facidx/8;
3319 int process_bit = facidx&7;
3320
3321 return( (xc->process_mask[process_idx]&(1<<process_bit)) != 0 );
3322 }
3323 }
3303 facidx--;
3304 if(facidx<xc->maxhandle)
3305 {
3306 int process_idx = facidx/8;
3307 int process_bit = facidx&7;
3308
3309 return( (xc->process_mask[process_idx]&(1<<process_bit)) != 0 );
3310 }
3311 }
33243312 return(0);
33253313 }
33263314
33313319
33323320 if(xc)
33333321 {
3334 facidx--;
3335 if(facidx<xc->maxhandle)
3336 {
3337 int idx = facidx/8;
3338 int bitpos = facidx&7;
3339
3340 xc->process_mask[idx] |= (1<<bitpos);
3341 }
3342 }
3322 facidx--;
3323 if(facidx<xc->maxhandle)
3324 {
3325 int idx = facidx/8;
3326 int bitpos = facidx&7;
3327
3328 xc->process_mask[idx] |= (1<<bitpos);
3329 }
3330 }
33433331 }
33443332
33453333
33493337
33503338 if(xc)
33513339 {
3352 facidx--;
3353 if(facidx<xc->maxhandle)
3354 {
3355 int idx = facidx/8;
3356 int bitpos = facidx&7;
3357
3358 xc->process_mask[idx] &= (~(1<<bitpos));
3359 }
3360 }
3340 facidx--;
3341 if(facidx<xc->maxhandle)
3342 {
3343 int idx = facidx/8;
3344 int bitpos = facidx&7;
3345
3346 xc->process_mask[idx] &= (~(1<<bitpos));
3347 }
3348 }
33613349 }
33623350
33633351
33673355
33683356 if(xc)
33693357 {
3370 memset(xc->process_mask, 0xff, (xc->maxhandle+7)/8);
3371 }
3358 memset(xc->process_mask, 0xff, (xc->maxhandle+7)/8);
3359 }
33723360 }
33733361
33743362
33783366
33793367 if(xc)
33803368 {
3381 memset(xc->process_mask, 0x00, (xc->maxhandle+7)/8);
3382 }
3369 memset(xc->process_mask, 0x00, (xc->maxhandle+7)/8);
3370 }
33833371 }
33843372
33853373
34963484 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
34973485
34983486 if(xc && (idx < xc->num_blackouts) && (xc->blackout_times))
3499 {
3500 return(xc->blackout_times[idx]);
3501 }
3502 else
3503 {
3504 return(0);
3505 }
3487 {
3488 return(xc->blackout_times[idx]);
3489 }
3490 else
3491 {
3492 return(0);
3493 }
35063494 }
35073495
35083496
35113499 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
35123500
35133501 if(xc && (idx < xc->num_blackouts) && (xc->blackout_activity))
3514 {
3515 return(xc->blackout_activity[idx]);
3516 }
3517 else
3518 {
3519 return(0);
3520 }
3502 {
3503 return(xc->blackout_activity[idx]);
3504 }
3505 else
3506 {
3507 return(0);
3508 }
35213509 }
35223510
35233511
35263514 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
35273515
35283516 if(xc)
3529 {
3530 xc->limit_range_valid = 1;
3531 xc->limit_range_start = start_time;
3532 xc->limit_range_end = end_time;
3533 }
3517 {
3518 xc->limit_range_valid = 1;
3519 xc->limit_range_start = start_time;
3520 xc->limit_range_end = end_time;
3521 }
35343522 }
35353523
35363524
35393527 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
35403528
35413529 if(xc)
3542 {
3543 xc->limit_range_valid = 0;
3544 }
3530 {
3531 xc->limit_range_valid = 0;
3532 }
35453533 }
35463534
35473535
35503538 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
35513539
35523540 if(xc)
3553 {
3554 xc->use_vcd_extensions = (enable != 0);
3555 }
3541 {
3542 xc->use_vcd_extensions = (enable != 0);
3543 }
35563544 }
35573545
35583546
35603548 {
35613549 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
35623550 if(xc)
3563 {
3564 xc->native_doubles_for_cb = (enable != 0);
3565 }
3551 {
3552 xc->native_doubles_for_cb = (enable != 0);
3553 }
35663554 }
35673555
35683556 /*
36043592 int pass_status = 1;
36053593
36063594 if(!xc->fh)
3607 {
3608 off_t offs_cache = ftello(xc->f);
3609 char *fnam = malloc(strlen(xc->filename) + 6 + 16 + 32 + 1);
3610 unsigned char *mem = malloc(FST_GZIO_LEN);
3611 off_t hl, uclen;
3612 off_t clen = 0;
3613 gzFile zhandle = NULL;
3614 int zfd;
3615 int htyp = FST_BL_SKIP;
3616
3617 /* can't handle both set at once should never happen in a real file */
3618 if(!xc->contains_hier_section_lz4 && xc->contains_hier_section)
3619 {
3620 htyp = FST_BL_HIER;
3621 }
3622 else
3623 if(xc->contains_hier_section_lz4 && !xc->contains_hier_section)
3624 {
3625 htyp = xc->contains_hier_section_lz4duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4;
3626 }
3627
3628 sprintf(fnam, "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);
3629 fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
3630 uclen = fstReaderUint64(xc->f);
3595 {
3596 off_t offs_cache = ftello(xc->f);
3597 char *fnam = malloc(strlen(xc->filename) + 6 + 16 + 32 + 1);
3598 unsigned char *mem = malloc(FST_GZIO_LEN);
3599 off_t hl, uclen;
3600 off_t clen = 0;
3601 gzFile zhandle = NULL;
3602 int zfd;
3603 int htyp = FST_BL_SKIP;
3604
3605 /* can't handle both set at once should never happen in a real file */
3606 if(!xc->contains_hier_section_lz4 && xc->contains_hier_section)
3607 {
3608 htyp = FST_BL_HIER;
3609 }
3610 else
3611 if(xc->contains_hier_section_lz4 && !xc->contains_hier_section)
3612 {
3613 htyp = xc->contains_hier_section_lz4duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4;
3614 }
3615
3616 sprintf(fnam, "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);
3617 fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
3618 uclen = fstReaderUint64(xc->f);
36313619 #ifndef __MINGW32__
3632 fflush(xc->f);
3633 #endif
3634 if(htyp == FST_BL_HIER)
3635 {
3636 fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
3637 uclen = fstReaderUint64(xc->f);
3620 fflush(xc->f);
3621 #endif
3622 if(htyp == FST_BL_HIER)
3623 {
3624 fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
3625 uclen = fstReaderUint64(xc->f);
36383626 #ifndef __MINGW32__
3639 fflush(xc->f);
3640 #endif
3641 zfd = dup(fileno(xc->f));
3642 zhandle = gzdopen(zfd, "rb");
3643 if(!zhandle)
3644 {
3645 close(zfd);
3646 free(mem);
3647 free(fnam);
3648 return(0);
3649 }
3650 }
3651 else
3652 if((htyp == FST_BL_HIER_LZ4) || (htyp == FST_BL_HIER_LZ4DUO))
3653 {
3654 fstReaderFseeko(xc, xc->f, xc->hier_pos - 8, SEEK_SET); /* get section len */
3655 clen = fstReaderUint64(xc->f) - 16;
3656 uclen = fstReaderUint64(xc->f);
3627 fflush(xc->f);
3628 #endif
3629 zfd = dup(fileno(xc->f));
3630 zhandle = gzdopen(zfd, "rb");
3631 if(!zhandle)
3632 {
3633 close(zfd);
3634 free(mem);
3635 free(fnam);
3636 return(0);
3637 }
3638 }
3639 else
3640 if((htyp == FST_BL_HIER_LZ4) || (htyp == FST_BL_HIER_LZ4DUO))
3641 {
3642 fstReaderFseeko(xc, xc->f, xc->hier_pos - 8, SEEK_SET); /* get section len */
3643 clen = fstReaderUint64(xc->f) - 16;
3644 uclen = fstReaderUint64(xc->f);
36573645 #ifndef __MINGW32__
3658 fflush(xc->f);
3659 #endif
3660 }
3646 fflush(xc->f);
3647 #endif
3648 }
36613649
36623650 #ifndef __MINGW32__
3663 xc->fh = fopen(fnam, "w+b");
3651 xc->fh = fopen(fnam, "w+b");
36643652 if(!xc->fh)
36653653 #endif
36663654 {
36673655 xc->fh = tmpfile_open(&xc->fh_nam);
36683656 free(fnam); fnam = NULL;
36693657 if(!xc->fh)
3670 {
3671 tmpfile_close(&xc->fh, &xc->fh_nam);
3672 free(mem);
3673 return(0);
3674 }
3658 {
3659 tmpfile_close(&xc->fh, &xc->fh_nam);
3660 free(mem);
3661 return(0);
3662 }
36753663 }
36763664
36773665 #ifndef __MINGW32__
3678 if(fnam) unlink(fnam);
3679 #endif
3680
3681 if(htyp == FST_BL_HIER)
3682 {
3683 for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
3684 {
3685 size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
3686 size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
3687 size_t fwlen;
3688
3689 if(gzreadlen != len)
3690 {
3691 pass_status = 0;
3692 break;
3693 }
3694
3695 fwlen = fstFwrite(mem, len, 1, xc->fh);
3696 if(fwlen != 1)
3697 {
3698 pass_status = 0;
3699 break;
3700 }
3701 }
3702 gzclose(zhandle);
3703 }
3704 else
3705 if(htyp == FST_BL_HIER_LZ4DUO)
3706 {
3707 unsigned char *lz4_cmem = malloc(clen);
3708 unsigned char *lz4_ucmem = malloc(uclen);
3709 unsigned char *lz4_ucmem2;
3710 uint64_t uclen2;
3711 int skiplen2 = 0;
3712
3713 fstFread(lz4_cmem, clen, 1, xc->f);
3714
3715 uclen2 = fstGetVarint64(lz4_cmem, &skiplen2);
3716 lz4_ucmem2 = malloc(uclen2);
3717 pass_status = (uclen2 == LZ4_decompress_safe_partial ((char *)lz4_cmem + skiplen2, (char *)lz4_ucmem2, clen - skiplen2, uclen2, uclen2));
3718 if(pass_status)
3719 {
3720 pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_ucmem2, (char *)lz4_ucmem, uclen2, uclen, uclen));
3721
3722 if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
3723 {
3724 pass_status = 0;
3725 }
3726 }
3727
3728 free(lz4_ucmem2);
3729 free(lz4_ucmem);
3730 free(lz4_cmem);
3731 }
3732 else
3733 if(htyp == FST_BL_HIER_LZ4)
3734 {
3735 unsigned char *lz4_cmem = malloc(clen);
3736 unsigned char *lz4_ucmem = malloc(uclen);
3737
3738 fstFread(lz4_cmem, clen, 1, xc->f);
3739 pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_cmem, (char *)lz4_ucmem, clen, uclen, uclen));
3740
3741 if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
3742 {
3743 pass_status = 0;
3744 }
3745
3746 free(lz4_ucmem);
3747 free(lz4_cmem);
3748 }
3749 else /* FST_BL_SKIP */
3750 {
3751 pass_status = 0;
3752 }
3753
3754 free(mem);
3755 free(fnam);
3756
3757 fstReaderFseeko(xc, xc->f, offs_cache, SEEK_SET);
3758 }
3666 if(fnam) unlink(fnam);
3667 #endif
3668
3669 if(htyp == FST_BL_HIER)
3670 {
3671 for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
3672 {
3673 size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
3674 size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
3675 size_t fwlen;
3676
3677 if(gzreadlen != len)
3678 {
3679 pass_status = 0;
3680 break;
3681 }
3682
3683 fwlen = fstFwrite(mem, len, 1, xc->fh);
3684 if(fwlen != 1)
3685 {
3686 pass_status = 0;
3687 break;
3688 }
3689 }
3690 gzclose(zhandle);
3691 }
3692 else
3693 if(htyp == FST_BL_HIER_LZ4DUO)
3694 {
3695 unsigned char *lz4_cmem = malloc(clen);
3696 unsigned char *lz4_ucmem = malloc(uclen);
3697 unsigned char *lz4_ucmem2;
3698 uint64_t uclen2;
3699 int skiplen2 = 0;
3700
3701 fstFread(lz4_cmem, clen, 1, xc->f);
3702
3703 uclen2 = fstGetVarint64(lz4_cmem, &skiplen2);
3704 lz4_ucmem2 = malloc(uclen2);
3705 pass_status = (uclen2 == (uint64_t)LZ4_decompress_safe_partial ((char *)lz4_cmem + skiplen2, (char *)lz4_ucmem2, clen - skiplen2, uclen2, uclen2));
3706 if(pass_status)
3707 {
3708 pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_ucmem2, (char *)lz4_ucmem, uclen2, uclen, uclen));
3709
3710 if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
3711 {
3712 pass_status = 0;
3713 }
3714 }
3715
3716 free(lz4_ucmem2);
3717 free(lz4_ucmem);
3718 free(lz4_cmem);
3719 }
3720 else
3721 if(htyp == FST_BL_HIER_LZ4)
3722 {
3723 unsigned char *lz4_cmem = malloc(clen);
3724 unsigned char *lz4_ucmem = malloc(uclen);
3725
3726 fstFread(lz4_cmem, clen, 1, xc->f);
3727 pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_cmem, (char *)lz4_ucmem, clen, uclen, uclen));
3728
3729 if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
3730 {
3731 pass_status = 0;
3732 }
3733
3734 free(lz4_ucmem);
3735 free(lz4_cmem);
3736 }
3737 else /* FST_BL_SKIP */
3738 {
3739 pass_status = 0;
3740 }
3741
3742 free(mem);
3743 free(fnam);
3744
3745 fstReaderFseeko(xc, xc->f, offs_cache, SEEK_SET);
3746 }
37593747
37603748 return(pass_status);
37613749 }
37673755 int pass_status = 0;
37683756
37693757 if(xc)
3770 {
3771 pass_status = 1;
3772 if(!xc->fh)
3773 {
3774 pass_status = fstReaderRecreateHierFile(xc);
3775 }
3776
3777 xc->do_rewind = 1;
3778 }
3758 {
3759 pass_status = 1;
3760 if(!xc->fh)
3761 {
3762 pass_status = fstReaderRecreateHierFile(xc);
3763 }
3764
3765 xc->do_rewind = 1;
3766 }
37793767
37803768 return(pass_status);
37813769 }
37923780 if(!xc) return(NULL);
37933781
37943782 if(!xc->fh)
3795 {
3796 if(!fstReaderRecreateHierFile(xc))
3797 {
3798 return(NULL);
3799 }
3800 }
3783 {
3784 if(!fstReaderRecreateHierFile(xc))
3785 {
3786 return(NULL);
3787 }
3788 }
38013789
38023790 if(xc->do_rewind)
3803 {
3804 xc->do_rewind = 0;
3805 xc->current_handle = 0;
3806 fstReaderFseeko(xc, xc->fh, 0, SEEK_SET);
3807 clearerr(xc->fh);
3808 }
3791 {
3792 xc->do_rewind = 0;
3793 xc->current_handle = 0;
3794 fstReaderFseeko(xc, xc->fh, 0, SEEK_SET);
3795 clearerr(xc->fh);
3796 }
38093797
38103798 if(!(isfeof=feof(xc->fh)))
3811 {
3812 int tag = fgetc(xc->fh);
3813 switch(tag)
3814 {
3815 case FST_ST_VCD_SCOPE:
3816 xc->hier.htyp = FST_HT_SCOPE;
3817 xc->hier.u.scope.typ = fgetc(xc->fh);
3818 xc->hier.u.scope.name = pnt = xc->str_scope_nam;
3819 while((ch = fgetc(xc->fh)))
3820 {
3821 *(pnt++) = ch;
3822 }; /* scopename */
3823 *pnt = 0;
3824 xc->hier.u.scope.name_length = pnt - xc->hier.u.scope.name;
3825
3826 xc->hier.u.scope.component = pnt = xc->str_scope_comp;
3827 while((ch = fgetc(xc->fh)))
3828 {
3829 *(pnt++) = ch;
3830 }; /* scopecomp */
3831 *pnt = 0;
3832 xc->hier.u.scope.component_length = pnt - xc->hier.u.scope.component;
3833 break;
3834
3835 case FST_ST_VCD_UPSCOPE:
3836 xc->hier.htyp = FST_HT_UPSCOPE;
3837 break;
3838
3839 case FST_ST_GEN_ATTRBEGIN:
3840 xc->hier.htyp = FST_HT_ATTRBEGIN;
3841 xc->hier.u.attr.typ = fgetc(xc->fh);
3842 xc->hier.u.attr.subtype = fgetc(xc->fh);
3843 xc->hier.u.attr.name = pnt = xc->str_scope_nam;
3844 while((ch = fgetc(xc->fh)))
3845 {
3846 *(pnt++) = ch;
3847 }; /* scopename */
3848 *pnt = 0;
3849 xc->hier.u.attr.name_length = pnt - xc->hier.u.scope.name;
3850
3851 xc->hier.u.attr.arg = fstReaderVarint64(xc->fh);
3852
3853 if(xc->hier.u.attr.typ == FST_AT_MISC)
3854 {
3855 if((xc->hier.u.attr.subtype == FST_MT_SOURCESTEM)||(xc->hier.u.attr.subtype == FST_MT_SOURCEISTEM))
3856 {
3857 int sidx_skiplen_dummy = 0;
3858 xc->hier.u.attr.arg_from_name = fstGetVarint64((unsigned char *)xc->str_scope_nam, &sidx_skiplen_dummy);
3859 }
3860 }
3861 break;
3862
3863 case FST_ST_GEN_ATTREND:
3864 xc->hier.htyp = FST_HT_ATTREND;
3865 break;
3866
3867 case FST_VT_VCD_EVENT:
3868 case FST_VT_VCD_INTEGER:
3869 case FST_VT_VCD_PARAMETER:
3870 case FST_VT_VCD_REAL:
3871 case FST_VT_VCD_REAL_PARAMETER:
3872 case FST_VT_VCD_REG:
3873 case FST_VT_VCD_SUPPLY0:
3874 case FST_VT_VCD_SUPPLY1:
3875 case FST_VT_VCD_TIME:
3876 case FST_VT_VCD_TRI:
3877 case FST_VT_VCD_TRIAND:
3878 case FST_VT_VCD_TRIOR:
3879 case FST_VT_VCD_TRIREG:
3880 case FST_VT_VCD_TRI0:
3881 case FST_VT_VCD_TRI1:
3882 case FST_VT_VCD_WAND:
3883 case FST_VT_VCD_WIRE:
3884 case FST_VT_VCD_WOR:
3885 case FST_VT_VCD_PORT:
3886 case FST_VT_VCD_SPARRAY:
3887 case FST_VT_VCD_REALTIME:
3888 case FST_VT_GEN_STRING:
3889 case FST_VT_SV_BIT:
3890 case FST_VT_SV_LOGIC:
3891 case FST_VT_SV_INT:
3892 case FST_VT_SV_SHORTINT:
3893 case FST_VT_SV_LONGINT:
3894 case FST_VT_SV_BYTE:
3895 case FST_VT_SV_ENUM:
3896 case FST_VT_SV_SHORTREAL:
3897 xc->hier.htyp = FST_HT_VAR;
3898 xc->hier.u.var.svt_workspace = FST_SVT_NONE;
3899 xc->hier.u.var.sdt_workspace = FST_SDT_NONE;
3900 xc->hier.u.var.sxt_workspace = 0;
3901 xc->hier.u.var.typ = tag;
3902 xc->hier.u.var.direction = fgetc(xc->fh);
3903 xc->hier.u.var.name = pnt = xc->str_scope_nam;
3904 while((ch = fgetc(xc->fh)))
3905 {
3906 *(pnt++) = ch;
3907 }; /* varname */
3908 *pnt = 0;
3909 xc->hier.u.var.name_length = pnt - xc->hier.u.var.name;
3910 xc->hier.u.var.length = fstReaderVarint32(xc->fh);
3911 if(tag == FST_VT_VCD_PORT)
3912 {
3913 xc->hier.u.var.length -= 2; /* removal of delimiting spaces */
3914 xc->hier.u.var.length /= 3; /* port -> signal size adjust */
3915 }
3916
3917 alias = fstReaderVarint32(xc->fh);
3918
3919 if(!alias)
3920 {
3921 xc->current_handle++;
3922 xc->hier.u.var.handle = xc->current_handle;
3923 xc->hier.u.var.is_alias = 0;
3924 }
3925 else
3926 {
3927 xc->hier.u.var.handle = alias;
3928 xc->hier.u.var.is_alias = 1;
3929 }
3930
3931 break;
3932
3933 default:
3934 isfeof = 1;
3935 break;
3936 }
3937 }
3799 {
3800 int tag = fgetc(xc->fh);
3801 switch(tag)
3802 {
3803 case FST_ST_VCD_SCOPE:
3804 xc->hier.htyp = FST_HT_SCOPE;
3805 xc->hier.u.scope.typ = fgetc(xc->fh);
3806 xc->hier.u.scope.name = pnt = xc->str_scope_nam;
3807 while((ch = fgetc(xc->fh)))
3808 {
3809 *(pnt++) = ch;
3810 }; /* scopename */
3811 *pnt = 0;
3812 xc->hier.u.scope.name_length = pnt - xc->hier.u.scope.name;
3813
3814 xc->hier.u.scope.component = pnt = xc->str_scope_comp;
3815 while((ch = fgetc(xc->fh)))
3816 {
3817 *(pnt++) = ch;
3818 }; /* scopecomp */
3819 *pnt = 0;
3820 xc->hier.u.scope.component_length = pnt - xc->hier.u.scope.component;
3821 break;
3822
3823 case FST_ST_VCD_UPSCOPE:
3824 xc->hier.htyp = FST_HT_UPSCOPE;
3825 break;
3826
3827 case FST_ST_GEN_ATTRBEGIN:
3828 xc->hier.htyp = FST_HT_ATTRBEGIN;
3829 xc->hier.u.attr.typ = fgetc(xc->fh);
3830 xc->hier.u.attr.subtype = fgetc(xc->fh);
3831 xc->hier.u.attr.name = pnt = xc->str_scope_nam;
3832 while((ch = fgetc(xc->fh)))
3833 {
3834 *(pnt++) = ch;
3835 }; /* scopename */
3836 *pnt = 0;
3837 xc->hier.u.attr.name_length = pnt - xc->hier.u.scope.name;
3838
3839 xc->hier.u.attr.arg = fstReaderVarint64(xc->fh);
3840
3841 if(xc->hier.u.attr.typ == FST_AT_MISC)
3842 {
3843 if((xc->hier.u.attr.subtype == FST_MT_SOURCESTEM)||(xc->hier.u.attr.subtype == FST_MT_SOURCEISTEM))
3844 {
3845 int sidx_skiplen_dummy = 0;
3846 xc->hier.u.attr.arg_from_name = fstGetVarint64((unsigned char *)xc->str_scope_nam, &sidx_skiplen_dummy);
3847 }
3848 }
3849 break;
3850
3851 case FST_ST_GEN_ATTREND:
3852 xc->hier.htyp = FST_HT_ATTREND;
3853 break;
3854
3855 case FST_VT_VCD_EVENT:
3856 case FST_VT_VCD_INTEGER:
3857 case FST_VT_VCD_PARAMETER:
3858 case FST_VT_VCD_REAL:
3859 case FST_VT_VCD_REAL_PARAMETER:
3860 case FST_VT_VCD_REG:
3861 case FST_VT_VCD_SUPPLY0:
3862 case FST_VT_VCD_SUPPLY1:
3863 case FST_VT_VCD_TIME:
3864 case FST_VT_VCD_TRI:
3865 case FST_VT_VCD_TRIAND:
3866 case FST_VT_VCD_TRIOR:
3867 case FST_VT_VCD_TRIREG:
3868 case FST_VT_VCD_TRI0:
3869 case FST_VT_VCD_TRI1:
3870 case FST_VT_VCD_WAND:
3871 case FST_VT_VCD_WIRE:
3872 case FST_VT_VCD_WOR:
3873 case FST_VT_VCD_PORT:
3874 case FST_VT_VCD_SPARRAY:
3875 case FST_VT_VCD_REALTIME:
3876 case FST_VT_GEN_STRING:
3877 case FST_VT_SV_BIT:
3878 case FST_VT_SV_LOGIC:
3879 case FST_VT_SV_INT:
3880 case FST_VT_SV_SHORTINT:
3881 case FST_VT_SV_LONGINT:
3882 case FST_VT_SV_BYTE:
3883 case FST_VT_SV_ENUM:
3884 case FST_VT_SV_SHORTREAL:
3885 xc->hier.htyp = FST_HT_VAR;
3886 xc->hier.u.var.svt_workspace = FST_SVT_NONE;
3887 xc->hier.u.var.sdt_workspace = FST_SDT_NONE;
3888 xc->hier.u.var.sxt_workspace = 0;
3889 xc->hier.u.var.typ = tag;
3890 xc->hier.u.var.direction = fgetc(xc->fh);
3891 xc->hier.u.var.name = pnt = xc->str_scope_nam;
3892 while((ch = fgetc(xc->fh)))
3893 {
3894 *(pnt++) = ch;
3895 }; /* varname */
3896 *pnt = 0;
3897 xc->hier.u.var.name_length = pnt - xc->hier.u.var.name;
3898 xc->hier.u.var.length = fstReaderVarint32(xc->fh);
3899 if(tag == FST_VT_VCD_PORT)
3900 {
3901 xc->hier.u.var.length -= 2; /* removal of delimiting spaces */
3902 xc->hier.u.var.length /= 3; /* port -> signal size adjust */
3903 }
3904
3905 alias = fstReaderVarint32(xc->fh);
3906
3907 if(!alias)
3908 {
3909 xc->current_handle++;
3910 xc->hier.u.var.handle = xc->current_handle;
3911 xc->hier.u.var.is_alias = 0;
3912 }
3913 else
3914 {
3915 xc->hier.u.var.handle = alias;
3916 xc->hier.u.var.is_alias = 1;
3917 }
3918
3919 break;
3920
3921 default:
3922 isfeof = 1;
3923 break;
3924 }
3925 }
39383926
39393927 return(!isfeof ? &xc->hier : NULL);
39403928 }
39493937 int vartype;
39503938 uint32_t len, alias;
39513939 /* uint32_t maxvalpos=0; */
3952 int num_signal_dyn = 65536;
3940 unsigned int num_signal_dyn = 65536;
39533941 int attrtype, subtype;
39543942 uint64_t attrarg;
39553943 fstHandle maxhandle_scanbuild;
39593947 xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
39603948
39613949 if(!xc->fh)
3962 {
3963 if(!fstReaderRecreateHierFile(xc))
3964 {
3965 return(0);
3966 }
3967 }
3950 {
3951 if(!fstReaderRecreateHierFile(xc))
3952 {
3953 return(0);
3954 }
3955 }
39683956
39693957 str = malloc(FST_ID_NAM_ATTR_SIZ+1);
39703958
39713959 if(fv)
3972 {
3973 char time_dimension[2] = {0, 0};
3974 int time_scale = 1;
3975
3976 fprintf(fv, "$date\n\t%s\n$end\n", xc->date);
3977 fprintf(fv, "$version\n\t%s\n$end\n", xc->version);
3978 if(xc->timezero) fprintf(fv, "$timezero\n\t%"PRId64"\n$end\n", xc->timezero);
3960 {
3961 char time_dimension[2] = {0, 0};
3962 int time_scale = 1;
3963
3964 fprintf(fv, "$date\n\t%s\n$end\n", xc->date);
3965 fprintf(fv, "$version\n\t%s\n$end\n", xc->version);
3966 if(xc->timezero) fprintf(fv, "$timezero\n\t%"PRId64"\n$end\n", xc->timezero);
39793967
39803968 switch(xc->timescale)
39813969 {
40134001 default: time_dimension[0] = 'n'; break;
40144002 }
40154003
4016 if(fv) fprintf(fv, "$timescale\n\t%d%ss\n$end\n", time_scale, time_dimension);
4017 }
4004 if(fv) fprintf(fv, "$timescale\n\t%d%ss\n$end\n", time_scale, time_dimension);
4005 }
40184006
40194007 xc->maxhandle = 0;
40204008 xc->num_alias = 0;
40274015
40284016 fstReaderFseeko(xc, xc->fh, 0, SEEK_SET);
40294017 while(!feof(xc->fh))
4030 {
4031 int tag = fgetc(xc->fh);
4032 switch(tag)
4033 {
4034 case FST_ST_VCD_SCOPE:
4035 scopetype = fgetc(xc->fh);
4036 if((scopetype < FST_ST_MIN) || (scopetype > FST_ST_MAX)) scopetype = FST_ST_VCD_MODULE;
4037 pnt = str;
4038 while((ch = fgetc(xc->fh)))
4039 {
4040 *(pnt++) = ch;
4041 }; /* scopename */
4042 *pnt = 0;
4043 while(fgetc(xc->fh)) { }; /* scopecomp */
4044
4045 if(fv) fprintf(fv, "$scope %s %s $end\n", modtypes[scopetype], str);
4046 break;
4047
4048 case FST_ST_VCD_UPSCOPE:
4049 if(fv) fprintf(fv, "$upscope $end\n");
4050 break;
4051
4052 case FST_ST_GEN_ATTRBEGIN:
4053 attrtype = fgetc(xc->fh);
4054 subtype = fgetc(xc->fh);
4055 pnt = str;
4056 while((ch = fgetc(xc->fh)))
4057 {
4058 *(pnt++) = ch;
4059 }; /* attrname */
4060 *pnt = 0;
4061
4062 if(!str[0]) { strcpy(str, "\"\""); }
4063
4064 attrarg = fstReaderVarint64(xc->fh);
4065
4066 if(fv && xc->use_vcd_extensions)
4067 {
4068 switch(attrtype)
4069 {
4070 case FST_AT_ARRAY: if((subtype < FST_AR_NONE) || (subtype > FST_AR_MAX)) subtype = FST_AR_NONE;
4071 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], arraytypes[subtype], str, attrarg);
4072 break;
4073 case FST_AT_ENUM: if((subtype < FST_EV_SV_INTEGER) || (subtype > FST_EV_MAX)) subtype = FST_EV_SV_INTEGER;
4074 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], enumvaluetypes[subtype], str, attrarg);
4075 break;
4076 case FST_AT_PACK: if((subtype < FST_PT_NONE) || (subtype > FST_PT_MAX)) subtype = FST_PT_NONE;
4077 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], packtypes[subtype], str, attrarg);
4078 break;
4079 case FST_AT_MISC:
4080 default: attrtype = FST_AT_MISC;
4081 if(subtype == FST_MT_COMMENT)
4082 {
4083 fprintf(fv, "$comment\n\t%s\n$end\n", str);
4084 }
4085 else
4086 {
4087 if((subtype == FST_MT_SOURCESTEM)||(subtype == FST_MT_SOURCEISTEM))
4088 {
4089 int sidx_skiplen_dummy = 0;
4090 uint64_t sidx = fstGetVarint64((unsigned char *)str, &sidx_skiplen_dummy);
4091
4092 fprintf(fv, "$attrbegin %s %02x %"PRId64" %"PRId64" $end\n", attrtypes[attrtype], subtype, sidx, attrarg);
4093 }
4094 else
4095 {
4096 fprintf(fv, "$attrbegin %s %02x %s %"PRId64" $end\n", attrtypes[attrtype], subtype, str, attrarg);
4097 }
4098 }
4099 break;
4100 }
4101 }
4102 break;
4103
4104 case FST_ST_GEN_ATTREND:
4105 if(fv && xc->use_vcd_extensions) fprintf(fv, "$attrend $end\n");
4106 break;
4107
4108 case FST_VT_VCD_EVENT:
4109 case FST_VT_VCD_INTEGER:
4110 case FST_VT_VCD_PARAMETER:
4111 case FST_VT_VCD_REAL:
4112 case FST_VT_VCD_REAL_PARAMETER:
4113 case FST_VT_VCD_REG:
4114 case FST_VT_VCD_SUPPLY0:
4115 case FST_VT_VCD_SUPPLY1:
4116 case FST_VT_VCD_TIME:
4117 case FST_VT_VCD_TRI:
4118 case FST_VT_VCD_TRIAND:
4119 case FST_VT_VCD_TRIOR:
4120 case FST_VT_VCD_TRIREG:
4121 case FST_VT_VCD_TRI0:
4122 case FST_VT_VCD_TRI1:
4123 case FST_VT_VCD_WAND:
4124 case FST_VT_VCD_WIRE:
4125 case FST_VT_VCD_WOR:
4126 case FST_VT_VCD_PORT:
4127 case FST_VT_VCD_SPARRAY:
4128 case FST_VT_VCD_REALTIME:
4129 case FST_VT_GEN_STRING:
4130 case FST_VT_SV_BIT:
4131 case FST_VT_SV_LOGIC:
4132 case FST_VT_SV_INT:
4133 case FST_VT_SV_SHORTINT:
4134 case FST_VT_SV_LONGINT:
4135 case FST_VT_SV_BYTE:
4136 case FST_VT_SV_ENUM:
4137 case FST_VT_SV_SHORTREAL:
4138 vartype = tag;
4139 /* vardir = */ fgetc(xc->fh); /* unused in VCD reader, but need to advance read pointer */
4140 pnt = str;
4141 while((ch = fgetc(xc->fh)))
4142 {
4143 *(pnt++) = ch;
4144 }; /* varname */
4145 *pnt = 0;
4146 len = fstReaderVarint32(xc->fh);
4147 alias = fstReaderVarint32(xc->fh);
4148
4149 if(!alias)
4150 {
4151 if(xc->maxhandle == num_signal_dyn)
4152 {
4153 num_signal_dyn *= 2;
4154 xc->signal_lens = realloc(xc->signal_lens, num_signal_dyn*sizeof(uint32_t));
4155 xc->signal_typs = realloc(xc->signal_typs, num_signal_dyn*sizeof(unsigned char));
4156 }
4157 xc->signal_lens[xc->maxhandle] = len;
4158 xc->signal_typs[xc->maxhandle] = vartype;
4159
4160 /* maxvalpos+=len; */
4161 if(len > xc->longest_signal_value_len)
4162 {
4163 xc->longest_signal_value_len = len;
4164 }
4165
4166 if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME) || (vartype == FST_VT_SV_SHORTREAL))
4167 {
4168 len = (vartype != FST_VT_SV_SHORTREAL) ? 64 : 32;
4169 xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
4170 }
4171 if(fv)
4172 {
4173 char vcdid_buf[16];
4174 uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
4175 fstVcdID(vcdid_buf, xc->maxhandle+1);
4176 fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
4177 }
4178 xc->maxhandle++;
4179 }
4180 else
4181 {
4182 if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME) || (vartype == FST_VT_SV_SHORTREAL))
4183 {
4184 len = (vartype != FST_VT_SV_SHORTREAL) ? 64 : 32;
4185 xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
4186 }
4187 if(fv)
4188 {
4189 char vcdid_buf[16];
4190 uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
4191 fstVcdID(vcdid_buf, alias);
4192 fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
4193 }
4194 xc->num_alias++;
4195 }
4196
4197 break;
4198
4199 default:
4200 break;
4201 }
4202 }
4018 {
4019 int tag = fgetc(xc->fh);
4020 switch(tag)
4021 {
4022 case FST_ST_VCD_SCOPE:
4023 scopetype = fgetc(xc->fh);
4024 if((scopetype < FST_ST_MIN) || (scopetype > FST_ST_MAX)) scopetype = FST_ST_VCD_MODULE;
4025 pnt = str;
4026 while((ch = fgetc(xc->fh)))
4027 {
4028 *(pnt++) = ch;
4029 }; /* scopename */
4030 *pnt = 0;
4031 while(fgetc(xc->fh)) { }; /* scopecomp */
4032
4033 if(fv) fprintf(fv, "$scope %s %s $end\n", modtypes[scopetype], str);
4034 break;
4035
4036 case FST_ST_VCD_UPSCOPE:
4037 if(fv) fprintf(fv, "$upscope $end\n");
4038 break;
4039
4040 case FST_ST_GEN_ATTRBEGIN:
4041 attrtype = fgetc(xc->fh);
4042 subtype = fgetc(xc->fh);
4043 pnt = str;
4044 while((ch = fgetc(xc->fh)))
4045 {
4046 *(pnt++) = ch;
4047 }; /* attrname */
4048 *pnt = 0;
4049
4050 if(!str[0]) { strcpy(str, "\"\""); }
4051
4052 attrarg = fstReaderVarint64(xc->fh);
4053
4054 if(fv && xc->use_vcd_extensions)
4055 {
4056 switch(attrtype)
4057 {
4058 case FST_AT_ARRAY: if((subtype < FST_AR_NONE) || (subtype > FST_AR_MAX)) subtype = FST_AR_NONE;
4059 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], arraytypes[subtype], str, attrarg);
4060 break;
4061 case FST_AT_ENUM: if((subtype < FST_EV_SV_INTEGER) || (subtype > FST_EV_MAX)) subtype = FST_EV_SV_INTEGER;
4062 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], enumvaluetypes[subtype], str, attrarg);
4063 break;
4064 case FST_AT_PACK: if((subtype < FST_PT_NONE) || (subtype > FST_PT_MAX)) subtype = FST_PT_NONE;
4065 fprintf(fv, "$attrbegin %s %s %s %"PRId64" $end\n", attrtypes[attrtype], packtypes[subtype], str, attrarg);
4066 break;
4067 case FST_AT_MISC:
4068 default: attrtype = FST_AT_MISC;
4069 if(subtype == FST_MT_COMMENT)
4070 {
4071 fprintf(fv, "$comment\n\t%s\n$end\n", str);
4072 }
4073 else
4074 {
4075 if((subtype == FST_MT_SOURCESTEM)||(subtype == FST_MT_SOURCEISTEM))
4076 {
4077 int sidx_skiplen_dummy = 0;
4078 uint64_t sidx = fstGetVarint64((unsigned char *)str, &sidx_skiplen_dummy);
4079
4080 fprintf(fv, "$attrbegin %s %02x %"PRId64" %"PRId64" $end\n", attrtypes[attrtype], subtype, sidx, attrarg);
4081 }
4082 else
4083 {
4084 fprintf(fv, "$attrbegin %s %02x %s %"PRId64" $end\n", attrtypes[attrtype], subtype, str, attrarg);
4085 }
4086 }
4087 break;
4088 }
4089 }
4090 break;
4091
4092 case FST_ST_GEN_ATTREND:
4093 if(fv && xc->use_vcd_extensions) fprintf(fv, "$attrend $end\n");
4094 break;
4095
4096 case FST_VT_VCD_EVENT:
4097 case FST_VT_VCD_INTEGER:
4098 case FST_VT_VCD_PARAMETER:
4099 case FST_VT_VCD_REAL:
4100 case FST_VT_VCD_REAL_PARAMETER:
4101 case FST_VT_VCD_REG:
4102 case FST_VT_VCD_SUPPLY0:
4103 case FST_VT_VCD_SUPPLY1:
4104 case FST_VT_VCD_TIME:
4105 case FST_VT_VCD_TRI:
4106 case FST_VT_VCD_TRIAND:
4107 case FST_VT_VCD_TRIOR:
4108 case FST_VT_VCD_TRIREG:
4109 case FST_VT_VCD_TRI0:
4110 case FST_VT_VCD_TRI1:
4111 case FST_VT_VCD_WAND:
4112 case FST_VT_VCD_WIRE:
4113 case FST_VT_VCD_WOR:
4114 case FST_VT_VCD_PORT:
4115 case FST_VT_VCD_SPARRAY:
4116 case FST_VT_VCD_REALTIME:
4117 case FST_VT_GEN_STRING:
4118 case FST_VT_SV_BIT:
4119 case FST_VT_SV_LOGIC:
4120 case FST_VT_SV_INT:
4121 case FST_VT_SV_SHORTINT:
4122 case FST_VT_SV_LONGINT:
4123 case FST_VT_SV_BYTE:
4124 case FST_VT_SV_ENUM:
4125 case FST_VT_SV_SHORTREAL:
4126 vartype = tag;
4127 /* vardir = */ fgetc(xc->fh); /* unused in VCD reader, but need to advance read pointer */
4128 pnt = str;
4129 while((ch = fgetc(xc->fh)))
4130 {
4131 *(pnt++) = ch;
4132 }; /* varname */
4133 *pnt = 0;
4134 len = fstReaderVarint32(xc->fh);
4135 alias = fstReaderVarint32(xc->fh);
4136
4137 if(!alias)
4138 {
4139 if(xc->maxhandle == num_signal_dyn)
4140 {
4141 num_signal_dyn *= 2;
4142 xc->signal_lens = realloc(xc->signal_lens, num_signal_dyn*sizeof(uint32_t));
4143 xc->signal_typs = realloc(xc->signal_typs, num_signal_dyn*sizeof(unsigned char));
4144 }
4145 xc->signal_lens[xc->maxhandle] = len;
4146 xc->signal_typs[xc->maxhandle] = vartype;
4147
4148 /* maxvalpos+=len; */
4149 if(len > xc->longest_signal_value_len)
4150 {
4151 xc->longest_signal_value_len = len;
4152 }
4153
4154 if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME) || (vartype == FST_VT_SV_SHORTREAL))
4155 {
4156 len = (vartype != FST_VT_SV_SHORTREAL) ? 64 : 32;
4157 xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
4158 }
4159 if(fv)
4160 {
4161 char vcdid_buf[16];
4162 uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
4163 fstVcdID(vcdid_buf, xc->maxhandle+1);
4164 fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
4165 }
4166 xc->maxhandle++;
4167 }
4168 else
4169 {
4170 if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME) || (vartype == FST_VT_SV_SHORTREAL))
4171 {
4172 len = (vartype != FST_VT_SV_SHORTREAL) ? 64 : 32;
4173 xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
4174 }
4175 if(fv)
4176 {
4177 char vcdid_buf[16];
4178 uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
4179 fstVcdID(vcdid_buf, alias);
4180 fprintf(fv, "$var %s %"PRIu32" %s %s $end\n", vartypes[vartype], modlen, vcdid_buf, str);
4181 }
4182 xc->num_alias++;
4183 }
4184
4185 break;
4186
4187 default:
4188 break;
4189 }
4190 }
42034191 if(fv) fprintf(fv, "$enddefinitions $end\n");
42044192
42054193 maxhandle_scanbuild = xc->maxhandle ? xc->maxhandle : 1; /*scan-build warning suppression, in reality we have at least one signal */
42364224
42374225 sectype = fgetc(xc->f);
42384226 if(sectype == FST_BL_ZWRAPPER)
4239 {
4240 FILE *fcomp;
4241 off_t offpnt, uclen;
4242 char gz_membuf[FST_GZIO_LEN];
4243 void *zhandle;
4244 int zfd;
4227 {
4228 FILE *fcomp;
4229 off_t offpnt, uclen;
4230 char gz_membuf[FST_GZIO_LEN];
4231 void *zhandle;
4232 int zfd;
42454233 int flen = strlen(xc->filename);
42464234 char *hf;
42474235
4248 seclen = fstReaderUint64(xc->f);
4249 uclen = fstReaderUint64(xc->f);
4250
4251 if(!seclen) return(0); /* not finished compressing, this is a failed read */
4236 seclen = fstReaderUint64(xc->f);
4237 uclen = fstReaderUint64(xc->f);
4238
4239 if(!seclen) return(0); /* not finished compressing, this is a failed read */
42524240
42534241 hf = calloc(1, flen + 16 + 32 + 1);
42544242
4255 sprintf(hf, "%s.upk_%d_%p", xc->filename, getpid(), (void *)xc);
4256 fcomp = fopen(hf, "w+b");
4257 if(!fcomp)
4258 {
4259 fcomp = tmpfile_open(&xc->f_nam);
4260 free(hf); hf = NULL;
4261 if(!fcomp) { tmpfile_close(&fcomp, &xc->f_nam); return(0); }
4262 }
4243 sprintf(hf, "%s.upk_%d_%p", xc->filename, getpid(), (void *)xc);
4244 fcomp = fopen(hf, "w+b");
4245 if(!fcomp)
4246 {
4247 fcomp = tmpfile_open(&xc->f_nam);
4248 free(hf); hf = NULL;
4249 if(!fcomp) { tmpfile_close(&fcomp, &xc->f_nam); return(0); }
4250 }
42634251
42644252 #if defined(FST_MACOSX)
4265 setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
4253 setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
42664254 #endif
42674255
42684256 #ifdef __MINGW32__
4269 setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
4270 xc->filename_unpacked = hf;
4257 setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
4258 xc->filename_unpacked = hf;
42714259 #else
4272 if(hf)
4273 {
4274 unlink(hf);
4275 free(hf);
4276 }
4277 #endif
4278
4279 fstReaderFseeko(xc, xc->f, 1+8+8, SEEK_SET);
4260 if(hf)
4261 {
4262 unlink(hf);
4263 free(hf);
4264 }
4265 #endif
4266
4267 fstReaderFseeko(xc, xc->f, 1+8+8, SEEK_SET);
42804268 #ifndef __MINGW32__
4281 fflush(xc->f);
4282 #endif
4283
4284 zfd = dup(fileno(xc->f));
4285 zhandle = gzdopen(zfd, "rb");
4286 if(zhandle)
4287 {
4288 for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN)
4289 {
4290 size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt);
4291 size_t gzreadlen = gzread(zhandle, gz_membuf, this_len);
4292 size_t fwlen;
4293
4294 if(gzreadlen != this_len)
4295 {
4296 gzread_pass_status = 0;
4297 break;
4298 }
4299 fwlen = fstFwrite(gz_membuf, this_len, 1, fcomp);
4300 if(fwlen != 1)
4301 {
4302 gzread_pass_status = 0;
4303 break;
4304 }
4305 }
4306 gzclose(zhandle);
4307 }
4308 else
4309 {
4310 close(zfd);
4311 }
4312 fflush(fcomp);
4313 fclose(xc->f);
4314 xc->f = fcomp;
4315 }
4269 fflush(xc->f);
4270 #endif
4271
4272 zfd = dup(fileno(xc->f));
4273 zhandle = gzdopen(zfd, "rb");
4274 if(zhandle)
4275 {
4276 for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN)
4277 {
4278 size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt);
4279 size_t gzreadlen = gzread(zhandle, gz_membuf, this_len);
4280 size_t fwlen;
4281
4282 if(gzreadlen != this_len)
4283 {
4284 gzread_pass_status = 0;
4285 break;
4286 }
4287 fwlen = fstFwrite(gz_membuf, this_len, 1, fcomp);
4288 if(fwlen != 1)
4289 {
4290 gzread_pass_status = 0;
4291 break;
4292 }
4293 }
4294 gzclose(zhandle);
4295 }
4296 else
4297 {
4298 close(zfd);
4299 }
4300 fflush(fcomp);
4301 fclose(xc->f);
4302 xc->f = fcomp;
4303 }
43164304
43174305 if(gzread_pass_status)
4318 {
4319 fstReaderFseeko(xc, xc->f, 0, SEEK_END);
4320 endfile = ftello(xc->f);
4321
4322 while(blkpos < endfile)
4323 {
4324 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
4325
4326 sectype = fgetc(xc->f);
4327 seclen = fstReaderUint64(xc->f);
4328
4329 if(sectype == EOF)
4330 {
4331 break;
4332 }
4306 {
4307 fstReaderFseeko(xc, xc->f, 0, SEEK_END);
4308 endfile = ftello(xc->f);
4309
4310 while(blkpos < endfile)
4311 {
4312 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
4313
4314 sectype = fgetc(xc->f);
4315 seclen = fstReaderUint64(xc->f);
4316
4317 if(sectype == EOF)
4318 {
4319 break;
4320 }
43334321
43344322 if((hdr_incomplete) && (!seclen))
43354323 {
43364324 break;
43374325 }
43384326
4339 if(!hdr_seen && (sectype != FST_BL_HDR))
4340 {
4341 break;
4342 }
4343
4344 blkpos++;
4345 if(sectype == FST_BL_HDR)
4346 {
4347 if(!hdr_seen)
4348 {
4349 int ch;
4350 double dcheck;
4351
4352 xc->start_time = fstReaderUint64(xc->f);
4353 xc->end_time = fstReaderUint64(xc->f);
4354
4355 hdr_incomplete = (xc->start_time == 0) && (xc->end_time == 0);
4356
4357 fstFread(&dcheck, 8, 1, xc->f);
4358 xc->double_endian_match = (dcheck == FST_DOUBLE_ENDTEST);
4359 if(!xc->double_endian_match)
4360 {
4361 union {
4362 unsigned char rvs_buf[8];
4363 double d;
4364 } vu;
4365
4366 unsigned char *dcheck_alias = (unsigned char *)&dcheck;
4367 int rvs_idx;
4368
4369 for(rvs_idx=0;rvs_idx<8;rvs_idx++)
4370 {
4371 vu.rvs_buf[rvs_idx] = dcheck_alias[7-rvs_idx];
4372 }
4373 if(vu.d != FST_DOUBLE_ENDTEST)
4374 {
4375 break; /* either corrupt file or wrong architecture (offset +33 also functions as matchword) */
4376 }
4377 }
4378
4379 hdr_seen = 1;
4380
4381 xc->mem_used_by_writer = fstReaderUint64(xc->f);
4382 xc->scope_count = fstReaderUint64(xc->f);
4383 xc->var_count = fstReaderUint64(xc->f);
4384 xc->maxhandle = fstReaderUint64(xc->f);
4385 xc->num_alias = xc->var_count - xc->maxhandle;
4386 xc->vc_section_count = fstReaderUint64(xc->f);
4387 ch = fgetc(xc->f);
4388 xc->timescale = (signed char)ch;
4389 fstFread(xc->version, FST_HDR_SIM_VERSION_SIZE, 1, xc->f);
4390 xc->version[FST_HDR_SIM_VERSION_SIZE] = 0;
4391 fstFread(xc->date, FST_HDR_DATE_SIZE, 1, xc->f);
4392 xc->date[FST_HDR_DATE_SIZE] = 0;
4393 ch = fgetc(xc->f);
4394 xc->filetype = (unsigned char)ch;
4395 xc->timezero = fstReaderUint64(xc->f);
4396 }
4397 }
4398 else if((sectype == FST_BL_VCDATA) || (sectype == FST_BL_VCDATA_DYN_ALIAS) || (sectype == FST_BL_VCDATA_DYN_ALIAS2))
4399 {
4400 if(hdr_incomplete)
4401 {
4402 uint64_t bt = fstReaderUint64(xc->f);
4403 xc->end_time = fstReaderUint64(xc->f);
4404
4405 if(!vc_section_count_actual) { xc->start_time = bt; }
4406 }
4407
4408 vc_section_count_actual++;
4409 }
4410 else if(sectype == FST_BL_GEOM)
4411 {
4412 if(!hdr_incomplete)
4413 {
4414 uint64_t clen = seclen - 24;
4415 uint64_t uclen = fstReaderUint64(xc->f);
4416 unsigned char *ucdata = malloc(uclen);
4417 unsigned char *pnt = ucdata;
4418 int i;
4419
4420 xc->contains_geom_section = 1;
4421 xc->maxhandle = fstReaderUint64(xc->f);
4422 xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
4423
4424 free(xc->process_mask);
4425 xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
4426
4427 if(clen != uclen)
4428 {
4429 unsigned char *cdata = malloc(clen);
4430 unsigned long destlen = uclen;
4431 unsigned long sourcelen = clen;
4432 int rc;
4433
4434 fstFread(cdata, clen, 1, xc->f);
4435 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
4436
4437 if(rc != Z_OK)
4438 {
4439 printf("geom uncompress rc = %d\n", rc);
4440 exit(255);
4441 }
4442
4443 free(cdata);
4444 }
4445 else
4446 {
4447 fstFread(ucdata, uclen, 1, xc->f);
4448 }
4449
4450 free(xc->signal_lens);
4451 xc->signal_lens = malloc(sizeof(uint32_t) * xc->maxhandle);
4452 free(xc->signal_typs);
4453 xc->signal_typs = malloc(sizeof(unsigned char) * xc->maxhandle);
4454
4455 for(i=0;i<xc->maxhandle;i++)
4456 {
4457 int skiplen;
4458 uint64_t val = fstGetVarint32(pnt, &skiplen);
4459
4460 pnt += skiplen;
4461
4462 if(val)
4463 {
4464 xc->signal_lens[i] = (val != 0xFFFFFFFF) ? val : 0;
4465 xc->signal_typs[i] = FST_VT_VCD_WIRE;
4466 if(xc->signal_lens[i] > xc->longest_signal_value_len)
4467 {
4468 xc->longest_signal_value_len = xc->signal_lens[i];
4469 }
4470 }
4471 else
4472 {
4473 xc->signal_lens[i] = 8; /* backpatch in real */
4474 xc->signal_typs[i] = FST_VT_VCD_REAL;
4475 /* xc->longest_signal_value_len handled above by overly large init size */
4476 }
4477 }
4478
4479 free(xc->temp_signal_value_buf);
4480 xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
4481
4482 free(ucdata);
4483 }
4484 }
4485 else if(sectype == FST_BL_HIER)
4486 {
4487 xc->contains_hier_section = 1;
4488 xc->hier_pos = ftello(xc->f);
4489 }
4490 else if(sectype == FST_BL_HIER_LZ4DUO)
4491 {
4492 xc->contains_hier_section_lz4 = 1;
4493 xc->contains_hier_section_lz4duo = 1;
4494 xc->hier_pos = ftello(xc->f);
4495 }
4496 else if(sectype == FST_BL_HIER_LZ4)
4497 {
4498 xc->contains_hier_section_lz4 = 1;
4499 xc->hier_pos = ftello(xc->f);
4500 }
4501 else if(sectype == FST_BL_BLACKOUT)
4502 {
4503 uint32_t i;
4504 uint64_t cur_bl = 0;
4505 uint64_t delta;
4506
4507 xc->num_blackouts = fstReaderVarint32(xc->f);
4508 free(xc->blackout_times);
4509 xc->blackout_times = calloc(xc->num_blackouts, sizeof(uint64_t));
4510 free(xc->blackout_activity);
4511 xc->blackout_activity = calloc(xc->num_blackouts, sizeof(unsigned char));
4512
4513 for(i=0;i<xc->num_blackouts;i++)
4514 {
4515 xc->blackout_activity[i] = fgetc(xc->f) != 0;
4516 delta = fstReaderVarint64(xc->f);
4517 cur_bl += delta;
4518 xc->blackout_times[i] = cur_bl;
4519 }
4520 }
4521
4522 blkpos += seclen;
4523 if(!hdr_seen) break;
4524 }
4525
4526 if(hdr_seen)
4527 {
4528 if(xc->vc_section_count != vc_section_count_actual)
4529 {
4530 xc->vc_section_count = vc_section_count_actual;
4531 }
4532
4533 if(!xc->contains_geom_section)
4534 {
4535 fstReaderProcessHier(xc, NULL); /* recreate signal_lens/signal_typs info */
4536 }
4537 }
4538 }
4327 if(!hdr_seen && (sectype != FST_BL_HDR))
4328 {
4329 break;
4330 }
4331
4332 blkpos++;
4333 if(sectype == FST_BL_HDR)
4334 {
4335 if(!hdr_seen)
4336 {
4337 int ch;
4338 double dcheck;
4339
4340 xc->start_time = fstReaderUint64(xc->f);
4341 xc->end_time = fstReaderUint64(xc->f);
4342
4343 hdr_incomplete = (xc->start_time == 0) && (xc->end_time == 0);
4344
4345 fstFread(&dcheck, 8, 1, xc->f);
4346 xc->double_endian_match = (dcheck == FST_DOUBLE_ENDTEST);
4347 if(!xc->double_endian_match)
4348 {
4349 union {
4350 unsigned char rvs_buf[8];
4351 double d;
4352 } vu;
4353
4354 unsigned char *dcheck_alias = (unsigned char *)&dcheck;
4355 int rvs_idx;
4356
4357 for(rvs_idx=0;rvs_idx<8;rvs_idx++)
4358 {
4359 vu.rvs_buf[rvs_idx] = dcheck_alias[7-rvs_idx];
4360 }
4361 if(vu.d != FST_DOUBLE_ENDTEST)
4362 {
4363 break; /* either corrupt file or wrong architecture (offset +33 also functions as matchword) */
4364 }
4365 }
4366
4367 hdr_seen = 1;
4368
4369 xc->mem_used_by_writer = fstReaderUint64(xc->f);
4370 xc->scope_count = fstReaderUint64(xc->f);
4371 xc->var_count = fstReaderUint64(xc->f);
4372 xc->maxhandle = fstReaderUint64(xc->f);
4373 xc->num_alias = xc->var_count - xc->maxhandle;
4374 xc->vc_section_count = fstReaderUint64(xc->f);
4375 ch = fgetc(xc->f);
4376 xc->timescale = (signed char)ch;
4377 fstFread(xc->version, FST_HDR_SIM_VERSION_SIZE, 1, xc->f);
4378 xc->version[FST_HDR_SIM_VERSION_SIZE] = 0;
4379 fstFread(xc->date, FST_HDR_DATE_SIZE, 1, xc->f);
4380 xc->date[FST_HDR_DATE_SIZE] = 0;
4381 ch = fgetc(xc->f);
4382 xc->filetype = (unsigned char)ch;
4383 xc->timezero = fstReaderUint64(xc->f);
4384 }
4385 }
4386 else if((sectype == FST_BL_VCDATA) || (sectype == FST_BL_VCDATA_DYN_ALIAS) || (sectype == FST_BL_VCDATA_DYN_ALIAS2))
4387 {
4388 if(hdr_incomplete)
4389 {
4390 uint64_t bt = fstReaderUint64(xc->f);
4391 xc->end_time = fstReaderUint64(xc->f);
4392
4393 if(!vc_section_count_actual) { xc->start_time = bt; }
4394 }
4395
4396 vc_section_count_actual++;
4397 }
4398 else if(sectype == FST_BL_GEOM)
4399 {
4400 if(!hdr_incomplete)
4401 {
4402 uint64_t clen = seclen - 24;
4403 uint64_t uclen = fstReaderUint64(xc->f);
4404 unsigned char *ucdata = malloc(uclen);
4405 unsigned char *pnt = ucdata;
4406 unsigned int i;
4407
4408 xc->contains_geom_section = 1;
4409 xc->maxhandle = fstReaderUint64(xc->f);
4410 xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
4411
4412 free(xc->process_mask);
4413 xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
4414
4415 if(clen != uclen)
4416 {
4417 unsigned char *cdata = malloc(clen);
4418 unsigned long destlen = uclen;
4419 unsigned long sourcelen = clen;
4420 int rc;
4421
4422 fstFread(cdata, clen, 1, xc->f);
4423 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
4424
4425 if(rc != Z_OK)
4426 {
4427 printf("geom uncompress rc = %d\n", rc);
4428 exit(255);
4429 }
4430
4431 free(cdata);
4432 }
4433 else
4434 {
4435 fstFread(ucdata, uclen, 1, xc->f);
4436 }
4437
4438 free(xc->signal_lens);
4439 xc->signal_lens = malloc(sizeof(uint32_t) * xc->maxhandle);
4440 free(xc->signal_typs);
4441 xc->signal_typs = malloc(sizeof(unsigned char) * xc->maxhandle);
4442
4443 for(i=0;i<xc->maxhandle;i++)
4444 {
4445 int skiplen;
4446 uint64_t val = fstGetVarint32(pnt, &skiplen);
4447
4448 pnt += skiplen;
4449
4450 if(val)
4451 {
4452 xc->signal_lens[i] = (val != 0xFFFFFFFF) ? val : 0;
4453 xc->signal_typs[i] = FST_VT_VCD_WIRE;
4454 if(xc->signal_lens[i] > xc->longest_signal_value_len)
4455 {
4456 xc->longest_signal_value_len = xc->signal_lens[i];
4457 }
4458 }
4459 else
4460 {
4461 xc->signal_lens[i] = 8; /* backpatch in real */
4462 xc->signal_typs[i] = FST_VT_VCD_REAL;
4463 /* xc->longest_signal_value_len handled above by overly large init size */
4464 }
4465 }
4466
4467 free(xc->temp_signal_value_buf);
4468 xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
4469
4470 free(ucdata);
4471 }
4472 }
4473 else if(sectype == FST_BL_HIER)
4474 {
4475 xc->contains_hier_section = 1;
4476 xc->hier_pos = ftello(xc->f);
4477 }
4478 else if(sectype == FST_BL_HIER_LZ4DUO)
4479 {
4480 xc->contains_hier_section_lz4 = 1;
4481 xc->contains_hier_section_lz4duo = 1;
4482 xc->hier_pos = ftello(xc->f);
4483 }
4484 else if(sectype == FST_BL_HIER_LZ4)
4485 {
4486 xc->contains_hier_section_lz4 = 1;
4487 xc->hier_pos = ftello(xc->f);
4488 }
4489 else if(sectype == FST_BL_BLACKOUT)
4490 {
4491 uint32_t i;
4492 uint64_t cur_bl = 0;
4493 uint64_t delta;
4494
4495 xc->num_blackouts = fstReaderVarint32(xc->f);
4496 free(xc->blackout_times);
4497 xc->blackout_times = calloc(xc->num_blackouts, sizeof(uint64_t));
4498 free(xc->blackout_activity);
4499 xc->blackout_activity = calloc(xc->num_blackouts, sizeof(unsigned char));
4500
4501 for(i=0;i<xc->num_blackouts;i++)
4502 {
4503 xc->blackout_activity[i] = fgetc(xc->f) != 0;
4504 delta = fstReaderVarint64(xc->f);
4505 cur_bl += delta;
4506 xc->blackout_times[i] = cur_bl;
4507 }
4508 }
4509
4510 blkpos += seclen;
4511 if(!hdr_seen) break;
4512 }
4513
4514 if(hdr_seen)
4515 {
4516 if(xc->vc_section_count != vc_section_count_actual)
4517 {
4518 xc->vc_section_count = vc_section_count_actual;
4519 }
4520
4521 if(!xc->contains_geom_section)
4522 {
4523 fstReaderProcessHier(xc, NULL); /* recreate signal_lens/signal_typs info */
4524 }
4525 }
4526 }
45394527
45404528 return(hdr_seen);
45414529 }
45624550 {
45634551 int flen = strlen(nam);
45644552 char *hf = calloc(1, flen + 6);
4565 int rc;
4553 int rc;
45664554
45674555 #if defined(__MINGW32__) || defined(FST_MACOSX)
4568 setvbuf(xc->f, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
4556 setvbuf(xc->f, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
45694557 #endif
45704558
45714559 memcpy(hf, nam, flen);
45724560 strcpy(hf + flen, ".hier");
45734561 xc->fh = fopen(hf, "rb");
45744562
4575 free(hf);
4576 xc->filename = strdup(nam);
4577 rc = fstReaderInit(xc);
4578
4579 if((rc) && (xc->vc_section_count) && (xc->maxhandle) && ((xc->fh)||(xc->contains_hier_section||(xc->contains_hier_section_lz4))))
4580 {
4581 /* more init */
4582 xc->do_rewind = 1;
4583 }
4584 else
4585 {
4586 fstReaderClose(xc);
4587 xc = NULL;
4588 }
4589 }
4563 free(hf);
4564 xc->filename = strdup(nam);
4565 rc = fstReaderInit(xc);
4566
4567 if((rc) && (xc->vc_section_count) && (xc->maxhandle) && ((xc->fh)||(xc->contains_hier_section||(xc->contains_hier_section_lz4))))
4568 {
4569 /* more init */
4570 xc->do_rewind = 1;
4571 }
4572 else
4573 {
4574 fstReaderClose(xc);
4575 xc = NULL;
4576 }
4577 }
45904578
45914579 return(xc);
45924580 }
45964584 {
45974585 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
45984586 if(xc)
4599 {
4600 free(xc->rvat_chain_mem); xc->rvat_chain_mem = NULL;
4601 free(xc->rvat_frame_data); xc->rvat_frame_data = NULL;
4602 free(xc->rvat_time_table); xc->rvat_time_table = NULL;
4603 free(xc->rvat_chain_table); xc->rvat_chain_table = NULL;
4604 free(xc->rvat_chain_table_lengths); xc->rvat_chain_table_lengths = NULL;
4605
4606 xc->rvat_data_valid = 0;
4607 }
4587 {
4588 free(xc->rvat_chain_mem); xc->rvat_chain_mem = NULL;
4589 free(xc->rvat_frame_data); xc->rvat_frame_data = NULL;
4590 free(xc->rvat_time_table); xc->rvat_time_table = NULL;
4591 free(xc->rvat_chain_table); xc->rvat_chain_table = NULL;
4592 free(xc->rvat_chain_table_lengths); xc->rvat_chain_table_lengths = NULL;
4593
4594 xc->rvat_data_valid = 0;
4595 }
46084596 }
46094597
46104598
46134601 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
46144602
46154603 if(xc)
4616 {
4617 fstReaderDeallocateScopeData(xc);
4618 fstReaderDeallocateRvatData(xc);
4619 free(xc->rvat_sig_offs); xc->rvat_sig_offs = NULL;
4620
4621 free(xc->process_mask); xc->process_mask = NULL;
4622 free(xc->blackout_times); xc->blackout_times = NULL;
4623 free(xc->blackout_activity); xc->blackout_activity = NULL;
4624 free(xc->temp_signal_value_buf); xc->temp_signal_value_buf = NULL;
4625 free(xc->signal_typs); xc->signal_typs = NULL;
4626 free(xc->signal_lens); xc->signal_lens = NULL;
4627 free(xc->filename); xc->filename = NULL;
4628
4629 if(xc->fh)
4630 {
4631 tmpfile_close(&xc->fh, &xc->fh_nam);
4632 }
4633
4634 if(xc->f)
4635 {
4636 tmpfile_close(&xc->f, &xc->f_nam);
4637 if(xc->filename_unpacked)
4638 {
4639 unlink(xc->filename_unpacked);
4640 free(xc->filename_unpacked);
4641 }
4642 }
4643
4644 free(xc);
4645 }
4604 {
4605 fstReaderDeallocateScopeData(xc);
4606 fstReaderDeallocateRvatData(xc);
4607 free(xc->rvat_sig_offs); xc->rvat_sig_offs = NULL;
4608
4609 free(xc->process_mask); xc->process_mask = NULL;
4610 free(xc->blackout_times); xc->blackout_times = NULL;
4611 free(xc->blackout_activity); xc->blackout_activity = NULL;
4612 free(xc->temp_signal_value_buf); xc->temp_signal_value_buf = NULL;
4613 free(xc->signal_typs); xc->signal_typs = NULL;
4614 free(xc->signal_lens); xc->signal_lens = NULL;
4615 free(xc->filename); xc->filename = NULL;
4616
4617 if(xc->fh)
4618 {
4619 tmpfile_close(&xc->fh, &xc->fh_nam);
4620 }
4621
4622 if(xc->f)
4623 {
4624 tmpfile_close(&xc->f, &xc->f_nam);
4625 if(xc->filename_unpacked)
4626 {
4627 unlink(xc->filename_unpacked);
4628 free(xc->filename_unpacked);
4629 }
4630 }
4631
4632 free(xc);
4633 }
46464634 }
46474635
46484636
46614649
46624650 int fstReaderIterBlocks2(void *ctx,
46634651 void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
4664 void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
4652 void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
46654653 void *user_callback_data_pointer, FILE *fv)
46664654 {
46674655 struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
46694657 uint64_t previous_time = UINT64_MAX;
46704658 uint64_t *time_table = NULL;
46714659 uint64_t tsec_nitems;
4672 int secnum = 0;
4660 unsigned int secnum = 0;
46734661 int blocks_skipped = 0;
46744662 off_t blkpos = 0;
46754663 uint64_t seclen, beg_tim;
47054693 length_remaining = calloc(xc->maxhandle, sizeof(uint32_t));
47064694
47074695 if(fv)
4708 {
4709 fprintf(fv, "$dumpvars\n");
4696 {
4697 fprintf(fv, "$dumpvars\n");
47104698 #ifndef FST_WRITEX_DISABLE
4711 fflush(fv);
4712 setvbuf(fv, (char *) NULL, _IONBF, 0); /* even buffered IO is slow so disable it and use our own routines that don't need seeking */
4713 xc->writex_fd = fileno(fv);
4714 #endif
4715 }
4699 fflush(fv);
4700 setvbuf(fv, (char *) NULL, _IONBF, 0); /* even buffered IO is slow so disable it and use our own routines that don't need seeking */
4701 xc->writex_fd = fileno(fv);
4702 #endif
4703 }
47164704
47174705 for(;;)
4718 {
4719 uint32_t *tc_head = NULL;
4720 traversal_mem_offs = 0;
4721
4722 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
4723
4724 sectype = fgetc(xc->f);
4725 seclen = fstReaderUint64(xc->f);
4726
4727 if((sectype == EOF) || (sectype == FST_BL_SKIP))
4728 {
4706 {
4707 uint32_t *tc_head = NULL;
4708 traversal_mem_offs = 0;
4709
4710 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
4711
4712 sectype = fgetc(xc->f);
4713 seclen = fstReaderUint64(xc->f);
4714
4715 if((sectype == EOF) || (sectype == FST_BL_SKIP))
4716 {
47294717 #ifdef FST_DEBUG
4730 fprintf(stderr, "<< EOF >>\n");
4731 #endif
4732 break;
4733 }
4734
4735 blkpos++;
4736 if((sectype != FST_BL_VCDATA) && (sectype != FST_BL_VCDATA_DYN_ALIAS) && (sectype != FST_BL_VCDATA_DYN_ALIAS2))
4737 {
4738 blkpos += seclen;
4739 continue;
4740 }
4741
4742 if(!seclen) break;
4743
4744 beg_tim = fstReaderUint64(xc->f);
4718 fprintf(stderr, "<< EOF >>\n");
4719 #endif
4720 break;
4721 }
4722
4723 blkpos++;
4724 if((sectype != FST_BL_VCDATA) && (sectype != FST_BL_VCDATA_DYN_ALIAS) && (sectype != FST_BL_VCDATA_DYN_ALIAS2))
4725 {
4726 blkpos += seclen;
4727 continue;
4728 }
4729
4730 if(!seclen) break;
4731
4732 beg_tim = fstReaderUint64(xc->f);
47454733 #ifdef FST_DEBUG
4746 end_tim =
4747 #endif
4748 fstReaderUint64(xc->f);
4749
4750 if(xc->limit_range_valid)
4751 {
4752 if(beg_tim < xc->limit_range_start)
4753 {
4754 blocks_skipped++;
4755 blkpos += seclen;
4756 continue;
4757 }
4758
4759 if(beg_tim > xc->limit_range_end) /* likely the compare in for(i=0;i<tsec_nitems;i++) below would do this earlier */
4760 {
4761 break;
4762 }
4763 }
4764
4765
4766 mem_required_for_traversal = fstReaderUint64(xc->f);
4767 mem_for_traversal = malloc(mem_required_for_traversal + 66); /* add in potential fastlz overhead */
4734 end_tim =
4735 #endif
4736 fstReaderUint64(xc->f);
4737
4738 if(xc->limit_range_valid)
4739 {
4740 if(beg_tim < xc->limit_range_start)
4741 {
4742 blocks_skipped++;
4743 blkpos += seclen;
4744 continue;
4745 }
4746
4747 if(beg_tim > xc->limit_range_end) /* likely the compare in for(i=0;i<tsec_nitems;i++) below would do this earlier */
4748 {
4749 break;
4750 }
4751 }
4752
4753
4754 mem_required_for_traversal = fstReaderUint64(xc->f);
4755 mem_for_traversal = malloc(mem_required_for_traversal + 66); /* add in potential fastlz overhead */
47684756 #ifdef FST_DEBUG
4769 fprintf(stderr, "sec: %d seclen: %d begtim: %d endtim: %d\n",
4770 secnum, (int)seclen, (int)beg_tim, (int)end_tim);
4771 fprintf(stderr, "\tmem_required_for_traversal: %d\n", (int)mem_required_for_traversal);
4772 #endif
4773 /* process time block */
4774 {
4775 unsigned char *ucdata;
4776 unsigned char *cdata;
4777 unsigned long destlen /* = tsec_uclen */; /* scan-build */
4778 unsigned long sourcelen /*= tsec_clen */; /* scan-build */
4779 int rc;
4780 unsigned char *tpnt;
4781 uint64_t tpval;
4782 int ti;
4783
4784 if(fstReaderFseeko(xc, xc->f, blkpos + seclen - 24, SEEK_SET) != 0) break;
4785 tsec_uclen = fstReaderUint64(xc->f);
4786 tsec_clen = fstReaderUint64(xc->f);
4787 tsec_nitems = fstReaderUint64(xc->f);
4757 fprintf(stderr, "sec: %u seclen: %d begtim: %d endtim: %d\n",
4758 secnum, (int)seclen, (int)beg_tim, (int)end_tim);
4759 fprintf(stderr, "\tmem_required_for_traversal: %d\n", (int)mem_required_for_traversal);
4760 #endif
4761 /* process time block */
4762 {
4763 unsigned char *ucdata;
4764 unsigned char *cdata;
4765 unsigned long destlen /* = tsec_uclen */; /* scan-build */
4766 unsigned long sourcelen /*= tsec_clen */; /* scan-build */
4767 int rc;
4768 unsigned char *tpnt;
4769 uint64_t tpval;
4770 unsigned int ti;
4771
4772 if(fstReaderFseeko(xc, xc->f, blkpos + seclen - 24, SEEK_SET) != 0) break;
4773 tsec_uclen = fstReaderUint64(xc->f);
4774 tsec_clen = fstReaderUint64(xc->f);
4775 tsec_nitems = fstReaderUint64(xc->f);
47884776 #ifdef FST_DEBUG
4789 fprintf(stderr, "\ttime section unc: %d, com: %d (%d items)\n",
4790 (int)tsec_uclen, (int)tsec_clen, (int)tsec_nitems);
4791 #endif
4792 if(tsec_clen > seclen) break; /* corrupted tsec_clen: by definition it can't be larger than size of section */
4793 ucdata = malloc(tsec_uclen);
4794 if(!ucdata) break; /* malloc fail as tsec_uclen out of range from corrupted file */
4795 destlen = tsec_uclen;
4796 sourcelen = tsec_clen;
4797
4798 fstReaderFseeko(xc, xc->f, -24 - ((off_t)tsec_clen), SEEK_CUR);
4799
4800 if(tsec_uclen != tsec_clen)
4801 {
4802 cdata = malloc(tsec_clen);
4803 fstFread(cdata, tsec_clen, 1, xc->f);
4804
4805 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
4806
4807 if(rc != Z_OK)
4808 {
4809 printf("tsec uncompress rc = %d\n", rc);
4810 exit(255);
4811 }
4812
4813 free(cdata);
4814 }
4815 else
4816 {
4817 fstFread(ucdata, tsec_uclen, 1, xc->f);
4818 }
4819
4820 free(time_table);
4821 time_table = calloc(tsec_nitems, sizeof(uint64_t));
4822 tpnt = ucdata;
4823 tpval = 0;
4824 for(ti=0;ti<tsec_nitems;ti++)
4825 {
4826 int skiplen;
4827 uint64_t val = fstGetVarint64(tpnt, &skiplen);
4828 tpval = time_table[ti] = tpval + val;
4829 tpnt += skiplen;
4830 }
4831
4832 tc_head = calloc(tsec_nitems /* scan-build */ ? tsec_nitems : 1, sizeof(uint32_t));
4833 free(ucdata);
4834 }
4835
4836 fstReaderFseeko(xc, xc->f, blkpos+32, SEEK_SET);
4837
4838 frame_uclen = fstReaderVarint64(xc->f);
4839 frame_clen = fstReaderVarint64(xc->f);
4840 frame_maxhandle = fstReaderVarint64(xc->f);
4841
4842 if(secnum == 0)
4843 {
4844 if((beg_tim != time_table[0]) || (blocks_skipped))
4845 {
4846 unsigned char *mu = malloc(frame_uclen);
4847 uint32_t sig_offs = 0;
4848
4849 if(fv)
4850 {
4851 char wx_buf[32];
4852 int wx_len;
4853
4854 if(beg_tim)
4855 {
4856 wx_len = sprintf(wx_buf, "#%"PRIu64"\n", beg_tim);
4857 fstWritex(xc, wx_buf, wx_len);
4858 }
4859 if((xc->num_blackouts)&&(cur_blackout != xc->num_blackouts))
4860 {
4861 if(beg_tim == xc->blackout_times[cur_blackout])
4862 {
4863 wx_len = sprintf(wx_buf, "$dump%s $end\n", (xc->blackout_activity[cur_blackout++]) ? "on" : "off");
4864 fstWritex(xc, wx_buf, wx_len);
4865 }
4866 }
4867 }
4868
4869 if(frame_uclen == frame_clen)
4870 {
4871 fstFread(mu, frame_uclen, 1, xc->f);
4872 }
4873 else
4874 {
4875 unsigned char *mc = malloc(frame_clen);
4876 int rc;
4877
4878 unsigned long destlen = frame_uclen;
4879 unsigned long sourcelen = frame_clen;
4880
4881 fstFread(mc, sourcelen, 1, xc->f);
4882 rc = uncompress(mu, &destlen, mc, sourcelen);
4883 if(rc != Z_OK)
4884 {
4885 printf("rc: %d\n", rc);
4886 exit(255);
4887 }
4888 free(mc);
4889 }
4890
4891
4892 for(idx=0;idx<frame_maxhandle;idx++)
4893 {
4894 int process_idx = idx/8;
4895 int process_bit = idx&7;
4896
4897 if(xc->process_mask[process_idx]&(1<<process_bit))
4898 {
4899 if(xc->signal_lens[idx] <= 1)
4900 {
4901 if(xc->signal_lens[idx] == 1)
4902 {
4903 unsigned char val = mu[sig_offs];
4904 if(value_change_callback)
4905 {
4906 xc->temp_signal_value_buf[0] = val;
4907 xc->temp_signal_value_buf[1] = 0;
4908 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4909 }
4910 else
4911 {
4912 if(fv)
4913 {
4914 char vcd_id[16];
4915
4916 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
4917 vcd_id[0] = val; /* collapse 3 writes into one I/O call */
4918 vcd_id[vcdid_len + 1] = '\n';
4919 fstWritex(xc, vcd_id, vcdid_len + 2);
4920 }
4921 }
4922 }
4923 else
4924 {
4925 /* variable-length ("0" length) records have no initial state */
4926 }
4927 }
4928 else
4929 {
4930 if(xc->signal_typs[idx] != FST_VT_VCD_REAL)
4931 {
4932 if(value_change_callback)
4933 {
4934 memcpy(xc->temp_signal_value_buf, mu+sig_offs, xc->signal_lens[idx]);
4935 xc->temp_signal_value_buf[xc->signal_lens[idx]] = 0;
4936 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4937 }
4938 else
4939 {
4940 if(fv)
4941 {
4942 char vcd_id[16];
4943 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
4944
4945 vcd_id[0] = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
4946 fstWritex(xc, vcd_id, 1);
4947 fstWritex(xc,mu+sig_offs, xc->signal_lens[idx]);
4948
4949 vcd_id[0] = ' '; /* collapse 3 writes into one I/O call */
4950 vcd_id[vcdid_len + 1] = '\n';
4951 fstWritex(xc, vcd_id, vcdid_len + 2);
4952 }
4953 }
4954 }
4955 else
4956 {
4957 double d;
4958 unsigned char *clone_d;
4959 unsigned char *srcdata = mu+sig_offs;
4960
4961 if(value_change_callback)
4962 {
4963 if(xc->native_doubles_for_cb)
4964 {
4965 if(xc->double_endian_match)
4966 {
4967 clone_d = srcdata;
4968 }
4969 else
4970 {
4971 int j;
4972
4973 clone_d = (unsigned char *)&d;
4974 for(j=0;j<8;j++)
4975 {
4976 clone_d[j] = srcdata[7-j];
4977 }
4978 }
4979 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, clone_d);
4980 }
4981 else
4982 {
4983 clone_d = (unsigned char *)&d;
4984 if(xc->double_endian_match)
4985 {
4986 memcpy(clone_d, srcdata, 8);
4987 }
4988 else
4989 {
4990 int j;
4991
4992 for(j=0;j<8;j++)
4993 {
4994 clone_d[j] = srcdata[7-j];
4995 }
4996 }
4997 sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
4998 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4999 }
5000 }
5001 else
5002 {
5003 if(fv)
5004 {
5005 char vcdid_buf[16];
5006 char wx_buf[64];
5007 int wx_len;
5008
5009 clone_d = (unsigned char *)&d;
5010 if(xc->double_endian_match)
5011 {
5012 memcpy(clone_d, srcdata, 8);
5013 }
5014 else
5015 {
5016 int j;
5017
5018 for(j=0;j<8;j++)
5019 {
5020 clone_d[j] = srcdata[7-j];
5021 }
5022 }
5023
5024 fstVcdID(vcdid_buf, idx+1);
5025 wx_len = sprintf(wx_buf, "r%.16g %s\n", d, vcdid_buf);
5026 fstWritex(xc, wx_buf, wx_len);
5027 }
5028 }
5029 }
5030 }
5031 }
5032
5033 sig_offs += xc->signal_lens[idx];
5034 }
5035
5036 free(mu);
5037 fstReaderFseeko(xc, xc->f, -((off_t)frame_clen), SEEK_CUR);
5038 }
5039 }
5040
5041 fstReaderFseeko(xc, xc->f, (off_t)frame_clen, SEEK_CUR); /* skip past compressed data */
5042
5043 vc_maxhandle = fstReaderVarint64(xc->f);
5044 vc_start = ftello(xc->f); /* points to '!' character */
5045 packtype = fgetc(xc->f);
4777 fprintf(stderr, "\ttime section unc: %d, com: %d (%d items)\n",
4778 (int)tsec_uclen, (int)tsec_clen, (int)tsec_nitems);
4779 #endif
4780 if(tsec_clen > seclen) break; /* corrupted tsec_clen: by definition it can't be larger than size of section */
4781 ucdata = malloc(tsec_uclen);
4782 if(!ucdata) break; /* malloc fail as tsec_uclen out of range from corrupted file */
4783 destlen = tsec_uclen;
4784 sourcelen = tsec_clen;
4785
4786 fstReaderFseeko(xc, xc->f, -24 - ((off_t)tsec_clen), SEEK_CUR);
4787
4788 if(tsec_uclen != tsec_clen)
4789 {
4790 cdata = malloc(tsec_clen);
4791 fstFread(cdata, tsec_clen, 1, xc->f);
4792
4793 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
4794
4795 if(rc != Z_OK)
4796 {
4797 printf("tsec uncompress rc = %d\n", rc);
4798 exit(255);
4799 }
4800
4801 free(cdata);
4802 }
4803 else
4804 {
4805 fstFread(ucdata, tsec_uclen, 1, xc->f);
4806 }
4807
4808 free(time_table);
4809 time_table = calloc(tsec_nitems, sizeof(uint64_t));
4810 tpnt = ucdata;
4811 tpval = 0;
4812 for(ti=0;ti<tsec_nitems;ti++)
4813 {
4814 int skiplen;
4815 uint64_t val = fstGetVarint64(tpnt, &skiplen);
4816 tpval = time_table[ti] = tpval + val;
4817 tpnt += skiplen;
4818 }
4819
4820 tc_head = calloc(tsec_nitems /* scan-build */ ? tsec_nitems : 1, sizeof(uint32_t));
4821 free(ucdata);
4822 }
4823
4824 fstReaderFseeko(xc, xc->f, blkpos+32, SEEK_SET);
4825
4826 frame_uclen = fstReaderVarint64(xc->f);
4827 frame_clen = fstReaderVarint64(xc->f);
4828 frame_maxhandle = fstReaderVarint64(xc->f);
4829
4830 if(secnum == 0)
4831 {
4832 if((beg_tim != time_table[0]) || (blocks_skipped))
4833 {
4834 unsigned char *mu = malloc(frame_uclen);
4835 uint32_t sig_offs = 0;
4836
4837 if(fv)
4838 {
4839 char wx_buf[32];
4840 int wx_len;
4841
4842 if(beg_tim)
4843 {
4844 wx_len = sprintf(wx_buf, "#%"PRIu64"\n", beg_tim);
4845 fstWritex(xc, wx_buf, wx_len);
4846 }
4847 if((xc->num_blackouts)&&(cur_blackout != xc->num_blackouts))
4848 {
4849 if(beg_tim == xc->blackout_times[cur_blackout])
4850 {
4851 wx_len = sprintf(wx_buf, "$dump%s $end\n", (xc->blackout_activity[cur_blackout++]) ? "on" : "off");
4852 fstWritex(xc, wx_buf, wx_len);
4853 }
4854 }
4855 }
4856
4857 if(frame_uclen == frame_clen)
4858 {
4859 fstFread(mu, frame_uclen, 1, xc->f);
4860 }
4861 else
4862 {
4863 unsigned char *mc = malloc(frame_clen);
4864 int rc;
4865
4866 unsigned long destlen = frame_uclen;
4867 unsigned long sourcelen = frame_clen;
4868
4869 fstFread(mc, sourcelen, 1, xc->f);
4870 rc = uncompress(mu, &destlen, mc, sourcelen);
4871 if(rc != Z_OK)
4872 {
4873 printf("rc: %d\n", rc);
4874 exit(255);
4875 }
4876 free(mc);
4877 }
4878
4879
4880 for(idx=0;idx<frame_maxhandle;idx++)
4881 {
4882 int process_idx = idx/8;
4883 int process_bit = idx&7;
4884
4885 if(xc->process_mask[process_idx]&(1<<process_bit))
4886 {
4887 if(xc->signal_lens[idx] <= 1)
4888 {
4889 if(xc->signal_lens[idx] == 1)
4890 {
4891 unsigned char val = mu[sig_offs];
4892 if(value_change_callback)
4893 {
4894 xc->temp_signal_value_buf[0] = val;
4895 xc->temp_signal_value_buf[1] = 0;
4896 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4897 }
4898 else
4899 {
4900 if(fv)
4901 {
4902 char vcd_id[16];
4903
4904 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
4905 vcd_id[0] = val; /* collapse 3 writes into one I/O call */
4906 vcd_id[vcdid_len + 1] = '\n';
4907 fstWritex(xc, vcd_id, vcdid_len + 2);
4908 }
4909 }
4910 }
4911 else
4912 {
4913 /* variable-length ("0" length) records have no initial state */
4914 }
4915 }
4916 else
4917 {
4918 if(xc->signal_typs[idx] != FST_VT_VCD_REAL)
4919 {
4920 if(value_change_callback)
4921 {
4922 memcpy(xc->temp_signal_value_buf, mu+sig_offs, xc->signal_lens[idx]);
4923 xc->temp_signal_value_buf[xc->signal_lens[idx]] = 0;
4924 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4925 }
4926 else
4927 {
4928 if(fv)
4929 {
4930 char vcd_id[16];
4931 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
4932
4933 vcd_id[0] = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
4934 fstWritex(xc, vcd_id, 1);
4935 fstWritex(xc,mu+sig_offs, xc->signal_lens[idx]);
4936
4937 vcd_id[0] = ' '; /* collapse 3 writes into one I/O call */
4938 vcd_id[vcdid_len + 1] = '\n';
4939 fstWritex(xc, vcd_id, vcdid_len + 2);
4940 }
4941 }
4942 }
4943 else
4944 {
4945 double d;
4946 unsigned char *clone_d;
4947 unsigned char *srcdata = mu+sig_offs;
4948
4949 if(value_change_callback)
4950 {
4951 if(xc->native_doubles_for_cb)
4952 {
4953 if(xc->double_endian_match)
4954 {
4955 clone_d = srcdata;
4956 }
4957 else
4958 {
4959 int j;
4960
4961 clone_d = (unsigned char *)&d;
4962 for(j=0;j<8;j++)
4963 {
4964 clone_d[j] = srcdata[7-j];
4965 }
4966 }
4967 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, clone_d);
4968 }
4969 else
4970 {
4971 clone_d = (unsigned char *)&d;
4972 if(xc->double_endian_match)
4973 {
4974 memcpy(clone_d, srcdata, 8);
4975 }
4976 else
4977 {
4978 int j;
4979
4980 for(j=0;j<8;j++)
4981 {
4982 clone_d[j] = srcdata[7-j];
4983 }
4984 }
4985 sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
4986 value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
4987 }
4988 }
4989 else
4990 {
4991 if(fv)
4992 {
4993 char vcdid_buf[16];
4994 char wx_buf[64];
4995 int wx_len;
4996
4997 clone_d = (unsigned char *)&d;
4998 if(xc->double_endian_match)
4999 {
5000 memcpy(clone_d, srcdata, 8);
5001 }
5002 else
5003 {
5004 int j;
5005
5006 for(j=0;j<8;j++)
5007 {
5008 clone_d[j] = srcdata[7-j];
5009 }
5010 }
5011
5012 fstVcdID(vcdid_buf, idx+1);
5013 wx_len = sprintf(wx_buf, "r%.16g %s\n", d, vcdid_buf);
5014 fstWritex(xc, wx_buf, wx_len);
5015 }
5016 }
5017 }
5018 }
5019 }
5020
5021 sig_offs += xc->signal_lens[idx];
5022 }
5023
5024 free(mu);
5025 fstReaderFseeko(xc, xc->f, -((off_t)frame_clen), SEEK_CUR);
5026 }
5027 }
5028
5029 fstReaderFseeko(xc, xc->f, (off_t)frame_clen, SEEK_CUR); /* skip past compressed data */
5030
5031 vc_maxhandle = fstReaderVarint64(xc->f);
5032 vc_start = ftello(xc->f); /* points to '!' character */
5033 packtype = fgetc(xc->f);
50465034
50475035 #ifdef FST_DEBUG
5048 fprintf(stderr, "\tframe_uclen: %d, frame_clen: %d, frame_maxhandle: %d\n",
5049 (int)frame_uclen, (int)frame_clen, (int)frame_maxhandle);
5050 fprintf(stderr, "\tvc_maxhandle: %d, packtype: %c\n", (int)vc_maxhandle, packtype);
5051 #endif
5052
5053 indx_pntr = blkpos + seclen - 24 -tsec_clen -8;
5054 fstReaderFseeko(xc, xc->f, indx_pntr, SEEK_SET);
5055 chain_clen = fstReaderUint64(xc->f);
5056 indx_pos = indx_pntr - chain_clen;
5036 fprintf(stderr, "\tframe_uclen: %d, frame_clen: %d, frame_maxhandle: %d\n",
5037 (int)frame_uclen, (int)frame_clen, (int)frame_maxhandle);
5038 fprintf(stderr, "\tvc_maxhandle: %d, packtype: %c\n", (int)vc_maxhandle, packtype);
5039 #endif
5040
5041 indx_pntr = blkpos + seclen - 24 -tsec_clen -8;
5042 fstReaderFseeko(xc, xc->f, indx_pntr, SEEK_SET);
5043 chain_clen = fstReaderUint64(xc->f);
5044 indx_pos = indx_pntr - chain_clen;
50575045 #ifdef FST_DEBUG
5058 fprintf(stderr, "\tindx_pos: %d (%d bytes)\n", (int)indx_pos, (int)chain_clen);
5059 #endif
5060 chain_cmem = malloc(chain_clen);
5061 if(!chain_cmem) goto block_err;
5062 fstReaderFseeko(xc, xc->f, indx_pos, SEEK_SET);
5063 fstFread(chain_cmem, chain_clen, 1, xc->f);
5064
5065 if(vc_maxhandle > vc_maxhandle_largest)
5066 {
5067 free(chain_table);
5068 free(chain_table_lengths);
5069
5070 vc_maxhandle_largest = vc_maxhandle;
5071 chain_table = calloc((vc_maxhandle+1), sizeof(off_t));
5072 chain_table_lengths = calloc((vc_maxhandle+1), sizeof(uint32_t));
5073 }
5074
5075 if(!chain_table || !chain_table_lengths) goto block_err;
5076
5077 pnt = chain_cmem;
5078 idx = 0;
5079 pval = 0;
5080
5081 if(sectype == FST_BL_VCDATA_DYN_ALIAS2)
5082 {
5083 uint32_t prev_alias = 0;
5084
5085 do {
5086 int skiplen;
5087
5088 if(*pnt & 0x01)
5089 {
5090 int64_t shval = fstGetSVarint64(pnt, &skiplen) >> 1;
5091 if(shval > 0)
5092 {
5093 pval = chain_table[idx] = pval + shval;
5094 if(idx) { chain_table_lengths[pidx] = pval - chain_table[pidx]; }
5095 pidx = idx++;
5096 }
5097 else if(shval < 0)
5098 {
5099 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5100 chain_table_lengths[idx] = prev_alias = shval; /* because during this loop iter would give stale data! */
5101 idx++;
5102 }
5103 else
5104 {
5105 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5106 chain_table_lengths[idx] = prev_alias; /* because during this loop iter would give stale data! */
5107 idx++;
5108 }
5109 }
5110 else
5111 {
5112 uint64_t val = fstGetVarint32(pnt, &skiplen);
5113
5114 int loopcnt = val >> 1;
5115 for(i=0;i<loopcnt;i++)
5116 {
5117 chain_table[idx++] = 0;
5118 }
5119 }
5120
5121 pnt += skiplen;
5122 } while (pnt != (chain_cmem + chain_clen));
5123 }
5124 else
5125 {
5126 do {
5127 int skiplen;
5128 uint64_t val = fstGetVarint32(pnt, &skiplen);
5129
5130 if(!val)
5131 {
5132 pnt += skiplen;
5133 val = fstGetVarint32(pnt, &skiplen);
5134 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5135 chain_table_lengths[idx] = -val; /* because during this loop iter would give stale data! */
5136 idx++;
5137 }
5138 else
5139 if(val&1)
5140 {
5141 pval = chain_table[idx] = pval + (val >> 1);
5142 if(idx) { chain_table_lengths[pidx] = pval - chain_table[pidx]; }
5143 pidx = idx++;
5144 }
5145 else
5146 {
5147 int loopcnt = val >> 1;
5148 for(i=0;i<loopcnt;i++)
5149 {
5150 chain_table[idx++] = 0;
5151 }
5152 }
5153
5154 pnt += skiplen;
5155 } while (pnt != (chain_cmem + chain_clen));
5156 }
5157
5158 chain_table[idx] = indx_pos - vc_start;
5159 chain_table_lengths[pidx] = chain_table[idx] - chain_table[pidx];
5160
5161 for(i=0;i<idx;i++)
5162 {
5163 int32_t v32 = chain_table_lengths[i];
5164 if((v32 < 0) && (!chain_table[i]))
5165 {
5166 v32 = -v32;
5167 v32--;
5168 if(((uint32_t)v32) < i) /* sanity check */
5169 {
5170 chain_table[i] = chain_table[v32];
5171 chain_table_lengths[i] = chain_table_lengths[v32];
5172 }
5173 }
5174 }
5046 fprintf(stderr, "\tindx_pos: %d (%d bytes)\n", (int)indx_pos, (int)chain_clen);
5047 #endif
5048 chain_cmem = malloc(chain_clen);
5049 if(!chain_cmem) goto block_err;
5050 fstReaderFseeko(xc, xc->f, indx_pos, SEEK_SET);
5051 fstFread(chain_cmem, chain_clen, 1, xc->f);
5052
5053 if(vc_maxhandle > vc_maxhandle_largest)
5054 {
5055 free(chain_table);
5056 free(chain_table_lengths);
5057
5058 vc_maxhandle_largest = vc_maxhandle;
5059 chain_table = calloc((vc_maxhandle+1), sizeof(off_t));
5060 chain_table_lengths = calloc((vc_maxhandle+1), sizeof(uint32_t));
5061 }
5062
5063 if(!chain_table || !chain_table_lengths) goto block_err;
5064
5065 pnt = chain_cmem;
5066 idx = 0;
5067 pval = 0;
5068
5069 if(sectype == FST_BL_VCDATA_DYN_ALIAS2)
5070 {
5071 uint32_t prev_alias = 0;
5072
5073 do {
5074 int skiplen;
5075
5076 if(*pnt & 0x01)
5077 {
5078 int64_t shval = fstGetSVarint64(pnt, &skiplen) >> 1;
5079 if(shval > 0)
5080 {
5081 pval = chain_table[idx] = pval + shval;
5082 if(idx) { chain_table_lengths[pidx] = pval - chain_table[pidx]; }
5083 pidx = idx++;
5084 }
5085 else if(shval < 0)
5086 {
5087 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5088 chain_table_lengths[idx] = prev_alias = shval; /* because during this loop iter would give stale data! */
5089 idx++;
5090 }
5091 else
5092 {
5093 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5094 chain_table_lengths[idx] = prev_alias; /* because during this loop iter would give stale data! */
5095 idx++;
5096 }
5097 }
5098 else
5099 {
5100 uint64_t val = fstGetVarint32(pnt, &skiplen);
5101
5102 fstHandle loopcnt = val >> 1;
5103 for(i=0;i<loopcnt;i++)
5104 {
5105 chain_table[idx++] = 0;
5106 }
5107 }
5108
5109 pnt += skiplen;
5110 } while (pnt != (chain_cmem + chain_clen));
5111 }
5112 else
5113 {
5114 do {
5115 int skiplen;
5116 uint64_t val = fstGetVarint32(pnt, &skiplen);
5117
5118 if(!val)
5119 {
5120 pnt += skiplen;
5121 val = fstGetVarint32(pnt, &skiplen);
5122 chain_table[idx] = 0; /* need to explicitly zero as calloc above might not run */
5123 chain_table_lengths[idx] = -val; /* because during this loop iter would give stale data! */
5124 idx++;
5125 }
5126 else
5127 if(val&1)
5128 {
5129 pval = chain_table[idx] = pval + (val >> 1);
5130 if(idx) { chain_table_lengths[pidx] = pval - chain_table[pidx]; }
5131 pidx = idx++;
5132 }
5133 else
5134 {
5135 fstHandle loopcnt = val >> 1;
5136 for(i=0;i<loopcnt;i++)
5137 {
5138 chain_table[idx++] = 0;
5139 }
5140 }
5141
5142 pnt += skiplen;
5143 } while (pnt != (chain_cmem + chain_clen));
5144 }
5145
5146 chain_table[idx] = indx_pos - vc_start;
5147 chain_table_lengths[pidx] = chain_table[idx] - chain_table[pidx];
5148
5149 for(i=0;i<idx;i++)
5150 {
5151 int32_t v32 = chain_table_lengths[i];
5152 if((v32 < 0) && (!chain_table[i]))
5153 {
5154 v32 = -v32;
5155 v32--;
5156 if(((uint32_t)v32) < i) /* sanity check */
5157 {
5158 chain_table[i] = chain_table[v32];
5159 chain_table_lengths[i] = chain_table_lengths[v32];
5160 }
5161 }
5162 }
51755163
51765164 #ifdef FST_DEBUG
5177 fprintf(stderr, "\tdecompressed chain idx len: %"PRIu32"\n", idx);
5178 #endif
5179
5180 mc_mem_len = 16384;
5181 mc_mem = malloc(mc_mem_len); /* buffer for compressed reads */
5182
5183 /* check compressed VC data */
5184 if(idx > xc->maxhandle) idx = xc->maxhandle;
5185 for(i=0;i<idx;i++)
5186 {
5187 if(chain_table[i])
5188 {
5189 int process_idx = i/8;
5190 int process_bit = i&7;
5191
5192 if(xc->process_mask[process_idx]&(1<<process_bit))
5193 {
5194 int rc = Z_OK;
5195 uint32_t val;
5196 uint32_t skiplen;
5197 uint32_t tdelta;
5198
5199 fstReaderFseeko(xc, xc->f, vc_start + chain_table[i], SEEK_SET);
5200 val = fstReaderVarint32WithSkip(xc->f, &skiplen);
5201 if(val)
5202 {
5203 unsigned char *mu = mem_for_traversal + traversal_mem_offs; /* uncomp: dst */
5204 unsigned char *mc; /* comp: src */
5205 unsigned long destlen = val;
5206 unsigned long sourcelen = chain_table_lengths[i];
5207
5208 if(mc_mem_len < chain_table_lengths[i])
5209 {
5210 free(mc_mem);
5211 mc_mem = malloc(mc_mem_len = chain_table_lengths[i]);
5212 }
5213 mc = mc_mem;
5214
5215 fstFread(mc, chain_table_lengths[i], 1, xc->f);
5216
5217 switch(packtype)
5218 {
5219 case '4': rc = (destlen == LZ4_decompress_safe_partial((char *)mc, (char *)mu, sourcelen, destlen, destlen)) ? Z_OK : Z_DATA_ERROR;
5220 break;
5221 case 'F': fastlz_decompress(mc, sourcelen, mu, destlen); /* rc appears unreliable */
5222 break;
5223 default: rc = uncompress(mu, &destlen, mc, sourcelen);
5224 break;
5225 }
5226
5227 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
5228 headptr[i] = traversal_mem_offs;
5229 length_remaining[i] = val;
5230 traversal_mem_offs += val;
5231 }
5232 else
5233 {
5234 int destlen = chain_table_lengths[i] - skiplen;
5235 unsigned char *mu = mem_for_traversal + traversal_mem_offs;
5236 fstFread(mu, destlen, 1, xc->f);
5237 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
5238 headptr[i] = traversal_mem_offs;
5239 length_remaining[i] = destlen;
5240 traversal_mem_offs += destlen;
5241 }
5242
5243 if(rc != Z_OK)
5244 {
5245 printf("\tfac: %d clen: %d (rc=%d)\n", (int)i, (int)val, rc);
5246 exit(255);
5247 }
5248
5249 if(xc->signal_lens[i] == 1)
5250 {
5251 uint32_t vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[i]);
5252 uint32_t shcnt = 2 << (vli & 1);
5253 tdelta = vli >> shcnt;
5254 }
5255 else
5256 {
5257 uint32_t vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[i]);
5258 tdelta = vli >> 1;
5259 }
5260
5261 scatterptr[i] = tc_head[tdelta];
5262 tc_head[tdelta] = i+1;
5263 }
5264 }
5265 }
5266
5267 free(mc_mem); /* there is no usage below for this, no real need to clear out mc_mem or mc_mem_len */
5268
5269 for(i=0;i<tsec_nitems;i++)
5270 {
5271 uint32_t tdelta;
5272 int skiplen, skiplen2;
5273 uint32_t vli;
5274
5275 if(fv)
5276 {
5277 char wx_buf[32];
5278 int wx_len;
5279
5280 if(time_table[i] != previous_time)
5281 {
5282 if(xc->limit_range_valid)
5283 {
5284 if(time_table[i] > xc->limit_range_end)
5285 {
5286 break;
5287 }
5288 }
5289
5290 wx_len = sprintf(wx_buf, "#%"PRIu64"\n", time_table[i]);
5291 fstWritex(xc, wx_buf, wx_len);
5292
5293 if((xc->num_blackouts)&&(cur_blackout != xc->num_blackouts))
5294 {
5295 if(time_table[i] == xc->blackout_times[cur_blackout])
5296 {
5297 wx_len = sprintf(wx_buf, "$dump%s $end\n", (xc->blackout_activity[cur_blackout++]) ? "on" : "off");
5298 fstWritex(xc, wx_buf, wx_len);
5299 }
5300 }
5301 previous_time = time_table[i];
5302 }
5303 }
5304
5305 while(tc_head[i])
5306 {
5307 idx = tc_head[i] - 1;
5308 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5309
5310 if(xc->signal_lens[idx] <= 1)
5311 {
5312 if(xc->signal_lens[idx] == 1)
5313 {
5314 unsigned char val;
5315 if(!(vli & 1))
5316 {
5317 /* tdelta = vli >> 2; */ /* scan-build */
5318 val = ((vli >> 1) & 1) | '0';
5319 }
5320 else
5321 {
5322 /* tdelta = vli >> 4; */ /* scan-build */
5323 val = FST_RCV_STR[((vli >> 1) & 7)];
5324 }
5325
5326 if(value_change_callback)
5327 {
5328 xc->temp_signal_value_buf[0] = val;
5329 xc->temp_signal_value_buf[1] = 0;
5330 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5331 }
5332 else
5333 {
5334 if(fv)
5335 {
5336 char vcd_id[16];
5337 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5338
5339 vcd_id[0] = val;
5340 vcd_id[vcdid_len+1] = '\n';
5341 fstWritex(xc, vcd_id, vcdid_len+2);
5342 }
5343 }
5344 headptr[idx] += skiplen;
5345 length_remaining[idx] -= skiplen;
5346
5347 tc_head[i] = scatterptr[idx];
5348 scatterptr[idx] = 0;
5349
5350 if(length_remaining[idx])
5351 {
5352 int shamt;
5353 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5354 shamt = 2 << (vli & 1);
5355 tdelta = vli >> shamt;
5356
5357 scatterptr[idx] = tc_head[i+tdelta];
5358 tc_head[i+tdelta] = idx+1;
5359 }
5360 }
5361 else
5362 {
5363 unsigned char *vdata;
5364 uint32_t len;
5365
5366 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5367 len = fstGetVarint32(mem_for_traversal + headptr[idx] + skiplen, &skiplen2);
5368 /* tdelta = vli >> 1; */ /* scan-build */
5369 skiplen += skiplen2;
5370 vdata = mem_for_traversal + headptr[idx] + skiplen;
5371
5372 if(!(vli & 1))
5373 {
5374 if(value_change_callback_varlen)
5375 {
5376 value_change_callback_varlen(user_callback_data_pointer, time_table[i], idx+1, vdata, len);
5377 }
5378 else
5379 {
5380 if(fv)
5381 {
5382 char vcd_id[16];
5383 int vcdid_len;
5384
5385 vcd_id[0] = 's';
5386 fstWritex(xc, vcd_id, 1);
5387
5388 vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5389 {
5390 unsigned char *vesc = malloc(len*4 + 1);
5391 int vlen = fstUtilityBinToEsc(vesc, vdata, len);
5392 fstWritex(xc, vesc, vlen);
5393 free(vesc);
5394 }
5395
5396 vcd_id[0] = ' ';
5397 vcd_id[vcdid_len + 1] = '\n';
5398 fstWritex(xc, vcd_id, vcdid_len+2);
5399 }
5400 }
5401 }
5402
5403 skiplen += len;
5404 headptr[idx] += skiplen;
5405 length_remaining[idx] -= skiplen;
5406
5407 tc_head[i] = scatterptr[idx];
5408 scatterptr[idx] = 0;
5409
5410 if(length_remaining[idx])
5411 {
5412 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5413 tdelta = vli >> 1;
5414
5415 scatterptr[idx] = tc_head[i+tdelta];
5416 tc_head[i+tdelta] = idx+1;
5417 }
5418 }
5419 }
5420 else
5421 {
5422 uint32_t len = xc->signal_lens[idx];
5423 unsigned char *vdata;
5424
5425 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5426 /* tdelta = vli >> 1; */ /* scan-build */
5427 vdata = mem_for_traversal + headptr[idx] + skiplen;
5428
5429 if(xc->signal_typs[idx] != FST_VT_VCD_REAL)
5430 {
5431 if(!(vli & 1))
5432 {
5433 int byte = 0;
5434 int bit;
5435 int j;
5436
5437 for(j=0;j<len;j++)
5438 {
5439 unsigned char ch;
5440 byte = j/8;
5441 bit = 7 - (j & 7);
5442 ch = ((vdata[byte] >> bit) & 1) | '0';
5443 xc->temp_signal_value_buf[j] = ch;
5444 }
5445 xc->temp_signal_value_buf[j] = 0;
5446
5447 if(value_change_callback)
5448 {
5449 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5450 }
5451 else
5452 {
5453 if(fv) {
5454 unsigned char ch_bp = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
5455
5456 fstWritex(xc, &ch_bp, 1);
5457 fstWritex(xc, xc->temp_signal_value_buf, len);
5458 }
5459 }
5460
5461 len = byte+1;
5462 }
5463 else
5464 {
5465 if(value_change_callback)
5466 {
5467 memcpy(xc->temp_signal_value_buf, vdata, len);
5468 xc->temp_signal_value_buf[len] = 0;
5469 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5470 }
5471 else
5472 {
5473 if(fv)
5474 {
5475 unsigned char ch_bp = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
5476
5477 fstWritex(xc, &ch_bp, 1);
5478 fstWritex(xc, vdata, len);
5479 }
5480 }
5481 }
5482 }
5483 else
5484 {
5485 double d;
5486 unsigned char *clone_d /*= (unsigned char *)&d */; /* scan-build */
5487 unsigned char buf[8];
5488 unsigned char *srcdata;
5489
5490 if(!(vli & 1)) /* very rare case, but possible */
5491 {
5492 int bit;
5493 int j;
5494
5495 for(j=0;j<8;j++)
5496 {
5497 unsigned char ch;
5498 bit = 7 - (j & 7);
5499 ch = ((vdata[0] >> bit) & 1) | '0';
5500 buf[j] = ch;
5501 }
5502
5503 len = 1;
5504 srcdata = buf;
5505 }
5506 else
5507 {
5508 srcdata = vdata;
5509 }
5510
5511 if(value_change_callback)
5512 {
5513 if(xc->native_doubles_for_cb)
5514 {
5515 if(xc->double_endian_match)
5516 {
5517 clone_d = srcdata;
5518 }
5519 else
5520 {
5521 int j;
5522
5523 clone_d = (unsigned char *)&d;
5524 for(j=0;j<8;j++)
5525 {
5526 clone_d[j] = srcdata[7-j];
5527 }
5528 }
5529 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, clone_d);
5530 }
5531 else
5532 {
5533 clone_d = (unsigned char *)&d;
5534 if(xc->double_endian_match)
5535 {
5536 memcpy(clone_d, srcdata, 8);
5537 }
5538 else
5539 {
5540 int j;
5541
5542 for(j=0;j<8;j++)
5543 {
5544 clone_d[j] = srcdata[7-j];
5545 }
5546 }
5547 sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
5548 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5549 }
5550 }
5551 else
5552 {
5553 if(fv)
5554 {
5555 char wx_buf[32];
5556 int wx_len;
5557
5558 clone_d = (unsigned char *)&d;
5559 if(xc->double_endian_match)
5560 {
5561 memcpy(clone_d, srcdata, 8);
5562 }
5563 else
5564 {
5565 int j;
5566
5567 for(j=0;j<8;j++)
5568 {
5569 clone_d[j] = srcdata[7-j];
5570 }
5571 }
5572
5573 wx_len = sprintf(wx_buf, "r%.16g", d);
5574 fstWritex(xc, wx_buf, wx_len);
5575 }
5576 }
5577 }
5578
5579 if(fv)
5580 {
5581 char vcd_id[16];
5582 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5583 vcd_id[0] = ' ';
5584 vcd_id[vcdid_len+1] = '\n';
5585 fstWritex(xc, vcd_id, vcdid_len+2);
5586 }
5587
5588 skiplen += len;
5589 headptr[idx] += skiplen;
5590 length_remaining[idx] -= skiplen;
5591
5592 tc_head[i] = scatterptr[idx];
5593 scatterptr[idx] = 0;
5594
5595 if(length_remaining[idx])
5596 {
5597 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5598 tdelta = vli >> 1;
5599
5600 scatterptr[idx] = tc_head[i+tdelta];
5601 tc_head[i+tdelta] = idx+1;
5602 }
5603 }
5604 }
5605 }
5165 fprintf(stderr, "\tdecompressed chain idx len: %"PRIu32"\n", idx);
5166 #endif
5167
5168 mc_mem_len = 16384;
5169 mc_mem = malloc(mc_mem_len); /* buffer for compressed reads */
5170
5171 /* check compressed VC data */
5172 if(idx > xc->maxhandle) idx = xc->maxhandle;
5173 for(i=0;i<idx;i++)
5174 {
5175 if(chain_table[i])
5176 {
5177 int process_idx = i/8;
5178 int process_bit = i&7;
5179
5180 if(xc->process_mask[process_idx]&(1<<process_bit))
5181 {
5182 int rc = Z_OK;
5183 uint32_t val;
5184 uint32_t skiplen;
5185 uint32_t tdelta;
5186
5187 fstReaderFseeko(xc, xc->f, vc_start + chain_table[i], SEEK_SET);
5188 val = fstReaderVarint32WithSkip(xc->f, &skiplen);
5189 if(val)
5190 {
5191 unsigned char *mu = mem_for_traversal + traversal_mem_offs; /* uncomp: dst */
5192 unsigned char *mc; /* comp: src */
5193 unsigned long destlen = val;
5194 unsigned long sourcelen = chain_table_lengths[i];
5195
5196 if(mc_mem_len < chain_table_lengths[i])
5197 {
5198 free(mc_mem);
5199 mc_mem = malloc(mc_mem_len = chain_table_lengths[i]);
5200 }
5201 mc = mc_mem;
5202
5203 fstFread(mc, chain_table_lengths[i], 1, xc->f);
5204
5205 switch(packtype)
5206 {
5207 case '4': rc = (destlen == (unsigned long)LZ4_decompress_safe_partial((char *)mc, (char *)mu, sourcelen, destlen, destlen)) ? Z_OK : Z_DATA_ERROR;
5208 break;
5209 case 'F': fastlz_decompress(mc, sourcelen, mu, destlen); /* rc appears unreliable */
5210 break;
5211 default: rc = uncompress(mu, &destlen, mc, sourcelen);
5212 break;
5213 }
5214
5215 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
5216 headptr[i] = traversal_mem_offs;
5217 length_remaining[i] = val;
5218 traversal_mem_offs += val;
5219 }
5220 else
5221 {
5222 int destlen = chain_table_lengths[i] - skiplen;
5223 unsigned char *mu = mem_for_traversal + traversal_mem_offs;
5224 fstFread(mu, destlen, 1, xc->f);
5225 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
5226 headptr[i] = traversal_mem_offs;
5227 length_remaining[i] = destlen;
5228 traversal_mem_offs += destlen;
5229 }
5230
5231 if(rc != Z_OK)
5232 {
5233 printf("\tfac: %d clen: %d (rc=%d)\n", (int)i, (int)val, rc);
5234 exit(255);
5235 }
5236
5237 if(xc->signal_lens[i] == 1)
5238 {
5239 uint32_t vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[i]);
5240 uint32_t shcnt = 2 << (vli & 1);
5241 tdelta = vli >> shcnt;
5242 }
5243 else
5244 {
5245 uint32_t vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[i]);
5246 tdelta = vli >> 1;
5247 }
5248
5249 scatterptr[i] = tc_head[tdelta];
5250 tc_head[tdelta] = i+1;
5251 }
5252 }
5253 }
5254
5255 free(mc_mem); /* there is no usage below for this, no real need to clear out mc_mem or mc_mem_len */
5256
5257 for(i=0;i<tsec_nitems;i++)
5258 {
5259 uint32_t tdelta;
5260 int skiplen, skiplen2;
5261 uint32_t vli;
5262
5263 if(fv)
5264 {
5265 char wx_buf[32];
5266 int wx_len;
5267
5268 if(time_table[i] != previous_time)
5269 {
5270 if(xc->limit_range_valid)
5271 {
5272 if(time_table[i] > xc->limit_range_end)
5273 {
5274 break;
5275 }
5276 }
5277
5278 wx_len = sprintf(wx_buf, "#%"PRIu64"\n", time_table[i]);
5279 fstWritex(xc, wx_buf, wx_len);
5280
5281 if((xc->num_blackouts)&&(cur_blackout != xc->num_blackouts))
5282 {
5283 if(time_table[i] == xc->blackout_times[cur_blackout])
5284 {
5285 wx_len = sprintf(wx_buf, "$dump%s $end\n", (xc->blackout_activity[cur_blackout++]) ? "on" : "off");
5286 fstWritex(xc, wx_buf, wx_len);
5287 }
5288 }
5289 previous_time = time_table[i];
5290 }
5291 }
5292
5293 while(tc_head[i])
5294 {
5295 idx = tc_head[i] - 1;
5296 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5297
5298 if(xc->signal_lens[idx] <= 1)
5299 {
5300 if(xc->signal_lens[idx] == 1)
5301 {
5302 unsigned char val;
5303 if(!(vli & 1))
5304 {
5305 /* tdelta = vli >> 2; */ /* scan-build */
5306 val = ((vli >> 1) & 1) | '0';
5307 }
5308 else
5309 {
5310 /* tdelta = vli >> 4; */ /* scan-build */
5311 val = FST_RCV_STR[((vli >> 1) & 7)];
5312 }
5313
5314 if(value_change_callback)
5315 {
5316 xc->temp_signal_value_buf[0] = val;
5317 xc->temp_signal_value_buf[1] = 0;
5318 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5319 }
5320 else
5321 {
5322 if(fv)
5323 {
5324 char vcd_id[16];
5325 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5326
5327 vcd_id[0] = val;
5328 vcd_id[vcdid_len+1] = '\n';
5329 fstWritex(xc, vcd_id, vcdid_len+2);
5330 }
5331 }
5332 headptr[idx] += skiplen;
5333 length_remaining[idx] -= skiplen;
5334
5335 tc_head[i] = scatterptr[idx];
5336 scatterptr[idx] = 0;
5337
5338 if(length_remaining[idx])
5339 {
5340 int shamt;
5341 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5342 shamt = 2 << (vli & 1);
5343 tdelta = vli >> shamt;
5344
5345 scatterptr[idx] = tc_head[i+tdelta];
5346 tc_head[i+tdelta] = idx+1;
5347 }
5348 }
5349 else
5350 {
5351 unsigned char *vdata;
5352 uint32_t len;
5353
5354 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5355 len = fstGetVarint32(mem_for_traversal + headptr[idx] + skiplen, &skiplen2);
5356 /* tdelta = vli >> 1; */ /* scan-build */
5357 skiplen += skiplen2;
5358 vdata = mem_for_traversal + headptr[idx] + skiplen;
5359
5360 if(!(vli & 1))
5361 {
5362 if(value_change_callback_varlen)
5363 {
5364 value_change_callback_varlen(user_callback_data_pointer, time_table[i], idx+1, vdata, len);
5365 }
5366 else
5367 {
5368 if(fv)
5369 {
5370 char vcd_id[16];
5371 int vcdid_len;
5372
5373 vcd_id[0] = 's';
5374 fstWritex(xc, vcd_id, 1);
5375
5376 vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5377 {
5378 unsigned char *vesc = malloc(len*4 + 1);
5379 int vlen = fstUtilityBinToEsc(vesc, vdata, len);
5380 fstWritex(xc, vesc, vlen);
5381 free(vesc);
5382 }
5383
5384 vcd_id[0] = ' ';
5385 vcd_id[vcdid_len + 1] = '\n';
5386 fstWritex(xc, vcd_id, vcdid_len+2);
5387 }
5388 }
5389 }
5390
5391 skiplen += len;
5392 headptr[idx] += skiplen;
5393 length_remaining[idx] -= skiplen;
5394
5395 tc_head[i] = scatterptr[idx];
5396 scatterptr[idx] = 0;
5397
5398 if(length_remaining[idx])
5399 {
5400 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5401 tdelta = vli >> 1;
5402
5403 scatterptr[idx] = tc_head[i+tdelta];
5404 tc_head[i+tdelta] = idx+1;
5405 }
5406 }
5407 }
5408 else
5409 {
5410 uint32_t len = xc->signal_lens[idx];
5411 unsigned char *vdata;
5412
5413 vli = fstGetVarint32(mem_for_traversal + headptr[idx], &skiplen);
5414 /* tdelta = vli >> 1; */ /* scan-build */
5415 vdata = mem_for_traversal + headptr[idx] + skiplen;
5416
5417 if(xc->signal_typs[idx] != FST_VT_VCD_REAL)
5418 {
5419 if(!(vli & 1))
5420 {
5421 int byte = 0;
5422 int bit;
5423 unsigned int j;
5424
5425 for(j=0;j<len;j++)
5426 {
5427 unsigned char ch;
5428 byte = j/8;
5429 bit = 7 - (j & 7);
5430 ch = ((vdata[byte] >> bit) & 1) | '0';
5431 xc->temp_signal_value_buf[j] = ch;
5432 }
5433 xc->temp_signal_value_buf[j] = 0;
5434
5435 if(value_change_callback)
5436 {
5437 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5438 }
5439 else
5440 {
5441 if(fv) {
5442 unsigned char ch_bp = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
5443
5444 fstWritex(xc, &ch_bp, 1);
5445 fstWritex(xc, xc->temp_signal_value_buf, len);
5446 }
5447 }
5448
5449 len = byte+1;
5450 }
5451 else
5452 {
5453 if(value_change_callback)
5454 {
5455 memcpy(xc->temp_signal_value_buf, vdata, len);
5456 xc->temp_signal_value_buf[len] = 0;
5457 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5458 }
5459 else
5460 {
5461 if(fv)
5462 {
5463 unsigned char ch_bp = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
5464
5465 fstWritex(xc, &ch_bp, 1);
5466 fstWritex(xc, vdata, len);
5467 }
5468 }
5469 }
5470 }
5471 else
5472 {
5473 double d;
5474 unsigned char *clone_d /*= (unsigned char *)&d */; /* scan-build */
5475 unsigned char buf[8];
5476 unsigned char *srcdata;
5477
5478 if(!(vli & 1)) /* very rare case, but possible */
5479 {
5480 int bit;
5481 int j;
5482
5483 for(j=0;j<8;j++)
5484 {
5485 unsigned char ch;
5486 bit = 7 - (j & 7);
5487 ch = ((vdata[0] >> bit) & 1) | '0';
5488 buf[j] = ch;
5489 }
5490
5491 len = 1;
5492 srcdata = buf;
5493 }
5494 else
5495 {
5496 srcdata = vdata;
5497 }
5498
5499 if(value_change_callback)
5500 {
5501 if(xc->native_doubles_for_cb)
5502 {
5503 if(xc->double_endian_match)
5504 {
5505 clone_d = srcdata;
5506 }
5507 else
5508 {
5509 int j;
5510
5511 clone_d = (unsigned char *)&d;
5512 for(j=0;j<8;j++)
5513 {
5514 clone_d[j] = srcdata[7-j];
5515 }
5516 }
5517 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, clone_d);
5518 }
5519 else
5520 {
5521 clone_d = (unsigned char *)&d;
5522 if(xc->double_endian_match)
5523 {
5524 memcpy(clone_d, srcdata, 8);
5525 }
5526 else
5527 {
5528 int j;
5529
5530 for(j=0;j<8;j++)
5531 {
5532 clone_d[j] = srcdata[7-j];
5533 }
5534 }
5535 sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
5536 value_change_callback(user_callback_data_pointer, time_table[i], idx+1, xc->temp_signal_value_buf);
5537 }
5538 }
5539 else
5540 {
5541 if(fv)
5542 {
5543 char wx_buf[32];
5544 int wx_len;
5545
5546 clone_d = (unsigned char *)&d;
5547 if(xc->double_endian_match)
5548 {
5549 memcpy(clone_d, srcdata, 8);
5550 }
5551 else
5552 {
5553 int j;
5554
5555 for(j=0;j<8;j++)
5556 {
5557 clone_d[j] = srcdata[7-j];
5558 }
5559 }
5560
5561 wx_len = sprintf(wx_buf, "r%.16g", d);
5562 fstWritex(xc, wx_buf, wx_len);
5563 }
5564 }
5565 }
5566
5567 if(fv)
5568 {
5569 char vcd_id[16];
5570 int vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
5571 vcd_id[0] = ' ';
5572 vcd_id[vcdid_len+1] = '\n';
5573 fstWritex(xc, vcd_id, vcdid_len+2);
5574 }
5575
5576 skiplen += len;
5577 headptr[idx] += skiplen;
5578 length_remaining[idx] -= skiplen;
5579
5580 tc_head[i] = scatterptr[idx];
5581 scatterptr[idx] = 0;
5582
5583 if(length_remaining[idx])
5584 {
5585 vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
5586 tdelta = vli >> 1;
5587
5588 scatterptr[idx] = tc_head[i+tdelta];
5589 tc_head[i+tdelta] = idx+1;
5590 }
5591 }
5592 }
5593 }
56065594
56075595 block_err:
5608 free(tc_head);
5609 free(chain_cmem);
5610 free(mem_for_traversal); mem_for_traversal = NULL;
5611
5612 secnum++;
5613 if(secnum == xc->vc_section_count) break; /* in case file is growing, keep with original block count */
5614 blkpos += seclen;
5615 }
5596 free(tc_head);
5597 free(chain_cmem);
5598 free(mem_for_traversal); mem_for_traversal = NULL;
5599
5600 secnum++;
5601 if(secnum == xc->vc_section_count) break; /* in case file is growing, keep with original block count */
5602 blkpos += seclen;
5603 }
56165604
56175605 if(mem_for_traversal) free(mem_for_traversal); /* scan-build */
56185606 free(length_remaining);
56205608 free(scatterptr);
56215609
56225610 if(chain_table) free(chain_table);
5623 if(chain_table_lengths) free(chain_table_lengths);
5611 if(chain_table_lengths) free(chain_table_lengths);
56245612
56255613 free(time_table);
56265614
56275615 #ifndef FST_WRITEX_DISABLE
56285616 if(fv)
5629 {
5630 fstWritex(xc, NULL, 0);
5631 }
5617 {
5618 fstWritex(xc, NULL, 0);
5619 }
56325620 #endif
56335621
56345622 return(1);
56405628 static char *fstExtractRvatDataFromFrame(struct fstReaderContext *xc, fstHandle facidx, char *buf)
56415629 {
56425630 if(facidx >= xc->rvat_frame_maxhandle)
5643 {
5644 return(NULL);
5645 }
5631 {
5632 return(NULL);
5633 }
56465634
56475635 if(xc->signal_lens[facidx] == 1)
5648 {
5649 buf[0] = (char)xc->rvat_frame_data[xc->rvat_sig_offs[facidx]];
5650 buf[1] = 0;
5651 }
5652 else
5653 {
5654 if(xc->signal_typs[facidx] != FST_VT_VCD_REAL)
5655 {
5656 memcpy(buf, xc->rvat_frame_data + xc->rvat_sig_offs[facidx], xc->signal_lens[facidx]);
5657 buf[xc->signal_lens[facidx]] = 0;
5658 }
5659 else
5660 {
5661 double d;
5662 unsigned char *clone_d = (unsigned char *)&d;
5663 unsigned char *srcdata = xc->rvat_frame_data + xc->rvat_sig_offs[facidx];
5664
5665 if(xc->double_endian_match)
5666 {
5667 memcpy(clone_d, srcdata, 8);
5668 }
5669 else
5670 {
5671 int j;
5672
5673 for(j=0;j<8;j++)
5674 {
5675 clone_d[j] = srcdata[7-j];
5676 }
5677 }
5678
5679 sprintf((char *)buf, "%.16g", d);
5680 }
5681 }
5636 {
5637 buf[0] = (char)xc->rvat_frame_data[xc->rvat_sig_offs[facidx]];
5638 buf[1] = 0;
5639 }
5640 else
5641 {
5642 if(xc->signal_typs[facidx] != FST_VT_VCD_REAL)
5643 {
5644 memcpy(buf, xc->rvat_frame_data + xc->rvat_sig_offs[facidx], xc->signal_lens[facidx]);
5645 buf[xc->signal_lens[facidx]] = 0;
5646 }
5647 else
5648 {
5649 double d;
5650 unsigned char *clone_d = (unsigned char *)&d;
5651 unsigned char *srcdata = xc->rvat_frame_data + xc->rvat_sig_offs[facidx];
5652
5653 if(xc->double_endian_match)
5654 {
5655 memcpy(clone_d, srcdata, 8);
5656 }
5657 else
5658 {
5659 int j;
5660
5661 for(j=0;j<8;j++)
5662 {
5663 clone_d[j] = srcdata[7-j];
5664 }
5665 }
5666
5667 sprintf((char *)buf, "%.16g", d);
5668 }
5669 }
56825670
56835671 return(buf);
56845672 }
56905678 off_t blkpos = 0, prev_blkpos;
56915679 uint64_t beg_tim, end_tim, beg_tim2, end_tim2;
56925680 int sectype;
5693 int secnum = 0;
5681 unsigned int secnum = 0;
56945682 uint64_t seclen;
56955683 uint64_t tsec_uclen = 0, tsec_clen = 0;
56965684 uint64_t tsec_nitems;
57065694 uint64_t pval;
57075695
57085696 if((!xc) || (!facidx) || (facidx > xc->maxhandle) || (!buf) || (!xc->signal_lens[facidx-1]))
5709 {
5710 return(NULL);
5711 }
5697 {
5698 return(NULL);
5699 }
57125700
57135701 if(!xc->rvat_sig_offs)
5714 {
5715 uint32_t cur_offs = 0;
5716
5717 xc->rvat_sig_offs = calloc(xc->maxhandle, sizeof(uint32_t));
5718 for(i=0;i<xc->maxhandle;i++)
5719 {
5720 xc->rvat_sig_offs[i] = cur_offs;
5721 cur_offs += xc->signal_lens[i];
5722 }
5723 }
5702 {
5703 uint32_t cur_offs = 0;
5704
5705 xc->rvat_sig_offs = calloc(xc->maxhandle, sizeof(uint32_t));
5706 for(i=0;i<xc->maxhandle;i++)
5707 {
5708 xc->rvat_sig_offs[i] = cur_offs;
5709 cur_offs += xc->signal_lens[i];
5710 }
5711 }
57245712
57255713 if(xc->rvat_data_valid)
5726 {
5727 if((xc->rvat_beg_tim <= tim) && (tim <= xc->rvat_end_tim))
5728 {
5729 goto process_value;
5730 }
5731
5732 fstReaderDeallocateRvatData(xc);
5733 }
5714 {
5715 if((xc->rvat_beg_tim <= tim) && (tim <= xc->rvat_end_tim))
5716 {
5717 goto process_value;
5718 }
5719
5720 fstReaderDeallocateRvatData(xc);
5721 }
57345722
57355723 xc->rvat_chain_pos_valid = 0;
57365724
57375725 for(;;)
5738 {
5739 fstReaderFseeko(xc, xc->f, (prev_blkpos = blkpos), SEEK_SET);
5740
5741 sectype = fgetc(xc->f);
5742 seclen = fstReaderUint64(xc->f);
5743
5744 if((sectype == EOF) || (sectype == FST_BL_SKIP) || (!seclen))
5745 {
5746 return(NULL); /* if this loop exits on break, it's successful */
5747 }
5748
5749 blkpos++;
5750 if((sectype != FST_BL_VCDATA) && (sectype != FST_BL_VCDATA_DYN_ALIAS) && (sectype != FST_BL_VCDATA_DYN_ALIAS2))
5751 {
5752 blkpos += seclen;
5753 continue;
5754 }
5755
5756 beg_tim = fstReaderUint64(xc->f);
5757 end_tim = fstReaderUint64(xc->f);
5758
5759 if((beg_tim <= tim) && (tim <= end_tim))
5760 {
5761 if((tim == end_tim) && (tim != xc->end_time))
5762 {
5763 off_t cached_pos = ftello(xc->f);
5764 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
5765
5766 sectype = fgetc(xc->f);
5767 seclen = fstReaderUint64(xc->f);
5768
5769 beg_tim2 = fstReaderUint64(xc->f);
5770 end_tim2 = fstReaderUint64(xc->f);
5771
5772 if(((sectype != FST_BL_VCDATA)&&(sectype != FST_BL_VCDATA_DYN_ALIAS)&&(sectype != FST_BL_VCDATA_DYN_ALIAS2)) || (!seclen) || (beg_tim2 != tim))
5773 {
5774 blkpos = prev_blkpos;
5775 break;
5776 }
5777 beg_tim = beg_tim2;
5778 end_tim = end_tim2;
5779 fstReaderFseeko(xc, xc->f, cached_pos, SEEK_SET);
5780 }
5781 break;
5782 }
5783
5784 blkpos += seclen;
5785 secnum++;
5786 }
5726 {
5727 fstReaderFseeko(xc, xc->f, (prev_blkpos = blkpos), SEEK_SET);
5728
5729 sectype = fgetc(xc->f);
5730 seclen = fstReaderUint64(xc->f);
5731
5732 if((sectype == EOF) || (sectype == FST_BL_SKIP) || (!seclen))
5733 {
5734 return(NULL); /* if this loop exits on break, it's successful */
5735 }
5736
5737 blkpos++;
5738 if((sectype != FST_BL_VCDATA) && (sectype != FST_BL_VCDATA_DYN_ALIAS) && (sectype != FST_BL_VCDATA_DYN_ALIAS2))
5739 {
5740 blkpos += seclen;
5741 continue;
5742 }
5743
5744 beg_tim = fstReaderUint64(xc->f);
5745 end_tim = fstReaderUint64(xc->f);
5746
5747 if((beg_tim <= tim) && (tim <= end_tim))
5748 {
5749 if((tim == end_tim) && (tim != xc->end_time))
5750 {
5751 off_t cached_pos = ftello(xc->f);
5752 fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
5753
5754 sectype = fgetc(xc->f);
5755 seclen = fstReaderUint64(xc->f);
5756
5757 beg_tim2 = fstReaderUint64(xc->f);
5758 end_tim2 = fstReaderUint64(xc->f);
5759
5760 if(((sectype != FST_BL_VCDATA)&&(sectype != FST_BL_VCDATA_DYN_ALIAS)&&(sectype != FST_BL_VCDATA_DYN_ALIAS2)) || (!seclen) || (beg_tim2 != tim))
5761 {
5762 blkpos = prev_blkpos;
5763 break;
5764 }
5765 beg_tim = beg_tim2;
5766 end_tim = end_tim2;
5767 fstReaderFseeko(xc, xc->f, cached_pos, SEEK_SET);
5768 }
5769 break;
5770 }
5771
5772 blkpos += seclen;
5773 secnum++;
5774 }
57875775
57885776 xc->rvat_beg_tim = beg_tim;
57895777 xc->rvat_end_tim = end_tim;
57915779 #ifdef FST_DEBUG
57925780 mem_required_for_traversal =
57935781 #endif
5794 fstReaderUint64(xc->f);
5782 fstReaderUint64(xc->f);
57955783
57965784 #ifdef FST_DEBUG
5797 fprintf(stderr, "rvat sec: %d seclen: %d begtim: %d endtim: %d\n",
5798 secnum, (int)seclen, (int)beg_tim, (int)end_tim);
5785 fprintf(stderr, "rvat sec: %u seclen: %d begtim: %d endtim: %d\n",
5786 secnum, (int)seclen, (int)beg_tim, (int)end_tim);
57995787 fprintf(stderr, "\tmem_required_for_traversal: %d\n", (int)mem_required_for_traversal);
58005788 #endif
58015789
58085796 int rc;
58095797 unsigned char *tpnt;
58105798 uint64_t tpval;
5811 int ti;
5799 unsigned int ti;
58125800
58135801 fstReaderFseeko(xc, xc->f, blkpos + seclen - 24, SEEK_SET);
58145802 tsec_uclen = fstReaderUint64(xc->f);
58165804 tsec_nitems = fstReaderUint64(xc->f);
58175805 #ifdef FST_DEBUG
58185806 fprintf(stderr, "\ttime section unc: %d, com: %d (%d items)\n",
5819 (int)tsec_uclen, (int)tsec_clen, (int)tsec_nitems);
5807 (int)tsec_uclen, (int)tsec_clen, (int)tsec_nitems);
58205808 #endif
58215809 ucdata = malloc(tsec_uclen);
58225810 destlen = tsec_uclen;
58245812
58255813 fstReaderFseeko(xc, xc->f, -24 - ((off_t)tsec_clen), SEEK_CUR);
58265814 if(tsec_uclen != tsec_clen)
5827 {
5828 cdata = malloc(tsec_clen);
5829 fstFread(cdata, tsec_clen, 1, xc->f);
5830
5831 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
5832
5833 if(rc != Z_OK)
5834 {
5835 printf("tsec uncompress rc = %d\n", rc);
5836 exit(255);
5837 }
5838
5839 free(cdata);
5840 }
5841 else
5842 {
5843 fstFread(ucdata, tsec_uclen, 1, xc->f);
5844 }
5815 {
5816 cdata = malloc(tsec_clen);
5817 fstFread(cdata, tsec_clen, 1, xc->f);
5818
5819 rc = uncompress(ucdata, &destlen, cdata, sourcelen);
5820
5821 if(rc != Z_OK)
5822 {
5823 printf("tsec uncompress rc = %d\n", rc);
5824 exit(255);
5825 }
5826
5827 free(cdata);
5828 }
5829 else
5830 {
5831 fstFread(ucdata, tsec_uclen, 1, xc->f);
5832 }
58455833
58465834 xc->rvat_time_table = calloc(tsec_nitems, sizeof(uint64_t));
58475835 tpnt = ucdata;
58485836 tpval = 0;
58495837 for(ti=0;ti<tsec_nitems;ti++)
5850 {
5851 int skiplen;
5852 uint64_t val = fstGetVarint64(tpnt, &skiplen);
5853 tpval = xc->rvat_time_table[ti] = tpval + val;
5854 tpnt += skiplen;
5855 }
5838 {
5839 int skiplen;
5840 uint64_t val = fstGetVarint64(tpnt, &skiplen);
5841 tpval = xc->rvat_time_table[ti] = tpval + val;
5842 tpnt += skiplen;
5843 }
58565844
58575845 free(ucdata);
58585846 }
58655853 xc->rvat_frame_data = malloc(frame_uclen);
58665854
58675855 if(frame_uclen == frame_clen)
5868 {
5869 fstFread(xc->rvat_frame_data, frame_uclen, 1, xc->f);
5870 }
5871 else
5872 {
5873 unsigned char *mc = malloc(frame_clen);
5874 int rc;
5875
5876 unsigned long destlen = frame_uclen;
5877 unsigned long sourcelen = frame_clen;
5878
5879 fstFread(mc, sourcelen, 1, xc->f);
5880 rc = uncompress(xc->rvat_frame_data, &destlen, mc, sourcelen);
5881 if(rc != Z_OK)
5882 {
5883 printf("decompress rc: %d\n", rc);
5884 exit(255);
5885 }
5886 free(mc);
5887 }
5856 {
5857 fstFread(xc->rvat_frame_data, frame_uclen, 1, xc->f);
5858 }
5859 else
5860 {
5861 unsigned char *mc = malloc(frame_clen);
5862 int rc;
5863
5864 unsigned long destlen = frame_uclen;
5865 unsigned long sourcelen = frame_clen;
5866
5867 fstFread(mc, sourcelen, 1, xc->f);
5868 rc = uncompress(xc->rvat_frame_data, &destlen, mc, sourcelen);
5869 if(rc != Z_OK)
5870 {
5871 printf("decompress rc: %d\n", rc);
5872 exit(255);
5873 }
5874 free(mc);
5875 }
58885876
58895877 xc->rvat_vc_maxhandle = fstReaderVarint64(xc->f);
5890 xc->rvat_vc_start = ftello(xc->f); /* points to '!' character */
5878 xc->rvat_vc_start = ftello(xc->f); /* points to '!' character */
58915879
58925880 #ifdef FST_DEBUG
58935881 fprintf(stderr, "\tframe_uclen: %d, frame_clen: %d, frame_maxhandle: %d\n",
5894 (int)frame_uclen, (int)frame_clen, (int)xc->rvat_frame_maxhandle);
5882 (int)frame_uclen, (int)frame_clen, (int)xc->rvat_frame_maxhandle);
58955883 fprintf(stderr, "\tvc_maxhandle: %d\n", (int)xc->rvat_vc_maxhandle);
58965884 #endif
58975885
59135901 idx = 0;
59145902 pval = 0;
59155903 do
5916 {
5917 int skiplen;
5918 uint64_t val = fstGetVarint32(pnt, &skiplen);
5904 {
5905 int skiplen;
5906 uint64_t val = fstGetVarint32(pnt, &skiplen);
59195907
59205908 if(!val)
5921 {
5922 pnt += skiplen;
5923 val = fstGetVarint32(pnt, &skiplen);
5924 xc->rvat_chain_table[idx] = 0;
5909 {
5910 pnt += skiplen;
5911 val = fstGetVarint32(pnt, &skiplen);
5912 xc->rvat_chain_table[idx] = 0;
59255913 xc->rvat_chain_table_lengths[idx] = -val;
59265914 idx++;
59275915 }
5928 else
5929 if(val&1)
5930 {
5931 pval = xc->rvat_chain_table[idx] = pval + (val >> 1);
5932 if(idx) { xc->rvat_chain_table_lengths[pidx] = pval - xc->rvat_chain_table[pidx]; }
5933 pidx = idx++;
5934 }
5935 else
5936 {
5937 int loopcnt = val >> 1;
5938 for(i=0;i<loopcnt;i++)
5939 {
5940 xc->rvat_chain_table[idx++] = 0;
5941 }
5942 }
5943
5944 pnt += skiplen;
5945 } while (pnt != (chain_cmem + chain_clen));
5916 else
5917 if(val&1)
5918 {
5919 pval = xc->rvat_chain_table[idx] = pval + (val >> 1);
5920 if(idx) { xc->rvat_chain_table_lengths[pidx] = pval - xc->rvat_chain_table[pidx]; }
5921 pidx = idx++;
5922 }
5923 else
5924 {
5925 fstHandle loopcnt = val >> 1;
5926 for(i=0;i<loopcnt;i++)
5927 {
5928 xc->rvat_chain_table[idx++] = 0;
5929 }
5930 }
5931
5932 pnt += skiplen;
5933 } while (pnt != (chain_cmem + chain_clen));
59465934
59475935 free(chain_cmem);
59485936 xc->rvat_chain_table[idx] = indx_pos - xc->rvat_vc_start;
59495937 xc->rvat_chain_table_lengths[pidx] = xc->rvat_chain_table[idx] - xc->rvat_chain_table[pidx];
59505938
59515939 for(i=0;i<idx;i++)
5952 {
5940 {
59535941 int32_t v32 = xc->rvat_chain_table_lengths[i];
5954 if((v32 < 0) && (!xc->rvat_chain_table[i]))
5955 {
5942 if((v32 < 0) && (!xc->rvat_chain_table[i]))
5943 {
59565944 v32 = -v32;
5957 v32--;
5958 if(((uint32_t)v32) < i) /* sanity check */
5959 {
5960 xc->rvat_chain_table[i] = xc->rvat_chain_table[v32];
5961 xc->rvat_chain_table_lengths[i] = xc->rvat_chain_table_lengths[v32];
5962 }
5963 }
5964 }
5945 v32--;
5946 if(((uint32_t)v32) < i) /* sanity check */
5947 {
5948 xc->rvat_chain_table[i] = xc->rvat_chain_table[v32];
5949 xc->rvat_chain_table_lengths[i] = xc->rvat_chain_table_lengths[v32];
5950 }
5951 }
5952 }
59655953
59665954 #ifdef FST_DEBUG
59675955 fprintf(stderr, "\tdecompressed chain idx len: %"PRIu32"\n", idx);
59725960 /* all data at this point is loaded or resident in fst cache, process and return appropriate value */
59735961 process_value:
59745962 if(facidx > xc->rvat_vc_maxhandle)
5975 {
5976 return(NULL);
5977 }
5963 {
5964 return(NULL);
5965 }
59785966
59795967 facidx--; /* scale down for array which starts at zero */
59805968
59815969
59825970 if(((tim == xc->rvat_beg_tim)&&(!xc->rvat_chain_table[facidx])) || (!xc->rvat_chain_table[facidx]))
5983 {
5984 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
5985 }
5971 {
5972 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
5973 }
59865974
59875975 if(facidx != xc->rvat_chain_facidx)
5988 {
5989 if(xc->rvat_chain_mem)
5990 {
5991 free(xc->rvat_chain_mem);
5992 xc->rvat_chain_mem = NULL;
5993
5994 xc->rvat_chain_pos_valid = 0;
5995 }
5996 }
5976 {
5977 if(xc->rvat_chain_mem)
5978 {
5979 free(xc->rvat_chain_mem);
5980 xc->rvat_chain_mem = NULL;
5981
5982 xc->rvat_chain_pos_valid = 0;
5983 }
5984 }
59975985
59985986 if(!xc->rvat_chain_mem)
5999 {
6000 uint32_t skiplen;
6001 fstReaderFseeko(xc, xc->f, xc->rvat_vc_start + xc->rvat_chain_table[facidx], SEEK_SET);
6002 xc->rvat_chain_len = fstReaderVarint32WithSkip(xc->f, &skiplen);
6003 if(xc->rvat_chain_len)
6004 {
6005 unsigned char *mu = malloc(xc->rvat_chain_len);
6006 unsigned char *mc = malloc(xc->rvat_chain_table_lengths[facidx]);
6007 unsigned long destlen = xc->rvat_chain_len;
6008 unsigned long sourcelen = xc->rvat_chain_table_lengths[facidx];
6009 int rc;
6010
6011 fstFread(mc, xc->rvat_chain_table_lengths[facidx], 1, xc->f);
6012 rc = uncompress(mu, &destlen, mc, sourcelen);
6013 free(mc);
6014
6015 if(rc != Z_OK)
6016 {
6017 printf("\tclen: %d (rc=%d)\n", (int)xc->rvat_chain_len, rc);
6018 exit(255);
6019 }
6020
6021 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
6022 xc->rvat_chain_mem = mu;
6023 }
6024 else
6025 {
6026 int destlen = xc->rvat_chain_table_lengths[facidx] - skiplen;
6027 unsigned char *mu = malloc(xc->rvat_chain_len = destlen);
6028 fstFread(mu, destlen, 1, xc->f);
6029 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
6030 xc->rvat_chain_mem = mu;
6031 }
6032
6033 xc->rvat_chain_facidx = facidx;
6034 }
5987 {
5988 uint32_t skiplen;
5989 fstReaderFseeko(xc, xc->f, xc->rvat_vc_start + xc->rvat_chain_table[facidx], SEEK_SET);
5990 xc->rvat_chain_len = fstReaderVarint32WithSkip(xc->f, &skiplen);
5991 if(xc->rvat_chain_len)
5992 {
5993 unsigned char *mu = malloc(xc->rvat_chain_len);
5994 unsigned char *mc = malloc(xc->rvat_chain_table_lengths[facidx]);
5995 unsigned long destlen = xc->rvat_chain_len;
5996 unsigned long sourcelen = xc->rvat_chain_table_lengths[facidx];
5997 int rc;
5998
5999 fstFread(mc, xc->rvat_chain_table_lengths[facidx], 1, xc->f);
6000 rc = uncompress(mu, &destlen, mc, sourcelen);
6001 free(mc);
6002
6003 if(rc != Z_OK)
6004 {
6005 printf("\tclen: %d (rc=%d)\n", (int)xc->rvat_chain_len, rc);
6006 exit(255);
6007 }
6008
6009 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
6010 xc->rvat_chain_mem = mu;
6011 }
6012 else
6013 {
6014 int destlen = xc->rvat_chain_table_lengths[facidx] - skiplen;
6015 unsigned char *mu = malloc(xc->rvat_chain_len = destlen);
6016 fstFread(mu, destlen, 1, xc->f);
6017 /* data to process is for(j=0;j<destlen;j++) in mu[j] */
6018 xc->rvat_chain_mem = mu;
6019 }
6020
6021 xc->rvat_chain_facidx = facidx;
6022 }
60356023
60366024 /* process value chain here */
60376025
60396027 uint32_t tidx = 0, ptidx = 0;
60406028 uint32_t tdelta;
60416029 int skiplen;
6042 int iprev = xc->rvat_chain_len;
6030 unsigned int iprev = xc->rvat_chain_len;
60436031 uint32_t pvli = 0;
60446032 int pskip = 0;
60456033
60466034 if((xc->rvat_chain_pos_valid)&&(tim >= xc->rvat_chain_pos_time))
6047 {
6048 i = xc->rvat_chain_pos_idx;
6049 tidx = xc->rvat_chain_pos_tidx;
6050 }
6051 else
6052 {
6053 i = 0;
6054 tidx = 0;
6055 xc->rvat_chain_pos_time = xc->rvat_beg_tim;
6056 }
6035 {
6036 i = xc->rvat_chain_pos_idx;
6037 tidx = xc->rvat_chain_pos_tidx;
6038 }
6039 else
6040 {
6041 i = 0;
6042 tidx = 0;
6043 xc->rvat_chain_pos_time = xc->rvat_beg_tim;
6044 }
60576045
60586046 if(xc->signal_lens[facidx] == 1)
6059 {
6060 while(i<xc->rvat_chain_len)
6061 {
6062 uint32_t vli = fstGetVarint32(xc->rvat_chain_mem + i, &skiplen);
6063 uint32_t shcnt = 2 << (vli & 1);
6064 tdelta = vli >> shcnt;
6065
6066 if(xc->rvat_time_table[tidx + tdelta] <= tim)
6067 {
6068 iprev = i;
6069 pvli = vli;
6070 ptidx = tidx;
6071 /* pskip = skiplen; */ /* scan-build */
6072
6073 tidx += tdelta;
6074 i+=skiplen;
6075 }
6076 else
6077 {
6078 break;
6079 }
6080 }
6081 if(iprev != xc->rvat_chain_len)
6082 {
6083 xc->rvat_chain_pos_tidx = ptidx;
6084 xc->rvat_chain_pos_idx = iprev;
6085 xc->rvat_chain_pos_time = tim;
6086 xc->rvat_chain_pos_valid = 1;
6087
6088 if(!(pvli & 1))
6089 {
6090 buf[0] = ((pvli >> 1) & 1) | '0';
6091 }
6092 else
6093 {
6094 buf[0] = FST_RCV_STR[((pvli >> 1) & 7)];
6095 }
6096 buf[1] = 0;
6097 return(buf);
6098 }
6099 else
6100 {
6101 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
6102 }
6047 {
6048 while(i<xc->rvat_chain_len)
6049 {
6050 uint32_t vli = fstGetVarint32(xc->rvat_chain_mem + i, &skiplen);
6051 uint32_t shcnt = 2 << (vli & 1);
6052 tdelta = vli >> shcnt;
6053
6054 if(xc->rvat_time_table[tidx + tdelta] <= tim)
6055 {
6056 iprev = i;
6057 pvli = vli;
6058 ptidx = tidx;
6059 /* pskip = skiplen; */ /* scan-build */
6060
6061 tidx += tdelta;
6062 i+=skiplen;
6063 }
6064 else
6065 {
6066 break;
6067 }
6068 }
6069 if(iprev != xc->rvat_chain_len)
6070 {
6071 xc->rvat_chain_pos_tidx = ptidx;
6072 xc->rvat_chain_pos_idx = iprev;
6073 xc->rvat_chain_pos_time = tim;
6074 xc->rvat_chain_pos_valid = 1;
6075
6076 if(!(pvli & 1))
6077 {
6078 buf[0] = ((pvli >> 1) & 1) | '0';
6079 }
6080 else
6081 {
6082 buf[0] = FST_RCV_STR[((pvli >> 1) & 7)];
6083 }
6084 buf[1] = 0;
6085 return(buf);
6086 }
6087 else
6088 {
6089 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
6090 }
61036091 }
61046092 else
61056093 {
6106 while(i<xc->rvat_chain_len)
6107 {
6108 uint32_t vli = fstGetVarint32(xc->rvat_chain_mem + i, &skiplen);
6109 tdelta = vli >> 1;
6110
6111 if(xc->rvat_time_table[tidx + tdelta] <= tim)
6112 {
6113 iprev = i;
6114 pvli = vli;
6115 ptidx = tidx;
6116 pskip = skiplen;
6117
6118 tidx += tdelta;
6119 i+=skiplen;
6120
6121 if(!(pvli & 1))
6122 {
6123 i+=((xc->signal_lens[facidx]+7)/8);
6124 }
6125 else
6126 {
6127 i+=xc->signal_lens[facidx];
6128 }
6129 }
6130 else
6131 {
6132 break;
6133 }
6134 }
6135
6136 if(iprev != xc->rvat_chain_len)
6137 {
6138 unsigned char *vdata = xc->rvat_chain_mem + iprev + pskip;
6139
6140 xc->rvat_chain_pos_tidx = ptidx;
6141 xc->rvat_chain_pos_idx = iprev;
6142 xc->rvat_chain_pos_time = tim;
6143 xc->rvat_chain_pos_valid = 1;
6144
6145 if(xc->signal_typs[facidx] != FST_VT_VCD_REAL)
6146 {
6147 if(!(pvli & 1))
6148 {
6149 int byte = 0;
6150 int bit;
6151 int j;
6152
6153 for(j=0;j<xc->signal_lens[facidx];j++)
6154 {
6155 unsigned char ch;
6156 byte = j/8;
6157 bit = 7 - (j & 7);
6158 ch = ((vdata[byte] >> bit) & 1) | '0';
6159 buf[j] = ch;
6160 }
6161 buf[j] = 0;
6162
6163 return(buf);
6164 }
6165 else
6166 {
6167 memcpy(buf, vdata, xc->signal_lens[facidx]);
6168 buf[xc->signal_lens[facidx]] = 0;
6169 return(buf);
6170 }
6171 }
6172 else
6173 {
6174 double d;
6175 unsigned char *clone_d = (unsigned char *)&d;
6176 unsigned char bufd[8];
6177 unsigned char *srcdata;
6178
6179 if(!(pvli & 1)) /* very rare case, but possible */
6180 {
6181 int bit;
6182 int j;
6183
6184 for(j=0;j<8;j++)
6185 {
6186 unsigned char ch;
6187 bit = 7 - (j & 7);
6188 ch = ((vdata[0] >> bit) & 1) | '0';
6189 bufd[j] = ch;
6190 }
6191
6192 srcdata = bufd;
6193 }
6194 else
6195 {
6196 srcdata = vdata;
6197 }
6198
6199 if(xc->double_endian_match)
6200 {
6201 memcpy(clone_d, srcdata, 8);
6202 }
6203 else
6204 {
6205 int j;
6206
6207 for(j=0;j<8;j++)
6208 {
6209 clone_d[j] = srcdata[7-j];
6210 }
6211 }
6212
6213 sprintf(buf, "r%.16g", d);
6214 return(buf);
6215 }
6216 }
6217 else
6218 {
6219 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
6220 }
6094 while(i<xc->rvat_chain_len)
6095 {
6096 uint32_t vli = fstGetVarint32(xc->rvat_chain_mem + i, &skiplen);
6097 tdelta = vli >> 1;
6098
6099 if(xc->rvat_time_table[tidx + tdelta] <= tim)
6100 {
6101 iprev = i;
6102 pvli = vli;
6103 ptidx = tidx;
6104 pskip = skiplen;
6105
6106 tidx += tdelta;
6107 i+=skiplen;
6108
6109 if(!(pvli & 1))
6110 {
6111 i+=((xc->signal_lens[facidx]+7)/8);
6112 }
6113 else
6114 {
6115 i+=xc->signal_lens[facidx];
6116 }
6117 }
6118 else
6119 {
6120 break;
6121 }
6122 }
6123
6124 if(iprev != xc->rvat_chain_len)
6125 {
6126 unsigned char *vdata = xc->rvat_chain_mem + iprev + pskip;
6127
6128 xc->rvat_chain_pos_tidx = ptidx;
6129 xc->rvat_chain_pos_idx = iprev;
6130 xc->rvat_chain_pos_time = tim;
6131 xc->rvat_chain_pos_valid = 1;
6132
6133 if(xc->signal_typs[facidx] != FST_VT_VCD_REAL)
6134 {
6135 if(!(pvli & 1))
6136 {
6137 int byte = 0;
6138 int bit;
6139 unsigned int j;
6140
6141 for(j=0;j<xc->signal_lens[facidx];j++)
6142 {
6143 unsigned char ch;
6144 byte = j/8;
6145 bit = 7 - (j & 7);
6146 ch = ((vdata[byte] >> bit) & 1) | '0';
6147 buf[j] = ch;
6148 }
6149 buf[j] = 0;
6150
6151 return(buf);
6152 }
6153 else
6154 {
6155 memcpy(buf, vdata, xc->signal_lens[facidx]);
6156 buf[xc->signal_lens[facidx]] = 0;
6157 return(buf);
6158 }
6159 }
6160 else
6161 {
6162 double d;
6163 unsigned char *clone_d = (unsigned char *)&d;
6164 unsigned char bufd[8];
6165 unsigned char *srcdata;
6166
6167 if(!(pvli & 1)) /* very rare case, but possible */
6168 {
6169 int bit;
6170 int j;
6171
6172 for(j=0;j<8;j++)
6173 {
6174 unsigned char ch;
6175 bit = 7 - (j & 7);
6176 ch = ((vdata[0] >> bit) & 1) | '0';
6177 bufd[j] = ch;
6178 }
6179
6180 srcdata = bufd;
6181 }
6182 else
6183 {
6184 srcdata = vdata;
6185 }
6186
6187 if(xc->double_endian_match)
6188 {
6189 memcpy(clone_d, srcdata, 8);
6190 }
6191 else
6192 {
6193 int j;
6194
6195 for(j=0;j<8;j++)
6196 {
6197 clone_d[j] = srcdata[7-j];
6198 }
6199 }
6200
6201 sprintf(buf, "r%.16g", d);
6202 return(buf);
6203 }
6204 }
6205 else
6206 {
6207 return(fstExtractRvatDataFromFrame(xc, facidx, buf));
6208 }
62216209 }
62226210 }
62236211
63696357 struct collchain_t *chain, *pchain;
63706358
63716359 if(!*base)
6372 {
6373 *base = calloc(1, (hashmask + 1) * sizeof(void *));
6374 }
6360 {
6361 *base = calloc(1, (hashmask + 1) * sizeof(void *));
6362 }
63756363 ar = *base;
63766364
63776365 h = (hf = j_hash(mem, length, length)) & hashmask;
63786366 pchain = chain = ar[h];
63796367 while(chain)
6380 {
6381 if((chain->fullhash == hf) && (chain->length == length) && !memcmp(chain->mem, mem, length))
6382 {
6383 if(pchain != chain) /* move hit to front */
6384 {
6385 pchain->next = chain->next;
6386 chain->next = ar[h];
6387 ar[h] = chain;
6388 }
6389 return(&(chain->payload));
6390 }
6391
6392 pchain = chain;
6393 chain = chain->next;
6394 }
6368 {
6369 if((chain->fullhash == hf) && (chain->length == length) && !memcmp(chain->mem, mem, length))
6370 {
6371 if(pchain != chain) /* move hit to front */
6372 {
6373 pchain->next = chain->next;
6374 chain->next = ar[h];
6375 ar[h] = chain;
6376 }
6377 return(&(chain->payload));
6378 }
6379
6380 pchain = chain;
6381 chain = chain->next;
6382 }
63956383
63966384 chain = calloc(1, sizeof(struct collchain_t) + length - 1);
63976385 memcpy(chain->mem, mem, length);
64116399 struct collchain_t *chain, *chain_next;
64126400
64136401 if(base && *base)
6414 {
6415 ar = *base;
6416 for(h=0;h<=hashmask;h++)
6417 {
6418 chain = ar[h];
6419 while(chain)
6420 {
6421 chain_next = chain->next;
6422 free(chain);
6423 chain = chain_next;
6424 }
6425 }
6426
6427 free(*base);
6428 *base = NULL;
6429 }
6402 {
6403 ar = *base;
6404 for(h=0;h<=hashmask;h++)
6405 {
6406 chain = ar[h];
6407 while(chain)
6408 {
6409 chain_next = chain->next;
6410 free(chain);
6411 chain = chain_next;
6412 }
6413 }
6414
6415 free(*base);
6416 *base = NULL;
6417 }
64306418 }
64316419
64326420 #endif
64476435 int i;
64486436
64496437 for(i=0;i<len;i++)
6450 {
6451 switch(src[i])
6452 {
6453 case '\a': *(dst++) = '\\'; *(dst++) = 'a'; break;
6454 case '\b': *(dst++) = '\\'; *(dst++) = 'b'; break;
6455 case '\f': *(dst++) = '\\'; *(dst++) = 'f'; break;
6456 case '\n': *(dst++) = '\\'; *(dst++) = 'n'; break;
6457 case '\r': *(dst++) = '\\'; *(dst++) = 'r'; break;
6458 case '\t': *(dst++) = '\\'; *(dst++) = 't'; break;
6459 case '\v': *(dst++) = '\\'; *(dst++) = 'v'; break;
6460 case '\'': *(dst++) = '\\'; *(dst++) = '\''; break;
6461 case '\"': *(dst++) = '\\'; *(dst++) = '\"'; break;
6462 case '\\': *(dst++) = '\\'; *(dst++) = '\\'; break;
6463 case '\?': *(dst++) = '\\'; *(dst++) = '\?'; break;
6464 default: if((src[i] > ' ') && (src[i] <= '~')) /* no white spaces in output */
6465 {
6466 *(dst++) = src[i];
6467 }
6468 else
6469 {
6470 val = src[i];
6471 *(dst++) = '\\';
6472 *(dst++) = (val/64) + '0'; val = val & 63;
6473 *(dst++) = (val/8) + '0'; val = val & 7;
6474 *(dst++) = (val) + '0';
6475 }
6476 break;
6477 }
6478 }
6438 {
6439 switch(src[i])
6440 {
6441 case '\a': *(dst++) = '\\'; *(dst++) = 'a'; break;
6442 case '\b': *(dst++) = '\\'; *(dst++) = 'b'; break;
6443 case '\f': *(dst++) = '\\'; *(dst++) = 'f'; break;
6444 case '\n': *(dst++) = '\\'; *(dst++) = 'n'; break;
6445 case '\r': *(dst++) = '\\'; *(dst++) = 'r'; break;
6446 case '\t': *(dst++) = '\\'; *(dst++) = 't'; break;
6447 case '\v': *(dst++) = '\\'; *(dst++) = 'v'; break;
6448 case '\'': *(dst++) = '\\'; *(dst++) = '\''; break;
6449 case '\"': *(dst++) = '\\'; *(dst++) = '\"'; break;
6450 case '\\': *(dst++) = '\\'; *(dst++) = '\\'; break;
6451 case '\?': *(dst++) = '\\'; *(dst++) = '\?'; break;
6452 default: if((src[i] > ' ') && (src[i] <= '~')) /* no white spaces in output */
6453 {
6454 *(dst++) = src[i];
6455 }
6456 else
6457 {
6458 val = src[i];
6459 *(dst++) = '\\';
6460 *(dst++) = (val/64) + '0'; val = val & 63;
6461 *(dst++) = (val/8) + '0'; val = val & 7;
6462 *(dst++) = (val) + '0';
6463 }
6464 break;
6465 }
6466 }
64796467
64806468 return(dst - d);
64816469 }
64926480 int i;
64936481
64946482 for(i=0;i<len;i++)
6495 {
6496 if(src[i] != '\\')
6497 {
6498 *(dst++) = src[i];
6499 }
6500 else
6501 {
6502 switch(src[++i])
6503 {
6504 case 'a': *(dst++) = '\a'; break;
6505 case 'b': *(dst++) = '\b'; break;
6506 case 'f': *(dst++) = '\f'; break;
6507 case 'n': *(dst++) = '\n'; break;
6508 case 'r': *(dst++) = '\r'; break;
6509 case 't': *(dst++) = '\t'; break;
6510 case 'v': *(dst++) = '\v'; break;
6511 case '\'': *(dst++) = '\''; break;
6512 case '\"': *(dst++) = '\"'; break;
6513 case '\\': *(dst++) = '\\'; break;
6514 case '\?': *(dst++) = '\?'; break;
6515
6516 case 'x': val[0] = toupper(src[++i]);
6517 val[1] = toupper(src[++i]);
6518 val[0] = ((val[0]>='A')&&(val[0]<='F')) ? (val[0] - 'A' + 10) : (val[0] - '0');
6519 val[1] = ((val[1]>='A')&&(val[1]<='F')) ? (val[1] - 'A' + 10) : (val[1] - '0');
6520 *(dst++) = val[0] * 16 + val[1];
6521 break;
6522
6523 case '0':
6524 case '1':
6525 case '2':
6526 case '3':
6527 case '4':
6528 case '5':
6529 case '6':
6530 case '7': val[0] = src[ i] - '0';
6531 val[1] = src[++i] - '0';
6532 val[2] = src[++i] - '0';
6533 *(dst++) = val[0] * 64 + val[1] * 8 + val[2];
6534 break;
6535
6536 default: *(dst++) = src[i]; break;
6537 }
6538 }
6539 }
6483 {
6484 if(src[i] != '\\')
6485 {
6486 *(dst++) = src[i];
6487 }
6488 else
6489 {
6490 switch(src[++i])
6491 {
6492 case 'a': *(dst++) = '\a'; break;
6493 case 'b': *(dst++) = '\b'; break;
6494 case 'f': *(dst++) = '\f'; break;
6495 case 'n': *(dst++) = '\n'; break;
6496 case 'r': *(dst++) = '\r'; break;
6497 case 't': *(dst++) = '\t'; break;
6498 case 'v': *(dst++) = '\v'; break;
6499 case '\'': *(dst++) = '\''; break;
6500 case '\"': *(dst++) = '\"'; break;
6501 case '\\': *(dst++) = '\\'; break;
6502 case '\?': *(dst++) = '\?'; break;
6503
6504 case 'x': val[0] = toupper(src[++i]);
6505 val[1] = toupper(src[++i]);
6506 val[0] = ((val[0]>='A')&&(val[0]<='F')) ? (val[0] - 'A' + 10) : (val[0] - '0');
6507 val[1] = ((val[1]>='A')&&(val[1]<='F')) ? (val[1] - 'A' + 10) : (val[1] - '0');
6508 *(dst++) = val[0] * 16 + val[1];
6509 break;
6510
6511 case '0':
6512 case '1':
6513 case '2':
6514 case '3':
6515 case '4':
6516 case '5':
6517 case '6':
6518 case '7': val[0] = src[ i] - '0';
6519 val[1] = src[++i] - '0';
6520 val[2] = src[++i] - '0';
6521 *(dst++) = val[0] * 64 + val[1] * 8 + val[2];
6522 break;
6523
6524 default: *(dst++) = src[i]; break;
6525 }
6526 }
6527 }
65406528
65416529 return(dst - s);
65426530 }
5656 };
5757
5858 enum fstBlockType {
59 FST_BL_HDR = 0,
59 FST_BL_HDR = 0,
6060 FST_BL_VCDATA = 1,
61 FST_BL_BLACKOUT = 2,
61 FST_BL_BLACKOUT = 2,
6262 FST_BL_GEOM = 3,
6363 FST_BL_HIER = 4,
6464 FST_BL_VCDATA_DYN_ALIAS = 5,
6666 FST_BL_HIER_LZ4DUO = 7,
6767 FST_BL_VCDATA_DYN_ALIAS2 = 8,
6868
69 FST_BL_ZWRAPPER = 254, /* indicates that whole trace is gz wrapped */
70 FST_BL_SKIP = 255 /* used while block is being written */
69 FST_BL_ZWRAPPER = 254, /* indicates that whole trace is gz wrapped */
70 FST_BL_SKIP = 255 /* used while block is being written */
7171 };
7272
7373 enum fstScopeType {
107107 };
108108
109109 enum fstVarType {
110 FST_VT_MIN = 0, /* start of vartypes */
110 FST_VT_MIN = 0, /* start of vartypes */
111111
112112 FST_VT_VCD_EVENT = 0,
113113 FST_VT_VCD_INTEGER = 1,
128128 FST_VT_VCD_WIRE = 16,
129129 FST_VT_VCD_WOR = 17,
130130 FST_VT_VCD_PORT = 18,
131 FST_VT_VCD_SPARRAY = 19, /* used to define the rownum (index) port for a sparse array */
131 FST_VT_VCD_SPARRAY = 19, /* used to define the rownum (index) port for a sparse array */
132132 FST_VT_VCD_REALTIME = 20,
133133
134 FST_VT_GEN_STRING = 21, /* generic string type (max len is defined dynamically via fstWriterEmitVariableLengthValueChange) */
134 FST_VT_GEN_STRING = 21, /* generic string type (max len is defined dynamically via fstWriterEmitVariableLengthValueChange) */
135135
136136 FST_VT_SV_BIT = 22,
137137 FST_VT_SV_LOGIC = 23,
138 FST_VT_SV_INT = 24, /* declare as size = 32 */
139 FST_VT_SV_SHORTINT = 25, /* declare as size = 16 */
140 FST_VT_SV_LONGINT = 26, /* declare as size = 64 */
141 FST_VT_SV_BYTE = 27, /* declare as size = 8 */
142 FST_VT_SV_ENUM = 28, /* declare as appropriate type range */
143 FST_VT_SV_SHORTREAL = 29, /* declare and emit same as FST_VT_VCD_REAL (needs to be emitted as double, not a float) */
144
145 FST_VT_MAX = 29 /* end of vartypes */
138 FST_VT_SV_INT = 24, /* declare as size = 32 */
139 FST_VT_SV_SHORTINT = 25, /* declare as size = 16 */
140 FST_VT_SV_LONGINT = 26, /* declare as size = 64 */
141 FST_VT_SV_BYTE = 27, /* declare as size = 8 */
142 FST_VT_SV_ENUM = 28, /* declare as appropriate type range */
143 FST_VT_SV_SHORTREAL = 29, /* declare and emit same as FST_VT_VCD_REAL (needs to be emitted as double, not a float) */
144
145 FST_VT_MAX = 29 /* end of vartypes */
146146 };
147147
148148 enum fstVarDir {
173173 enum fstAttrType {
174174 FST_AT_MIN = 0,
175175
176 FST_AT_MISC = 0, /* self-contained: does not need matching FST_HT_ATTREND */
176 FST_AT_MISC = 0, /* self-contained: does not need matching FST_HT_ATTREND */
177177 FST_AT_ARRAY = 1,
178178 FST_AT_ENUM = 2,
179179 FST_AT_PACK = 3,
184184 enum fstMiscType {
185185 FST_MT_MIN = 0,
186186
187 FST_MT_COMMENT = 0, /* use fstWriterSetComment() to emit */
188 FST_MT_ENVVAR = 1, /* use fstWriterSetEnvVar() to emit */
189 FST_MT_SUPVAR = 2, /* use fstWriterCreateVar2() to emit */
187 FST_MT_COMMENT = 0, /* use fstWriterSetComment() to emit */
188 FST_MT_ENVVAR = 1, /* use fstWriterSetEnvVar() to emit */
189 FST_MT_SUPVAR = 2, /* use fstWriterCreateVar2() to emit */
190190 FST_MT_PATHNAME = 3, /* reserved for fstWriterSetSourceStem() string -> number management */
191191 FST_MT_SOURCESTEM = 4, /* use fstWriterSetSourceStem() to emit */
192192 FST_MT_SOURCEISTEM = 5, /* use fstWriterSetSourceInstantiationStem() to emit */
273273 FST_SDT_MAX = 16,
274274
275275 FST_SDT_SVT_SHIFT_COUNT = 10, /* FST_SVT_* is ORed in by fstWriterCreateVar2() to the left after shifting FST_SDT_SVT_SHIFT_COUNT */
276 FST_SDT_ABS_MAX = ((1<<(FST_SDT_SVT_SHIFT_COUNT))-1)
276 FST_SDT_ABS_MAX = ((1<<(FST_SDT_SVT_SHIFT_COUNT))-1)
277277 };
278278
279279
282282 unsigned char htyp;
283283
284284 union {
285 /* if htyp == FST_HT_SCOPE */
286 struct fstHierScope {
287 unsigned char typ; /* FST_ST_MIN ... FST_ST_MAX */
288 const char *name;
289 const char *component;
290 uint32_t name_length; /* strlen(u.scope.name) */
291 uint32_t component_length; /* strlen(u.scope.component) */
292 } scope;
293
294 /* if htyp == FST_HT_VAR */
295 struct fstHierVar {
296 unsigned char typ; /* FST_VT_MIN ... FST_VT_MAX */
297 unsigned char direction; /* FST_VD_MIN ... FST_VD_MAX */
298 unsigned char svt_workspace; /* zeroed out by FST reader, for client code use */
299 unsigned char sdt_workspace; /* zeroed out by FST reader, for client code use */
300 unsigned int sxt_workspace; /* zeroed out by FST reader, for client code use */
301 const char *name;
302 uint32_t length;
303 fstHandle handle;
304 uint32_t name_length; /* strlen(u.var.name) */
305 unsigned is_alias : 1;
306 } var;
307
308 /* if htyp == FST_HT_ATTRBEGIN */
309 struct fstHierAttr {
310 unsigned char typ; /* FST_AT_MIN ... FST_AT_MAX */
311 unsigned char subtype; /* from fstMiscType, fstArrayType, fstEnumValueType, fstPackType */
312 const char *name;
313 uint64_t arg; /* number of array elements, struct members, or some other payload (possibly ignored) */
314 uint64_t arg_from_name; /* for when name is overloaded as a variable-length integer (FST_AT_MISC + FST_MT_SOURCESTEM) */
315 uint32_t name_length; /* strlen(u.attr.name) */
316 } attr;
317 } u;
285 /* if htyp == FST_HT_SCOPE */
286 struct fstHierScope {
287 unsigned char typ; /* FST_ST_MIN ... FST_ST_MAX */
288 const char *name;
289 const char *component;
290 uint32_t name_length; /* strlen(u.scope.name) */
291 uint32_t component_length; /* strlen(u.scope.component) */
292 } scope;
293
294 /* if htyp == FST_HT_VAR */
295 struct fstHierVar {
296 unsigned char typ; /* FST_VT_MIN ... FST_VT_MAX */
297 unsigned char direction; /* FST_VD_MIN ... FST_VD_MAX */
298 unsigned char svt_workspace; /* zeroed out by FST reader, for client code use */
299 unsigned char sdt_workspace; /* zeroed out by FST reader, for client code use */
300 unsigned int sxt_workspace; /* zeroed out by FST reader, for client code use */
301 const char *name;
302 uint32_t length;
303 fstHandle handle;
304 uint32_t name_length; /* strlen(u.var.name) */
305 unsigned is_alias : 1;
306 } var;
307
308 /* if htyp == FST_HT_ATTRBEGIN */
309 struct fstHierAttr {
310 unsigned char typ; /* FST_AT_MIN ... FST_AT_MAX */
311 unsigned char subtype; /* from fstMiscType, fstArrayType, fstEnumValueType, fstPackType */
312 const char *name;
313 uint64_t arg; /* number of array elements, struct members, or some other payload (possibly ignored) */
314 uint64_t arg_from_name; /* for when name is overloaded as a variable-length integer (FST_AT_MISC + FST_MT_SOURCESTEM) */
315 uint32_t name_length; /* strlen(u.attr.name) */
316 } attr;
317 } u;
318318 };
319319
320320
321321 /*
322322 * writer functions
323323 */
324 void fstWriterClose(void *ctx);
325 void * fstWriterCreate(const char *nam, int use_compressed_hier);
326 /* used for Verilog/SV */
327 fstHandle fstWriterCreateVar(void *ctx, enum fstVarType vt, enum fstVarDir vd,
328 uint32_t len, const char *nam, fstHandle aliasHandle);
329 /* future expansion for VHDL and other languages. The variable type, data type, etc map onto
330 the current Verilog/SV one. The "type" string is optional for a more verbose or custom description */
331 fstHandle fstWriterCreateVar2(void *ctx, enum fstVarType vt, enum fstVarDir vd,
332 uint32_t len, const char *nam, fstHandle aliasHandle,
333 const char *type, enum fstSupplementalVarType svt, enum fstSupplementalDataType sdt);
334 void fstWriterEmitValueChange(void *ctx, fstHandle handle, const void *val);
335 void fstWriterEmitVariableLengthValueChange(void *ctx, fstHandle handle, const void *val, uint32_t len);
336 void fstWriterEmitDumpActive(void *ctx, int enable);
337 void fstWriterEmitTimeChange(void *ctx, uint64_t tim);
338 void fstWriterFlushContext(void *ctx);
339 int fstWriterGetDumpSizeLimitReached(void *ctx);
340 int fstWriterGetFseekFailed(void *ctx);
341 void fstWriterSetAttrBegin(void *ctx, enum fstAttrType attrtype, int subtype,
342 const char *attrname, uint64_t arg);
343 void fstWriterSetAttrEnd(void *ctx);
344 void fstWriterSetComment(void *ctx, const char *comm);
345 void fstWriterSetDate(void *ctx, const char *dat);
346 void fstWriterSetDumpSizeLimit(void *ctx, uint64_t numbytes);
347 void fstWriterSetEnvVar(void *ctx, const char *envvar);
348 void fstWriterSetFileType(void *ctx, enum fstFileType filetype);
349 void fstWriterSetPackType(void *ctx, enum fstWriterPackType typ);
350 void fstWriterSetParallelMode(void *ctx, int enable);
351 void fstWriterSetRepackOnClose(void *ctx, int enable); /* type = 0 (none), 1 (libz) */
352 void fstWriterSetScope(void *ctx, enum fstScopeType scopetype,
353 const char *scopename, const char *scopecomp);
354 void fstWriterSetSourceInstantiationStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
355 void fstWriterSetSourceStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
356 void fstWriterSetTimescale(void *ctx, int ts);
357 void fstWriterSetTimescaleFromString(void *ctx, const char *s);
358 void fstWriterSetTimezero(void *ctx, int64_t tim);
359 void fstWriterSetUpscope(void *ctx);
360 void fstWriterSetVersion(void *ctx, const char *vers);
324 void fstWriterClose(void *ctx);
325 void * fstWriterCreate(const char *nam, int use_compressed_hier);
326 /* used for Verilog/SV */
327 fstHandle fstWriterCreateVar(void *ctx, enum fstVarType vt, enum fstVarDir vd,
328 uint32_t len, const char *nam, fstHandle aliasHandle);
329 /* future expansion for VHDL and other languages. The variable type, data type, etc map onto
330 the current Verilog/SV one. The "type" string is optional for a more verbose or custom description */
331 fstHandle fstWriterCreateVar2(void *ctx, enum fstVarType vt, enum fstVarDir vd,
332 uint32_t len, const char *nam, fstHandle aliasHandle,
333 const char *type, enum fstSupplementalVarType svt, enum fstSupplementalDataType sdt);
334 void fstWriterEmitValueChange(void *ctx, fstHandle handle, const void *val);
335 void fstWriterEmitVariableLengthValueChange(void *ctx, fstHandle handle, const void *val, uint32_t len);
336 void fstWriterEmitDumpActive(void *ctx, int enable);
337 void fstWriterEmitTimeChange(void *ctx, uint64_t tim);
338 void fstWriterFlushContext(void *ctx);
339 int fstWriterGetDumpSizeLimitReached(void *ctx);
340 int fstWriterGetFseekFailed(void *ctx);
341 void fstWriterSetAttrBegin(void *ctx, enum fstAttrType attrtype, int subtype,
342 const char *attrname, uint64_t arg);
343 void fstWriterSetAttrEnd(void *ctx);
344 void fstWriterSetComment(void *ctx, const char *comm);
345 void fstWriterSetDate(void *ctx, const char *dat);
346 void fstWriterSetDumpSizeLimit(void *ctx, uint64_t numbytes);
347 void fstWriterSetEnvVar(void *ctx, const char *envvar);
348 void fstWriterSetFileType(void *ctx, enum fstFileType filetype);
349 void fstWriterSetPackType(void *ctx, enum fstWriterPackType typ);
350 void fstWriterSetParallelMode(void *ctx, int enable);
351 void fstWriterSetRepackOnClose(void *ctx, int enable); /* type = 0 (none), 1 (libz) */
352 void fstWriterSetScope(void *ctx, enum fstScopeType scopetype,
353 const char *scopename, const char *scopecomp);
354 void fstWriterSetSourceInstantiationStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
355 void fstWriterSetSourceStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
356 void fstWriterSetTimescale(void *ctx, int ts);
357 void fstWriterSetTimescaleFromString(void *ctx, const char *s);
358 void fstWriterSetTimezero(void *ctx, int64_t tim);
359 void fstWriterSetUpscope(void *ctx);
360 void fstWriterSetVersion(void *ctx, const char *vers);
361361
362362
363363 /*
364364 * reader functions
365365 */
366 void fstReaderClose(void *ctx);
367 void fstReaderClrFacProcessMask(void *ctx, fstHandle facidx);
368 void fstReaderClrFacProcessMaskAll(void *ctx);
369 uint64_t fstReaderGetAliasCount(void *ctx);
370 const char * fstReaderGetCurrentFlatScope(void *ctx);
371 void * fstReaderGetCurrentScopeUserInfo(void *ctx);
372 int fstReaderGetCurrentScopeLen(void *ctx);
373 const char * fstReaderGetDateString(void *ctx);
374 int fstReaderGetDoubleEndianMatchState(void *ctx);
375 uint64_t fstReaderGetDumpActivityChangeTime(void *ctx, uint32_t idx);
376 unsigned char fstReaderGetDumpActivityChangeValue(void *ctx, uint32_t idx);
377 uint64_t fstReaderGetEndTime(void *ctx);
378 int fstReaderGetFacProcessMask(void *ctx, fstHandle facidx);
379 int fstReaderGetFileType(void *ctx);
380 int fstReaderGetFseekFailed(void *ctx);
381 fstHandle fstReaderGetMaxHandle(void *ctx);
382 uint64_t fstReaderGetMemoryUsedByWriter(void *ctx);
383 uint32_t fstReaderGetNumberDumpActivityChanges(void *ctx);
384 uint64_t fstReaderGetScopeCount(void *ctx);
385 uint64_t fstReaderGetStartTime(void *ctx);
386 signed char fstReaderGetTimescale(void *ctx);
387 int64_t fstReaderGetTimezero(void *ctx);
388 uint64_t fstReaderGetValueChangeSectionCount(void *ctx);
389 char * fstReaderGetValueFromHandleAtTime(void *ctx, uint64_t tim, fstHandle facidx, char *buf);
390 uint64_t fstReaderGetVarCount(void *ctx);
391 const char * fstReaderGetVersionString(void *ctx);
366 void fstReaderClose(void *ctx);
367 void fstReaderClrFacProcessMask(void *ctx, fstHandle facidx);
368 void fstReaderClrFacProcessMaskAll(void *ctx);
369 uint64_t fstReaderGetAliasCount(void *ctx);
370 const char * fstReaderGetCurrentFlatScope(void *ctx);
371 void * fstReaderGetCurrentScopeUserInfo(void *ctx);
372 int fstReaderGetCurrentScopeLen(void *ctx);
373 const char * fstReaderGetDateString(void *ctx);
374 int fstReaderGetDoubleEndianMatchState(void *ctx);
375 uint64_t fstReaderGetDumpActivityChangeTime(void *ctx, uint32_t idx);
376 unsigned char fstReaderGetDumpActivityChangeValue(void *ctx, uint32_t idx);
377 uint64_t fstReaderGetEndTime(void *ctx);
378 int fstReaderGetFacProcessMask(void *ctx, fstHandle facidx);
379 int fstReaderGetFileType(void *ctx);
380 int fstReaderGetFseekFailed(void *ctx);
381 fstHandle fstReaderGetMaxHandle(void *ctx);
382 uint64_t fstReaderGetMemoryUsedByWriter(void *ctx);
383 uint32_t fstReaderGetNumberDumpActivityChanges(void *ctx);
384 uint64_t fstReaderGetScopeCount(void *ctx);
385 uint64_t fstReaderGetStartTime(void *ctx);
386 signed char fstReaderGetTimescale(void *ctx);
387 int64_t fstReaderGetTimezero(void *ctx);
388 uint64_t fstReaderGetValueChangeSectionCount(void *ctx);
389 char * fstReaderGetValueFromHandleAtTime(void *ctx, uint64_t tim, fstHandle facidx, char *buf);
390 uint64_t fstReaderGetVarCount(void *ctx);
391 const char * fstReaderGetVersionString(void *ctx);
392392 struct fstHier *fstReaderIterateHier(void *ctx);
393 int fstReaderIterateHierRewind(void *ctx);
394 int fstReaderIterBlocks(void *ctx,
395 void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
396 void *user_callback_data_pointer, FILE *vcdhandle);
397 int fstReaderIterBlocks2(void *ctx,
398 void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
399 void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
400 void *user_callback_data_pointer, FILE *vcdhandle);
401 void fstReaderIterBlocksSetNativeDoublesOnCallback(void *ctx, int enable);
402 void * fstReaderOpen(const char *nam);
403 void * fstReaderOpenForUtilitiesOnly(void);
404 const char * fstReaderPopScope(void *ctx);
405 int fstReaderProcessHier(void *ctx, FILE *vcdhandle);
406 const char * fstReaderPushScope(void *ctx, const char *nam, void *user_info);
407 void fstReaderResetScope(void *ctx);
408 void fstReaderSetFacProcessMask(void *ctx, fstHandle facidx);
409 void fstReaderSetFacProcessMaskAll(void *ctx);
410 void fstReaderSetLimitTimeRange(void *ctx, uint64_t start_time, uint64_t end_time);
411 void fstReaderSetUnlimitedTimeRange(void *ctx);
412 void fstReaderSetVcdExtensions(void *ctx, int enable);
393 int fstReaderIterateHierRewind(void *ctx);
394 int fstReaderIterBlocks(void *ctx,
395 void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
396 void *user_callback_data_pointer, FILE *vcdhandle);
397 int fstReaderIterBlocks2(void *ctx,
398 void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
399 void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
400 void *user_callback_data_pointer, FILE *vcdhandle);
401 void fstReaderIterBlocksSetNativeDoublesOnCallback(void *ctx, int enable);
402 void * fstReaderOpen(const char *nam);
403 void * fstReaderOpenForUtilitiesOnly(void);
404 const char * fstReaderPopScope(void *ctx);
405 int fstReaderProcessHier(void *ctx, FILE *vcdhandle);
406 const char * fstReaderPushScope(void *ctx, const char *nam, void *user_info);
407 void fstReaderResetScope(void *ctx);
408 void fstReaderSetFacProcessMask(void *ctx, fstHandle facidx);
409 void fstReaderSetFacProcessMaskAll(void *ctx);
410 void fstReaderSetLimitTimeRange(void *ctx, uint64_t start_time, uint64_t end_time);
411 void fstReaderSetUnlimitedTimeRange(void *ctx);
412 void fstReaderSetVcdExtensions(void *ctx, int enable);
413413
414414
415415 /*
416416 * utility functions
417417 */
418 int fstUtilityBinToEsc(unsigned char *d, unsigned char *s, int len);
419 int fstUtilityEscToBin(unsigned char *d, unsigned char *s, int len);
418 int fstUtilityBinToEsc(unsigned char *d, unsigned char *s, int len);
419 int fstUtilityEscToBin(unsigned char *d, unsigned char *s, int len);
420420
421421 #ifdef __cplusplus
422422 }
3434 Tuning parameters
3535 **************************************/
3636 /*
37 * MEMORY_USAGE :
38 * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
39 * Increasing memory usage improves compression ratio
40 * Reduced memory usage can improve speed, due to cache effect
41 * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
42 */
43 #define MEMORY_USAGE 14
44
45 /*
4637 * HEAPMODE :
4738 * Select how default compression functions will allocate memory for their hash table,
4839 * in memory stack (0:default, fastest), or in memory heap (1:requires memory allocation (malloc)).
5546 **************************************/
5647 /* 32 or 64 bits ? */
5748 #if (defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) \
58 || defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) \
59 || defined(__64BIT__) || defined(_LP64) || defined(__LP64__) \
49 || defined(__powerpc64__) || defined(__powerpc64le__) \
50 || defined(__ppc64__) || defined(__ppc64le__) \
51 || defined(__PPC64__) || defined(__PPC64LE__) \
6052 || defined(__ia64) || defined(__itanium__) || defined(_M_IA64) ) /* Detects 64 bits mode */
6153 # define LZ4_ARCH64 1
6254 #else
6759 * Little Endian or Big Endian ?
6860 * Overwrite the #define below if you know your architecture endianess
6961 */
62 #include <stdlib.h> /* Apparently required to detect endianess */
7063 #if defined (__GLIBC__)
7164 # include <endian.h>
7265 # if (__BYTE_ORDER == __BIG_ENDIAN)
223216 /**************************************
224217 Constants
225218 **************************************/
226 #define LZ4_HASHLOG (MEMORY_USAGE-2)
227 #define HASHTABLESIZE (1 << MEMORY_USAGE)
228 #define HASHNBCELLS4 (1 << LZ4_HASHLOG)
219 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
220 #define HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
221 #define HASH_SIZE_U32 (1 << LZ4_HASHLOG)
229222
230223 #define MINMATCH 4
231224
254247 Structures and local types
255248 **************************************/
256249 typedef struct {
257 U32 hashTable[HASHNBCELLS4];
250 U32 hashTable[HASH_SIZE_U32];
251 U32 currentOffset;
252 U32 initCheck;
253 const BYTE* dictionary;
258254 const BYTE* bufferStart;
259 const BYTE* base;
260 const BYTE* nextBlock;
261 } LZ4_Data_Structure;
262
263 typedef enum { notLimited = 0, limited = 1 } limitedOutput_directive;
255 U32 dictSize;
256 } LZ4_stream_t_internal;
257
258 typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive;
264259 typedef enum { byPtr, byU32, byU16 } tableType_t;
265260
266 typedef enum { noPrefix = 0, withPrefix = 1 } prefix64k_directive;
261 typedef enum { noDict = 0, withPrefix64k, usingExtDict } dict_directive;
262 typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive;
267263
268264 typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive;
269265 typedef enum { full = 0, partial = 1 } earlyEnd_directive;
288284 /**************************************
289285 Macros
290286 **************************************/
287 #define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(!!(c)) }; } /* use only *after* variable declarations */
291288 #if LZ4_ARCH64 || !defined(__GNUC__)
292 # define LZ4_WILDCOPY(d,s,e) { do { LZ4_COPY8(d,s) } while (d<e); } /* at the end, d>=e; */
293 #else
294 # define LZ4_WILDCOPY(d,s,e) { if (likely(e-d <= 8)) LZ4_COPY8(d,s) else do { LZ4_COPY8(d,s) } while (d<e); }
295 #endif
296 #define LZ4_SECURECOPY(d,s,e) { if (d<e) LZ4_WILDCOPY(d,s,e); }
289 # define LZ4_WILDCOPY(d,s,e) { do { LZ4_COPY8(d,s) } while (d<e); } /* at the end, d>=e; */
290 #else
291 # define LZ4_WILDCOPY(d,s,e) { if (likely(e-d <= 8)) LZ4_COPY8(d,s) else do { LZ4_COPY8(d,s) } while (d<e); }
292 #endif
297293
298294
299295 /****************************
301297 ****************************/
302298 #if LZ4_ARCH64
303299
304 FORCE_INLINE int LZ4_NbCommonBytes (register U64 val)
300 int LZ4_NbCommonBytes (register U64 val)
305301 {
306302 # if defined(LZ4_BIG_ENDIAN)
307303 # if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
333329
334330 #else
335331
336 FORCE_INLINE int LZ4_NbCommonBytes (register U32 val)
332 int LZ4_NbCommonBytes (register U32 val)
337333 {
338334 # if defined(LZ4_BIG_ENDIAN)
339335 # if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
365361 #endif
366362
367363
368 /****************************
364 /********************************
369365 Compression functions
370 ****************************/
371 FORCE_INLINE int LZ4_hashSequence(U32 sequence, tableType_t tableType)
366 ********************************/
367 int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
368
369 static int LZ4_hashSequence(U32 sequence, tableType_t tableType)
372370 {
373371 if (tableType == byU16)
374372 return (((sequence) * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1)));
376374 return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
377375 }
378376
379 FORCE_INLINE int LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(A32(p), tableType); }
380
381 FORCE_INLINE void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
377 static int LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(A32(p), tableType); }
378
379 static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
382380 {
383381 switch (tableType)
384382 {
388386 }
389387 }
390388
391 FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
389 static void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
392390 {
393391 U32 h = LZ4_hashPosition(p, tableType);
394392 LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
395393 }
396394
397 FORCE_INLINE const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
395 static const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
398396 {
399397 if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; }
400398 if (tableType == byU32) { U32* hashTable = (U32*) tableBase; return hashTable[h] + srcBase; }
401399 { U16* hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */
402400 }
403401
404 FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
402 static const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
405403 {
406404 U32 h = LZ4_hashPosition(p, tableType);
407405 return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
408406 }
409407
410
411 FORCE_INLINE int LZ4_compress_generic(
408 static unsigned LZ4_count(const BYTE* pIn, const BYTE* pRef, const BYTE* pInLimit)
409 {
410 const BYTE* const pStart = pIn;
411
412 while (likely(pIn<pInLimit-(STEPSIZE-1)))
413 {
414 size_t diff = AARCH(pRef) ^ AARCH(pIn);
415 if (!diff) { pIn+=STEPSIZE; pRef+=STEPSIZE; continue; }
416 pIn += LZ4_NbCommonBytes(diff);
417 return (unsigned)(pIn - pStart);
418 }
419 if (sizeof(void*)==8) if ((pIn<(pInLimit-3)) && (A32(pRef) == A32(pIn))) { pIn+=4; pRef+=4; }
420 if ((pIn<(pInLimit-1)) && (A16(pRef) == A16(pIn))) { pIn+=2; pRef+=2; }
421 if ((pIn<pInLimit) && (*pRef == *pIn)) pIn++;
422
423 return (unsigned)(pIn - pStart);
424 }
425
426
427 static int LZ4_compress_generic(
412428 void* ctx,
413429 const char* source,
414430 char* dest,
415431 int inputSize,
416432 int maxOutputSize,
417433
418 limitedOutput_directive limitedOutput,
434 limitedOutput_directive outputLimited,
419435 tableType_t tableType,
420 prefix64k_directive prefix)
421 {
436 dict_directive dict,
437 dictIssue_directive dictIssue)
438 {
439 LZ4_stream_t_internal* const dictPtr = (LZ4_stream_t_internal*)ctx;
440
422441 const BYTE* ip = (const BYTE*) source;
423 const BYTE* const base = (prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->base : (const BYTE*) source;
424 const BYTE* const lowLimit = ((prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->bufferStart : (const BYTE*)source);
442 const BYTE* base;
443 const BYTE* lowLimit;
444 const BYTE* const lowRefLimit = ip - dictPtr->dictSize;
445 const BYTE* const dictionary = dictPtr->dictionary;
446 const BYTE* const dictEnd = dictionary + dictPtr->dictSize;
447 const size_t dictDelta = dictEnd - (const BYTE*)source;
425448 const BYTE* anchor = (const BYTE*) source;
426449 const BYTE* const iend = ip + inputSize;
427450 const BYTE* const mflimit = iend - MFLIMIT;
428451 const BYTE* const matchlimit = iend - LASTLITERALS;
429452
430453 BYTE* op = (BYTE*) dest;
431 BYTE* const oend = op + maxOutputSize;
432
433 int length;
454 BYTE* const olimit = op + maxOutputSize;
455
434456 const int skipStrength = SKIPSTRENGTH;
435457 U32 forwardH;
458 size_t refDelta=0;
436459
437460 /* Init conditions */
438 if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
439 if ((prefix==withPrefix) && (ip != ((LZ4_Data_Structure*)ctx)->nextBlock)) return 0; /* must continue from end of previous block */
440 if (prefix==withPrefix) ((LZ4_Data_Structure*)ctx)->nextBlock=iend; /* do it now, due to potential early exit */
441 if ((tableType == byU16) && (inputSize>=(int)LZ4_64KLIMIT)) return 0; /* Size too large (not within 64K limit) */
442 if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
461 if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
462 switch(dict)
463 {
464 case noDict:
465 default:
466 base = (const BYTE*)source;
467 lowLimit = (const BYTE*)source;
468 break;
469 case withPrefix64k:
470 base = (const BYTE*)source - dictPtr->currentOffset;
471 lowLimit = (const BYTE*)source - dictPtr->dictSize;
472 break;
473 case usingExtDict:
474 base = (const BYTE*)source - dictPtr->currentOffset;
475 lowLimit = (const BYTE*)source;
476 break;
477 }
478 if ((tableType == byU16) && (inputSize>=(int)LZ4_64KLIMIT)) return 0; /* Size too large (not within 64K limit) */
479 if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
443480
444481 /* First Byte */
445482 LZ4_putPosition(ip, ctx, tableType, base);
448485 /* Main Loop */
449486 for ( ; ; )
450487 {
451 int findMatchAttempts = (1U << skipStrength) + 3;
452 const BYTE* forwardIp = ip;
453488 const BYTE* ref;
454489 BYTE* token;
455
456 /* Find a match */
457 do {
458 U32 h = forwardH;
459 int step = findMatchAttempts++ >> skipStrength;
460 ip = forwardIp;
461 forwardIp = ip + step;
462
463 if (unlikely(forwardIp > mflimit)) { goto _last_literals; }
464
465 forwardH = LZ4_hashPosition(forwardIp, tableType);
466 ref = LZ4_getPositionOnHash(h, ctx, tableType, base);
467 LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
468
469 } while ((ref + MAX_DISTANCE < ip) || (A32(ref) != A32(ip)));
490 {
491 const BYTE* forwardIp = ip;
492 unsigned step=1;
493 unsigned searchMatchNb = (1U << skipStrength);
494
495 /* Find a match */
496 do {
497 U32 h = forwardH;
498 ip = forwardIp;
499 forwardIp += step;
500 step = searchMatchNb++ >> skipStrength;
501 //if (step>8) step=8; // required for valid forwardIp ; slows down uncompressible data a bit
502
503 if (unlikely(forwardIp > mflimit)) goto _last_literals;
504
505 ref = LZ4_getPositionOnHash(h, ctx, tableType, base);
506 if (dict==usingExtDict)
507 {
508 if (ref<(const BYTE*)source)
509 {
510 refDelta = dictDelta;
511 lowLimit = dictionary;
512 }
513 else
514 {
515 refDelta = 0;
516 lowLimit = (const BYTE*)source;
517 }
518 }
519 forwardH = LZ4_hashPosition(forwardIp, tableType);
520 LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
521
522 } while ( ((dictIssue==dictSmall) ? (ref < lowRefLimit) : 0)
523 || ((tableType==byU16) ? 0 : (ref + MAX_DISTANCE < ip))
524 || (A32(ref+refDelta) != A32(ip)) );
525 }
470526
471527 /* Catch up */
472 while ((ip>anchor) && (ref > lowLimit) && (unlikely(ip[-1]==ref[-1]))) { ip--; ref--; }
473
474 /* Encode Literal length */
475 length = (int)(ip - anchor);
476 token = op++;
477 if ((limitedOutput) && (unlikely(op + length + (2 + 1 + LASTLITERALS) + (length/255) > oend))) return 0; /* Check output limit */
478 if (length>=(int)RUN_MASK)
528 while ((ip>anchor) && (ref+refDelta > lowLimit) && (unlikely(ip[-1]==ref[refDelta-1]))) { ip--; ref--; }
529
479530 {
480 int len = length-RUN_MASK;
481 *token=(RUN_MASK<<ML_BITS);
482 for(; len >= 255 ; len-=255) *op++ = 255;
483 *op++ = (BYTE)len;
531 /* Encode Literal length */
532 unsigned litLength = (unsigned)(ip - anchor);
533 token = op++;
534 if ((outputLimited) && (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit)))
535 return 0; /* Check output limit */
536 if (litLength>=RUN_MASK)
537 {
538 int len = (int)litLength-RUN_MASK;
539 *token=(RUN_MASK<<ML_BITS);
540 for(; len >= 255 ; len-=255) *op++ = 255;
541 *op++ = (BYTE)len;
542 }
543 else *token = (BYTE)(litLength<<ML_BITS);
544
545 /* Copy Literals */
546 { BYTE* end = op+litLength; LZ4_WILDCOPY(op,anchor,end); op=end; }
484547 }
485 else *token = (BYTE)(length<<ML_BITS);
486
487 /* Copy Literals */
488 { BYTE* end=(op)+(length); LZ4_WILDCOPY(op,anchor,end); op=end; }
489548
490549 _next_match:
491550 /* Encode Offset */
492 LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));
493
494 /* Start Counting */
495 ip+=MINMATCH; ref+=MINMATCH; /* MinMatch already verified */
551 LZ4_WRITE_LITTLEENDIAN_16(op, (U16)(ip-ref));
552
553 /* Encode MatchLength */
554 {
555 unsigned matchLength;
556
557 if ((dict==usingExtDict) && (lowLimit==dictionary))
558 {
559 const BYTE* limit;
560 ref += refDelta;
561 limit = ip + (dictEnd-ref);
562 if (limit > matchlimit) limit = matchlimit;
563 matchLength = LZ4_count(ip+MINMATCH, ref+MINMATCH, limit);
564 ip += MINMATCH + matchLength;
565 if (ip==limit)
566 {
567 unsigned more = LZ4_count(ip, (const BYTE*)source, matchlimit);
568 matchLength += more;
569 ip += more;
570 }
571 }
572 else
573 {
574 matchLength = LZ4_count(ip+MINMATCH, ref+MINMATCH, matchlimit);
575 ip += MINMATCH + matchLength;
576 }
577
578 if (matchLength>=ML_MASK)
579 {
580 if ((outputLimited) && (unlikely(op + (1 + LASTLITERALS) + (matchLength>>8) > olimit)))
581 return 0; /* Check output limit */
582 *token += ML_MASK;
583 matchLength -= ML_MASK;
584 for (; matchLength >= 510 ; matchLength-=510) { *op++ = 255; *op++ = 255; }
585 if (matchLength >= 255) { matchLength-=255; *op++ = 255; }
586 *op++ = (BYTE)matchLength;
587 }
588 else *token += (BYTE)(matchLength);
589 }
590
496591 anchor = ip;
497 while (likely(ip<matchlimit-(STEPSIZE-1)))
498 {
499 size_t diff = AARCH(ref) ^ AARCH(ip);
500 if (!diff) { ip+=STEPSIZE; ref+=STEPSIZE; continue; }
501 ip += LZ4_NbCommonBytes(diff);
502 goto _endCount;
503 }
504 if (LZ4_ARCH64) if ((ip<(matchlimit-3)) && (A32(ref) == A32(ip))) { ip+=4; ref+=4; }
505 if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }
506 if ((ip<matchlimit) && (*ref == *ip)) ip++;
507 _endCount:
508
509 /* Encode MatchLength */
510 length = (int)(ip - anchor);
511 if ((limitedOutput) && (unlikely(op + (1 + LASTLITERALS) + (length>>8) > oend))) return 0; /* Check output limit */
512 if (length>=(int)ML_MASK)
513 {
514 *token += ML_MASK;
515 length -= ML_MASK;
516 for (; length > 509 ; length-=510) { *op++ = 255; *op++ = 255; }
517 if (length >= 255) { length-=255; *op++ = 255; }
518 *op++ = (BYTE)length;
519 }
520 else *token += (BYTE)(length);
521592
522593 /* Test end of chunk */
523 if (ip > mflimit) { anchor = ip; break; }
594 if (ip > mflimit) break;
524595
525596 /* Fill table */
526597 LZ4_putPosition(ip-2, ctx, tableType, base);
527598
528599 /* Test next position */
529600 ref = LZ4_getPosition(ip, ctx, tableType, base);
601 if (dict==usingExtDict)
602 {
603 if (ref<(const BYTE*)source)
604 {
605 refDelta = dictDelta;
606 lowLimit = dictionary;
607 }
608 else
609 {
610 refDelta = 0;
611 lowLimit = (const BYTE*)source;
612 }
613 }
530614 LZ4_putPosition(ip, ctx, tableType, base);
531 if ((ref + MAX_DISTANCE >= ip) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
615 if ( ((dictIssue==dictSmall) ? (ref>=lowRefLimit) : 1)
616 && (ref+MAX_DISTANCE>=ip)
617 && (A32(ref+refDelta)==A32(ip)) )
618 { token=op++; *token=0; goto _next_match; }
532619
533620 /* Prepare next loop */
534 anchor = ip++;
535 forwardH = LZ4_hashPosition(ip, tableType);
621 forwardH = LZ4_hashPosition(++ip, tableType);
536622 }
537623
538624 _last_literals:
539625 /* Encode Last Literals */
540626 {
541627 int lastRun = (int)(iend - anchor);
542 if ((limitedOutput) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */
628 if ((outputLimited) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize))
629 return 0; /* Check output limit */
543630 if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun >= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
544631 else *op++ = (BYTE)(lastRun<<ML_BITS);
545632 memcpy(op, anchor, iend - anchor);
554641 int LZ4_compress(const char* source, char* dest, int inputSize)
555642 {
556643 #if (HEAPMODE)
557 void* ctx = ALLOCATOR(HASHNBCELLS4, 4); /* Aligned on 4-bytes boundaries */
558 #else
559 U32 ctx[1U<<(MEMORY_USAGE-2)] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
644 void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
645 #else
646 U32 ctx[LZ4_STREAMSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
560647 #endif
561648 int result;
562649
563650 if (inputSize < (int)LZ4_64KLIMIT)
564 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noPrefix);
651 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue);
565652 else
566 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
653 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue);
567654
568655 #if (HEAPMODE)
569656 FREEMEM(ctx);
574661 int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
575662 {
576663 #if (HEAPMODE)
577 void* ctx = ALLOCATOR(HASHNBCELLS4, 4); /* Aligned on 4-bytes boundaries */
578 #else
579 U32 ctx[1U<<(MEMORY_USAGE-2)] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
664 void* ctx = ALLOCATOR(LZ4_STREAMSIZE_U32, 4); /* Aligned on 4-bytes boundaries */
665 #else
666 U32 ctx[LZ4_STREAMSIZE_U32] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
580667 #endif
581668 int result;
582669
583670 if (inputSize < (int)LZ4_64KLIMIT)
584 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, byU16, noPrefix);
671 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue);
585672 else
586 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
673 result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue);
587674
588675 #if (HEAPMODE)
589676 FREEMEM(ctx);
592679 }
593680
594681
595 /*****************************
596 Using external allocation
597 *****************************/
598
599 int LZ4_sizeofState() { return 1 << MEMORY_USAGE; }
600
601
602 int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
603 {
604 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
605 MEM_INIT(state, 0, LZ4_sizeofState());
606
607 if (inputSize < (int)LZ4_64KLIMIT)
608 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noPrefix);
609 else
610 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
611 }
612
613
614 int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
615 {
616 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
617 MEM_INIT(state, 0, LZ4_sizeofState());
618
619 if (inputSize < (int)LZ4_64KLIMIT)
620 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limited, byU16, noPrefix);
621 else
622 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
623 }
624
625
626 /****************************
627 Stream functions
628 ****************************/
629
630 int LZ4_sizeofStreamState()
631 {
632 return sizeof(LZ4_Data_Structure);
633 }
634
635 FORCE_INLINE void LZ4_init(LZ4_Data_Structure* lz4ds, const BYTE* base)
636 {
637 MEM_INIT(lz4ds->hashTable, 0, sizeof(lz4ds->hashTable));
638 lz4ds->bufferStart = base;
639 lz4ds->base = base;
640 lz4ds->nextBlock = base;
641 }
642
643 int LZ4_resetStreamState(void* state, const char* inputBuffer)
644 {
645 if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */
646 LZ4_init((LZ4_Data_Structure*)state, (const BYTE*)inputBuffer);
647 return 0;
648 }
649
650 void* LZ4_create (const char* inputBuffer)
651 {
652 void* lz4ds = ALLOCATOR(1, sizeof(LZ4_Data_Structure));
653 LZ4_init ((LZ4_Data_Structure*)lz4ds, (const BYTE*)inputBuffer);
654 return lz4ds;
655 }
656
657
658 int LZ4_free (void* LZ4_Data)
659 {
660 FREEMEM(LZ4_Data);
682 /*****************************************
683 Experimental : Streaming functions
684 *****************************************/
685
686 void* LZ4_createStream()
687 {
688 void* lz4s = ALLOCATOR(4, LZ4_STREAMSIZE_U32);
689 MEM_INIT(lz4s, 0, LZ4_STREAMSIZE);
690 return lz4s;
691 }
692
693 int LZ4_free (void* LZ4_stream)
694 {
695 FREEMEM(LZ4_stream);
661696 return (0);
662697 }
663698
664699
665 char* LZ4_slideInputBuffer (void* LZ4_Data)
666 {
667 LZ4_Data_Structure* lz4ds = (LZ4_Data_Structure*)LZ4_Data;
668 size_t delta = lz4ds->nextBlock - (lz4ds->bufferStart + 64 KB);
669
670 if ( (lz4ds->base - delta > lz4ds->base) /* underflow control */
671 || ((size_t)(lz4ds->nextBlock - lz4ds->base) > 0xE0000000) ) /* close to 32-bits limit */
672 {
673 size_t deltaLimit = (lz4ds->nextBlock - 64 KB) - lz4ds->base;
674 int nH;
675
676 for (nH=0; nH < HASHNBCELLS4; nH++)
700 int LZ4_loadDict (void* LZ4_dict, const char* dictionary, int dictSize)
701 {
702 LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict;
703 const BYTE* p = (const BYTE*)dictionary;
704 const BYTE* const dictEnd = p + dictSize;
705 const BYTE* base;
706
707 LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */
708 if (dict->initCheck) MEM_INIT(dict, 0, sizeof(LZ4_stream_t_internal)); /* Uninitialized structure detected */
709
710 if (dictSize < MINMATCH)
711 {
712 dict->dictionary = NULL;
713 dict->dictSize = 0;
714 return 1;
715 }
716
717 if (p <= dictEnd - 64 KB) p = dictEnd - 64 KB;
718 base = p - dict->currentOffset;
719 dict->dictionary = p;
720 dict->dictSize = (U32)(dictEnd - p);
721 dict->currentOffset += dict->dictSize;
722
723 while (p <= dictEnd-MINMATCH)
724 {
725 LZ4_putPosition(p, dict, byU32, base);
726 p+=3;
727 }
728
729 return 1;
730 }
731
732
733 void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src)
734 {
735 if ((LZ4_dict->currentOffset > 0x80000000) ||
736 ((size_t)LZ4_dict->currentOffset > (size_t)src)) /* address space overflow */
737 {
738 /* rescale hash table */
739 U32 delta = LZ4_dict->currentOffset - 64 KB;
740 const BYTE* dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize;
741 int i;
742 for (i=0; i<HASH_SIZE_U32; i++)
677743 {
678 if ((size_t)(lz4ds->hashTable[nH]) < deltaLimit) lz4ds->hashTable[nH] = 0;
679 else lz4ds->hashTable[nH] -= (U32)deltaLimit;
744 if (LZ4_dict->hashTable[i] < delta) LZ4_dict->hashTable[i]=0;
745 else LZ4_dict->hashTable[i] -= delta;
680746 }
681 memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
682 lz4ds->base = lz4ds->bufferStart;
683 lz4ds->nextBlock = lz4ds->base + 64 KB;
684 }
685 else
686 {
687 memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
688 lz4ds->nextBlock -= delta;
689 lz4ds->base -= delta;
690 }
691
692 return (char*)(lz4ds->nextBlock);
693 }
694
695
696 int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize)
697 {
698 return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, 0, notLimited, byU32, withPrefix);
699 }
700
701
702 int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize)
703 {
704 return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, maxOutputSize, limited, byU32, withPrefix);
705 }
747 LZ4_dict->currentOffset = 64 KB;
748 if (LZ4_dict->dictSize > 64 KB) LZ4_dict->dictSize = 64 KB;
749 LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize;
750 }
751 }
752
753
754 FORCE_INLINE int LZ4_compress_continue_generic (void* LZ4_stream, const char* source, char* dest, int inputSize,
755 int maxOutputSize, limitedOutput_directive limit)
756 {
757 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_stream;
758 const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
759
760 const BYTE* smallest = (const BYTE*) source;
761 if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */
762 if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd;
763 LZ4_renormDictT(streamPtr, smallest);
764
765 /* Check overlapping input/dictionary space */
766 {
767 const BYTE* sourceEnd = (const BYTE*) source + inputSize;
768 if ((sourceEnd > streamPtr->dictionary) && (sourceEnd < dictEnd))
769 {
770 streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
771 if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB;
772 if (streamPtr->dictSize < 4) streamPtr->dictSize = 0;
773 streamPtr->dictionary = dictEnd - streamPtr->dictSize;
774 }
775 }
776
777 /* prefix mode : source data follows dictionary */
778 if (dictEnd == (const BYTE*)source)
779 {
780 int result;
781 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
782 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, dictSmall);
783 else
784 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, withPrefix64k, noDictIssue);
785 streamPtr->dictSize += (U32)inputSize;
786 streamPtr->currentOffset += (U32)inputSize;
787 return result;
788 }
789
790 /* external dictionary mode */
791 {
792 int result;
793 if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
794 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, dictSmall);
795 else
796 result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limit, byU32, usingExtDict, noDictIssue);
797 streamPtr->dictionary = (const BYTE*)source;
798 streamPtr->dictSize = (U32)inputSize;
799 streamPtr->currentOffset += (U32)inputSize;
800 return result;
801 }
802 }
803
804
805 int LZ4_compress_continue (void* LZ4_stream, const char* source, char* dest, int inputSize)
806 {
807 return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, 0, notLimited);
808 }
809
810 int LZ4_compress_limitedOutput_continue (void* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize)
811 {
812 return LZ4_compress_continue_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput);
813 }
814
815
816 // Hidden debug function, to force separate dictionary mode
817 int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize)
818 {
819 LZ4_stream_t_internal* streamPtr = (LZ4_stream_t_internal*)LZ4_dict;
820 int result;
821 const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
822
823 const BYTE* smallest = dictEnd;
824 if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
825 LZ4_renormDictT((LZ4_stream_t_internal*)LZ4_dict, smallest);
826
827 result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue);
828
829 streamPtr->dictionary = (const BYTE*)source;
830 streamPtr->dictSize = (U32)inputSize;
831 streamPtr->currentOffset += (U32)inputSize;
832
833 return result;
834 }
835
836
837 int LZ4_saveDict (void* LZ4_dict, char* safeBuffer, int dictSize)
838 {
839 LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict;
840 const BYTE* previousDictEnd = dict->dictionary + dict->dictSize;
841
842 if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */
843 if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize;
844
845 memcpy(safeBuffer, previousDictEnd - dictSize, dictSize);
846
847 dict->dictionary = (const BYTE*)safeBuffer;
848 dict->dictSize = (U32)dictSize;
849
850 return 1;
851 }
852
706853
707854
708855 /****************************
709856 Decompression functions
710857 ****************************/
711
712858 /*
713859 * This generic decompression function cover all use cases.
714860 * It shall be instanciated several times, using different sets of directives
722868 int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */
723869
724870 int endOnInput, /* endOnOutputSize, endOnInputSize */
725 int prefix64k, /* noPrefix, withPrefix */
726871 int partialDecoding, /* full, partial */
727 int targetOutputSize /* only used if partialDecoding==partial */
872 int targetOutputSize, /* only used if partialDecoding==partial */
873 int dict, /* noDict, withPrefix64k, usingExtDict */
874 const char* dictStart, /* only if dict==usingExtDict */
875 int dictSize /* note : = 0 if noDict */
728876 )
729877 {
730878 /* Local Variables */
736884 BYTE* const oend = op + outputSize;
737885 BYTE* cpy;
738886 BYTE* oexit = op + targetOutputSize;
739
740 /*const size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0}; / static reduces speed for LZ4_decompress_safe() on GCC64 */
887 const BYTE* const lowLimit = (const BYTE*)dest - dictSize;
888
889 const BYTE* const dictEnd = (const BYTE*)dictStart + dictSize;
890 //#define OLD
891 #ifdef OLD
892 const size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0}; /* static reduces speed for LZ4_decompress_safe() on GCC64 */
893 #else
741894 const size_t dec32table[] = {4-0, 4-3, 4-2, 4-3, 4-0, 4-0, 4-0, 4-0}; /* static reduces speed for LZ4_decompress_safe() on GCC64 */
895 #endif
742896 static const size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3};
897
898 const int checkOffset = (endOnInput) && (dictSize < (int)(64 KB));
743899
744900
745901 /* Special cases */
758914 token = *ip++;
759915 if ((length=(token>>ML_BITS)) == RUN_MASK)
760916 {
761 unsigned s=255;
762 while (((endOnInput)?ip<iend:1) && (s==255))
917 unsigned s;
918 do
763919 {
764920 s = *ip++;
765921 length += s;
766922 }
923 while (likely((endOnInput)?ip<iend-RUN_MASK:1) && (s==255));
924 if ((sizeof(void*)==4) && unlikely(length>LZ4_MAX_INPUT_SIZE)) goto _output_error; /* overflow detection */
767925 }
768926
769927 /* copy literals */
790948
791949 /* get offset */
792950 LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;
793 if ((prefix64k==noPrefix) && (unlikely(ref < (BYTE* const)dest))) goto _output_error; /* Error : offset outside destination buffer */
951 if ((checkOffset) && (unlikely(ref < lowLimit))) goto _output_error; /* Error : offset outside destination buffer */
794952
795953 /* get matchlength */
796954 if ((length=(token&ML_MASK)) == ML_MASK)
797955 {
798 while ((!endOnInput) || (ip<iend-(LASTLITERALS+1))) /* Ensure enough bytes remain for LASTLITERALS + token */
956 unsigned s;
957 do
799958 {
800 unsigned s = *ip++;
959 if (endOnInput && (ip > iend-LASTLITERALS)) goto _output_error;
960 s = *ip++;
801961 length += s;
802 if (s==255) continue;
803 break;
962 } while (s==255);
963 if ((sizeof(void*)==4) && unlikely(length>LZ4_MAX_INPUT_SIZE)) goto _output_error; /* overflow detection */
964 }
965
966 /* check external dictionary */
967 if ((dict==usingExtDict) && (ref < (BYTE* const)dest))
968 {
969 if (unlikely(op+length+MINMATCH > oend-LASTLITERALS)) goto _output_error;
970
971 if (length+MINMATCH <= (size_t)(dest-(char*)ref))
972 {
973 ref = dictEnd - (dest-(char*)ref);
974 memcpy(op, ref, length+MINMATCH);
975 op += length+MINMATCH;
804976 }
977 else
978 {
979 size_t copySize = (size_t)(dest-(char*)ref);
980 memcpy(op, dictEnd - copySize, copySize);
981 op += copySize;
982 copySize = length+MINMATCH - copySize;
983 if (copySize > (size_t)((char*)op-dest)) /* overlap */
984 {
985 BYTE* const cpy = op + copySize;
986 const BYTE* ref = (BYTE*)dest;
987 while (op < cpy) *op++ = *ref++;
988 }
989 else
990 {
991 memcpy(op, dest, copySize);
992 op += copySize;
993 }
994 }
995 continue;
805996 }
806997
807998 /* copy repeated sequence */
8121003 op[1] = ref[1];
8131004 op[2] = ref[2];
8141005 op[3] = ref[3];
815 /*op += 4, ref += 4; ref -= dec32table[op-ref];
1006 #ifdef OLD
1007 op += 4, ref += 4; ref -= dec32table[op-ref];
8161008 A32(op) = A32(ref);
817 op += STEPSIZE-4; ref -= dec64;*/
1009 op += STEPSIZE-4; ref -= dec64;
1010 #else
8181011 ref += dec32table[op-ref];
8191012 A32(op+4) = A32(ref);
8201013 op += STEPSIZE; ref -= dec64;
1014 #endif
8211015 } else { LZ4_COPYSTEP(op,ref); }
8221016 cpy = op + length - (STEPSIZE-4);
8231017
8241018 if (unlikely(cpy>oend-COPYLENGTH-(STEPSIZE-4)))
8251019 {
8261020 if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last 5 bytes must be literals */
827 LZ4_SECURECOPY(op, ref, (oend-COPYLENGTH));
1021 if (op<oend-COPYLENGTH) LZ4_WILDCOPY(op, ref, (oend-COPYLENGTH));
8281022 while(op<cpy) *op++=*ref++;
8291023 op=cpy;
8301024 continue;
8451039 }
8461040
8471041
848 int LZ4_decompress_safe(const char* source, char* dest, int inputSize, int maxOutputSize)
849 {
850 return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, full, 0);
851 }
852
853 int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int inputSize, int maxOutputSize)
854 {
855 return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, withPrefix, full, 0);
856 }
857
858 int LZ4_decompress_safe_partial(const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize)
859 {
860 return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, partial, targetOutputSize);
861 }
862
863 int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int outputSize)
864 {
865 return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
866 }
867
868 int LZ4_decompress_fast(const char* source, char* dest, int outputSize)
869 {
870 #ifdef _MSC_VER /* This version is faster with Visual */
871 return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, noPrefix, full, 0);
872 #else
873 return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
874 #endif
875 }
876
1042 int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxOutputSize)
1043 {
1044 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, noDict, NULL, 0);
1045 }
1046
1047 int LZ4_decompress_safe_partial(const char* source, char* dest, int compressedSize, int targetOutputSize, int maxOutputSize)
1048 {
1049 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, partial, targetOutputSize, noDict, NULL, 0);
1050 }
1051
1052 int LZ4_decompress_fast(const char* source, char* dest, int originalSize)
1053 {
1054 return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, NULL, 0);
1055 }
1056
1057 /* streaming decompression functions */
1058
1059 //#define LZ4_STREAMDECODESIZE_U32 4
1060 //#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U32 * sizeof(unsigned int))
1061 //typedef struct { unsigned int table[LZ4_STREAMDECODESIZE_U32]; } LZ4_streamDecode_t;
1062 typedef struct
1063 {
1064 const char* dictionary;
1065 int dictSize;
1066 } LZ4_streamDecode_t_internal;
1067
1068 /*
1069 * If you prefer dynamic allocation methods,
1070 * LZ4_createStreamDecode()
1071 * provides a pointer (void*) towards an initialized LZ4_streamDecode_t structure.
1072 */
1073 void* LZ4_createStreamDecode()
1074 {
1075 void* lz4s = ALLOCATOR(sizeof(U32), LZ4_STREAMDECODESIZE_U32);
1076 MEM_INIT(lz4s, 0, LZ4_STREAMDECODESIZE);
1077 return lz4s;
1078 }
1079
1080 /*
1081 * LZ4_setDictDecode
1082 * Use this function to instruct where to find the dictionary
1083 * This function is not necessary if previous data is still available where it was decoded.
1084 * Loading a size of 0 is allowed (same effect as no dictionary).
1085 * Return : 1 if OK, 0 if error
1086 */
1087 int LZ4_setDictDecode (void* LZ4_streamDecode, const char* dictionary, int dictSize)
1088 {
1089 LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode;
1090 lz4sd->dictionary = dictionary;
1091 lz4sd->dictSize = dictSize;
1092 return 1;
1093 }
1094
1095 /*
1096 *_continue() :
1097 These decoding functions allow decompression of multiple blocks in "streaming" mode.
1098 Previously decoded blocks must still be available at the memory position where they were decoded.
1099 If it's not possible, save the relevant part of decoded data into a safe buffer,
1100 and indicate where it stands using LZ4_setDictDecode()
1101 */
1102 int LZ4_decompress_safe_continue (void* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize)
1103 {
1104 LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode;
1105 int result;
1106
1107 result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, lz4sd->dictionary, lz4sd->dictSize);
1108 if (result <= 0) return result;
1109 if (lz4sd->dictionary + lz4sd->dictSize == dest)
1110 {
1111 lz4sd->dictSize += result;
1112 }
1113 else
1114 {
1115 lz4sd->dictionary = dest;
1116 lz4sd->dictSize = result;
1117 }
1118
1119 return result;
1120 }
1121
1122 int LZ4_decompress_fast_continue (void* LZ4_streamDecode, const char* source, char* dest, int originalSize)
1123 {
1124 LZ4_streamDecode_t_internal* lz4sd = (LZ4_streamDecode_t_internal*) LZ4_streamDecode;
1125 int result;
1126
1127 result = LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, usingExtDict, lz4sd->dictionary, lz4sd->dictSize);
1128 if (result <= 0) return result;
1129 if (lz4sd->dictionary + lz4sd->dictSize == dest)
1130 {
1131 lz4sd->dictSize += result;
1132 }
1133 else
1134 {
1135 lz4sd->dictionary = dest;
1136 lz4sd->dictSize = result;
1137 }
1138
1139 return result;
1140 }
1141
1142
1143 /*
1144 Advanced decoding functions :
1145 *_usingDict() :
1146 These decoding functions work the same as "_continue" ones,
1147 the dictionary must be explicitly provided within parameters
1148 */
1149
1150 int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize)
1151 {
1152 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, dictStart, dictSize);
1153 }
1154
1155 int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSize, const char* dictStart, int dictSize)
1156 {
1157 return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, usingExtDict, dictStart, dictSize);
1158 }
1159
1160
1161 /***************************************************
1162 Obsolete Functions
1163 ***************************************************/
1164 /*
1165 These function names are deprecated and should no longer be used.
1166 They are only provided here for compatibility with older user programs.
1167 - LZ4_uncompress is totally equivalent to LZ4_decompress_fast
1168 - LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe
1169 */
1170 int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
1171 int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
1172
1173
1174 /* Obsolete Streaming functions */
1175
1176 int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; }
1177
1178 void LZ4_init(LZ4_stream_t_internal* lz4ds, const BYTE* base)
1179 {
1180 MEM_INIT(lz4ds, 0, LZ4_STREAMSIZE);
1181 lz4ds->bufferStart = base;
1182 }
1183
1184 int LZ4_resetStreamState(void* state, const char* inputBuffer)
1185 {
1186 if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */
1187 LZ4_init((LZ4_stream_t_internal*)state, (const BYTE*)inputBuffer);
1188 return 0;
1189 }
1190
1191 void* LZ4_create (const char* inputBuffer)
1192 {
1193 void* lz4ds = ALLOCATOR(4, LZ4_STREAMSIZE_U32);
1194 LZ4_init ((LZ4_stream_t_internal*)lz4ds, (const BYTE*)inputBuffer);
1195 return lz4ds;
1196 }
1197
1198 char* LZ4_slideInputBuffer (void* LZ4_Data)
1199 {
1200 LZ4_stream_t_internal* lz4ds = (LZ4_stream_t_internal*)LZ4_Data;
1201
1202 LZ4_saveDict((LZ4_stream_t*)LZ4_Data, (char*)lz4ds->bufferStart, 64 KB);
1203
1204 return (char*)(lz4ds->bufferStart + 64 KB);
1205 }
1206
1207 /* Obsolete compresson functions using User-allocated state */
1208
1209 int LZ4_sizeofState() { return LZ4_STREAMSIZE; }
1210
1211 int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
1212 {
1213 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
1214 MEM_INIT(state, 0, LZ4_STREAMSIZE);
1215
1216 if (inputSize < (int)LZ4_64KLIMIT)
1217 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue);
1218 else
1219 return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue);
1220 }
1221
1222 int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
1223 {
1224 if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
1225 MEM_INIT(state, 0, LZ4_STREAMSIZE);
1226
1227 if (inputSize < (int)LZ4_64KLIMIT)
1228 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue);
1229 else
1230 return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue);
1231 }
1232
1233 /* Obsolete streaming decompression functions */
1234
1235 int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize)
1236 {
1237 return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, withPrefix64k, NULL, 64 KB);
1238 }
1239
1240 int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize)
1241 {
1242 return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, NULL, 64 KB);
1243 }
00 /*
11 LZ4 - Fast LZ compression algorithm
22 Header File
3 Copyright (C) 2011-2013, Yann Collet.
3 Copyright (C) 2011-2014, Yann Collet.
44 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
55
66 Redistribution and use in source and binary forms, with or without
2727 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 You can contact the author at :
30 - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
3130 - LZ4 source repository : http://code.google.com/p/lz4/
31 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
3232 */
3333 #pragma once
3434
4141 Version
4242 **************************************/
4343 #define LZ4_VERSION_MAJOR 1 /* for major interface/format changes */
44 #define LZ4_VERSION_MINOR 1 /* for minor interface/format changes */
45 #define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
46
47
48 /**************************************
49 Compiler Options
50 **************************************/
51 #if (defined(__GNUC__) && defined(__STRICT_ANSI__)) || (defined(_MSC_VER) && !defined(__cplusplus)) /* Visual Studio */
52 # define inline __inline /* Visual C is not C99, but supports some kind of inline */
53 #endif
44 #define LZ4_VERSION_MINOR 2 /* for minor interface/format changes */
45 #define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */
46
47
48 /**************************************
49 Tuning parameter
50 **************************************/
51 /*
52 * LZ4_MEMORY_USAGE :
53 * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
54 * Increasing memory usage improves compression ratio
55 * Reduced memory usage can improve speed, due to cache effect
56 * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
57 */
58 #define LZ4_MEMORY_USAGE 14
5459
5560
5661 /**************************************
5863 **************************************/
5964
6065 int LZ4_compress (const char* source, char* dest, int inputSize);
61 int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
66 int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxOutputSize);
6267
6368 /*
6469 LZ4_compress() :
7176 or 0 if the compression fails
7277
7378 LZ4_decompress_safe() :
74 maxOutputSize : is the size of the destination buffer (which must be already allocated)
79 compressedSize : is obviously the source size
80 maxOutputSize : is the size of the destination buffer, which must be already allocated.
7581 return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
82 If the destination buffer is not large enough, decoding will stop and output an error code (<0).
7683 If the source stream is detected malformed, the function will stop decoding and return a negative result.
77 This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets
84 This function is protected against buffer overflow exploits :
85 it never writes outside of output buffer, and never reads outside of input buffer.
86 Therefore, it is protected against malicious data packets.
87 */
88
89
90 /*
91 Note :
92 Should you prefer to explicitly allocate compression-table memory using your own allocation method,
93 use the streaming functions provided below, simply reset the memory area between each call to LZ4_compress_continue()
7894 */
7995
8096
8399 **************************************/
84100 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
85101 #define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
86 static inline int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
87102
88103 /*
89104 LZ4_compressBound() :
90105 Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
91106 primarily useful for memory allocation of output buffer.
92 inline function is recommended for the general case,
93107 macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).
94108
95109 isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE
96110 return : maximum output size in a "worst case" scenario
97111 or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
98112 */
99
100
101 int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
113 int LZ4_compressBound(int isize);
114
102115
103116 /*
104117 LZ4_compress_limitedOutput() :
111124 return : the number of bytes written in buffer 'dest'
112125 or 0 if the compression fails
113126 */
114
115
116 int LZ4_decompress_fast (const char* source, char* dest, int outputSize);
127 int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
128
117129
118130 /*
119131 LZ4_decompress_fast() :
120 outputSize : is the original (uncompressed) size
132 originalSize : is the original and therefore uncompressed size
121133 return : the number of bytes read from the source buffer (in other words, the compressed size)
122134 If the source stream is malformed, the function will stop decoding and return a negative result.
135 Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes.
123136 note : This function is a bit faster than LZ4_decompress_safe()
124 This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.
125 Use this function preferably into a trusted environment (data to decode comes from a trusted source).
126 Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
127 */
128
129 int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
137 It provides fast decompression and fully respect memory boundaries for properly formed compressed data.
138 It does not provide full protection against intentionnally modified data stream.
139 Use this function in a trusted environment (data to decode comes from a trusted source).
140 */
141 int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
142
130143
131144 /*
132145 LZ4_decompress_safe_partial() :
133 This function decompress a compressed block of size 'inputSize' at position 'source'
146 This function decompress a compressed block of size 'compressedSize' at position 'source'
134147 into output buffer 'dest' of size 'maxOutputSize'.
135148 The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
136149 reducing decompression time.
140153 If the source stream is detected malformed, the function will stop decoding and return a negative result.
141154 This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
142155 */
143
144
145 int LZ4_sizeofState();
156 int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxOutputSize);
157
158
159 /***********************************************
160 Experimental Streaming Compression Functions
161 ***********************************************/
162
163 #define LZ4_STREAMSIZE_U32 ((1 << (LZ4_MEMORY_USAGE-2)) + 8)
164 #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U32 * sizeof(unsigned int))
165 /*
166 * LZ4_stream_t
167 * information structure to track an LZ4 stream.
168 * important : set this structure content to zero before first use !
169 */
170 typedef struct { unsigned int table[LZ4_STREAMSIZE_U32]; } LZ4_stream_t;
171
172 /*
173 * If you prefer dynamic allocation methods,
174 * LZ4_createStream
175 * provides a pointer (void*) towards an initialized LZ4_stream_t structure.
176 * LZ4_free just frees it.
177 */
178 void* LZ4_createStream();
179 int LZ4_free (void* LZ4_stream);
180
181
182 /*
183 * LZ4_loadDict
184 * Use this function to load a static dictionary into LZ4_stream.
185 * Any previous data will be forgotten, only 'dictionary' will remain in memory.
186 * Loading a size of 0 is allowed (same effect as init).
187 * Return : 1 if OK, 0 if error
188 */
189 int LZ4_loadDict (void* LZ4_stream, const char* dictionary, int dictSize);
190
191 /*
192 * LZ4_compress_continue
193 * Compress data block 'source', using blocks compressed before as dictionary to improve compression ratio
194 * Previous data blocks are assumed to still be present at their previous location.
195 */
196 int LZ4_compress_continue (void* LZ4_stream, const char* source, char* dest, int inputSize);
197
198 /*
199 * LZ4_compress_limitedOutput_continue
200 * Same as before, but also specify a maximum target compressed size (maxOutputSize)
201 * If objective cannot be met, compression exits, and returns a zero.
202 */
203 int LZ4_compress_limitedOutput_continue (void* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize);
204
205 /*
206 * LZ4_saveDict
207 * If previously compressed data block is not guaranteed to remain at its previous memory location
208 * save it into a safe place (char* safeBuffer)
209 * Note : you don't need to call LZ4_loadDict() afterwards,
210 * dictionary is immediately usable, you can therefore call again LZ4_compress_continue()
211 * Return : 1 if OK, 0 if error
212 * Note : any dictSize > 64 KB will be interpreted as 64KB.
213 */
214 int LZ4_saveDict (void* LZ4_stream, char* safeBuffer, int dictSize);
215
216
217 /************************************************
218 Experimental Streaming Decompression Functions
219 ************************************************/
220
221 #define LZ4_STREAMDECODESIZE_U32 4
222 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U32 * sizeof(unsigned int))
223 /*
224 * LZ4_streamDecode_t
225 * information structure to track an LZ4 stream.
226 * important : set this structure content to zero before first use !
227 */
228 typedef struct { unsigned int table[LZ4_STREAMDECODESIZE_U32]; } LZ4_streamDecode_t;
229
230 /*
231 * If you prefer dynamic allocation methods,
232 * LZ4_createStreamDecode()
233 * provides a pointer (void*) towards an initialized LZ4_streamDecode_t structure.
234 * LZ4_free just frees it.
235 */
236 void* LZ4_createStreamDecode();
237 int LZ4_free (void* LZ4_stream); /* yes, it's the same one as for compression */
238
239 /*
240 *_continue() :
241 These decoding functions allow decompression of multiple blocks in "streaming" mode.
242 Previously decoded blocks must still be available at the memory position where they were decoded.
243 If it's not possible, save the relevant part of decoded data into a safe buffer,
244 and indicate where it stands using LZ4_setDictDecode()
245 */
246 int LZ4_decompress_safe_continue (void* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize);
247 int LZ4_decompress_fast_continue (void* LZ4_streamDecode, const char* source, char* dest, int originalSize);
248
249 /*
250 * LZ4_setDictDecode
251 * Use this function to instruct where to find the dictionary.
252 * This function can be used to specify a static dictionary,
253 * or to instruct where to find some previously decoded data saved into a different memory space.
254 * Setting a size of 0 is allowed (same effect as no dictionary).
255 * Return : 1 if OK, 0 if error
256 */
257 int LZ4_setDictDecode (void* LZ4_streamDecode, const char* dictionary, int dictSize);
258
259
260 /*
261 Advanced decoding functions :
262 *_usingDict() :
263 These decoding functions work the same as
264 a combination of LZ4_setDictDecode() followed by LZ4_decompress_x_continue()
265 all together into a single function call.
266 It doesn't use nor update an LZ4_streamDecode_t structure.
267 */
268 int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize);
269 int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize);
270
271
272
273
274 /**************************************
275 Obsolete Functions
276 **************************************/
277 /*
278 Obsolete decompression functions
279 These function names are deprecated and should no longer be used.
280 They are only provided here for compatibility with older user programs.
281 - LZ4_uncompress is the same as LZ4_decompress_fast
282 - LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe
283 */
284 int LZ4_uncompress (const char* source, char* dest, int outputSize);
285 int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
286
287 /* Obsolete functions for externally allocated state; use streaming interface instead */
288 int LZ4_sizeofState(void);
146289 int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
147290 int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
148291
149 /*
150 These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
151 To know how much memory must be allocated for the compression tables, use :
152 int LZ4_sizeofState();
153
154 Note that tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).
155
156 The allocated memory can be provided to the compressions functions using 'void* state' parameter.
157 LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.
158 They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).
159 */
160
161
162 /**************************************
163 Streaming Functions
164 **************************************/
292 /* Obsolete streaming functions; use new streaming interface whenever possible */
165293 void* LZ4_create (const char* inputBuffer);
166 int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
167 int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
168 char* LZ4_slideInputBuffer (void* LZ4_Data);
169 int LZ4_free (void* LZ4_Data);
170
171 /*
172 These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
173 In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :
174
175 void* LZ4_create (const char* inputBuffer);
176 The result of the function is the (void*) pointer on the LZ4 Data Structure.
177 This pointer will be needed in all other functions.
178 If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
179 The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
180 The input buffer must be already allocated, and size at least 192KB.
181 'inputBuffer' will also be the 'const char* source' of the first block.
182
183 All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
184 To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().
185 Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(),
186 but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.
187 If next block does not begin immediately after the previous one, the compression will fail (return 0).
188
189 When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :
190 char* LZ4_slideInputBuffer(void* LZ4_Data);
191 must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
192 Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
193 ==> The memory position where the next input data block must start is provided as the result of the function.
194
195 Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.
196
197 When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.
198 */
199
200 int LZ4_sizeofStreamState();
201 int LZ4_resetStreamState(void* state, const char* inputBuffer);
202
203 /*
204 These functions achieve the same result as :
205 void* LZ4_create (const char* inputBuffer);
206
207 They are provided here to allow the user program to allocate memory using its own routines.
208
209 To know how much space must be allocated, use LZ4_sizeofStreamState();
210 Note also that space must be 4-bytes aligned.
211
212 Once space is allocated, you must initialize it using : LZ4_resetStreamState(void* state, const char* inputBuffer);
213 void* state is a pointer to the space allocated.
214 It must be aligned on 4-bytes boundaries, and be large enough.
215 The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
216 The input buffer must be already allocated, and size at least 192KB.
217 'inputBuffer' will also be the 'const char* source' of the first block.
218
219 The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().
220 return value of LZ4_resetStreamState() must be 0 is OK.
221 Any other value means there was an error (typically, pointer is not aligned on 4-bytes boundaries).
222 */
223
224
225 int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);
226 int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);
227
228 /*
229 *_withPrefix64k() :
230 These decoding functions work the same as their "normal name" versions,
231 but can use up to 64KB of data in front of 'char* dest'.
232 These functions are necessary to decode inter-dependant blocks.
233 */
234
235
236 /**************************************
237 Obsolete Functions
238 **************************************/
239 /*
240 These functions are deprecated and should no longer be used.
241 They are provided here for compatibility with existing user programs.
242 */
243 static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
244 static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
245
294 int LZ4_sizeofStreamState(void);
295 int LZ4_resetStreamState(void* state, const char* inputBuffer);
296 char* LZ4_slideInputBuffer (void* state);
297
298 /* Obsolete streaming decoding functions */
299 int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int compressedSize, int maxOutputSize);
300 int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int originalSize);
246301
247302
248303 #if defined (__cplusplus)
249304 }
250305 #endif
251
2929 #include "wave_locale.h"
3030
3131 static char *match = NULL;
32 static int matchlen = 0;
32 static uint32_t matchlen = 0;
3333 static int names_only = 0;
3434 static char *killed_list = NULL;
3535 char killed_value = 1;
105105
106106 static char *get_facname(void *lt, fstHandle pnt_facidx)
107107 {
108 (void) lt;
109
108110 if(scope_idx[pnt_facidx] && scope_names[scope_idx[pnt_facidx]])
109111 {
110112 char *fst_scope_name = scope_names[scope_idx[pnt_facidx]];
251253 char *lxname=NULL;
252254 int c;
253255 int rc;
254 int i, j, k;
256 uint32_t i, j, k;
255257 int comprehensive = 0;
256258
257259
184184 {
185185 lxtint32_t idx = top_elem - lt->next_radix;
186186 unsigned int vch;
187 int i;
187 lxtint32_t i;
188188
189189 switch(lt->fac_curpos_width)
190190 {
298298 {
299299 unsigned int vch;
300300 unsigned int which_time;
301 int i;
301 lxtint32_t i;
302302 int uniq = 0;
303303
304304 switch(lt->fac_curpos_width)
416416 else
417417 if(lt->len[idx] > b->string_lens[vch])
418418 {
419 int lendelta = lt->len[idx] - b->string_lens[vch];
419 lxtint32_t lendelta = lt->len[idx] - b->string_lens[vch];
420420 int fill = (b->string_pointers[vch][0]!='1') ? b->string_pointers[vch][0] : '0';
421421
422422 for(i=0;i<lendelta;i++)
473473 static void lxt2_rd_build_radix(struct lxt2_rd_trace *lt, struct lxt2_rd_block *b, int granule,
474474 lxtint32_t strtfac, lxtint32_t endfac)
475475 {
476 int i;
476 lxtint32_t i;
477477 int offset;
478478
479479 for(i=0;i<LXT2_RD_GRANULE_SIZE+1;i++) /* +1 because tzc returns 33/65 when its arg == 0 */
514514 */
515515 static void lxt2_rd_regenerate_process_mask(struct lxt2_rd_trace *lt)
516516 {
517 int i, j, lim, idx;
517 lxtint32_t i;
518 int j, lim, idx;
518519
519520 if((lt)&&(lt->process_mask_dirty))
520521 {
559560 {
560561 char vld;
561562 char *pnt;
562 int i;
563 lxtint32_t i;
563564 int granule = 0;
564565 char sect_typ;
565566 lxtint32_t strtfac_gran=0;
743744 */
744745 void lxt2_rd_null_callback(struct lxt2_rd_trace **lt, lxtint64_t *pnt_time, lxtint32_t *pnt_facidx, char **pnt_value)
745746 {
747 (void) lt;
748 (void) pnt_time;
749 (void) pnt_facidx;
750 (void) pnt_value;
751
746752 /* fprintf(stderr, LXT2_RDLOAD"%lld %d %s\n", *pnt_time, *pnt_facidx, *pnt_value); */
747753 }
748754
755761 struct lxt2_rd_trace *lxt2_rd_init(const char *name)
756762 {
757763 struct lxt2_rd_trace *lt=(struct lxt2_rd_trace *)calloc(1, sizeof(struct lxt2_rd_trace));
758 int i;
764 lxtint32_t i;
759765
760766 if(!(lt->handle=fopen(name, "rb")))
761767 {
855861 rc=gzread(lt->zhandle, m, lt->zfacname_predec_size);
856862 gzclose(lt->zhandle); lt->zhandle=NULL;
857863
858 if(rc!=lt->zfacname_predec_size)
864 if(((lxtint32_t)rc)!=lt->zfacname_predec_size)
859865 {
860866 fprintf(stderr, LXT2_RDLOAD"*** name section mangled %d (act) vs "LXT2_RD_LD" (exp)\n", rc, lt->zfacname_predec_size);
861867 free(m);
10221028 if(lt)
10231029 {
10241030 struct lxt2_rd_block *b, *bt;
1025 int i;
1031 lxtint32_t i;
10261032
10271033 if(lt->process_mask) { free(lt->process_mask); lt->process_mask=NULL; }
10281034 if(lt->process_mask_compressed) { free(lt->process_mask_compressed); lt->process_mask_compressed=NULL; }
12321238 char *lxt2_rd_get_facname(struct lxt2_rd_trace *lt, lxtint32_t facidx)
12331239 {
12341240 char *pnt;
1235 int clone, j;
1241 lxtint32_t clone, j;
12361242
12371243 if(lt)
12381244 {
14611467 int striped_kill = 0;
14621468 unsigned int real_uncompressed_siz = 0;
14631469 unsigned char gzid[2];
1464 int i;
1470 lxtint32_t i;
14651471
14661472 if(lt)
14671473 {
15001506 char *pnt;
15011507 off_t fspos = b->filepos;
15021508
1503 int zlen = 16;
1509 lxtint32_t zlen = 16;
15041510 char *zbuff=malloc(zlen);
15051511 struct z_stream_s strm;
15061512
15761582 lt->zhandle = gzdopen(dup(fileno(lt->handle)), "rb");
15771583 rc=gzread(lt->zhandle, b->mem, b->uncompressed_siz);
15781584 gzclose(lt->zhandle); lt->zhandle=NULL;
1579 if(rc!=b->uncompressed_siz)
1585 if(((lxtint32_t)rc)!=b->uncompressed_siz)
15801586 {
15811587 fprintf(stderr, LXT2_RDLOAD"short read on block %d vs "LXT2_RD_LD" (exp), ignoring\n", rc, b->uncompressed_siz);
15821588 free(b->mem); b->mem=NULL;
264264 struct lxt2_rd_trace * lxt2_rd_init(const char *name);
265265 void lxt2_rd_close(struct lxt2_rd_trace *lt);
266266
267 _LXT2_RD_INLINE lxtint64_t lxt2_rd_set_max_block_mem_usage(struct lxt2_rd_trace *lt, lxtint64_t block_mem_max);
268 _LXT2_RD_INLINE lxtint64_t lxt2_rd_get_block_mem_usage(struct lxt2_rd_trace *lt);
269 _LXT2_RD_INLINE unsigned int lxt2_rd_get_num_blocks(struct lxt2_rd_trace *lt);
267 lxtint64_t lxt2_rd_set_max_block_mem_usage(struct lxt2_rd_trace *lt, lxtint64_t block_mem_max);
268 lxtint64_t lxt2_rd_get_block_mem_usage(struct lxt2_rd_trace *lt);
269 unsigned int lxt2_rd_get_num_blocks(struct lxt2_rd_trace *lt);
270270 unsigned int lxt2_rd_get_num_active_blocks(struct lxt2_rd_trace *lt);
271271
272 _LXT2_RD_INLINE lxtint32_t lxt2_rd_get_num_facs(struct lxt2_rd_trace *lt);
272 lxtint32_t lxt2_rd_get_num_facs(struct lxt2_rd_trace *lt);
273273 char * lxt2_rd_get_facname(struct lxt2_rd_trace *lt, lxtint32_t facidx);
274274 struct lxt2_rd_geometry * lxt2_rd_get_fac_geometry(struct lxt2_rd_trace *lt, lxtint32_t facidx);
275 _LXT2_RD_INLINE lxtint32_t lxt2_rd_get_fac_rows(struct lxt2_rd_trace *lt, lxtint32_t facidx);
276 _LXT2_RD_INLINE lxtsint32_t lxt2_rd_get_fac_msb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
277 _LXT2_RD_INLINE lxtsint32_t lxt2_rd_get_fac_lsb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
278 _LXT2_RD_INLINE lxtint32_t lxt2_rd_get_fac_flags(struct lxt2_rd_trace *lt, lxtint32_t facidx);
279 _LXT2_RD_INLINE lxtint32_t lxt2_rd_get_fac_len(struct lxt2_rd_trace *lt, lxtint32_t facidx);
280 _LXT2_RD_INLINE lxtint32_t lxt2_rd_get_alias_root(struct lxt2_rd_trace *lt, lxtint32_t facidx);
281
282 _LXT2_RD_INLINE char lxt2_rd_get_timescale(struct lxt2_rd_trace *lt);
283 _LXT2_RD_INLINE lxtsint64_t lxt2_rd_get_timezero(struct lxt2_rd_trace *lt);
284 _LXT2_RD_INLINE lxtint64_t lxt2_rd_get_start_time(struct lxt2_rd_trace *lt);
285 _LXT2_RD_INLINE lxtint64_t lxt2_rd_get_end_time(struct lxt2_rd_trace *lt);
286
287 _LXT2_RD_INLINE int lxt2_rd_get_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
288 _LXT2_RD_INLINE int lxt2_rd_set_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
289 _LXT2_RD_INLINE int lxt2_rd_clr_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
290 _LXT2_RD_INLINE int lxt2_rd_set_fac_process_mask_all(struct lxt2_rd_trace *lt);
291 _LXT2_RD_INLINE int lxt2_rd_clr_fac_process_mask_all(struct lxt2_rd_trace *lt);
275 lxtint32_t lxt2_rd_get_fac_rows(struct lxt2_rd_trace *lt, lxtint32_t facidx);
276 lxtsint32_t lxt2_rd_get_fac_msb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
277 lxtsint32_t lxt2_rd_get_fac_lsb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
278 lxtint32_t lxt2_rd_get_fac_flags(struct lxt2_rd_trace *lt, lxtint32_t facidx);
279 lxtint32_t lxt2_rd_get_fac_len(struct lxt2_rd_trace *lt, lxtint32_t facidx);
280 lxtint32_t lxt2_rd_get_alias_root(struct lxt2_rd_trace *lt, lxtint32_t facidx);
281
282 char lxt2_rd_get_timescale(struct lxt2_rd_trace *lt);
283 lxtsint64_t lxt2_rd_get_timezero(struct lxt2_rd_trace *lt);
284 lxtint64_t lxt2_rd_get_start_time(struct lxt2_rd_trace *lt);
285 lxtint64_t lxt2_rd_get_end_time(struct lxt2_rd_trace *lt);
286
287 int lxt2_rd_get_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
288 int lxt2_rd_set_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
289 int lxt2_rd_clr_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
290 int lxt2_rd_set_fac_process_mask_all(struct lxt2_rd_trace *lt);
291 int lxt2_rd_clr_fac_process_mask_all(struct lxt2_rd_trace *lt);
292292
293293 /* null value_change_callback calls an empty dummy function */
294294 int lxt2_rd_iter_blocks(struct lxt2_rd_trace *lt,
295295 void (*value_change_callback)(struct lxt2_rd_trace **lt, lxtint64_t *time, lxtint32_t *facidx, char **value),
296296 void *user_callback_data_pointer);
297 _LXT2_RD_INLINE void * lxt2_rd_get_user_callback_data_pointer(struct lxt2_rd_trace *lt);
297 void * lxt2_rd_get_user_callback_data_pointer(struct lxt2_rd_trace *lt);
298298
299299 /* time (un)/restricted read ops */
300300 unsigned int lxt2_rd_limit_time_range(struct lxt2_rd_trace *lt, lxtint64_t strt_time, lxtint64_t end_time);
577577
578578 static void lxt2_wr_emitfacs(struct lxt2_wr_trace *lt)
579579 {
580 int i;
580 unsigned int i;
581581
582582 if((lt)&&(lt->numfacs))
583583 {
584584 struct lxt2_wr_symbol *s = lt->symchain;
585585 struct lxt2_wr_symbol **aliascache = calloc(lt->numalias ? lt->numalias : 1, sizeof(struct lxt2_wr_symbol *));
586 int aliases_encountered, facs_encountered;
586 unsigned int aliases_encountered, facs_encountered;
587587
588588 lt->sorted_facs = (struct lxt2_wr_symbol **)calloc(lt->numfacs, sizeof(struct lxt2_wr_symbol *));
589589
10561056 for(cnt = 0; cnt < lt->break_header_size; cnt += sizeof(buf))
10571057 {
10581058 seg = lt->break_header_size - cnt;
1059 if(seg > sizeof(buf))
1059 if(seg > (off_t)sizeof(buf))
10601060 {
10611061 seg = sizeof(buf);
10621062 }
13681368 for(i=0;i<lt->num_map_entries;i++)
13691369 {
13701370 /* fprintf(stderr, "+++ %08x (%d)(%d)\n", dt->item, i, dt->val); */
1371 if(dt->val != i)
1371 if(((unsigned int)dt->val) != i)
13721372 {
13731373 fprintf(stderr, "internal error line %d\n", __LINE__);
13741374 exit(255);
162162 struct lxt2_wr_symbol *sym[LXT2_WR_SYMPRIME];
163163 struct lxt2_wr_symbol **sorted_facs;
164164 struct lxt2_wr_symbol *symchain;
165 int numfacs, numalias;
165 unsigned int numfacs, numalias;
166166 int numfacbytes;
167167 int longestname;
168168
173173 lxtstime_t timezero;
174174 unsigned int timegranule;
175175 int timescale;
176 int timepos;
176 unsigned int timepos;
177177 unsigned int maxgranule;
178178 lxttime_t firsttime, lasttime;
179179 lxttime_t timetable[LXT2_WR_GRANULE_SIZE];
2929 #include "wave_locale.h"
3030
3131 static char *match = NULL;
32 static int matchlen = 0;
32 static unsigned int matchlen = 0;
3333 static int names_only = 0;
3434 static char *killed_list = NULL;
3535 char killed_value = 1;
180180 char *lxname=NULL;
181181 int c;
182182 int rc;
183 int i, j, k;
183 unsigned int i;
184 int j, k;
184185 int comprehensive = 0;
185186
186187 WAVE_LOCALE_FIX
10031003
10041004 static void lt_finalize_dictionary(struct lt_trace *lt)
10051005 {
1006 int i;
1006 unsigned int i;
10071007
10081008 lt->sorted_dict = calloc(lt->num_dict_entries, sizeof(dslxt_Tree *));
10091009
15931593 /*
15941594 * emission for trace values..
15951595 */
1596 static unsigned int lt_optimask[]=
1596 static int lt_optimask[]=
15971597 {
15981598 0x00000000,
15991599
16731673 if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
16741674 {
16751675 int numbytes; /* number of bytes to store value minus one */
1676 int len = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
1676 unsigned int len = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
16771677 unsigned int last_change_delta;
16781678
16791679 if((lt->clock_compress)&&(s->rows==0))
22822282 char prevch;
22832283 unsigned int last_change_delta;
22842284
2285 int len = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
2285 unsigned int len = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
22862286
22872287 if((lt->clock_compress)&&(s->rows==0))
22882288 {
22902290 {
22912291 int legal = 0;
22922292 int ivalue = 0;
2293 int i;
2293 unsigned int i;
22942294 char *pntv = value;
22952295 int delta1, delta2;
22962296
25882588
25892589 if(!tagadd)
25902590 {
2591 int len2 = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
2591 unsigned int len2 = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
25922592 if((mvl & (LT_MVL_2|LT_MVL_4|LT_MVL_9)) == LT_MVL_2)
25932593 {
2594 int i;
2594 unsigned int i;
25952595 int bitpos = 7;
25962596 int outval = 0;
25972597 int thisval= 0;
26752675 else
26762676 if((mvl & (LT_MVL_4|LT_MVL_9)) == LT_MVL_4)
26772677 {
2678 int i;
2678 unsigned int i;
26792679 int bitpos = 6;
26802680 int outval = 0;
26812681 int thisval= 0;
27092709 else
27102710 /* if(mvl & LT_MVL_9) */
27112711 {
2712 int i;
2712 unsigned int i;
27132713 int bitpos = 4;
27142714 int outval = 0;
27152715 int thisval= 0;
9393 if((rc = *consume_ptr))
9494 {
9595 unsigned int len = get_32(consume_ptr+1);
96 int i;
96 unsigned int i;
9797
9898 for(i=0;i<len;i++)
9999 {
106106 if(pnt)
107107 {
108108 pnt++;
109 sscanf(pnt, "%d", &numfacs);
109 sscanf(pnt, "%u", &numfacs);
110110 }
111111 }
112112 break;
440440 #ifdef VCD2FST_EXTLOADERS_CONV
441441 static int suffix_check(const char *s, const char *sfx)
442442 {
443 int sfxlen = strlen(sfx);
443 size_t sfxlen = strlen(sfx);
444444 return((strlen(s)>=sfxlen)&&(!strcasecmp(s+strlen(s)-sfxlen,sfx)));
445445 }
446446 #endif
457457 fstHandle returnedhandle;
458458 JRB node;
459459 uint64_t prev_tim = 0;
460 size_t bin_fixbuff_len = 65537;
460 ssize_t bin_fixbuff_len = 65537;
461461 char *bin_fixbuff = NULL;
462462 int hash_kill = 0;
463463 unsigned int hash_max = 0;
312312 vztint64_t *times=NULL;
313313 vztint32_t *change_dict=NULL;
314314 vztint32_t *val_dict=NULL;
315 int num_time_ticks, num_sections, num_dict_entries;
315 unsigned int num_time_ticks, num_sections, num_dict_entries;
316316 char *pnt = b->mem;
317 int i, j, m, num_dict_words;
317 vztint32_t i, j, m, num_dict_words;
318318 /* vztint32_t *block_end = (vztint32_t *)(pnt + b->uncompressed_siz); */
319319 vztint32_t *val_tmp;
320320 unsigned int num_bitplanes;
498498
499499 vztint32_t vzt_rd_next_value_chg_time(struct vzt_rd_trace *lt, struct vzt_rd_block *b, vztint32_t time_offset, vztint32_t facidx)
500500 {
501 int i;
501 unsigned int i;
502502 vztint32_t len = lt->len[facidx];
503503 vztint32_t vindex_offset = lt->vindex_offset[facidx];
504504 vztint32_t vindex_offset_x = vindex_offset + lt->total_values;
588588 int vzt_rd_fac_value(struct vzt_rd_trace *lt, struct vzt_rd_block *b, vztint32_t time_offset, vztint32_t facidx, char *value)
589589 {
590590 vztint32_t len = lt->len[facidx];
591 int i;
591 unsigned int i;
592592 int word = time_offset / 32;
593593 int bit = time_offset & 31;
594594 int row_size = b->num_sections;
803803 */
804804 int vzt_rd_process_block(struct vzt_rd_trace *lt, struct vzt_rd_block *b)
805805 {
806 int i, i2;
806 unsigned int i, i2;
807807 vztint32_t idx;
808808 char *pnt=lt->value_current_sector, *pnt2=lt->value_previous_sector;
809809 char buf[32];
948948 */
949949 void vzt_rd_null_callback(struct vzt_rd_trace **lt, vztint64_t *pnt_time, vztint32_t *pnt_facidx, char **pnt_value)
950950 {
951 (void) lt;
952 (void) pnt_time;
953 (void) pnt_facidx;
954 (void) pnt_value;
955
951956 /* fprintf(stderr, VZT_RDLOAD"%lld %d %s\n", *pnt_time, *pnt_facidx, *pnt_value); */
952957 }
953958
11031108 char *vzt_rd_get_facname(struct vzt_rd_trace *lt, vztint32_t facidx)
11041109 {
11051110 char *pnt;
1106 int clonecnt, j;
1111 unsigned int clonecnt, j;
11071112
11081113 if(lt)
11091114 {
12421247 _VZT_RD_INLINE int vzt_rd_set_fac_process_mask_all(struct vzt_rd_trace *lt)
12431248 {
12441249 int rc=0;
1245 int i;
1250 unsigned int i;
12461251
12471252 if(lt)
12481253 {
13561361
13571362 static void vzt_rd_decompress_blk(struct vzt_rd_trace *lt, struct vzt_rd_block *b, int reopen)
13581363 {
1359 int rc;
1364 unsigned int rc;
13601365 void *zhandle;
13611366 FILE *handle;
13621367 if(reopen)
16691674 struct vzt_rd_trace *vzt_rd_init_smp(const char *name, unsigned int num_cpus)
16701675 {
16711676 struct vzt_rd_trace *lt=(struct vzt_rd_trace *)calloc(1, sizeof(struct vzt_rd_trace));
1672 int i;
1677 unsigned int i;
16731678 unsigned int vindex_offset;
16741679
16751680 if(!(lt->handle=fopen(name, "rb")))
17171722 else
17181723 {
17191724 size_t rcf;
1720 int rc;
1725 unsigned int rc;
17211726 char *m;
17221727 off_t pos, fend;
1723 int t;
1728 unsigned int t;
17241729 struct vzt_rd_block *b;
17251730
17261731 vzt_rd_pthread_mutex_init(lt, &lt->mutex, NULL);
20042009 }
20052010 else
20062011 {
2007 int old_longest_len = lt->longest_len;
2012 unsigned int old_longest_len = lt->longest_len;
20082013 int pmxlen = 31;
20092014 char *pbuff = malloc(pmxlen+1);
20102015 char *pname;
20112016 int plen, plen2;
2012 int i;
2017 unsigned int i;
20132018 int pidx;
20142019 int num_after_combine = lt->numfacs;
20152020 int num_synvecs = 0;
20182023
20192024 for(i=0;i<lt->numfacs-1;i++)
20202025 {
2021 int j;
2026 unsigned int j;
20222027
20232028 if(lt->len[i] != 1) continue;
20242029
20632068 {
20642069 if(lt->flags[i] & VZT_RD_SYM_F_ALIAS) /* not necessary, only for sanity */
20652070 {
2066 int j = vzt_rd_get_alias_root(lt, i);
2067 int k, l;
2071 unsigned int j = vzt_rd_get_alias_root(lt, i);
2072 unsigned int k, l;
20682073
20692074 if(lt->len[i])
20702075 {
20762081
20772082 if(lt->len[i]==lt->len[j])
20782083 {
2079 int nfm1 = lt->numfacs-1;
2084 unsigned int nfm1 = lt->numfacs-1;
20802085 if((i != nfm1) && (j != nfm1))
20812086 {
20822087 if(lt->len[i+1] && lt->len[j+1])
22532258 */
22542259 static char *vzt_rd_process_block_single_factime(struct vzt_rd_trace *lt, struct vzt_rd_block *b, vztint64_t simtime, vztint32_t idx)
22552260 {
2256 int i;
2261 unsigned int i;
22572262 char *pnt=lt->value_current_sector; /* convenient workspace mem */
22582263 char *buf = lt->value_previous_sector; /* convenient workspace mem */
22592264 char *rcval = NULL;
22612266 vzt_rd_block_vch_decode(lt, b);
22622267 vzt_rd_pthread_mutex_lock(lt, &b->mutex);
22632268
2264 if((b->last_rd_value_simtime == simtime) && (b->last_rd_value_idx != ~0))
2269 if((b->last_rd_value_simtime == simtime) && (b->last_rd_value_idx != ((vztint32_t)~0)))
22652270 {
22662271 i = b->last_rd_value_idx;
22672272 }
157157 vztint32_t *change_dict;
158158 vztint32_t *val_dict;
159159 char **sindex;
160 int num_time_ticks, num_sections, num_dict_entries, num_str_entries;
160 unsigned int num_time_ticks, num_sections, num_dict_entries, num_str_entries;
161161
162162 off_t filepos; /* where block starts in file if we have to reload */
163163
237237 vztint64_t block_mem_consumed, block_mem_max;
238238 pthread_mutex_t mutex; /* for these */
239239
240 int pthreads; /* pthreads are enabled, set to max processor # (starting at zero for a uni) */
240 unsigned int pthreads; /* pthreads are enabled, set to max processor # (starting at zero for a uni) */
241241 unsigned process_linear : 1; /* set by gtkwave for read optimization */
242242 unsigned vectorize : 1; /* set when coalescing blasted bitvectors */
243243 };
250250 struct vzt_rd_trace * vzt_rd_init_smp(const char *name, unsigned int num_cpus);
251251 void vzt_rd_close(struct vzt_rd_trace *lt);
252252
253 _VZT_RD_INLINE vztint64_t vzt_rd_set_max_block_mem_usage(struct vzt_rd_trace *lt, vztint64_t block_mem_max);
254 _VZT_RD_INLINE vztint64_t vzt_rd_get_block_mem_usage(struct vzt_rd_trace *lt);
255 _VZT_RD_INLINE unsigned int vzt_rd_get_num_blocks(struct vzt_rd_trace *lt);
253 vztint64_t vzt_rd_set_max_block_mem_usage(struct vzt_rd_trace *lt, vztint64_t block_mem_max);
254 vztint64_t vzt_rd_get_block_mem_usage(struct vzt_rd_trace *lt);
255 unsigned int vzt_rd_get_num_blocks(struct vzt_rd_trace *lt);
256256 unsigned int vzt_rd_get_num_active_blocks(struct vzt_rd_trace *lt);
257257
258 _VZT_RD_INLINE vztint32_t vzt_rd_get_num_facs(struct vzt_rd_trace *lt);
258 vztint32_t vzt_rd_get_num_facs(struct vzt_rd_trace *lt);
259259 char * vzt_rd_get_facname(struct vzt_rd_trace *lt, vztint32_t facidx);
260260 struct vzt_rd_geometry * vzt_rd_get_fac_geometry(struct vzt_rd_trace *lt, vztint32_t facidx);
261 _VZT_RD_INLINE vztint32_t vzt_rd_get_fac_rows(struct vzt_rd_trace *lt, vztint32_t facidx);
262 _VZT_RD_INLINE vztsint32_t vzt_rd_get_fac_msb(struct vzt_rd_trace *lt, vztint32_t facidx);
263 _VZT_RD_INLINE vztsint32_t vzt_rd_get_fac_lsb(struct vzt_rd_trace *lt, vztint32_t facidx);
264 _VZT_RD_INLINE vztint32_t vzt_rd_get_fac_flags(struct vzt_rd_trace *lt, vztint32_t facidx);
265 _VZT_RD_INLINE vztint32_t vzt_rd_get_fac_len(struct vzt_rd_trace *lt, vztint32_t facidx);
266 _VZT_RD_INLINE vztint32_t vzt_rd_get_alias_root(struct vzt_rd_trace *lt, vztint32_t facidx);
267
268 _VZT_RD_INLINE char vzt_rd_get_timescale(struct vzt_rd_trace *lt);
269 _VZT_RD_INLINE vztint64_t vzt_rd_get_start_time(struct vzt_rd_trace *lt);
270 _VZT_RD_INLINE vztint64_t vzt_rd_get_end_time(struct vzt_rd_trace *lt);
271 _VZT_RD_INLINE vztsint64_t vzt_rd_get_timezero(struct vzt_rd_trace *lt);
272
273 _VZT_RD_INLINE int vzt_rd_get_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
274 _VZT_RD_INLINE int vzt_rd_set_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
275 _VZT_RD_INLINE int vzt_rd_clr_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
276 _VZT_RD_INLINE int vzt_rd_set_fac_process_mask_all(struct vzt_rd_trace *lt);
277 _VZT_RD_INLINE int vzt_rd_clr_fac_process_mask_all(struct vzt_rd_trace *lt);
261 vztint32_t vzt_rd_get_fac_rows(struct vzt_rd_trace *lt, vztint32_t facidx);
262 vztsint32_t vzt_rd_get_fac_msb(struct vzt_rd_trace *lt, vztint32_t facidx);
263 vztsint32_t vzt_rd_get_fac_lsb(struct vzt_rd_trace *lt, vztint32_t facidx);
264 vztint32_t vzt_rd_get_fac_flags(struct vzt_rd_trace *lt, vztint32_t facidx);
265 vztint32_t vzt_rd_get_fac_len(struct vzt_rd_trace *lt, vztint32_t facidx);
266 vztint32_t vzt_rd_get_alias_root(struct vzt_rd_trace *lt, vztint32_t facidx);
267
268 char vzt_rd_get_timescale(struct vzt_rd_trace *lt);
269 vztint64_t vzt_rd_get_start_time(struct vzt_rd_trace *lt);
270 vztint64_t vzt_rd_get_end_time(struct vzt_rd_trace *lt);
271 vztsint64_t vzt_rd_get_timezero(struct vzt_rd_trace *lt);
272
273 int vzt_rd_get_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
274 int vzt_rd_set_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
275 int vzt_rd_clr_fac_process_mask(struct vzt_rd_trace *lt, vztint32_t facidx);
276 int vzt_rd_set_fac_process_mask_all(struct vzt_rd_trace *lt);
277 int vzt_rd_clr_fac_process_mask_all(struct vzt_rd_trace *lt);
278278
279279 /* null value_change_callback calls an empty dummy function */
280280 int vzt_rd_iter_blocks(struct vzt_rd_trace *lt,
281281 void (*value_change_callback)(struct vzt_rd_trace **lt, vztint64_t *time, vztint32_t *facidx, char **value),
282282 void *user_callback_data_pointer);
283 _VZT_RD_INLINE void * vzt_rd_get_user_callback_data_pointer(struct vzt_rd_trace *lt);
283 void * vzt_rd_get_user_callback_data_pointer(struct vzt_rd_trace *lt);
284284 void vzt_rd_process_blocks_linearly(struct vzt_rd_trace *lt, int doit);
285285
286286 /* time (un)/restricted read ops */
11061106 for(cnt = 0; cnt < lt->break_header_size; cnt += sizeof(buf))
11071107 {
11081108 seg = lt->break_header_size - cnt;
1109 if(seg > sizeof(buf))
1109 if(seg > (off_t)sizeof(buf))
11101110 {
11111111 seg = sizeof(buf);
11121112 }
12201220 int i, j;
12211221 vztsint32_t k;
12221222 int val;
1223 int numticks;
1223 unsigned int numticks;
12241224
12251225 if(!lt->timegranule)
12261226 {
13621362 else
13631363 {
13641364 vzt_wr_emit_uv32z(lt, numticks); /* number of time ticks */
1365 for(i=0;i<numticks;i++)
1365 for(i=0;i<((int)numticks);i++)
13661366 {
13671367 vzt_wr_emit_uv64z(lt, i ? lt->timetable[i] - lt->timetable[i-1] : lt->timetable[i]); /* emit delta */
13681368 }
14231423 for(i=0;i<lt->numstrings;i++)
14241424 {
14251425 /* fprintf(stderr, "%8d %8d) '%s'\n", ds->val, i, ds->item); */
1426 if(ds->val != i)
1426 if(ds->val != ((vztint32_t)i))
14271427 {
14281428 fprintf(stderr, "internal error line %d\n", __LINE__);
14291429 exit(255);
3030 #include "wave_locale.h"
3131
3232 static char *match = NULL;
33 static int matchlen = 0;
33 static uint32_t matchlen = 0;
3434 static int names_only = 0;
3535 static char *killed_list = NULL;
3636 char killed_value = 1;
182182 char *lxname=NULL;
183183 int c;
184184 int rc;
185 int i, j, k;
185 uint32_t i, j, k;
186186 int comprehensive = 0;
187187
188188
8181 }
8282
8383
84 char *compress_facility(unsigned char *key, int len)
84 char *compress_facility(unsigned char *key, unsigned int len)
8585 {
8686 size_t mat = 0;
8787 size_t plen;
1515 #define HIER_DEPACK_STATIC (1)
1616
1717 void init_facility_pack(void);
18 char *compress_facility(unsigned char *key, int len);
18 char *compress_facility(unsigned char *key, unsigned int len);
1919 void freeze_facility_pack(void);
2020
2121 char *hier_decompress_flagged(char *n, int *was_packed);
229229
230230 static void enter_callback_e(GtkWidget *widget, GtkWidget *nothing)
231231 {
232 (void)widget;
233 (void)nothing;
234
232235 G_CONST_RETURN gchar *entry_text;
233236 int len;
234237 entry_text = gtk_entry_get_text(GTK_ENTRY(GLOBALS->entry_hiersearch_c_2));
246249
247250 static void destroy_callback_e(GtkWidget *widget, GtkWidget *nothing)
248251 {
252 (void)widget;
253 (void)nothing;
254
249255 DEBUG(printf("Entry Cancel\n"));
250256 GLOBALS->entrybox_text_local_hiersearch_c_1=NULL;
251257 wave_gtk_grab_remove(GLOBALS->window1_hiersearch_c_1);
309315
310316 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
311317 {
318 (void)nothing;
319
312320 int i;
313321
314322 if(!GLOBALS->h_selectedtree_hiersearch_c_1) return;
407415
408416 static void insert_callback(GtkWidget *widget, GtkWidget *nothing)
409417 {
418 (void)nothing;
419
410420 Traces tcache;
411421 int i;
412422
522532
523533 static void replace_callback(GtkWidget *widget, GtkWidget *nothing)
524534 {
535 (void)nothing;
536
525537 Traces tcache;
526538 int i;
527539 Trptr tfirst=NULL, tlast=NULL;
684696 static void
685697 bundle_cleanup(GtkWidget *widget, gpointer data)
686698 {
699 (void)widget;
700 (void)data;
701
687702 if(GLOBALS->entrybox_text_local_hiersearch_c_1)
688703 {
689704 char *efix;
743758 static void
744759 bundle_callback_up(GtkWidget *widget, gpointer data)
745760 {
761 (void)widget;
762 (void)data;
763
746764 GLOBALS->bundle_direction_hiersearch_c_1=0;
747765 bundle_callback_generic();
748766 }
750768 static void
751769 bundle_callback_down(GtkWidget *widget, gpointer data)
752770 {
771 (void)widget;
772 (void)data;
773
753774 GLOBALS->bundle_direction_hiersearch_c_1=1;
754775 bundle_callback_generic();
755776 }
759780 static void select_row_callback(GtkWidget *widget, gint row, gint column,
760781 GdkEventButton *event, gpointer data)
761782 {
783 (void)widget;
784 (void)column;
785 (void)event;
786 (void)data;
787
762788 struct tree *t;
763789
764790 t=(struct tree *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_hiersearch_c_1), row);
834860 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
835861 GdkEventButton *event, gpointer data)
836862 {
863 (void)widget;
864 (void)column;
865 (void)event;
866 (void)data;
867
837868 struct tree *t;
838869
839870 t=(struct tree *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_hiersearch_c_1), row);
852883
853884 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
854885 {
886 (void)widget;
887 (void)nothing;
888
855889 GLOBALS->is_active_hiersearch_c_1=0;
856890 gtk_widget_destroy(GLOBALS->window_hiersearch_c_3);
857891 GLOBALS->window_hiersearch_c_3 = NULL;
140140 return(wcnt);
141141 }
142142 #else
143 (void)h;
144 (void)mem;
145 (void)len;
146
143147 fprintf(stderr, "LZMA support was not compiled into this executable, sorry.\n");
144148 exit(255);
145149 #endif
408412 return(rc);
409413
410414 #else
415 (void)handle;
416 (void)mem;
417 (void)len;
418
411419 fprintf(stderr, "LZMA support was not compiled into this executable, sorry.\n");
412420 exit(255);
413421 #endif
5151 void log_text(GtkWidget *text, GdkFont *font, char *str)
5252 {
5353 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
54 (void)font;
55
5456 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &GLOBALS->iter_logfile_c_2,
5557 str, -1, GLOBALS->mono_tag_logfile_c_1, GLOBALS->size_tag_logfile_c_1, NULL);
5658 #else
6163 void log_text_bold(GtkWidget *text, GdkFont *font, char *str)
6264 {
6365 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
66 (void)font;
67
6468 gtk_text_buffer_insert_with_tags (GTK_TEXT_VIEW (text)->buffer, &GLOBALS->iter_logfile_c_2,
6569 str, -1, GLOBALS->bold_tag_logfile_c_2, GLOBALS->mono_tag_logfile_c_1, GLOBALS->size_tag_logfile_c_1, NULL);
6670 #else
7175 static void
7276 log_realize_text (GtkWidget *text, gpointer data)
7377 {
78 (void)text;
79 (void)data;
80
7481 /* nothing for now */
7582 }
7683
107114 static gboolean
108115 button_release_event (GtkWidget *text, GdkEventButton *event)
109116 {
117 (void)event;
118
110119 gchar *sel;
111120
112121 #if defined(WAVE_USE_GTK2) && !defined(GTK_ENABLE_BROKEN)
137146 gtk_text_iter_forward_char(&end);
138147 gch = gtk_text_iter_get_char(&end);
139148 }
149
150 if((sel[slen-1]>='0')&&(sel[slen-1]<='9')) /* need to append units? */
151 {
152 int silen = strlen(WAVE_SI_UNITS);
153 int silp;
154
155 gch = tolower(gch);
156 if(gch == 's')
157 {
158 do_si_append = 1;
159 }
160 else
161 {
162 for(silp=0;silp<silen;silp++)
163 {
164 if((unsigned)gch == (unsigned)WAVE_SI_UNITS[silp])
165 {
166 do_si_append = 1;
167 break;
168 }
169 }
170 }
171 }
172
173 if(do_si_append)
174 {
175 sel2 = malloc_2(slen + 2);
176 sprintf(sel2, "%s%c", sel, (unsigned char)gch);
177 }
178
179 tm = unformat_time(sel2 ? sel2 : sel, GLOBALS->time_dimension);
180 if((tm >= GLOBALS->tims.first) && (tm <= GLOBALS->tims.last))
181 {
182 GLOBALS->tims.lmbcache = -1;
183 update_markertime(GLOBALS->tims.marker = tm);
184 center_op();
185 signalarea_configure_event(GLOBALS->signalarea, NULL);
186 wavearea_configure_event(GLOBALS->wavearea, NULL);
187 update_markertime(GLOBALS->tims.marker = tm); /* centering problem in GTK2 */
188 }
189 }
190
191 if(sel2) { free_2(sel2); }
192 g_free(sel);
193 }
194 }
195 }
196 #else
197
198 #ifndef WAVE_USE_GTK2
199 GtkEditable *oe = GTK_EDITABLE(&GTK_TEXT(text)->editable);
200 GtkTextClass *tc = (GtkTextClass *) ((GtkObject*) (GTK_OBJECT(text)))->klass;
201 GtkEditableClass *oec = &tc->parent_class;
202 #else
203 GtkOldEditable *oe = GTK_OLD_EDITABLE(&GTK_TEXT(text)->old_editable);
204 GtkOldEditableClass *oec = GTK_OLD_EDITABLE_GET_CLASS(oe);
205 #endif
206
207 if(oe->has_selection)
208 {
209 if(oec->get_chars)
210 {
211 sel = oec->get_chars(oe, oe->selection_start_pos, oe->selection_end_pos);
212
213 if(sel)
214 {
215 int slen = strlen(sel);
216 char *sel2 = NULL;
217
218 if((slen)&&(sel[0]>='0')&&(sel[0]<='9'))
219 {
220 TimeType tm;
221 gint gchpos = oe->selection_end_pos;
222 gchar *extra = oec->get_chars(oe, gchpos, gchpos+2);
223 gchar gch = extra ? extra[0] : 0;
224 int do_si_append = 0;
225
226 if(gch==' ') /* in case time is of format "100 ps" with a space */
227 {
228 gch = gch ? extra[1] : 0;
229 }
230
231 if(extra) g_free(extra);
140232
141233 if((sel[slen-1]>='0')&&(sel[slen-1]<='9')) /* need to append units? */
142234 {
167259 sprintf(sel2, "%s%c", sel, (unsigned char)gch);
168260 }
169261
170 tm = unformat_time(sel2 ? sel2 : sel, GLOBALS->time_dimension);
171 if((tm >= GLOBALS->tims.first) && (tm <= GLOBALS->tims.last))
172 {
173 GLOBALS->tims.lmbcache = -1;
174 update_markertime(GLOBALS->tims.marker = tm);
175 center_op();
176 signalarea_configure_event(GLOBALS->signalarea, NULL);
177 wavearea_configure_event(GLOBALS->wavearea, NULL);
178 update_markertime(GLOBALS->tims.marker = tm); /* centering problem in GTK2 */
179 }
180 }
181
182 if(sel2) { free_2(sel2); }
183 g_free(sel);
184 }
185 }
186 }
187 #else
188
189 #ifndef WAVE_USE_GTK2
190 GtkEditable *oe = GTK_EDITABLE(&GTK_TEXT(text)->editable);
191 GtkTextClass *tc = (GtkTextClass *) ((GtkObject*) (GTK_OBJECT(text)))->klass;
192 GtkEditableClass *oec = &tc->parent_class;
193 #else
194 GtkOldEditable *oe = GTK_OLD_EDITABLE(&GTK_TEXT(text)->old_editable);
195 GtkOldEditableClass *oec = GTK_OLD_EDITABLE_GET_CLASS(oe);
196 #endif
197
198 if(oe->has_selection)
199 {
200 if(oec->get_chars)
201 {
202 sel = oec->get_chars(oe, oe->selection_start_pos, oe->selection_end_pos);
203
204 if(sel)
205 {
206 int slen = strlen(sel);
207 char *sel2 = NULL;
208
209 if((slen)&&(sel[0]>='0')&&(sel[0]<='9'))
210 {
211 TimeType tm;
212 gint gchpos = oe->selection_end_pos;
213 gchar *extra = oec->get_chars(oe, gchpos, gchpos+2);
214 gchar gch = extra ? extra[0] : 0;
215 int do_si_append = 0;
216
217 if(gch==' ') /* in case time is of format "100 ps" with a space */
218 {
219 gch = gch ? extra[1] : 0;
220 }
221
222 if(extra) g_free(extra);
223
224 if((sel[slen-1]>='0')&&(sel[slen-1]<='9')) /* need to append units? */
225 {
226 int silen = strlen(WAVE_SI_UNITS);
227 int silp;
228
229 gch = tolower(gch);
230 if(gch == 's')
231 {
232 do_si_append = 1;
233 }
234 else
235 {
236 for(silp=0;silp<silen;silp++)
237 {
238 if(gch == WAVE_SI_UNITS[silp])
239 {
240 do_si_append = 1;
241 break;
242 }
243 }
244 }
245 }
246
247 if(do_si_append)
248 {
249 sel2 = malloc_2(slen + 2);
250 sprintf(sel2, "%s%c", sel, (unsigned char)gch);
251 }
252
253262 tm = unformat_time(sel2 ? sel2 : sel, GLOBALS->time_dimension);
254263 if((tm >= GLOBALS->tims.first) && (tm <= GLOBALS->tims.last))
255264 {
344353
345354 static void ok_callback(GtkWidget *widget, GtkWidget *cached_window)
346355 {
356 (void)widget;
357
347358 struct logfile_instance_t *l = log_collection;
348359 struct logfile_instance_t *lprev = NULL;
349360
375386
376387 static void destroy_callback(GtkWidget *widget, GtkWidget *cached_window)
377388 {
389 (void)cached_window;
390
378391 ok_callback(widget, widget);
379392 }
380393
543556
544557 static void logbox_reload_single(GtkWidget *window, GtkWidget *text, char *default_text)
545558 {
559 (void)window;
560
546561 FILE *handle;
547562 struct wave_logfile_lines_t *wlog_head=NULL, *wlog_curr=NULL;
548563 int wlog_size = 0;
241241
242242 if(numalias)
243243 {
244 unsigned int idx_lft = 0;
245 unsigned int idx_lftmax = GLOBALS->numfacs - numalias;
246 unsigned int idx_rgh = GLOBALS->numfacs - numalias;
244 int idx_lft = 0;
245 int idx_lftmax = GLOBALS->numfacs - numalias;
246 int idx_rgh = GLOBALS->numfacs - numalias;
247247 struct symbol **facs_merge=(struct symbol **)malloc_2(GLOBALS->numfacs*sizeof(struct symbol *));
248248
249249 fprintf(stderr, LXT2_RDLOAD"Merging in %d aliases.\n", numalias);
444444 */
445445 static void lx2_callback(struct lxt2_rd_trace **lt, lxtint64_t *tim, lxtint32_t *facidx, char **value)
446446 {
447 (void)lt;
448
447449 struct HistEnt *htemp = histent_calloc();
448450 struct lx2_entry *l2e = GLOBALS->lx2_table_lx2_c_1+(*facidx);
449451 struct fac *f = GLOBALS->mvlfacs_lx2_c_1+(*facidx);
324324 {
325325 gzFile zhandle;
326326 off_t offs = GLOBALS->zdictionary_offset_lxt_c_1+24;
327 int total_mem, rc, i;
327 int total_mem, rc;
328 unsigned int i;
328329 char *decmem=NULL;
329330 char *pnt;
330331 #if defined __MINGW32__ || defined _MSC_VER
947948
948949 while(offs < vlen)
949950 {
950 unsigned int facidx = 0;
951 int facidx = 0;
951952 unsigned char cmd;
952953 off_t offscache2, offscache3;
953954 unsigned int height;
10481049 if(!cmdkill)
10491050 switch(cmd)
10501051 {
1051 int modlen;
1052 unsigned int modlen;
10521053 case 0x0:
10531054 modlen = (!(GLOBALS->mvlfacs_lxt_c_2[facidx].flags&LT_SYM_F_INTEGER)) ? GLOBALS->mvlfacs_lxt_c_2[facidx].len : 32;
10541055 if((GLOBALS->dict_string_mem_array_lxt_c_1) && (modlen>GLOBALS->dict_width_lxt_c_1))
11981199 */
11991200 static char *parse_offset(struct fac *which, off_t offs)
12001201 {
1201 int v, v2, j;
1202 int k, l;
1202 int v, v2;
1203 unsigned int j;
1204 int k;
1205 unsigned int l;
12031206 char *pnt;
12041207 char repeat;
12051208
12131216 case 0x00: /* MVL2 */
12141217 {
12151218 unsigned int msk;
1216 int bitcnt=0;
1219 unsigned int bitcnt=0;
12171220 int ch;
12181221
12191222 if((GLOBALS->dict_string_mem_array_lxt_c_1) && (l>GLOBALS->dict_width_lxt_c_1))
12821285
12831286 case 0x01: /* MVL4 */
12841287 {
1285 int bitcnt=0;
1288 unsigned int bitcnt=0;
12861289 int ch;
12871290 int rsh;
12881291
13041307
13051308 case 0x02: /* MVL9 */
13061309 {
1307 int bitcnt=0;
1310 unsigned int bitcnt=0;
13081311 int ch;
13091312 int rsh;
13101313
8888 guint page_num,
8989 gpointer user_data)
9090 {
91 (void)notebook;
92 (void)page;
93 (void)user_data;
94
9195 char timestr[32];
9296 struct Global *g_old = GLOBALS;
9397
171175 #if !defined _MSC_VER
172176 void kill_stems_browser(void)
173177 {
174 int ix;
178 unsigned int ix;
175179
176180 for(ix=0;ix<GLOBALS->num_notebook_pages;ix++)
177181 {
184188
185189 static int plug_destroy (GtkWidget *widget, gpointer data)
186190 {
191 (void)widget;
192 (void)data;
193
187194 exit(0);
188195
189196 return(FALSE);
347354 * file selection for -n/--nocli flag
348355 */
349356
350 static void wave_get_filename_cleanup(GtkWidget *widget, gpointer data) { gtk_main_quit(); /* do nothing but exit gtk loop */ }
357 static void wave_get_filename_cleanup(GtkWidget *widget, gpointer data)
358 {
359 (void)widget;
360 (void)data;
361
362 gtk_main_quit(); /* do nothing but exit gtk loop */
363 }
351364
352365 static char *wave_get_filename(char *dfile)
353366 {
692705 #endif
693706 }
694707
695 #if defined(__APPLE__)
696 do_primary_inits:
697 #endif
698
699708 if(!mainwindow_already_built)
700709 {
701710 wave_gconf_init(argc, argv);
15141523 sym_hash_destroy(GLOBALS);
15151524
15161525 /* reset/initialize various markers and time values */
1517 for(i=0;i<26;i++) GLOBALS->named_markers[i]=-1; /* reset all named markers */
1526 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++) GLOBALS->named_markers[i]=-1; /* reset all named markers */
15181527
15191528 GLOBALS->tims.last=GLOBALS->max_time;
15201529 GLOBALS->tims.end=GLOBALS->tims.last; /* until the configure_event of wavearea */
00 /*
1 * Copyright (c) Tony Bybell 1999-2008.
1 * Copyright (c) Tony Bybell 1999-2014.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
1515 #include "analyzer.h"
1616 #include "currenttime.h"
1717
18 static void gtkwave_strrev(char *p)
19 {
20 char *q = p;
21 while(q && *q) ++q;
22 for(--q; p < q; ++p, --q)
23 *p = *p ^ *q,
24 *q = *p ^ *q,
25 *p = *p ^ *q;
26 }
27
28
29 char *make_bijective_marker_id_string(char *buf, unsigned int value)
30 {
31 char *pnt = buf;
32
33 value++; /* bijective values start at one */
34 while (value)
35 {
36 value--;
37 *(pnt++) = (char)('A' + value % ('Z'-'A'+1));
38 value = value / ('Z'-'A'+1);
39 }
40
41 *pnt = 0;
42 gtkwave_strrev(buf);
43 return(buf);
44 }
45
46
47 unsigned int bijective_marker_id_string_hash(char *so)
48 {
49 unsigned int val=0;
50 int i;
51 int len = strlen(so);
52 char sn[16];
53 char *s = sn;
54
55 strcpy(sn, so);
56 gtkwave_strrev(sn);
57
58 s += len;
59 for(i=0;i<len;i++)
60 {
61 char c = toupper(*(--s));
62 if((c < 'A') || (c > 'Z')) break;
63 val *= ('Z'-'A'+1);
64 val += ((unsigned char)c) - ('A' - 1);
65 }
66
67 val--; /* bijective values start at one so decrement */
68 return(val);
69 }
70
71
72 unsigned int bijective_marker_id_string_len(char *s)
73 {
74 int len = 0;
75
76 while(*s)
77 {
78 char c = toupper(*s);
79 if((c >= 'A') && (c <= 'Z'))
80 {
81 len++;
82 s++;
83 continue;
84 }
85 else
86 {
87 break;
88 }
89 }
90
91 return(len);
92 }
93
94
1895 static void str_change_callback(GtkWidget *entry, gpointer which)
1996 {
2097 G_CONST_RETURN gchar *entry_text;
2198 int i;
22
23 i = ((int) (((long) which) & 31L)) % 26;
99 uint32_t hashmask = WAVE_NUM_NAMED_MARKERS;
100 hashmask |= hashmask >> 1;
101 hashmask |= hashmask >> 2;
102 hashmask |= hashmask >> 4;
103 hashmask |= hashmask >> 8;
104 hashmask |= hashmask >> 16;
105
106 i = ((int) (((long) which) & hashmask)) % WAVE_NUM_NAMED_MARKERS;
24107 GLOBALS->dirty_markerbox_c_1 = 1;
25108
26109 entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
47130 {
48131 G_CONST_RETURN gchar *entry_text;
49132 int i;
50
51 i = ((int) (((long) which) & 31L)) % 26;
133 uint32_t hashmask = WAVE_NUM_NAMED_MARKERS;
134 hashmask |= hashmask >> 1;
135 hashmask |= hashmask >> 2;
136 hashmask |= hashmask >> 4;
137 hashmask |= hashmask >> 8;
138 hashmask |= hashmask >> 16;
139
140 i = ((int) (((long) which) & hashmask)) % WAVE_NUM_NAMED_MARKERS;
52141 GLOBALS->dirty_markerbox_c_1 = 1;
53142
54143 entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
75164 }
76165
77166
78
79
80167 static void change_callback(GtkWidget *widget, gpointer which)
81168 {
169 (void)widget;
170
82171 GtkWidget *entry;
83172 TimeType temp;
84173 G_CONST_RETURN gchar *entry_text;
85174 char buf[49];
86175 int i;
87176 int ent_idx;
88
89 ent_idx = ((int) (((long) which) & 31L)) % 26;
177 uint32_t hashmask = WAVE_NUM_NAMED_MARKERS;
178 hashmask |= hashmask >> 1;
179 hashmask |= hashmask >> 2;
180 hashmask |= hashmask >> 4;
181 hashmask |= hashmask >> 8;
182 hashmask |= hashmask >> 16;
183
184 ent_idx = ((int) (((long) which) & hashmask)) % WAVE_NUM_NAMED_MARKERS;
90185
91186 entry=GLOBALS->entries_markerbox_c_1[ent_idx];
92187
102197 temp -= GLOBALS->global_time_offset;
103198 if((temp<GLOBALS->tims.start)||(temp>GLOBALS->tims.last)) goto failure;
104199
105 for(i=0;i<26;i++)
200 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
106201 {
107202 if(temp==GLOBALS->shadow_markers_markerbox_c_1[i])
108203 {
125220
126221 static void enter_callback(GtkWidget *widget, gpointer which)
127222 {
223 (void)widget;
224
128225 GtkWidget *entry;
129226 /* TimeType *modify; */ /* scan-build */
130227 TimeType temp;
132229 char buf[49];
133230 int i;
134231 int ent_idx;
135
136 ent_idx = ((int) (((long) which) & 31L)) % 26;
232 uint32_t hashmask = WAVE_NUM_NAMED_MARKERS;
233 hashmask |= hashmask >> 1;
234 hashmask |= hashmask >> 2;
235 hashmask |= hashmask >> 4;
236 hashmask |= hashmask >> 8;
237 hashmask |= hashmask >> 16;
238
239 ent_idx = ((int) (((long) which) & hashmask)) % WAVE_NUM_NAMED_MARKERS;
137240
138241 entry=GLOBALS->entries_markerbox_c_1[ent_idx];
139242
145248 temp -= GLOBALS->global_time_offset;
146249 if((temp<GLOBALS->tims.start)||(temp>GLOBALS->tims.last)) goto failure;
147250
148 for(i=0;i<26;i++)
251 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
149252 {
150253 if(temp==GLOBALS->shadow_markers_markerbox_c_1[i]) goto failure;
151254 }
174277
175278 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
176279 {
280 (void)widget;
281 (void)nothing;
282
177283 if(GLOBALS->dirty_markerbox_c_1)
178284 {
179285 int i;
180 for(i=0;i<26;i++)
286 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
181287 {
182288 GLOBALS->named_markers[i]=GLOBALS->shadow_markers_markerbox_c_1[i];
183289 if(GLOBALS->marker_names[i]) free_2(GLOBALS->marker_names[i]);
198304
199305 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
200306 {
201 int i;
202 for(i=0;i<26;i++)
307 (void)widget;
308 (void)nothing;
309
310 int i;
311 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
203312 {
204313 if(GLOBALS->marker_names[i]) free_2(GLOBALS->marker_names[i]);
205314 GLOBALS->marker_names[i] = GLOBALS->shadow_marker_names[i];
217326 GtkWidget *vbox, *hbox, *vbox_g, *label;
218327 GtkWidget *button1, *button2, *scrolled_win, *frame, *separator;
219328 GtkWidget *table;
220 char labtitle[2]={0,0};
329 char labtitle[16];
221330 int i;
222331
223332 GLOBALS->cleanup_markerbox_c_4=func;
224333 GLOBALS->dirty_markerbox_c_1=0;
225334
226 for(i=0;i<26;i++)
335 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
227336 {
228337 GLOBALS->shadow_markers_markerbox_c_1[i] = GLOBALS->named_markers[i];
229338 GLOBALS->shadow_marker_names[i] = strdup_2(GLOBALS->marker_names[i]);
265374 gtk_container_add (GTK_CONTAINER (frame), scrolled_win);
266375 gtk_container_add (GTK_CONTAINER (vbox), frame);
267376
268 for(i=0;i<26;i++)
377 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
269378 {
270379 char buf[49];
271380
276385 gtk_box_pack_start (GTK_BOX (vbox_g), separator, TRUE, TRUE, 0);
277386 }
278387
279 labtitle[0]='A'+i;
388
389 make_bijective_marker_id_string(labtitle, i);
280390 label=gtk_label_new(labtitle);
281391 gtk_widget_show (label);
282392 gtk_box_pack_start (GTK_BOX (vbox_g), label, TRUE, TRUE, 0);
00 /*
1 * Copyright (c) Tony Bybell 2010
1 * Copyright (c) Tony Bybell 2010-2014
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
99 #ifndef WAVE_MARKERBOX_H
1010 #define WAVE_MARKERBOX_H
1111
12 void markerbox(char *title, GtkSignalFunc func);
12 #ifdef WAVE_MANYMARKERS_MODE
13
14 /* 702 will go from A-Z, AA-AZ, ... , ZA-ZZ */
15 /* this is a bijective name similar to the columns on spreadsheets */
16 /* the upper count is (practically) unbounded */
17 #define WAVE_NUM_NAMED_MARKERS (702)
18
19 #else
20
21 /* do not go less than 26! */
22 #define WAVE_NUM_NAMED_MARKERS (26)
1323
1424 #endif
1525
26
27 void markerbox(char *title, GtkSignalFunc func);
28
29 char *make_bijective_marker_id_string(char *buf, unsigned int value);
30 unsigned int bijective_marker_id_string_hash(char *so);
31 unsigned int bijective_marker_id_string_len(char *s);
32
33 #endif
34
2626 #include "lx2.h"
2727 #include "hierpack.h"
2828 #include "tcl_helper.h"
29 #include <cocoa_misc.h>
2930 #include <assert.h>
3031
3132 #if !defined __MINGW32__ && !defined _MSC_VER
5253 /* marshals for handling menu items vs button pressed items */
5354
5455 static void service_left_edge_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
55 { service_left_edge(widget, null_data); }
56 {
57 (void)callback_action;
58
59 service_left_edge(widget, null_data);
60 }
5661
5762 static void service_right_edge_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
58 { service_right_edge(widget, null_data); }
63 {
64 (void)callback_action;
65
66 service_right_edge(widget, null_data);
67 }
5968
6069 static void service_zoom_in_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
61 { service_zoom_in(widget, null_data); }
70 {
71 (void)callback_action;
72
73 service_zoom_in(widget, null_data);
74 }
6275
6376 static void service_zoom_out_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
64 { service_zoom_out(widget, null_data); }
77 {
78 (void)callback_action;
79
80 service_zoom_out(widget, null_data);
81 }
6582
6683 static void service_zoom_full_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
67 { service_zoom_full(widget, null_data); }
84 {
85 (void)callback_action;
86
87 service_zoom_full(widget, null_data);
88 }
6889
6990 static void service_zoom_fit_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
70 { service_zoom_fit(widget, null_data); }
91 {
92 (void)callback_action;
93
94 service_zoom_fit(widget, null_data);
95 }
7196
7297 static void service_zoom_left_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
73 { service_zoom_left(widget, null_data); }
98 {
99 (void)callback_action;
100
101 service_zoom_left(widget, null_data);
102 }
74103
75104 static void service_zoom_right_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
76 { service_zoom_right(widget, null_data); }
105 {
106 (void)callback_action;
107
108 service_zoom_right(widget, null_data);
109 }
77110
78111 static void service_zoom_undo_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
79 { service_zoom_undo(widget, null_data); }
112 {
113 (void)callback_action;
114
115 service_zoom_undo(widget, null_data);
116 }
80117
81118 static void fetch_right_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
82 { fetch_right(widget, null_data); }
119 {
120 (void)callback_action;
121
122 fetch_right(widget, null_data);
123 }
83124
84125 static void fetch_left_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
85 { fetch_left(widget, null_data); }
126 {
127 (void)callback_action;
128
129 fetch_left(widget, null_data);
130 }
86131
87132 static void discard_right_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
88 { discard_right(widget, null_data); }
133 {
134 (void)callback_action;
135
136 discard_right(widget, null_data);
137 }
89138
90139 static void discard_left_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
91 { discard_left(widget, null_data); }
140 {
141 (void)callback_action;
142
143 discard_left(widget, null_data);
144 }
92145
93146 static void service_right_shift_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
94 { service_right_shift(widget, null_data); }
147 {
148 (void)callback_action;
149
150 service_right_shift(widget, null_data);
151 }
95152
96153 static void service_left_shift_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
97 { service_left_shift(widget, null_data); }
154 {
155 (void)callback_action;
156
157 service_left_shift(widget, null_data);
158 }
98159
99160 static void service_right_page_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
100 { service_right_page(widget, null_data); }
161 {
162 (void)callback_action;
163
164 service_right_page(widget, null_data);
165 }
101166
102167 static void service_left_page_marshal(gpointer null_data, guint callback_action, GtkWidget *widget)
103 { service_left_page(widget, null_data); }
168 {
169 (void)callback_action;
170
171 service_left_page(widget, null_data);
172 }
104173
105174 /* ruler */
106175
107176 static void menu_def_ruler(gpointer null_data, guint callback_action, GtkWidget *widget)
108177 {
178 (void)null_data;
179 (void)callback_action;
180 (void)widget;
181
109182 if(GLOBALS->helpbox_is_active)
110183 {
111184 help_text_bold("\n\nDefine Time Ruler Marks");
144217
145218 static void lock_marker_left(gpointer null_data, guint callback_action, GtkWidget *widget)
146219 {
220 (void)null_data;
221 (void)callback_action;
222 (void)widget;
223
147224 int ent_idx = GLOBALS->named_marker_lock_idx;
148225 int i;
149226 int success = 0;
163240 return;
164241 }
165242
166 if(ent_idx < 0) ent_idx = 26;
243 if(ent_idx < 0) ent_idx = WAVE_NUM_NAMED_MARKERS;
167244 ent_idx--;
168 if(ent_idx < 0) ent_idx = 25;
169
170 for(i=0;i<26;i++)
245 if(ent_idx < 0) ent_idx = WAVE_NUM_NAMED_MARKERS-1;
246
247 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
171248 {
172249 if(GLOBALS->named_markers[ent_idx] >= 0)
173250 {
176253 }
177254
178255 ent_idx--;
179 if(ent_idx < 0) ent_idx = 25;
256 if(ent_idx < 0) ent_idx = WAVE_NUM_NAMED_MARKERS-1;
180257 }
181258
182259 if(!success)
197274
198275 static void lock_marker_right(gpointer null_data, guint callback_action, GtkWidget *widget)
199276 {
277 (void)null_data;
278 (void)callback_action;
279 (void)widget;
280
200281 int ent_idx = GLOBALS->named_marker_lock_idx;
201282 int i;
202283 int success = 0;
203284
204285 if(ent_idx < 0) ent_idx = -1; /* not really necessary */
205286 ent_idx++;
206 if(ent_idx > 25) ent_idx = 0;
287 if(ent_idx > (WAVE_NUM_NAMED_MARKERS-1)) ent_idx = 0;
207288
208289 if(GLOBALS->helpbox_is_active)
209290 {
220301 return;
221302 }
222303
223 for(i=0;i<26;i++)
304 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
224305 {
225306 if(GLOBALS->named_markers[ent_idx] >= 0)
226307 {
229310 }
230311
231312 ent_idx++;
232 if(ent_idx > 25) ent_idx = 0;
313 if(ent_idx > (WAVE_NUM_NAMED_MARKERS-1)) ent_idx = 0;
233314 }
234315
235316 if(!success)
252333
253334 static void unlock_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
254335 {
336 (void)null_data;
337 (void)callback_action;
338 (void)widget;
339
255340 if(GLOBALS->helpbox_is_active)
256341 {
257342 help_text_bold("\n\nUnlock from Named Marker");
275360
276361 #ifdef WAVE_USE_MLIST_T
277362 void menu_scale_to_td_x(GtkWidget *widget, gpointer data)
363 {
364 (void)widget;
365 (void)data;
278366 #else
279367 void menu_scale_to_td_x(gpointer null_data, guint callback_action, GtkWidget *widget)
280 #endif
281 {
368 {
369 (void)null_data;
370 (void)callback_action;
371 (void)widget;
372 #endif
373
282374 if(GLOBALS->helpbox_is_active)
283375 {
284376 help_text_bold("\n\nScale To Time Dimension: None");
302394
303395 #ifdef WAVE_USE_MLIST_T
304396 void menu_scale_to_td_s(GtkWidget *widget, gpointer data)
397 {
398 (void)widget;
399 (void)data;
305400 #else
306401 void menu_scale_to_td_s(gpointer null_data, guint callback_action, GtkWidget *widget)
307 #endif
308 {
402 {
403 (void)null_data;
404 (void)callback_action;
405 (void)widget;
406 #endif
407
309408 if(GLOBALS->helpbox_is_active)
310409 {
311410 help_text_bold("\n\nScale To Time Dimension: sec");
329428
330429 #ifdef WAVE_USE_MLIST_T
331430 void menu_scale_to_td_m(GtkWidget *widget, gpointer data)
431 {
432 (void)widget;
433 (void)data;
332434 #else
333435 void menu_scale_to_td_m(gpointer null_data, guint callback_action, GtkWidget *widget)
334 #endif
335 {
436 {
437 (void)null_data;
438 (void)callback_action;
439 (void)widget;
440 #endif
441
336442 if(GLOBALS->helpbox_is_active)
337443 {
338444 help_text_bold("\n\nScale To Time Dimension: ms");
356462
357463 #ifdef WAVE_USE_MLIST_T
358464 void menu_scale_to_td_u(GtkWidget *widget, gpointer data)
465 {
466 (void)widget;
467 (void)data;
359468 #else
360469 void menu_scale_to_td_u(gpointer null_data, guint callback_action, GtkWidget *widget)
361 #endif
362 {
470 {
471 (void)null_data;
472 (void)callback_action;
473 (void)widget;
474 #endif
475
363476 if(GLOBALS->helpbox_is_active)
364477 {
365478 help_text_bold("\n\nScale To Time Dimension: us");
383496
384497 #ifdef WAVE_USE_MLIST_T
385498 void menu_scale_to_td_n(GtkWidget *widget, gpointer data)
499 {
500 (void)widget;
501 (void)data;
386502 #else
387503 void menu_scale_to_td_n(gpointer null_data, guint callback_action, GtkWidget *widget)
388 #endif
389 {
504 {
505 (void)null_data;
506 (void)callback_action;
507 (void)widget;
508 #endif
509
390510 if(GLOBALS->helpbox_is_active)
391511 {
392512 help_text_bold("\n\nScale To Time Dimension: ns");
410530
411531 #ifdef WAVE_USE_MLIST_T
412532 void menu_scale_to_td_p(GtkWidget *widget, gpointer data)
533 {
534 (void)widget;
535 (void)data;
413536 #else
414537 void menu_scale_to_td_p(gpointer null_data, guint callback_action, GtkWidget *widget)
415 #endif
416 {
538 {
539 (void)null_data;
540 (void)callback_action;
541 (void)widget;
542 #endif
543
417544 if(GLOBALS->helpbox_is_active)
418545 {
419546 help_text_bold("\n\nScale To Time Dimension: ps");
437564
438565 #ifdef WAVE_USE_MLIST_T
439566 void menu_scale_to_td_f(GtkWidget *widget, gpointer data)
567 {
568 (void)widget;
569 (void)data;
440570 #else
441571 void menu_scale_to_td_f(gpointer null_data, guint callback_action, GtkWidget *widget)
442 #endif
443 {
572 {
573 (void)null_data;
574 (void)callback_action;
575 (void)widget;
576 #endif
577
444578 if(GLOBALS->helpbox_is_active)
445579 {
446580 help_text_bold("\n\nScale To Time Dimension: fs");
467601
468602 void menu_dataformat_xlate_ttrans_1(gpointer null_data, guint callback_action, GtkWidget *widget)
469603 {
604 (void)null_data;
605 (void)callback_action;
606 (void)widget;
607
470608 if(GLOBALS->helpbox_is_active)
471609 {
472610 help_text_bold("\n\nTransaction Filter Process");
481619
482620 void menu_dataformat_xlate_ttrans_0(gpointer null_data, guint callback_action, GtkWidget *widget)
483621 {
622 (void)null_data;
623 (void)callback_action;
624 (void)widget;
625
484626 if(GLOBALS->helpbox_is_active)
485627 {
486628 help_text_bold("\n\nTransaction Filter Process Disable");
497639
498640 void menu_dataformat_xlate_proc_1(gpointer null_data, guint callback_action, GtkWidget *widget)
499641 {
642 (void)null_data;
643 (void)callback_action;
644 (void)widget;
645
500646 if(GLOBALS->helpbox_is_active)
501647 {
502648 help_text_bold("\n\nTranslate Filter Process");
511657
512658 void menu_dataformat_xlate_proc_0(gpointer null_data, guint callback_action, GtkWidget *widget)
513659 {
660 (void)null_data;
661 (void)callback_action;
662 (void)widget;
663
514664 if(GLOBALS->helpbox_is_active)
515665 {
516666 help_text_bold("\n\nTranslate Filter Process Disable");
528678
529679 void menu_dataformat_xlate_file_1(gpointer null_data, guint callback_action, GtkWidget *widget)
530680 {
681 (void)null_data;
682 (void)callback_action;
683 (void)widget;
684
531685 if(GLOBALS->helpbox_is_active)
532686 {
533687 help_text_bold("\n\nTranslate Filter File");
543697
544698 void menu_dataformat_xlate_file_0(gpointer null_data, guint callback_action, GtkWidget *widget)
545699 {
700 (void)null_data;
701 (void)callback_action;
702 (void)widget;
703
546704 if(GLOBALS->helpbox_is_active)
547705 {
548706 help_text_bold("\n\nTranslate Filter File Disable");
561719
562720 void menu_write_lxt_file_cleanup(GtkWidget *widget, gpointer data)
563721 {
722 (void)widget;
723 (void)data;
724
564725 int rc;
565726
566727 if(!GLOBALS->filesel_ok)
595756 void
596757 menu_write_lxt_file(gpointer null_data, guint callback_action, GtkWidget *widget)
597758 {
759 (void)null_data;
760 (void)callback_action;
761 (void)widget;
762
598763 if(GLOBALS->helpbox_is_active)
599764 {
600765 help_text_bold("\n\nWrite LXT File As");
631796
632797 void menu_write_vcd_file_cleanup(GtkWidget *widget, gpointer data)
633798 {
799 (void)widget;
800 (void)data;
801
634802 int rc;
635803
636804 if(!GLOBALS->filesel_ok)
665833 void
666834 menu_write_vcd_file(gpointer null_data, guint callback_action, GtkWidget *widget)
667835 {
836 (void)null_data;
837 (void)callback_action;
838 (void)widget;
839
668840 if(GLOBALS->helpbox_is_active)
669841 {
670842 help_text_bold("\n\nWrite VCD File As");
693865
694866 void menu_write_tim_file_cleanup(GtkWidget *widget, gpointer data)
695867 {
868 (void)widget;
869 (void)data;
870
696871 int rc;
697872
698873 if(!GLOBALS->filesel_ok)
727902 void
728903 menu_write_tim_file(gpointer null_data, guint callback_action, GtkWidget *widget)
729904 {
905 (void)null_data;
906 (void)callback_action;
907 (void)widget;
908
730909 if(GLOBALS->helpbox_is_active)
731910 {
732911 help_text_bold("\n\nWrite TIM File As");
756935
757936 void menu_unwarp_traces_all(gpointer null_data, guint callback_action, GtkWidget *widget)
758937 {
938 (void)null_data;
939 (void)callback_action;
940 (void)widget;
941
759942 Trptr t;
760943 int found=0;
761944
790973
791974 void menu_unwarp_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
792975 {
976 (void)null_data;
977 (void)callback_action;
978 (void)widget;
979
793980 Trptr t;
794981 int found=0;
795982
8251012
8261013 void warp_cleanup(GtkWidget *widget, gpointer data)
8271014 {
1015 (void)widget;
1016 (void)data;
1017
8281018 if(GLOBALS->entrybox_text)
8291019 {
8301020 TimeType gt, delta;
8731063
8741064 void menu_warp_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
8751065 {
1066 (void)null_data;
1067 (void)callback_action;
1068 (void)widget;
1069
8761070 char gt[32];
8771071 Trptr t;
8781072 int found=0;
9191113
9201114 void menu_altwheel(gpointer null_data, guint callback_action, GtkWidget *widget)
9211115 {
1116 (void)null_data;
1117 (void)callback_action;
1118 (void)widget;
1119
9221120 if(GLOBALS->helpbox_is_active)
9231121 {
9241122 help_text_bold("\n\nAlternate Wheel Mode");
9641162
9651163 void wave_scrolling_on(gpointer null_data, guint callback_action, GtkWidget *widget)
9661164 {
1165 (void)null_data;
1166 (void)callback_action;
1167 (void)widget;
1168
9671169 if(GLOBALS->helpbox_is_active)
9681170 {
9691171 help_text_bold("\n\nWave Scrolling");
10111213
10121214 void menu_keep_xz_colors(gpointer null_data, guint callback_action, GtkWidget *widget)
10131215 {
1216 (void)null_data;
1217 (void)callback_action;
1218 (void)widget;
1219
10141220 if(GLOBALS->helpbox_is_active)
10151221 {
10161222 help_text_bold("\n\nKeep xz Colors");
10501256
10511257 void menu_autocoalesce(gpointer null_data, guint callback_action, GtkWidget *widget)
10521258 {
1259 (void)null_data;
1260 (void)callback_action;
1261 (void)widget;
1262
10531263 if(GLOBALS->helpbox_is_active)
10541264 {
10551265 help_text_bold("\n\nAutocoalesce");
10931303
10941304 void menu_autocoalesce_reversal(gpointer null_data, guint callback_action, GtkWidget *widget)
10951305 {
1306 (void)null_data;
1307 (void)callback_action;
1308 (void)widget;
1309
10961310 if(GLOBALS->helpbox_is_active)
10971311 {
10981312 help_text_bold("\n\nAutocoalesce Reversal");
11351349
11361350 void menu_autoname_bundles_on(gpointer null_data, guint callback_action, GtkWidget *widget)
11371351 {
1352 (void)null_data;
1353 (void)callback_action;
1354 (void)widget;
1355
11381356 if(GLOBALS->helpbox_is_active)
11391357 {
11401358 help_text_bold("\n\nAutoname Bundles");
11871405
11881406 void menu_hgrouping(gpointer null_data, guint callback_action, GtkWidget *widget)
11891407 {
1408 (void)null_data;
1409 (void)callback_action;
1410 (void)widget;
1411
11901412 if(GLOBALS->helpbox_is_active)
11911413 {
11921414 help_text_bold("\n\nSearch Hierarchy Grouping");
12341456
12351457 void set_hier_cleanup(GtkWidget *widget, gpointer data, int level)
12361458 {
1459 (void)widget;
1460 (void)data;
1461
12371462 char update_string[128];
12381463 Trptr t;
12391464 int i;
13231548
13241549 void menu_set_max_hier(gpointer null_data, guint callback_action, GtkWidget *widget)
13251550 {
1551 (void)null_data;
1552 (void)callback_action;
1553 (void)widget;
1554
13261555 char za[32];
13271556
13281557 if(GLOBALS->helpbox_is_active)
13461575
13471576 void menu_toggle_hier(gpointer null_data, guint callback_action, GtkWidget *widget)
13481577 {
1578 (void)callback_action;
1579
13491580 if(GLOBALS->helpbox_is_active)
13501581 {
13511582 help_text_bold("\n\nToggle Trace Hier");
13651596 /**/
13661597 void menu_use_roundcaps(gpointer null_data, guint callback_action, GtkWidget *widget)
13671598 {
1599 (void)null_data;
1600 (void)callback_action;
1601 (void)widget;
1602
13681603 if(GLOBALS->helpbox_is_active)
13691604 {
13701605 help_text_bold("\n\nDraw Roundcapped Vectors");
14171652 /**/
14181653 void menu_lxt_clk_compress(gpointer null_data, guint callback_action, GtkWidget *widget)
14191654 {
1655 (void)null_data;
1656 (void)callback_action;
1657 (void)widget;
1658
14201659 if(GLOBALS->helpbox_is_active)
14211660 {
14221661 help_text_bold("\n\nLXT Clock Compress to Z");
14621701 /**/
14631702 void menu_use_full_precision(gpointer null_data, guint callback_action, GtkWidget *widget)
14641703 {
1704 (void)null_data;
1705 (void)callback_action;
1706 (void)widget;
1707
14651708 if(GLOBALS->helpbox_is_active)
14661709 {
14671710 help_text_bold("\n\nFull Precision");
15101753 /**/
15111754 void menu_remove_marked(gpointer null_data, guint callback_action, GtkWidget *widget)
15121755 {
1756 (void)null_data;
1757 (void)callback_action;
1758 (void)widget;
1759
15131760 if(GLOBALS->helpbox_is_active)
15141761 {
15151762 help_text_bold("\n\nRemove Pattern Marks");
15421789 /**/
15431790 void menu_use_color(gpointer null_data, guint callback_action, GtkWidget *widget)
15441791 {
1792 (void)null_data;
1793 (void)callback_action;
1794 (void)widget;
1795
15451796 if(GLOBALS->helpbox_is_active)
15461797 {
15471798 help_text_bold("\n\nUse Color");
15611812 /**/
15621813 void menu_use_bw(gpointer null_data, guint callback_action, GtkWidget *widget)
15631814 {
1815 (void)null_data;
1816 (void)callback_action;
1817 (void)widget;
1818
15641819 if(GLOBALS->helpbox_is_active)
15651820 {
15661821 help_text_bold("\n\nUse Black and White");
15811836 /**/
15821837 void menu_zoom10_snap(gpointer null_data, guint callback_action, GtkWidget *widget)
15831838 {
1839 (void)null_data;
1840 (void)callback_action;
1841 (void)widget;
1842
15841843 if(GLOBALS->helpbox_is_active)
15851844 {
15861845 help_text_bold("\n\nZoom Pow10 Snap");
16341893 /**/
16351894 void menu_zoom_dynf(gpointer null_data, guint callback_action, GtkWidget *widget)
16361895 {
1896 (void)null_data;
1897 (void)callback_action;
1898 (void)widget;
1899
16371900 if(GLOBALS->helpbox_is_active)
16381901 {
16391902 help_text_bold("\n\nPartial VCD Dynamic Zoom Full");
16761939 /**/
16771940 void menu_zoom_dyne(gpointer null_data, guint callback_action, GtkWidget *widget)
16781941 {
1942 (void)null_data;
1943 (void)callback_action;
1944 (void)widget;
1945
16791946 if(GLOBALS->helpbox_is_active)
16801947 {
16811948 help_text_bold("\n\nPartial VCD Dynamic Zoom To End");
17181985 /**/
17191986 void menu_left_justify(gpointer null_data, guint callback_action, GtkWidget *widget)
17201987 {
1988 (void)null_data;
1989 (void)callback_action;
1990 (void)widget;
1991
17211992 if(GLOBALS->helpbox_is_active)
17221993 {
17231994 help_text_bold("\n\nLeft Justify Signals");
17372008 /**/
17382009 void menu_right_justify(gpointer null_data, guint callback_action, GtkWidget *widget)
17392010 {
2011 (void)null_data;
2012 (void)callback_action;
2013 (void)widget;
2014
17402015 if(GLOBALS->helpbox_is_active)
17412016 {
17422017 help_text_bold("\n\nRight Justify Signals");
17562031 /**/
17572032 void menu_enable_constant_marker_update(gpointer null_data, guint callback_action, GtkWidget *widget)
17582033 {
2034 (void)null_data;
2035 (void)callback_action;
2036 (void)widget;
2037
17592038 if(GLOBALS->helpbox_is_active)
17602039 {
17612040 help_text_bold("\n\nConstant Marker Update");
18032082 /**/
18042083 void menu_enable_standard_trace_select(gpointer null_data, guint callback_action, GtkWidget *widget)
18052084 {
2085 (void)null_data;
2086 (void)callback_action;
2087 (void)widget;
2088
18062089 if(GLOBALS->helpbox_is_active)
18072090 {
18082091 help_text_bold("\n\nStandard Trace Select");
18462129 /**/
18472130 void menu_enable_dynamic_resize(gpointer null_data, guint callback_action, GtkWidget *widget)
18482131 {
2132 (void)null_data;
2133 (void)callback_action;
2134 (void)widget;
2135
18492136 if(GLOBALS->helpbox_is_active)
18502137 {
18512138 help_text_bold("\n\nDynamic Resize");
19012188 /**/
19022189 void menu_toggle_delta_or_frequency(gpointer null_data, guint callback_action, GtkWidget *widget)
19032190 {
2191 (void)null_data;
2192 (void)callback_action;
2193 (void)widget;
2194
19042195 if(GLOBALS->helpbox_is_active)
19052196 {
19062197 help_text_bold("\n\nToggle Delta-Frequency");
19202211 /**/
19212212 void menu_toggle_max_or_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
19222213 {
2214 (void)null_data;
2215 (void)callback_action;
2216 (void)widget;
2217
19232218 if(GLOBALS->helpbox_is_active)
19242219 {
19252220 help_text_bold("\n\nToggle Max-Marker");
19402235 #ifdef MAC_INTEGRATION
19412236 void menu_help_manual(gpointer null_data, guint callback_action, GtkWidget *widget)
19422237 {
2238 (void)null_data;
2239 (void)callback_action;
2240 (void)widget;
2241
19432242 if(GLOBALS->helpbox_is_active)
19442243 {
19452244 help_text_bold("\n\nWave User's Guide");
19832282 /**/
19842283 void menu_help(gpointer null_data, guint callback_action, GtkWidget *widget)
19852284 {
2285 (void)null_data;
2286 (void)callback_action;
2287 (void)widget;
2288
19862289 if(GLOBALS->helpbox_is_active)
19872290 {
19882291 help_text_bold("\n\nWave Help");
19972300 /**/
19982301 void menu_version(gpointer null_data, guint callback_action, GtkWidget *widget)
19992302 {
2303 (void)null_data;
2304 (void)callback_action;
2305 (void)widget;
2306
20002307 if(GLOBALS->helpbox_is_active)
20012308 {
20022309 help_text_bold("\n\nWave Version");
20122319 /**/
20132320 void menu_quit_callback(GtkWidget *widget, gpointer data)
20142321 {
2322 (void)widget;
2323
20152324 char sstr[32];
20162325
20172326 if(data)
20282337 }
20292338 void menu_quit(gpointer null_data, guint callback_action, GtkWidget *widget)
20302339 {
2340 (void)null_data;
2341 (void)callback_action;
2342 (void)widget;
2343
20312344 if(GLOBALS->helpbox_is_active)
20322345 {
20332346 help_text_bold("\n\nQuit");
20512364
20522365 void menu_quit_close_callback(GtkWidget *widget, gpointer dummy_data)
20532366 {
2367 (void)widget;
2368 (void)dummy_data;
2369
20542370 unsigned int i, j=0;
20552371 unsigned int this_page = GLOBALS->this_context_page;
20562372 unsigned np = GLOBALS->num_notebook_pages;
21182434
21192435 void menu_quit_close(gpointer null_data, guint callback_action, GtkWidget *widget)
21202436 {
2437 (void)null_data;
2438 (void)callback_action;
2439 (void)widget;
2440
21212441 if(GLOBALS->helpbox_is_active)
21222442 {
21232443 help_text_bold("\n\nClose");
21642484 static void
21652485 menu_open_group(GtkWidget *widget, gpointer data)
21662486 {
2487 (void)widget;
2488 (void)data;
2489
21672490 Trptr t;
21682491 unsigned dirty = 0;
21692492
22002523 static void
22012524 menu_close_group(GtkWidget *widget, gpointer data)
22022525 {
2526 (void)widget;
2527 (void)data;
2528
22032529 Trptr t;
22042530 unsigned dirty = 0;
22052531
23302656 static void
23312657 create_group_cleanup(GtkWidget *widget, gpointer data)
23322658 {
2659 (void)widget;
2660 (void)data;
2661
23332662 unsigned dirty = 0;
23342663
23352664 dirty = create_group(GLOBALS->entrybox_text, NULL);
23522681 void
23532682 menu_create_group(gpointer null_data, guint callback_action, GtkWidget *widget)
23542683 {
2684 (void)null_data;
2685 (void)callback_action;
2686 (void)widget;
23552687
23562688 Trptr t;
23572689 unsigned dirty = 0;
25062838 void
25072839 menu_expand(gpointer null_data, guint callback_action, GtkWidget *widget)
25082840 {
2841 (void)null_data;
2842 (void)callback_action;
2843 (void)widget;
2844
25092845 Trptr t, t_next;
25102846 int dirty=0;
25112847 int j;
26062942 void
26072943 menu_toggle_group(gpointer null_data, guint callback_action, GtkWidget *widget)
26082944 {
2945 (void)null_data;
2946 (void)callback_action;
2947 (void)widget;
2948
26092949 Trptr t;
26102950 unsigned dirty_group = 0;
26112951 unsigned dirty_signal = 0;
26673007
26683008 static void rename_cleanup(GtkWidget *widget, gpointer data)
26693009 {
3010 (void)widget;
3011 (void)data;
3012
26703013 Trptr t = GLOBALS->trace_to_alias_menu_c_1;
26713014
26723015 if(GLOBALS->entrybox_text)
27223065
27233066 static void menu_rename(GtkWidget *widget, gpointer data)
27243067 {
3068 (void)widget;
3069 (void)data;
3070
27253071 Trptr t;
27263072 /* currently only called by various combine menu options, so no help menu text */
27273073
31383484 void
31393485 menu_combine_down(gpointer null_data, guint callback_action, GtkWidget *widget)
31403486 {
3487 (void)null_data;
3488 (void)callback_action;
3489 (void)widget;
3490
31413491 bvptr v;
31423492
31433493 if(GLOBALS->helpbox_is_active)
31883538 void
31893539 menu_combine_up(gpointer null_data, guint callback_action, GtkWidget *widget)
31903540 {
3541 (void)null_data;
3542 (void)callback_action;
3543 (void)widget;
3544
31913545 bvptr v;
31923546
31933547 if(GLOBALS->helpbox_is_active)
32393593
32403594 void menu_tracesearchbox_callback(GtkWidget *widget, gpointer data)
32413595 {
3596 (void)widget;
3597 (void)data;
32423598 }
32433599
32443600 void menu_tracesearchbox(gpointer null_data, guint callback_action, GtkWidget *widget)
32453601 {
3602 (void)null_data;
3603 (void)callback_action;
3604 (void)widget;
3605
32463606 Trptr t;
32473607
32483608 if(GLOBALS->helpbox_is_active)
33003660 void
33013661 menu_new_viewer_cleanup(GtkWidget *widget, gpointer data)
33023662 {
3663 (void)widget;
3664 (void)data;
3665
33033666 pid_t pid;
33043667
33053668 if(GLOBALS->filesel_ok)
33783741 void
33793742 menu_new_viewer(gpointer null_data, guint callback_action, GtkWidget *widget)
33803743 {
3744 (void)null_data;
3745 (void)callback_action;
3746 (void)widget;
3747
33813748 static int mnv = 0;
33823749
33833750 if(!mnv && !GLOBALS->busy_busy_c_1)
35123879 void
35133880 menu_new_viewer_tab_cleanup(GtkWidget *widget, gpointer data)
35143881 {
3882 (void)widget;
3883 (void)data;
3884
35153885 if(GLOBALS->filesel_ok)
35163886 {
35173887 menu_new_viewer_tab_cleanup_2(*GLOBALS->fileselbox_text, GLOBALS->optimize_vcd);
35223892 void
35233893 menu_new_viewer_tab(gpointer null_data, guint callback_action, GtkWidget *widget)
35243894 {
3895 (void)null_data;
3896 (void)callback_action;
3897 (void)widget;
3898
35253899 if(GLOBALS->helpbox_is_active)
35263900 {
35273901 help_text_bold("\n\nOpen New Tab");
35493923 void
35503924 menu_reload_waveform(gpointer null_data, guint callback_action, GtkWidget *widget)
35513925 {
3926 (void)null_data;
3927 (void)callback_action;
3928 (void)widget;
3929
35523930 if(GLOBALS->helpbox_is_active)
35533931 {
35543932 help_text_bold("\n\nReload Current Waveform");
35893967 void
35903968 menu_print(gpointer null_data, guint callback_action, GtkWidget *widget)
35913969 {
3970 (void)null_data;
3971 (void)callback_action;
3972 (void)widget;
3973
35923974 if(GLOBALS->helpbox_is_active)
35933975 {
35943976 help_text_bold("\n\nPrint To File");
36093991 /**/
36103992 void menu_markerbox_callback(GtkWidget *widget, gpointer data)
36113993 {
3994 (void)widget;
3995 (void)data;
36123996 }
36133997
36143998 void menu_markerbox(gpointer null_data, guint callback_action, GtkWidget *widget)
36153999 {
4000 (void)null_data;
4001 (void)callback_action;
4002 (void)widget;
4003
36164004 if(GLOBALS->helpbox_is_active)
36174005 {
36184006 help_text_bold("\n\nShow-Change Marker Data");
36194007 help_text(
36204008 " displays and allows the modification of the times for"
3621 " all 26 named markers by filling in the leftmost entry boxes. In addition, optional marker text"
4009 " all named markers by filling in the leftmost entry boxes. In addition, optional marker text"
36224010 " rather than a generic single letter name may be specified by filling in the rightmost entry boxes."
36234011 " Note that the time for each marker must be unique."
36244012 );
36314019
36324020 void copy_pri_b_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
36334021 {
4022 (void)null_data;
4023 (void)callback_action;
4024 (void)widget;
4025
36344026 if(GLOBALS->helpbox_is_active)
36354027 {
36364028 help_text_bold("\n\nCopy Primary -> B Marker");
36584050 /**/
36594051 void delete_unnamed_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
36604052 {
4053 (void)null_data;
4054 (void)callback_action;
4055 (void)widget;
4056
36614057 if(GLOBALS->helpbox_is_active)
36624058 {
36634059 help_text_bold("\n\nDelete Primary Marker");
36944090 /**/
36954091 void collect_all_named_markers(gpointer null_data, guint callback_action, GtkWidget *widget)
36964092 {
4093 (void)null_data;
4094 (void)callback_action;
4095 (void)widget;
4096
36974097 int i;
36984098 int dirty=0;
36994099
37094109
37104110 DEBUG(printf("collect_all_unnamed_markers()\n"));
37114111
3712 for(i=0;i<26;i++)
4112 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
37134113 {
37144114 if(GLOBALS->named_markers[i]!=-1)
37154115 {
37334133 /**/
37344134 void collect_named_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
37354135 {
4136 (void)null_data;
4137 (void)callback_action;
4138 (void)widget;
4139
37364140 int i;
37374141
37384142 if(GLOBALS->helpbox_is_active)
37494153
37504154 if(GLOBALS->tims.marker!=-1)
37514155 {
3752 for(i=0;i<26;i++)
4156 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
37534157 {
37544158 if(GLOBALS->named_markers[i]==GLOBALS->tims.marker)
37554159 {
37714175 /**/
37724176 void drop_named_marker(gpointer null_data, guint callback_action, GtkWidget *widget)
37734177 {
4178 (void)null_data;
4179 (void)callback_action;
4180 (void)widget;
4181
37744182 int i;
37754183
37764184 if(GLOBALS->helpbox_is_active)
37774185 {
4186 char nm_s[32];
4187
4188 sprintf(nm_s, "%d", WAVE_NUM_NAMED_MARKERS);
4189
37784190 help_text_bold("\n\nDrop Named Marker");
37794191 help_text(
37804192 " drops a named marker where the current primary (unnamed)"
3781 " marker is placed. A maximum of 26 named markers are allowed"
4193 " marker is placed. A maximum of "
4194 );
4195
4196 help_text(
4197 nm_s
4198 );
4199
4200 help_text(
4201 " named markers are allowed"
37824202 " and the times for all must be different."
37834203 );
37844204 return;
37914211 {
37924212 /* only one per slot requirement removed...
37934213 #if 0
3794 for(i=0;i<26;i++)
4214 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
37954215 {
37964216 if(GLOBALS->named_markers[i]==GLOBALS->tims.marker) return;
37974217 }
37984218 #endif
37994219 ...only one per slot requirement removed */
38004220
3801 for(i=0;i<26;i++)
4221 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
38024222 {
38034223 if(GLOBALS->named_markers[i]==-1)
38044224 {
38134233 /**/
38144234 void menu_treesearch_cleanup(GtkWidget *widget, gpointer data)
38154235 {
4236 (void)widget;
4237 (void)data;
4238
38164239 MaxSignalLength();
38174240 signalarea_configure_event(GLOBALS->signalarea, NULL);
38184241 wavearea_configure_event(GLOBALS->wavearea, NULL);
38214244
38224245 void menu_treesearch(gpointer null_data, guint callback_action, GtkWidget *widget)
38234246 {
4247 (void)null_data;
4248 (void)callback_action;
4249 (void)widget;
4250
38244251 if(GLOBALS->helpbox_is_active)
38254252 {
38264253 help_text_bold("\n\nSignal Search Tree");
38414268 void
38424269 menu_showchangeall_cleanup(GtkWidget *widget, gpointer data)
38434270 {
4271 (void)widget;
4272 (void)data;
4273
38444274 Trptr t;
38454275 Ulong flags;
38464276
38684298 void
38694299 menu_showchangeall(gpointer null_data, guint callback_action, GtkWidget *widget)
38704300 {
4301 (void)null_data;
4302 (void)callback_action;
4303 (void)widget;
4304
38714305 Trptr t;
38724306
38734307 if(GLOBALS->helpbox_is_active)
39014335 void
39024336 menu_showchange_cleanup(GtkWidget *widget, gpointer data)
39034337 {
4338 (void)widget;
4339 (void)data;
4340
39044341 GLOBALS->signalwindow_width_dirty=1;
39054342 MaxSignalLength();
39064343 signalarea_configure_event(GLOBALS->signalarea, NULL);
39114348 void
39124349 menu_showchange(gpointer null_data, guint callback_action, GtkWidget *widget)
39134350 {
4351 (void)null_data;
4352 (void)callback_action;
4353 (void)widget;
4354
39144355 Trptr t;
39154356
39164357 if(GLOBALS->helpbox_is_active)
39434384 /**/
39444385 void menu_remove_aliases(gpointer null_data, guint callback_action, GtkWidget *widget)
39454386 {
4387 (void)null_data;
4388 (void)callback_action;
4389 (void)widget;
4390
39464391 Trptr t;
39474392 int dirty=0, none_selected = 1;
39484393
40194464
40204465 static void alias_cleanup(GtkWidget *widget, gpointer data)
40214466 {
4467 (void)widget;
4468 (void)data;
4469
40224470 Trptr t = GLOBALS->trace_to_alias_menu_c_1;
40234471
40244472 if(GLOBALS->entrybox_text)
40634511
40644512 void menu_alias(gpointer null_data, guint callback_action, GtkWidget *widget)
40654513 {
4514 (void)null_data;
4515 (void)callback_action;
4516 (void)widget;
4517
40664518 Trptr t;
40674519
40684520 if(GLOBALS->helpbox_is_active)
41184570 /**/
41194571 void menu_hiersearch_cleanup(GtkWidget *widget, gpointer data)
41204572 {
4573 (void)widget;
4574 (void)data;
4575
41214576 MaxSignalLength();
41224577 signalarea_configure_event(GLOBALS->signalarea, NULL);
41234578 wavearea_configure_event(GLOBALS->wavearea, NULL);
41264581
41274582 void menu_hiersearch(gpointer null_data, guint callback_action, GtkWidget *widget)
41284583 {
4584 (void)null_data;
4585 (void)callback_action;
4586 (void)widget;
4587
41294588 if(GLOBALS->helpbox_is_active)
41304589 {
41314590 help_text_bold("\n\nHierarchy Search");
41434602 /**/
41444603 void menu_signalsearch_cleanup(GtkWidget *widget, gpointer data)
41454604 {
4605 (void)widget;
4606 (void)data;
4607
41464608 MaxSignalLength();
41474609 signalarea_configure_event(GLOBALS->signalarea, NULL);
41484610 wavearea_configure_event(GLOBALS->wavearea, NULL);
41514613
41524614 void menu_signalsearch(gpointer null_data, guint callback_action, GtkWidget *widget)
41534615 {
4616 (void)null_data;
4617 (void)callback_action;
4618 (void)widget;
4619
41544620 if(GLOBALS->helpbox_is_active)
41554621 {
41564622 help_text_bold("\n\nSignal Search Regexp");
42184684 static void
42194685 regexp_unhighlight_cleanup(GtkWidget *widget, gpointer data)
42204686 {
4687 (void)widget;
4688 (void)data;
4689
42214690 regexp_highlight_generic(0);
42224691 }
42234692
42244693 void
42254694 menu_regexp_unhighlight(gpointer null_data, guint callback_action, GtkWidget *widget)
42264695 {
4696 (void)null_data;
4697 (void)callback_action;
4698 (void)widget;
4699
42274700 if(GLOBALS->helpbox_is_active)
42284701 {
42294702 help_text_bold("\n\nUnHighlight Regexp");
42424715 static void
42434716 regexp_highlight_cleanup(GtkWidget *widget, gpointer data)
42444717 {
4718 (void)widget;
4719 (void)data;
4720
42454721 regexp_highlight_generic(1);
42464722 }
42474723
42484724 void
42494725 menu_regexp_highlight(gpointer null_data, guint callback_action, GtkWidget *widget)
42504726 {
4727 (void)null_data;
4728 (void)callback_action;
4729 (void)widget;
4730
42514731 if(GLOBALS->helpbox_is_active)
42524732 {
42534733 help_text_bold("\n\nHighlight Regexp");
42704750 void
42714751 menu_write_screengrab_cleanup(GtkWidget *widget, gpointer data)
42724752 {
4753 (void)widget;
4754 (void)data;
4755
42734756 GdkWindow *gw;
42744757 gint w, h;
42754758 GdkColormap *cm;
43224805 void
43234806 menu_write_screengrab_as(gpointer null_data, guint callback_action, GtkWidget *widget)
43244807 {
4808 (void)null_data;
4809 (void)callback_action;
4810 (void)widget;
4811
43254812 if(GLOBALS->helpbox_is_active)
43264813 {
43274814 help_text_bold("\n\nGrab To File");
43454832 void
43464833 menu_write_save_cleanup(GtkWidget *widget, gpointer data)
43474834 {
4835 (void)widget;
4836 (void)data;
4837
43484838 FILE *wave;
43494839
43504840 if(!GLOBALS->filesel_ok)
43714861 void
43724862 menu_write_save_file_as(gpointer null_data, guint callback_action, GtkWidget *widget)
43734863 {
4864 (void)null_data;
4865 (void)callback_action;
4866 (void)widget;
4867
43744868 if(GLOBALS->helpbox_is_active)
43754869 {
43764870 help_text_bold("\n\nWrite Save File As");
43914885 void
43924886 menu_write_save_file(gpointer null_data, guint callback_action, GtkWidget *widget)
43934887 {
4888 (void)null_data;
4889 (void)callback_action;
4890 (void)widget;
4891
43944892 if(GLOBALS->helpbox_is_active)
43954893 {
43964894 help_text_bold("\n\nWrite Save File");
44264924 void
44274925 menu_read_save_cleanup(GtkWidget *widget, gpointer data)
44284926 {
4927 (void)widget;
4928 (void)data;
4929
44294930 if(GLOBALS->filesel_ok)
44304931 {
44314932 char *wname;
44424943 void
44434944 menu_read_save_file(gpointer null_data, guint callback_action, GtkWidget *widget)
44444945 {
4946 (void)null_data;
4947 (void)callback_action;
4948 (void)widget;
4949
44454950 if(GLOBALS->helpbox_is_active)
44464951 {
44474952 help_text_bold("\n\nRead Save File");
44674972 void
44684973 menu_read_stems_cleanup(GtkWidget *widget, gpointer data)
44694974 {
4470 char *fname ;
4975 (void)widget;
4976 (void)data;
4977
4978 char *fname;
44714979
44724980 if(GLOBALS->filesel_ok)
44734981 {
44844992 void
44854993 menu_read_stems_file(gpointer null_data, guint callback_action, GtkWidget *widget)
44864994 {
4995 (void)null_data;
4996 (void)callback_action;
4997 (void)widget;
4998
44874999 if(GLOBALS->helpbox_is_active)
44885000 {
44895001 help_text_bold("\n\nRead Verilog Stemsfile");
45155027 void
45165028 menu_read_log_cleanup(GtkWidget *widget, gpointer data)
45175029 {
5030 (void)widget;
5031 (void)data;
5032
45185033 char *fname ;
45195034
45205035 if(GLOBALS->filesel_ok)
45325047 void
45335048 menu_read_log_file(gpointer null_data, guint callback_action, GtkWidget *widget)
45345049 {
5050 (void)null_data;
5051 (void)callback_action;
5052 (void)widget;
5053
45355054 if(GLOBALS->helpbox_is_active)
45365055 {
45375056 help_text_bold("\n\nRead Logfile");
45505069 void
45515070 menu_read_script_cleanup(GtkWidget *widget, gpointer data)
45525071 {
4553 char *fname ;
5072 (void)widget;
5073 (void)data;
5074
5075 char *fname;
45545076
45555077 if(GLOBALS->filesel_ok)
45565078 {
45675089 void
45685090 menu_read_script_file(gpointer null_data, guint callback_action, GtkWidget *widget)
45695091 {
5092 (void)null_data;
5093 (void)callback_action;
5094 (void)widget;
5095
45705096 if(GLOBALS->helpbox_is_active)
45715097 {
45725098 help_text_bold("\n\nRead Script File");
45855111 void
45865112 menu_insert_blank_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
45875113 {
5114 (void)null_data;
5115 (void)callback_action;
5116 (void)widget;
5117
45885118 if(GLOBALS->helpbox_is_active)
45895119 {
45905120 help_text_bold("\n\nInsert Blank");
46085138 void
46095139 menu_insert_analog_height_extension(gpointer null_data, guint callback_action, GtkWidget *widget)
46105140 {
5141 (void)null_data;
5142 (void)callback_action;
5143 (void)widget;
5144
46115145 if(GLOBALS->helpbox_is_active)
46125146 {
46135147 help_text_bold("\n\nInsert Analog Height Extension");
46315165 static void
46325166 comment_trace_cleanup(GtkWidget *widget, gpointer data)
46335167 {
5168 (void)widget;
5169 (void)data;
5170
46345171 InsertBlankTrace(GLOBALS->entrybox_text, 0);
46355172 if(GLOBALS->entrybox_text) { free_2(GLOBALS->entrybox_text); GLOBALS->entrybox_text=NULL; }
46365173 GLOBALS->signalwindow_width_dirty=1;
46425179 void
46435180 menu_insert_comment_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
46445181 {
5182 (void)null_data;
5183 (void)callback_action;
5184 (void)widget;
5185
46455186 if(GLOBALS->helpbox_is_active)
46465187 {
46475188 help_text_bold("\n\nInsert Comment");
46625203 /**/
46635204 static void strace_repcnt_cleanup(GtkWidget *widget, gpointer data)
46645205 {
5206 (void)widget;
5207 (void)data;
5208
46655209 if(GLOBALS->entrybox_text)
46665210 {
46675211 GLOBALS->strace_repeat_count = atoi_64(GLOBALS->entrybox_text);
46735217
46745218 void menu_strace_repcnt(gpointer null_data, guint callback_action, GtkWidget *widget)
46755219 {
5220 (void)null_data;
5221 (void)callback_action;
5222 (void)widget;
5223
46765224 char gt[32];
46775225
46785226 if(GLOBALS->helpbox_is_active)
46915239 /**/
46925240 static void movetotime_cleanup(GtkWidget *widget, gpointer data)
46935241 {
5242 (void)widget;
5243 (void)data;
5244
46945245 if(GLOBALS->entrybox_text)
46955246 {
4696 TimeType gt;
5247 TimeType gt = GLOBALS->tims.first;
46975248 char update_string[128];
46985249 char timval[40];
46995250 GtkAdjustment *hadj;
47015252
47025253 if((GLOBALS->entrybox_text[0] >= 'A' && GLOBALS->entrybox_text[0] <= 'Z')||(GLOBALS->entrybox_text[0] >= 'a' && GLOBALS->entrybox_text[0] <= 'z'))
47035254 {
4704 int uch = toupper((int)(unsigned char)GLOBALS->entrybox_text[0]);
4705 gt=GLOBALS->named_markers[uch - 'A'];
5255 char *su = GLOBALS->entrybox_text;
5256 int uch;
5257 while(*su)
5258 {
5259 uch = toupper((int)(unsigned char)*su);
5260 *su = uch;
5261 su++;
5262 }
5263
5264 uch = bijective_marker_id_string_hash(GLOBALS->entrybox_text);
5265
5266 if((uch >= 0)&&(uch < WAVE_NUM_NAMED_MARKERS))
5267 {
5268 gt=GLOBALS->named_markers[uch];
5269 }
47065270 }
47075271 else
47085272 {
47375301
47385302 void menu_movetotime(gpointer null_data, guint callback_action, GtkWidget *widget)
47395303 {
5304 (void)null_data;
5305 (void)callback_action;
5306 (void)widget;
5307
47405308 char gt[32];
47415309
47425310 if(GLOBALS->helpbox_is_active)
47575325 /**/
47585326 static void fetchsize_cleanup(GtkWidget *widget, gpointer data)
47595327 {
5328 (void)widget;
5329 (void)data;
5330
47605331 if(GLOBALS->entrybox_text)
47615332 {
47625333 TimeType fw;
47795350
47805351 void menu_fetchsize(gpointer null_data, guint callback_action, GtkWidget *widget)
47815352 {
5353 (void)null_data;
5354 (void)callback_action;
5355 (void)widget;
5356
47825357 char fw[32];
47835358
47845359 if(GLOBALS->helpbox_is_active)
47995374 /**/
48005375 static void zoomsize_cleanup(GtkWidget *widget, gpointer data)
48015376 {
5377 (void)widget;
5378 (void)data;
5379
48025380 if(GLOBALS->entrybox_text)
48035381 {
48045382 float f;
48325410
48335411 void menu_zoomsize(gpointer null_data, guint callback_action, GtkWidget *widget)
48345412 {
5413 (void)null_data;
5414 (void)callback_action;
5415 (void)widget;
5416
48355417 char za[32];
48365418
48375419 if(GLOBALS->helpbox_is_active)
48525434 /**/
48535435 static void zoombase_cleanup(GtkWidget *widget, gpointer data)
48545436 {
5437 (void)widget;
5438 (void)data;
5439
48555440 if(GLOBALS->entrybox_text)
48565441 {
48575442 float za;
48835468
48845469 void menu_zoombase(gpointer null_data, guint callback_action, GtkWidget *widget)
48855470 {
5471 (void)null_data;
5472 (void)callback_action;
5473 (void)widget;
5474
48865475 char za[32];
48875476
48885477 if(GLOBALS->helpbox_is_active)
49505539 void
49515540 menu_colorformat_0(gpointer null_data, guint callback_action, GtkWidget *widget)
49525541 {
5542 (void)null_data;
5543 (void)callback_action;
5544 (void)widget;
5545
49535546 if(GLOBALS->helpbox_is_active)
49545547 {
49555548 help_text_bold("\n\nColor Format Normal");
49655558 void
49665559 menu_colorformat_1(gpointer null_data, guint callback_action, GtkWidget *widget)
49675560 {
5561 (void)null_data;
5562 (void)callback_action;
5563 (void)widget;
5564
49685565 if(GLOBALS->helpbox_is_active)
49695566 {
49705567 help_text_bold("\n\nColor Format Red");
49805577 void
49815578 menu_colorformat_2(gpointer null_data, guint callback_action, GtkWidget *widget)
49825579 {
5580 (void)null_data;
5581 (void)callback_action;
5582 (void)widget;
5583
49835584 if(GLOBALS->helpbox_is_active)
49845585 {
49855586 help_text_bold("\n\nColor Format Orange");
49955596 void
49965597 menu_colorformat_3(gpointer null_data, guint callback_action, GtkWidget *widget)
49975598 {
5599 (void)null_data;
5600 (void)callback_action;
5601 (void)widget;
5602
49985603 if(GLOBALS->helpbox_is_active)
49995604 {
50005605 help_text_bold("\n\nColor Format Yellow");
50105615 void
50115616 menu_colorformat_4(gpointer null_data, guint callback_action, GtkWidget *widget)
50125617 {
5618 (void)null_data;
5619 (void)callback_action;
5620 (void)widget;
5621
50135622 if(GLOBALS->helpbox_is_active)
50145623 {
50155624 help_text_bold("\n\nColor Format Green");
50255634 void
50265635 menu_colorformat_5(gpointer null_data, guint callback_action, GtkWidget *widget)
50275636 {
5637 (void)null_data;
5638 (void)callback_action;
5639 (void)widget;
5640
50285641 if(GLOBALS->helpbox_is_active)
50295642 {
50305643 help_text_bold("\n\nColor Format Blue");
50405653 void
50415654 menu_colorformat_6(gpointer null_data, guint callback_action, GtkWidget *widget)
50425655 {
5656 (void)null_data;
5657 (void)callback_action;
5658 (void)widget;
5659
50435660 if(GLOBALS->helpbox_is_active)
50445661 {
50455662 help_text_bold("\n\nColor Format Indigo");
50555672 void
50565673 menu_colorformat_7(gpointer null_data, guint callback_action, GtkWidget *widget)
50575674 {
5675 (void)null_data;
5676 (void)callback_action;
5677 (void)widget;
5678
50585679 if(GLOBALS->helpbox_is_active)
50595680 {
50605681 help_text_bold("\n\nColor Format Violet");
50705691 void
50715692 menu_colorformat_cyc(gpointer null_data, guint callback_action, GtkWidget *widget)
50725693 {
5694 (void)null_data;
5695 (void)callback_action;
5696 (void)widget;
5697
50735698 if(GLOBALS->helpbox_is_active)
50745699 {
50755700 help_text_bold("\n\nColor Format Cycle");
52675892 static void
52685893 menu_open_hierarchy_2(gpointer null_data, guint callback_action, GtkWidget *widget, int typ)
52695894 {
5895 (void)null_data;
5896 (void)callback_action;
5897 (void)widget;
5898
52705899 Trptr t;
52715900 int fix=0;
52725901 struct tree *t_forced = NULL;
54246053 static void
54256054 menu_open_hierarchy_2a(gpointer null_data, guint callback_action, GtkWidget *widget, int typ)
54266055 {
6056 (void)null_data;
6057 (void)callback_action;
6058 (void)widget;
6059
54276060 if(GLOBALS->helpbox_is_active)
54286061 {
54296062 if((typ == FST_MT_SOURCESTEM) || (typ == FST_MT_SOURCEISTEM))
55516184 void
55526185 menu_dataformat_ascii(gpointer null_data, guint callback_action, GtkWidget *widget)
55536186 {
6187 (void)null_data;
6188 (void)callback_action;
6189 (void)widget;
6190
55546191 if(GLOBALS->helpbox_is_active)
55556192 {
55566193 help_text_bold("\n\nData Format-ASCII");
55686205 void
55696206 menu_dataformat_real(gpointer null_data, guint callback_action, GtkWidget *widget)
55706207 {
6208 (void)null_data;
6209 (void)callback_action;
6210 (void)widget;
6211
55716212 if(GLOBALS->helpbox_is_active)
55726213 {
55736214 help_text_bold("\n\nData Format-BitsToReal");
55866227 void
55876228 menu_dataformat_real2bon(gpointer null_data, guint callback_action, GtkWidget *widget)
55886229 {
6230 (void)null_data;
6231 (void)callback_action;
6232 (void)widget;
6233
55896234 if(GLOBALS->helpbox_is_active)
55906235 {
55916236 help_text_bold("\n\nData Format-RealToBits On");
56066251 void
56076252 menu_dataformat_real2boff(gpointer null_data, guint callback_action, GtkWidget *widget)
56086253 {
6254 (void)null_data;
6255 (void)callback_action;
6256 (void)widget;
6257
56096258 if(GLOBALS->helpbox_is_active)
56106259 {
56116260 help_text_bold("\n\nData Format-RealToBits Off");
56226271 void
56236272 menu_dataformat_hex(gpointer null_data, guint callback_action, GtkWidget *widget)
56246273 {
6274 (void)null_data;
6275 (void)callback_action;
6276 (void)widget;
6277
56256278 if(GLOBALS->helpbox_is_active)
56266279 {
56276280 help_text_bold("\n\nData Format-Hex");
56396292 void
56406293 menu_dataformat_dec(gpointer null_data, guint callback_action, GtkWidget *widget)
56416294 {
6295 (void)null_data;
6296 (void)callback_action;
6297 (void)widget;
6298
56426299 if(GLOBALS->helpbox_is_active)
56436300 {
56446301 help_text_bold("\n\nData Format-Decimal");
56566313 void
56576314 menu_dataformat_signed(gpointer null_data, guint callback_action, GtkWidget *widget)
56586315 {
6316 (void)null_data;
6317 (void)callback_action;
6318 (void)widget;
6319
56596320 if(GLOBALS->helpbox_is_active)
56606321 {
56616322 help_text_bold("\n\nData Format-Signed");
56736334 void
56746335 menu_dataformat_bin(gpointer null_data, guint callback_action, GtkWidget *widget)
56756336 {
6337 (void)null_data;
6338 (void)callback_action;
6339 (void)widget;
6340
56766341 if(GLOBALS->helpbox_is_active)
56776342 {
56786343 help_text_bold("\n\nData Format-Binary");
56906355 void
56916356 menu_dataformat_oct(gpointer null_data, guint callback_action, GtkWidget *widget)
56926357 {
6358 (void)null_data;
6359 (void)callback_action;
6360 (void)widget;
6361
56936362 if(GLOBALS->helpbox_is_active)
56946363 {
56956364 help_text_bold("\n\nData Format-Octal");
57076376 void
57086377 menu_dataformat_rjustify_on(gpointer null_data, guint callback_action, GtkWidget *widget)
57096378 {
6379 (void)null_data;
6380 (void)callback_action;
6381 (void)widget;
6382
57106383 if(GLOBALS->helpbox_is_active)
57116384 {
57126385 help_text_bold("\n\nData Format-Right Justify-On");
57246397 void
57256398 menu_dataformat_rjustify_off(gpointer null_data, guint callback_action, GtkWidget *widget)
57266399 {
6400 (void)null_data;
6401 (void)callback_action;
6402 (void)widget;
6403
57276404 if(GLOBALS->helpbox_is_active)
57286405 {
57296406 help_text_bold("\n\nData Format-Right Justify-Off");
57416418 void
57426419 menu_dataformat_bingray_on(gpointer null_data, guint callback_action, GtkWidget *widget)
57436420 {
6421 (void)null_data;
6422 (void)callback_action;
6423 (void)widget;
6424
57446425 if(GLOBALS->helpbox_is_active)
57456426 {
57466427 help_text_bold("\n\nData Format-Gray Filters-To Gray");
57596440 void
57606441 menu_dataformat_graybin_on(gpointer null_data, guint callback_action, GtkWidget *widget)
57616442 {
6443 (void)null_data;
6444 (void)callback_action;
6445 (void)widget;
6446
57626447 if(GLOBALS->helpbox_is_active)
57636448 {
57646449 help_text_bold("\n\nData Format-Gray Filters-From Gray");
57786463 void
57796464 menu_dataformat_nogray(gpointer null_data, guint callback_action, GtkWidget *widget)
57806465 {
6466 (void)null_data;
6467 (void)callback_action;
6468 (void)widget;
6469
57816470 if(GLOBALS->helpbox_is_active)
57826471 {
57836472 help_text_bold("\n\nData Format-Gray Filters-None");
57956484 void
57966485 menu_dataformat_popcnt_on(gpointer null_data, guint callback_action, GtkWidget *widget)
57976486 {
6487 (void)null_data;
6488 (void)callback_action;
6489 (void)widget;
6490
57986491 if(GLOBALS->helpbox_is_active)
57996492 {
58006493 help_text_bold("\n\nData Format-Popcnt-On");
58136506 void
58146507 menu_dataformat_popcnt_off(gpointer null_data, guint callback_action, GtkWidget *widget)
58156508 {
6509 (void)null_data;
6510 (void)callback_action;
6511 (void)widget;
6512
58166513 if(GLOBALS->helpbox_is_active)
58176514 {
58186515 help_text_bold("\n\nData Format-Popcnt-Off");
58306527 void
58316528 menu_dataformat_invert_on(gpointer null_data, guint callback_action, GtkWidget *widget)
58326529 {
6530 (void)null_data;
6531 (void)callback_action;
6532 (void)widget;
6533
58336534 if(GLOBALS->helpbox_is_active)
58346535 {
58356536 help_text_bold("\n\nData Format-Invert-On");
58476548 void
58486549 menu_dataformat_invert_off(gpointer null_data, guint callback_action, GtkWidget *widget)
58496550 {
6551 (void)null_data;
6552 (void)callback_action;
6553 (void)widget;
6554
58506555 if(GLOBALS->helpbox_is_active)
58516556 {
58526557 help_text_bold("\n\nData Format-Invert-Off");
58646569 void
58656570 menu_dataformat_reverse_on(gpointer null_data, guint callback_action, GtkWidget *widget)
58666571 {
6572 (void)null_data;
6573 (void)callback_action;
6574 (void)widget;
6575
58676576 if(GLOBALS->helpbox_is_active)
58686577 {
58696578 help_text_bold("\n\nData Format-Reverse Bits-On");
58816590 void
58826591 menu_dataformat_reverse_off(gpointer null_data, guint callback_action, GtkWidget *widget)
58836592 {
6593 (void)null_data;
6594 (void)callback_action;
6595 (void)widget;
6596
58846597 if(GLOBALS->helpbox_is_active)
58856598 {
58866599 help_text_bold("\n\nData Format-Reverse Bits-Off");
58986611 void
58996612 menu_dataformat_exclude_on(gpointer null_data, guint callback_action, GtkWidget *widget)
59006613 {
6614 (void)null_data;
6615 (void)callback_action;
6616 (void)widget;
6617
59016618 if(GLOBALS->helpbox_is_active)
59026619 {
59036620 help_text_bold("\n\nExclude");
59146631 void
59156632 menu_dataformat_exclude_off(gpointer null_data, guint callback_action, GtkWidget *widget)
59166633 {
6634 (void)null_data;
6635 (void)callback_action;
6636 (void)widget;
6637
59176638 if(GLOBALS->helpbox_is_active)
59186639 {
59196640 help_text_bold("\n\nShow");
59316652 void
59326653 menu_dataformat_rangefill_zero(gpointer null_data, guint callback_action, GtkWidget *widget)
59336654 {
6655 (void)null_data;
6656 (void)callback_action;
6657 (void)widget;
6658
59346659 if(GLOBALS->helpbox_is_active)
59356660 {
59366661 help_text_bold("\n\nData Format-Range Fill With 0s");
59496674 void
59506675 menu_dataformat_rangefill_one(gpointer null_data, guint callback_action, GtkWidget *widget)
59516676 {
6677 (void)null_data;
6678 (void)callback_action;
6679 (void)widget;
6680
59526681 if(GLOBALS->helpbox_is_active)
59536682 {
59546683 help_text_bold("\n\nData Format-Range Fill With 1s");
59696698 void
59706699 menu_dataformat_rangefill_off(gpointer null_data, guint callback_action, GtkWidget *widget)
59716700 {
6701 (void)null_data;
6702 (void)callback_action;
6703 (void)widget;
6704
59726705 if(GLOBALS->helpbox_is_active)
59736706 {
59746707 help_text_bold("\n\nData Format-Zero Range Fill Off");
59856718 void
59866719 menu_dataformat_analog_off(gpointer null_data, guint callback_action, GtkWidget *widget)
59876720 {
6721 (void)null_data;
6722 (void)callback_action;
6723 (void)widget;
6724
59886725 if(GLOBALS->helpbox_is_active)
59896726 {
59906727 help_text_bold("\n\nAnalog Off");
60016738 void
60026739 menu_dataformat_analog_step(gpointer null_data, guint callback_action, GtkWidget *widget)
60036740 {
6741 (void)null_data;
6742 (void)callback_action;
6743 (void)widget;
6744
60046745 if(GLOBALS->helpbox_is_active)
60056746 {
60066747 help_text_bold("\n\nAnalog Step");
60176758 void
60186759 menu_dataformat_analog_interpol(gpointer null_data, guint callback_action, GtkWidget *widget)
60196760 {
6761 (void)null_data;
6762 (void)callback_action;
6763 (void)widget;
6764
60206765 if(GLOBALS->helpbox_is_active)
60216766 {
60226767 help_text_bold("\n\nAnalog Interpolate");
60336778 void
60346779 menu_dataformat_analog_interpol_step(gpointer null_data, guint callback_action, GtkWidget *widget)
60356780 {
6781 (void)null_data;
6782 (void)callback_action;
6783 (void)widget;
6784
60366785 if(GLOBALS->helpbox_is_active)
60376786 {
60386787 help_text_bold("\n\nAnalog Interpolate Annotated");
60506799 void
60516800 menu_dataformat_analog_resize_screen(gpointer null_data, guint callback_action, GtkWidget *widget)
60526801 {
6802 (void)null_data;
6803 (void)callback_action;
6804 (void)widget;
6805
60536806 if(GLOBALS->helpbox_is_active)
60546807 {
60556808 help_text_bold("\n\nAnalog Resizing Screen Data");
60676820 void
60686821 menu_dataformat_analog_resize_all(gpointer null_data, guint callback_action, GtkWidget *widget)
60696822 {
6823 (void)null_data;
6824 (void)callback_action;
6825 (void)widget;
6826
60706827 if(GLOBALS->helpbox_is_active)
60716828 {
60726829 help_text_bold("\n\nAnalog Resizing All Data");
60846841 /**/
60856842 void menu_dataformat_highlight_all(gpointer null_data, guint callback_action, GtkWidget *widget)
60866843 {
6844 (void)null_data;
6845 (void)callback_action;
6846 (void)widget;
6847
60876848 Trptr t;
60886849
60896850 if(GLOBALS->helpbox_is_active)
61116872
61126873 void menu_dataformat_unhighlight_all(gpointer null_data, guint callback_action, GtkWidget *widget)
61136874 {
6875 (void)null_data;
6876 (void)callback_action;
6877 (void)widget;
6878
61146879 Trptr t;
61156880
61166881 if(GLOBALS->helpbox_is_active)
61386903
61396904 void menu_lexize(gpointer null_data, guint callback_action, GtkWidget *widget)
61406905 {
6906 (void)null_data;
6907 (void)callback_action;
6908 (void)widget;
6909
61416910 if(GLOBALS->helpbox_is_active)
61426911 {
61436912 help_text_bold("\n\nSigsort All");
61616930 /**/
61626931 void menu_alphabetize(gpointer null_data, guint callback_action, GtkWidget *widget)
61636932 {
6933 (void)null_data;
6934 (void)callback_action;
6935 (void)widget;
6936
61646937 if(GLOBALS->helpbox_is_active)
61656938 {
61666939 help_text_bold("\n\nAlphabetize All");
61846957 /**/
61856958 void menu_alphabetize2(gpointer null_data, guint callback_action, GtkWidget *widget)
61866959 {
6960 (void)null_data;
6961 (void)callback_action;
6962 (void)widget;
6963
61876964 if(GLOBALS->helpbox_is_active)
61886965 {
61896966 help_text_bold("\n\nAlphabetize All (CaseIns)");
62076984 /**/
62086985 void menu_reverse(gpointer null_data, guint callback_action, GtkWidget *widget)
62096986 {
6987 (void)null_data;
6988 (void)callback_action;
6989 (void)widget;
6990
62106991 if(GLOBALS->helpbox_is_active)
62116992 {
62126993 help_text_bold("\n\nReverse All");
62317012 void
62327013 menu_cut_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
62337014 {
7015 (void)null_data;
7016 (void)callback_action;
7017 (void)widget;
7018
62347019 Trptr cutbuffer = NULL;
62357020
62367021 if(GLOBALS->helpbox_is_active)
62717056 void
62727057 menu_copy_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
62737058 {
7059 (void)null_data;
7060 (void)callback_action;
7061 (void)widget;
7062
62747063 Trptr t = GLOBALS->traces.first;
62757064 gboolean highlighted = FALSE;
62767065
63197108 void
63207109 menu_paste_traces(gpointer null_data, guint callback_action, GtkWidget *widget)
63217110 {
7111 (void)null_data;
7112 (void)callback_action;
7113 (void)widget;
7114
63227115 if(GLOBALS->helpbox_is_active)
63237116 {
63247117 help_text_bold("\n\nPaste");
63607153 /**/
63617154 void menu_center_zooms(gpointer null_data, guint callback_action, GtkWidget *widget)
63627155 {
7156 (void)null_data;
7157 (void)callback_action;
7158 (void)widget;
7159
63637160 if(GLOBALS->helpbox_is_active)
63647161 {
63657162 help_text_bold("\n\nCenter Zooms");
63917188
63927189 void menu_show_base(gpointer null_data, guint callback_action, GtkWidget *widget)
63937190 {
7191 (void)null_data;
7192 (void)callback_action;
7193 (void)widget;
7194
63947195 if(GLOBALS->helpbox_is_active)
63957196 {
63967197 help_text_bold("\n\nShow Base Symbols");
64247225 /**/
64257226 void menu_show_grid(gpointer null_data, guint callback_action, GtkWidget *widget)
64267227 {
7228 (void)null_data;
7229 (void)callback_action;
7230 (void)widget;
7231
64277232 if(GLOBALS->helpbox_is_active)
64287233 {
64297234 help_text_bold("\n\nShow Grid");
64547259 /**/
64557260 void menu_show_wave_highlight(gpointer null_data, guint callback_action, GtkWidget *widget)
64567261 {
7262 (void)null_data;
7263 (void)callback_action;
7264 (void)widget;
7265
64577266 if(GLOBALS->helpbox_is_active)
64587267 {
64597268 help_text_bold("\n\nShow Wave Highlight");
64847293 /**/
64857294 void menu_show_mouseover(gpointer null_data, guint callback_action, GtkWidget *widget)
64867295 {
7296 (void)null_data;
7297 (void)callback_action;
7298 (void)widget;
7299
64877300 if(GLOBALS->helpbox_is_active)
64887301 {
64897302 help_text_bold("\n\nShow Mouseover");
71167929 */
71177930 int file_quit_cmd_callback (GtkWidget *widget, gpointer data)
71187931 {
7932 (void)widget;
7933 (void)data;
7934
71197935 if(!GLOBALS->enable_fast_exit)
71207936 {
71217937 simplereqbox("Quit Program",300,"Do you really want to quit?","Yes", "No", GTK_SIGNAL_FUNC(menu_quit_callback), 1);
71387954 */
71397955 int execute_script(char *name, int dealloc_name)
71407956 {
7141 int i;
7957 unsigned int i;
71427958 int nlen = strlen(name);
71437959
71447960 if(GLOBALS->tcl_running)
73488164
73498165 void do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
73508166 {
8167 (void)my_widget;
8168
73518169 GtkWidget *menu;
73528170 int button, event_time;
73538171
74158233
74168234 void do_sst_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
74178235 {
8236 (void)my_widget;
8237
74188238 GtkWidget *menu;
74198239 int button, event_time;
74208240
76188438 {
76198439 struct menu_item_t *ptr = lst;
76208440 struct menu_item_t *optr;
7621 int i;
76228441 GtkWidget *menu;
76238442 GtkWidget *menuitem;
76248443
1616 void
1717 service_left_page(GtkWidget *text, gpointer data)
1818 {
19 (void)text;
20 (void)data;
21
1922 TimeType ntinc, ntfrac;
2023
2124 if(GLOBALS->helpbox_is_active)
3336
3437 ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx); /* really don't need this var but the speed of ui code is human dependent.. */
3538 ntfrac=ntinc*GLOBALS->page_divisor;
36 if((ntfrac<1)||(ntinc<1))
39 if((ntfrac<1)||(ntinc<1))
3740 ntfrac= /*ntinc=*/ 1; /* scan-build */
3841
39 if((GLOBALS->tims.start-ntfrac)>GLOBALS->tims.first)
42 if((GLOBALS->tims.start-ntfrac)>GLOBALS->tims.first)
4043 GLOBALS->tims.timecache=GLOBALS->tims.start-ntfrac;
41 else
44 else
4245 GLOBALS->tims.timecache=GLOBALS->tims.first;
4346
4447 GTK_ADJUSTMENT(GLOBALS->wave_hslider)->value=GLOBALS->tims.timecache;
5053 void
5154 service_right_page(GtkWidget *text, gpointer data)
5255 {
56 (void)text;
57 (void)data;
58
5359 TimeType ntinc, ntfrac;
5460
5561 if(GLOBALS->helpbox_is_active)
6773
6874 ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);
6975 ntfrac=ntinc*GLOBALS->page_divisor;
70
71 if((ntfrac<1)||(ntinc<1))
76
77 if((ntfrac<1)||(ntinc<1))
7278 ntfrac=ntinc=1;
7379
7480 if((GLOBALS->tims.start+ntfrac)<(GLOBALS->tims.last-ntinc+1))
7884 else
7985 {
8086 GLOBALS->tims.timecache=GLOBALS->tims.last-ntinc+1;
81 if(GLOBALS->tims.timecache<GLOBALS->tims.first)
87 if(GLOBALS->tims.timecache<GLOBALS->tims.first)
8288 GLOBALS->tims.timecache=GLOBALS->tims.first;
8389 }
8490
11721172 xl = ((gdouble) (t - GLOBALS->tims.start)) / pixstep; /* snap to integer */
11731173 if ((xl >= 0) && (xl < GLOBALS->wavewidth))
11741174 {
1175 char nbuff[2];
1176 nbuff[0] = 'A' + i;
1177 nbuff[1] = 0x00;
1175 char nbuff[16];
1176 make_bijective_marker_id_string(nbuff, i);
11781177
11791178 pr_setgray (prc, gray);
11801179 for (y = GLOBALS->fontheight - 1;
12261225 {
12271226 int i;
12281227
1229 for(i=0;i<26;i++)
1228 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
12301229 {
12311230 if(i != GLOBALS->named_marker_lock_idx)
12321231 {
3636 void remove_all_proc_filters(void)
3737 {
3838 struct Global *GLOBALS_cache = GLOBALS;
39 int i, j;
39 unsigned int i, j;
4040
4141 for(j=0;j<GLOBALS->num_notebook_pages;j++)
4242 {
207207
208208 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
209209 {
210 (void)widget;
211 (void)nothing;
212
210213 GLOBALS->is_active_ptranslate_c_2=0;
211214 gtk_widget_destroy(GLOBALS->window_ptranslate_c_5);
212215 GLOBALS->window_ptranslate_c_5 = NULL;
221224 static void select_row_callback(GtkWidget *widget, gint row, gint column,
222225 GdkEventButton *event, gpointer data)
223226 {
227 (void)widget;
228 (void)row;
229 (void)column;
230 (void)event;
231 (void)data;
232
224233 GLOBALS->current_filter_ptranslate_c_1 = row + 1;
225234 }
226235
227236 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
228237 GdkEventButton *event, gpointer data)
229238 {
239 (void)widget;
240 (void)row;
241 (void)column;
242 (void)event;
243 (void)data;
244
230245 GLOBALS->current_filter_ptranslate_c_1 = 0; /* none */
231246 }
232247
233248
234249 static void add_filter_callback_2(GtkWidget *widget, GtkWidget *nothing)
235250 {
251 (void)widget;
252 (void)nothing;
253
236254 int i;
237255 GtkCList *cl;
238256
279297
280298 static void add_filter_callback(GtkWidget *widget, GtkWidget *nothing)
281299 {
300 (void)widget;
301 (void)nothing;
302
282303 if(GLOBALS->num_proc_filters == PROC_FILTER_MAX)
283304 {
284305 status_text("Max number of process filters installed already.\n");
3636 */
3737 static void render_clicked(GtkWidget *widget, gpointer which)
3838 {
39 (void)widget;
40
3941 int i;
4042
4143 for(i=0;i<4;i++) GLOBALS->target_mutex_renderopt_c_1[i]=0;
4850
4951 static void pagesize_clicked(GtkWidget *widget, gpointer which)
5052 {
53 (void)widget;
54
5155 int i;
5256
5357 for(i=0;i<5;i++) GLOBALS->page_mutex_renderopt_c_1[i]=0;
6064
6165 static void rendertype_clicked(GtkWidget *widget, gpointer which)
6266 {
67 (void)widget;
68
6369 int i;
6470
6571 for(i=0;i<3;i++) GLOBALS->render_mutex_renderopt_c_1[i]=0;
7480 static void
7581 ps_print_cleanup(GtkWidget *widget, gpointer data)
7682 {
83 (void)widget;
84 (void)data;
85
7786 FILE *wave;
7887
7988 if(GLOBALS->filesel_ok)
97106 static void
98107 pdf_print_cleanup(GtkWidget *widget, gpointer data)
99108 {
109 (void)widget;
110 (void)data;
111
100112 FILE *wave;
101113 FILE *wave2;
102114
169181 static void
170182 mif_print_cleanup(GtkWidget *widget, gpointer data)
171183 {
184 (void)widget;
185 (void)data;
186
172187 FILE *wave;
173188
174189 if(GLOBALS->filesel_ok)
193208 #ifdef WAVE_GTK_UNIX_PRINT
194209 static void wave_GtkPrintJobCompleteFunc(GtkPrintJob *print_job, gpointer user_data, GError *error)
195210 {
211 (void)print_job;
212 (void)error;
213
196214 if(user_data)
197215 {
198216 const char *ban = "Sent print job";
209227 static void
210228 unix_print_cleanup(GtkWidget *widget, gpointer data)
211229 {
230 (void)widget;
231 (void)data;
232
212233 #ifdef WAVE_GTK_UNIX_PRINT
213234 GtkWidget *ropt = gtk_print_unix_dialog_new("GTK Print UNIX Options", GTK_WINDOW(GLOBALS->mainwindow));
214235 gint gd_rc;
325346
326347 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
327348 {
349 (void)widget;
350 (void)nothing;
351
328352 GLOBALS->is_active_renderopt_c_3=0;
329353 gtk_widget_destroy(GLOBALS->window_renderopt_c_6);
330354 GLOBALS->window_renderopt_c_6 = NULL;
186186
187187 fprintf(wave,"*%f "TTFormat, (float)(GLOBALS->tims.zoom),GLOBALS->tims.marker);
188188
189 for(i=0;i<26;i++)
189 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
190190 {
191191 TimeType nm = GLOBALS->named_markers[i]; /* gcc compiler problem...thinks this is a 'long int' in printf format warning reporting */
192192 fprintf(wave," "TTFormat,nm);
193193 }
194194 fprintf(wave,"\n");
195195
196 for(i=0;i<26;i++)
196 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
197197 {
198198 if(GLOBALS->marker_names[i])
199199 {
200 fprintf(wave, "[markername] %c%s\n", 'A'+i, GLOBALS->marker_names[i]);
200 char mbuf[16];
201
202 make_bijective_marker_id_string(mbuf, i);
203 if(strlen(mbuf)<2)
204 {
205 fprintf(wave, "[markername] %s%s\n", mbuf, GLOBALS->marker_names[i]);
206 }
207 else
208 {
209 fprintf(wave, "[markername_long] %s %s\n", mbuf, GLOBALS->marker_names[i]);
210 }
201211 }
202212 }
203213
10661076 {
10671077 case 1: GLOBALS->tims.marker=ttlocal; break;
10681078 default:
1069 if((which-2)<26) GLOBALS->named_markers[which-2]=ttlocal;
1079 if((which-2)<WAVE_NUM_NAMED_MARKERS) GLOBALS->named_markers[which-2]=ttlocal;
10701080 break;
10711081 }
10721082 }
16211631 if(*pnt)
16221632 {
16231633 which = (*pnt) - 'A';
1624 if((which >=0) && (which <= 25))
1634 if((which >=0) && (which < WAVE_NUM_NAMED_MARKERS))
16251635 {
16261636 pnt++;
16271637
16291639 {
16301640 if(GLOBALS->marker_names[which]) free_2(GLOBALS->marker_names[which]);
16311641 GLOBALS->marker_names[which] = strdup_2(pnt);
1642 }
1643 }
1644 }
1645 }
1646 else if (strcmp (w2, "markername_long") == 0)
1647 {
1648 char *pnt = w;
1649 int which;
1650
1651 if((*pnt) && (isspace((int)(unsigned char)*pnt))) pnt++;
1652
1653 if(*pnt)
1654 {
1655 char *pnt2 = strchr(pnt, ' ');
1656 if(pnt2)
1657 {
1658 *pnt2 = 0;
1659 which = bijective_marker_id_string_hash(pnt);
1660 if((which >=0) && (which < WAVE_NUM_NAMED_MARKERS))
1661 {
1662 pnt = pnt2 + 1;
1663 if((*pnt) && (isspace((int)(unsigned char)*pnt))) pnt++;
1664
1665 if(*pnt)
1666 {
1667 if(GLOBALS->marker_names[which]) free_2(GLOBALS->marker_names[which]);
1668 GLOBALS->marker_names[which] = strdup_2(pnt);
1669 }
16321670 }
16331671 }
16341672 }
17231761 */
17241762 int maketraces_lx2(char *str, char *alias, int quick_return)
17251763 {
1764 (void)alias;
1765
17261766 char *pnt, *wild;
17271767 char ch, wild_active=0;
17281768 int len;
25972637 */
25982638 gboolean deal_with_rpc_open_2(const gchar *path, gpointer user_data, gboolean is_save_file_only)
25992639 {
2640 (void)user_data;
2641
26002642 const char *suffixes[] =
26012643 {
26022644 ".vcd", ".evcd", ".dump",
26752717 */
26762718 gboolean deal_with_termination(GtkOSXApplication *app, gpointer user_data)
26772719 {
2720 (void)app;
2721 (void)user_data;
2722
26782723 gboolean do_not_terminate = FALSE; /* future expansion */
26792724
26802725 if(do_not_terminate)
26922737 */
26932738 gboolean deal_with_finder_open(GtkOSXApplication *app, gchar *path, gpointer user_data)
26942739 {
2740 (void)app;
2741
26952742 return(deal_with_rpc_open(path, user_data));
26962743 }
26972744
27002747
27012748 int suffix_check(const char *s, const char *sfx)
27022749 {
2703 int sfxlen = strlen(sfx);
2750 unsigned int sfxlen = strlen(sfx);
27042751 return((strlen(s)>=sfxlen)&&(!strcasecmp(s+strlen(s)-sfxlen,sfx)));
27052752 }
27062753
8181
8282 static void enter_callback_e(GtkWidget *widget, GtkWidget *nothing)
8383 {
84 (void)widget;
85 (void)nothing;
86
8487 G_CONST_RETURN gchar *entry_text;
8588 int len;
8689 char *vname="<Vector>";
100103
101104 static void destroy_callback_e(GtkWidget *widget, GtkWidget *nothing)
102105 {
106 (void)widget;
107 (void)nothing;
108
103109 DEBUG(printf("Entry Cancel\n"));
104110 GLOBALS->entrybox_text_local_search_c_2=NULL;
105111 wave_gtk_grab_remove(GLOBALS->window1_search_c_2);
168174
169175 static void regex_clicked(GtkWidget *widget, gpointer which)
170176 {
177 (void)widget;
178
171179 int i;
172180
173181 for(i=0;i<5;i++) GLOBALS->regex_mutex_search_c_1[i]=0;
188196 static void
189197 bundle_cleanup(GtkWidget *widget, gpointer data)
190198 {
199 (void)widget;
200 (void)data;
201
191202 if(GLOBALS->entrybox_text_local_search_c_2)
192203 {
193204 char *efix;
225236 static void
226237 bundle_callback_up(GtkWidget *widget, gpointer data)
227238 {
239 (void)widget;
240 (void)data;
241
228242 GLOBALS->bundle_direction_search_c_2=0;
229243 bundle_callback_generic();
230244 }
232246 static void
233247 bundle_callback_down(GtkWidget *widget, gpointer data)
234248 {
249 (void)widget;
250 (void)data;
251
235252 GLOBALS->bundle_direction_search_c_2=1;
236253 bundle_callback_generic();
237254 }
238255
239256 static void insert_callback(GtkWidget *widget, GtkWidget *nothing)
240257 {
258 (void)nothing;
259
241260 search_insert_callback(widget, 0); /* native to search */
242261 }
243262
390409
391410 static void replace_callback(GtkWidget *widget, GtkWidget *nothing)
392411 {
412 (void)nothing;
413
393414 Traces tcache;
394415 int i;
395416 Trptr tfirst, tlast;
575596
576597 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
577598 {
599 (void)nothing;
600
578601 int i;
579602 struct symchain *symc, *symc_current;
580603
699722 static void select_row_callback(GtkWidget *widget, gint row, gint column,
700723 GdkEventButton *event, gpointer data)
701724 {
725 (void)widget;
726 (void)column;
727 (void)event;
728 (void)data;
729
702730 struct symbol *s;
703731
704732 s=(struct symbol *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_search_c_3), row);
710738 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
711739 GdkEventButton *event, gpointer data)
712740 {
741 (void)widget;
742 (void)column;
743 (void)event;
744 (void)data;
745
713746 struct symbol *s;
714747
715748 s=(struct symbol *)gtk_clist_get_row_data(GTK_CLIST(GLOBALS->clist_search_c_3), row);
866899
867900 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
868901 {
902 (void)widget;
903 (void)nothing;
904
869905 if((!GLOBALS->is_insert_running_search_c_1)&&(!GLOBALS->is_replace_running_search_c_1)&&(!GLOBALS->is_append_running_search_c_1)&&(!GLOBALS->is_searching_running_search_c_1))
870906 {
871907 GLOBALS->is_active_search_c_4=0;
878914
879915 static void select_all_callback(GtkWidget *widget, GtkWidget *nothing)
880916 {
917 (void)widget;
918 (void)nothing;
919
881920 gtk_clist_select_all(GTK_CLIST(GLOBALS->clist_search_c_3));
882921 }
883922
884923 static void unselect_all_callback(GtkWidget *widget, GtkWidget *nothing)
885924 {
925 (void)widget;
926 (void)nothing;
927
886928 gtk_clist_unselect_all(GTK_CLIST(GLOBALS->clist_search_c_3));
887929 }
888930
1515 void
1616 service_left_shift(GtkWidget *text, gpointer data)
1717 {
18 (void)text;
19 (void)data;
20
1821 GtkAdjustment *hadj;
1922 gfloat inc;
2023 TimeType ntinc;
5154 void
5255 service_right_shift(GtkWidget *text, gpointer data)
5356 {
57 (void)text;
58 (void)data;
59
5460 GtkAdjustment *hadj;
5561 gfloat inc;
5662 TimeType ntinc, pageinc;
3232
3333 static void toggle1_callback(GtkWidget *widget, GtkWidget *nothing)
3434 {
35 (void)nothing;
36
3537 toggle_generic(widget, TR_RJUSTIFY);
3638 }
3739 static void toggle2_callback(GtkWidget *widget, GtkWidget *nothing)
3840 {
41 (void)nothing;
42
3943 toggle_generic(widget, TR_INVERT);
4044 }
4145 static void toggle3_callback(GtkWidget *widget, GtkWidget *nothing)
4246 {
47 (void)nothing;
48
4349 toggle_generic(widget, TR_REVERSE);
4450 }
4551 static void toggle4_callback(GtkWidget *widget, GtkWidget *nothing)
4652 {
53 (void)nothing;
54
4755 toggle_generic(widget, TR_EXCLUDE);
4856 }
4957
5058 static void enter_callback(GtkWidget *widget, GtkWidget *nothing)
5159 {
60 (void)widget;
61 (void)nothing;
62
5263 GLOBALS->flags_showchange_c_1=GLOBALS->flags_showchange_c_1&(~(TR_HIGHLIGHT|TR_NUMMASK));
5364
5465 if(GTK_TOGGLE_BUTTON(GLOBALS->button1_showchange_c_1)->active)
93104
94105 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
95106 {
107 (void)widget;
108 (void)nothing;
109
96110 wave_gtk_grab_remove(GLOBALS->window_showchange_c_8);
97111 gtk_widget_destroy(GLOBALS->window_showchange_c_8);
98112 GLOBALS->window_showchange_c_8 = NULL;
2929 static void
3030 service_hslider(GtkWidget *text, gpointer data)
3131 {
32 (void)text;
33 (void)data;
34
3235 GtkAdjustment *hadj;
3336 gint xsrc;
3437
8184 GtkWidget *widget, GdkDragContext *dc, gpointer data
8285 )
8386 {
87 (void)widget;
88 (void)dc;
89 (void)data;
8490
8591 GLOBALS->dnd_state = 1;
8692 }
94100 GtkWidget *widget, GdkDragContext *dc, gpointer data
95101 )
96102 {
103 (void)widget;
104 (void)dc;
105 (void)data;
106
97107 GtkWidget *ddest;
98108 int which;
99109 gdouble x,y;
215225 gpointer data
216226 )
217227 {
228 (void)xx;
229 (void)yy;
230 (void)data;
231
218232 gboolean same_widget;
219233 GdkDragAction suggested_action;
220234 GtkWidget *src_widget, *tar_widget;
412426 */
413427 static gint keypress_local(GtkWidget *widget, GdkEventKey *event, gpointer data)
414428 {
429 (void)widget;
430 (void)data;
431
415432 GtkAdjustment *wadj;
416433 int num_traces_displayable;
417434 int target;
708725
709726 static gboolean mouseover_timer(gpointer dummy)
710727 {
728 (void)dummy;
729
711730 static gboolean run_once = FALSE;
712731 gdouble x,y;
713732 GdkModifierType state;
10091028
10101029 static gint motion_notify_event_std(GtkWidget *widget, GdkEventMotion *event)
10111030 {
1031 (void)widget;
1032
10121033 gdouble x,y;
10131034 GdkModifierType state;
10141035
10401061
10411062 static gint button_release_event_std(GtkWidget *widget, GdkEventButton *event)
10421063 {
1064 (void)widget;
1065 (void)event;
1066
10431067 if(GLOBALS->std_collapse_pressed)
10441068 {
10451069 GLOBALS->std_collapse_pressed = 0;
12681292
12691293 gint signalarea_configure_event(GtkWidget *widget, GdkEventConfigure *event)
12701294 {
1295 (void)event;
1296
12711297 GtkAdjustment *wadj, *hadj;
12721298 int num_traces_displayable;
12731299 int width;
15011527 static int focus_in_local(GtkWidget *widget, GdkEventFocus *event)
15021528 {
15031529 #ifdef FOCUS_DEBUG_MSGS
1530 (void)event;
1531
15041532 printf("Focus in: %08x %08x\n", widget, GLOBALS->signalarea_event_box);
1533 #else
1534 (void)widget;
1535 (void)event;
15051536 #endif
15061537
15071538 GLOBALS->signalarea_has_focus = TRUE;
15141545 static int focus_out_local(GtkWidget *widget, GdkEventFocus *event)
15151546 {
15161547 #ifdef FOCUS_DEBUG_MSGS
1548 (void)event;
1549
15171550 printf("Focus out: %08x\n", widget);
1551 #else
1552 (void)widget;
1553 (void)event;
15181554 #endif
15191555
15201556 GLOBALS->signalarea_has_focus = FALSE;
2222
2323 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
2424 {
25 (void)widget;
26 (void)nothing;
27
2528 DEBUG(printf("OK\n"));
2629 wave_gtk_grab_remove(GLOBALS->window_simplereq_c_9);
2730 gtk_widget_destroy(GLOBALS->window_simplereq_c_9);
3134
3235 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
3336 {
37 (void)widget;
38 (void)nothing;
39
3440 DEBUG(printf("Cancel\n"));
3541 wave_gtk_grab_remove(GLOBALS->window_simplereq_c_9);
3642 gtk_widget_destroy(GLOBALS->window_simplereq_c_9);
4753 GtkWidget *button1, *button2;
4854 GtkWidget *label, *separator;
4955 GtkWidget *pixmapwid1;
56 #else
57 (void)width;
5058 #endif
5159
5260 if(GLOBALS->window_simplereq_c_9) return; /* only should happen with GtkPlug */
689689
690690 gint splash_button_press_event(GtkWidget *widget, GdkEventExpose *event)
691691 {
692 (void)widget;
693 (void)event;
694
692695 if(GLOBALS->timeout_tag) { gtk_timeout_remove(GLOBALS->timeout_tag); GLOBALS->timeout_tag = 0; }
693696
694697 if(GLOBALS->wave_splash_pixmap)
712715
713716 gint splash_kill(gpointer dummy)
714717 {
718 (void)dummy;
719
715720 gulong usec;
716721 if(GLOBALS && GLOBALS->gt_splash_c_1)
717722 {
5555 void
5656 realize_text (GtkWidget *text, gpointer data)
5757 {
58 (void)text;
59 (void)data;
60
5861 char buf[128];
5962
6063 if(GLOBALS->is_vcd)
212212 GET_WV_STRACE_CURWIN(widget);
213213
214214 GLOBALS->strace_ctx->mark_idx_start=((struct item_mark_string*)which)->idx;
215 if (GLOBALS->strace_ctx->mark_idx_start<0 || GLOBALS->strace_ctx->mark_idx_start>=(sizeof(item_mark_start_strings)/sizeof(struct item_mark_string)))
215 if (GLOBALS->strace_ctx->mark_idx_start<0 || GLOBALS->strace_ctx->mark_idx_start>=(int)(sizeof(item_mark_start_strings)/sizeof(struct item_mark_string)))
216216 {
217217 fprintf(stderr, "Internal error: GLOBALS->mark_idx_start out of range %d\n", GLOBALS->strace_ctx->mark_idx_start);
218218 exit(255);
225225 GET_WV_STRACE_CURWIN(widget);
226226
227227 GLOBALS->strace_ctx->mark_idx_end=((struct item_mark_string*)which)->idx;
228 if (GLOBALS->strace_ctx->mark_idx_end<0 || GLOBALS->strace_ctx->mark_idx_end>=(sizeof(item_mark_end_strings)/sizeof(struct item_mark_string)))
228 if (GLOBALS->strace_ctx->mark_idx_end<0 || GLOBALS->strace_ctx->mark_idx_end>=(int)(sizeof(item_mark_end_strings)/sizeof(struct item_mark_string)))
229229 {
230230 fprintf(stderr, "Internal error: GLOBALS->mark_idx_end out of range %d\n",GLOBALS->strace_ctx->mark_idx_end);
231231 exit(255);
264264
265265 static void forwards_callback(GtkWidget *widget, GtkWidget *nothing)
266266 {
267 (void)nothing;
268
267269 GET_WV_STRACE_CURWIN(widget);
268270
269271 /* no cleanup necessary, but do real search */
273275
274276 static void backwards_callback(GtkWidget *widget, GtkWidget *nothing)
275277 {
278 (void)nothing;
279
276280 GET_WV_STRACE_CURWIN(widget);
277281
278282 /* no cleanup necessary, but do real search */
282286
283287 static void mark_callback(GtkWidget *widget, GtkWidget *nothing)
284288 {
289 (void)nothing;
290
285291 GET_WV_STRACE_CURWIN(widget);
286292
287293 DEBUG(printf("Marking..\n"));
300306
301307 static void clear_callback(GtkWidget *widget, GtkWidget *nothing)
302308 {
309 (void)nothing;
310
303311 GET_WV_STRACE_CURWIN(widget);
304312
305313 DEBUG(printf("Clearing..\n"));
316324
317325 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
318326 {
327 (void)nothing;
328
319329 GET_WV_STRACE_CURWIN(widget);
320330
321331 free_straces();
495505
496506 do /* add GUI elements for displaying mark count and mark count start/end */
497507 {
498 int idx;
508 unsigned int idx;
499509 GtkWidget *ptr_mark_start_label, *ptr_mark_end_label;
500510 GtkWidget *mark_count_hbox_start, *mark_count_hbox_end;
501511 GtkWidget *count_vbox_left, *count_vbox_right, *count_vbox, *count_hbox;
145145
146146 h^=h2; /* combine the two hashes */
147147 GLOBALS->hashcache=h%SYMPRIME;
148 #else
149 (void)s;
148150 #endif
149151 return(GLOBALS->hashcache);
150152 }
159161 struct symbol *s=(struct symbol *)calloc_2(1,sizeof(struct symbol));
160162
161163 #ifdef _WAVE_HAVE_JUDY
164 (void)hv;
162165
163166 PPvoid_t PPValue = JudySLIns(&GLOBALS->sym_judy, (uint8_t *)name, PJE0);
164167 *((struct symbol **)PPValue) = s;
178181 struct symbol *s=(struct symbol *)calloc_2(1,sizeof(struct symbol));
179182
180183 #ifdef _WAVE_HAVE_JUDY
184 (void)hv;
181185
182186 PPvoid_t PPValue = JudySLIns(&GLOBALS->sym_judy, (uint8_t *)name, PJE0);
183187 *((struct symbol **)PPValue) = s;
00 /*
1 * Copyright (c) Tony Bybell 2008-2012.
1 * Copyright (c) Tony Bybell 2008-2014.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
5353
5454 static int gtkwavetcl_badNumArgs(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int expected)
5555 {
56 (void)clientData;
57
5658 Tcl_Obj *aobj;
5759 char reportString[1024];
5860
6567
6668 static int gtkwavetcl_nop(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
6769 {
70 (void)clientData;
71 (void)interp;
72 (void)objc;
73 (void)objv;
74
6875 /* nothing, this is simply to call gtk's main loop */
6976 gtkwave_main_iteration();
7077 return(TCL_OK);
7279
7380 static int gtkwavetcl_printInteger(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int intVal)
7481 {
82 (void)clientData;
83 (void)objc;
84 (void)objv;
85
7586 Tcl_Obj *aobj;
7687 char reportString[33];
7788
8596
8697 static int gtkwavetcl_printTimeType(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], TimeType ttVal)
8798 {
99 (void)clientData;
100 (void)objc;
101 (void)objv;
102
88103 Tcl_Obj *aobj;
89104 char reportString[65];
90105
98113
99114 static int gtkwavetcl_printDouble(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], double dVal)
100115 {
116 (void)clientData;
117 (void)objc;
118 (void)objv;
119
101120 Tcl_Obj *aobj;
102121 char reportString[65];
103122
111130
112131 static int gtkwavetcl_printString(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char *reportString)
113132 {
133 (void)clientData;
134 (void)objc;
135 (void)objv;
136
114137 Tcl_Obj *aobj;
115138
116139 aobj = Tcl_NewStringObj(reportString, -1);
229252
230253 static int gtkwavetcl_getTimeDimension(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
231254 {
255 (void)clientData;
256 (void)objc;
257 (void)objv;
258
232259 Tcl_Obj *aobj;
233260 char reportString[2];
234261
243270
244271 static int gtkwavetcl_getArgv(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
245272 {
273 (void)clientData;
274 (void)objc;
275 (void)objv;
276
246277 if(GLOBALS->argvlist)
247278 {
248279 Tcl_Obj *aobj = Tcl_NewStringObj(GLOBALS->argvlist, -1);
278309
279310 static int gtkwavetcl_getDumpType(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
280311 {
312 (void)clientData;
313 (void)objc;
314 (void)objv;
315
281316 Tcl_Obj *aobj;
282317 char *reportString = "UNKNOWN";
283318
328363 if(objc == 2)
329364 {
330365 char *s = get_Tcl_string(objv[1]);
331 int which;
366 int which = -1;
332367
333368 if((s[0]>='A')&&(s[0]<='Z'))
334369 {
335 TimeType value = GLOBALS->named_markers[s[0] - 'A'];
336 return(gtkwavetcl_printTimeType(clientData, interp, objc, objv, value));
370 which = bijective_marker_id_string_hash(s);
337371 }
338372 else
339373 if((s[0]>='a')&&(s[0]<='z'))
340374 {
341 TimeType value = GLOBALS->named_markers[s[0] - 'a'];
342 return(gtkwavetcl_printTimeType(clientData, interp, objc, objv, value));
343 }
344
345 which = atoi(s);
346 if((which >= 0) && (which < 26))
375 which = bijective_marker_id_string_hash(s);
376 }
377 else
378 {
379 which = atoi(s);
380 }
381
382 if((which >= 0) && (which < WAVE_NUM_NAMED_MARKERS))
347383 {
348384 TimeType value = GLOBALS->named_markers[which];
349385 return(gtkwavetcl_printTimeType(clientData, interp, objc, objv, value));
567603
568604 if((sv[0]>='A')&&(sv[0]<='Z'))
569605 {
570 which = sv[0] - 'A';
606 which = bijective_marker_id_string_hash(sv);
571607 }
572608 else
573609 if((sv[0]>='a')&&(sv[0]<='z'))
574610 {
575 which = sv[0] - 'a';
611 which = bijective_marker_id_string_hash(sv);
576612 }
577613 else
578614 {
579615 which = atoi(sv);
580616 }
581617
582 if((which >= 0) && (which < 26))
618 if((which >= 0) && (which < WAVE_NUM_NAMED_MARKERS))
583619 {
584620 char *s = get_Tcl_string(objv[2]);
585621 Trptr t = GLOBALS->traces.first;
913949
914950 if((s[0]>='A')&&(s[0]<='Z'))
915951 {
916 which = s[0] - 'A';
952 which = bijective_marker_id_string_hash(s);
917953 }
918954 else
919955 if((s[0]>='a')&&(s[0]<='z'))
920956 {
921 which = s[0] - 'a';
957 which = bijective_marker_id_string_hash(s);
922958 }
923959 else
924960 {
925961 which = atoi(s);
926962 }
927963
928 if((which >= 0) && (which < 26))
964 if((which >= 0) && (which < WAVE_NUM_NAMED_MARKERS))
929965 {
930966 char *t = get_Tcl_string(objv[2]);
931967 TimeType gt=unformat_time(t, GLOBALS->time_dimension);
14511487
14521488 static int gtkwavetcl_signalChangeList(ClientData clientData, Tcl_Interp *interp,
14531489 int objc, Tcl_Obj *CONST objv[]) {
1490 (void) clientData;
1491
14541492 int dir = STRACE_FORWARD ;
14551493 TimeType start_time = 0 ;
14561494 TimeType end_time = MAX_HISTENT_TIME ;
18621862 GtkTreeIter *iter,
18631863 gpointer data)
18641864 {
1865 (void)path;
1866
18651867 struct tree *sel;
18661868 int i;
18671869 int low, high;
25532555
25542556 static void declare_tclcb_variables(Tcl_Interp *interp)
25552557 {
2558 (void)interp;
2559
25562560 int i = 0 ;
25572561 while(tclcb_var_flags[i] != -1)
25582562 {
27492753
27502754 void gtkUpdate(ClientData ignore)
27512755 {
2756 (void)ignore;
2757
27522758 while (gtk_events_pending()) { gtk_main_iteration(); }
27532759 Tcl_CreateTimerHandler(50,gtkUpdate, (ClientData) NULL); /* ajb: was 0 period ...caused 100% CPU spike */
27542760 }
28232829
28242830 static gboolean repscript_timer(gpointer dummy)
28252831 {
2832 (void)dummy;
2833
28262834 static gboolean run_once = FALSE;
28272835
28282836 if(run_once == FALSE) /* avoid any race conditions with the toolkit for uninitialized data */
28872895 exit(255);
28882896 }
28892897 #else
2898 (void)me;
2899 (void)install_tk;
28902900 GLOBALS->interp = Tcl_CreateInterp();
28912901 #endif
28922902 }
28982908 char commandName[32768];
28992909 gtkwave_mlist_t *ife;
29002910 int num_menu_items;
2911 #if !((defined(__MACH__) && defined(__APPLE__)))
29012912 int n = 0;
2913 #endif
29022914
29032915 #ifndef WAVE_TCL_STUBIFY
29042916 Tcl_FindExecutable(argv[0]);
30343046
30353047 void make_tcl_interpreter(char *argv[])
30363048 {
3049 (void)argv;
3050
30373051 /* nothing */
30383052 }
30393053
30403054
30413055 const char *gtkwavetcl_setvar(const char *name1, const char *val, int flags)
30423056 {
3057 (void)name1;
3058 (void)val;
3059 (void) flags;
3060
30433061 return(NULL);
30443062 }
30453063
30463064
30473065 const char *gtkwavetcl_setvar_nonblocking(const char *name1, const char *val, int flags)
30483066 {
3067 (void) name1;
3068 (void) val;
3069 (void) flags;
3070
30493071 return(NULL);
30503072 }
30513073
30523074
30533075 char *rpc_script_execute(const char *nam)
30543076 {
3077 (void) nam;
3078
30553079 return(strdup_2("--script TCL_ERROR : Tcl support not compiled into gtkwave\n"));
30563080 }
30573081
504504 */
505505
506506 Tcl_Interp *NpCreateMainInterp(char *me, int install_tk) {
507 (void)me;
508
507509 ThreadSpecificData *tsdPtr;
508510 Tcl_Interp *interp;
509511
297297 Trptr is_signal_displayed(char *name) {
298298 Trptr t=GLOBALS->traces.first ;
299299 char *p = strchr(name, '['), *p1 ;
300 int len, len1 ;
300 unsigned int len, len1 ;
301301 if(p)
302302 *p = '\0' ;
303303 len = strlen(name) ;
322322
323323 if(p) {
324324 p1 = strchr(p,'[') ;
325 len1 = (p1) ? p1 - p : strlen(p) ;
325 len1 = (p1) ? (unsigned int)(p1 - p) : strlen(p) ;
326326 cc = ((len == len1) && !strncmp(name, p, len));
327327 if(was_packed) free_2(p);
328328 if(cc)
4646
4747 void from_entry_callback(GtkWidget *widget, GtkWidget *entry)
4848 {
49 (void)widget;
50
4951 G_CONST_RETURN gchar *entry_text;
5052 TimeType newlo;
5153 char fromstr[40];
8486
8587 void to_entry_callback(GtkWidget *widget, GtkWidget *entry)
8688 {
89 (void)widget;
90
8791 G_CONST_RETURN gchar *entry_text;
8892 TimeType newhi;
8993 char tostr[40];
302302
303303 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
304304 {
305 (void)widget;
306 (void)nothing;
307
305308 GLOBALS->is_active_translate_c_5=0;
306309 gtk_widget_destroy(GLOBALS->window_translate_c_11);
307310 GLOBALS->window_translate_c_11 = NULL;
316319 static void select_row_callback(GtkWidget *widget, gint row, gint column,
317320 GdkEventButton *event, gpointer data)
318321 {
322 (void)widget;
323 (void)row;
324 (void)column;
325 (void)event;
326 (void)data;
327
319328 GLOBALS->current_filter_translate_c_2 = row + 1;
320329 }
321330
322331 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
323332 GdkEventButton *event, gpointer data)
324333 {
334 (void)widget;
335 (void)row;
336 (void)column;
337 (void)event;
338 (void)data;
339
325340 GLOBALS->current_filter_translate_c_2 = 0; /* none */
326341 }
327342
328343
329344 static void add_filter_callback_2(GtkWidget *widget, GtkWidget *nothing)
330345 {
346 (void)widget;
347 (void)nothing;
348
331349 int i;
332350 GtkCList *cl;
333351
374392
375393 static void add_filter_callback(GtkWidget *widget, GtkWidget *nothing)
376394 {
395 (void)widget;
396 (void)nothing;
397
377398 if(GLOBALS->num_file_filters == FILE_FILTER_MAX)
378399 {
379400 status_text("Max number of file filters installed already.\n");
2222
2323 void mkmenu_treesearch_cleanup(GtkWidget *widget, gpointer data)
2424 {
25 (void)widget;
26 (void)data;
27
2528 /* nothing */
2629 }
2730
489489
490490 static void tree_expand_callback(GtkCTree *ctree, GtkCTreeNode *node, gpointer user_data)
491491 {
492 (void)ctree;
493 (void)user_data;
494
492495 create_sst_nodes_if_necessary(node);
493496 generic_tree_expand_collapse_callback(1, node);
494497 #ifdef WAVE_ALLOW_QUARTZ_FLUSH_WORKAROUND
502505
503506 static void tree_collapse_callback(GtkCTree *ctree, GtkCTreeNode *node, gpointer user_data)
504507 {
508 (void)ctree;
509 (void)user_data;
510
505511 generic_tree_expand_collapse_callback(0, node);
506512 #ifdef WAVE_ALLOW_QUARTZ_FLUSH_WORKAROUND
507513 #ifdef MAC_INTEGRATION
590596 static void select_row_callback(GtkWidget *widget, gint row, gint column,
591597 GdkEventButton *event, gpointer data)
592598 {
599 (void)widget;
600 (void)column;
601 (void)event;
602 (void)data;
603
593604 struct tree *t;
594605 GtkCTreeNode* node = gtk_ctree_node_nth(GLOBALS->ctree_main, row);
595606
643654 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
644655 GdkEventButton *event, gpointer data)
645656 {
657 (void)widget;
658 (void)column;
659 (void)event;
660 (void)data;
661
646662 struct tree *t;
647663
648664 if(GLOBALS->selected_hierarchy_name)
668684 static
669685 gboolean filter_edit_cb (GtkWidget *widget, GdkEventKey *ev, gpointer *data)
670686 {
687 (void)data;
688
671689 /* Maybe this test is too strong ? */
672690 if (ev->keyval == GDK_Return)
673691 {
758776
759777 static void enter_callback_e(GtkWidget *widget, GtkWidget *nothing)
760778 {
779 (void)widget;
780 (void)nothing;
781
761782 G_CONST_RETURN gchar *entry_text;
762783 int len;
763784 entry_text = gtk_entry_get_text(GTK_ENTRY(GLOBALS->entry_a_treesearch_gtk2_c_2));
775796
776797 static void destroy_callback_e(GtkWidget *widget, GtkWidget *nothing)
777798 {
799 (void)widget;
800 (void)nothing;
801
778802 DEBUG(printf("Entry Cancel\n"));
779803 GLOBALS->entrybox_text_local_treesearch_gtk2_c_3=NULL;
780804 wave_gtk_grab_remove(GLOBALS->window1_treesearch_gtk2_c_3);
906930 GtkTreeIter *iter,
907931 gpointer data)
908932 {
933 (void)path;
934 (void)data;
935
909936 struct tree *sel;
910937
911938 /* Extract the tree. */
952979 static void
953980 bundle_cleanup(GtkWidget *widget, gpointer data)
954981 {
982 (void)widget;
983 (void)data;
984
955985 gtk_tree_selection_selected_foreach
956986 (GLOBALS->sig_selection_treesearch_gtk2_c_1, &bundle_cleanup_foreach, NULL);
957987
9801010 static void
9811011 bundle_callback_up(GtkWidget *widget, gpointer data)
9821012 {
1013 (void)widget;
1014 (void)data;
1015
9831016 GLOBALS->bundle_direction_treesearch_gtk2_c_3=0;
9841017 bundle_callback_generic();
9851018 }
9871020 static void
9881021 bundle_callback_down(GtkWidget *widget, gpointer data)
9891022 {
1023 (void)widget;
1024 (void)data;
1025
9901026 GLOBALS->bundle_direction_treesearch_gtk2_c_3=1;
9911027 bundle_callback_generic();
9921028 }
10031039 GtkTreeIter *iter,
10041040 gpointer data)
10051041 {
1042 (void)path;
1043 (void)data;
1044
10061045 struct tree *sel;
10071046 /* const enum cb_action action = (enum cb_action)data; */
10081047 int i;
11341173 GtkTreeIter *iter,
11351174 gpointer data)
11361175 {
1176 (void)path;
1177 (void)data;
1178
11371179 struct tree *sel;
11381180 /* const enum cb_action action = (enum cb_action)data; */
11391181 int i;
12331275
12341276 static void insert_callback(GtkWidget *widget, GtkWidget *nothing)
12351277 {
1278 (void)nothing;
1279
12361280 set_window_busy(widget);
12371281 action_callback (ACTION_INSERT);
12381282 set_window_idle(widget);
12401284
12411285 static void replace_callback(GtkWidget *widget, GtkWidget *nothing)
12421286 {
1287 (void)nothing;
1288
12431289 set_window_busy(widget);
12441290 action_callback (ACTION_REPLACE);
12451291 set_window_idle(widget);
12471293
12481294 static void ok_callback(GtkWidget *widget, GtkWidget *nothing)
12491295 {
1296 (void)nothing;
1297
12501298 set_window_busy(widget);
12511299 action_callback (ACTION_APPEND);
12521300 set_window_idle(widget);
12551303
12561304 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
12571305 {
1306 (void)widget;
1307 (void)nothing;
1308
12581309 GLOBALS->is_active_treesearch_gtk2_c_6=0;
12591310 gtk_widget_destroy(GLOBALS->window_treesearch_gtk2_c_12);
12601311 GLOBALS->window_treesearch_gtk2_c_12 = NULL;
12801331 gboolean path_currently_selected,
12811332 gpointer userdata)
12821333 {
1334 (void)selection;
1335 (void)userdata;
1336
12831337 GtkTreeIter iter;
12841338
12851339 if (gtk_tree_model_get_iter(model, &iter, path))
13131367
13141368 static gint button_press_event_std(GtkWidget *widget, GdkEventButton *event)
13151369 {
1370 (void)widget;
1371
13161372 if(event->type == GDK_2BUTTON_PRESS)
13171373 {
13181374 if(GLOBALS->selected_hierarchy_name && GLOBALS->selected_sig_name)
16641720 */
16651721 GtkWidget* treeboxframe(char *title, GtkSignalFunc func)
16661722 {
1723 (void)title;
1724
16671725 GtkWidget *scrolled_win, *sig_scroll_win;
16681726 GtkWidget *hbox;
16691727 GtkWidget *button1, *button2, *button3, *button3a, *button4;
19381996 GtkWidget *widget, GdkDragContext *dc, gpointer data
19391997 )
19401998 {
1999 (void)data;
2000
19412001 if((widget == NULL) || (dc == NULL))
19422002 return;
19432003
19642024 GtkWidget *widget, GdkDragContext *dc, gpointer data
19652025 )
19662026 {
2027 (void)widget;
2028 (void)dc;
2029 (void)data;
2030
19672031 Trptr t;
19682032 int trwhich, trtarget;
19692033 GdkModifierType state;
21262190 gpointer data
21272191 )
21282192 {
2193 (void)x;
2194 (void)y;
2195 (void)data;
2196
21292197 gboolean same_widget;
21302198 GdkDragAction suggested_action;
21312199 GtkWidget *src_widget, *tar_widget;
21922260 gpointer data
21932261 )
21942262 {
2263 (void)dc;
2264 (void)info;
2265 (void)t;
2266 (void)data;
2267
21952268 int upd = 0;
21962269 GLOBALS->tree_dnd_requested = 1; /* indicate that a request for data occurred... */
21972270
22622335 GtkWidget *widget, GdkDragContext *dc,
22632336 gint x, gint y, GtkSelectionData *selection_data,
22642337 guint info, guint t, gpointer data) {
2338 (void)x;
2339 (void)y;
2340 (void)t;
2341
22652342 gboolean same;
22662343 GtkWidget *source_widget;
22672344
23712448 GtkWidget *widget, GdkDragContext *dc, gpointer data
23722449 )
23732450 {
2451 (void)widget;
2452 (void)dc;
2453 (void)data;
2454
23742455 /* nothing */
23752456 }
23762457
00 /*
1 * Copyright (c) Tony Bybell 2010-2012.
1 * Copyright (c) Tony Bybell 2010-2014.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
2121
2222 static void args_entry_callback(GtkWidget *widget, GtkWidget *entry)
2323 {
24 (void)widget;
25
2426 G_CONST_RETURN gchar *entry_text;
2527
2628 entry_text=gtk_entry_get_text(GTK_ENTRY(entry));
5355 void remove_all_ttrans_filters(void)
5456 {
5557 struct Global *GLOBALS_cache = GLOBALS;
56 int i, j;
58 unsigned int i, j;
5759
5860 for(j=0;j<GLOBALS->num_notebook_pages;j++)
5961 {
302304
303305 static void destroy_callback(GtkWidget *widget, GtkWidget *nothing)
304306 {
307 (void)widget;
308 (void)nothing;
309
305310 GLOBALS->is_active_ttranslate_c_2=0;
306311 gtk_widget_destroy(GLOBALS->window_ttranslate_c_5);
307312 GLOBALS->window_ttranslate_c_5 = NULL;
316321 static void select_row_callback(GtkWidget *widget, gint row, gint column,
317322 GdkEventButton *event, gpointer data)
318323 {
324 (void)widget;
325 (void)column;
326 (void)event;
327 (void)data;
328
319329 GLOBALS->current_filter_ttranslate_c_1 = row + 1;
320330 }
321331
322332 static void unselect_row_callback(GtkWidget *widget, gint row, gint column,
323333 GdkEventButton *event, gpointer data)
324334 {
335 (void)widget;
336 (void)row;
337 (void)column;
338 (void)event;
339 (void)data;
340
325341 GLOBALS->current_filter_ttranslate_c_1 = 0; /* none */
326342 }
327343
328344
329345 static void add_filter_callback_2(GtkWidget *widget, GtkWidget *nothing)
330346 {
347 (void)widget;
348 (void)nothing;
349
331350 int i;
332351 GtkCList *cl;
333352
374393
375394 static void add_filter_callback(GtkWidget *widget, GtkWidget *nothing)
376395 {
396 (void)widget;
397 (void)nothing;
398
377399 if(GLOBALS->num_ttrans_filters == TTRANS_FILTER_MAX)
378400 {
379401 status_text("Max number of transaction filters processes installed already.\n");
721743 else
722744 if((*pnt=='M')||(*pnt=='m'))
723745 {
746 int mlen;
724747 pnt++;
725 if(((*pnt>='A')&&(*pnt<='Z')) || ((*pnt>='a')&&(*pnt<='z')))
726 {
727 int which_marker = ((*pnt>='A')&&(*pnt<='Z')) ? (*pnt - 'A') : (*pnt - 'a');
728 TimeType tim = atoi_64(pnt+1) * GLOBALS->time_scale;
729 int slen;
730 char *sp;
731
732 if(tim < LLDescriptor(0)) tim = LLDescriptor(-1);
733 GLOBALS->named_markers[which_marker] = tim;
734
735 while(*pnt) { if(!isspace((int)(unsigned char)*pnt)) pnt++; else break; }
736 while(*pnt) { if(isspace((int)(unsigned char)*pnt)) pnt++; else break; }
737
738 sp = pnt;
739 slen = strlen(sp);
740
741 if(slen)
748
749 mlen = bijective_marker_id_string_len(pnt);
750 if(mlen)
751 {
752 int which_marker = bijective_marker_id_string_hash(pnt);
753 if((which_marker >= 0) && (which_marker < WAVE_NUM_NAMED_MARKERS))
742754 {
743 pnt = sp + slen - 1;
744 do
755 TimeType tim = atoi_64(pnt+mlen) * GLOBALS->time_scale;
756 int slen;
757 char *sp;
758
759 if(tim < LLDescriptor(0)) tim = LLDescriptor(-1);
760 GLOBALS->named_markers[which_marker] = tim;
761
762 while(*pnt) { if(!isspace((int)(unsigned char)*pnt)) pnt++; else break; }
763 while(*pnt) { if(isspace((int)(unsigned char)*pnt)) pnt++; else break; }
764
765 sp = pnt;
766 slen = strlen(sp);
767
768 if(slen)
745769 {
746 if(isspace((int)(unsigned char)*pnt)) { *pnt = 0; pnt--; slen--; } else { break; }
747 } while(pnt != (sp-1));
770 pnt = sp + slen - 1;
771 do
772 {
773 if(isspace((int)(unsigned char)*pnt)) { *pnt = 0; pnt--; slen--; } else { break; }
774 } while(pnt != (sp-1));
775 }
776
777 if(GLOBALS->marker_names[which_marker]) free_2(GLOBALS->marker_names[which_marker]);
778 GLOBALS->marker_names[which_marker] = (sp && (*sp) && (tim >= LLDescriptor(0))) ? strdup_2(sp) : NULL;
748779 }
749
750 if(GLOBALS->marker_names[which_marker]) free_2(GLOBALS->marker_names[which_marker]);
751 GLOBALS->marker_names[which_marker] = (sp && (*sp) && (tim >= LLDescriptor(0))) ? strdup_2(sp) : NULL;
752780 }
753781
754782 continue;
2828
2929 static int plug_removed(GtkWidget *widget, gpointer data)
3030 {
31 (void)widget;
32 (void)data;
33
3134 static int cnt = 2;
3235
3336 fprintf(stderr, "GtkPlug removed\n");
4447
4548 int quit_callback (GtkWidget *widget, gpointer data)
4649 {
50 (void)widget;
51
4752 fprintf(stderr,"%s\n", (char *)data);
4853 gtk_exit(0);
4954
29632963 {
29642964 struct vlist_t *v = np->mv.mvlfac_vlist;
29652965 int len = 1;
2966 int list_size;
2966 unsigned int list_size;
29672967 unsigned char vlist_type;
29682968 /* unsigned int vartype = 0; */ /* scan-build */
29692969 unsigned int vlist_pos = 0;
29822982
29832983 if(GLOBALS->vlist_prepack)
29842984 {
2985 depacked = vlist_packer_decompress(v, (unsigned int *)&list_size);
2985 depacked = vlist_packer_decompress(v, &list_size);
29862986 vlist_destroy(v);
29872987 }
29882988 else
1616
1717 static void w32redirect_fprintf(FILE *sfd, const char *format, ...)
1818 {
19 #if !defined _MSC_VER && !defined __MINGW32__
20
2119 va_list ap;
2220 va_start(ap, format);
2321 vfprintf(sfd, format, ap);
2422 va_end(ap);
25
26 #else
27
28 char buf[16385];
29 BOOL bSuccess;
30 DWORD dwWritten;
31
32 va_list ap;
33 va_start(ap, format);
34 buf[0] = 0;
35 vsprintf(buf, format, ap);
36 bSuccess = WriteFile((HANDLE)sfd, buf, strlen(buf), &dwWritten, NULL);
37 va_end(ap);
38
39 #endif
4023 }
4124
4225 /*
292275 static void heapify(int i, int heap_size)
293276 {
294277 int l, r;
295 unsigned int largest;
278 int largest;
296279 vcdsav_Tree *t;
297280 int maxele=heap_size/2-1; /* points to where heapswaps don't matter anymore */
298281
243243
244244 if(numalias)
245245 {
246 unsigned int idx_lft = 0;
247 unsigned int idx_lftmax = GLOBALS->numfacs - numalias;
248 unsigned int idx_rgh = GLOBALS->numfacs - numalias;
246 int idx_lft = 0;
247 int idx_lftmax = GLOBALS->numfacs - numalias;
248 int idx_rgh = GLOBALS->numfacs - numalias;
249249 struct symbol **facs_merge=(struct symbol **)malloc_2(GLOBALS->numfacs*sizeof(struct symbol *));
250250
251251 fprintf(stderr, VZT_RDLOAD"Merging in %d aliases.\n", numalias);
446446 */
447447 static void vzt_callback(struct vzt_rd_trace **lt, lxtint64_t *tim, lxtint32_t *facidx, char **value)
448448 {
449 (void)lt;
450
449451 struct HistEnt *htemp = histent_calloc();
450452 struct lx2_entry *l2e = GLOBALS->vzt_table_vzt_c_1+(*facidx);
451453 struct fac *f = GLOBALS->mvlfacs_vzt_c_3+(*facidx);
9393
9494 static gint slider_bpr(GtkWidget *widget, GdkEventButton *event)
9595 {
96 (void)widget;
97
9698 int xi = event->x;
9799 int xl = GLOBALS->str_wid_x;
98100 int xr = GLOBALS->str_wid_x + GLOBALS->str_wid_width;
114116
115117 static gint slider_brr(GtkWidget *widget, GdkEventButton *event)
116118 {
119 (void)widget;
120 (void)event;
121
117122 GLOBALS->str_wid_state = 0;
118123 return(FALSE);
119124 }
121126
122127 static gint slider_mnr(GtkWidget *widget, GdkEventMotion *event)
123128 {
129 (void)widget;
130
124131 #ifndef WAVE_USE_GTK2
125132 gdouble x, y;
126133 #endif
331338 if(!GLOBALS->cursor_snap) return(marker);
332339
333340 /* potential snapping to a named marker time */
334 for(i=0;i<26;i++)
341 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
335342 {
336343 if(GLOBALS->named_markers[i] != -1)
337344 {
553560 xl=((gdouble)(t-GLOBALS->tims.start))/pixstep; /* snap to integer */
554561 if((xl>=0)&&(xl<GLOBALS->wavewidth))
555562 {
556 char nbuff[2];
557 nbuff[0]='A'+i; nbuff[1]=0x00;
563 char nbuff[16];
564 make_bijective_marker_id_string(nbuff, i);
558565
559566 for(y=GLOBALS->fontheight-1;y<=GLOBALS->waveheight-1;y+=8)
560567 {
596603
597604 if(!GLOBALS->wavepixmap_wavewindow_c_1) return;
598605
599 for(i=0;i<26;i++)
606 for(i=0;i<WAVE_NUM_NAMED_MARKERS;i++)
600607 {
601608 if(i != GLOBALS->named_marker_lock_idx)
602609 {
798805 static void
799806 service_hslider(GtkWidget *text, gpointer data)
800807 {
808 (void)text;
809 (void)data;
810
801811 DEBUG(printf("Wave HSlider Moved\n"));
802812
803813 if((GLOBALS->wavepixmap_wavewindow_c_1)&&(GLOBALS->wavewidth>1))
829839 static void
830840 service_vslider(GtkWidget *text, gpointer data)
831841 {
842 (void)text;
843 (void)data;
844
832845 GtkAdjustment *sadj, *hadj;
833846 int trtarget;
834847 int xsrc;
959972
960973 static gint motion_notify_event(GtkWidget *widget, GdkEventMotion *event)
961974 {
975 (void)widget;
976
962977 gdouble x, y, pixstep, offset;
963978 GdkModifierType state;
964979 TimeType newcurr;
11701185 void
11711186 alt_move_left(GtkWidget *text, gpointer data)
11721187 {
1188 (void)text;
1189 (void)data;
1190
11731191 TimeType ntinc, ntfrac;
11741192
11751193 ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx); /* really don't need this var but the speed of ui code is human dependent.. */
11891207 void
11901208 alt_move_right(GtkWidget *text, gpointer data)
11911209 {
1210 (void)text;
1211 (void)data;
1212
11921213 TimeType ntinc, ntfrac;
11931214
11941215 ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);
12141235
12151236 void alt_zoom_out(GtkWidget *text, gpointer data)
12161237 {
1238 (void)text;
1239 (void)data;
1240
12171241 TimeType middle=0, width;
12181242 TimeType marker = GLOBALS->cached_currenttimeval_currenttime_c_1;
12191243 /* Zoom on mouse cursor, not marker */
12671291
12681292 void alt_zoom_in(GtkWidget *text, gpointer data)
12691293 {
1294 (void)text;
1295 (void)data;
1296
12701297 if(GLOBALS->tims.zoom<0) /* otherwise it's ridiculous and can cause */
12711298 { /* overflow problems in the scope */
12721299 TimeType middle=0, width;
13271354 static gint
13281355 scroll_event( GtkWidget * widget, GdkEventScroll * event )
13291356 {
1357 (void)widget;
1358
13301359 int num_traces_displayable=(GLOBALS->signalarea->allocation.height)/(GLOBALS->fontheight);
13311360 num_traces_displayable--;
13321361
14801509
14811510 static gint button_release_event(GtkWidget *widget, GdkEventButton *event)
14821511 {
1512 (void)widget;
1513
14831514 if((event->button)&&(event->button==GLOBALS->in_button_press_wavewindow_c_1))
14841515 {
14851516 GLOBALS->in_button_press_wavewindow_c_1=0;
16011632
16021633 gint wavearea_configure_event(GtkWidget *widget, GdkEventConfigure *event)
16031634 {
1635 (void)event;
1636
16041637 if((!widget)||(!widget->window)) return(TRUE);
16051638
16061639 DEBUG(printf("WaveWin Configure Event h: %d, w: %d\n",widget->allocation.height,
4141
4242 void service_zoom_left(GtkWidget *text, gpointer data)
4343 {
44 (void)text;
45 (void)data;
46
4447 GtkAdjustment *hadj;
4548
4649 if(GLOBALS->helpbox_is_active)
5962
6063 void service_zoom_right(GtkWidget *text, gpointer data)
6164 {
65 (void)text;
66 (void)data;
67
6268 GtkAdjustment *hadj;
6369 TimeType ntinc;
6470
8389
8490 void service_zoom_out(GtkWidget *text, gpointer data)
8591 {
92 (void)text;
93 (void)data;
94
8695 TimeType middle=0, width;
8796
8897 if(GLOBALS->helpbox_is_active)
139148
140149 void service_zoom_in(GtkWidget *text, gpointer data)
141150 {
151 (void)text;
152 (void)data;
153
142154 if(GLOBALS->helpbox_is_active)
143155 {
144156 help_text_bold("\n\nZoom In");
198210
199211 void service_zoom_undo(GtkWidget *text, gpointer data)
200212 {
213 (void)text;
214 (void)data;
215
201216 gdouble temp;
202217
203218 if(GLOBALS->helpbox_is_active)
226241
227242 void service_zoom_fit(GtkWidget *text, gpointer data)
228243 {
244 (void)text;
245 (void)data;
246
229247 gdouble estimated;
230248 int fixedwidth;
231249
270288
271289 void service_zoom_full(GtkWidget *text, gpointer data)
272290 {
291 (void)text;
292 (void)data;
293
273294 gdouble estimated;
274295 int fixedwidth;
275296