envbvs@epb2.lbl.gov (Brian V. Smith) (07/04/90)
Submitted-by: envbvs@epb2.lbl.gov (Brian V. Smith) Posting-number: Volume 8, Issue 19 Archive-name: xfig2.8/part10 #! /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 10 (of 21)." # Contents: FORMAT1.4X ellipse.c glue.c main.c read1_3.c # Wrapped by envbvs@epb2.lbl.gov on Thu Jun 28 08:52:17 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'FORMAT1.4X' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'FORMAT1.4X'\" else echo shar: Extracting \"'FORMAT1.4X'\" \(9677 characters\) sed "s/^X//" >'FORMAT1.4X' <<'END_OF_FILE' XThe following is the format of fig output (fig 1.4X). X X(0) The only difference between 1.4 and 1.4X is that the interpretation X of the "pen" value in ARC_BOX is now the radius of the corners of the box. X Also, the ARC_BOX is sub-type 4 of POLYLINE. X X(1) The very first line is a comment line containing the name and version: X #FIG 1.4X X X The character # at the first column of a line indicates that the line X is a comment line which will be ignored. X X(2) The first non-comment line consists of two numbers : X X int fig_resolution (pixels/inch) X int coordinate_system (1 : origin is at the lower left corner X 2 : Upper left) X X Fig_resolution is the resolution fig is using for the current file. X It may not be the same as screen resolution (which can be higher or X lower). I assume that a pixel is square, therefore this number X represents drawing resolution in both direction. I've experimented X with fig automatically changing this number according to the resolution X of the monitor it is running on (The screen resolution, width and height X in pixels, not pixel/inch, can be done by doing a ioctl on the /dev/fb). X I've found that for monitors with higher resolution but same size X (19" diagonal), I preferred using the pixels for other things than X having fig occupying most of the screen. Thus I opted for a fixed X pixel-per-inch number which make fig window smaller on higher resolution X monitor (than the standard sun monitor). This however may change in X the future version. X X(3) The rest of the file contains various objects. An object can be one X of six classes (or types). X X i) Ellipse which is a generalization of circle. X ii) Polyline which includes polygon and box. X iii) Spline which includes closed/open control/interpolated spline. X iv) Text. X v) Arc. X vi) Compound object which is composed of one or more objects. X X In the following elaboration on object formats, every value of fig X output are separated by blank characters or new line ('\n'). The X value of the not-used parameters will be -1. X X A number of values are described as unused or not applicable to some X object even though they are defined for those objects. These value X will (hopefully) be used in the future version of fig. The intention X of their uses are the following. X X Value Usage X ----- ----- X area_fill The stipple pattern (which will be align) for X filling object internals. For example, an filled X arc will look like a piece of pie. X X** pen This will be a structure defining the shape of X pen used in drawing objects. It also includes X the the stipple pattern for line filling. X The default pen is a circular pen with black X filling. X X ** In 1.4X, pen is the radius (pixels) of the rounded-corner boxes. X X thickness Every pen has the thickness of one. X Thickness scales the size of a pen. X X depth This value adds a half dimension to fig. X It is useful when we have overlapping filled X objects and we want one to obliterate another. X An object can have only one depth (including X compound object). An object that is in less X depth can obscure the one with greater depth X if they overlap. X X style Only polyline (including polygon and box) can X be rendered with dashed line. However the X objects created when the dash-line mode was on X will be recorded as such. Currently the filter X f2ps (1) is able to render the desired line style X effect on hard copy. Three line styles are defined. X X 0 : SOLID_LINE X 1 : DASH_LINE X 2 : DOTTED_LINE X X style_val For dash style, it is the length of a dash. X For dotted line it indicates the approximated X gap of consecutive dots. X X (3.1) ELLIPSE X X First line : X type name (brief description) X ---- ---- ------------------- X int object_code (always 1) X int sub_type (1 : ellipse defined by radiuses X 2 : ellipse defined by diameters X 3 : circle defined by radius X 4 : circle defined by diameter) X int style (See the end of this section) X int thickness (pixels, not used) X int color (not used) X int depth (not used) X int pen (not used) X int area_fill (not used) X float style_val (pixels, not used) X int direction (always 1) X float angle (radian, the angle of the x-axis) X int center_x, center_y (pixels) X int radius_x, radius_y (pixels) X int start_x, start_y (pixels; the 1st point entered) X int end_x, end_y (pixels; the last point entered) X X (3.2) POLYLINE X X First line : X type name (brief description) X ---- ---- ------------------- X int object_code (always 2) X int sub_type (1 : polyline, 2 : box, X 3 : polygon, 4 : rounded-corner box) X int style (See the end of this section) X int thickness (pixels, not used) X int color (not used) X int depth (not used) X int pen **** (pixels, radius of rounded-corner boxes) X int area_fill (not used) X float style_val (pixels) X int forward_arrow (0: off, 1: on) X int backward_arrow (0: off, 1: on) X X Forward arrow line : same as ARC object X X Backward arrow line : same as ARC object X X Points line : X type name (brief description) X ---- ---- ------------------- X int x1, y1 (pixels) X int x2, y2 (pixels) X . X . X int xn, yn (this will be the same as the 1st X point for polygon and box) X int x, y (always 9999, 9999; marks the end of X point for polygon and box) X X (3.3) SPLINE X X First line : X type name (brief description) X ---- ---- ------------------- X int object_code (always 3) X int sub_type (0 : open spline X 1 : closed spline X 2 : open interpolated spline X 3 : closed interpolated spline) X int style (See the end of this section) X int thickness (pixels, not used) X int color (not used) X int depth (not used) X int pen (not used) X int area_fill (not used) X float style_val (pixels, not used) X int forward_arrow (0: off, 1: on) X int backward_arrow (0: off, 1: on) X X Forward arrow line : same as ARC object X X Backward arrow line : same as ARC object X X Points line : same as POLYLINE object X X Control points line (absent if sub_type is 1 or 2) : X Control points of interpolated spline. There are two control X points for each knots. A section i, of the spline is drawn X using Bezier cubic with the following four points: X (x ,y ), (rx ,ry ), (lx , ly ), (x , y ). X i i i i i+1 i+1 i+1 i+1 X For closed interpolated spline the last pair of control points, X (lxn,lyn) and (rxn,ryn) (which can be ignored), are the same as X (lx1,ly1) and (rx1,ry1) respectively. X X type name (brief description) X ---- ---- ------------------- X float lx1, ly1 (pixels) X float rx1, ry1 (pixels) X float lx2, ly2 (pixels) X float rx2, ry2 (pixels) X . X . X float lxn, lyn (pixels) X float rxn, ryn (pixels) X X (3.4) TEXT X type name (brief description) X ---- ---- ------------------- X int object (always 4) X int sub_type (0 : Left justified X 1 : Center justified X 2 : Right justified) X int font (font number 0-...) X int font_size (point size) X int pen (not used) X int color (not used) X int depth (not used) X int angle (radian, not used, the angle of the X the base line of the string) X int font_style (not used) X int height (pixels) X int length (pixels) X int x, y (pixels, coordinate of the origin X of the string. If sub_type = 0, it is X the lower left corner of the string. X If sub_type = 1, it is the lower X center. Otherwise it is the lower X right corner of the string.) X char string[] (ascii characters; starts after a blank X character following the last number and X ends before the character '\1'. This X character is not part of the string. X Note that the string may contain '\n'.) X (3.5) ARC X X First line : X type name (brief description) X ---- ---- ------------------- X int object_code (always 5) X int sub_type (always 1) X int style (See the end of this section) X int line_thickness (pixels, not used) X int color (not used) X int depth (not used) X int pen (not used) X int area_fill (not used) X float style_val (pixels, not used) X int direction (0 : clockwise, 1 : counterclockwise) X int forward_arrow (0: no forward arrow, 1: on) X int backward_arrow (0: no forward arrow, 1: on) X float center_x, center_y (center of the arc) X int x1, y1 (pixels, the 1st point the user entered) X int x2, y2 (pixels, the 2nd point) X int x3, y3 (pixels, the last point) X X Forward arrow line (Optional; absent if forward_arrow is 0) : X type name (brief description) X ---- ---- ------------------- X int arrow_type (not used) X int arrow_style (not used) X float arrow_thickness (not used) X float arrow_width (pixels) X float arrow_height (pixels) X X Backward arrow line (Optional; absent if backward_arrow is 0) : X type name (brief description) X ---- ---- ------------------- X int arrow_type (not used) X int arrow_style (not used) X float arrow_thickness (not used) X float arrow_width (pixels) X float arrow_height (pixels) X X (3.6) COMPOUND X X A line with object code 6 signifies the start of a compound. X There are four more numbers on this line which indicate the X upper right corner and the lower left corner of the bounding X box of this compound. A line with object code -6 signifies X the end of the compound. Compound may be nested. X X First line : X type name (brief description) X ---- ---- ------------------- X int object_code (always 6) X int upperright_corner_x (pixels) X int upperright_corner_y (pixels) X int lowerleft_corner_x (pixels) X int lowerleft_corner_y (pixels) X X Subsequent lines : X objects X . X . X X Last line : X -6 X END_OF_FILE if test 9677 -ne `wc -c <'FORMAT1.4X'`; then echo shar: \"'FORMAT1.4X'\" unpacked with wrong size! fi # end of 'FORMAT1.4X' fi if test -f 'ellipse.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ellipse.c'\" else echo shar: Extracting \"'ellipse.c'\" \(9796 characters\) sed "s/^X//" >'ellipse.c' <<'END_OF_FILE' 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 "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X Xextern int line_style, line_thickness; Xextern float cur_styleval; Xextern float cur_angle; Xextern int cur_color; Xextern int cur_areafill; Xextern int fill_mode; Xextern int fix_x, fix_y, cur_x, cur_y; 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 set_popupmenu(); X Xextern F_compound objects; X X/************************* local procedures ********************/ X Xextern int init_ellipsebyradius_drawing(); Xextern int init_ellipsebydiameter_drawing(); Xextern int init_circlebyradius_drawing(); Xextern int init_circlebydiameter_drawing(); Xextern int move_ebrbox(), move_ebdbox(); Xextern int move_cbrbox(), move_cbdbox(); Xextern int create_ellipsebydia(); Xextern int create_ellipsebyrad(); Xextern int create_circlebyrad(); Xextern int create_circlebydia(); X X#define round(z) (int)((z)+.5) X Xcenter_marker(x, y) Xint x, y; X{ X pw_vector(canvas_win, x, y-2, x, y+2, INV_PAINT, 1, SOLID_LINE, 0.0); X pw_vector(canvas_win, x-2, y, x+2, y, INV_PAINT, 1, SOLID_LINE, 0.0); X } X Xellipsebyradius_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_ellipsebyradius_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_ellipsebyradius_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_ebrbox; X canvas_leftbut_proc = canvas_rightbut_proc = null_proc; X canvas_middlebut_proc = create_ellipsebyrad; X set_temp_cursor(&null_cursor); X ellipsebyrad_box(INV_PAINT); X set_action_on(); X } X Xmove_ebrbox(x, y) Xint x, y; X{ X ellipsebyrad_box(INV_PAINT); X cur_x = x; X cur_y = y; X ellipsebyrad_box(INV_PAINT); X } X Xellipsebyrad_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int rx, ry; X X rx = cur_x - fix_x; X ry = cur_y - fix_y; X x1 = fix_x + rx; X x2 = fix_x - rx; X y1 = fix_y + ry; X y2 = fix_y - ry; X draw_rectbox(x1, y1, x2, y2, op); X } X Xcreate_ellipsebyrad(x, y) Xint x, y; X{ X F_ellipse *ellipse; X X ellipsebyrad_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(ellipse))) { X blink_msg(); X put_msg(Err_mem); X return; X } X ellipse->type = T_ELLIPSE_BY_RAD; X ellipse->style = line_style; X ellipse->thickness = line_thickness; X ellipse->style_val = cur_styleval; X ellipse->angle = cur_angle; X ellipse->color = cur_color; X ellipse->depth = 0; X ellipse->pen = 0; X ellipse->area_fill = fill_mode? cur_areafill : 0; X ellipse->direction = 1; X ellipse->center.x = fix_x; X ellipse->center.y = fix_y; X ellipse->radiuses.x = abs(x - fix_x) +1; X ellipse->radiuses.y = abs(y - fix_y) +1; X ellipse->start.x = fix_x; X ellipse->start.y = fix_y; X ellipse->end.x = x; X ellipse->end.y = y; X ellipse->next = NULL; X draw_ellipse(ellipse, DRAW); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, ellipse); X set_latestellipse(ellipse); X set_modifiedflag(); X ellipsebyradius_drawing_selected(); X } X Xellipsebydiameter_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_ellipsebydiameter_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_ellipsebydiameter_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_ebdbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_ellipsebydia; X set_temp_cursor(&null_cursor); X ellipsebydia_box(INV_PAINT); X set_action_on(); X } X Xmove_ebdbox(x, y) Xint x, y; X{ X ellipsebydia_box(INV_PAINT); X cur_x = x; X cur_y = y; X ellipsebydia_box(INV_PAINT); X } X Xellipsebydia_box(op) Xint op; X{ X draw_rectbox(fix_x, fix_y, cur_x, cur_y, op); X } X Xcreate_ellipsebydia(x, y) Xint x, y; X{ X F_ellipse *ellipse; X X ellipsebydia_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(ellipse))) { X blink_msg(); X put_msg(Err_mem); X return; X } X ellipse->type = T_ELLIPSE_BY_DIA; X ellipse->style = line_style; X ellipse->thickness = line_thickness; X ellipse->style_val = cur_styleval; X ellipse->angle = cur_angle; X ellipse->color = cur_color; X ellipse->depth = 0; X ellipse->pen = NULL; X /* added 3/1/89 B.V.Smith */ X ellipse->area_fill = fill_mode? cur_areafill : 0; X ellipse->direction = 1; X ellipse->center.x = (fix_x + x) / 2; X ellipse->center.y = (fix_y + y) / 2; X ellipse->radiuses.x = abs(ellipse->center.x - fix_x); X ellipse->radiuses.y = abs(ellipse->center.y - fix_y); X ellipse->start.x = fix_x; X ellipse->start.y = fix_y; X ellipse->end.x = x; X ellipse->end.y = y; X ellipse->next = NULL; X draw_ellipse(ellipse, DRAW); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, ellipse); X set_latestellipse(ellipse); X set_modifiedflag(); X ellipsebydiameter_drawing_selected(); X } X X/*************************** circle section ************************/ X Xcirclebyradius_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_circlebyradius_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_circlebyradius_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_cbrbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_circlebyrad; X set_temp_cursor(&null_cursor); X circlebyrad_box(INV_PAINT); X set_action_on(); X } X Xmove_cbrbox(x, y) Xint x, y; X{ X circlebyrad_box(INV_PAINT); X cur_x = x; X cur_y = y; X circlebyrad_box(INV_PAINT); X } X Xcirclebyrad_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int radius, rx, ry; X X rx = cur_x - fix_x; X ry = cur_y - fix_y; X radius = round(sqrt((double) (rx*rx + ry*ry))); X x1 = fix_x + radius; X x2 = fix_x - radius; X y1 = fix_y + radius; X y2 = fix_y - radius; X draw_rectbox(x1, y1, x2, y2, op); X pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, op, 1, SOLID_LINE, 0.0); X } X Xcreate_circlebyrad(x, y) Xint x, y; X{ X F_ellipse *c; X int rx, ry; X X circlebyrad_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(c))) { X blink_msg(); X put_msg(Err_mem); X return; X } X c->type = T_CIRCLE_BY_RAD; X c->style = line_style; X c->thickness = line_thickness; X c->style_val = cur_styleval; X c->angle = 0.0; X c->color = cur_color; X c->depth = 0; X c->pen = NULL; X /* added 3/1/89 B.V.Smith */ X c->area_fill = fill_mode? cur_areafill : 0; X c->direction = 1; X c->center.x = fix_x; X c->center.y = fix_y; X rx = fix_x - x; ry = fix_y - y; X c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry))); X c->start.x = fix_x; X c->start.y = fix_y; X c->end.x = x; X c->end.y = y; X c->next = NULL; X draw_ellipse(c, DRAW); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, c); X set_latestellipse(c); X set_modifiedflag(); X circlebyradius_drawing_selected(); X } X Xcirclebydiameter_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_circlebydiameter_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_circlebydiameter_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_cbdbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_circlebydia; X set_temp_cursor(&null_cursor); X circlebydia_box(INV_PAINT); X set_action_on(); X } X Xmove_cbdbox(x, y) Xint x, y; X{ X circlebydia_box(INV_PAINT); X cur_x = x; X cur_y = y; X circlebydia_box(INV_PAINT); X } X Xcirclebydia_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int radius, rx, ry; X X rx = (cur_x - fix_x) / 2; X ry = (cur_y - fix_y) / 2; X radius = round(sqrt((double) (rx*rx + ry*ry))); X x1 = fix_x + rx + radius; X x2 = fix_x + rx - radius; X y1 = fix_y + ry + radius; X y2 = fix_y + ry - radius; X draw_rectbox(x1, y1, x2, y2, op); X pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, op, 1, SOLID_LINE, 0.0); X } X Xcreate_circlebydia(x, y) Xint x, y; X{ X F_ellipse *c; X int rx, ry; X X circlebydia_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(c))) { X blink_msg(); X put_msg(Err_mem); X return; X } X c->type = T_CIRCLE_BY_DIA; X c->style = line_style; X c->thickness = line_thickness; X c->style_val = cur_styleval; X c->angle = 0.0; X c->color = cur_color; X c->depth = 0; X c->pen = NULL; X /* added 3/1/89 B.V.Smith */ X c->area_fill = fill_mode? cur_areafill : 0; X c->direction = 1; X c->center.x = (fix_x + x) / 2 + .5; X c->center.y = (fix_y + y) / 2 + .5; X rx = x - c->center.x; ry = y - c->center.y; X c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry))); X c->start.x = fix_x; X c->start.y = fix_y; X c->end.x = x; X c->end.y = y; X c->next = NULL; X draw_ellipse(c, DRAW); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, c); X set_latestellipse(c); X set_modifiedflag(); X circlebydiameter_drawing_selected(); X } X Xdraw_ellipse(e, op) XF_ellipse *e; Xint op; X{ X int a, b; X X a = e->radiuses.x; X b = e->radiuses.y; X curve(canvas_win, a, 0, a, 0, e->direction, (b*b), (a*a), X e->center.x, e->center.y, op, X e->thickness, e->style, e->style_val, e->area_fill); X } END_OF_FILE if test 9796 -ne `wc -c <'ellipse.c'`; then echo shar: \"'ellipse.c'\" unpacked with wrong size! fi # end of 'ellipse.c' fi if test -f 'glue.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'glue.c'\" else echo shar: Extracting \"'glue.c'\" \(10982 characters\) sed "s/^X//" >'glue.c' <<'END_OF_FILE' 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 "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X X#define TOLERANCE 7 X#define min(a, b) (((a) < (b)) ? (a) : (b)) X#define max(a, b) (((a) > (b)) ? (a) : (b)) X Xextern F_pos last_position, new_position; /* undo.c */ Xextern int fix_x, fix_y, cur_x, cur_y; 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 set_popupmenu(); X Xextern F_compound objects; Xextern int compoundbox_shown; Xextern int pointmarker_shown; Xextern int foreground_color, background_color; X Xextern int create_compound(); Xextern F_compound *compound_point_search(); X Xextern int init_create_compound(); X Xcompound_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_create_compound; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_create_compound(x, y) Xint x, y; X{ X init_box_drawing(x, y); X canvas_middlebut_proc = create_compound; X canvas_leftbut_proc = canvas_rightbut_proc = null_proc; X } X Xcreate_compound(x, y) Xint x, y; X{ X F_compound *c; X X if (NULL == (Compound_malloc(c))) { X put_msg(Err_mem); X return; X } X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT); X c->nwcorner.x = min(fix_x, x); X c->nwcorner.y = min(fix_y, y); X c->secorner.x = max(fix_x, x); X c->secorner.y = max(fix_y, y); X if (compose_compound(c) == 0) { X free((char*)c); X compound_selected(); X put_msg("Empty compound, ignore"); X return; X } X draw_compoundbox(c, INV_PAINT); X c->next = NULL; X clean_up(); X set_action(F_GLUE); X insert_compound(&objects.compounds, c); X set_latestcompound(c); X compound_selected(); X } X Xcompose_compound(c) XF_compound *c; X{ X c->ellipses = NULL; X c->lines = NULL; X c->texts = NULL; X c->splines = NULL; X c->arcs = NULL; X c->compounds = NULL; X get_ellipse(&c->ellipses, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_lineobj(&c->lines, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_spline(&c->splines, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_text(&c->texts, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_arc(&c->arcs, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_compound(&c->compounds, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X /* get rid of point-marker */ X if (pointmarker_shown) toggle_compoundpointmarker(c); X if (c->ellipses != NULL) return(1); X if (c->splines != NULL) return(1); X if (c->lines != NULL) return(1); X if (c->texts != NULL) return(1); X if (c->arcs != NULL) return(1); X if (c->compounds != NULL) return(1); X return(0); X } X Xdraw_compoundbox(c, op) XF_compound *c; Xint op; X{ X draw_rectbox( c->nwcorner.x-1, c->nwcorner.y-1, X c->secorner.x+1, c->secorner.y+1, op); X draw_rectbox( c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y, op); X draw_rectbox( c->nwcorner.x+1, c->nwcorner.y+1, X c->secorner.x-1, c->secorner.y-1, op); X } X Xget_ellipse(list, xmin, ymin, xmax, ymax) XF_ellipse **list; Xint xmin, ymin, xmax, ymax; X{ X F_ellipse *e, *ee, *ellipse; X X for (e = objects.ellipses; e != NULL;) { X if (xmin > e->center.x - e->radiuses.x) { X ee = e; e = e->next; continue; X } X if (xmax < e->center.x + e->radiuses.x) { X ee = e; e = e->next; continue; X } X if (ymin > e->center.y - e->radiuses.y) { X ee = e; e = e->next; continue; X } X if (ymax < e->center.y + e->radiuses.y) { X ee = e; e = e->next; continue; X } X ellipse = e; X if (e == objects.ellipses) X e = objects.ellipses = objects.ellipses->next; X else { X e = ee->next = e->next; X } X ellipse->next = *list; X *list = ellipse; X } X } X Xget_arc(list, xmin, ymin, xmax, ymax) XF_arc **list; Xint xmin, ymin, xmax, ymax; X{ X F_arc *a, *arc, *aa; X int urx, ury, llx, lly; X X for (a = objects.arcs; a != NULL;) { X arc_bound(a, &llx, &lly, &urx, &ury); X if (xmin > llx) goto out; X if (xmax < urx) goto out; X if (ymin > lly) goto out; X if (ymax < ury) goto out; X arc = a; X if (a == objects.arcs) X a = objects.arcs = objects.arcs->next; X else X a = aa->next = a->next; X arc->next = *list; X *list = arc; X continue; X out: X aa = a; a = a->next; X } X } X Xget_lineobj(list, xmin, ymin, xmax, ymax) XF_line **list; Xint xmin, ymin, xmax, ymax; X{ X F_line *line, *l, *ll; X F_point *p; X int inbound; X X for (l = objects.lines; l != NULL;) { X for (inbound = 1, p = l->points; p!= NULL && inbound; X p = p->next) { X inbound = 0; X if (xmin > p->x) continue; X if (xmax < p->x) continue; X if (ymin > p->y) continue; X if (ymax < p->y) continue; X inbound = 1; X } X if (! inbound) { X ll = l; l = l->next; continue; X } X line = l; X if (l == objects.lines) X l = objects.lines = objects.lines->next; X else X l = ll->next = l->next; X line->next = *list; X *list = line; X } X } X Xget_spline(list, xmin, ymin, xmax, ymax) XF_spline **list; Xint xmin, ymin, xmax, ymax; X{ X F_spline *spline, *s, *ss; X int urx, ury, llx, lly; X X for (s = objects.splines; s != NULL;) { X spline_bound(s, &llx, &lly, &urx, &ury); X if (xmin > llx) goto out; X if (xmax < urx) goto out; X if (ymin > lly) goto out; X if (ymax < ury) goto out; X spline = s; X if (s == objects.splines) X s = objects.splines = objects.splines->next; X else X s = ss->next = s->next; X spline->next = *list; X *list = spline; X continue; X out: X ss = s; s = s->next; X } X } X Xget_text(list, xmin, ymin, xmax, ymax) XF_text **list; Xint xmin, ymin, xmax, ymax; X{ X int halflen; X F_text *text, *t, *tt; X X for (t = objects.texts; t != NULL;) { X halflen = t->length/2; X if ( ((t->type == T_LEFT_JUSTIFIED) && xmin > t->base_x) || X ((t->type == T_CENTER_JUSTIFIED) && xmin > t->base_x - halflen) || X ((t->type == T_RIGHT_JUSTIFIED) && xmin > t->base_x - t->length) ) X { X tt = t; t = t->next ; continue; X } X if ( ((t->type == T_LEFT_JUSTIFIED) && xmax < t->base_x + t->length) || X ((t->type == T_CENTER_JUSTIFIED) && xmax < t->base_x + halflen) || X ((t->type == T_RIGHT_JUSTIFIED) && xmax < t->base_x) ) X { X tt = t; t = t->next ; continue; X } X if (ymin > t->base_y - t->height) { X tt = t; t = t->next; continue; X } X if (ymax < t->base_y) { X tt = t; t = t->next; continue; X } X text = t; X if (t == objects.texts) X t = objects.texts = objects.texts->next; X else X t = tt->next = t->next; X text->next = *list; X *list = text; X } X } X Xget_compound(list, xmin, ymin, xmax, ymax) XF_compound **list; Xint xmin, ymin, xmax, ymax; X{ X F_compound *compd, *c, *cc; X for (c = objects.compounds; c != NULL;) X { X if (xmin > c->nwcorner.x) X { X cc = c; X c = c->next; X continue; X } X if (xmax < c->secorner.x) X { X cc = c; X c = c->next; X continue; X } X if (ymin > c->nwcorner.y) X { X cc = c; X c = c->next; X continue; X } X if (ymax < c->secorner.y) X { X cc = c; X c = c->next; X continue; X } X compd = c; X if (c == objects.compounds) X c = objects.compounds = objects.compounds->next; X else X c = cc->next = c->next; X compd->next = *list; X *list = compd; X } X} X XF_compound * Xcompound_point_search(x, y, tol, px, py) Xint x, y, tol, *px, *py; X{ X F_compound *c; X X for (c = objects.compounds; c != NULL; c = c->next) { X if (abs(c->nwcorner.x - x) <= tol && X abs(c->nwcorner.y - y) <= tol) { X *px = c->nwcorner.x; X *py = c->nwcorner.y; X return(c); X } X if (abs(c->nwcorner.x - x) <= tol && X abs(c->secorner.y - y) <= tol) { X *px = c->nwcorner.x; X *py = c->secorner.y; X return(c); X } X if (abs(c->secorner.x - x) <= tol && X abs(c->nwcorner.y - y) <= tol) { X *px = c->secorner.x; X *py = c->nwcorner.y; X return(c); X } X if (abs(c->secorner.x - x) <= tol && X abs(c->secorner.y - y) <= tol) { X *px = c->secorner.x; X *py = c->secorner.y; X return(c); X } X } X return(NULL); X } X Xdraw_compound(c) XF_compound *c; X{ X draw_compoundelements(c, foreground_color, foreground_color, X PAINT, PAINT, PAINT, PAINT); X } X Xerase_compound(c) XF_compound *c; X{ X draw_compoundelements(c, background_color, background_color, X ERASE, ERASE, INV_PAINT, ERASE); X } X Xdraw_compoundelements(c, arcop, ellipseop, lineop, splineop, textop, compop) XF_compound *c; Xint arcop, ellipseop, lineop, splineop, textop, compop; X{ X F_line *l; X F_spline *s; X F_ellipse *e; X F_text *t; X F_arc *a; X F_compound *c1; X X for (l = c->lines; l != NULL; l = l->next) { X draw_line(l, lineop); X } X for (s = c->splines; s != NULL; s = s->next) { X draw_spline(s, splineop); X } X for (a = c->arcs; a != NULL; a = a->next) { X draw_arc(a, arcop); X } X for (e = c->ellipses; e != NULL; e = e->next) { X draw_ellipse(e, ellipseop); X } X for (t = c->texts; t != NULL; t = t->next) { X draw_text(t, textop); X } X for (c1 = c->compounds; c1 != NULL; c1 = c1->next) { X draw_compoundbox(c1, INV_PAINT); X compop == ERASE ? erase_compound(c1) : draw_compound(c1); X } X } X XF_compound * Xcompound_search(x, y, tolerance, px, py) Xint x, y, tolerance, *px, *py; X{ X F_compound *c; X float tol2; X X tol2 = tolerance * tolerance; X X for (c = objects.compounds; c != NULL; c = c->next) { X if (close_to_vector(c->nwcorner.x, c->nwcorner.y, c->nwcorner.x, X c->secorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->secorner.x, c->secorner.y, c->nwcorner.x, X c->secorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->secorner.x, c->secorner.y, c->secorner.x, X c->nwcorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->nwcorner.x, c->nwcorner.y, c->secorner.x, X c->nwcorner.y, x, y, tolerance, tol2, px, py)) X return(c); X } X return(NULL); X } X Xtoggle_compoundpointmarker(c) XF_compound *c; X{ X F_line *l; X F_spline *s; X F_ellipse *e; X F_arc *a; X X for (l = c->lines; l != NULL; l = l->next) { X toggle_linepointmarker(l); X } X for (s = c->splines; s != NULL; s = s->next) { X toggle_splinepointmarker(s); X } X for (a = c->arcs; a != NULL; a = a->next) { X toggle_arcpointmarker(a); X } X for (e = c->ellipses; e != NULL; e = e->next) { X toggle_ellipsepointmarker(e); X } X } X Xshow_compoundbox() X{ X F_compound *c; X X if (compoundbox_shown) return; X compoundbox_shown = 1; X for (c = objects.compounds; c != NULL; c = c->next) X draw_compoundbox(c, INV_PAINT); X } X Xerase_compoundbox() X{ X F_compound *c; X X if (! compoundbox_shown) return; X compoundbox_shown = 0; X for (c = objects.compounds; c != NULL; c = c->next) X draw_compoundbox(c, INV_PAINT); X } X X X END_OF_FILE if test 10982 -ne `wc -c <'glue.c'`; then echo shar: \"'glue.c'\" unpacked with wrong size! fi # end of 'glue.c' fi if test -f 'main.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'main.c'\" else echo shar: Extracting \"'main.c'\" \(9736 characters\) sed "s/^X//" >'main.c' <<'END_OF_FILE' 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#include "patchlevel.h" X#include "resources.h" X#include "font.h" X Xextern int ICON_COLUMN; Xextern int CANVAS_HEIGHT, CANVAS_WIDTH; Xextern int PANEL_WID, PANEL2_WID; Xextern int SIDERULER_WIDTH, SIDERULER_HEIGHT; Xextern int TOPRULER_WIDTH, TOPRULER_HEIGHT; Xextern (*canvas_rightbut_proc)(); Xextern set_popupmenu(); Xextern int cur_areafill; Xextern int print_landscape; Xextern int size_button; X X#include "fig.icon.X" XPixmap fig_icon; X Xstatic char tool_name[100] = " FIG : FACILITY FOR INTERACTIVE GENERATION OF FIGURES "; Xstatic sigwinched(); X X/************** FIG options ******************/ X Xextern appresStruct appres; X XTOOL tool; Xchar file_header[32] = "#FIG "; Xstatic char *filename = NULL; X Xstatic Boolean true = True; Xstatic Boolean false = False; Xstatic int zero = 0; X Xstatic XtResource application_resources[] = { X {XtNjustify, XtCJustify, XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, RHS_PANEL), XtRBoolean, (caddr_t)&false}, X {"landscape", XtCOrientation, XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, landscape), XtRBoolean, (caddr_t)&true}, X {"debug", "Debug", XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, DEBUG), XtRBoolean, (caddr_t)&false}, X {"pwidth", XtCWidth, XtRFloat, sizeof(float), X XtOffset(appresPtr, tmp_width), XtRInt, (caddr_t)&zero}, X {"pheight", XtCHeight, XtRFloat, sizeof(float), X XtOffset(appresPtr, tmp_height), XtRInt, (caddr_t)&zero}, X {XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, INVERSE), XtRBoolean, (caddr_t)&false}, X {"trackCursor", "Track", XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, TRACKING), XtRBoolean, (caddr_t)&true}, X {"inches", "Inches", XtRBoolean, sizeof(Boolean), X XtOffset(appresPtr, INCHES), XtRBoolean, (caddr_t)&true}, X {"boldFont", "BoldFont", XtRString, sizeof(char *), X XtOffset(appresPtr, boldFont), XtRString, (caddr_t)NULL}, X {"normalFont", "NormalFont", XtRString, sizeof(char *), X XtOffset(appresPtr, normalFont), XtRString, (caddr_t)NULL}, X}; X Xstatic XrmOptionDescRec options[] = X{ X {"-right", ".justify", XrmoptionNoArg, "True" }, X {"-left", ".justify", XrmoptionNoArg, "False"}, X {"-debug", ".debug", XrmoptionNoArg, "True"}, X {"-landscape", ".landscape", XrmoptionNoArg, "True"}, X {"-Landscape", ".landscape", XrmoptionNoArg, "True"}, X {"-portrait", ".landscape", XrmoptionNoArg, "False"}, X {"-Portrait", ".landscape", XrmoptionNoArg, "False"}, X {"-pwidth", ".pwidth", XrmoptionSepArg, 0}, X {"-pheight", ".pheight", XrmoptionSepArg, 0}, X {"-inverse", ".reverseVideo", XrmoptionNoArg, "True"}, X {"-notrack", ".trackCursor", XrmoptionNoArg, "False"}, X {"-track", ".trackCursor", XrmoptionNoArg, "True"}, X {"-inches", ".inches", XrmoptionNoArg, "True"}, X {"-imperial", ".inches", XrmoptionNoArg, "True"}, X {"-centimeters", ".inches", XrmoptionNoArg, "False"}, X {"-metric", ".inches", XrmoptionNoArg, "False"}, X {"-boldFont", ".boldFont", XrmoptionSepArg, 0}, X {"-normalFont", ".normalFont", XrmoptionSepArg, 0}, X}; X Xstatic XtCallbackRec callbacks[] = X{ X { NULL, NULL }, X}; X Xstatic Arg form_args[] = X{ X { XtNcallback, (XtArgVal)callbacks }, X { XtNinput, (XtArgVal) TRUE }, X { XtNdefaultDistance, (XtArgVal) 1 }, X}; X Xmain(argc,argv) X int argc; X char *argv[]; X{ X#define NCHILDREN 8 X TOOL form, children[NCHILDREN]; X Arg tmp_arg[4]; X int ichild; X char tstr[10]; X XWMHints *wmhints; X char i; X X strcat(tool_name, " V. "); X strcat(tool_name, FIG_VERSION); X strcat(tool_name, " Protocol V. "); X strcat(tool_name, PROTOCOL_VERSION); X strcat(tool_name, " Patch Lev. "); X sprintf(tstr,"%d",PATCHLEVEL); X strcat(tool_name, tstr); X strcat(file_header, PROTOCOL_VERSION); X printf("Initializing FIG v%s Protocol v%s (X11 patchlevel %d) ... \n", X FIG_VERSION, PROTOCOL_VERSION, PATCHLEVEL); X tool = XtInitialize("fig", "Fig", options, XtNumber(options), X &argc, argv); X X fix_converters(); X XtGetApplicationResources(tool, &appres, application_resources, X 10, NULL, 0 ); X X i=1; X while (argc-- > 1) X { X if (*argv[i] != '-') /* search for non - name */ X { X filename = argv[i]; X break; X } X i++; X } X X print_landscape = appres.landscape; /* match print and screen format to start */ X X tool_d = XtDisplay(tool); X tool_s = XtScreen(tool); X tool_sn = DefaultScreen(tool_d); X X /* run synchronously for debugging */ X X if (appres.DEBUG) X { X XSynchronize(tool_d, 1); X fprintf(stderr,"Debug mode, running synchronously\n"); X } X X if( CellsOfScreen(tool_s) == 2 && appres.INVERSE ) X { X XrmValue value; X XrmDatabase newdb = (XrmDatabase) 0, old; X X value.size = sizeof("White"); X value.addr = "White"; X XrmPutResource(&newdb, "xfig*borderColor", "String", X &value); X value.size = sizeof("White"); X value.addr = "White"; X XrmPutResource(&newdb, "xfig*foreground", "String", X &value); X value.size = sizeof("Black"); X value.addr = "Black"; X XrmPutResource(&newdb, "xfig*background", "String", X &value); X old = XtDatabase(tool_d); X XrmMergeDatabases(newdb, &old); X X /* now set the tool part, since its already created */ X XtSetArg(tmp_arg[0], XtNborderColor, X WhitePixelOfScreen(tool_s)); X XtSetArg(tmp_arg[1], XtNforeground, X WhitePixelOfScreen(tool_s)); X XtSetArg(tmp_arg[2], XtNbackground, X BlackPixelOfScreen(tool_s)); X XtSetValues(tool, tmp_arg, 3); X } X X init_font(); X X gc = DefaultGC(tool_d, tool_sn); X bold_gc = DefaultGC(tool_d, tool_sn); X X /* set the roman and bold fonts for the message windows */ X XSetFont(tool_d, gc, roman_font->fid); X XSetFont(tool_d, bold_gc, bold_font->fid); X X init_cursor(); X form = XtCreateManagedWidget("form", formWidgetClass, tool, X form_args, XtNumber(form_args)); X X if (size_button == 0) X size_button = DEF_PRINTFONTSIZE; X X ICON_COLUMN = ICON_COLUMN_PORT; X CANVAS_WIDTH = appres.tmp_width * (appres.INCHES ? PIX_PER_INCH : PIX_PER_CM); X CANVAS_HEIGHT = appres.tmp_height * (appres.INCHES ? PIX_PER_INCH : PIX_PER_CM); X X if( CANVAS_WIDTH == 0 ) X CANVAS_WIDTH = appres.landscape ? DEF_CANVAS_WIDTH_L : DEF_CANVAS_WIDTH_P; X X if( CANVAS_HEIGHT == 0 ) X CANVAS_HEIGHT = appres.landscape ? DEF_CANVAS_HEIGHT_L : DEF_CANVAS_HEIGHT_P; X X X if( (CANVAS_HEIGHT < DEF_CANVAS_HEIGHT_P) || X (HeightOfScreen(tool_s) < DEF_CANVAS_HEIGHT_P) ) X ICON_COLUMN = ICON_COLUMN_LAND; X X (void) init_panel(form); X (void) init_topruler(form) ; X (void) init_menu(form); /* command menu */ X (void) init_canvas(form); X (void) init_fontmenu(form); /* printer font menu */ X (void) init_sideruler(form); X (void) init_msg(form); X (void) init_panel2(form); /* second panel */ X (void) init_indicator_panel(form); /* current line size, area fill, etc */ X X ichild = 0; X children[ichild++] = panel_sw; X children[ichild++] = topruler_sw; X children[ichild++] = psfont; /* shows current printer font name */ X children[ichild++] = sideruler_sw; /* side ruler */ X children[ichild++] = canvas_sw; /* main drawing canvas */ X children[ichild++] = msg_sw; /* message window */ X children[ichild++] = panel2_sw; /* lower button panel */ X children[ichild++] = ind_box; /* fill/line/radius indicators */ X X /* until the following XtRealizeWidget() is called, there X are NO windows in existence */ X X XtManageChildren(children, NCHILDREN); X XtRealizeWidget(tool); X X /* Set the input field to true to allow keyboard input */ X wmhints = XGetWMHints(tool_d, XtWindow(tool)); X wmhints->flags |= InputHint; /* add in input hint */ X wmhints->input = True; X XSetWMHints(tool_d, XtWindow(tool),wmhints); X X if( appres.RHS_PANEL ) /* side button panel is on right size */ 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 X XtSetArg(tmp_arg[0], XtNfromHoriz, 0); X XtSetArg(tmp_arg[1], XtNfromVert, topruler_sw); X XtSetArg(tmp_arg[2], XtNleft, XtChainLeft); /* chain to left of form */ X XtSetArg(tmp_arg[3], XtNright, XtChainLeft); X XtSetValues(sideruler_sw, tmp_arg, 4); X 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 X /* relocate the side button panel */ X XtUnmanageChild(panel_sw); X XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw); /* panel right of canvas */ X XtSetArg(tmp_arg[1], XtNfromVert, 0); X XtSetArg(tmp_arg[2], XtNleft, XtChainRight); /* chain to right of form */ X XtSetArg(tmp_arg[3], XtNright, XtChainRight); X XtSetValues(panel_sw, tmp_arg, 4); X XtManageChild(panel_sw); X X /* relocate the indicator panel */ X XtUnmanageChild(ind_box); X XtSetArg(tmp_arg[0], XtNfromHoriz, canvas_sw); /* right of canvas */ X XtSetArg(tmp_arg[1], XtNleft, XtChainRight); /* chain to right of form */ X XtSetArg(tmp_arg[2], XtNright, XtChainRight); X XtSetValues(ind_box, tmp_arg, 3); X XtManageChild(ind_box); X } X fig_icon = XCreateBitmapFromData(tool_d, XtWindow(tool), X fig_bits, fig_width, fig_height); X X XtSetArg(tmp_arg[0], XtNtitle, tool_name); X XtSetArg(tmp_arg[1], XtNiconPixmap, fig_icon); X XtSetValues(tool, tmp_arg, 2); X X init_gc(); X init_fill_pm(); X init_fill_gc(); X show_fill_color(); X#ifndef TFX X show_radius(); X#endif X setup_panel(); X setup_rulers(); X setup_canvas(); X setup_msg(); X setup_fontmenu(); /* install bitmaps in printer font menu */ X printer_select(); X show_fontsize(); X show_line_thickness(); X put_msg("READY"); X canvas_rightbut_proc = set_popupmenu; X if (filename != NULL) X edit_file(filename); X (void)signal(SIGINT, SIG_IGN); /* so we don't lose work accidentally */ X X XtMainLoop(); X} END_OF_FILE if test 9736 -ne `wc -c <'main.c'`; then echo shar: \"'main.c'\" unpacked with wrong size! fi # end of 'main.c' fi if test -f 'read1_3.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'read1_3.c'\" else echo shar: Extracting \"'read1_3.c'\" \(10689 characters\) sed "s/^X//" >'read1_3.c' <<'END_OF_FILE' 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 : March 1988. X * X * %W% %G% X*/ X X/*******************************************************************/ X/*************** Read version 1.3 format ***************/ X/*******************************************************************/ X#include "fig.h" X#include "alloc.h" X#include "object.h" X X/******* Fig 1.3 subtype of objects *******/ X#define DRAW_ELLIPSE_BY_RAD 1 X#define DRAW_ELLIPSE_BY_DIA 2 X#define DRAW_CIRCLE_BY_RAD 3 X#define DRAW_CIRCLE_BY_DIA 4 X#define DRAW_CIRCULAR_ARC 5 X#define DRAW_POLYLINE 6 X#define DRAW_BOX 7 X#define DRAW_POLYGON 8 X#define DRAW_TEXT 9 X#define DRAW_SPLINE 10 X#define DRAW_CLOSEDSPLINE 11 X#define DRAW_COMPOUND 13 X Xextern F_arrow *forward_arrow(), *backward_arrow(); Xextern int errno; Xextern char *sys_errlist[]; Xextern int sys_nerr, errno; X Xstatic F_ellipse *read_1_3_ellipseobject(); Xstatic F_line *read_1_3_lineobject(); Xstatic F_text *read_1_3_textobject(); Xstatic F_spline *read_1_3_splineobject(); Xstatic F_arc *read_1_3_arcobject(); Xstatic F_compound *read_1_3_compoundobject(); X Xextern int line_no; Xextern int num_object; X Xint Xread_1_3_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 n; X int object, pixperinch, canvaswid, canvasht, coord_sys; X X n = fscanf(fp,"%d%d%d%d\n", &pixperinch, &coord_sys, &canvaswid, &canvasht); X if (n != 4) { X put_msg("Incorrect format in the first line in input file"); X return(-1); X } X obj->nwcorner.x = pixperinch; X obj->nwcorner.y = coord_sys; X while (fscanf(fp, "%d", &object) == 1) { X switch (object) { X case O_POLYLINE : X if ((l = read_1_3_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_1_3_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_1_3_ellipseobject(fp)) == 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_1_3_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_1_3_textobject(fp)) == 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_1_3_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 %d", object); X return(-1); X } /* switch */ X } /* while */ X if (feof(fp)) X return(0); X else X return(errno); X } X Xstatic F_arc * Xread_1_3_arcobject(fp) XFILE *fp; X{ X F_arc *a; X int f, b, h, w, n; X X if (NULL == (Arc_malloc(a))) { X put_msg(Err_mem); X return(NULL); X } X a->type = T_3_POINTS_ARC; X a->color = BLACK; X a->depth = 0; X a->pen = 0; X a->for_arrow = NULL; X a->back_arrow = NULL; X a->next = NULL; X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %f %f %d %d %d %d %d %d\n", X &a->type, &a->style, &a->thickness, X &a->style_val, &a->direction, &f, &b, X &h, &w, &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("incomplete arc data"); X free((char*)a); X return(NULL); X } X if (f) { X a->for_arrow = forward_arrow(); X a->for_arrow->wid = w; X a->for_arrow->ht = h; X } X if (b) { X a->back_arrow = backward_arrow(); X a->back_arrow->wid = w; X a->back_arrow->ht = h; X } X return(a); X } X Xstatic F_compound * Xread_1_3_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 if (NULL == (Compound_malloc(com))) { X put_msg(Err_mem); X return(NULL); X } 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 = fscanf(fp, " %d %d %d %d\n", &com->nwcorner.x, &com->nwcorner.y, X &com->secorner.x, &com->secorner.y); X if (n != 4) { X put_msg("Incorrect compound object format"); X return(NULL); X } X while (fscanf(fp, "%d", &object) == 1) { X switch (object) { X case O_POLYLINE : X if ((l = read_1_3_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_1_3_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_1_3_ellipseobject(fp)) == 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_1_3_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_1_3_textobject(fp)) == 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_1_3_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 } /* switch */ X } X if (feof(fp)) X return(com); X else { X put_msg("Format error: %s", sys_errlist[errno]); X return(NULL); X } X } X Xstatic F_ellipse * Xread_1_3_ellipseobject(fp) XFILE *fp; X{ X F_ellipse *e; X int n, t; X X if (NULL == (Ellipse_malloc(e))) { X put_msg(Err_mem); X return(NULL); X } X e->color = BLACK; X e->angle = 0.0; X e->depth = 0; X e->pen = 0; X e->area_fill = NULL; X e->next = NULL; X n = fscanf(fp," %d %d %d %f %d %d %d %d %d %d %d %d %d\n", X &t, &e->style, X &e->thickness, &e->style_val, &e->direction, 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 != 13) { X put_msg("incomplete ellipse data"); X free((char*)e); X return(NULL); X } X if (t == DRAW_ELLIPSE_BY_RAD) X e->type = T_ELLIPSE_BY_RAD; X else if (t == DRAW_ELLIPSE_BY_DIA) X e->type = T_ELLIPSE_BY_DIA; X else if (t == DRAW_CIRCLE_BY_RAD) X e->type = T_CIRCLE_BY_RAD; X else X e->type = T_CIRCLE_BY_DIA; X return(e); X } X Xstatic F_line * Xread_1_3_lineobject(fp) XFILE *fp; X{ X F_line *l; X F_point *p, *q; X int f, b, h, w, n, t, x, y; X X if (NULL == (Line_malloc(l))) { X put_msg(Err_mem); X return(NULL); X } X l->color = BLACK; X l->depth = 0; X l->pen = 0; X l->area_fill = NULL; X l->for_arrow = NULL; X l->back_arrow = NULL; X l->next = NULL; X if (NULL == (Point_malloc(p))) { X put_msg(Err_mem); X return(NULL); X } X l->points = p; X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %d", &t, X &l->style, &l->thickness, &l->style_val, X &f, &b, &h, &w, &p->x, &p->y); X if (n != 10) { X put_msg("incomplete line data"); X free((char*)l); X return(NULL); X } X if (t == DRAW_POLYLINE) X l->type = T_POLYLINE; X else if (t == DRAW_POLYGON) X l->type = T_POLYGON; X else X l->type = T_BOX; X if (f) { X l->for_arrow = forward_arrow(); X l->for_arrow->wid = w; X l->for_arrow->ht = h; X } X if (b) { X l->back_arrow = backward_arrow(); X l->back_arrow->wid = w; X l->back_arrow->ht = h; X } X for (;;) { X if (fscanf(fp, " %d %d", &x, &y) != 2) { X put_msg("incomplete line object"); 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 return(NULL); X } X q->x = x; X q->y = y; X q->next = NULL; X p->next = q; X p = q; X } X return(l); X } X Xstatic F_spline * Xread_1_3_splineobject(fp) XFILE *fp; X{ X F_spline *s; X F_point *p, *q; X int f, b, h, w, n, t, x, y; X X if (NULL == (Spline_malloc(s))) { X put_msg(Err_mem); X return(NULL); X } X s->color = BLACK; X s->depth = 0; X s->pen = 0; X s->area_fill = NULL; X s->for_arrow = NULL; X s->back_arrow = NULL; X s->controls = NULL; X s->next = NULL; X if (NULL == (Point_malloc(p))) { X put_msg(Err_mem); X return(NULL); X } X s->points = p; X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %d", X &t, &s->style, &s->thickness, &s->style_val, X &f, &b, X &h, &w, &p->x, &p->y); X if (n != 10) { X put_msg("incomplete spline data"); X free((char*)s); X return(NULL); X } X if (t == DRAW_CLOSEDSPLINE) X s->type = T_CLOSED_NORMAL; X else X s->type = T_OPEN_NORMAL; X if (f) { X s->for_arrow = forward_arrow(); X s->for_arrow->wid = w; X s->for_arrow->ht = h; X } X if (b) { X s->back_arrow = backward_arrow(); X s->back_arrow->wid = w; X s->back_arrow->ht = h; X } X for (;;) { X if (fscanf(fp, " %d %d", &x, &y) != 2) { X put_msg("incomplete spline object"); 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 return(NULL); X } X q->x = x; X q->y = y; X q->next = NULL; X p->next = q; X p = q; X } X return(s); X } X Xstatic F_text * Xread_1_3_textobject(fp) XFILE *fp; X{ X F_text *t; X int n; X char buf[128]; X X if (NULL == (Text_malloc(t))) { X put_msg(Err_mem); X return(NULL); X } X t->type = T_LEFT_JUSTIFIED; X t->style = PLAIN; X t->color = BLACK; X t->depth = 0; X t->pen = 0; X t->angle = 0.0; X t->next = NULL; X n = fscanf(fp," %d %d %d %d %d %d %d %[^\n]", &t->font, X &t->size, &t->style, &t->height, &t->length, X &t->base_x, &t->base_y, buf); X if (n != 8) { X put_msg("incomplete text data"); X free((char*)t); X return(NULL); X } X t->cstring = (char *) calloc((unsigned)(strlen(buf)+1), sizeof(char)); X if (t->cstring == NULL) { X put_msg(Err_mem); X free((char*) t); X return(NULL); X } X strcpy(t->cstring, buf); X if (t->size == 0) t->size = 18; X return(t); X } END_OF_FILE if test 10689 -ne `wc -c <'read1_3.c'`; then echo shar: \"'read1_3.c'\" unpacked with wrong size! fi # end of 'read1_3.c' fi echo shar: End of archive 10 \(of 21\). cp /dev/null ark10isdone 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@sun.com / argv@ora.com Opinions expressed reflect those of the author only.