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