william@CS.UCLA.EDU (William Cheng) (08/04/90)
Submitted-by: william@CS.UCLA.EDU (William Cheng) Posting-number: Volume 8, Issue 59 Archive-name: tgif/patch2.02 Patch-To: tgif: Volume 7, Issue 56-76 (original: tgif-1.2) Patch-To: tgif: Volume 8, Issue 46-48 (Patch1: tgif-1.2 => tgif-1.9) ---------------------------------> cut here <--------------------------------- *** font.c.orig Thu Aug 2 09:44:45 1990 --- font.c Thu Aug 2 09:44:47 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/font.c,v 1.2 90/06/26 00:05:27 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/font.c,v 1.5 90/07/30 15:54:02 william Exp $"; #endif *************** *** 631,635 **** } ! ChangeFont (FontIndex) int FontIndex; { --- 631,635 ---- } ! void ChangeFont (FontIndex) int FontIndex; { *** grid.c.orig Thu Aug 2 09:44:54 1990 --- grid.c Thu Aug 2 09:44:55 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/grid.c,v 1.4 90/06/26 00:05:37 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/grid.c,v 1.6 90/07/16 10:18:38 william Exp $"; #endif *************** *** 30,34 **** int gridOn = TRUE; int xyGrid = DEFAULT_GRID; - int curScale = 1; int pageStyle = PORTRAIT; int whereToPrint = PRINTER; --- 30,33 ---- *************** *** 586,588 **** --- 585,591 ---- *GridY = Y; } + } + + void CleanUpGrids () + { } *** group.c.orig Thu Aug 2 09:45:01 1990 --- group.c Thu Aug 2 09:45:02 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/group.c,v 1.2 90/06/26 00:05:45 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/group.c,v 1.3 90/07/30 11:10:25 william Exp $"; #endif *************** *** 86,92 **** } ! void ReadGroupObj (FP, ObjPtr) FILE * FP; struct ObjRec * * ObjPtr; { struct GroupRec * group_ptr; --- 86,93 ---- } ! void ReadGroupObj (FP, ObjPtr, PRTGIF) FILE * FP; struct ObjRec * * ObjPtr; + int PRTGIF; { struct GroupRec * group_ptr; *************** *** 97,101 **** * ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); ! while (ReadObj (FP, &obj_ptr)) { obj_ptr->next = top_obj; --- 98,102 ---- * ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); ! while (ReadObj (FP, &obj_ptr, PRTGIF)) { obj_ptr->next = top_obj; *** mainloop.c.orig Thu Aug 2 09:45:10 1990 --- mainloop.c Thu Aug 2 09:45:12 1990 *************** *** 6,13 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/mainloop.c,v 1.4 90/06/26 00:10:31 william Exp $"; #endif #include <stdio.h> #include <X11/Xlib.h> #include "const.h" --- 6,14 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/mainloop.c,v 1.12 90/07/30 11:01:17 william Exp $"; #endif #include <stdio.h> + #include <signal.h> #include <X11/Xlib.h> #include "const.h" *************** *** 22,25 **** --- 23,27 ---- #include "file.e" #include "font.e" + #include "grid.e" #include "menu.e" #include "msg.e" *************** *** 29,36 **** --- 31,41 ---- #include "ruler.e" #include "scroll.e" + #include "select.e" #include "setup.e" + #include "stk.e" #include "text.e" int geometrySpecified = FALSE; + int exitNormally = FALSE; char geometrySpec[80]; char initMsg1[80], initMsg2[80]; *************** *** 111,114 **** --- 116,120 ---- { CleanUpDrawingWindow (); + CleanUpStk (); CleanUpChoices (); *************** *** 122,126 **** --- 128,137 ---- CleanUpNames (); CleanUpText (); + CleanUpColors (); + CleanUpFiles (); + CleanUpGrids (); + DelAllCutSel (); + XDestroyWindow (mainDisplay, mainWindow); if (iconWindowCreated) *************** *** 146,149 **** --- 157,161 ---- if (strcmp (Op, "init") == 0) { + exitNormally = FALSE; if ((mainDisplay = XOpenDisplay (NULL)) == 0) { *************** *** 156,160 **** rootWindow = RootWindow (mainDisplay, mainScreen); ! /* XSetErrorHandler (MyErrorHandler); */ Setup (); --- 168,177 ---- rootWindow = RootWindow (mainDisplay, mainScreen); ! XSetErrorHandler (EmergencySave); ! XSetIOErrorHandler (EmergencySave); ! signal (SIGHUP, EmergencySave); ! signal (SIGFPE, EmergencySave); ! signal (SIGBUS, EmergencySave); ! signal (SIGSEGV, EmergencySave); Setup (); *************** *** 175,179 **** Msg (s); ! while (ReadObj (fp, &obj_ptr)) if (obj_ptr != NULL) AddObj (NULL, topObj, obj_ptr); --- 192,196 ---- Msg (s); ! while (ReadObj (fp, &obj_ptr, FALSE)) if (obj_ptr != NULL) AddObj (NULL, topObj, obj_ptr); *************** *** 202,205 **** --- 219,223 ---- quitDraw = TRUE; XSync (mainDisplay, TRUE); + exitNormally = TRUE; AllocStrings (FuncStr, Str1, Menu1, Str2, Menu2, Str3, Menu3); strcpy (*FuncStr, "Quit"); *** menu.c.orig Thu Aug 2 09:45:23 1990 --- menu.c Thu Aug 2 09:45:25 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/menu.c,v 1.10 90/06/25 23:58:20 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/menu.c,v 1.11 90/07/30 11:00:59 william Exp $"; #endif *************** *** 525,529 **** importingFile = TRUE; /* ignore the 'state' predicate */ ! while (ReadObj (fp, &obj_ptr)) if (obj_ptr != NULL) { --- 525,529 ---- importingFile = TRUE; /* ignore the 'state' predicate */ ! while (ReadObj (fp, &obj_ptr, FALSE)) if (obj_ptr != NULL) { *** move.c.orig Thu Aug 2 09:45:32 1990 --- move.c Thu Aug 2 09:45:33 1990 *************** *** 7,11 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/move.c,v 1.5 90/06/26 00:11:08 william Exp $"; #endif #include <stdio.h> --- 7,11 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/move.c,v 1.6 90/07/07 23:57:07 william Exp $"; #endif #include <stdio.h> *************** *** 64,69 **** for (i = 0; i < ObjPtr->detail.g->sn; i++) { ! ObjPtr->detail.g->svlist[i].x += Dx; ! ObjPtr->detail.g->svlist[i].y += Dy; } } --- 64,69 ---- for (i = 0; i < ObjPtr->detail.g->sn; i++) { ! ObjPtr->detail.g->svlist[i].x += (Dx>>zoomScale); ! ObjPtr->detail.g->svlist[i].y += (Dy>>zoomScale); } } *** names.c.orig Thu Aug 2 09:45:44 1990 --- names.c Thu Aug 2 09:45:45 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/names.c,v 1.4 90/05/22 15:49:54 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/names.c,v 1.6 90/07/27 14:39:29 william Exp $"; #endif *************** *** 50,53 **** --- 50,55 ---- static int nameScrollAreaH; /* heighr of the grey scroll area */ + static int doubleClickInterval; + static GC nameGC; static GC revNameGC; *************** *** 55,58 **** --- 57,61 ---- void InitNames () { + char * c_ptr; XGCValues values; *************** *** 76,79 **** --- 79,88 ---- *curDomainName = '\0'; + + if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "DoubleClickInterval")) != + NULL) + doubleClickInterval = atoi (c_ptr); + else + doubleClickInterval = 300; } *************** *** 281,289 **** } static ! void NameDspHandler (button_ev) XButtonEvent * button_ev; { ! int row_offset, len, top; top = defaultFontAsc+1; --- 290,303 ---- } + static Time lastClickTime; + static int justClicked; + static int lastNameMarked; + static ! int NameDspHandler (button_ev) XButtonEvent * button_ev; { ! int row_offset, len, top; ! Time click_time; top = defaultFontAsc+1; *************** *** 290,294 **** row_offset = (int)(button_ev->y / ROW_HEIGHT); - if (nameMarked != INVALID && nameMarked == row_offset+nameFirst) return; if (nameMarked != INVALID && --- 304,307 ---- *************** *** 315,318 **** --- 328,341 ---- nameDspPtr[nameMarked], len); } + + click_time = button_ev->time; + if (justClicked && nameMarked != INVALID && lastNameMarked == nameMarked && + (click_time-lastClickTime) < doubleClickInterval) + return (TRUE); + + justClicked = TRUE; + lastClickTime = click_time; + lastNameMarked = nameMarked; + return (INVALID); } *************** *** 396,399 **** --- 419,423 ---- KeyPressMask | ButtonPressMask | ExposureMask); + justClicked = FALSE; while (looping) { *************** *** 475,479 **** NameScrollHandler (button_ev); else if (button_ev->window == nameDspWin) ! NameDspHandler (button_ev); } } --- 499,509 ---- NameScrollHandler (button_ev); else if (button_ev->window == nameDspWin) ! { ! if (NameDspHandler (button_ev) != INVALID) ! { ! looping = FALSE; ! index = nameMarked; ! } ! } } } *** pattern.c.orig Thu Aug 2 09:45:58 1990 --- pattern.c Thu Aug 2 09:45:59 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/pattern.c,v 1.2 90/06/26 00:11:14 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/pattern.c,v 1.3 90/07/11 21:30:41 william Exp $"; #endif *************** *** 661,663 **** --- 661,770 ---- if (index != INVALID) ChangeAllSelPen (index); + } + + static + int ToggleObjLineType (ObjPtr) + struct ObjRec * ObjPtr; + { + register struct ObjRec * obj_ptr; + register int changed = FALSE; + + for (obj_ptr = ObjPtr; obj_ptr != NULL; obj_ptr = obj_ptr->prev) + switch (obj_ptr->type) + { + case OBJ_POLY: + obj_ptr->detail.p->curved = !obj_ptr->detail.p->curved; + if (obj_ptr->detail.p->curved == LT_SPLINE) + obj_ptr->detail.p->svlist = MakeSplinePolyVertex ( + &(obj_ptr->detail.p->sn), drawOrigX, drawOrigY, + obj_ptr->detail.p->n, obj_ptr->detail.p->vlist); + else + cfree (obj_ptr->detail.p->svlist); + changed = TRUE; + AdjObjBBox (obj_ptr); + break; + case OBJ_POLYGON: + obj_ptr->detail.g->curved = !obj_ptr->detail.g->curved; + if (obj_ptr->detail.g->curved == LT_SPLINE) + obj_ptr->detail.g->svlist = MakeSplinePolygonVertex ( + &(obj_ptr->detail.g->sn), drawOrigX, drawOrigY, + obj_ptr->detail.g->n, obj_ptr->detail.g->vlist); + else + cfree (obj_ptr->detail.g->svlist); + changed = TRUE; + AdjObjBBox (obj_ptr); + break; + + case OBJ_GROUP: + case OBJ_SYM: + if (ToggleObjLineType (obj_ptr->detail.r->last)) + { + changed = TRUE; + AdjObjBBox (obj_ptr); + } + break; + } + return (changed); + } + + void ToggleAllSelLineType () + { + register struct SelRec * sel_ptr; + register struct ObjRec * obj_ptr; + register int changed = FALSE; + + if (topSel == NULL) + { + curSpline = !curSpline; + ShowLineType (); + return; + } + + for (sel_ptr = botSel; sel_ptr != NULL; sel_ptr = sel_ptr->prev) + { + obj_ptr = sel_ptr->obj; + switch (obj_ptr->type) + { + case OBJ_POLY: + obj_ptr->detail.p->curved = !(obj_ptr->detail.p->curved); + if (obj_ptr->detail.p->curved == LT_SPLINE) + obj_ptr->detail.p->svlist = MakeSplinePolyVertex ( + &(obj_ptr->detail.p->sn), drawOrigX, drawOrigY, + obj_ptr->detail.p->n, obj_ptr->detail.p->vlist); + else + cfree (obj_ptr->detail.p->svlist); + changed = TRUE; + AdjObjBBox (obj_ptr); + break; + case OBJ_POLYGON: + obj_ptr->detail.g->curved = !(obj_ptr->detail.g->curved); + if (obj_ptr->detail.g->curved == LT_SPLINE) + obj_ptr->detail.g->svlist = MakeSplinePolygonVertex ( + &(obj_ptr->detail.g->sn), drawOrigX, drawOrigY, + obj_ptr->detail.g->n, obj_ptr->detail.g->vlist); + else + cfree (obj_ptr->detail.g->svlist); + changed = TRUE; + AdjObjBBox (obj_ptr); + break; + + case OBJ_GROUP: + case OBJ_SYM: + if (ToggleObjLineType (obj_ptr->detail.r->last)) + { + changed = TRUE; + AdjObjBBox (obj_ptr); + } + break; + } + } + + if (changed) + { + SetFileModified (TRUE); + HighLightReverse (); + RedrawAnArea (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale), + selRbX+(1<<zoomScale), selRbY+(1<<zoomScale)); + HighLightForward (); + } } *** prtgif.c.orig Thu Aug 2 09:46:13 1990 --- prtgif.c Thu Aug 2 09:46:14 1990 *************** *** 6,10 **** #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/prtgif.c,v 1.9 90/06/05 10:09:52 william Exp $"; #endif --- 6,10 ---- #ifndef lint static char RCSid[] = ! "@(#)$Header: /n/kona/u/tangram/u/william/X11/TGIF/RCS/prtgif.c,v 1.14 90/07/30 11:02:37 william Exp $"; #endif *************** *** 14,37 **** #include "types.h" - #include "attr.e" - #include "box.e" #include "file.e" - #include "font.e" #include "grid.e" - #include "group.e" #include "obj.e" - #include "oval.e" - #include "pattern.e" - #include "poly.e" - #include "polygon.e" #include "setup.e" - #include "text.e" extern char * getenv (); /* extern int malloc_debug (); */ - extern int PDrawReadObj (); ! static char drawPath[MAXSTRING]; ! static short pDrawCursorH[] = { 9, 11, 13, 14, 19, 26, --- 14,30 ---- #include "types.h" #include "file.e" #include "grid.e" #include "obj.e" #include "setup.e" + #define PRTGIF (TRUE) + extern char * getenv (); /* extern int malloc_debug (); */ ! int lastFile = TRUE; ! ! short pDrawCursorH[] = { 9, 11, 13, 14, 19, 26, *************** *** 53,57 **** 11, 10, 12, 14, 18, 24 }; ! static short pDrawFontAsc[] = { 7, 8, 10, 11, 15, 20, --- 46,51 ---- 11, 10, 12, 14, 18, 24 }; ! ! short pDrawFontAsc[] = { 7, 8, 10, 11, 15, 20, *************** *** 73,77 **** 8, 8, 9, 11, 14, 19 }; ! static short pDrawFontDes[] = { 2, 3, 3, 3, 4, 6, --- 67,72 ---- 8, 8, 9, 11, 14, 19 }; ! ! short pDrawFontDes[] = { 2, 3, 3, 3, 4, 6, *************** *** 95,621 **** static ! void PDrawDumpTextObj (FP, ObjPtr) ! FILE * FP; ! register struct ObjRec * ObjPtr; ! { ! int x, y, font_size, xinc, yinc; ! struct StrRec * s_ptr; ! struct TextRec * text_ptr = ObjPtr->detail.t; ! ! if (text_ptr->pen == NONEPAT) return; ! ! curFont = text_ptr->font; ! curStyle = text_ptr->style; ! curSize = text_ptr->size; ! textJust = text_ptr->just; ! curRotate = text_ptr->rotate; ! penPat = text_ptr->pen; ! textCursorH = pDrawCursorH[FontIndex(curFont,curSize,curStyle)]; ! canvasFontAsc = pDrawFontAsc[FontIndex(curFont,curSize,curStyle)]; ! canvasFontDes = pDrawFontDes[FontIndex(curFont,curSize,curStyle)]; ! ! x = ObjPtr->x; ! y = ObjPtr->y; ! ! if (curFont == FONT_SYM) ! { ! fprintf (FP, "/Symbol "); ! font_size = pointSize[curSize]; ! fprintf (FP, "findfont [%1d 0 0 -%1d 0 %1d] makefont setfont\n", ! font_size, font_size, font_size); ! } ! else ! { ! switch (curFont) ! { ! case FONT_TIM: fprintf (FP, "/Times"); break; ! case FONT_COU: fprintf (FP, "/Courier"); break; ! case FONT_HEL: fprintf (FP, "/Helvetica"); break; ! case FONT_CEN: fprintf (FP, "/NewCenturySchlbk"); break; ! } ! switch (curStyle) ! { ! case STYLE_BI: ! switch (curFont) ! { ! case FONT_TIM: fprintf (FP, "-BoldItalic "); break; ! case FONT_COU: fprintf (FP, "-BoldOblique "); break; ! case FONT_HEL: fprintf (FP, "-BoldOblique "); break; ! case FONT_CEN: fprintf (FP, "-BoldItalic "); break; ! } ! break; ! case STYLE_BR: fprintf (FP, "-Bold "); break; ! case STYLE_NI: ! switch (curFont) ! { ! case FONT_TIM: fprintf (FP, "-Italic "); break; ! case FONT_COU: fprintf (FP, "-Oblique "); break; ! case FONT_HEL: fprintf (FP, "-Oblique "); break; ! case FONT_CEN: fprintf (FP, "-Italic "); break; ! } ! break; ! case STYLE_NR: ! switch (curFont) ! { ! case FONT_TIM: fprintf (FP, "-Roman "); break; ! case FONT_COU: fprintf (FP, " "); break; ! case FONT_HEL: fprintf (FP, " "); break; ! case FONT_CEN: fprintf (FP, "-Roman "); break; ! } ! break; ! } ! font_size = pointSize[curSize]; ! fprintf (FP, "findfont [%1d 0 0 -%1d 0 %1d] makefont setfont\n", ! font_size, font_size, font_size); ! } ! ! switch (penPat) ! { ! case SOLIDPAT: fprintf (FP, " 0 setgray\n"); break; ! case BACKPAT: fprintf (FP, " 1 setgray\n"); break; ! default: ! fprintf (FP, " pat%1d 8 1 0 72 300 32 div div setpattern\n", penPat); ! break; ! } ! ! switch (curRotate) ! { ! case ROTATE0: xinc = 0; yinc = textCursorH; break; ! case ROTATE90: xinc = -textCursorH; yinc = 0; break; ! case ROTATE180: xinc = 0; yinc = -textCursorH; break; ! case ROTATE270: xinc = textCursorH; yinc = 0; break; ! } ! ! for (s_ptr = text_ptr->first; s_ptr != NULL; s_ptr = s_ptr->next) ! { ! switch (curRotate) ! { ! case ROTATE0: ! fprintf (FP, " %1d %1d moveto (", x, y-canvasFontDes); ! break; ! case ROTATE90: ! fprintf (FP, " %1d %1d moveto 90 rotate (", x+canvasFontDes, y); ! break; ! case ROTATE180: ! fprintf (FP, " %1d %1d moveto 180 rotate (", x, y+canvasFontDes); ! break; ! case ROTATE270: ! fprintf (FP, " %1d %1d moveto 270 rotate (", x-canvasFontDes, y); ! break; ! } ! DumpOneStr (FP, s_ptr->s); ! switch (textJust) ! { ! case JUST_L: fprintf (FP, ") show"); break; ! case JUST_C: fprintf (FP, ") centertext"); break; ! case JUST_R: fprintf (FP, ") righttext"); break; ! } ! switch (curRotate) ! { ! case ROTATE0: fprintf (FP, "\n"); break; ! case ROTATE90: fprintf (FP, " -90 rotate \n"); break; ! case ROTATE180: fprintf (FP, " -180 rotate \n"); break; ! case ROTATE270: fprintf (FP, " -270 rotate \n"); break; ! } ! x += xinc; ! y += yinc; ! } ! fprintf (FP, "\n"); ! fprintf (FP, " 0 setgray\n"); ! } ! ! static ! void PDrawDumpAttrs (FP, AttrPtr) ! FILE * FP; ! register struct AttrRec * AttrPtr; ! { ! for ( ; AttrPtr != NULL; AttrPtr = AttrPtr->prev) ! if (AttrPtr->shown) ! PDrawDumpTextObj (FP, AttrPtr->obj); ! } ! ! static ! void PDrawDumpAllObj (FP, ObjPtr) ! FILE * FP; ! register struct ObjRec * ObjPtr; ! { ! register struct ObjRec * obj_ptr; ! ! switch (ObjPtr->type) ! { ! case OBJ_POLY: ! DumpPolyObj (FP, ObjPtr); ! PDrawDumpAttrs (FP, ObjPtr->detail.p->lattr); ! break; ! case OBJ_BOX: DumpBoxObj (FP, ObjPtr); break; ! case OBJ_OVAL: DumpOvalObj (FP, ObjPtr); break; ! case OBJ_TEXT: PDrawDumpTextObj (FP, ObjPtr); break; ! case OBJ_POLYGON: DumpPolygonObj (FP, ObjPtr); break; ! case OBJ_SYM: ! case OBJ_ICON: ! case OBJ_GROUP: ! obj_ptr = ObjPtr->detail.r->last; ! for ( ; obj_ptr != NULL; obj_ptr = obj_ptr->prev) ! PDrawDumpAllObj (FP, obj_ptr); ! PDrawDumpAttrs (FP, ObjPtr->detail.r->lattr); ! if (ObjPtr->type == OBJ_SYM) DumpSymOutline (FP, ObjPtr); ! break; ! } ! } ! ! static struct StrRec * pDrawFirstStr = NULL, * pDrawLastStr = NULL; ! ! static ! void PDrawAddStr (PrevPtr, NextPtr, StrPtr) ! struct StrRec * PrevPtr, * NextPtr, * StrPtr; ! { ! StrPtr->prev = PrevPtr; ! StrPtr->next = NextPtr; ! ! if (PrevPtr == NULL) ! pDrawFirstStr = StrPtr; ! else ! PrevPtr->next = StrPtr; ! ! if (NextPtr == NULL) ! pDrawLastStr = StrPtr; ! else ! NextPtr->prev = StrPtr; ! } ! ! static ! void PDrawReadTextObj (FP, Inbuf, ObjPtr) ! FILE * FP; ! char * Inbuf; ! struct ObjRec * * ObjPtr; ! { ! register int i; ! struct StrRec * s_ptr; ! struct TextRec * text_ptr; ! char color_str[80], * s; ! char tmp_str[MAXSTRING+1], inbuf[MAXSTRING+1]; ! int num_lines, x, y, font, style, size; ! int text_just, rotate, pen; ! ! * ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); ! s = FindChar ('(', Inbuf); ! s = ParseStr (s, ',', color_str); ! if (fileVersion <= 2) ! { ! sscanf (s, "%d , %d , %d , %d , %d , %d , %d", &x, &y, &font, &style, ! &size, &num_lines, &text_just); ! rotate = 0; ! pen = 1; ! } ! else ! sscanf (s, "%d , %d , %d , %d , %d , %d , %d , %d , %d", &x, &y, &font, ! &style, &size, &num_lines, &text_just, &rotate, &pen); ! ! text_ptr = (struct TextRec *) calloc (1, sizeof(struct TextRec)); ! text_ptr->just = text_just; ! text_ptr->lines = num_lines; ! text_ptr->rotate = rotate; ! text_ptr->pen = pen; ! ! curFont = text_ptr->font = font; ! curStyle = text_ptr->style = style; ! curSize = text_ptr->size = size; ! textJust = text_just; ! curRotate = rotate; ! penPat = pen; ! textCursorH = pDrawCursorH[FontIndex(curFont,curSize,curStyle)]; ! canvasFontAsc = pDrawFontAsc[FontIndex(curFont,curSize,curStyle)]; ! ! for (i = 0; i < num_lines; i++) ! { ! fgets (inbuf, MAXSTRING, FP); ! strcpy(tmp_str, FindChar ('"', inbuf)); ! s = FindChar ('"', tmp_str); ! *(--s) = '\0'; ! s_ptr = (struct StrRec *) calloc (1, sizeof(struct StrRec)); ! strcpy (s_ptr->s, tmp_str); ! PDrawAddStr (pDrawLastStr, NULL, s_ptr); ! } ! text_ptr->first = pDrawFirstStr; ! text_ptr->last = pDrawLastStr; ! ! pDrawFirstStr = pDrawLastStr = NULL; ! ! (*ObjPtr)->x = x; ! (*ObjPtr)->y = y; ! (*ObjPtr)->type = OBJ_TEXT; ! (*ObjPtr)->color = FindColorIndex (color_str); ! (*ObjPtr)->detail.t = text_ptr; ! } ! ! static ! void PDrawReadState (Inbuf) ! char * Inbuf; ! { ! char * s; ! ! s = FindChar ('(', Inbuf); ! sscanf (s, "%d", &pageStyle); ! s = FindChar (',', s); ! if (*s == '\0') ! fileVersion = INVALID; ! else ! sscanf (s, "%d", &fileVersion); ! } ! ! static ! void PDrawReadGroupObj (FP, ObjPtr) ! FILE * FP; ! struct ObjRec * * ObjPtr; ! { ! struct GroupRec * group_ptr; ! struct ObjRec * top_obj = NULL, * bot_obj = NULL, * obj_ptr; ! int ltx, lty, rbx, rby; ! int obj_ltx, obj_lty, obj_rbx, obj_rby; ! ! * ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); ! ! while (PDrawReadObj (FP, &obj_ptr)) ! { ! obj_ptr->next = top_obj; ! if (top_obj == NULL) ! bot_obj = obj_ptr; ! else ! top_obj->prev = obj_ptr; ! top_obj = obj_ptr; ! } ! top_obj->prev = NULL; ! ! group_ptr = (struct GroupRec *) calloc (1, sizeof(struct GroupRec)); ! group_ptr->first = top_obj; ! group_ptr->last = bot_obj; ! ! ltx = top_obj->bbox.ltx; ! lty = top_obj->bbox.lty; ! rbx = top_obj->bbox.rbx; ! rby = top_obj->bbox.rby; ! obj_ltx = top_obj->obbox.ltx; ! obj_lty = top_obj->obbox.lty; ! obj_rbx = top_obj->obbox.rbx; ! obj_rby = top_obj->obbox.rby; ! for (obj_ptr = top_obj->next; obj_ptr != NULL; obj_ptr = obj_ptr->next) ! { ! if (obj_ptr->bbox.ltx < ltx) ltx = obj_ptr->bbox.ltx; ! if (obj_ptr->bbox.lty < lty) lty = obj_ptr->bbox.lty; ! if (obj_ptr->bbox.rbx > rbx) rbx = obj_ptr->bbox.rbx; ! if (obj_ptr->bbox.rby > rby) rby = obj_ptr->bbox.rby; ! if (obj_ptr->obbox.ltx < obj_ltx) obj_ltx = obj_ptr->obbox.ltx; ! if (obj_ptr->obbox.lty < obj_lty) obj_lty = obj_ptr->obbox.lty; ! if (obj_ptr->obbox.rbx > obj_rbx) obj_rbx = obj_ptr->obbox.rbx; ! if (obj_ptr->obbox.rby > obj_rby) obj_rby = obj_ptr->obbox.rby; ! } ! ! (*ObjPtr)->x = obj_ltx; ! (*ObjPtr)->y = obj_lty; ! (*ObjPtr)->type = OBJ_GROUP; ! (*ObjPtr)->bbox.ltx = ltx; ! (*ObjPtr)->bbox.lty = lty; ! (*ObjPtr)->bbox.rbx = rbx; ! (*ObjPtr)->bbox.rby = rby; ! (*ObjPtr)->obbox.ltx = obj_ltx; ! (*ObjPtr)->obbox.lty = obj_lty; ! (*ObjPtr)->obbox.rbx = obj_rbx; ! (*ObjPtr)->obbox.rby = obj_rby; ! (*ObjPtr)->detail.r = group_ptr; ! } ! ! static ! int PDrawReadAttr (FP, AttrPtr) ! FILE * FP; ! struct AttrRec * * AttrPtr; ! { ! struct ObjRec * TextObj; ! char inbuf[MAXSTRING+1], * s; ! char name[MAXSTRING+1], value[MAXSTRING+1]; ! int len, shown, nameshown, inherited; ! ! fgets (inbuf, MAXSTRING, FP); ! ! if (inbuf[0] == ']') return (FALSE); ! ! *AttrPtr = (struct AttrRec *) calloc (1, sizeof(struct AttrRec)); ! ! len = strlen(inbuf) - 1; ! inbuf[len] = '\0'; ! ! strcpy(name, FindChar ('"', inbuf)); ! s = FindChar ('"', inbuf); ! s = FindChar (',', s); ! strcpy(value, FindChar ('"', s)); ! s = FindChar ('"', value); ! s = FindChar (',', s); ! sscanf (s, "%d, %d, %d", &shown, &nameshown, &inherited); ! ! s = FindChar ('"', name); ! *(--s) = '\0'; ! strcpy ((*AttrPtr)->name, name); ! s = FindChar ('"', value); ! *(--s) = '\0'; ! strcpy ((*AttrPtr)->s, value); ! ! (*AttrPtr)->shown = shown; ! (*AttrPtr)->nameshown = nameshown; ! (*AttrPtr)->inherited = inherited; ! ! PDrawReadObj (FP, &TextObj); ! TextObj->detail.t->attr = *AttrPtr; ! (*AttrPtr)->obj = TextObj; ! ! return (TRUE); ! } ! ! int PDrawReadObj (FP, ObjPtr) ! FILE * FP; ! struct ObjRec * * ObjPtr; ! { ! char inbuf[MAXSTRING+1], obj_name[10], tmp_str[MAXSTRING+1]; ! char * s, * s1; ! int len, id; ! struct AttrRec * top_attr = NULL, * bot_attr = NULL, * attr_ptr; ! ! while (fgets (inbuf, MAXSTRING, FP) != NULL) ! { ! if (inbuf[0] == ']') return (FALSE); ! ! len = strlen(inbuf)-1; ! inbuf[len] = '\0'; ! ParseStr (inbuf, '(', obj_name); ! if (strcmp (obj_name, "poly") == 0) ! { ! ReadPolyObj (inbuf, ObjPtr); ! if (fileVersion != INVALID) ! while (PDrawReadAttr (FP, &attr_ptr)) ! { ! attr_ptr->owner = *ObjPtr; ! attr_ptr->prev = NULL; ! attr_ptr->next = top_attr; ! if (top_attr == NULL) ! bot_attr = attr_ptr; ! else ! top_attr->prev = attr_ptr; ! top_attr = attr_ptr; ! } ! if (bot_attr != NULL) bot_attr->next = NULL; ! (*ObjPtr)->detail.p->fattr = top_attr; ! (*ObjPtr)->detail.p->lattr = bot_attr; ! AdjObjBBox (*ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "box") == 0) ! { ! ReadBoxObj (inbuf, ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "oval") == 0) ! { ! ReadOvalObj (inbuf, ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "text") == 0) ! { ! PDrawReadTextObj (FP, inbuf, ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "polygon") == 0) ! { ! ReadPolygonObj (inbuf, ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "group") == 0) ! { ! PDrawReadGroupObj (FP, ObjPtr); ! if (fileVersion != INVALID) ! while (PDrawReadAttr (FP, &attr_ptr)) ! { ! attr_ptr->owner = *ObjPtr; ! attr_ptr->prev = NULL; ! attr_ptr->next = top_attr; ! if (top_attr == NULL) ! bot_attr = attr_ptr; ! else ! top_attr->prev = attr_ptr; ! top_attr = attr_ptr; ! } ! if (bot_attr != NULL) bot_attr->next = NULL; ! (*ObjPtr)->detail.r->fattr = top_attr; ! (*ObjPtr)->detail.r->lattr = bot_attr; ! AdjObjBBox (*ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "sym") == 0) ! { ! PDrawReadGroupObj (FP, ObjPtr); ! (*ObjPtr)->type = OBJ_SYM; ! if (fileVersion != INVALID) ! while (PDrawReadAttr (FP, &attr_ptr)) ! { ! attr_ptr->owner = *ObjPtr; ! attr_ptr->prev = NULL; ! attr_ptr->next = top_attr; ! if (top_attr == NULL) ! bot_attr = attr_ptr; ! else ! top_attr->prev = attr_ptr; ! top_attr = attr_ptr; ! } ! if (bot_attr != NULL) bot_attr->next = NULL; ! (*ObjPtr)->detail.r->fattr = top_attr; ! (*ObjPtr)->detail.r->lattr = bot_attr; ! AdjObjBBox (*ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "icon") == 0) ! { ! PDrawReadGroupObj (FP, ObjPtr); ! (*ObjPtr)->type = OBJ_ICON; ! if (fgets (inbuf, MAXSTRING, FP) == NULL) return (FALSE); ! ! strcpy(tmp_str, FindChar ('"', inbuf)); ! s = FindChar ('"', tmp_str); ! if (fileVersion != INVALID) ! { ! s1 = FindChar (',', s); ! sscanf (s1, "%d", &id); ! if (id >= objId) objId = id+1; ! (*ObjPtr)->detail.r->id = id; ! } ! (*ObjPtr)->detail.r->dirty = FALSE; ! *(--s) = '\0'; ! strcpy ((*ObjPtr)->detail.r->s, tmp_str); ! if (fileVersion != INVALID) ! while (PDrawReadAttr (FP, &attr_ptr)) ! { ! attr_ptr->owner = *ObjPtr; ! attr_ptr->prev = NULL; ! attr_ptr->next = top_attr; ! if (top_attr == NULL) ! bot_attr = attr_ptr; ! else ! top_attr->prev = attr_ptr; ! top_attr = attr_ptr; ! } ! if (bot_attr != NULL) bot_attr->next = NULL; ! (*ObjPtr)->detail.r->fattr = top_attr; ! (*ObjPtr)->detail.r->lattr = bot_attr; ! AdjObjBBox (*ObjPtr); ! return (TRUE); ! } ! else if (strcmp (obj_name, "state") == 0) ! { ! PDrawReadState (inbuf); ! *ObjPtr = NULL; ! return (TRUE); ! } ! } ! return (FALSE); ! } ! ! static ! void PDrawLoad (FileName) char * FileName; { --- 90,94 ---- static ! int PDrawLoad (FileName) char * FileName; { *************** *** 630,634 **** { printf ("Can not open '%s'.", full_name); ! return; } --- 103,107 ---- { printf ("Can not open '%s'.", full_name); ! return (FALSE); } *************** *** 635,639 **** printf ("Reading '%s' ...\n", full_name); ! while (PDrawReadObj (fp, &obj_ptr)) if (obj_ptr != NULL) AddObj (NULL, topObj, obj_ptr); --- 108,112 ---- printf ("Reading '%s' ...\n", full_name); ! while (ReadObj (fp, &obj_ptr, PRTGIF)) if (obj_ptr != NULL) AddObj (NULL, topObj, obj_ptr); *************** *** 640,714 **** fclose (fp); } - static - void PDrawDump () - { - register struct ObjRec * obj_ptr; - char cmd[MAXSTRING+1], tmp_str[MAXSTRING+1]; - char tmp_file[MAXSTRING+1], ps_file[MAXSTRING+1]; - FILE * fp, * fps; - - if (botObj == NULL) { printf ("No object to print."); return; } - - strcpy (tmp_file, "/tmp/TgifXXXXXX"); - mktemp (tmp_file); - unlink (tmp_file); - - if ((fp = fopen (tmp_file, "w")) == NULL) - { - printf ("Can not create $s, print aborted.", tmp_file); - return; - } - - printf ("Writing to %s ...\n", tmp_file); - - fprintf (fp, "%%!\n"); - DumpBBox (fp); - sprintf(ps_file, "%s/.psmac", drawPath); - if ((fps = fopen (ps_file, "r")) == NULL) - { - printf ("Can not find %s, print aborted.\n", ps_file); - fclose (fp); - unlink (tmp_file); - return; - } - while (fgets (tmp_str, 256, fps) != NULL) /* copy the header file */ - fputs (tmp_str, fp); - - fprintf (fp, "gsave\n\n"); - switch (pageStyle) - { - case LANDSCAPE: - case HIGHLAND: - case SLIDELAND: fprintf (fp, "90 rotate\n"); break; - } - fprintf (fp, "%1d %s mul %1d %s mul translate\n", psDotsPerInch, - psXOffStr[pageStyle], psDotsPerInch, psYOffStr[pageStyle]); - fprintf (fp, "%s -%s scale\n\n", - psScaleStr[pageStyle], psScaleStr[pageStyle]); - - for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev) - PDrawDumpAllObj (fp, obj_ptr); - - fprintf (fp, "grestore\n\n"); - fprintf (fp, "showpage\n"); - fclose (fp); - - sprintf (cmd, "lpr %s 2>&1", tmp_file); - if ((fp = popen (cmd, "r")) == NULL) - { - printf ("Can not execute '%s', print aborted.\n", cmd); - unlink (tmp_file); - return; - } - while (fgets (tmp_str, 256, fp) != NULL) sleep (5); - - pclose (fp); - unlink (tmp_file); - - printf ("%s printed.\n\n", tmp_file); - } - main (argc, argv) int argc; --- 113,119 ---- fclose (fp); + return (TRUE); } main (argc, argv) int argc; *************** *** 717,720 **** --- 122,126 ---- char inbuf[MAXSTRING+1]; char * c_ptr; + int len; /* malloc_debug (1); */ *************** *** 729,732 **** --- 135,145 ---- strcpy (drawPath, c_ptr); + if ((argc > 1) && (strcmp (argv[1], "-p") == 0)) + { + whereToPrint = LATEX_FIG; + argv++; + argc--; + } + switch (argc) { *************** *** 735,740 **** while (fgets (inbuf, MAXSTRING, stdin) != NULL) { ! PDrawLoad (inbuf); ! PDrawDump (); printf ("\nDraw File Name to Print> "); } --- 148,161 ---- while (fgets (inbuf, MAXSTRING, stdin) != NULL) { ! len = strlen (inbuf); ! if (len > 0) ! { ! if (inbuf[--len] == '\n') inbuf[len] = '\0'; ! if (PDrawLoad (inbuf)) ! { ! Dump (PRTGIF, inbuf); ! DelAllObj (); ! } ! } printf ("\nDraw File Name to Print> "); } *************** *** 743,750 **** for (argc--, argv++; argc > 0; argc--, argv++) { ! PDrawLoad (*argv); ! PDrawDump (); ! DelAllObj (); } } } --- 164,175 ---- for (argc--, argv++; argc > 0; argc--, argv++) { ! lastFile = (argc == 1); ! if (PDrawLoad (*argv)) ! { ! Dump (PRTGIF, *argv); ! DelAllObj (); ! } } } + exit (0); } ---------------------------------> cut here <--------------------------------- -- Bill Cheng // UCLA Computer Science Department // (213) 206-7135 3277 Boelter Hall // Los Angeles, California 90024 // USA william@CS.UCLA.EDU ...!{uunet|ucbvax}!cs.ucla.edu!william dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.