v05i001: Xplot, Patch2

Dan Heller argv at island.uu.net
Tue Sep 19 18:21:25 AEST 1989


Submitted-by: uunet!helios.tn.cornell.edu!arthur (Arthur Smith)
Posting-number: Volume 5, Issue 1
Archive-name: xplot/patch2
Patch-To: xplot: Volume 4, Issue 81

The patch consists of a shar file containing the patchlevel.h
file which it seems is now required, and a patch file to be
applied to xplot.c. The patches were based on suggestions
or code supplied by a number of people, particularly dana at bellcore.com
who fixed it to work with color. There is a new #define variable
"WideLabel", which determines whether the current point is
moved after a label is drawn. This is not required in the plot(5)
standard, but seems to be assumed by various graphics programs,
particularly by graph(1). The time WAITINTERVAL in microseconds
is intended to put in a delay in the read process, so that
xplot doesn't keep redrawing the screen each time there is a small
gap in data input. If there are any problems, my e-mail address is
below:

				Arthur

		arpanet:	arthur at helios.tn.cornell.edu
		bitnet:		arthur at crnlassp

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by helios!arthur on Mon Sep 18 18:27:27 EDT 1989
# Contents:  patchlevel.h xplot.patch2
 
echo x - patchlevel.h
sed 's/^@//' > "patchlevel.h" <<'@//E*O*F patchlevel.h//'
2.0
@//E*O*F patchlevel.h//
chmod u=rw,g=r,o=r patchlevel.h
 
echo x - xplot.patch2
sed 's/^@//' > "xplot.patch2" <<'@//E*O*F xplot.patch2//'
*** xplot.c.orig	Wed Sep 13 13:56:40 1989
--- xplot.c	Wed Sep 13 13:27:33 1989
***************
*** 10,15 ****
--- 10,16 ----
  #include <X11/Label.h>
  
  #define LINE 512
+ #define WAITINTERVAL 50000
  char buf[LINE];
  char cptr[LINE];
  char *prog;
***************
*** 21,27 ****
  GC gc;
  XGCValues gcv;
  XtInputId inid;
! /*XtAppContext app_context; */
  int rwidth = 500, rheight = 500;
  
  short xmin, ymax;
--- 22,29 ----
  GC gc;
  XGCValues gcv;
  XtInputId inid;
! Pixel fg, bg;
! XFontStruct *font;
  int rwidth = 500, rheight = 500;
  
  short xmin, ymax;
***************
*** 211,219 ****
  int argc;
  char **argv;
  {
! 	int i, dimset, narg;
  
- 	dimset = 0;
  	for (i=0;i<argc;i++){
  		if (strcmp(argv[i],"-geometry"))
  			continue;
--- 213,221 ----
  int argc;
  char **argv;
  {
! 	int i, dimset = 0, narg;
! 	char *ptr;
  
  	for (i=0;i<argc;i++){
  		if (strcmp(argv[i],"-geometry"))
  			continue;
***************
*** 226,249 ****
  	}
  	toplevel = XtInitialize(argv[0], "xplot",NULL, 0, &argc, argv); 
  	dpy = XtDisplay(toplevel);
- /*	app_context = XtCreateApplicationContext(); */
  
! 	pixmap = XCreatePixmap(dpy,DefaultRootWindow(dpy), rwidth, rheight, 1);
! 	gc = XCreateGC(dpy, pixmap, 0L, &gcv);
! 	XSetForeground(dpy,gc,1);
  
! 	XtSetArg(wargs[0], XtNbitmap, pixmap);
! 	narg = 1;
  	if (dimset == 0) {
! 		XtSetArg(wargs[1], XtNheight, rheight);
! 		XtSetArg(wargs[2], XtNwidth, rwidth);
! 		narg = 3;
  	} 
  	child = XtCreateManagedWidget(prog, labelWidgetClass,
  						toplevel, wargs, narg);
- /*	XtCreateManagedWidget(prog, labelWidgetClass, child, wargs, narg); */
  	XtRealizeWidget(toplevel);
  	widgetwin = XtWindow(child);
  	inid = XtAddInput(fileno(instrm), XtInputReadMask, doplot, NULL);
  	XtMainLoop();
  }
--- 228,271 ----
  	}
  	toplevel = XtInitialize(argv[0], "xplot",NULL, 0, &argc, argv); 
  	dpy = XtDisplay(toplevel);
  
! 	if (!dimset)
! 		if (ptr = XGetDefault(dpy,"xplot","geometry")){
! 			dimset = 1;
! 			rwidth = atoi(ptr);
! 			rheight = atoi(1 + index(ptr,'x'));
! 		}
  
! 	pixmap = XCreatePixmap(dpy,DefaultRootWindow(dpy), rwidth, rheight,
! 		DefaultDepth(dpy, DefaultScreen(dpy)));
! 
! 	narg = 0;
! 	XtSetArg(wargs[narg], XtNbitmap, pixmap); narg++;
! 	XtSetArg(wargs[narg], XtNinternalWidth, 0); narg++;
! 	XtSetArg(wargs[narg], XtNinternalHeight, 0); narg++;
  	if (dimset == 0) {
! 		XtSetArg(wargs[narg], XtNheight, rheight); narg++;
! 		XtSetArg(wargs[narg], XtNwidth, rwidth); narg++;
  	} 
+ 
  	child = XtCreateManagedWidget(prog, labelWidgetClass,
  						toplevel, wargs, narg);
  	XtRealizeWidget(toplevel);
  	widgetwin = XtWindow(child);
+ 
+ 	narg = 0;
+ 	XtSetArg(wargs[narg], XtNbackground, &bg); narg++;
+ 	XtSetArg(wargs[narg], XtNforeground, &fg); narg++;
+ 	XtSetArg(wargs[narg], XtNfont, &font); narg++;
+ 	XtGetValues(child, wargs, narg);
+ 
+ 	gcv.foreground = fg;
+ 	gcv.background = bg;
+ 	gcv.font = font->fid;
+ 	gc = XCreateGC(dpy, pixmap, GCForeground | GCBackground | GCFont,
+ 			 &gcv);
+ 	erase();
+ 
  	inid = XtAddInput(fileno(instrm), XtInputReadMask, doplot, NULL);
  	XtMainLoop();
  }
***************
*** 254,262 ****
  {
  /* Wait for button event */
  /* Clear pixmap */
! 	XSetForeground(dpy,gc,0);
  	XFillRectangle(dpy,pixmap,gc,0,0,rwidth,rheight);
! 	XSetForeground(dpy,gc,1);
  }
  
  /* Don't know how I'm going to do this ! */
--- 276,284 ----
  {
  /* Wait for button event */
  /* Clear pixmap */
! 	XSetForeground(dpy, gc, bg);
  	XFillRectangle(dpy,pixmap,gc,0,0,rwidth,rheight);
! 	XSetForeground(dpy, gc, fg);
  }
  
  /* Don't know how I'm going to do this ! */
***************
*** 266,271 ****
--- 288,296 ----
  {
  	XDrawString(dpy,pixmap,gc,MAPX(curpt[0]),MAPY(curpt[1]),s,
  			strlen(s) - 1);
+ #ifdef WideLabel
+ 	curpt[0] += (strlen(s)*font->max_bounds.width)/xfactor;
+ #endif
  }
  
  line(x1,y1,x2,y2)
***************
*** 411,418 ****
  	if (len > 0)
  		bcopy(curp, cptr, len);
  	if ((lenp = fread(cptr+len, 1, LINE - len, strm)) == 0){
! 		endinp = 1;
! 		return 0;
  	}
  	len += lenp;
  	curp = cptr;
--- 436,446 ----
  	if (len > 0)
  		bcopy(curp, cptr, len);
  	if ((lenp = fread(cptr+len, 1, LINE - len, strm)) == 0){
! 		usleep(WAITINTERVAL); /* Wait in case stuff is on the way */
! 		if ((lenp = fread(cptr+len, 1, LINE - len, strm)) == 0){
! 			endinp = 1;
! 			return 0;
! 		}
  	}
  	len += lenp;
  	curp = cptr;
@//E*O*F xplot.patch2//
chmod u=rw,g=r,o=r xplot.patch2
 
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
       1       1       4 patchlevel.h
     177     564    4376 xplot.patch2
     178     565    4380 total
!!!
wc  patchlevel.h xplot.patch2 | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0



More information about the Comp.sources.x mailing list