Adding matherr exception handler function to avoid error message when
[dyninst.git] / visiClients / barchart / barChartDriver.C
1 // barChartDriver.C
2
3 /* $Log: barChartDriver.C,v $
4 /* Revision 1.9  1995/11/08 21:17:12  naim
5 /* Adding matherr exception handler function to avoid error message when
6 /* computing the "not a number" (NaN) value - naim
7 /*
8  * Revision 1.8  1995/11/08  02:17:06  tamches
9  * minor cleanups
10  *
11  * Revision 1.7  1995/09/22 19:25:04  tamches
12  * removed warnings under g++ 2.7.0
13  *
14  * Revision 1.6  1995/08/06  22:11:13  tamches
15  * barChart now uses tcl2c.
16  * Now needs no command-line args.
17  *
18  * Revision 1.5  1995/07/06  18:55:31  tamches
19  * Now contains a main program suitable for tk4.0
20  *
21  * Revision 1.4  1994/10/13  00:52:36  tamches
22  * Minor additions to support a new command related to sorting
23  * of resources
24  *
25  * Revision 1.3  1994/10/10  23:08:43  tamches
26  * preliminary changes on the way to swapping the x and y axes
27  *
28  * Revision 1.2  1994/09/29  20:05:36  tamches
29  * minor cvs fixes
30  *
31  * Revision 1.1  1994/09/29  19:50:51  tamches
32  * initial implementation.
33  * entrypoint for barchart C++ program.  we create new tcl
34  * commands (which will eventually call back to barChartTcl.C
35  * and from there barChart.C) and then launch barChart.tcl.
36  *
37 */
38
39 #include <assert.h>
40 #include <stdlib.h>
41 #include <iostream.h>
42
43 #include <tclclean.h>
44 #include <tkclean.h>
45 #include "dg2.h"
46 #include "barChartTcl.h"
47 #include "util/h/matherr.h"
48
49 void panic(const char *msg) {
50    cerr << msg << endl;
51    exit(5);
52 }
53
54 Tcl_Interp *MainInterp = NULL; // needed by Dg
55
56 int main(int argc, char **) {
57    // barChart no longer requires any arguments, thanks to tcl2c.
58    if (argc == 2)
59       panic("barChart: argc should be 1");
60
61    if (argc > 3)
62       panic("barChart: argc should be at most 3");
63
64    if (argc == 3)
65       cout << "barChart notice: due to tcl2c, argc should be just 1 (was 3)...ignoring parameters" << endl;
66
67    MainInterp = Tcl_CreateInterp();
68    assert(MainInterp);
69
70    Tk_Window mainTkWindow = Tk_CreateMainWindow(MainInterp, NULL,
71                                                 "barChart",
72                                                 "BarChart");
73    if (mainTkWindow == NULL) {
74       cerr << "Could not Tk_CreateMainWindow()!" << endl;
75       cerr << MainInterp->result << endl;
76       exit(5);
77    }
78
79    if (TCL_OK != Tcl_Init(MainInterp)) {
80       cerr << "Could not Tcl_Init: " << MainInterp->result << endl;
81       exit(5);
82    }
83
84    if (TCL_OK != Tk_Init(MainInterp)) {
85       cerr << "Could not Tk_Init: " << MainInterp->result << endl;
86       exit(5);
87    }
88
89    if (TCL_OK != Dg2_Init(MainInterp)) {
90       cerr << "Could not Dg2_Init: " << MainInterp->result << endl;
91       exit(5);
92    }
93
94    Tcl_SetVar(MainInterp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
95
96    // Install our new tcl commands
97    Tcl_CreateCommand(MainInterp, "resizeCallback", resizeCallbackCommand,
98                      NULL, // ClientData
99                      deleteDummyProc);
100
101    Tcl_CreateCommand(MainInterp, "exposeCallback", exposeCallbackCommand,
102                      NULL, // ClientData
103                      deleteDummyProc);
104
105    Tcl_CreateCommand(MainInterp, "resourcesAxisHasChanged",
106                      resourcesAxisHasChangedCommand,
107                      NULL, // ClientData
108                      deleteDummyProc);
109
110    Tcl_CreateCommand(MainInterp, "metricsAxisHasChanged", metricsAxisHasChangedCommand,
111                      NULL, // ClientData
112                      deleteDummyProc);
113
114    Tcl_CreateCommand(MainInterp, "newScrollPosition", newScrollPositionCommand,
115                      NULL, // ClientData
116                      deleteDummyProc);
117
118    Tcl_CreateCommand(MainInterp, "dataFormatHasChanged", dataFormatHasChangedCommand,
119                      NULL, // ClientData
120                      deleteDummyProc);
121
122    Tcl_CreateCommand(MainInterp, "rethinkIndirectResourcesCallback",
123                      rethinkIndirectResourcesCommand,
124                      NULL, // ClientData
125                      deleteDummyProc);
126
127    Tcl_CreateCommand(MainInterp, "launchBarChart", launchBarChartCommand,
128                      NULL, // ClientData
129                      deleteLaunchBarChartCommand);
130
131    // Krishna's tcl2c stuff gets loaded here:
132    // (initialize_tcl_sources() was auto-generated by 'tcl2c')
133    extern int initialize_tcl_sources(Tcl_Interp *);
134    if (TCL_OK != initialize_tcl_sources(MainInterp)) {
135       cerr << "barChart: could not initialize_tcl_sources: " << MainInterp->result << endl;
136       exit(5);
137    }
138
139 //if (TCL_OK != Tcl_EvalFile(MainInterp, "/p/paradyn/development/tamches/core/visiClients/barchart/barChart.tcl")) {
140 //      cerr << "barChart: could not initialize_tcl_sources: " << MainInterp->result << endl;
141 //      exit(5);
142 //   }
143   
144
145    Tk_MainLoop(); // returns when all tk windows are closed
146
147    // shouldn't we be doing some cleanup here?
148 }