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