update for tcl7.5
[dyninst.git] / visiClients / barchart / src / barChartDriver.C
1 // barChartDriver.C
2
3 /* $Log: barChartDriver.C,v $
4 /* Revision 1.15  1996/08/05 07:09:14  tamches
5 /* update for tcl7.5
6 /*
7  * Revision 1.14  1996/05/15 18:03:15  tamches
8  * added newMetricMaxValCallbackCommand
9  *
10  * Revision 1.13  1996/01/11 01:52:53  tamches
11  * added command long2shortFocusName
12  *
13  * Revision 1.12  1996/01/10 02:25:34  tamches
14  * added --xsynch and --debug command-line options
15  * installed getMetricColorNameCommand
16  *
17  * Revision 1.11  1995/12/20 18:37:59  newhall
18  * matherr.h does not need to be included by visis
19  *
20  * Revision 1.10  1995/11/29 00:39:48  tamches
21  * now include tkTools.h, pdLogo.h
22  * Now hardcode the pdLogo
23  *
24  * Revision 1.9  1995/11/08 21:17:12  naim
25  * Adding matherr exception handler function to avoid error message when
26  * computing the "not a number" (NaN) value - naim
27  *
28  * Revision 1.8  1995/11/08  02:17:06  tamches
29  * minor cleanups
30  *
31  * Revision 1.7  1995/09/22 19:25:04  tamches
32  * removed warnings under g++ 2.7.0
33  *
34  * Revision 1.6  1995/08/06  22:11:13  tamches
35  * barChart now uses tcl2c.
36  * Now needs no command-line args.
37  *
38  * Revision 1.5  1995/07/06  18:55:31  tamches
39  * Now contains a main program suitable for tk4.0
40  *
41  * Revision 1.4  1994/10/13  00:52:36  tamches
42  * Minor additions to support a new command related to sorting
43  * of resources
44  *
45  * Revision 1.3  1994/10/10  23:08:43  tamches
46  * preliminary changes on the way to swapping the x and y axes
47  *
48  * Revision 1.2  1994/09/29  20:05:36  tamches
49  * minor cvs fixes
50  *
51  * Revision 1.1  1994/09/29  19:50:51  tamches
52  * initial implementation.
53  * entrypoint for barchart C++ program.  we create new tcl
54  * commands (which will eventually call back to barChartTcl.C
55  * and from there barChart.C) and then launch barChart.tcl.
56  *
57 */
58
59 #include <assert.h>
60 #include <stdlib.h>
61 #include <iostream.h>
62
63 #include "tcl.h"
64 #include "tk.h"
65 #include "tkTools.h"
66
67 #include "pdLogo.h"
68 #include "paradyn/xbm/logo.xbm"
69
70 #include "dg2.h"
71 #include "barChartTcl.h"
72
73 void panic(const char *msg) {
74    cerr << msg << endl;
75    exit(5);
76 }
77
78 Tcl_Interp *MainInterp = NULL; // needed by Dg
79 bool xsynchFlag = false;
80
81 int main(int argc, char **argv) {
82    // Loop through the arguments:
83    for (argc--, argv++; argc > 0; argc--, argv++) {
84       if (0==strcmp(*argv, "--xsynch"))
85          xsynchFlag = true;
86       else if (0==strcmp(*argv, "--debug")) {
87          xsynchFlag = true;
88          cout << "barChart pid " << getpid() << " at sigpause..." << endl;
89          sigpause(0);
90       }
91       else {
92          cerr << "barChart: unrecognized argument \"" << *argv << "\"" << endl;
93          return 5;
94       }
95    }
96
97    // barChart no longer requires any arguments, thanks to tcl2c.
98    if (argc == 2)
99       panic("barChart: argc should be 1");
100
101    MainInterp = Tcl_CreateInterp();
102    assert(MainInterp);
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                      deleteDummyProc);
154
155    Tcl_CreateCommand(MainInterp, "newMetricMaxValCallback", newMetricMaxValCallbackCommand,
156                      NULL, // ClientData
157                      deleteDummyProc);
158
159    Tcl_CreateCommand(MainInterp, "launchBarChart", launchBarChartCommand,
160                      NULL, // ClientData
161                      deleteLaunchBarChartCommand);
162
163    // Krishna's tcl2c stuff gets loaded here:
164    // (initialize_tcl_sources() was auto-generated by 'tcl2c')
165    extern int initialize_tcl_sources(Tcl_Interp *);
166    if (TCL_OK != initialize_tcl_sources(MainInterp))
167       tclpanic(MainInterp, "barChart: could not initialize_tcl_sources");
168
169 //if (TCL_OK != Tcl_EvalFile(MainInterp, "/p/paradyn/development/tamches/core/visiClients/barchart/barChart.tcl"))
170 //   tclpanic(MainInterp, "could not source barChart.tcl manually");
171
172    pdLogo::install_fixed_logo("paradynLogo", logo_bits, logo_width, logo_height);
173    tcl_cmd_installer createPdLogo(MainInterp, "makeLogo",
174                                   pdLogo::makeLogoCommand,
175                                   (ClientData)Tk_MainWindow(MainInterp));
176
177    myTclEval(MainInterp, "init_barchart_window");
178    myTclEval(MainInterp, "Initialize");
179
180    Tk_MainLoop(); // returns when all tk windows are closed
181
182    // shouldn't we be doing some cleanup here?
183 }