v08i016: xfig -- X Drawing Tool, Part07/21

Brian V. Smith envbvs at epb2.lbl.gov
Tue Jul 3 07:26:20 AEST 1990


Submitted-by: envbvs at epb2.lbl.gov (Brian V. Smith)
Posting-number: Volume 8, Issue 16
Archive-name: xfig2.8/part07

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 7 (of 21)."
# Contents:  @figs/arithmetic.fig addpt.c copy.c draw.c global.c text.c
# Wrapped by envbvs at epb2.lbl.gov on Thu Jun 28 08:51:42 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f '@figs/arithmetic.fig' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'@figs/arithmetic.fig'\"
else
echo shar: Extracting \"'@figs/arithmetic.fig'\" \(7345 characters\)
sed "s/^X//" >'@figs/arithmetic.fig' <<'END_OF_FILE'
X#FIG 1.4
X80 2
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 335 175 335 202 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 276 175 276 202 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 254 205 296 205 296 222 254 222 254 205 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 365 622 365 653 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 356 625 356 653 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 348 629 348 653 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 536 445 536 470 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 536 497 536 704 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 492 470 492 495 582 495 582 470 492 470 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 437 567 459 567 459 701 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 390 565 409 565 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 412 538 412 594 437 594 437 538 412 538 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 320 624 296 624 296 704 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 365 465 365 505 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 356 465 356 502 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 348 465 348 498 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 339 493 339 465 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 268 508 254 508 254 704 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 296 508 320 508 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 271 482 296 482 296 534 271 534 271 482 9999 9999
X2 3 0 1 0 0 0 0 0.000 0 0
X	 323 487 390 517 390 610 323 640 323 602 348 589 348 538 323 525 323 487 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 536 222 527 226 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 531 283 531 303 595 303 595 401 569 401 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 531 177 531 264 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 501 264 501 281 561 281 561 264 501 264 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 501 333 501 443 569 443 569 333 501 333 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 487 386 500 399 487 412 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 445 405 492 405 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 445 393 492 393 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 399 337 390 341 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 399 222 390 226 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 395 393 395 283 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 365 264 365 281 425 281 425 264 365 264 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 395 177 395 264 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 429 367 429 431 445 431 445 367 429 367 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 113 405 429 405 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 113 393 429 393 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 105 175 574 175 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 105 162 574 162 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 130 175 130 202 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 109 205 152 205 152 222 109 222 109 205 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 169 205 211 205 211 222 169 222 169 205 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 190 175 190 202 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 130 247 130 307 190 307 190 247 130 247 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 130 222 146 244 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 190 222 172 244 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 135 183 126 187 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 194 183 186 187 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 160 307 160 330 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 130 333 130 350 190 350 190 333 130 333 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 160 350 160 390 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 164 316 156 320 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 164 367 156 371 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 309 367 301 371 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 309 316 301 320 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 305 350 305 390 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 276 333 276 350 335 350 335 333 276 333 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 305 307 305 333 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 339 183 331 187 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 279 183 271 187 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 335 222 317 244 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 0
X	0 0 1.000 4.000 8.000
X	 276 222 292 244 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 276 247 276 307 335 307 335 247 276 247 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 313 205 356 205 356 222 313 222 313 205 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 152 567 219 567 219 585 152 585 152 567 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 152 585 219 585 219 602 152 602 152 585 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 152 602 219 602 219 619 152 619 152 602 9999 9999
X2 2 0 1 0 0 0 0 0.000 0 0
X	 152 619 219 619 219 636 152 636 152 619 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 135 704 561 704 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 135 717 561 717 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 555 698 567 710 555 723 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 0
X	 141 699 127 711 141 724 9999 9999
X2 1 0 1 0 0 0 0 0.000 1 1
X	0 0 1.000 4.000 8.000
X	0 0 1.000 4.000 8.000
X	 186 638 186 701 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 107 214 92 214 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 213 214 229 214 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 251 214 237 214 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 191 341 207 341 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 337 341 352 341 9999 9999
X2 1 0 1 0 0 0 0 0.000 0 1
X	0 0 1.000 4.000 8.000
X	 358 214 373 214 9999 9999
X2 1 0 2 0 0 0 0 0.000 0 0
X	 171 288 151 268 9999 9999
X2 1 0 2 0 0 0 0 0.000 0 0
X	 171 268 151 288 9999 9999
X2 1 0 2 0 0 0 0 0.000 0 0
X	 305 268 305 288 9999 9999
X2 1 0 2 0 0 0 0 0.000 0 0
X	 315 278 295 278 9999 9999
X4 0 0 12 0 0 0 0.000 1 9 90 263 145 ARITHMETIC UNIT
X4 0 0 12 0 0 0 0.000 1 9 72 116 518 ADDRESS UNIT
X4 0 0 12 0 0 0 0.000 1 9 54 326 457 OPERATION
X4 0 0 12 0 0 0 0.000 1 9 30 497 508 (MAR)
X4 0 0 12 0 0 0 0.000 1 9 72 258 738 ADDRESS  BUS
X4 0 0 12 0 0 0 0.000 1 9 66 335 671 COND  CODES
X4 0 0 12 0 0 0 0.000 1 9 18 412 534 OUT
X4 0 0 12 0 0 0 0.000 1 9 66 496 487 MEM ADR REG
X4 0 0 12 0 0 0 0.000 1 9 18 356 567 ALU
X4 0 0 12 0 0 0 0.000 1 9 12 177 632 R0
X4 0 0 12 0 0 0 0.000 1 9 12 177 614 R1
X4 0 0 12 0 0 0 0.000 1 9 12 177 597 R2
X4 0 0 12 0 0 0 0.000 1 9 12 177 580 R3
X4 0 0 12 0 0 0 0.000 1 9 24 266 473 TEMP
X4 0 0 12 0 0 0 0.000 1 9 42 509 440 ADDRESS
X4 0 0 12 0 0 0 0.000 1 9 48 536 260 DATA OUT
X4 0 0 12 0 0 0 0.000 1 9 36 536 247 MEMORY
X4 0 0 12 0 0 0 0.000 1 9 18 519 277 MDO
X4 0 0 12 0 0 0 0.000 1 9 24 378 277 YTOA
X4 0 0 12 0 0 0 0.000 1 9 18 539 401 OUT
X4 0 0 12 0 0 0 0.000 1 9 12 506 401 IN
X4 0 0 12 0 0 0 0.000 1 9 18 519 376 RAM
X4 0 0 12 0 0 0 0.000 1 9 24 514 358 DATA
X4 0 0 12 0 0 0 0.000 1 9 36 420 358 YTOMEM
X4 0 0 12 0 0 0 0.000 1 9 30 207 388 Y BUS
X4 0 0 12 0 0 0 0.000 1 9 24 135 158 ABUS
X4 0 0 12 0 0 0 0.000 1 9 24 113 217 MUL0
X4 0 0 12 0 0 0 0.000 1 9 24 172 217 MUL1
X4 0 0 12 0 0 0 0.000 1 9 36 135 346 MULOUT
X4 0 0 12 0 0 0 0.000 1 9 36 279 346 ADDOUT
X4 0 0 12 0 0 0 0.000 1 9 24 318 217 ADD1
X4 0 0 12 0 0 0 0.000 1 9 24 258 217 ADD0
END_OF_FILE
echo shar: 32 control characters may be missing from \"'@figs/arithmetic.fig'\"
if test 7345 -ne `wc -c <'@figs/arithmetic.fig'`; then
    echo shar: \"'@figs/arithmetic.fig'\" unpacked with wrong size!
fi
# end of '@figs/arithmetic.fig'
fi
if test -f 'addpt.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'addpt.c'\"
else
echo shar: Extracting \"'addpt.c'\" \(7922 characters\)
sed "s/^X//" >'addpt.c' <<'END_OF_FILE'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X *	January 1985.
X *	1st revision : August 1985.
X *	2nd revision : March 1988.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "alloc.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define			TOLERANCE	3
X
Xextern F_line		*line_search();
Xextern F_spline		*spline_search();
Xextern			(*canvas_kbd_proc)();
Xextern			(*canvas_locmove_proc)();
Xextern			(*canvas_leftbut_proc)();
Xextern			(*canvas_middlebut_proc)();
Xextern			(*canvas_rightbut_proc)();
Xextern			null_proc();
Xextern			set_popupmenu();
Xextern			determine_angle();
X
Xextern int		manhattan_mode, mountain_mode;
Xextern int		latexline_mode, latexarrow_mode;
Xextern int		cur_x, cur_y, fix_x, fix_y;
Xextern int		pointmarker_shown;
Xextern F_line		*line;
Xextern F_spline		*spline;
X
Xextern F_point		*added_point;
Xextern F_point		*left_point, *right_point;
X
Xextern int		init_point_adding();
Xextern int		move_addedpoint();
Xextern int		fix_linepoint_adding();
Xextern int		mm_fix_linepoint_adding();
Xextern int		fix_splinepoint_adding();
Xextern int		latex_elasticline();
X
Xstatic F_line		*cur_line;
Xstatic F_spline		*cur_spline;
X
Xpoint_adding_selected()
X{
X	canvas_kbd_proc = null_proc;
X	canvas_locmove_proc = null_proc;
X	canvas_leftbut_proc = init_point_adding;
X	canvas_middlebut_proc = null_proc;
X	canvas_rightbut_proc = set_popupmenu;
X	set_cursor(&pick9_cursor);
X	}
X
Xinit_point_adding(x, y)
Xint	x, y;
X{
X	int	px, py;
X
X	if ((cur_line = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    if (cur_line->type == T_BOX || cur_line->type == T_ARC_BOX) {
X		put_msg("Adding points to a box is not allowed");
X		return;
X		}
X	    init_linepointadding(px, py);
X	    }
X	else if ((cur_spline = spline_search(x,y,TOLERANCE,&px,&py)) != NULL){
X	    init_splinepointadding(px, py);
X	    }
X	else {
X	    return;
X	    }
X	canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X	erase_pointmarker();
X	}
X
Xwrapup_pointadding()
X{
X	show_pointmarker();
X	point_adding_selected();
X	}
X
X/**************************  spline  *******************************/
X
Xinit_splinepointadding(px, py)
Xint		px, py;
X{
X	find_endpoints(cur_spline->points, px, py, &left_point, &right_point);
X	set_temp_cursor(&null_cursor);
X	win_setmouseposition(canvas_win, px, py);
X	cur_x = px; cur_y = py;
X	if (left_point == NULL && closed_spline(cur_spline)) {
X	    /* The added_point is between the 1st and 2nd point. */
X	    left_point = right_point;
X	    right_point = right_point->next;
X	    }
X	draw_addedlink(INV_PAINT);
X	canvas_locmove_proc = move_addedpoint;
X	canvas_middlebut_proc = fix_splinepoint_adding;
X	}
X
Xfix_splinepoint_adding(x, y)
Xint	x, y;
X{
X	F_point		*p;
X
X	if (NULL == (Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    wrapup_pointadding();
X	    return;
X	    }
X	clean_up();
X	added_point = p;
X	added_point->x = x;
X	added_point->y = y;
X	draw_addedlink(INV_PAINT);
X	if (-1 == splinepoint_adding(cur_spline, added_point))
X	    wrapup_pointadding();
X	set_action_object(F_ADD_POINT, O_SPLINE);
X	set_latestspline(cur_spline);
X	wrapup_pointadding();
X	}
X
X/*
XWarning: Do not change the value of the pointers left_point and
Xright_point.  Added_point is always inserted between left_point
Xand right_point, except in two cases. 
X	(1) left_point is NULL, the added_point will be prepended
X		to the list of points. This case will never
X		occur if the spline is closed (periodic).
X	(2) right_point is NULL, the added_point will be appended
X		to the end of the list.
X*/
X
Xsplinepoint_adding(spline, added_point)
XF_spline	*spline;
XF_point		*added_point;
X{
X	F_control	*c;
X
X	set_temp_cursor(&wait_cursor);
X	if (int_spline(spline)) {	/* Interpolated spline */
X	    if (NULL == (Control_malloc(c))) {
X		put_msg(Err_mem);
X		return(-1);
X		}
X	    }
X	if (pointmarker_shown) toggle_splinepointmarker(spline);  
X	draw_spline(spline, ERASE); /* erase old spline */
X	if (left_point == NULL) {
X	    added_point->next = spline->points;
X	    spline->points = added_point;
X	    }
X	else {
X	    added_point->next = right_point;
X	    left_point->next = added_point;
X	    }
X
X	if (int_spline(spline)) {	/* Interpolated spline */
X	    c->next = spline->controls;
X	    spline->controls = c;
X	    remake_control_points(spline);
X	    }
X
X	draw_spline(spline, PAINT); /* draw the modified spline */
X	if (pointmarker_shown) toggle_splinepointmarker(spline);  
X	reset_cursor();
X	set_modifiedflag();
X	return(1);
X	}
X
X/***************************  line  ********************************/
X
Xinit_linepointadding(px, py)
Xint	px, py;
X{
X	find_endpoints(cur_line->points,px,py,&left_point,&right_point);
X	set_temp_cursor(&null_cursor);
X	win_setmouseposition(canvas_win, px, py);
X	cur_x = fix_x = px; cur_y = fix_y = py;
X	if (left_point == NULL && cur_line->type == T_POLYGON) {
X	    left_point = right_point;
X	    right_point = right_point->next;
X	    }
X	if (left_point != NULL && right_point != NULL)
X	    pw_vector(canvas_win, left_point->x, left_point->y,
X		right_point->x, right_point->y, INV_PAINT, 
X		cur_line->thickness, cur_line->style, cur_line->style_val);
X	draw_addedlink(INV_PAINT);
X	if (latexline_mode || latexarrow_mode) {
X	    canvas_locmove_proc = latex_elasticline;
X	    canvas_middlebut_proc = mm_fix_linepoint_adding;
X	    }
X	if( (mountain_mode || manhattan_mode) &&
X	   (left_point == NULL || right_point == NULL) )
X	{
X		canvas_locmove_proc = determine_angle;
X		canvas_middlebut_proc = mm_fix_linepoint_adding;
X	}
X	else
X	{
X		canvas_locmove_proc = move_addedpoint;
X		canvas_middlebut_proc = fix_linepoint_adding;
X	}
X	}
X
Xfix_linepoint_adding(x, y)
Xint	x, y;
X{
X	F_point		*p;
X
X	if (NULL == (Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    wrapup_pointadding();
X	    return;
X	    }
X	clean_up();
X	added_point = p;
X	added_point->x = x;
X	added_point->y = y;
X	draw_addedlink(INV_PAINT);
X	linepoint_adding(cur_line, added_point);
X	set_action_object(F_ADD_POINT, O_POLYLINE);
X	set_latestline(cur_line);
X	wrapup_pointadding();
X	}
X
Xmm_fix_linepoint_adding()
X{
X	F_point		*p;
X
X	if (NULL == (Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    wrapup_pointadding();
X	    return;
X	    }
X	clean_up();
X	added_point = p;
X	added_point->x = cur_x;
X	added_point->y = cur_y;
X	draw_addedlink(INV_PAINT);
X	linepoint_adding(cur_line, added_point);
X	set_action_object(F_ADD_POINT, O_POLYLINE);
X	set_latestline(cur_line);
X	wrapup_pointadding();
X	}
X
Xlinepoint_adding(line, added_point)
XF_line	*line;
XF_point	*added_point;
X{
X	if (pointmarker_shown) toggle_linepointmarker(line);
X	draw_line(line, ERASE);
X	if (left_point == NULL) {
X	    added_point->next = line->points;
X	    line->points = added_point;
X	    }
X	else {
X	    added_point->next = left_point->next;
X	    left_point->next = added_point;
X	    }
X	draw_line(line, PAINT);
X	if (pointmarker_shown) toggle_linepointmarker(line);  
X	set_modifiedflag();
X	}
X
X/*******************************************************************/
X
X/*
XIf (x,y) is close to a point, q, fp points to q and sp points to q->next
X(right).  However if q is the first point, fp contains NULL and sp points to q.
X*/
X
Xfind_endpoints(p, x, y, fp, sp)
XF_point	*p, **fp, **sp;
Xint	x, y;
X{
X	int	d;
X	F_point	*a = NULL, *b = p;
X
X	if (x == b->x && y == b->y) {
X	    *fp = a;
X	    *sp = b;
X	    return;
X	    }
X
X	for (a = p, b = p->next; b != NULL; a = b, b = b->next){
X	    if (x == b->x && y == b->y) {
X		*fp = b;
X		*sp = b->next;
X		return;
X		}
X	    if (close_to_vector(a->x, a->y, b->x, b->y, x, y, 1, 1.0, &d, &d)) {
X		*fp = a;
X		*sp = b;
X		return;
X		}
X	    }
X	*fp = a;
X	*sp = b;
X	}
X
Xdraw_addedlink(op)
Xint	op;
X{
X	if (left_point != NULL) {
X	    pw_vector(canvas_win, left_point->x, left_point->y,
X			cur_x, cur_y, op, 1, SOLID_LINE, 0.0);
X	   }
X	if (right_point != NULL) {
X	    pw_vector(canvas_win, right_point->x, 
X			right_point->y, cur_x, cur_y, op, 1, SOLID_LINE, 0.0);
X	    }
X	}
X
Xmove_addedpoint(x, y)
Xint	x, y;
X{
X	draw_addedlink(INV_PAINT);
X	cur_x = x;
X	cur_y = y;
X	draw_addedlink(INV_PAINT);
X	}
END_OF_FILE
if test 7922 -ne `wc -c <'addpt.c'`; then
    echo shar: \"'addpt.c'\" unpacked with wrong size!
fi
# end of 'addpt.c'
fi
if test -f 'copy.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'copy.c'\"
else
echo shar: Extracting \"'copy.c'\" \(8048 characters\)
sed "s/^X//" >'copy.c' <<'END_OF_FILE'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X *	January 1985.
X *	1st revision : Aug 1985.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "alloc.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define			TOLERANCE	7
X
Xextern			(*canvas_kbd_proc)();
Xextern			(*canvas_locmove_proc)();
Xextern			(*canvas_leftbut_proc)();
Xextern			(*canvas_middlebut_proc)();
Xextern			(*canvas_rightbut_proc)();
Xextern			(*return_proc)();
Xextern			null_proc();
Xextern			set_popupmenu();
Xextern F_line		*line_search(), *copy_line();
Xextern F_arc		*arc_search(), *copy_arc();
Xextern F_ellipse	*ellipse_search(), *copy_ellipse();
Xextern F_text		*text_search(), *copy_text();
Xextern F_spline		*spline_search(), *copy_spline();
Xextern F_compound	*compound_search(), *copy_compound();
X
Xextern F_compound	objects;
X
Xextern int		copy_selected();
Xextern int		init_copy();
X
Xcopy_selected()
X{
X	canvas_kbd_proc = null_proc;
X	canvas_locmove_proc = null_proc;
X	canvas_leftbut_proc = init_copy;
X	canvas_middlebut_proc = null_proc;
X	canvas_rightbut_proc = set_popupmenu;
X	return_proc = copy_selected;
X	set_cursor(&pick15_cursor);
X	reset_action_on();
X	}
X
Xinit_copy(x, y)
Xint	x, y;
X{
X	F_line		*l, *line;
X	F_ellipse	*e, *ellipse;
X	F_text		*t, *text;
X	F_spline	*s, *spline;
X	F_arc		*a, *arc;
X	F_compound	*c, *compound;
X	int		px, py;
X
X	if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    compound = copy_compound(c);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    win_setmouseposition(canvas_win, px, py);
X	    clean_up();
X	    set_action_object(F_CREATE, O_COMPOUND);
X	    insert_compound(&objects.compounds, compound);
X	    set_latestcompound(compound);
X	    init_compounddragging(compound, px, py);
X	    }
X	else if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    line = copy_line(l);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    win_setmouseposition(canvas_win, px, py);
X	    clean_up();
X	    set_action_object(F_CREATE, O_POLYLINE);
X	    insert_line(&objects.lines, line);
X	    set_latestline(line);
X	    init_linedragging(line, px, py);
X	    }
X	else if ((t = text_search(x, y)) != NULL) {
X	    text = copy_text(t);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    clean_up();
X	    set_action_object(F_CREATE, O_TEXT);
X	    insert_text(&objects.texts, text);
X	    set_latesttext(text);
X	    init_textdragging(text, x, y);
X	    }
X	else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    ellipse = copy_ellipse(e);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    win_setmouseposition(canvas_win, px, py);
X	    clean_up();
X	    set_action_object(F_CREATE, O_ELLIPSE);
X	    insert_ellipse(&objects.ellipses, ellipse);
X	    set_latestellipse(ellipse);
X	    init_ellipsedragging(ellipse, px, py);
X	    }
X	else if ((a = arc_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    arc = copy_arc(a);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    win_setmouseposition(canvas_win, px, py);
X	    clean_up();
X	    set_action_object(F_CREATE, O_ARC);
X	    insert_arc(&objects.arcs, arc);
X	    set_latestarc(arc);
X	    init_arcdragging(arc, px, py);
X	    }
X	else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    spline = copy_spline(s);
X	    erase_pointmarker();
X	    set_temp_cursor(&null_cursor);
X	    win_setmouseposition(canvas_win, px, py);
X	    clean_up();
X	    set_action_object(F_CREATE, O_SPLINE);
X	    insert_spline(&objects.splines, spline);
X	    set_latestspline(spline);
X	    init_splinedragging(spline, px, py);
X	    }
X	else
X	    return;
X	canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X	}
X
XF_arc *
Xcopy_arc(a)
XF_arc	*a;
X{
X	F_arc	*arc;
X
X	if (NULL == (Arc_malloc(arc))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	*arc = *a;
X	arc->next = NULL;
X	return(arc);
X	}
X
XF_ellipse *
Xcopy_ellipse(e)
XF_ellipse	*e;
X{
X	F_ellipse	*ellipse;
X
X	if (NULL == (Ellipse_malloc(ellipse))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	*ellipse = *e;
X	ellipse->next = NULL;
X	return(ellipse);
X	}
X
XF_line *
Xcopy_line(l)
XF_line	*l;
X{
X	F_line	*line;
X	F_point	*p, *point, *last_point;
X
X	if (NULL == (Line_malloc(line))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	*line = *l;
X	if (NULL == (Point_malloc(point))) {
X	    put_msg(Err_mem);
X	    free((char *)line);
X	    return(NULL);
X	    }
X	line->points = point;
X	last_point = point;
X	p = l->points;
X	*point = *p;
X	point->next = NULL;
X	for (p = p->next; p != NULL; p = p->next) {
X	    last_point->next = Point_malloc(point);
X	    if (point == NULL) return(NULL);
X	    *point = *p;
X	    point->next = NULL;
X	    last_point = point;
X	    }
X	line->next = NULL;
X	return(line);
X	}
X
XF_spline *
Xcopy_spline(s)
XF_spline	*s;
X{
X	F_spline	*spline;
X	F_point		*p, *point, *last_point;
X	F_control	*cntrl_pnt, *cp, *last_cntrl_pnt;
X
X	if (NULL == (Spline_malloc(spline))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	*spline = *s;
X	spline->next = NULL;
X
X	if (NULL == (Point_malloc(point))) {
X	    put_msg(Err_mem);
X	    free((char *)spline);
X	    return(NULL);
X	    }
X	last_point = spline->points = point;
X	p = s->points;
X	*point = *p;
X	for (p = p->next; p != NULL; p = p->next) {
X	    last_point->next = Point_malloc(point);
X	    if (point == NULL) return(NULL);
X	    *point = *p;
X	    last_point = point;
X	    }
X	last_point->next = NULL;
X
X	spline->controls = NULL;
X	if (s->controls == NULL) return(spline);
X
X	if (NULL == (Control_malloc(cntrl_pnt))) {
X	    put_msg(Err_mem);
X	    free((char *)spline);
X	    free((char *)point);
X	    return(NULL);
X	    }
X	last_cntrl_pnt = spline->controls = cntrl_pnt;
X	cp = s->controls;
X	*cntrl_pnt = *cp;
X	for (cp = cp->next; cp != NULL; cp = cp->next) {
X	    last_cntrl_pnt->next = Control_malloc(cntrl_pnt);
X	    if (cntrl_pnt == NULL) return(NULL);
X	    *cntrl_pnt = *cp;
X	    last_cntrl_pnt = cntrl_pnt;
X	    }
X	last_cntrl_pnt->next = NULL;
X
X	return(spline);
X	}
X
XF_text *
Xcopy_text(t)
XF_text	*t;
X{
X	F_text		*text;
X	extern char	*calloc();
X
X	if (NULL == (Text_malloc(text))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	*text = *t;
X	text->cstring = calloc((unsigned)(strlen(t->cstring)+1), sizeof(char));
X	if (text->cstring == NULL) {
X	    free((char*)text);
X	    text = NULL;
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	strcpy(text->cstring, t->cstring);
X	text->next = NULL;
X	return(text);
X	}
X
XF_compound *
Xcopy_compound(c)
XF_compound	*c;
X{
X	F_ellipse	*e, *ee;
X	F_arc		*a, *aa;
X	F_line		*l, *ll;
X	F_spline	*s, *ss;
X	F_text		*t, *tt;
X	F_compound	*cc, *ccc, *compound;
X
X	if (NULL == (Compound_malloc(compound))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	compound->nwcorner = c->nwcorner;
X	compound->secorner = c->secorner;
X	compound->arcs = NULL;
X	compound->ellipses = NULL;
X	compound->lines = NULL;
X	compound->splines = NULL;
X	compound->texts = NULL;
X	compound->compounds = NULL;
X	compound->next = NULL;
X	for (e = c->ellipses; e != NULL; e = e->next) {
X	    if (NULL == (ee = copy_ellipse(e))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_ellipse(&compound->ellipses, ee);
X	    }
X	for (a = c->arcs; a != NULL; a = a->next) {
X	    if (NULL == (aa = copy_arc(a))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_arc(&compound->arcs, aa);
X	    }
X	for (l = c->lines; l != NULL; l = l->next) {
X	    if (NULL == (ll = copy_line(l))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_line(&compound->lines, ll);
X	    }
X	for (s = c->splines; s != NULL; s = s->next) {
X	    if (NULL == (ss = copy_spline(s))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_spline(&compound->splines, ss);
X	    }
X	for (t = c->texts; t != NULL; t = t->next) {
X	    if (NULL == (tt = copy_text(t))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_text(&compound->texts, tt);
X	    }
X	for (cc = c->compounds; cc != NULL; cc = cc->next) {
X	    if (NULL == (ccc = copy_compound(cc))) {
X		put_msg(Err_mem);
X		return(NULL);
X		}
X	    insert_compound(&compound->compounds, ccc);
X	    }
X	return(compound);
X	}
END_OF_FILE
if test 8048 -ne `wc -c <'copy.c'`; then
    echo shar: \"'copy.c'\" unpacked with wrong size!
fi
# end of 'copy.c'
fi
if test -f 'draw.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'draw.c'\"
else
echo shar: Extracting \"'draw.c'\" \(8203 characters\)
sed "s/^X//" >'draw.c' <<'END_OF_FILE'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1988 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X *	March 1988.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "object.h"
X#include "paintop.h"
X
Xextern int		pointmarker_shown, compoundbox_shown;
Xextern int		background_color, foreground_color;
X
X/* COMMENTED OUT
Xerase_objects(objects)
XF_compound	*objects;
X{
X	erase_arcs(objects->arcs);
X	erase_ellipses(objects->ellipses);
X	erase_lines(objects->lines);
X	erase_texts(objects->texts);
X	erase_splines(objects->splines);
X	erase_compounds(objects->compounds);
X	}
X*/
X
Xerase_splines(splines)
XF_spline	*splines;
X{
X	F_spline	*s;
X
X	for (s = splines; s != NULL; s = s->next) {
X	    if (pointmarker_shown) toggle_splinepointmarker(s);
X	    draw_spline(s, ERASE);
X	    };
X	}
X
Xerase_ellipses(ellipses)
XF_ellipse	*ellipses;
X{
X	F_ellipse	*e;
X
X	for (e = ellipses; e != NULL; e = e->next) {
X	    if (pointmarker_shown) toggle_ellipsepointmarker(e);
X	    draw_ellipse(e, background_color);
X	    };
X	}
X
Xerase_arcs(arcs)
XF_arc	*arcs;
X{
X	F_arc	*a;
X
X	for (a = arcs; a != NULL; a = a->next) {
X	    if (pointmarker_shown) toggle_arcpointmarker(a);
X	    draw_arc(a, background_color);
X	    };
X	}
X
Xerase_compounds(compounds)
XF_compound	*compounds;
X{
X	F_compound	*c;
X
X	for (c = compounds; c != NULL; c = c->next) {
X	    if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X	    erase_compound(c);
X	    };
X	}
X
Xerase_lines(lines)
XF_line	*lines;
X{
X	F_line	*l;
X
X	for (l = lines; l != NULL; l = l->next) {
X	    if (pointmarker_shown) toggle_linepointmarker(l);
X	    draw_line(l, ERASE);
X	    };
X	}
X
Xerase_texts(texts)
XF_text	*texts;
X{
X	F_text	*t;
X
X	for (t = texts; t != NULL; t = t->next) {
X	    draw_text(t, INV_PAINT);
X	    };
X	}
X
X/*
Xdraw_objects(objects)
XF_compound	*objects;
X{
X	draw_arcs(objects->arcs);
X	draw_ellipses(objects->ellipses);
X	draw_lines(objects->lines);
X	draw_texts(objects->texts);
X	draw_splines(objects->splines);
X	draw_compounds(objects->compounds);
X	}
X*/
X
Xdraw_ellipses(ellipses)
XF_ellipse	*ellipses;
X{
X	F_ellipse	*e;
X
X	for (e = ellipses; e != NULL; e = e->next) {
X	    draw_ellipse(e, foreground_color);
X	    if (pointmarker_shown) toggle_ellipsepointmarker(e);
X	    };
X	}
X
Xdraw_arcs(arcs)
XF_arc	*arcs;
X{
X	F_arc	*a;
X
X	for (a = arcs; a != NULL; a = a->next) {
X	    draw_arc(a, foreground_color);
X	    if (pointmarker_shown) toggle_arcpointmarker(a);
X	    };
X	}
X
Xdraw_lines(lines)
XF_line	*lines;
X{
X	F_line	*l;
X
X	for (l = lines; l != NULL; l = l->next) {
X	    draw_line(l, PAINT);
X	    if (pointmarker_shown) 
X		toggle_linepointmarker(l);
X	    }
X	}
X
Xdraw_splines(splines)
XF_spline	*splines;
X{
X	F_spline	*s;
X
X	for (s = splines; s != NULL; s = s->next) {
X	    draw_spline(s, PAINT);
X	    if (pointmarker_shown) toggle_splinepointmarker(s);
X	    };
X	}
X
Xdraw_texts(texts)
XF_text	*texts;
X{
X	F_text	*t;
X
X	for (t = texts; t != NULL; t = t->next) {
X	    draw_text(t, PAINT);
X	    };
X	}
X
Xdraw_compounds(compounds)
XF_compound	*compounds;
X{
X	F_compound	*c;
X
X	for (c = compounds; c != NULL; c = c->next) {
X	    draw_compound(c);
X	    if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X	    };
X	}
X
X/*	draw arrow heading from (x1, y1) to (x2, y2)	*/
X
Xdraw_arrow(x1, y1, x2, y2, arrow, op)
Xint	x1, y1, x2, y2, op;
XF_arrow	*arrow;
X{
X	float	x, y, xb, yb, dx, dy, l, sina, cosa;
X	int	xc, yc, xd, yd;
X	float	wid = arrow->wid, ht = arrow->ht;
X
X	dx = x2 - x1;  dy = y1 - y2;
X	l = sqrt((double)(dx*dx + dy*dy));
X	if(l == 0)
X		return;
X	sina = dy / l;  cosa = dx / l;
X	xb = x2*cosa - y2*sina;
X	yb = x2*sina + y2*cosa;
X	x = xb - ht;
X	y = yb - wid / 2;
X	xc = x*cosa + y*sina + .5;
X	yc = -x*sina + y*cosa + .5;
X	y = yb + wid / 2;
X	xd = x*cosa + y*sina + .5;
X	yd = -x*sina + y*cosa + .5;
X	pw_vector(canvas_win, xc, yc, x2, y2, op, 
X		   (int) arrow->thickness, arrow->style, 0.0);
X	pw_vector(canvas_win, xd, yd, x2, y2, op, 
X		   (int) arrow->thickness, arrow->style, 0.0);
X	}
X
Xdraw_spline(spline, op)
XF_spline	*spline;
Xint		op;
X{
X	if (int_spline(spline))
X	    draw_intspline(spline, op);
X	else if (spline->type == T_CLOSED_NORMAL)
X	    draw_closed_spline(spline, op);
X	else if (spline->type == T_OPEN_NORMAL)
X	    draw_open_spline(spline, op);
X	}
X
X#define		STACK_DEPTH		32
Xtypedef		struct stack {
X			float	x1, y1, x2, y2, x3, y3, x4, y4;
X			}
X		Stack;
Xstatic Stack	stack[20];
Xstatic Stack	*stack_top;
Xstatic int	stack_count;
X
Xclear_stack()
X{
X	stack_top = stack;
X	stack_count = 0;
X	}
X
Xpush(x1, y1, x2, y2, x3, y3, x4, y4)
Xfloat	x1, y1, x2, y2, x3, y3, x4, y4;
X{
X	stack_top->x1 = x1;
X	stack_top->y1 = y1;
X	stack_top->x2 = x2;
X	stack_top->y2 = y2;
X	stack_top->x3 = x3;
X	stack_top->y3 = y3;
X	stack_top->x4 = x4;
X	stack_top->y4 = y4;
X	stack_top++;
X	stack_count++;
X	}
X
Xint
Xpop(x1, y1, x2, y2, x3, y3, x4, y4)
Xfloat	*x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4;
X{
X	if (stack_count == 0) return(0);
X	stack_top--;
X	stack_count--;
X	*x1 = stack_top->x1;
X	*y1 = stack_top->y1;
X	*x2 = stack_top->x2;
X	*y2 = stack_top->y2;
X	*x3 = stack_top->x3;
X	*y3 = stack_top->y3;
X	*x4 = stack_top->x4;
X	*y4 = stack_top->y4;
X	return(1);
X	}
X
Xdraw_line(line, op)
XF_line	*line;
Xint	op;
X{
X	F_point		*point;
X	XPoint		*points, *pptr;
X	int		npoints;
X	int		xx, yy, x, y;
X
X	/* fill the object first then draw outline */
X	fill_object(line,op);
X
X	if (line->type == T_ARC_BOX)	/* box with rounded corners */
X		{
X		draw_arc_box(line,op);
X		return;
X		}
X
X	point = line->points;
X	/* get and save first point */
X	x = point->x;
X	y = point->y;
X	if (line->points->next == NULL) { /* A single point */
X		XDrawPoint(tool_d, canvas_win, gccache[op], x, y);
X	    return;
X	    }
X	if (line->back_arrow) /* backward arrow  */
X	    draw_arrow(point->next->x, point->next->y, x, y, 
X		line->back_arrow, op);
X	if (line->style == SOLID_LINE)	/* accumulate the points for solid line */
X		{
X		npoints = 0;
X		/* count number of points in this object */
X		for ( ; point != NULL; point = point->next)
X			npoints++;
X		/* accumulate the points in an array */
X		if ((points = (XPoint *) malloc(npoints*sizeof(XPoint))) == 0)
X			{
X			fprintf(stderr,"draw_line(): No memory\n");
X			return;
X			}
X		pptr = points;
X		}
X	for (point=line->points; point != NULL; point = point->next) {
X	    if (line->style == SOLID_LINE)
X		    {
X		    pptr->x = point->x;
X		    pptr->y = point->y;
X		    pptr++;
X		    }
X	    else	/* draw dashed or dotted line segment by segment
X			   otherwise when moving one segment later there
X			   is an alignment problem with the dashes */
X		pw_vector(canvas_win, x, y, point->x, point->y, op,
X			line->thickness, line->style, line->style_val);
X	    xx = x; yy = y;
X	    x = point->x;
X	    y = point->y;
X	    }
X	if (line->style == SOLID_LINE)
X	    {
X	    pw_lines(canvas_win, points, npoints, op, 
X		line->thickness, line->style, line->style_val, 0);
X	    free(points);
X	    }
X	if (line->for_arrow) 
X	    draw_arrow(xx, yy, x, y, line->for_arrow, op);
X	}
X
Xdraw_arc_box(line, op)
XF_line *line;
Xint op;
X	{
X	F_point		*point;
X	int		xmin,xmax,ymin,ymax;
X	int		thick, style;
X	float		val;
X	int		radius,diam;
X	GC		gc;
X
X	thick = line->thickness;
X	if (thick == 0)
X		return;
X	point = line->points;
X	style = line->style;
X	val   = line->style_val;
X	radius = line->radius;
X
X	xmin = xmax = point->x;
X	ymin = ymax = point->y;
X	while (point->next)		/* find lower left (upper-left on screen) */
X		{			/* and upper right (lower right on screen) */
X		point = point->next;
X		if (point->x < xmin)
X			xmin = point->x;
X		else if (point->x > xmax)
X			xmax = point->x;
X		if (point->y < ymin)
X			ymin = point->y;
X		else if (point->y > ymax)
X			ymax = point->y;
X		}
X	set_line_stuff(thick,style,val,op);
X	gc = gccache[op];
X	diam = 2*radius;
X	XDrawArc(tool_d, canvas_win, gc, xmin, ymin,
X			diam, diam, 90*64, 90*64);
X	XDrawLine(tool_d, canvas_win, gc, xmin, ymin+radius, xmin, ymax-radius+1);
X	XDrawArc(tool_d, canvas_win, gc, xmin, ymax-diam,
X			diam, diam, 180*64, 90*64);
X	XDrawLine(tool_d, canvas_win, gc, xmin+radius, ymax, xmax-radius+1, ymax);
X	XDrawArc(tool_d, canvas_win, gc, xmax-diam, ymax-diam,
X			diam, diam, 270*64, 90*64);
X	XDrawLine(tool_d, canvas_win, gc, xmax, ymax-radius, xmax, ymin+radius-1);
X	XDrawArc(tool_d, canvas_win, gc, xmax-diam, ymin,
X			diam, diam, 0*64, 90*64);
X	XDrawLine(tool_d, canvas_win, gc, xmax-radius, ymin, xmin+radius-1, ymin);
X	}
END_OF_FILE
if test 8203 -ne `wc -c <'draw.c'`; then
    echo shar: \"'draw.c'\" unpacked with wrong size!
fi
# end of 'draw.c'
fi
if test -f 'global.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'global.c'\"
else
echo shar: Extracting \"'global.c'\" \(7384 characters\)
sed "s/^X//" >'global.c' <<'END_OF_FILE'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X *	January 1985.
X *	1st revision : Aug 1985.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#define	GLOBAL		/* force resources and font to allocate space */
X#include "resources.h"
X#include "font.h"
X#undef	GLOBAL
X#include "const.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X/**********************  canvas variables  ************************/
X
Xint			(*canvas_kbd_proc)();
Xint			(*canvas_locmove_proc)();
Xint			(*canvas_leftbut_proc)();
Xint			(*canvas_middlebut_proc)();
Xint			(*canvas_rightbut_proc)();
Xint			(*return_proc)();
Xint			fix_x, fix_y;
Xint			cur_x, cur_y;
X
Xint			action_on = 0;
Xint			pointmarker_shown = 0;
Xint			compoundbox_shown = 0;
X
Xint			ICON_COLUMN;
Xint			CANVAS_HEIGHT, CANVAS_WIDTH;
Xint			PANEL_WID, PANEL2_WID;
Xint			SIDERULER_WIDTH, SIDERULER_HEIGHT;
Xint			TOPRULER_WIDTH, TOPRULER_HEIGHT;
X
Xint			num_point;
XF_point			*first_point, *cur_point;
X
X/************************  Objects  **********************/
X
X/*
XObject_tails (not always) point to the last objects in each linked list
Xin objects.  It is used to speed up an undo-read action.  When a file
Xis read, the lists of the objects read are stored in saved_objects
Xand the pointers to tails of the lists in objects would kept in object_tails
Xthe "next" members of the tail objects point to the lists in saved_objects.
XTo undo, one would only set all the "next" of tail object to NULL;
X
XObject_tails is also used for speeding up the undo of compound breaking
Xaction in similar fashion.
X*/
XF_compound		object_tails = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
XF_compound		objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
XF_compound		saved_objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
XF_compound		*saved_compound = NULL;	/* Saved the broken compound */
X
X/*************************  Undo  variables  **********************/
X
Xint			last_action = F_NULL;
Xint			last_object;
Xint			last_axis;
Xint			last_rotateangle;
Xstruct {int x, y;}	last_position, new_position;
XF_point			*moved_point;
XF_point			*deleted_point;
XF_point			*added_point;
XF_point			*left_point;
XF_point			*right_point;
Xint			movedpoint_num;
X
X/***************************  Modes  ****************************/
X
Xint			manhattan_mode		= 0;
Xint			mountain_mode		= 0;
Xint			autoforwardarrow_mode	= 0;
Xint			autobackwardarrow_mode	= 0;
Xint			latexline_mode		= 0;
Xint			latexarrow_mode		= 0;
Xint			magnet_mode		= 0;
Xint			line_thickness		= 1;
Xint			line_style		= SOLID_LINE;
Xint			cur_radius		= 7;
Xint			pen_size		= 0;
Xint			pen_type		= 0;
Xint			flip_axis		= -1;
Xint			rotate_angle		= 0;
Xint			fill_mode		= 0;
Xint			print_landscape		= 0;	/* def. orientation for printer */
Xint			size_button;			/* font size button value */
Xint			font_button		= 0;	/* font button value */
Xint			type_button		= T_LEFT_JUSTIFIED;	/* text type button value */
Xint			cur_font;			/* font of current text object */
Xint			cur_fontsize;			/* size of current text object font */
Xint			cur_areafill		= 1;
Xfloat			cur_dashlength		= 4;
Xfloat			cur_dotgap		= 3;
Xfloat			cur_styleval		= 0.0;
Xfloat			cur_angle		= 0.0;
Xint			cur_color		= BLACK;
Xint			cur_textstyle		= PLAIN;
Xint			cur_textjust		= T_LEFT_JUSTIFIED;
X		/* line thicknesses for each gc */
Xint			gc_thickness[NUMOPS]	= {-1,-1,-1,-1};
Xint			gc_line_style[NUMOPS]	= {-1,-1,-1,-1};
X
X/*************************  Flags/Resources  *******************************/
X
Xint			cur_command = -1;
X
X/* Resources */
X
XappresStruct appres;
X
X/************************  Status  ****************************/
X
Xchar			directory[1024];
Xchar			current_file[200] = "";
Xint			cur_printer=0;
Xchar			*printer="";
Xchar			*printer_list[MAXPRINTERS]={"Specify","Default","File"};
Xint			figure_modified = 0;
X
X/************************  Error messages  ****************************/
X
Xchar		Err_incomp[] = "Incomplete %s object at line %d.";
Xchar		Err_mem[] = "Running out of memory.";
X
X/************************  Routines  ****************************/
X
Xnull_proc()
X{
X	}
X
Xset_modifiedflag()
X{
X	figure_modified = 1;
X	}
X
Xset_action_on()
X{
X	action_on = 1;
X	}
X
Xreset_action_on()
X{
X	action_on = 0;
X	}
X
Xreset_cursor()
X{
X	XDefineCursor(tool_d, canvas_win, (Cursor)cur_cursor->bitmap);
X	}
X
Xset_temp_cursor(cursor)
XCURSOR	cursor;
X{
X	XDefineCursor(tool_d, canvas_win, (Cursor)cursor->bitmap);
X	}
X
Xset_cursor(cursor)
XCURSOR	cursor;
X{
X	cur_cursor = cursor;
X	XDefineCursor(tool_d, canvas_win, (Cursor)cursor->bitmap);
X	}
X
Xset_lastaxis(a)
Xint	a;
X{
X	last_axis = a;
X	}
X
Xset_lastangle(a)
Xint	a;
X{
X	last_rotateangle = a;
X	}
X
Xset_lastposition(x, y)
Xint	x, y;
X{
X	last_position.x = x;
X	last_position.y = y;
X	}
X
Xset_action(action)
Xint	 action;
X{
X	last_action = action;
X	}
X
Xset_action_object(action, object)
Xint	 action, object;
X{
X	last_action = action;
X	last_object = object;
X	}
X
X/*
XClean_up should be called before committing a user's request.
XClean_up will attempt to free all the allocated memories which
Xresulted from delete/remove action.  It will set the last_action
Xto F_NULL.  Thus this routine should be before set_action_object().
Xif they are to be called in the same routine.
X*/
Xclean_up()
X{
X	if (last_action == F_REMOVE) {
X	    switch (last_object) {
X		case O_ARC :
X		    free_arc(&saved_objects.arcs);
X		    break;
X		case O_COMPOUND :
X		    free_compound(&saved_objects.compounds);
X		    break;
X		case O_ELLIPSE :
X		    free_ellipse(&saved_objects.ellipses);
X		    break;
X		case O_POLYLINE :
X		    free_line(&saved_objects.lines);
X		    break;
X		case O_SPLINE :
X		    free_spline(&saved_objects.splines);
X		    break;
X		case O_TEXT :
X		    free_text(&saved_objects.texts);
X		    break;
X		case O_ALL_OBJECT :
X		    free_arc(&saved_objects.arcs);
X		    free_compound(&saved_objects.compounds);
X		    free_ellipse(&saved_objects.ellipses);
X		    free_line(&saved_objects.lines);
X		    free_spline(&saved_objects.splines);
X		    free_text(&saved_objects.texts);
X		    break;
X		}
X	    }
X	else if (last_action == F_DELETE_POINT) {
X	    free((char*)deleted_point);
X	    deleted_point = NULL;
X	    }
X	else if (last_action == F_REMOVE_ALL || last_action == F_EDIT) {
X	    free_arc(&saved_objects.arcs);
X	    free_compound(&saved_objects.compounds);
X	    free_ellipse(&saved_objects.ellipses);
X	    free_line(&saved_objects.lines);
X	    free_spline(&saved_objects.splines);
X	    free_text(&saved_objects.texts);
X	    }
X	else if (last_action == F_BREAK) {
X	    free_compound(&saved_compound);
X	    }
X	else if (last_action == F_CREATE) {
X	    saved_objects.arcs = NULL;
X	    saved_objects.compounds = NULL;
X	    saved_objects.ellipses = NULL;
X	    saved_objects.lines = NULL;
X	    saved_objects.splines = NULL;
X	    saved_objects.texts = NULL;
X	    }
X	else if (last_action == F_TURN) {
X	    if (last_object == O_POLYLINE) {
X		free_line(&saved_objects.lines);
X		}
X	    else {	/* last_object == O_SPLINE */
X		free_spline(&saved_objects.splines);
X		}
X	    }
X	last_action = F_NULL;
X	}
X
Xset_latestarc(arc)
XF_arc	*arc;
X{
X	saved_objects.arcs = arc;
X	}
X
Xset_latestcompound(compound)
XF_compound	*compound;
X{
X	saved_objects.compounds = compound;
X	}
X
Xset_latestellipse(ellipse)
XF_ellipse	*ellipse;
X{
X	saved_objects.ellipses = ellipse;
X	}
X
Xset_latestline(line)
XF_line	*line;
X{
X	saved_objects.lines = line;
X	}
X
Xset_latestspline(spline)
XF_spline	*spline;
X{
X	saved_objects.splines = spline;
X	}
X
Xset_latesttext(text)
XF_text	*text;
X{
X	saved_objects.texts = text;
X	}
END_OF_FILE
if test 7384 -ne `wc -c <'global.c'`; then
    echo shar: \"'global.c'\" unpacked with wrong size!
fi
# end of 'global.c'
fi
if test -f 'text.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'text.c'\"
else
echo shar: Extracting \"'text.c'\" \(7248 characters\)
sed "s/^X//" >'text.c' <<'END_OF_FILE'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X *	January 1985.
X *	1st revision : Aug 1985.
X *	2nd revision : Feb 1988.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "alloc.h"
X#include "const.h"
X#include "font.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
Xextern			(*canvas_kbd_proc)();
Xextern			(*canvas_locmove_proc)();
Xextern			(*canvas_leftbut_proc)();
Xextern			(*canvas_middlebut_proc)();
Xextern			(*canvas_rightbut_proc)();
Xextern			null_proc();
Xextern	char		*calloc();
Xextern			set_popupmenu();
Xextern	F_text		*text_search();
Xextern	PIX_FONT	lookfont();
X
Xextern	int		font_button, size_button;
Xextern	int		type_button;
X
Xextern	int		cur_font, cur_fontsize;
Xextern			char_handler();
Xextern	int		cur_x, cur_y;
Xextern	char		prefix[], suffix[];
Xextern	int		leng_prefix, leng_suffix;
Xextern	int		cur_color;
Xextern	int		cur_textstyle;
Xextern	int		cur_textjust;
Xextern	float		cur_angle;
X
Xextern	F_compound	objects;
X
Xstatic	int		char_ht, char_wid;
Xstatic	int		base_x, base_y;
Xstatic	F_text		*cur_text;
Xstatic	PR_SIZE		tsize;
Xstatic	PR_SIZE		ssize;
X
XF_text			*create_text();
Xstatic			finish_text_input();
Xstatic			finish_n_start();
Xstatic			init_text_input();
Xstatic			wrap_up();
X
Xstatic
Xfinish_n_start(x, y)
X{
X	wrap_up();
X	init_text_input(x, y);
X	}
X
Xstatic
Xfinish_text_input()
X{
X	wrap_up();
X	text_drawing_selected();
X	}
X
Xstatic
Xwrap_up()
X{
X	PR_SIZE		size;
X	int		kbd_received;
X
X	reset_action_on();
X	kbd_received = terminate_char_handler();
X	if ( ! kbd_received) return;
X
X	if (cur_text == NULL) {	/* a brand new text */
X	    if (leng_prefix == 0) return;
X	    cur_text = create_text();
X	    insert_text(&objects.texts, cur_text);
X	    }
X	else {			/* existing text modified */
X	    strcat(prefix, suffix);
X	    leng_prefix += leng_suffix;
X	    if (leng_prefix == 0) {
X		delete_text(&objects.texts, cur_text);
X		cfree(cur_text->cstring);
X		free((char*)cur_text);
X		return;
X		}
X	    if (strlen(cur_text->cstring) >= leng_prefix) { 
X		strcpy(cur_text->cstring, prefix);
X		}
X	    else { /* free old and allocate new */
X		cfree(cur_text->cstring);
X		cur_text->cstring = calloc((unsigned)(leng_prefix+1), sizeof(char));
X		if (cur_text->cstring != NULL)
X		  strcpy(cur_text->cstring, prefix);
X		}
X	    size = pf_textwidth(cur_text->font, cur_text->size, leng_prefix, prefix);
X	    cur_text->height = size.y;
X	    cur_text->length = size.x;  /* in pixels */
X	    }
X	draw_text(cur_text, PAINT);
X	clean_up();
X	set_action_object(F_TEXT, O_TEXT);
X	set_latesttext(cur_text);
X	set_modifiedflag();
X	}
X
Xstatic
Xinit_text_input(x, y)
Xint	x, y;
X{
X	int basx;
X
X	cur_x = x;
X	cur_y = y;
X
X	set_action_on();
X	canvas_kbd_proc = char_handler;
X	canvas_middlebut_proc = finish_text_input;
X	canvas_leftbut_proc = finish_n_start;
X	canvas_rightbut_proc = null_proc;
X
X	/* set current font info to indicator button settings */
X	cur_fontsize = size_button;
X	cur_font = font_button;
X	cur_textjust = type_button;
X
X	/* load the X font and get its id for this font, size */
X	canvas_font = lookfont(cur_font, cur_fontsize);
X	char_ht = char_height(canvas_font);
X	char_wid = char_width(canvas_font);
X
X	if ((cur_text = text_search(cur_x, cur_y)) == NULL) {	/* new text input */
X	    leng_prefix = leng_suffix = 0;
X	    *suffix = 0;
X	    prefix[leng_prefix] = '\0';
X	    base_x = cur_x;
X	    base_y = cur_y;
X	    }
X	else { 		/* clicked on existing text */
X	    /* leng_prefix is # of char in the text before the cursor */
X	    leng_suffix = strlen(cur_text->cstring);
X	    basx = cur_text->base_x;
X	    if (cur_text->type == T_CENTER_JUSTIFIED)
X		basx -= cur_text->length/2;
X	    else if (cur_text->type == T_RIGHT_JUSTIFIED)
X		basx -= cur_text->length;
X	    leng_prefix = prefix_length(cur_text->cstring, cur_x - basx);
X	    leng_suffix -= leng_prefix;
X	    cpy_n_char(prefix, cur_text->cstring, leng_prefix);
X	    strcpy(suffix, &cur_text->cstring[leng_prefix]);
X	    tsize = pf_textwidth(cur_text->font, cur_text->size, leng_prefix, prefix);
X	    ssize = pf_textwidth(cur_text->font, cur_text->size, leng_suffix, suffix);
X	    cur_x = base_x = basx;
X	    cur_y = base_y = cur_text->base_y;
X	    cur_x += tsize.x;
X	    cur_font = cur_text->font;
X	    cur_fontsize = cur_text->size;
X	    cur_textjust = cur_text->type;
X	    }
X	initialize_char_handler(canvas_win, finish_text_input, 
X			base_x, base_y);
X	}
X
X/* This procedure is called before any other text stuff here */
X
Xtext_drawing_selected()
X{
X	canvas_kbd_proc = null_proc;
X	canvas_locmove_proc = null_proc;
X	canvas_middlebut_proc = null_proc;
X	canvas_leftbut_proc = init_text_input;
X	canvas_rightbut_proc = set_popupmenu;
X
X	set_cursor(&pencil_cursor);
X	}
X
XF_text *
Xcreate_text()
X{
X	F_text		*text;
X	PR_SIZE		size;
X
X	if ((Text_malloc(text)) == NULL) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	text->cstring = calloc((unsigned)(leng_prefix+1), sizeof(char));
X	if (text->cstring == NULL) {
X	    put_msg(Err_mem);
X	    free((char *)text);
X	    return(NULL);
X	    }
X	text->type = cur_textjust;;
X	text->font = cur_font;	/* put in current font number */
X	text->size = cur_fontsize;	/* added 9/25/89 B.V.Smith */
X	text->angle = cur_angle;
X	text->style = cur_textstyle;
X	text->color = cur_color;
X	text->depth = 0;
X	text->pen = 0;
X	size = pf_textwidth(text->font, text->size, leng_prefix, prefix);
X	text->length = size.x;	/* in pixels */
X	text->height = size.y;	/* in pixels */
X	text->base_x = base_x;
X	text->base_y = base_y;
X	strcpy(text->cstring, prefix);
X	text->next = NULL;
X	return(text);
X	}
X
Xcpy_n_char(dst, src, n)
Xchar	*dst, *src;
Xint	 n;
X{
X	/* src must be longer than n chars */
X
X	while (n--) *dst++ = *src++;
X	*dst = '\0';
X	}
X
Xint
Xprefix_length(string, where_p)
Xchar		*string;
Xint		 where_p;
X{
X	/* c stands for character unit and p for pixel unit */
X	int		l, len_c, len_p;
X	int		char_wid, where_c;
X	PR_SIZE		size;
X
X	if (canvas_font == NULL) 
X		fprintf(stderr,"Error, in prefix_length, canvas_font = NULL\n");
X	len_c = strlen(string);
X	size = pf_textwidth(cur_text->font, cur_text->size, len_c, string);
X	len_p = size.x;
X	if (where_p >= len_p) return(len_c); /* entire string is the preffix */
X
X	char_wid = char_width(canvas_font);
X	where_c = where_p / char_wid;	/* estimated char position */
X	size = pf_textwidth(cur_text->font, cur_text->size, where_c, string);
X	l = size.x;	/* actual lenght (pixels) of string of where_c chars */
X	if (l < where_p) {
X	    do {	/* add the width of next char to l */
X		l += (char_wid = char_advance(canvas_font,string[where_c++]));
X		} while (l < where_p);
X	    if (l-(char_wid>>1) >= where_p) where_c--;
X	    }
X	else if (l > where_p) {
X	    do {	/* subtract the width of last char from l */
X		l -= (char_wid = char_advance(canvas_font,string[--where_c]));
X		} while (l > where_p);
X	    if (l+(char_wid>>1) >= where_p) where_c++;
X	    }
X	return(where_c);
X	}
X
Xdraw_text(text, op)
XF_text	*text;
Xint	op;
X{
X	PR_SIZE	size;
X	int x;
X
X	x = text->base_x;
X	if (text->type == T_CENTER_JUSTIFIED || text->type == T_RIGHT_JUSTIFIED)
X		{
X		size = pf_textwidth(text->font,text->size,strlen(text->cstring),text->cstring);
X		if (text->type == T_CENTER_JUSTIFIED)
X			x -= size.x/2;
X		else
X			x -= size.x;
X		}
X	pw_text(canvas_win, x, text->base_y, 
X		op, text->font, text->size, text->cstring);
X	}
END_OF_FILE
if test 7248 -ne `wc -c <'text.c'`; then
    echo shar: \"'text.c'\" unpacked with wrong size!
fi
# end of 'text.c'
fi
echo shar: End of archive 7 \(of 21\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 21 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list