[comp.sources.x] v01i009: xfig: a MacDraw style line editor

mikew@wyse.wyse.com (Mike Wexler) (08/17/88)

Submitted-by: ken@cs.rochester.edu (Ken Yap)
Posting-number: Volume 1, Issue 9
Archive-name: xfig/part08

#! /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 8 (of 11)."
# Contents:  main.c read.c ruler.c
# Wrapped by mikew@wyse on Tue Aug 16 13:14:40 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f main.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(14448 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
X *	1st revision : Aug 1985.
X *
X *	%W%	%G%
X*/
X#include "fig.h"
X#include "const.h"
X#include "version.h"
X
Xextern int		borderwid, windowspacing, toolstripeht;
Xextern int		ICON_COLUMN;
Xextern int		CANVAS_HEIGHT, CANVAS_WIDTH;
Xextern int		CANVAS_LEFT, CANVAS_TOP;
Xextern int		PANEL_LEFT, PANEL_TOP, PANEL_HEIGHT, PANEL_WID;
Xextern int		MSG_LEFT, MSG_TOP, MSG_WIDTH;
Xextern int		SIDERULER_LEFT, SIDERULER_TOP;
Xextern int		SIDERULER_WIDTH, SIDERULER_HEIGHT;
Xextern int		SIDERULER_START;
Xextern int		TOPRULER_LEFT, TOPRULER_TOP;
Xextern int		TOPRULER_WIDTH, TOPRULER_HEIGHT;
Xextern			(*canvas_rightbut_proc)();
Xextern			set_popupmenu();
X
X#include "fig.icon"
X#include "resources.h"
X
X#define 		FIG_ICON_WIDTH		MY_ICON_WIDTH
X#define 		FIG_ICON_HEIGHT		MY_ICON_HEIGHT
X#define			SCREEN_WIDTH		1152
X#define			SCREEN_HEIGHT		900
X#define			min(a,b)		(((a) < (b)) ? (a) : (b))
X
Xmpr_static(fig_icon_pr, FIG_ICON_WIDTH, FIG_ICON_HEIGHT, 1, icon_data);
Xstatic struct icon	fig_icon  =  {
X				FIG_ICON_WIDTH+4, FIG_ICON_HEIGHT+4, NULL,
X				{2, 2, FIG_ICON_WIDTH, FIG_ICON_HEIGHT},
X				&fig_icon_pr, {0, 0, 0, 0}, NULL, NULL,
X				ICON_BKGRDSET };
X
Xstatic char	tool_name[80] = " FIG : FACILITY FOR INTERACTIVE GENERATION OF FIGURES ";
Xstatic RECT		icon_rect, tool_rect;
Xstatic			sigwinched();
X
X/************** FIG options ******************/
X
Xextern int		DEBUG;
Xextern int		RHS_PANEL;
Xextern int		INVERSE;
X
XTOOL			tool;
Xint			WINDOW_WIDTH, WINDOW_HEIGHT;
Xchar			file_header[32] = "#FIG ";
Xstatic char		*file = NULL;
X
Xget_args(argc, argv)
Xint	argc;
Xchar	**argv;
X{
X	char	*option;
X
X        CANVAS_HEIGHT = DEF_CANVAS_HEIGHT;
X        CANVAS_WIDTH = DEF_CANVAS_WIDTH;
X        ICON_COLUMN = ICON_COLUMN_PORT;
X	while (--argc > 0)  {
X	   option = *++argv;
X	   if (*option == '-') {
X		 while(*++option != '\0') {
X			 switch(*option) {
X			 case 'r':	/* put panel on right side */
X				 RHS_PANEL = 1;
X				 break;
X				 
X			 case 'd':	/* turn on debugging */
X				 DEBUG = 1;
X				 break;
X				 
X			 case 'p':   /* 8 X 10 portrait mode */
X			 case 'P':
X				 CANVAS_HEIGHT = DEF_CANVAS_HEIGHT;
X				 CANVAS_WIDTH = DEF_CANVAS_WIDTH;
X				 ICON_COLUMN = ICON_COLUMN_PORT;
X				 break;
X				 
X			 case 'l':   /* 10 X 8 landscape mode */
X			 case 'L':
X				 CANVAS_HEIGHT = DEF_CANVAS_WIDTH;
X				 CANVAS_WIDTH = DEF_CANVAS_HEIGHT;
X				 ICON_COLUMN = ICON_COLUMN_LAND;
X				 break;
X				 
X			 case 'w':	/* set width to size you want */
X				 CANVAS_WIDTH = atof(*++argv) * PIX_PER_INCH;
X				 argc--;
X				 break;
X				 
X			 case 'h':	/* set height to size you want */
X				 CANVAS_HEIGHT = atof(*++argv) * PIX_PER_INCH;
X				 if( CANVAS_HEIGHT < DEF_CANVAS_HEIGHT)
X					 ICON_COLUMN = ICON_COLUMN_LAND;
X				 argc--;
X				 break;
X				 
X			 case 'i':	/* reverse video */
X				 INVERSE = 1;
X				 invert_color();
X				 break;
X				 
X			 default:
X				 printf ("%s: Flag <%c> unrecognized\n", argv[0], *option);
X				 exit(1);
X				 
X			 }
X		 }
X	 }
X	 else
X	 {
X		 file = option;
X	 }
X    }
X}
X
X#ifndef	X11
Xmain(argc, argv)
Xint	argc;
Xchar	**argv;
X{
X	ICON_COLUMN = ICON_COLUMN_PORT;
X	get_args(argc, argv);
X	strcat(tool_name, FIG_VERSION);
X	strcat(file_header, FIG_VERSION);
X	printf("Initializing FIG %s%s (SunView) ...\n", FIG_VERSION, MINOR_VERSION);
X	tool = tool_create(tool_name, TOOL_NAMESTRIPE, NULL, &fig_icon);
X	if (tool == (TOOL)0) exit(1);
X	compute_window_sizes();
X	set_window_size();
X
X	init_font();
X	if (init_panel(tool) == 0) exit(1);
X	if (init_canvas(tool) == 0) exit(1);
X	if (init_msg(tool) == 0) exit(1);
X	if (init_sideruler(tool) == 0) exit(1);
X	if (init_topruler(tool) == 0) exit(1);
X	set_subwindow_sizes();
X
X	if (file != NULL) {
X	    edit_file(file);
X	    }
X	signal(SIGWINCH, sigwinched);
X	canvas_rightbut_proc = set_popupmenu;
X	tool_install(tool);
X	for(;;) {
X	    tool_select(tool, 0);
X	    quit();	/* This is where one of the exit points is */
X	    }
X}
X#else
X
Xstatic int zero = 0;
Xint	landscape;
Xfloat	tmp_width = 0.0, tmp_height = 0.0;
X
Xstatic XtResource application_resources[] = {
X	{XtNjustify, XtCJustify, XtRBoolean, sizeof(int),
X		 (Cardinal)&RHS_PANEL, XtRString, "False"},
X	{"debug", "Debug", XtRBoolean, sizeof(int),
X		 (Cardinal)&DEBUG, XtRString, "False"},
X	{XtNorientation, XtCOrientation, XtRBoolean, sizeof(int),
X		 (Cardinal)&landscape, XtRBoolean, False},
X	{XtNwidth, XtCWidth, XtRFloat, sizeof(float),
X		 (Cardinal)&tmp_width, XtRInt, (caddr_t)&zero},
X	{XtNheight, XtCHeight, XtRFloat, sizeof(float),
X		 (Cardinal)&tmp_height, XtRInt, (caddr_t)&zero},
X	{XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(int),
X		 (Cardinal)&INVERSE, XtRString, "False"},
X};
X
Xstatic XrmOptionDescRec options[] =
X{
X	{"-right", ".justify", XrmoptionNoArg, "True" },
X	{"-debug", ".debug", XrmoptionNoArg, "True"},
X	{"-landscape", ".orientation", XrmoptionNoArg, "True"},
X	{"-Landscape", ".orientation", XrmoptionNoArg, "True"},
X	{"-portrait", ".orientation", XrmoptionNoArg, "False"},
X	{"-Portrait", ".orientation", XrmoptionNoArg, "False"},
X	{"-width", ".width", XrmoptionSepArg, 0},
X	{"-height", ".height", XrmoptionSepArg, 0},
X	{"-inverse", ".reverseVideo", XrmoptionNoArg, "True"}
X};
X
Xstatic XtCallbackRec	callbacks[] =
X{
X	{ NULL, NULL },
X};
X
Xstatic Arg	form_args[] =
X{
X	{ XtNcallback, (XtArgVal)callbacks },
X};
X
Xmain(argc,argv)
X	int		argc;
X	char		*argv[];
X{
X	TOOL		form, children[5];
X	Arg		tmp_arg[2];
X	int		init_panel(), init_msg(), init_canvas(),
X			init_sideruler(), init_topruler();
X
X	strcat(tool_name, FIG_VERSION);
X	strcat(file_header, FIG_VERSION);
X	printf("Initializing FIG %s%s (X11) ... \n", FIG_VERSION, MINOR_VERSION);
X	tool = XtInitialize("fig", "Fig", options, XtNumber(options),
X		&argc, argv);
X
X	XtSetArg(tmp_arg[0], XtNtitle, tool_name);
X	XtSetValues(tool, tmp_arg, 1);
X
X	fix_converters();
X	XtGetApplicationResources(tool, 0, application_resources,
X                                   XtNumber(application_resources), NULL, 0 );
X	if (argc > 1)
X		file = argv[1];
X
X	tool_d = XtDisplay(tool);
X	tool_s = XtScreen(tool);
X	tool_sn = DefaultScreen(tool_d);
X	gc = DefaultGC(tool_d, tool_sn);
X	init_font();
X	init_cursor();
X	form = XtCreateManagedWidget("form", formWidgetClass, tool,
X		form_args, XtNumber(form_args));
X	
X	ICON_COLUMN = ICON_COLUMN_PORT;
X	CANVAS_WIDTH = tmp_width * PIX_PER_INCH;
X	CANVAS_HEIGHT = tmp_height * PIX_PER_INCH;
X
X	if( CANVAS_WIDTH == 0 )
X		CANVAS_WIDTH = landscape ? DEF_CANVAS_HEIGHT :
X				DEF_CANVAS_WIDTH;
X	
X	if( CANVAS_HEIGHT == 0 )
X		CANVAS_HEIGHT = landscape ? DEF_CANVAS_WIDTH :
X			DEF_CANVAS_HEIGHT;
X	
X	if( CANVAS_HEIGHT < DEF_CANVAS_HEIGHT )
X		ICON_COLUMN = ICON_COLUMN_LAND;
X		
X	(void)init_panel(form);
X	children[0] = panel_sw;
X	(void)init_topruler(form);
X	children[1] = topruler_sw;
X	(void)init_menu(form);
X	(void)init_canvas(form);
X	children[2] = canvas_sw;
X	(void)init_msg(form);
X	children[3] = msg_sw;
X	(void)init_sideruler(form);
X	children[4] = sideruler_sw;
X	XtManageChildren(children, 5);
X	XtRealizeWidget(tool);
X	if( RHS_PANEL )
X	{
X		XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
X		XtSetArg(tmp_arg[1], XtNhorizDistance, RULER_WIDTH+2);
X		XtSetValues(topruler_sw, tmp_arg, 2);
X		XtSetArg(tmp_arg[0], XtNfromHoriz, 0);
X		XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
X		XtSetValues(sideruler_sw, tmp_arg, 2);
X		XtUnmanageChild(msg_sw);
X		XtSetArg(tmp_arg[0], XtNfromHoriz, sideruler_sw);
X		XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw);
X		XtSetValues(canvas_sw, tmp_arg, 2);
X		XtManageChild(msg_sw);
X		XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw);
X		XtSetArg(tmp_arg[1], XtNfromVert, 0);
X		XtSetValues(panel_sw, tmp_arg, 2);
X		XtSetArg(tmp_arg[0], XtNfromHoriz, sideruler_sw);
X		XtSetArg(tmp_arg[1], XtNfromVert, canvas_sw);
X		XtSetValues(msg_sw, tmp_arg, 2);
X		XtUnmanageChild(msg_sw);
X		XtManageChild(msg_sw);
X	}
X	init_gc();
X	setup_panel();
X	setup_rulers();
X	setup_canvas();
X	setup_msg();
X	canvas_rightbut_proc = set_popupmenu;
X	if (file != NULL)
X		edit_file(file);
X	(void)signal(SIGINT, SIG_IGN);	/* so we don't lose work accidentally */
X	XtMainLoop();
X}
X#endif	X11
X
X#ifndef	X11
X#define		TOPRULER_CANVAS_SPACING		5
X#define		SIDERULER_CANVAS_SPACING	5
X#define		PANEL_CANVAS_SPACING		5
X#define		PANEL_MSG_SPACING		5
X
Xcompute_window_sizes()
X{
X	borderwid = tool_borderwidth(tool);
X	windowspacing = tool_subwindowspacing(tool);
X	toolstripeht = tool_stripeheight(tool);
X	PANEL_WID = ICON_COLUMN * SWITCH_ICON_WIDTH;
X	PANEL_HEIGHT = RULER_WIDTH + CANVAS_HEIGHT + TOPRULER_CANVAS_SPACING;
X	PANEL_TOP = toolstripeht + 2;
X	MSG_WIDTH = PANEL_WID + RULER_WIDTH + CANVAS_WIDTH
X		+ SIDERULER_CANVAS_SPACING + PANEL_CANVAS_SPACING;
X	MSG_TOP = PANEL_HEIGHT + PANEL_TOP + PANEL_MSG_SPACING;
X	MSG_LEFT = borderwid;
X
X	TOPRULER_TOP = PANEL_TOP;
X	TOPRULER_WIDTH = CANVAS_WIDTH;
X	TOPRULER_HEIGHT = RULER_WIDTH;
X
X	CANVAS_TOP = TOPRULER_TOP + RULER_WIDTH + TOPRULER_CANVAS_SPACING;
X
X	SIDERULER_TOP = TOPRULER_TOP;
X	SIDERULER_WIDTH = RULER_WIDTH;
X	SIDERULER_HEIGHT = PANEL_HEIGHT;
X	SIDERULER_START = RULER_WIDTH + TOPRULER_CANVAS_SPACING;
X
X	WINDOW_WIDTH = borderwid + borderwid + MSG_WIDTH;
X	WINDOW_HEIGHT = MSG_TOP + MSG_HEIGHT + borderwid;
X
X	if (RHS_PANEL) { /* panel on the right of drawing area */
X	    SIDERULER_LEFT = borderwid;
X	    CANVAS_LEFT = SIDERULER_LEFT + RULER_WIDTH
X			+ SIDERULER_CANVAS_SPACING;
X	    PANEL_LEFT = CANVAS_LEFT + CANVAS_WIDTH + PANEL_CANVAS_SPACING;
X	    TOPRULER_LEFT = CANVAS_LEFT;
X	    }
X	else {
X	    PANEL_LEFT = borderwid;
X	    CANVAS_LEFT = PANEL_LEFT + PANEL_WID + PANEL_CANVAS_SPACING;
X	    SIDERULER_LEFT = CANVAS_LEFT + CANVAS_WIDTH
X			+ SIDERULER_CANVAS_SPACING;
X	    TOPRULER_LEFT = CANVAS_LEFT;
X	    }
X	}
X
Xset_window_size()
X{
X	if (wmgr_iswindowopen(tool->tl_windowfd) )  {
X	    win_getrect(tool->tl_windowfd, &tool_rect);
X	    win_getsavedrect(tool->tl_windowfd, &icon_rect);
X	    }
X	else {
X	    win_getrect(tool->tl_windowfd, &icon_rect);
X	    win_getsavedrect(tool->tl_windowfd, &tool_rect);
X	    }
X	if (tool_rect.r_width != WINDOW_WIDTH
X		|| tool_rect.r_height != WINDOW_HEIGHT) {
X	    tool_rect.r_width = WINDOW_WIDTH;
X	    tool_rect.r_height = WINDOW_HEIGHT;
X	    icon_rect.r_left = min(icon_rect.r_left, SCREEN_WIDTH-FIG_ICON_WIDTH-4);
X	    icon_rect.r_top = min(icon_rect.r_top, SCREEN_HEIGHT-FIG_ICON_HEIGHT-4);
X	    if (tool_rect.r_left < 0
X		    || tool_rect.r_left + tool_rect.r_width > SCREEN_WIDTH
X		    || tool_rect.r_top < 0
X		    || tool_rect.r_top + tool_rect.r_height > SCREEN_HEIGHT) {
X		tool_rect.r_left  = 300;
X		tool_rect.r_top   = 10;
X		}
X	    if (wmgr_iswindowopen(tool->tl_windowfd) )  {
X		win_setrect(tool->tl_windowfd, &tool_rect);
X		win_setsavedrect(tool->tl_windowfd, &icon_rect);
X		}
X	    else {
X		win_setrect(tool->tl_windowfd, &icon_rect);
X		win_setsavedrect(tool->tl_windowfd, &tool_rect);
X		}
X	    }
X	}
X
Xstatic
Xsigwinched()
X{
X	tool_sigwinch(tool);
X	set_window_size();
X	set_subwindow_sizes();
X	}
X
Xset_subwindow_sizes()
X{
X	set_window(panel_sw, PANEL_TOP, PANEL_LEFT, PANEL_WID, PANEL_HEIGHT);
X	set_window(msg_sw, MSG_TOP, MSG_LEFT, MSG_WIDTH, MSG_HEIGHT);
X	set_window(canvas_sw, CANVAS_TOP, CANVAS_LEFT, CANVAS_WIDTH,
X			CANVAS_HEIGHT);
X	set_window(sideruler_sw, SIDERULER_TOP, SIDERULER_LEFT, RULER_WIDTH,
X			SIDERULER_HEIGHT);
X	set_window(topruler_sw, TOPRULER_TOP, TOPRULER_LEFT, CANVAS_WIDTH,
X			RULER_WIDTH);
X	}
X
Xset_window(win, t, l, w, h)
XTOOLSW		win;
Xint		t, l, w, h;
X{
X	RECT		r;
X
X	if (wmgr_iswindowopen(tool->tl_windowfd) )
X	    win_getrect(win->ts_windowfd, &r);
X	else 
X	    win_getsavedrect(win->ts_windowfd, &r);
X
X	if (r.r_top!= t || r.r_left != l || r.r_width != w || r.r_height != h) {
X	    r.r_top = t;
X	    r.r_left = l;
X	    r.r_width = w;
X	    r.r_height = h;
X	    if (wmgr_iswindowopen(tool->tl_windowfd))
X		win_setrect(win->ts_windowfd, &r);
X	    else 
X		win_setsavedrect(win->ts_windowfd, &r);
X	    }
X	}
X#endif	X11
X
X/*
X	if (wmgr_iswindowopen(tool->tl_windowfd) )
X	    win_getrect(msg_sw->ts_windowfd, &msg_rect);
X	else 
X	    win_getsavedrect(msg_sw->ts_windowfd, &msg_rect);
X	if ( msg_rect.r_top != MSG_TOP || msg_rect.r_left != MSG_LEFT ||  
X		msg_rect.r_width != MSG_WIDTH ||  
X		msg_rect.r_height != MSG_HEIGHT) {
X	    msg_rect.r_top = MSG_TOP;
X	    msg_rect.r_left = MSG_LEFT;
X	    msg_rect.r_width = MSG_WIDTH;
X	    msg_rect.r_height = MSG_HEIGHT;
X	    if (wmgr_iswindowopen(tool->tl_windowfd))
X		win_setrect(msg_sw->ts_windowfd, &msg_rect);
X	    else 
X		win_setsavedrect(msg_sw->ts_windowfd, &msg_rect);
X	    }
X
X	if (wmgr_iswindowopen(tool->tl_windowfd) )
X	    win_getrect(canvas_sw->ts_windowfd, &canvas_rect);
X	else 
X	    win_getsavedrect(canvas_sw->ts_windowfd, &canvas_rect);
X	if (canvas_rect.r_top != CANVAS_TOP || 
X		canvas_rect.r_left != CANVAS_LEFT ||
X		canvas_rect.r_width != CANVAS_WIDTH || 
X		canvas_rect.r_height != CANVAS_HEIGHT) {
X	    canvas_rect.r_top = CANVAS_TOP;
X	    canvas_rect.r_left = CANVAS_LEFT;
X	    canvas_rect.r_width = CANVAS_WIDTH;
X	    canvas_rect.r_height = CANVAS_HEIGHT;
X	    if (wmgr_iswindowopen(tool->tl_windowfd))
X		win_setrect(canvas_sw->ts_windowfd, &canvas_rect);
X	    else 
X		win_setsavedrect(canvas_sw->ts_windowfd, &canvas_rect);
X	    }
X
X	if (wmgr_iswindowopen(tool->tl_windowfd) )
X	    win_getrect(topruler_sw->ts_windowfd, &topruler_rect);
X	else 
X	    win_getsavedrect(topruler_sw->ts_windowfd, &topruler_rect);
X	if (topruler_rect.r_top != TOPRULER_TOP || 
X		topruler_rect.r_left != TOPRULER_LEFT ||
X		topruler_rect.r_width != CANVAS_WIDTH || 
X		topruler_rect.r_height != RULER_WIDTH) {
X	    topruler_rect.r_top = TOPRULER_TOP;
X	    topruler_rect.r_left = TOPRULER_LEFT;
X	    topruler_rect.r_width = TOPRULER_WIDTH;
X	    topruler_rect.r_height = TOPRULER_HEIGHT;
X	    if (wmgr_iswindowopen(tool->tl_windowfd))
X		win_setrect(topruler_sw->ts_windowfd, &topruler_rect);
X	    else 
X		win_setsavedrect(topruler_sw->ts_windowfd, &topruler_rect);
X	    }
X
X	if (wmgr_iswindowopen(tool->tl_windowfd) )
X	    win_getrect(sideruler_sw->ts_windowfd, &sideruler_rect);
X	else 
X	    win_getsavedrect(sideruler_sw->ts_windowfd, &sideruler_rect);
X	if (sideruler_rect.r_top != SIDERULER_TOP || 
X		sideruler_rect.r_left != SIDERULER_LEFT ||
X		sideruler_rect.r_width != RULER_WIDTH || 
X		sideruler_rect.r_height != SIDERULER_HEIGHT) {
X	    sideruler_rect.r_top = SIDERULER_TOP;
X	    sideruler_rect.r_left = SIDERULER_LEFT;
X	    sideruler_rect.r_width = SIDERULER_WIDTH;
X	    sideruler_rect.r_height = SIDERULER_HEIGHT;
X	    if (wmgr_iswindowopen(tool->tl_windowfd))
X		win_setrect(sideruler_sw->ts_windowfd, &sideruler_rect);
X	    else 
X		win_setsavedrect(sideruler_sw->ts_windowfd, &sideruler_rect);
X	    }
X	}
X*/
END_OF_main.c
if test 14448 -ne `wc -c <main.c`; then
    echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f read.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"read.c\"
else
echo shar: Extracting \"read.c\" \(14208 characters\)
sed "s/^X//" >read.c <<'END_OF_read.c'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985, 1988 by Supoj Sutanthavibul (supoj@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 "alloc.h"
X#include "object.h"
X
Xextern F_arrow		*make_arrow();
Xextern char		*calloc();
Xextern int errno;
X
Xstatic F_ellipse	*read_ellipseobject();
Xstatic F_line		*read_lineobject();
Xstatic F_text		*read_textobject();
Xstatic F_spline		*read_splineobject();
Xstatic F_arc		*read_arcobject();
Xstatic F_compound	*read_compoundobject();
X
X#define			BUF_SIZE		1024
X
Xchar			buf[BUF_SIZE];
Xint			line_no = 0;
Xint			num_object;
X
Xread_fail_message(file, err)
Xchar	*file;
Xint	err;
X{
X	extern char	*sys_errlist[];
X
X	if (err == 0)		/* Successful read */
X	    return;
X	else if (err == ENAMETOOLONG)
X	    put_msg("File name \"%s\" is too long", file);
X	else if (err == ENOENT)
X	    put_msg("File \"%s\" does not exist", file);
X	else if (err == ENOTDIR)
X	    put_msg("A name in the path \"%s\" is not a directory", file);
X	else if (err == EACCES)
X	    put_msg("Read access to file \"%s\" is blocked", file);
X	else if (err == EISDIR)
X	    put_msg("File \"%s\" is a directory", file);
X	else if (err == -2) {
X	    put_msg("File \"%s\" is empty", file);
X	    }
X	else if (err == -1) {
X	    /* Format error; relevant error message is already delivered */
X	    }
X	else
X	    put_msg("File \"%s\" is not accessable; %s", file, sys_errlist[err]);
X	}
X
X/**********************************************************
XRead_fig returns :
X
X     0 : successful read.
X    -1 : File is in incorrect format
X    -2 : File is empty
Xerr_no : if file can not be read for various reasons
X
XThe resolution (ppi) and the cooridnate system (coord_sys) are
Xstored in obj->nwcorner.x and obj->nwcorner.x respectively.
X**********************************************************/
X
Xread_fig(file_name, obj)
Xchar		*file_name;
XF_compound	*obj;
X{
X	FILE	*fp;
X
X	if ((fp = fopen(file_name, "r")) == NULL)
X	    return(errno);
X	else
X	    return(readfp_fig(fp, obj));
X	}
X
Xreadfp_fig(fp, obj)
XFILE  *fp;
XF_compound    *obj;
X{
X        char            c;
X        int             status;
X  
X	num_object = 0;
X	c = fgetc(fp);
X	if (feof(fp)) return(-2);
X	ungetc(c, fp);
X	bzero((char*)obj, COMOBJ_SIZE);
X	if (c == '#')
X	    status = read_objects(fp, obj);
X	else
X	    status = read_1_3_objects(fp, obj);
X	fclose(fp);
X	return(status);
X        }
X	
Xint
Xread_objects(fp, obj)
XFILE		*fp;
XF_compound	*obj;
X{
X	F_ellipse	*e, *le = NULL;
X	F_line		*l, *ll = NULL;
X	F_text		*t, *lt = NULL;
X	F_spline	*s, *ls = NULL;
X	F_arc		*a, *la = NULL;
X	F_compound	*c, *lc = NULL;
X	int		object, ppi, coord_sys;
X
X	fgets(buf, BUF_SIZE, fp);	/* get the line "#FIG 1.4" */
X	line_no++;
X	if (get_line(fp) < 0) {
X	    put_msg("File is truncated");
X	    return(-1);
X	    }
X	if (2 != sscanf(buf,"%d%d\n", &ppi, &coord_sys)) {
X	    put_msg("Incomplete data at line %d", line_no);
X	    return(-1);
X	    }
X
X	obj->nwcorner.x = ppi;
X	obj->nwcorner.y = coord_sys;
X	while (get_line(fp) > 0) {
X	    if (1 != sscanf(buf, "%d", &object)) {
X		put_msg("Incorrect format at line %d", line_no);
X		return(-1);
X		}
X	    switch (object) {
X		case O_POLYLINE :
X		    if ((l = read_lineobject(fp)) == NULL) return(-1);
X		    if (ll)
X			ll = (ll->next = l);
X		    else 
X			ll = obj->lines = l;
X		    num_object++;
X		    break;
X		case O_SPLINE :
X		    if ((s = read_splineobject(fp)) == NULL) return(-1);
X		    if (ls)
X			ls = (ls->next = s);
X		    else 
X			ls = obj->splines = s;
X		    num_object++;
X		    break;
X		case O_ELLIPSE :
X		    if ((e = read_ellipseobject()) == NULL) return(-1);
X		    if (le)
X			le = (le->next = e);
X		    else 
X			le = obj->ellipses = e;
X		    num_object++;
X		    break;
X		case O_ARC :
X		    if ((a = read_arcobject(fp)) == NULL) return(-1);
X		    if (la)
X			la = (la->next = a);
X		    else 
X			la = obj->arcs = a;
X		    num_object++;
X		    break;
X		case O_TEXT :
X		    if ((t = read_textobject()) == NULL) return(-1);
X		    if (lt)
X			lt = (lt->next = t);
X		    else 
X			lt = obj->texts = t;
X		    num_object++;
X		    break;
X		case O_COMPOUND :
X		    if ((c = read_compoundobject(fp)) == NULL) return(-1);
X		    if (lc)
X			lc = (lc->next = c);
X		    else 
X			lc = obj->compounds = c;
X		    num_object++;
X		    break;
X		default :
X		    put_msg("Incorrect object code at line %d", line_no);
X		    return(-1);
X		} /*  switch */
X	    } /*  while */
X	if (feof(fp))
X	    return(0);
X	else
X	    return(errno);
X	} /*  read_objects */
X
Xstatic F_arc *
Xread_arcobject(fp)
XFILE	*fp;
X{
X	F_arc	*a;
X	int	n, fa, ba;
X	int	type, style;
X	float	thickness, wid, ht;
X
X	if (NULL == (Arc_malloc(a))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	a->pen = NULL;
X	a->area_fill = NULL;
X	a->next = NULL;
X	n = sscanf(buf, "%*d%d%d%d%d%d%*d%*d%f%d%d%d%f%f%d%d%d%d%d%d\n",
X		&a->type, &a->style, &a->thickness, 
X		&a->color, &a->depth, /* skip pen and area_fill */
X		&a->style_val, &a->direction, &fa, &ba,
X		&a->center.x, &a->center.y, 
X		&a->point[0].x, &a->point[0].y, 
X		&a->point[1].x, &a->point[1].y, 
X		&a->point[2].x, &a->point[2].y);
X	if (n != 17) {
X	    put_msg(Err_incomp, "arc", line_no);
X	    free((char*)a);
X	    return(NULL);
X	    }
X
X	skip_comment(fp);
X	if (fa) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "arc", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    a->for_arrow = make_arrow(type, style, thickness, wid, ht);
X	    skip_comment(fp);
X	    }
X	skip_comment(fp);
X	if (ba) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "arc", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    a->back_arrow = make_arrow(type, style, thickness, wid, ht);
X	    }
X	return(a);
X	}
X
Xstatic F_compound *
Xread_compoundobject(fp)
XFILE	*fp;
X{
X	F_arc		*a, *la = NULL;
X	F_ellipse	*e, *le = NULL;
X	F_line		*l, *ll = NULL;
X	F_spline	*s, *ls = NULL;
X	F_text		*t, *lt = NULL;
X	F_compound	*com, *c, *lc = NULL;
X	int		n, object;
X
X	Compound_malloc(com);
X	com->arcs = NULL;
X	com->ellipses = NULL;
X	com->lines = NULL;
X	com->splines = NULL;
X	com->texts = NULL;
X	com->compounds = NULL;
X	com->next = NULL;
X	n = sscanf(buf, "%*d%d%d%d%d\n", &com->nwcorner.x, &com->nwcorner.y,
X		&com->secorner.x, &com->secorner.y);
X	if (4 != n) {
X	    put_msg(Err_incomp, "compound", line_no);
X	    free((char*)com);
X	    return(NULL);
X	    }
X	while (get_line(fp) > 0) {
X	    if (1 != sscanf(buf, "%d", &object)) {
X		put_msg(Err_incomp, "compound", line_no);
X		free_compound(&com);
X		return(NULL);
X		}
X	    switch (object) {
X		case O_POLYLINE :
X		    if ((l = read_lineobject(fp)) == NULL) { 
X			free_line(&l);
X			return(NULL);
X			}
X		    if (ll)
X			ll = (ll->next = l);
X		    else 
X			ll = com->lines = l;
X		    break;
X		case O_SPLINE :
X		    if ((s = read_splineobject(fp)) == NULL) { 
X			free_spline(&s);
X			return(NULL);
X			}
X		    if (ls)
X			ls = (ls->next = s);
X		    else 
X			ls = com->splines = s;
X		    break;
X		case O_ELLIPSE :
X		    if ((e = read_ellipseobject()) == NULL) { 
X			free_ellipse(&e);
X			return(NULL);
X			}
X		    if (le)
X			le = (le->next = e);
X		    else 
X			le = com->ellipses = e;
X		    break;
X		case O_ARC :
X		    if ((a = read_arcobject(fp)) == NULL) { 
X			free_arc(&a);
X			return(NULL);
X			}
X		    if (la)
X			la = (la->next = a);
X		    else 
X			la = com->arcs = a;
X		    break;
X		case O_TEXT :
X		    if ((t = read_textobject()) == NULL) { 
X			free_text(&t);
X			return(NULL);
X			}
X		    if (lt)
X			lt = (lt->next = t);
X		    else 
X			lt = com->texts = t;
X		    break;
X		case O_COMPOUND :
X		    if ((c = read_compoundobject(fp)) == NULL) { 
X			free_compound(&c);
X			return(NULL);
X			}
X		    if (lc)
X			lc = (lc->next = c);
X		    else 
X			lc = com->compounds = c;
X		    break;
X		case O_END_COMPOUND :
X		    return(com);
X		default :
X		    put_msg("Wrong object code at line %d", line_no);
X		    return(NULL);
X		} /*  switch */
X	    }
X	if (feof(fp))
X	    return(com);
X	else
X	    return(NULL);
X	}
X
Xstatic F_ellipse *
Xread_ellipseobject()
X{
X	F_ellipse	*e;
X	int		n, pen, fill;
X
X	Ellipse_malloc(e);
X	e->area_fill = NULL;
X	e->pen = NULL;
X	e->next = NULL;
X	n = sscanf(buf, "%*d%d%d%d%d%d%d%d%f%d%f%d%d%d%d%d%d%d%d\n",
X		&e->type, &e->style, &e->thickness,
X		&e->color, &e->depth, &pen, &fill,
X		&e->style_val, &e->direction, &e->angle,
X		&e->center.x, &e->center.y, 
X		&e->radiuses.x, &e->radiuses.y, 
X		&e->start.x, &e->start.y, 
X		&e->end.x, &e->end.y);
X	if (n != 18) {
X	    put_msg(Err_incomp, "ellipse", line_no);
X	    free((char*)e);
X	    return(NULL);
X	    }
X	return(e);
X	}
X
Xstatic F_line *
Xread_lineobject(fp)
XFILE	*fp;
X{
X	F_line	*l;
X	F_point	*p, *q;
X	int	n, x, y, pen, fill, fa, ba;
X	int	type, style;
X	float	thickness, wid, ht;
X
X	Line_malloc(l);
X	l->points = NULL;
X	l->pen = NULL;
X	l->area_fill = NULL;
X	l->for_arrow = NULL;
X	l->back_arrow = NULL;
X	l->next = NULL;
X
X	n = sscanf(buf, "%*d%d%d%d%d%d%d%d%f%d%d%d%d",
X		&l->type, &l->style, &l->thickness, &l->color,
X		&l->depth, &pen, &fill, &l->style_val, &fa, &ba);
X	if (n != 10) {
X	    put_msg(Err_incomp, "line", line_no);
X	    free((char*)l);
X	    return(NULL);
X	    }
X	skip_comment(fp);
X	if (fa) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "line", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    l->for_arrow = make_arrow(type, style, thickness, wid, ht);
X	    skip_comment(fp);
X	    }
X	if (ba) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "line", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    l->back_arrow = make_arrow(type, style, thickness, wid, ht);
X	    skip_comment(fp);
X	    }
X
X	if (NULL == (l->points = Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    return(NULL);
X	    }
X	if (fscanf(fp, "%d%d", &p->x, &p->y) != 2) {
X	    put_msg(Err_incomp, "line", line_no);
X	    free_linestorage(l);
X	    return(NULL);
X	    }
X	for (;;) {
X	    if (fscanf(fp, "%d%d", &x, &y) != 2) {
X		put_msg(Err_incomp, "line", line_no);
X		free_linestorage(l);
X		return(NULL);
X		}
X	    if (x == 9999) break;
X	    if (NULL == (Point_malloc(q))) {
X		put_msg(Err_mem);
X		free_linestorage(l);
X		return(NULL);
X		}
X	    q->x = x;
X	    q->y = y;
X	    q->next = NULL;
X	    p->next = q;
X	    p = q;
X	    }
X	skip_line(fp);
X	return(l);
X	}
X
Xstatic F_spline *
Xread_splineobject(fp)
XFILE	*fp;
X{
X	F_spline	*s;
X	F_point		*p, *q;
X	F_control	*cp, *cq;
X	int		c, n, x, y, pen, fill, fa, ba;
X	int		type, style;
X	float		thickness, wid, ht;
X	float		lx, ly, rx, ry;
X
X	Spline_malloc(s);
X	s->points = NULL;
X	s->controls = NULL;
X	s->pen = NULL;
X	s->area_fill = NULL;
X	s->for_arrow = NULL;
X	s->back_arrow = NULL;
X	s->next = NULL;
X
X	n = sscanf(buf, "%*d%d%d%d%d%d%d%d%f%d%d%d%d%d%d", 
X	    	&s->type, &s->style, &s->thickness, &s->color,
X		&s->depth, &pen, &fill, &s->style_val, &fa, &ba);
X	if (n != 10) {
X	    put_msg(Err_incomp, "spline", line_no);
X	    free((char*)s);
X	    return(NULL);
X	    }
X	skip_comment(fp);
X	if (fa) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "spline", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    s->for_arrow = make_arrow(type, style, thickness, wid, ht);
X	    skip_comment(fp);
X	    }
X	if (ba) {
X	    line_no++;
X	    if (5 != fscanf(fp, "%d%d%f%f%f", &type, &style, &thickness, &wid, &ht)) {
X		fprintf(stderr, Err_incomp, "spline", line_no);
X		return(NULL);
X		}
X	    skip_line(fp);
X	    s->back_arrow = make_arrow(type, style, thickness, wid, ht);
X	    skip_comment(fp);
X	    }
X
X	/* Read points */
X	if ((n = fscanf(fp, "%d%d", &x, &y)) != 2) {
X	    put_msg(Err_incomp, "spline", line_no);
X	    free_splinestorage(s);
X	    return(NULL);
X	    };
X	if (NULL == (s->points = Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    free_splinestorage(s);
X	    return(NULL);
X	    }
X	p->x = x; p->y = y;
X	for (c = 1;;) {
X	    if (fscanf(fp, "%d%d", &x, &y) != 2) {
X		put_msg(Err_incomp, "spline", line_no);
X		p->next = NULL;
X		free_splinestorage(s);
X		return(NULL);
X		};
X	    if (x == 9999) break;
X	    if (NULL == (Point_malloc(q))) {
X		put_msg(Err_mem);
X		free_splinestorage(s);
X		return(NULL);
X		}
X	    q->x = x;
X	    q->y = y;
X	    p->next = q;
X	    p = q;
X	    c++;
X	    }
X	p->next = NULL;
X	skip_line(fp);
X
X	if (normal_spline(s)) return(s);
X
X	skip_comment(fp);
X	/* Read controls */
X	if ((n = fscanf(fp, "%f%f%f%f", &lx, &ly, &rx, &ry)) != 4) {
X	    put_msg(Err_incomp, "spline", line_no);
X	    free_splinestorage(s);
X	    return(NULL);
X	    };
X	if (NULL == (s->controls = Control_malloc(cp))) {
X	    put_msg(Err_mem);
X	    free_splinestorage(s);
X	    return(NULL);
X	    }
X	cp->lx = lx; cp->ly = ly;
X	cp->rx = rx; cp->ry = ry;
X	while (--c) {
X	    if (fscanf(fp, "%f%f%f%f", &lx, &ly, &rx, &ry) != 4) {
X		put_msg(Err_incomp, "spline", line_no);
X		cp->next = NULL;
X		free_splinestorage(s);
X		return(NULL);
X		};
X	    if (NULL == (Control_malloc(cq))) {
X		put_msg(Err_mem);
X		cp->next = NULL;
X		free_splinestorage(s);
X		return(NULL);
X		}
X	    cq->lx = lx; cq->ly = ly;
X	    cq->rx = rx; cq->ry = ry;
X	    cp->next = cq;
X	    cp = cq;
X	    }
X	cp->next = NULL;
X
X	skip_line(fp);
X	return(s);
X	}
X
Xstatic F_text *
Xread_textobject()
X{
X	F_text	*t;
X	int	n, pen;
X	char	s[BUF_SIZE];
X
X	Text_malloc(t);
X	t->next = NULL;
X	n = sscanf(buf,"%*d%d%d%d%d%d%d%f%d%d%d%d%d %[^\1]",
X		&t->font, &t->type, &t->size, &pen,
X		&t->color, &t->depth, &t->angle,
X		&t->style, &t->height, &t->length, 
X		&t->base_x, &t->base_y, s);
X	if (n != 13) {
X	    put_msg(Err_incomp, "text", line_no);
X	    free((char*)t);
X	    return(NULL);
X	    }
X	t->cstring = (char*)calloc((unsigned)(strlen(s)+1), sizeof(char));
X	if (NULL == t->cstring) {
X	    put_msg(Err_mem);
X	    free((char*)t);
X	    return(NULL);
X	    }
X	strcpy(t->cstring, s);
X	return(t);
X	}
X
Xget_line(fp)
XFILE	*fp;
X{
X	while (1) {
X	    if (NULL == fgets(buf, BUF_SIZE, fp)) {
X		return(-1);
X		}
X	    line_no++;
X	    if (*buf != '#') return(1);		/* Skip comment lines */
X	    }
X	}
X
Xskip_comment(fp)
XFILE	*fp;
X{
X	char c;
X
X	while ((c = fgetc(fp)) == '#') skip_line(fp);
X	if (c != '#') ungetc(c, fp);
X	}
X
Xskip_line(fp)
XFILE	*fp;
X{
X	while (fgetc(fp) != '\n') {
X	    if (feof(fp)) return;
X	    }
X	}
END_OF_read.c
if test 14208 -ne `wc -c <read.c`; then
    echo shar: \"read.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f ruler.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"ruler.c\"
else
echo shar: Extracting \"ruler.c\" \(14178 characters\)
sed "s/^X//" >ruler.c <<'END_OF_ruler.c'
X/* 
X *	FIG : Facility for Interactive Generation of figures
X *
X *	Copyright (c) 1985 by Supoj Sutanthavibul (supoj@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 "const.h"
X#include "font.h"
X#include "paintop.h"
X
X#define			INCH_MARK		12
X#define			HALF_MARK		11
X#define			QUARTER_MARK		8
X#define			SIXTEENTH_MARK		6
X
X#define			MARK_HT			5
X#define			TRM_WID			15
X#define			TRM_HT			8
X#define			SRM_WID			8
X#define			SRM_HT			15
X
Xextern int		CANVAS_HEIGHT, CANVAS_WIDTH;
Xextern int		SIDERULER_WIDTH, SIDERULER_HEIGHT;
Xextern int		TOPRULER_WIDTH, TOPRULER_HEIGHT;
Xextern int		SIDERULER_HEIGHT, SIDERULER_START;
Xextern int		TOPRULER_LEFT, TOPRULER_TOP;
Xextern			null_proc();
Xextern int		RHS_PANEL;
X
Xstatic			lasty = -100;
Xstatic			lastx = -100;
Xstatic int	 	start;
Xstatic char		*number[] = {"0", "1", "2", "3", "4", "5", 
X					"6", "7", "8", "9", "10", "11" };
Xstatic int		troffx = -7, troffy = -10;
Xstatic short		tr_marker_image[8] = {
X				0xFFFE,	/* *************** */
X				0x7FFC,	/*  *************  */
X				0x3FF8,	/*   ***********   */
X				0x1FF0,	/*    *********    */
X				0x0FE0,	/*     *******     */
X				0x07C0,	/*      *****      */
X				0x0380,	/*       ***       */
X				0x0100	/*        *        */
X				};
Xstatic			mpr_static(trm_pr, TRM_WID, TRM_HT, 1, tr_marker_image);
Xstatic int		srroffx = 2, srroffy = -7;
Xstatic short		srr_marker_image[15] = {
X				0x0100,	/*          *  */
X				0x0300,	/*         **  */
X				0x0700,	/*        ***  */
X				0x0F00,	/*       ****  */
X				0x1F00,	/*      *****  */
X				0x3F00,	/*     ******  */
X				0x7F00,	/*    *******  */
X				0xFF00, /*   ********  */
X				0x7F00,	/*    *******  */
X				0x3F00,	/*     ******  */
X				0x1F00,	/*      *****  */
X				0x0F00,	/*       ****  */
X				0x0700,	/*        ***  */
X				0x0300,	/*         **  */
X				0x0100	/*          *  */
X				};
X#ifndef	X11
Xstatic		mpr_static(srrm_pr, SRM_WID, SRM_HT, 1, srr_marker_image);
X#else
Xstatic		mpr_static(srrm_pr, 16, SRM_HT, 1, srr_marker_image);
X#endif
X
Xstatic int		srloffx = -10, srloffy = -7;
Xstatic short		srl_marker_image[15] = {
X				0x8000,	/*  *          */
X				0xC000,	/*  **         */
X				0xE000,	/*  ***        */
X				0xF000,	/*  ****       */
X				0xF800,	/*  *****      */
X				0xFC00,	/*  ******     */
X				0xFE00,	/*  *******    */
X				0xFF00,	/*  ********   */
X				0xFE00,	/*  *******    */
X				0xFC00,	/*  ******     */
X				0xF800,	/*  *****      */
X				0xF000,	/*  ****       */
X				0xE000,	/*  ***        */
X				0xC000,	/*  **         */
X				0x8000	/*  *          */
X				};
X#ifndef	X11
Xstatic		mpr_static(srlm_pr, SRM_WID, SRM_HT, 1, srl_marker_image);
X#else
Xstatic		mpr_static(srlm_pr, 16, SRM_HT, 1, srl_marker_image);
X#endif
X
X#ifdef	X11
Xstatic Pixmap		toparrow_pm, sidearrow_pm;
X#endif
X
Xset_toprulermark(x)
Xint	x;
X{
X#ifndef	X11
X	pw_write(topruler_pixwin, lastx + troffx, RULER_WIDTH + troffy, 
X		TRM_WID, TRM_HT, INV_PAINT, &trm_pr, 0, 0);
X	pw_write(topruler_pixwin, x + troffx, RULER_WIDTH + troffy, 
X		TRM_WID, TRM_HT, INV_PAINT, &trm_pr, 0, 0);
X#else
X	XCopyArea(tool_d, toparrow_pm, topruler_pixwin, gccache[INV_PAINT],
X		0, 0, trm_pr.width, trm_pr.height,
X		lastx + troffx, TOPRULER_HEIGHT + troffy);
X	XCopyArea(tool_d, toparrow_pm, topruler_pixwin, gccache[INV_PAINT],
X		0, 0, trm_pr.width, trm_pr.height,
X		x + troffx, TOPRULER_HEIGHT + troffy);
X#endif	X11
X	lastx = x;
X	}
X
X#ifndef	X11
Xstatic
Xsideruler_sighandler()
X{
X	pw_damaged(sideruler_pixwin);
X	pw_repairretained(sideruler_pixwin);
X	pw_donedamaged(sideruler_pixwin);
X	}
X
Xstatic
Xflush_input(nullsw, ibits, obits, ebits, timer)
Xcaddr_t		nullsw;
Xint		*ibits, *obits, *ebits;
Xstruct timeval	*timer;
X{
X	INPUTEVENT		ie;
X
X	(void)input_readevent(srswfd, &ie);
X	*ibits = *obits = *ebits = 0;
X	}
X
X
Xint
Xinit_sideruler(tool)
XTOOL		tool;
X{
X	INPUTMASK		mask;
X
X	sideruler_sw = tool_createsubwindow(tool, "side ruler", 
X				SIDERULER_WIDTH, SIDERULER_HEIGHT);
X	if (sideruler_sw == (TOOLSW)0) return(0);
X	(int) sideruler_sw->ts_data = srswfd = sideruler_sw->ts_windowfd;
X
X	sideruler_pixwin = pw_open(srswfd);
X	sideruler_pixwin->pw_prretained = mem_create(SIDERULER_WIDTH, 
X						SIDERULER_HEIGHT, 1);
X	input_imnull(&mask);
X	win_setinputcodebit(&mask, MS_RIGHT);
X	/* Pass input events other than right mouse to parent window */
X	win_setinputmask(srswfd, &mask, NULL, WIN_NULLLINK);
X	win_setcursor(srswfd, &bull_cursor);
X	sideruler_sw->ts_io.tio_selected = flush_input;
X	sideruler_sw->ts_io.tio_handlesigwinch = sideruler_sighandler;
X	sideruler_sw->ts_destroy = null_proc;
X
X	show_sideruler();
X	return(1);
X	}
X#else
Xstatic Arg	ruler_args[] =
X{
X	{ XtNx, (XtArgVal)0 },
X	{ XtNy, (XtArgVal)0 },
X	{ XtNwidth, (XtArgVal)0 },
X	{ XtNheight, (XtArgVal)0 },
X	{ XtNlabel, (XtArgVal)"" },
X	{ XtNfromHoriz, (XtArgVal)NULL },
X	{ XtNhorizDistance, (XtArgVal)0 },
X	{ XtNfromVert, (XtArgVal)NULL },
X	{ XtNvertDistance, (XtArgVal)0 },
X};
X
Xextern int	SIDERULER_WIDTH, SIDERULER_HEIGHT;
Xextern int	TOPRULER_WIDTH, TOPRULER_HEIGHT;
X
Xint init_sideruler(tool)
X	TOOL		tool;
X{
X	ruler_args[2].value = SIDERULER_WIDTH = RULER_WIDTH;
X	ruler_args[3].value = SIDERULER_HEIGHT = CANVAS_HEIGHT;
X	ruler_args[5].value = (XtArgVal)canvas_sw;
X	ruler_args[7].value = (XtArgVal)topruler_sw;
X	sideruler_sw = XtCreateWidget("sruler", labelWidgetClass, tool,
X		ruler_args, XtNumber(ruler_args));
X	return(1);
X}
X
Xsetup_rulers()
X{
X	register int		i, j;
X	register Pixmap		p;
X#define	QINCH	(PIX_PER_INCH / 4)
X#define	SINCH	(PIX_PER_INCH / 16)
X	char			number[3];
X	static Arg		ruler_args[] =
X	{
X		{ XtNbackgroundPixmap, (XtArgVal)NULL },
X	};
X
X	topruler_pixwin = trswfd = XtWindow(topruler_sw);
X	sideruler_pixwin = srswfd = XtWindow(sideruler_sw);
X	XDefineCursor(tool_d, trswfd, (Cursor)bull_cursor.bitmap);
X	XDefineCursor(tool_d, srswfd, (Cursor)bull_cursor.bitmap);
X
X	/* top ruler, adjustments for digits are kludges based on 6x13 char */
X	p = XCreatePixmap(tool_d, topruler_pixwin,
X		TOPRULER_WIDTH, TOPRULER_HEIGHT, 1);
X	for (i = SINCH - 1; i <= TOPRULER_WIDTH; i += SINCH)
X	{
X		j = i + 1;
X		if (j % PIX_PER_INCH == 0)
X		{
X			XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
X				TOPRULER_HEIGHT - INCH_MARK - 1);
X			sprintf(number, "%d", j / PIX_PER_INCH);
X			XDrawString(tool_d, p, gc, i - 2,
X				TOPRULER_HEIGHT - INCH_MARK - 3, number,
X				j < PIX_PER_INCH * 10 ? 1 : 2);
X		}
X		else if (j % QINCH == 0)
X			XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
X				TOPRULER_HEIGHT - QUARTER_MARK - 1);
X		else if (j % SINCH == 0)
X			XDrawLine(tool_d, p, gc, i, TOPRULER_HEIGHT - 1, i,
X				TOPRULER_HEIGHT - SIXTEENTH_MARK - 1);
X	}
X	ruler_args[0].value = (XtArgVal)p;
X	XtSetValues(topruler_sw, ruler_args, 1);
X
X	/* side ruler, adjustments for digits are kludges based on 6x13 char */
X	p = XCreatePixmap(tool_d, sideruler_pixwin,
X		SIDERULER_WIDTH, SIDERULER_HEIGHT, 1);
X	if( RHS_PANEL )
X	{
X		for (i = SINCH - 1; i <= SIDERULER_HEIGHT; i += SINCH)
X		{
X			j = i + 1;
X			if (j % PIX_PER_INCH == 0)
X			{
X				XDrawLine(tool_d, p, gc, RULER_WIDTH-INCH_MARK,
X					  i, RULER_WIDTH, i);
X				sprintf(number, "%d", j / PIX_PER_INCH);
X				XDrawString(tool_d, p, gc,
X					    RULER_WIDTH-INCH_MARK - 8, i + 3,
X					    number, j < PIX_PER_INCH * 10 ? 1 : 2);
X			}
X			else if (j % QINCH == 0)
X				XDrawLine(tool_d, p, gc,
X					  RULER_WIDTH-QUARTER_MARK, i,
X					  RULER_WIDTH, i);
X			else if (j % SINCH == 0)
X				XDrawLine(tool_d, p, gc,
X					  RULER_WIDTH-SIXTEENTH_MARK, i,
X					  RULER_WIDTH, i);
X		}
X	}
X	else
X	{
X		for (i = SINCH - 1; i <= SIDERULER_HEIGHT; i += SINCH)
X		{
X			j = i + 1;
X			if (j % PIX_PER_INCH == 0)
X			{
X				XDrawLine(tool_d, p, gc, 0, i,
X					  INCH_MARK - 1, i);
X				sprintf(number, "%d", j / PIX_PER_INCH);
X				XDrawString(tool_d, p, gc, INCH_MARK + 3,
X					    i + 3, number,
X					    j < PIX_PER_INCH * 10 ? 1 : 2);
X			}	
X			else if (j % QINCH == 0)
X				XDrawLine(tool_d, p, gc, 0, i,
X					  QUARTER_MARK - 1, i);
X			else if (j % SINCH == 0)
X				XDrawLine(tool_d, p, gc, 0, i,
X					  SIXTEENTH_MARK - 1, i);
X		}	
X	}
X	ruler_args[0].value = (XtArgVal)p;
X	XtSetValues(sideruler_sw, ruler_args, 1);
X
X	/* make pixmaps for ruler arrows */
X	toparrow_pm = XCreatePixmap(tool_d, topruler_pixwin, trm_pr.width,
X		trm_pr.height, trm_pr.depth);
X	XPutImage(tool_d, toparrow_pm, gc, &trm_pr, 0, 0, 0, 0,
X		trm_pr.width, trm_pr.height);
X	
X	if( RHS_PANEL )
X	{
X		sidearrow_pm = XCreatePixmap(tool_d, sideruler_pixwin, srlm_pr.width,
X					     srlm_pr.height, srlm_pr.depth);
X		XPutImage(tool_d, sidearrow_pm, gc, &srlm_pr, 0, 0, 0, 0,
X			  srlm_pr.width, srlm_pr.height);
X	}
X	else
X	{
X		sidearrow_pm = XCreatePixmap(tool_d, sideruler_pixwin, srrm_pr.width,
X					     srrm_pr.height, srrm_pr.depth);
X		XPutImage(tool_d, sidearrow_pm, gc, &srrm_pr, 0, 0, 0, 0,
X			  srrm_pr.width, srrm_pr.height);
X	}
X}
X#endif	X11
X
X#ifndef	X11
Xshow_sideruler()
X{
X	int	 i, qinch, sinch, charht, charx, end;
X	char	**d;
X
X	pw_writebackground(sideruler_pixwin, 0, 0, 2048, 2048, PAINT);
X	if (RHS_PANEL){
X	    start = RULER_WIDTH;
X	    charx = RULER_WIDTH - INCH_MARK - char_width(bold_font);
X	    }
X	else {
X	    start = 0;
X	    charx = INCH_MARK + 2;
X	    }
X
X	charht = char_height(bold_font);
X	for (d = number, i = SIDERULER_START + charht / 2 - 3;
X		i < SIDERULER_HEIGHT; 
X		d++, i += PIX_PER_INCH) {
X	    pw_text(sideruler_pixwin, charx, i, PAINT, bold_font, *d);
X	    }
X	qinch = PIX_PER_INCH / 4;
X	sinch = PIX_PER_INCH / 16;
X	/*  Draw Scale  */
X	end = abs(start - INCH_MARK);
X	for (i = SIDERULER_START - 1; i < SIDERULER_HEIGHT; i += PIX_PER_INCH) 
X	    pw_vector(sideruler_pixwin, start, i, end, i, PAINT, 1);
X	end = abs(start - HALF_MARK);
X	for (i = SIDERULER_START - 1 + PIX_PER_INCH / 2; 
X		i < SIDERULER_HEIGHT; i += PIX_PER_INCH)
X	    pw_vector(sideruler_pixwin, start, i, end, i, PAINT, 1);
X	end = abs(start - QUARTER_MARK);
X	for (i = SIDERULER_START - 1; i < SIDERULER_HEIGHT; i += qinch)
X	    pw_vector(sideruler_pixwin, start, i, end, i, PAINT, 1);
X	end = abs(start - SIXTEENTH_MARK);
X	for (i = SIDERULER_START - 1; i < SIDERULER_HEIGHT; i += sinch)
X	    pw_vector(sideruler_pixwin, start, i, end, i, PAINT, 1);
X	/*  Darw marker  */
X	if (RHS_PANEL) { /*  side ruler is on the LSH of canvas */
X	    pw_write(sideruler_pixwin, RULER_WIDTH+srloffx, lasty+srloffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srlm_pr, 0, 0);
X	    }
X	else { /*  side ruler is on the RSH of canvas */
X	    pw_write(sideruler_pixwin, srroffx, lasty+srroffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srrm_pr, 0, 0);
X	    }
X	}
X#endif	X11
X
X#ifndef	X11
Xstatic
Xtopruler_sighandler()
X{
X	pw_damaged(topruler_pixwin);
X	pw_repairretained(topruler_pixwin);
X	pw_donedamaged(topruler_pixwin);
X	}
X
Xint
Xinit_topruler(tool)
XTOOL		tool;
X{
X	INPUTMASK		mask;
X
X	topruler_sw = tool_createsubwindow(tool, "top ruler", 
X				TOPRULER_WIDTH, TOPRULER_HEIGHT);
X	if (topruler_sw == (TOOLSW)0) return(0);
X	(int) topruler_sw->ts_data = trswfd = topruler_sw->ts_windowfd;
X
X	topruler_pixwin = pw_open(trswfd);
X	topruler_pixwin->pw_prretained = mem_create(TOPRULER_WIDTH, 
X						TOPRULER_HEIGHT, 1);
X	topruler_sw->ts_io.tio_selected = flush_input;
X	input_imnull(&mask);
X	win_setinputcodebit(&mask, MS_RIGHT);
X	win_setinputmask(trswfd, &mask, NULL, WIN_NULLLINK);
X	win_setcursor(srswfd, &bull_cursor);
X	topruler_sw->ts_io.tio_handlesigwinch = topruler_sighandler;
X	topruler_sw->ts_destroy = null_proc;
X
X	show_topruler();
X	return(1);
X	}
X#else
Xint init_topruler(tool)
X	TOOL		tool;
X{
X	ruler_args[2].value = TOPRULER_WIDTH = CANVAS_WIDTH;;
X	ruler_args[3].value = TOPRULER_HEIGHT = RULER_WIDTH;
X	ruler_args[5].value = (XtArgVal)panel_sw;
X	topruler_sw = XtCreateWidget("truler", labelWidgetClass, tool,
X		ruler_args, XtNumber(ruler_args));
X	return(1);
X}
X#endif	X11
X
X#ifndef	X11
Xshow_topruler()
X{
X	int	 i, qinch, len, sinch, charwid;
X	char	**d;
X
X	pw_writebackground(topruler_pixwin, 0, 0, 2048, 2048, PAINT);
X
X	charwid = char_width(bold_font);
X	len = RULER_WIDTH - INCH_MARK;
X	for (d = number, d++, i = PIX_PER_INCH - charwid / 2; 
X		i < CANVAS_WIDTH; 
X		d++, i += PIX_PER_INCH) {
X	    pw_text(topruler_pixwin, i, len, PAINT, bold_font, *d);
X	    }
X	qinch = PIX_PER_INCH / 4;
X	sinch = PIX_PER_INCH / 16;
X	/*  Draw Scale  */
X	len = RULER_WIDTH - INCH_MARK;
X	for (i = -1; i < CANVAS_WIDTH; i += PIX_PER_INCH)
X	    pw_vector(topruler_pixwin, i, RULER_WIDTH, i, len, PAINT, 1);
X	len = RULER_WIDTH - HALF_MARK;
X	for (i = -1; i < CANVAS_WIDTH; i += PIX_PER_INCH)
X	    pw_vector(topruler_pixwin, i, RULER_WIDTH, i, len, PAINT, 1);
X	len = RULER_WIDTH - QUARTER_MARK;
X	for (i = -1; i < CANVAS_WIDTH; i += qinch)
X	    pw_vector(topruler_pixwin, i, RULER_WIDTH, i, len, PAINT, 1);
X	len = RULER_WIDTH - SIXTEENTH_MARK;
X	for (i = -1; i < CANVAS_WIDTH; i += sinch)
X	    pw_vector(topruler_pixwin, i, RULER_WIDTH, i, len, PAINT, 1);
X	/*  Darw marker  */
X	pw_write(topruler_pixwin, lastx + troffx, RULER_WIDTH + troffy, 
X		TRM_WID, TRM_HT, INV_PAINT, &trm_pr, 0, 0);
X	}
X#endif	X11
X
Xset_rulermark(x, y)
Xint	x, y;
X{
X	set_siderulermark(y);
X	set_toprulermark(x);
X	}
X
Xset_siderulermark(y)
Xint	y;
X{
X	int	sy;
X
X#ifndef	X11
X	sy = SIDERULER_START + y;
X	if (RHS_PANEL) { /*  side ruler is on the LSH of canvas */
X	    pw_write(sideruler_pixwin, RULER_WIDTH+srloffx, lasty+srloffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srlm_pr, 0, 0);
X	    pw_write(sideruler_pixwin, RULER_WIDTH+srloffx, sy+srloffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srlm_pr, 0, 0);
X	    }
X	else { /*  side ruler is on the RSH of canvas */
X	    pw_write(sideruler_pixwin, srroffx, lasty+srroffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srrm_pr, 0, 0);
X	    pw_write(sideruler_pixwin, srroffx, sy+srroffy, 
X			SRM_WID, SRM_HT, INV_PAINT, &srrm_pr, 0, 0);
X	    }
X	lasty = sy;
X#else
X	if( RHS_PANEL ) {
X		XCopyArea(tool_d, sidearrow_pm, sideruler_pixwin,
X			  gccache[INV_PAINT], 0, 0, srlm_pr.width,
X			  srlm_pr.height, RULER_WIDTH+srloffx, lasty + srloffy);
X		XCopyArea(tool_d, sidearrow_pm, sideruler_pixwin,
X			  gccache[INV_PAINT], 0, 0, srlm_pr.width,
X			  srlm_pr.height, RULER_WIDTH+srloffx, y + srloffy);
X	}
X	else
X	{
X		XCopyArea(tool_d, sidearrow_pm, sideruler_pixwin,
X			  gccache[INV_PAINT], 0, 0, srrm_pr.width,
X			  srrm_pr.height, -srroffx, lasty + srroffy);
X		XCopyArea(tool_d, sidearrow_pm, sideruler_pixwin,
X			  gccache[INV_PAINT], 0, 0, srrm_pr.width,
X			  srrm_pr.height, -srroffx, y + srroffy);
X	}
X	lasty = y;
X#endif	X11
X}
END_OF_ruler.c
if test 14178 -ne `wc -c <ruler.c`; then
    echo shar: \"ruler.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 8 \(of 11\).
cp /dev/null ark8isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 11 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
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330