2 /* Revision 1.5 1994/04/13 21:21:50 newhall
3 /* *** empty log message ***
5 * Revision 1.4 1994/03/26 04:37:08 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);
60 //////////////////////////////
62 Widget toplevel, paned, clear, print, quit, text;
64 //////////////////////////////
66 // extern int fprintf(), bcopy(), read(), perror(), printf();
68 String fallback_resources[] = {
71 "?.?.text.preferredPaneSize: 200",
72 "?.?.text.width: 200",
73 "?.?.text.textSource.editType: edit",
74 "?.?.text.scrollVertical: whenNeeded",
75 "?.?.text.scrollHorizontal: whenNeeded",
76 "?.?.text.autoFill: on",
77 "*clear*label: Clear",
78 "*print*label: Print",
83 /////////////////////////////////////////////////////////////
84 //void fd_input(XtPointer client_data,int *fid,XtInputId *id)
86 // Widget text = (Widget) client_data;
88 // XawTextPosition pos;
93 // XtSetArg(args[0], XtNinsertPosition, &pos);
94 // XtGetValues(text, args, ONE);
96 // if ((nbytes = read(*fid, buf, BUFSIZ)) == -1)
97 // perror("fd_input");
98 // else if (nbytes > 0) {
100 // tb.length = nbytes;
102 // tb.format = FMT8BIT;
104 // if (XawTextReplace(text,pos,pos+nbytes-1,&tb) != XawEditDone) {
105 // fprintf(stderr,"XawTextReplace returned error\n");
109 // XtSetArg(args[0], XtNinsertPosition, pos);
110 // XtSetValues(text, args, ONE);
114 // callback routine for FOLD and DATAVALUES
115 int fd_input(int dummy){
122 int noMetrics,noResources,noBins;
126 XtSetArg(args[0], XtNinsertPosition, &pos);
127 XtGetValues(text, args, ONE);
130 noMetrics = dataGrid.NumMetrics();
131 noResources = dataGrid.NumResources();
132 noBins = dataGrid.NumBins();
133 for(i=0;i < noMetrics; i++)
134 for(j=0;j<noResources;j++){
135 for(k=0;k<noBins;k++){
136 if((value = dataGrid[i][j][k]) != ERROR){
137 sprintf(&buf[0],"%s%d%s%d%s%d%s%lf\n","dataGrid[",i,"][",j,"][",k,
141 sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k ,
149 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
150 fprintf(stderr,"XawTextReplace returned error\n");
153 XtSetArg(args[0], XtNinsertPosition, pos);
154 XtSetValues(text, args, ONE);
157 sprintf(&buf[0],"\n");
163 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
164 fprintf(stderr,"XawTextReplace returned error\n");
167 XtSetArg(args[0], XtNinsertPosition, pos);
168 XtSetValues(text, args, ONE);
173 // callback routine for ADDMETRICSRESOURCES
174 int fd_input2(int dummy){
180 int noMetrics,noResources,noBins;
184 XtSetArg(args[0], XtNinsertPosition, &pos);
185 XtGetValues(text, args, ONE);
186 noMetrics = dataGrid.NumMetrics();
187 noResources = dataGrid.NumResources();
188 noBins = dataGrid.NumBins();
189 value = dataGrid.BinWidth();
190 aggr = dataGrid.FoldMethod(0);
191 sprintf(&buf[0],"\n%s%d%s%d%s%d%s%lf%s%d\n","noMetrics = ",noMetrics,
192 ", no resources = ",noResources,", num Bins = ",noBins,
193 "\nbinWidth = ",value,", Fold Method = ",aggr);
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);
209 /////////////////////////////////////////////////////////////
212 /////////////////////////////////////
214 static void GetMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
216 GetMetsRes(NULL,NULL,0);
218 /////////////////////////////////////
223 int main(int argc,char **argv)
225 // XtAppContext app_con;
226 // Widget toplevel, paned, clear, print, quit, text;
229 //////////////////////////////////////
230 // variables added for paradyn integration
232 //////////////////////////////////////
234 toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
235 &argc, argv, fallback_resources,
239 * Check to see that all arguments were processed, and if not then
240 * report an error and exit.
244 Syntax(app_con, argv[0]);
246 //////////////////////////////////////
247 // call VisiInit: step (1) from README file
249 if((fd = VisiInit()) < 0){
252 //////////////////////////////////////
255 //////////////////////////////////////
256 // register event callbacks: step (2) from README file
258 ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2);
259 ok = RegistrationCallback(DATAVALUES,fd_input);
260 ok = RegistrationCallback(FOLD,fd_input);
262 // start visi: get initial metric and resource choices: step (3) from README
265 //////////////////////////////////////
267 paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
269 clear = XtCreateManagedWidget("clear", commandWidgetClass, paned,
271 print = XtCreateManagedWidget("print", commandWidgetClass, paned,
273 quit = XtCreateManagedWidget("quit", commandWidgetClass, paned,
276 //////////////////////////////////////
277 // this is for an upcall to Paradyn: step (3a) from README
279 getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass,
281 //////////////////////////////////////
284 XtSetArg(args[0], XtNstring, "This is a test.\n");
286 text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned,
289 XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
290 XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
291 XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con);
293 ///////////////////////////////////////
294 // Add callbacks for upcalls to Paradyn: step (3b) from README
296 XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con);
297 //////////////////////////////////////
299 //////////////////////////////////////
300 // register function to handle that input
301 // XtAppAddInput(app_con, fileno(stdin), (XtPointer) XtInputReadMask,
302 // (XtInputCallbackProc) fd_input, text);
303 //////////////////////////////////////
306 //////////////////////////////////////
307 // register visi_callback routine as callback on events assoc. w/ file desc
308 // step (4) from README file
310 XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask,
311 (XtInputCallbackProc) visi_callback, text);
312 //////////////////////////////////////
315 XtRealizeWidget(toplevel);
316 XtAppMainLoop(app_con);
319 /* Function Name: ClearText
320 * Description: This function clears all text out of the text widget.
321 * Arguments: w - *** UNUSED ***
322 * text_ptr - a pointer to the text widget.
323 * call_data - *** UNUSED ***.
328 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data)
330 Widget text = (Widget) text_ptr;
333 XtSetArg(args[0], XtNstring, "");
334 XtSetValues(text, args, ONE);
337 /* Function Name: PrintText
338 * Description: This function clears all text out of the text widget.
339 * Arguments: w - *** UNUSED ***
340 * text_ptr - a pointer to the text widget.
341 * call_data - *** UNUSED ***.
346 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data)
348 Widget text = (Widget) text_ptr;
352 XtSetArg(args[0], XtNstring, &str);
353 XtGetValues(text, args, ONE);
355 fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str);
358 /* Function Name: QuitProgram
359 * Description: This function exits the program
360 * Arguments: w - *** UNUSED ***
361 * text_ptr - a pointer to the text widget.
362 * call_data - *** UNUSED ***.
367 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data)
369 fprintf(stderr, "Bye!\n");
370 XtDestroyApplicationContext(app_con);
374 /* Function Name: Syntax
375 * Description: Prints a the calling syntax for this function to stdout.
376 * Arguments: app_con - the application context.
377 * call - the name of the application.
378 * Returns: none - exits tho.
381 static void Syntax(XtAppContext app_con,char *call)
383 XtDestroyApplicationContext(app_con);
384 fprintf( stderr, "Usage: %s \n", call);