reorginization of visiLib
[dyninst.git] / visiClients / barchart / barChartDriver.C
1 // barChartDriver.C
2
3 /* $Log: barChartDriver.C,v $
4 /* Revision 1.13  1996/01/11 01:52:53  tamches
5 /* added command long2shortFocusName
6 /*
7  * Revision 1.12  1996/01/10 02:25:34  tamches
8  * added --xsynch and --debug command-line options
9  * installed getMetricColorNameCommand
10  *
11  * Revision 1.11  1995/12/20 18:37:59  newhall
12  * matherr.h does not need to be included by visis
13  *
14  * Revision 1.10  1995/11/29 00:39:48  tamches
15  * now include tkTools.h, pdLogo.h
16  * Now hardcode the pdLogo
17  *
18  * Revision 1.9  1995/11/08 21:17:12  naim
19  * Adding matherr exception handler function to avoid error message when
20  * computing the "not a number" (NaN) value - naim
21  *
22  * Revision 1.8  1995/11/08  02:17:06  tamches
23  * minor cleanups
24  *
25  * Revision 1.7  1995/09/22 19:25:04  tamches
26  * removed warnings under g++ 2.7.0
27  *
28  * Revision 1.6  1995/08/06  22:11:13  tamches
29  * barChart now uses tcl2c.
30  * Now needs no command-line args.
31  *
32  * Revision 1.5  1995/07/06  18:55:31  tamches
33  * Now contains a main program suitable for tk4.0
34  *
35  * Revision 1.4  1994/10/13  00:52:36  tamches
36  * Minor additions to support a new command related to sorting
37  * of resources
38  *
39  * Revision 1.3  1994/10/10  23:08:43  tamches
40  * preliminary changes on the way to swapping the x and y axes
41  *
42  * Revision 1.2  1994/09/29  20:05:36  tamches
43  * minor cvs fixes
44  *
45  * Revision 1.1  1994/09/29  19:50:51  tamches
46  * initial implementation.
47  * entrypoint for barchart C++ program.  we create new tcl
48  * commands (which will eventually call back to barChartTcl.C
49  * and from there barChart.C) and then launch barChart.tcl.
50  *
51 */
52
53 #include <assert.h>
54 #include <stdlib.h>
55 #include <iostream.h>
56
57 #include "tcl.h"
58 #include "tk.h"
59 #include "tkTools.h"
60
61 #include "pdLogo.h"
62 #include "paradyn/xbm/logo.xbm"
63
64 #include "dg2.h"
65 #include "barChartTcl.h"
66
67 void panic(const char *msg) {
68    cerr << msg << endl;
69    exit(5);
70 }
71
72 Tcl_Interp *MainInterp = NULL; // needed by Dg
73 bool xsynchFlag = false;
74
75 int main(int argc, char **argv) {
76    // Loop through the arguments:
77    for (argc--, argv++; argc > 0; argc--, argv++) {
78       if (0==strcmp(*argv, "--xsynch"))
79          xsynchFlag = true;
80       else if (0==strcmp(*argv, "--debug")) {
81          xsynchFlag = true;
82          cout << "barChart pid " << getpid() << " at sigpause..." << endl;
83          sigpause(0);
84       }
85       else {
86          cerr << "barChart: unrecognized argument \"" << *argv << "\"" << endl;
87          return 5;
88       }
89    }
90
91    // barChart no longer requires any arguments, thanks to tcl2c.
92    if (argc == 2)
93       panic("barChart: argc should be 1");
94
95    MainInterp = Tcl_CreateInterp();
96    assert(MainInterp);
97
98    Tk_Window mainTkWindow = Tk_CreateMainWindow(MainInterp, NULL,
99                                                 "barChart",
100                                                 "BarChart");
101    if (mainTkWindow == NULL)
102       tclpanic(MainInterp, "Could not Tk_CreateMainWindow()");
103
104    if (TCL_OK != Tcl_Init(MainInterp))
105       tclpanic(MainInterp, "Could not Tcl_Init()");
106
107    if (TCL_OK != Tk_Init(MainInterp))
108       tclpanic(MainInterp, "Could not Tk_Init");
109
110    if (TCL_OK != Dg2_Init(MainInterp))
111       tclpanic(MainInterp, "Could not Dg2_Init()");
112
113    Tcl_SetVar(MainInterp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
114
115    // Install our new tcl commands
116    Tcl_CreateCommand(MainInterp, "resizeCallback", resizeCallbackCommand,
117                      NULL, // ClientData
118                      deleteDummyProc);
119
120    Tcl_CreateCommand(MainInterp, "exposeCallback", exposeCallbackCommand,
121                      NULL, // ClientData
122                      deleteDummyProc);
123
124    Tcl_CreateCommand(MainInterp, "resourcesAxisHasChanged",
125                      resourcesAxisHasChangedCommand,
126                      NULL, // ClientData
127                      deleteDummyProc);
128
129    Tcl_CreateCommand(MainInterp, "metricsAxisHasChanged", metricsAxisHasChangedCommand,
130                      NULL, // ClientData
131                      deleteDummyProc);
132
133    Tcl_CreateCommand(MainInterp, "newScrollPosition", newScrollPositionCommand,
134                      NULL, // ClientData
135                      deleteDummyProc);
136
137    Tcl_CreateCommand(MainInterp, "dataFormatHasChanged", dataFormatHasChangedCommand,
138                      NULL, // ClientData
139                      deleteDummyProc);
140
141    Tcl_CreateCommand(MainInterp, "rethinkIndirectResourcesCallback",
142                      rethinkIndirectResourcesCommand,
143                      NULL, // ClientData
144                      deleteDummyProc);
145
146    Tcl_CreateCommand(MainInterp, "getMetricColorName",
147                      getMetricColorNameCommand,
148                      NULL, // ClientData
149                      deleteDummyProc);
150
151    Tcl_CreateCommand(MainInterp, "long2shortFocusName", long2shortFocusNameCommand,
152                      NULL, // ClientData
153                      deleteLaunchBarChartCommand);
154
155    Tcl_CreateCommand(MainInterp, "launchBarChart", launchBarChartCommand,
156                      NULL, // ClientData
157                      deleteLaunchBarChartCommand);
158
159    // Krishna's tcl2c stuff gets loaded here:
160    // (initialize_tcl_sources() was auto-generated by 'tcl2c')
161    extern int initialize_tcl_sources(Tcl_Interp *);
162    if (TCL_OK != initialize_tcl_sources(MainInterp))
163       tclpanic(MainInterp, "barChart: could not initialize_tcl_sources");
164
165 //if (TCL_OK != Tcl_EvalFile(MainInterp, "/p/paradyn/development/tamches/core/visiClients/barchart/barChart.tcl"))
166 //   tclpanic(MainInterp, "could not source barChart.tcl manually");
167
168    pdLogo::install_fixed_logo("paradynLogo", logo_bits, logo_width, logo_height);
169    tcl_cmd_installer createPdLogo(MainInterp, "makeLogo",
170                                   pdLogo::makeLogoCommand,
171                                   (ClientData)mainTkWindow);
172
173    myTclEval(MainInterp, "init_barchart_window");
174    myTclEval(MainInterp, "Initialize");
175
176    Tk_MainLoop(); // returns when all tk windows are closed
177
178    // shouldn't we be doing some cleanup here?
179 }