2 /* Revision 1.6 1994/06/08 17:34:55 newhall
3 /* *** empty log message ***
5 * Revision 1.5 1994/04/13 21:21:54 newhall
6 * *** empty log message ***
8 * Revision 1.4 1994/03/26 04:37:11 newhall
9 * change all floats to double
14 * This an example of how to use the Text and Paned widgets.
16 * November 14, 1989 - Chris D. Peterson
18 * Updated to also demonstrate XtAppAddInput() -- Bruce Irvin 3/8/94
22 * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $
24 * Copyright 1989 Massachusetts Institute of Technology
26 * Permission to use, copy, modify, distribute, and sell this software and its
27 * documentation for any purpose is hereby granted without fee, provided that
28 * the above copyright notice appear in all copies and that both that
29 * copyright notice and this permission notice appear in supporting
30 * documentation, and that the name of M.I.T. not be used in advertising or
31 * publicity pertaining to distribution of the software without specific,
32 * written prior permission. M.I.T. makes no representations about the
33 * suitability of this software for any purpose. It is provided "as is"
34 * without express or implied warranty.
36 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
38 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
40 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
41 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 #include <X11/Intrinsic.h>
46 #include <X11/StringDefs.h>
48 #include <X11/Xaw/AsciiText.h>
49 #include <X11/Xaw/Command.h>
50 #include <X11/Xaw/Paned.h>
52 #include <X11/Xaw/Cardinals.h>
54 //////////////////////////////////
55 #include "../h/visualization.h"
56 //////////////////////////////////
58 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data);
59 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data);
60 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data);
61 static void Syntax(XtAppContext app_con,char *call);
62 //////////////////////////////
64 Widget toplevel, paned, clear, print, quit, text;
65 Widget getMR, stopMR, phaseN;
66 //////////////////////////////
68 // extern int fprintf(), bcopy(), read(), perror(), printf();
70 String fallback_resources[] = {
73 "?.?.text.preferredPaneSize: 200",
74 "?.?.text.width: 200",
75 "?.?.text.textSource.editType: edit",
76 "?.?.text.scrollVertical: whenNeeded",
77 "?.?.text.scrollHorizontal: whenNeeded",
78 "?.?.text.autoFill: on",
79 "*clear*label: Clear",
80 "*print*label: Print",
85 // callback routine for FOLD and DATAVALUES
86 int fd_input(int dummy){
93 int noMetrics,noResources,noBins;
97 XtSetArg(args[0], XtNinsertPosition, &pos);
98 XtGetValues(text, args, ONE);
101 fprintf(stderr,"@@@@ in callback for datavalues and fold\n");
102 noMetrics = dataGrid.NumMetrics();
103 noResources = dataGrid.NumResources();
104 noBins = dataGrid.NumBins();
105 for(i=0;i < noMetrics; i++)
106 for(j=0;j<noResources;j++){
107 for(k=0;k<noBins;k++){
108 if((value = dataGrid[i][j][k]) != ERROR){
109 sprintf(&buf[0],"%s%d%s%d%s%d%s%lf\n","dataGrid[",i,"][",j,"][",k,
113 sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k ,
121 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
122 fprintf(stderr,"XawTextReplace returned error\n");
125 XtSetArg(args[0], XtNinsertPosition, pos);
126 XtSetValues(text, args, ONE);
129 sprintf(&buf[0],"\n");
135 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
136 fprintf(stderr,"XawTextReplace returned error\n");
139 XtSetArg(args[0], XtNinsertPosition, pos);
140 XtSetValues(text, args, ONE);
146 // callback routine for ADDMETRICSRESOURCES
147 int fd_input2(int dummy){
153 int noMetrics,noResources,noBins;
157 fprintf(stderr,"@@@@ in callback for ADDMETRICSRESOURCES\n");
158 XtSetArg(args[0], XtNinsertPosition, &pos);
159 XtGetValues(text, args, ONE);
160 noMetrics = dataGrid.NumMetrics();
161 noResources = dataGrid.NumResources();
162 noBins = dataGrid.NumBins();
163 value = dataGrid.BinWidth();
164 aggr = dataGrid.FoldMethod(0);
165 sprintf(&buf[0],"\n%s%d%s%d%s%d%s%lf%s%d\n","noMetrics = ",noMetrics,
166 ", no resources = ",noResources,", num Bins = ",noBins,
167 "\nbinWidth = ",value,", Fold Method = ",aggr);
174 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
175 fprintf(stderr,"XawTextReplace returned error\n");
178 XtSetArg(args[0], XtNinsertPosition, pos);
179 XtSetValues(text, args, ONE);
183 // callback routine for NEWMETRICSRESOURCES, PHASENAME
184 int fd_input3(int dummy){
191 XtSetArg(args[0], XtNinsertPosition, &pos);
192 XtGetValues(text, args, ONE);
193 sprintf(&buf[0],"\n%s\n",
194 "This operation is not fully supported: only the call is implemented");
200 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
201 fprintf(stderr,"XawTextReplace returned error\n");
204 XtSetArg(args[0], XtNinsertPosition, pos);
205 XtSetValues(text, args, ONE);
210 /////////////////////////////////////
211 static void GetMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
213 fprintf(stderr,"@@@@ in GetMetsRes upcall\n");
214 GetMetsRes(NULL,NULL,0);
217 static void StopMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
219 fprintf(stderr,"@@@@ in StopMetsRes upcall\n");
224 static void PName(Widget w,XtAppContext app_con,XtPointer call_data){
226 fprintf(stderr,"@@@@ in PName upcall\n");
227 NamePhase(0.0,1.0," ");
229 /////////////////////////////////////
232 int main(int argc,char **argv)
234 // XtAppContext app_con;
235 // Widget toplevel, paned, clear, print, quit, text;
238 /////////////////////////////////////
239 // variables added for paradyn integration
241 /////////////////////////////////////
243 toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
244 &argc, argv, fallback_resources,
248 * Check to see that all arguments were processed, and if not then
249 * report an error and exit.
253 Syntax(app_con, argv[0]);
255 //////////////////////////////////////
256 // call VisiInit: step (1) from README file
258 if((fd = VisiInit()) < 0){
261 //////////////////////////////////////
263 //////////////////////////////////////
264 // register event callbacks: step (2) from README file
266 ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2);
267 ok = RegistrationCallback(DATAVALUES,fd_input);
268 ok = RegistrationCallback(FOLD,fd_input);
269 ok = RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input);
270 ok = RegistrationCallback(NEWMETRICSRESOURCES,fd_input3);
271 ok = RegistrationCallback(PHASENAME,fd_input3);
272 //////////////////////////////////////
274 //////////////////////////////////////
275 // start visi: get initial metric and resource choices: step (3) from README
277 // ok = StartVisi(0,0);
278 //////////////////////////////////////
280 paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
282 clear = XtCreateManagedWidget("clear", commandWidgetClass, paned,
284 print = XtCreateManagedWidget("print", commandWidgetClass, paned,
286 quit = XtCreateManagedWidget("quit", commandWidgetClass, paned,
288 //////////////////////////////////////
289 // this is for an upcall to Paradyn: step (3a) from README
291 getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass,
293 stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass,
295 phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass,
298 //////////////////////////////////////
300 XtSetArg(args[0], XtNstring, "This is a test.\n");
302 text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned,
305 XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
306 XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
307 XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con);
309 ///////////////////////////////////////
310 // Add callbacks for upcalls to Paradyn: step (3b) from README
312 XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con);
313 XtAddCallback(stopMR, XtNcallback, StopMetsRes, (XtPointer) app_con);
314 XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con);
315 //////////////////////////////////////
317 //////////////////////////////////////
318 // register visi_callback routine as callback on events assoc. w/ file desc
319 // step (4) from README file
321 XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask,
322 (XtInputCallbackProc) visi_callback, text);
323 //////////////////////////////////////
325 XtRealizeWidget(toplevel);
326 XtAppMainLoop(app_con);
329 /* Function Name: ClearText
330 * Description: This function clears all text out of the text widget.
331 * Arguments: w - *** UNUSED ***
332 * text_ptr - a pointer to the text widget.
333 * call_data - *** UNUSED ***.
338 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data)
340 Widget text = (Widget) text_ptr;
343 XtSetArg(args[0], XtNstring, "");
344 XtSetValues(text, args, ONE);
347 /* Function Name: PrintText
348 * Description: This function clears all text out of the text widget.
349 * Arguments: w - *** UNUSED ***
350 * text_ptr - a pointer to the text widget.
351 * call_data - *** UNUSED ***.
356 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data)
358 Widget text = (Widget) text_ptr;
362 XtSetArg(args[0], XtNstring, &str);
363 XtGetValues(text, args, ONE);
365 fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str);
368 /* Function Name: QuitProgram
369 * Description: This function exits the program
370 * Arguments: w - *** UNUSED ***
371 * text_ptr - a pointer to the text widget.
372 * call_data - *** UNUSED ***.
377 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data)
379 fprintf(stderr, "Bye!\n");
380 XtDestroyApplicationContext(app_con);
384 /* Function Name: Syntax
385 * Description: Prints a the calling syntax for this function to stdout.
386 * Arguments: app_con - the application context.
387 * call - the name of the application.
388 * Returns: none - exits tho.
391 static void Syntax(XtAppContext app_con,char *call)
393 XtDestroyApplicationContext(app_con);
394 fprintf( stderr, "Usage: %s \n", call);