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