2 /* Revision 1.5 1994/04/13 21:21:54 newhall
3 /* *** empty log message ***
5 * Revision 1.4 1994/03/26 04:37:11 newhall
6 * change all floats to double
11 * This an example of how to use the Text and Paned widgets.
13 * November 14, 1989 - Chris D. Peterson
15 * Updated to also demonstrate XtAppAddInput() -- Bruce Irvin 3/8/94
19 * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $
21 * Copyright 1989 Massachusetts Institute of Technology
23 * Permission to use, copy, modify, distribute, and sell this software and its
24 * documentation for any purpose is hereby granted without fee, provided that
25 * the above copyright notice appear in all copies and that both that
26 * copyright notice and this permission notice appear in supporting
27 * documentation, and that the name of M.I.T. not be used in advertising or
28 * publicity pertaining to distribution of the software without specific,
29 * written prior permission. M.I.T. makes no representations about the
30 * suitability of this software for any purpose. It is provided "as is"
31 * without express or implied warranty.
33 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
35 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
36 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
37 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
38 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 #include <X11/Intrinsic.h>
43 #include <X11/StringDefs.h>
45 #include <X11/Xaw/AsciiText.h>
46 #include <X11/Xaw/Command.h>
47 #include <X11/Xaw/Paned.h>
49 #include <X11/Xaw/Cardinals.h>
51 //////////////////////////////////
52 #include "../h/visualization.h"
53 //////////////////////////////////
55 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data);
56 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data);
57 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data);
58 static void Syntax(XtAppContext app_con,char *call);
59 //////////////////////////////
61 Widget toplevel, paned, clear, print, quit, text;
62 Widget getMR, stopMR, phaseN;
63 //////////////////////////////
65 // extern int fprintf(), bcopy(), read(), perror(), printf();
67 String fallback_resources[] = {
70 "?.?.text.preferredPaneSize: 200",
71 "?.?.text.width: 200",
72 "?.?.text.textSource.editType: edit",
73 "?.?.text.scrollVertical: whenNeeded",
74 "?.?.text.scrollHorizontal: whenNeeded",
75 "?.?.text.autoFill: on",
76 "*clear*label: Clear",
77 "*print*label: Print",
82 // callback routine for FOLD and DATAVALUES
83 int fd_input(int dummy){
90 int noMetrics,noResources,noBins;
94 XtSetArg(args[0], XtNinsertPosition, &pos);
95 XtGetValues(text, args, ONE);
98 fprintf(stderr,"@@@@ in callback for datavalues and fold\n");
99 noMetrics = dataGrid.NumMetrics();
100 noResources = dataGrid.NumResources();
101 noBins = dataGrid.NumBins();
102 for(i=0;i < noMetrics; i++)
103 for(j=0;j<noResources;j++){
104 for(k=0;k<noBins;k++){
105 if((value = dataGrid[i][j][k]) != ERROR){
106 sprintf(&buf[0],"%s%d%s%d%s%d%s%lf\n","dataGrid[",i,"][",j,"][",k,
110 sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k ,
118 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
119 fprintf(stderr,"XawTextReplace returned error\n");
122 XtSetArg(args[0], XtNinsertPosition, pos);
123 XtSetValues(text, args, ONE);
126 sprintf(&buf[0],"\n");
132 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
133 fprintf(stderr,"XawTextReplace returned error\n");
136 XtSetArg(args[0], XtNinsertPosition, pos);
137 XtSetValues(text, args, ONE);
143 // callback routine for ADDMETRICSRESOURCES
144 int fd_input2(int dummy){
150 int noMetrics,noResources,noBins;
154 fprintf(stderr,"@@@@ in callback for ADDMETRICSRESOURCES\n");
155 XtSetArg(args[0], XtNinsertPosition, &pos);
156 XtGetValues(text, args, ONE);
157 noMetrics = dataGrid.NumMetrics();
158 noResources = dataGrid.NumResources();
159 noBins = dataGrid.NumBins();
160 value = dataGrid.BinWidth();
161 aggr = dataGrid.FoldMethod(0);
162 sprintf(&buf[0],"\n%s%d%s%d%s%d%s%lf%s%d\n","noMetrics = ",noMetrics,
163 ", no resources = ",noResources,", num Bins = ",noBins,
164 "\nbinWidth = ",value,", Fold Method = ",aggr);
171 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
172 fprintf(stderr,"XawTextReplace returned error\n");
175 XtSetArg(args[0], XtNinsertPosition, pos);
176 XtSetValues(text, args, ONE);
180 // callback routine for NEWMETRICSRESOURCES, PHASENAME
181 int fd_input3(int dummy){
188 XtSetArg(args[0], XtNinsertPosition, &pos);
189 XtGetValues(text, args, ONE);
190 sprintf(&buf[0],"\n%s\n",
191 "This operation is not fully supported: only the call is implemented");
197 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
198 fprintf(stderr,"XawTextReplace returned error\n");
201 XtSetArg(args[0], XtNinsertPosition, pos);
202 XtSetValues(text, args, ONE);
207 /////////////////////////////////////
208 static void GetMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
210 fprintf(stderr,"@@@@ in GetMetsRes upcall\n");
211 GetMetsRes(NULL,NULL,0);
214 static void StopMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
216 fprintf(stderr,"@@@@ in StopMetsRes upcall\n");
220 static void PName(Widget w,XtAppContext app_con,XtPointer call_data){
222 fprintf(stderr,"@@@@ in PName upcall\n");
223 NamePhase(0.0,1.0," ");
225 /////////////////////////////////////
228 int main(int argc,char **argv)
230 // XtAppContext app_con;
231 // Widget toplevel, paned, clear, print, quit, text;
234 /////////////////////////////////////
235 // variables added for paradyn integration
237 /////////////////////////////////////
239 toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
240 &argc, argv, fallback_resources,
244 * Check to see that all arguments were processed, and if not then
245 * report an error and exit.
249 Syntax(app_con, argv[0]);
251 //////////////////////////////////////
252 // call VisiInit: step (1) from README file
254 if((fd = VisiInit()) < 0){
257 //////////////////////////////////////
259 //////////////////////////////////////
260 // register event callbacks: step (2) from README file
262 ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2);
263 ok = RegistrationCallback(DATAVALUES,fd_input);
264 ok = RegistrationCallback(FOLD,fd_input);
265 ok = RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input);
266 ok = RegistrationCallback(NEWMETRICSRESOURCES,fd_input3);
267 ok = RegistrationCallback(PHASENAME,fd_input3);
268 //////////////////////////////////////
270 //////////////////////////////////////
271 // start visi: get initial metric and resource choices: step (3) from README
273 // ok = StartVisi(0,0);
274 //////////////////////////////////////
276 paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
278 clear = XtCreateManagedWidget("clear", commandWidgetClass, paned,
280 print = XtCreateManagedWidget("print", commandWidgetClass, paned,
282 quit = XtCreateManagedWidget("quit", commandWidgetClass, paned,
284 //////////////////////////////////////
285 // this is for an upcall to Paradyn: step (3a) from README
287 getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass,
289 stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass,
291 phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass,
294 //////////////////////////////////////
296 XtSetArg(args[0], XtNstring, "This is a test.\n");
298 text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned,
301 XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
302 XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
303 XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con);
305 ///////////////////////////////////////
306 // Add callbacks for upcalls to Paradyn: step (3b) from README
308 XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con);
309 XtAddCallback(stopMR, XtNcallback, StopMetsRes, (XtPointer) app_con);
310 XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con);
311 //////////////////////////////////////
313 //////////////////////////////////////
314 // register visi_callback routine as callback on events assoc. w/ file desc
315 // step (4) from README file
317 XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask,
318 (XtInputCallbackProc) visi_callback, text);
319 //////////////////////////////////////
321 XtRealizeWidget(toplevel);
322 XtAppMainLoop(app_con);
325 /* Function Name: ClearText
326 * Description: This function clears all text out of the text widget.
327 * Arguments: w - *** UNUSED ***
328 * text_ptr - a pointer to the text widget.
329 * call_data - *** UNUSED ***.
334 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data)
336 Widget text = (Widget) text_ptr;
339 XtSetArg(args[0], XtNstring, "");
340 XtSetValues(text, args, ONE);
343 /* Function Name: PrintText
344 * Description: This function clears all text out of the text widget.
345 * Arguments: w - *** UNUSED ***
346 * text_ptr - a pointer to the text widget.
347 * call_data - *** UNUSED ***.
352 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data)
354 Widget text = (Widget) text_ptr;
358 XtSetArg(args[0], XtNstring, &str);
359 XtGetValues(text, args, ONE);
361 fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str);
364 /* Function Name: QuitProgram
365 * Description: This function exits the program
366 * Arguments: w - *** UNUSED ***
367 * text_ptr - a pointer to the text widget.
368 * call_data - *** UNUSED ***.
373 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data)
375 fprintf(stderr, "Bye!\n");
376 XtDestroyApplicationContext(app_con);
380 /* Function Name: Syntax
381 * Description: Prints a the calling syntax for this function to stdout.
382 * Arguments: app_con - the application context.
383 * call - the name of the application.
384 * Returns: none - exits tho.
387 static void Syntax(XtAppContext app_con,char *call)
389 XtDestroyApplicationContext(app_con);
390 fprintf( stderr, "Usage: %s \n", call);