Commit | Line | Data |
---|---|---|
70170e36 | 1 | /* @(#)long2.c 1.2 %G% |
1acf8029 DS |
2 | * |
3 | * Copyright -C- 1982 Barry S. Roitblat | |
4 | * | |
5 | * | |
6 | * This file contains routines to implement the long text commands | |
7 | * of the gremlin PICTURE editor. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include "gremlin.h" | |
12 | #include "grem2.h" | |
13 | #include <ctype.h> | |
14 | ||
15 | /* imports from graphics files */ | |
16 | ||
17 | extern GRVector(), GRArc(), GRPutText(), GRClose(); | |
18 | extern GRDisplayPoint(), GRDeletePoint(), GRBlankPoints(); | |
19 | extern charxsize, charysize, GrXMax, GrYMax; | |
20 | ||
21 | /* import from path.c */ | |
22 | ||
23 | extern int PSetPath(), PConvertTilde(); | |
24 | extern char *PGetPath(); | |
25 | ||
26 | /* imports from display.c */ | |
27 | ||
28 | extern DISScreenAdd(), DISScreenErase(); | |
29 | extern DISDisplaySet(), DISEraseSet(), DISClearSetDisplay(); | |
30 | ||
31 | /* imports from database files */ | |
32 | ||
33 | extern ELT *DBInit(), *DBCreateElt(), *DBRead(); | |
34 | extern DBDelete(), DBGravitate(), DBClearElt(); | |
35 | extern ELT *DBCopy(); | |
36 | extern DBXform(), DBChangeBrush(); | |
37 | extern DBAddSet(), DBClearSet(); | |
38 | extern POINT *PTInit(), *PTMakePoint(); | |
39 | extern PTDeletePoint(); | |
40 | ||
41 | /* imports from undodb.c */ | |
42 | ||
43 | extern UNELT *unlist, *unback; | |
44 | extern UNForget(); | |
45 | ||
46 | /* imports from short.c */ | |
47 | ||
48 | extern SHUpdate(); | |
49 | extern int adj[]; | |
50 | ||
51 | /* imports from textio.c */ | |
52 | ||
53 | extern TxPutString(), TxPutMsg(), TxMsgOK(), TxClose(); | |
54 | extern TXFIELD TAlign, TAdjust, TBrush, TFont, TGravity, TCSize; | |
55 | extern TEdit, TJustmode; | |
56 | ||
57 | /* imports from menu.c */ | |
58 | ||
59 | extern MNHighLt(), MNUnHighLt(); | |
60 | extern HiMen[], HiFont[], HiBrush[], HiMode[]; | |
61 | ||
62 | /* imports from c */ | |
63 | ||
64 | extern char *malloc(); | |
65 | extern char *strcpy(), *sprintf(); | |
66 | ||
67 | /* imports from main.c */ | |
68 | ||
69 | extern ELT *PICTURE; /* current PICTURE database */ | |
70 | extern ELT *cset; /* current set database */ | |
71 | extern CBRUSH, CSIZE, CFONT; /* current brush, size, font */ | |
72 | extern CJUST; /* current text justification */ | |
73 | extern Gridon; /* grid mode flag */ | |
74 | extern Orientation; /* orientation of workspace */ | |
75 | extern SEARCH; /* flag for path search */ | |
76 | extern Alignment; /* point alignment indicator */ | |
77 | extern float PX, PY; /* cursor coordinates */ | |
78 | extern float Lastx, Lasty; /* previous cursor coordinates */ | |
79 | extern SEQ; /* point sequence number */ | |
80 | extern POINT *POINTLIST, *BACKPOINT;/* accumulated point list */ | |
81 | extern Gridsize; /* grid spacing */ | |
82 | extern Adjustment; /* point adjustment mode */ | |
83 | extern GravityOn; /* gravity mode flag */ | |
84 | extern Consume; /* point clear flag */ | |
85 | extern CHANGED; /* PICTURE changed flag */ | |
86 | extern ELT *MEN[]; /* pointers for user symbols */ | |
87 | extern POINT MENPOINT[]; /* pointers used fo user symbols */ | |
88 | extern cmdbuf[]; /* line buffer for commands */ | |
89 | extern char *textpos[], *dispmode[];/* text positioning modes */ | |
90 | extern int textmode[]; /* text positioning */ | |
91 | extern char *lines[], *fonts[]; /* line and character styles */ | |
92 | extern int jmodes, lnum[], fnum[]; | |
93 | ||
94 | /* imports from long1.c */ | |
95 | extern bang; | |
96 | extern GetNumParm(); | |
97 | extern LGLookup(); | |
98 | extern SetOrient(); | |
99 | ||
100 | char *Editfile; | |
101 | ||
102 | #define BADNUM -1 | |
103 | #define NONUM -2 | |
104 | #define Delimiter(c) ((c == '\0') || (c == ' ') || (c == ',')) | |
105 | ||
106 | static char badarg[10] = "bad args"; | |
107 | ||
70170e36 | 108 | |
1acf8029 DS |
109 | LGFont(line) |
110 | char *line; | |
111 | /* | |
112 | * This routine looks at the command line for parameters to set | |
113 | * the current Font. | |
114 | */ | |
115 | ||
116 | { | |
117 | int new, index; | |
118 | char string[2]; | |
119 | ||
120 | Consume = FALSE; | |
121 | index = 0; | |
122 | if (isalpha(*(++line))) | |
123 | { | |
124 | new = LGLookup(line, fonts, &index); | |
125 | if ( new >= 0) new = fnum[new]; | |
126 | else new = BADNUM; | |
127 | } | |
128 | else new = GetNumParm(line, &index); | |
129 | if ( (new == BADNUM) || (new > NFONTS) ) | |
130 | { | |
131 | error(badarg); | |
132 | return; | |
133 | } | |
134 | if (new != NONUM) | |
135 | { | |
136 | MNUnHighLt(HiFont[CFONT-1]); | |
137 | MNHighLt(HiFont[new-1], hicolor); | |
138 | CFONT = new; | |
139 | (void) sprintf(string, "%1d",new); | |
140 | TxPutString(&TFont,string); | |
141 | } | |
142 | } /* end LGFont */ | |
143 | ||
70170e36 | 144 | |
1acf8029 DS |
145 | LGJust(line) |
146 | char *line; | |
147 | /* | |
148 | * This routine looks at the command line for parameters to set | |
149 | * the current text justification mode. | |
150 | */ | |
151 | ||
152 | { | |
153 | int new, index; | |
154 | ||
155 | Consume = FALSE; | |
156 | index = 0; | |
157 | if (isalpha(*(++line))) | |
158 | { | |
159 | /* make sure mode is in lower case, and look up in table */ | |
160 | if (isupper(*line)) | |
161 | { | |
162 | *line = tolower(*line); | |
163 | *(line+1) = tolower(*(line+1)); | |
164 | } | |
165 | for (new = 0; (strcmp(line, textpos[new]) != 0); ++new) | |
166 | if (new > jmodes) | |
167 | { | |
168 | error("no such mode"); | |
169 | return; | |
170 | } | |
171 | if ( new < 0) new = BADNUM; | |
172 | } | |
173 | else new = GetNumParm(line, &index) - 1; | |
174 | if ( (new <= BADNUM) || (new > jmodes) ) | |
175 | { | |
176 | error(badarg); | |
177 | return; | |
178 | } | |
179 | if (new != NONUM) | |
180 | { | |
181 | new = textmode[new]; | |
182 | CJUST = new; | |
183 | TxPutString(&TJustmode,dispmode[new]); | |
184 | } | |
185 | } /* end LGJust */ | |
186 | ||
70170e36 | 187 | |
1acf8029 DS |
188 | LGSize(line) |
189 | char *line; | |
190 | /* | |
191 | * This routine changes the current character size. | |
192 | */ | |
193 | ||
194 | { | |
195 | int new, index; | |
196 | char string[2]; | |
197 | ||
198 | index = 1; | |
199 | new = GetNumParm(line, &index); | |
200 | if ( (new == BADNUM) || (new > NSIZES) ) | |
201 | { | |
202 | error(badarg); | |
203 | return; | |
204 | } | |
205 | if (new != NONUM) | |
206 | { | |
207 | CSIZE = new; | |
208 | (void) sprintf(string, "%1d",new); | |
209 | TxPutString(&TCSize,string); | |
210 | } | |
211 | Consume = FALSE; | |
212 | } /* end LGSize */ | |
213 | ||
214 | LGAlign(line) | |
215 | char *line; | |
216 | /* | |
217 | * This routine sets the point alignment indicator | |
218 | */ | |
219 | ||
220 | { | |
221 | int newalign, index; | |
222 | char string[4]; | |
223 | ||
224 | index = 1; | |
225 | newalign = GetNumParm(line, &index); | |
226 | if (newalign == NONUM) | |
227 | if (Alignment == 1) Alignment = Gridsize; | |
228 | else Alignment = 1; | |
229 | else | |
230 | { | |
231 | if ((newalign < 1) || (newalign > GrYMax/2) ) | |
232 | { | |
233 | error(badarg); | |
234 | return; | |
235 | } | |
236 | Alignment = newalign; | |
237 | } | |
238 | (void) sprintf(string, "%3d",Alignment); | |
239 | TxPutString(&TAlign,string); | |
240 | Consume = FALSE; | |
241 | } /* end LGAlign */ | |
242 | ||
70170e36 | 243 | |
1acf8029 DS |
244 | LGIncludeSet(line) |
245 | char *line; | |
246 | /* | |
247 | * This routine adds all elements selected by points in POINTLIST | |
248 | * to the current set. It does not remove previously selected elements. | |
249 | * | |
250 | */ | |
251 | ||
252 | { | |
253 | POINT *p1, *p2; | |
254 | ELT *e1; | |
255 | float n1, n2; | |
256 | ||
257 | if (DBNullelt(PICTURE)) return; | |
258 | if (SEQ == 0) /* no points: entire picture becomes */ | |
259 | { /* current set */ | |
260 | e1 = PICTURE; | |
261 | while ( !DBNullelt(e1) ) | |
262 | { | |
263 | DBAddSet(e1); | |
264 | DISDisplaySet(e1); | |
265 | e1 = DBNextElt(e1); | |
266 | } | |
267 | } /* end if */ | |
268 | else | |
269 | { | |
270 | p1 = POINTLIST; | |
271 | while ( !Nullpoint(p1) ) | |
272 | { | |
273 | DBGravitate(p1->x, p1->y, &n1, &n2, &p2, &e1, PICTURE); | |
274 | if ( !DBNullelt(e1) ) | |
275 | { | |
276 | DBAddSet(e1); | |
277 | DISDisplaySet(e1); | |
278 | } | |
279 | p1 = PTNextPoint(p1); | |
280 | } /* end while */; | |
281 | } /* end else */ | |
282 | } /* end LGIncludeSet */ | |
283 | ||
284 | ||
70170e36 | 285 | |
1acf8029 DS |
286 | LGMenu(line) |
287 | char *line; | |
288 | /* | |
289 | * This routine implements the menu command. The contents of | |
290 | * the specified user menu item is copied into the PICTURE transformed | |
291 | * to the positioning point. | |
292 | */ | |
293 | ||
294 | { | |
295 | ||
296 | ELT *elist, *e1; | |
297 | POINT *plist; | |
298 | int symbol, index; | |
299 | float xmat[3][2]; | |
300 | ||
301 | if (SEQ < 1) | |
302 | { | |
303 | error("no positioning point"); | |
304 | return; | |
305 | } | |
306 | index = 1; | |
307 | symbol = GetNumParm(line, &index); | |
308 | if ( (symbol <= 0) || (symbol > NUSER) ) | |
309 | { | |
310 | error(badarg); | |
311 | return; | |
312 | } | |
313 | symbol--; /* users inputs number between 1 and N, actual | |
314 | symbol number is between 0 and N-1 */ | |
315 | xmat[0][0] = xmat[1][1] = 1; /* create transformation matrix */ | |
316 | xmat[0][1] = xmat[1][0] = 0; /* for copy into PICTURE */ | |
317 | plist = POINTLIST; | |
318 | while ( !Nullpoint(plist) ) | |
319 | { | |
320 | DISClearSetDisplay(); /* Clear old current set */ | |
321 | DBClearSet(); | |
322 | xmat[2][0] = plist->x - (MENPOINT[symbol]).x; | |
323 | xmat[2][1] = plist->y - (MENPOINT[symbol]).y; | |
324 | elist = MEN[symbol]; | |
325 | while ( !DBNullelt(elist) ) /* copy buffer to picture */ | |
326 | { | |
327 | e1 = DBCopy(elist, xmat, &PICTURE); | |
328 | DBAddSet(e1); | |
329 | DISScreenAdd(e1, (linemask | setmask)); | |
330 | elist = DBNextElt(elist); | |
331 | } /* end while */ | |
332 | plist = PTNextPoint(plist); | |
333 | } /* end while */ | |
334 | CHANGED = TRUE; | |
335 | } /* end LGMenu */ | |
336 | ||
70170e36 | 337 | |
1acf8029 DS |
338 | LGRead(line) |
339 | char *line; | |
340 | /* | |
341 | * This routine reads in the specified filename (command line) to the | |
342 | * selected user symbol or current set if no user symbol is selected. If | |
343 | * no filename is specified, the current set is copied to the user symbol; | |
344 | */ | |
345 | ||
346 | { | |
347 | POINT pos, ppos; | |
348 | ELT *elist, *e1; | |
349 | char tname[50], filename[100]; | |
350 | float xmat[3][2]; | |
351 | int i, orient; | |
352 | ||
353 | if ( *line == '\0' ) /* no arguments */ | |
354 | { | |
355 | error(badarg); | |
356 | return; | |
357 | } | |
358 | ++line; | |
359 | (void) sscanf(line, "%s", tname); | |
360 | elist = DBRead(tname, &orient, &pos); /* read file */ | |
361 | UNForget(); /* forget changes registered by DBRead */ | |
362 | if (SEQ < 1) /* no positioning point */ | |
363 | { | |
364 | ppos.x = pos.x; | |
365 | ppos.y = pos.y; | |
366 | } | |
367 | else | |
368 | { | |
369 | ppos.x = POINTLIST->x; | |
370 | ppos.y = POINTLIST->y; | |
371 | } | |
372 | xmat[0][0] = xmat[1][1] = 1; /* set up matrix to copy to */ | |
373 | xmat[0][1] = xmat[1][0] = 0; /* appropriate place in */ | |
374 | xmat[2][0] = ppos.x - pos.x; /* picture as current set */ | |
375 | xmat[2][1] = ppos.y - pos.y; | |
376 | DBClearSet(); | |
377 | DISClearSetDisplay(); | |
378 | while ( !DBNullelt(elist) ) | |
379 | { | |
380 | e1 = DBCopy(elist, xmat, &PICTURE); | |
381 | DISScreenAdd(e1, (linemask | setmask)); | |
382 | DBAddSet(e1); | |
383 | e1 = DBNextElt(elist); | |
384 | DBClearElt(elist); | |
385 | elist = e1; | |
386 | } | |
387 | CHANGED = TRUE; | |
388 | } /* end LGRead */ | |
389 | ||
70170e36 | 390 | |
1acf8029 DS |
391 | LGEdit(line) |
392 | char *line; | |
393 | /* | |
394 | * This routine reads in a new PICTURE for editing | |
395 | */ | |
396 | ||
397 | { | |
398 | FILE *fp, *POpen(); | |
399 | POINT pos; | |
400 | ELT *e1; | |
401 | char *tn, tname[50]; | |
402 | int i; | |
403 | ||
404 | if (!bang) /* no ! */ | |
405 | { | |
406 | if (CHANGED) | |
407 | { | |
408 | error("no write"); | |
409 | return; | |
410 | } | |
411 | } /* end if !bang */; | |
412 | DBClearSet(); | |
413 | while ( !DBNullelt(PICTURE) ) /* clear current PICTURE */ | |
414 | { | |
415 | e1 = DBNextElt(PICTURE); | |
416 | DBClearElt(PICTURE); | |
417 | PICTURE = e1; | |
418 | }; | |
419 | ++line; | |
420 | tn = tname; | |
421 | (void) sscanf(line, "%s", tname); | |
422 | ||
423 | POINTLIST = PTInit(); /* Initialize globals */ | |
424 | SEQ = 0; | |
425 | CHANGED = FALSE; | |
426 | ||
427 | i = strlen(tname); | |
428 | if (i > 0) /* filename present */ | |
429 | { | |
430 | fp = POpen(tname, (char **) NULL, SEARCH); | |
431 | TxPutString(&TEdit, tname); | |
432 | if (fp == NULL) | |
433 | { | |
434 | PICTURE = DBInit(); | |
435 | error(" (creating new file)"); | |
436 | } | |
437 | else | |
438 | { | |
439 | PICTURE = DBRead(tname, &Orientation, &pos); | |
440 | SetOrient(Orientation); /* Set appropriate picture area | |
441 | * orientation */ | |
442 | } | |
443 | (void) strcpy (Editfile, tname); | |
444 | } | |
445 | else | |
446 | { | |
447 | TxPutString(&TEdit, ""); | |
448 | (void) strcpy(Editfile, ""); | |
449 | } | |
450 | unlist = unback = nullun; | |
451 | CP(); | |
452 | SHUpdate(); /* display new picture */ | |
453 | } /* end LGEdit */ | |
454 | ||
455 | static restorepoints() | |
456 | ||
457 | /* This routine (re) displays the points in the back-up pointlist | |
458 | */ | |
459 | { | |
460 | ||
461 | int i; | |
462 | POINT *plist, *pl1, *pl2; | |
463 | ||
464 | GRBlankPoints(); | |
465 | plist = BACKPOINT; | |
466 | for (i=0; !Nullpoint(plist); ++i) | |
467 | { | |
468 | Lastx = plist->x; | |
469 | Lasty = plist->y; | |
470 | GRDisplayPoint( (int) plist->x, (int) plist->y, i, pointstyle ); | |
471 | plist = PTNextPoint(plist); | |
472 | } | |
473 | pl1 = POINTLIST; | |
474 | POINTLIST = BACKPOINT; | |
475 | SEQ = i; | |
476 | BACKPOINT = pl1; | |
477 | } /* end restorepoints */ | |
478 | ||
70170e36 | 479 | |
1acf8029 DS |
480 | LGUndo(line) |
481 | char *line; | |
482 | /* | |
483 | * This routine uses the information in the undo database to reconstruct | |
484 | * the PICTURE as it was before the last command. The undo database is set | |
485 | * so that the next undo would nullify this one. | |
486 | * An undo of an Add is to delete the new element. | |
487 | * Add the old element back to undo a delete. | |
488 | * Modified elements are undone by copying the old element into the database | |
489 | * in place of the modified element. | |
490 | */ | |
491 | ||
492 | { | |
493 | UNELT *fix, *temp; | |
494 | ELT *(*e1); | |
495 | ||
496 | fix = unlist; /* initialize unlist so that undo-ing can */ | |
497 | unlist = nullun; /* add items to properly undo the undo */ | |
498 | if (fix == nullun) | |
499 | { | |
500 | fix = unback; | |
501 | unback = nullun; | |
502 | } | |
503 | DBClearSet(); | |
504 | DISClearSetDisplay(); | |
505 | GRBlankPoints(); | |
506 | while (fix != nullun) | |
507 | { | |
508 | switch (fix->action) | |
509 | { | |
510 | case ADD: DISScreenErase(fix->newelt, linemask); | |
511 | TxMsgOK(); | |
512 | restorepoints(); | |
513 | DBDelete(fix->newelt, fix->dbase); | |
514 | temp = fix->nextun; | |
515 | free((char *) fix); | |
516 | fix = temp; | |
517 | break; | |
518 | ||
519 | case DELETE: fix->action = ADD; /* create undo unelt */ | |
520 | fix->newelt = fix->oldelt; | |
521 | fix->oldelt = NULL; | |
522 | fix->newelt->nextelt = PICTURE; | |
523 | restorepoints(); | |
524 | DBAddSet(fix->newelt); | |
525 | DISScreenAdd(fix->newelt,(linemask|setmask)); | |
526 | PICTURE = fix->newelt; /* put in database */ | |
527 | temp = fix->nextun; | |
528 | fix->nextun = unlist; /* link into unlist */ | |
529 | unlist = fix; | |
530 | fix = temp; | |
531 | break; | |
532 | ||
533 | case MOD: DISScreenErase(fix->newelt, linemask); | |
534 | TxMsgOK(); | |
535 | restorepoints(); | |
536 | DISScreenAdd(fix->oldelt, (setmask | linemask)); | |
537 | DBAddSet(fix->oldelt); | |
538 | e1 = fix->dbase; | |
539 | while ( *e1 != fix->newelt ) | |
540 | { /* find elt to replace */ | |
541 | e1 = &(DBNextElt((*e1))); | |
542 | } | |
543 | fix->oldelt->nextelt = DBNextElt((*e1)); | |
544 | *e1 = fix->oldelt; | |
545 | fix->oldelt = fix->newelt; | |
546 | fix->newelt = *e1; /* create undo unelt */ | |
547 | temp = fix->nextun; | |
548 | fix->nextun = unlist; | |
549 | unlist = fix; /* link into unlist */ | |
550 | fix = temp; | |
551 | break; | |
552 | ||
553 | } /* end switch */; | |
554 | } /* end while */ | |
555 | Consume = FALSE; | |
556 | } /* LGUndo */ | |
557 | ||
70170e36 | 558 | |
1acf8029 DS |
559 | LGWrite(line) |
560 | char *line; | |
561 | /* | |
562 | * This routine writes the current PICTURE into the specified filename | |
563 | * or to the current Editfile | |
564 | */ | |
565 | ||
566 | { | |
567 | FILE *fp, *fopen(); | |
568 | char tname[50], filename[100], string[100], *tn, *fn, *wfile; | |
569 | ELT *elist; | |
570 | POINT *plist, pos; | |
571 | int i, space, stat; | |
572 | ||
573 | space = 100; | |
574 | ++line; | |
575 | tn = tname; fn = filename; | |
576 | (void) sscanf(line, "%s", tname); | |
577 | i = strlen(tname); | |
578 | if (i == 0) /* no filename */ | |
579 | { | |
580 | if ( *Editfile == '\0' ) | |
581 | { | |
582 | error("write to where?"); | |
583 | return; | |
584 | } | |
585 | fp = fopen(Editfile, "w"); | |
586 | wfile = Editfile; | |
587 | } | |
588 | else | |
589 | { | |
590 | stat = PConvertTilde(&tn, &fn, &space); | |
591 | *fn = '\0'; | |
592 | if (stat == FALSE) | |
593 | { | |
594 | sprintf(string, "unknown path %s", tname); | |
595 | error(string); | |
596 | return; | |
597 | } | |
598 | if ( !bang ) /* user doesn't insist */ | |
599 | { | |
600 | fp = fopen(filename, "r"); | |
601 | if ( fp != NULL ) | |
602 | { | |
603 | error("file already exists"); | |
604 | return; | |
605 | } | |
606 | } | |
607 | fp = fopen(filename, "w"); | |
608 | wfile = filename; | |
609 | }; | |
610 | if (fp == NULL) /* file error */ | |
611 | { | |
612 | (void) sprintf(string,"can't open %s", wfile); | |
613 | error(string); | |
614 | return; | |
615 | }; | |
616 | TxPutMsg("writing file..."); | |
617 | CHANGED = FALSE; | |
618 | if (SEQ > 0) /* specified a positioning point */ | |
619 | { | |
620 | pos.x = POINTLIST->x; | |
621 | pos.y = POINTLIST->y; | |
622 | } | |
623 | else | |
624 | { | |
625 | if ( !DBNullelt(PICTURE) ) | |
626 | { | |
627 | pos.x = PICTURE->ptlist->x; | |
628 | pos.y = PICTURE->ptlist->y; | |
629 | } | |
630 | else | |
631 | { | |
632 | pos.x = pos.y = 0; | |
633 | }; | |
634 | } | |
635 | fprintf(fp,"gremlinfile\n"); /* write header */ | |
636 | fprintf(fp, "%d %1.2f %1.2f\n", Orientation, pos.x, pos.y); | |
637 | elist = PICTURE; | |
638 | while ( !DBNullelt(elist) ) /* write each element */ | |
639 | { | |
640 | fprintf(fp, "%d\n", elist->type); | |
641 | plist = elist->ptlist; | |
642 | while ( !Nullpoint(plist) ) /* write each point */ | |
643 | { | |
644 | fprintf(fp, "%1.2f %1.2f\n",plist->x, plist->y); | |
645 | plist = PTNextPoint(plist); | |
646 | } /* end while plist */ | |
647 | fprintf(fp, "%1.2f %1.2f\n", -1.0, -1.0); /* end pointlist */ | |
648 | fprintf(fp, "%d %d\n",elist->brushf, elist->size); | |
649 | fprintf(fp,"%d %s\n ", strlen(elist->textpt), elist->textpt); | |
650 | elist = DBNextElt(elist); | |
651 | } /* end while */ | |
652 | fprintf(fp,"%d\n",-1); /* end of element list */ | |
653 | TxMsgOK(); | |
654 | (void) fclose(fp); | |
655 | } /* end LGWrite */; | |
656 | ||
70170e36 | 657 | |
1acf8029 DS |
658 | LGQuit(line) |
659 | char *line; | |
660 | /* | |
661 | * This routine terminates the editor. The terminal states for the text | |
662 | * terminal and the graphics display are restored and an EXIT is performed. | |
663 | */ | |
664 | ||
665 | { | |
666 | if (!bang) | |
667 | { | |
668 | if (CHANGED) | |
669 | { | |
670 | error("no write"); | |
671 | return; | |
672 | } | |
673 | } /* end if */; | |
674 | GRClose(); | |
675 | TxClose(); | |
676 | exit(0); | |
677 | } /* end LGQuit */ | |
678 | ||
679 | LGHAdjust() | |
680 | /* | |
681 | * Horizontal adjust - | |
682 | * This routine toggles the adjustment mode. | |
683 | */ | |
684 | ||
685 | { | |
686 | if (Adjustment == HORZ) | |
687 | { | |
688 | MNUnHighLt(HiMode[adj[HORZ]]); | |
689 | Adjustment = NOADJ; | |
690 | TxPutString(&TAdjust, "NO ADJUSTMENT"); | |
691 | } | |
692 | else | |
693 | { | |
694 | MNUnHighLt(HiMode[adj[Adjustment]]); | |
695 | MNHighLt(HiMode[adj[HORZ]], hicolor); | |
696 | Adjustment = HORZ; | |
697 | TxPutString(&TAdjust, " HORIZONTAL "); | |
698 | } | |
699 | Consume = FALSE; | |
700 | } | |
701 | ||
70170e36 | 702 | |
1acf8029 DS |
703 | LGVAdjust() |
704 | /* | |
705 | * Vertical adjust - | |
706 | * This routine toggles the adjustment mode. | |
707 | */ | |
708 | ||
709 | { | |
710 | if (Adjustment == VERT) | |
711 | { | |
712 | MNUnHighLt(HiMode[adj[VERT]]); | |
713 | Adjustment = NOADJ; | |
714 | TxPutString(&TAdjust, "NO ADJUSTMENT"); | |
715 | } | |
716 | else | |
717 | { | |
718 | MNUnHighLt(HiMode[adj[Adjustment]]); | |
719 | MNHighLt(HiMode[adj[VERT]], hicolor); | |
720 | Adjustment = VERT; | |
721 | TxPutString(&TAdjust, " VERTICAL "); | |
722 | } | |
723 | Consume = FALSE; | |
724 | } | |
725 | ||
726 | ||
70170e36 | 727 | |
1acf8029 DS |
728 | static sign(x) |
729 | float x; | |
730 | /* | |
731 | * This local routine returns 1 if x >= 0 | |
732 | * otherwise returns 0; | |
733 | */ | |
734 | ||
735 | { | |
736 | if (x >= 0) return(1); | |
737 | else return(0); | |
738 | } | |
739 | ||
740 | LGMirror(line) | |
741 | char *line; | |
742 | /* | |
743 | * This routine mirrors the elements in the current set as defined | |
744 | * by points. The mirroring is accomplished by defining a transformation | |
745 | * matrix and calling DBXform. | |
746 | */ | |
747 | ||
748 | { | |
749 | ELT *e1; | |
750 | POINT pt, pos, *p1, *p2; | |
751 | float xmat[3][2], scalex, scaley; | |
752 | int i, j; | |
753 | ||
754 | if (SEQ < 3) /* not enough points */ | |
755 | { | |
756 | error("not enough points"); | |
757 | return; | |
758 | } | |
759 | if (DBNullelt(cset)) | |
760 | { | |
761 | error("no current set"); | |
762 | return; | |
763 | } | |
764 | p1 = PTNextPoint(POINTLIST); | |
765 | p2 = PTNextPoint(p1); | |
766 | scalex = scaley = 1; | |
767 | if (sign(p1->x - POINTLIST->x) != sign(p2->x - POINTLIST->x)) | |
768 | scalex = -scalex; | |
769 | if (sign(p1->y - POINTLIST->y) != sign(p2->y - POINTLIST->y)) | |
770 | scaley = -scaley; | |
771 | ||
772 | /* create transformation matrix to translate set to origin, | |
773 | performing the mirroring and translating back */ | |
774 | ||
775 | xmat[0][0] = scalex; | |
776 | xmat[1][1] = scaley; | |
777 | xmat[1][0] = xmat[0][1] = 0; | |
778 | xmat[2][0] = - POINTLIST->x * (scalex - 1.0); | |
779 | xmat[2][1] = - POINTLIST->y * (scaley - 1.0); | |
780 | e1 = cset; | |
781 | while ( !DBNullelt(e1) ) | |
782 | { | |
783 | DISScreenErase(e1, (linemask | setmask)); | |
784 | TxMsgOK(); | |
785 | DBXform(e1, xmat, &PICTURE); | |
786 | if (TEXT(e1->type)) | |
787 | { | |
788 | GRsetwmask(textmask | setmask); | |
789 | p1 = e1->ptlist; | |
790 | GRPutText(e1->type, p1, e1->brushf, e1->size,e1->textpt, &pos); | |
791 | i= strlen(e1->textpt); | |
792 | p2 = PTInit(); | |
793 | (void) PTMakePoint(p1->x, p1->y, &p2); | |
794 | /* add extra positioning points */ | |
795 | (void) PTMakePoint(pos.x, pos.y, &p2); | |
796 | (void) PTMakePoint(pos.x + i * charxsize / 2, pos.y, &p2); | |
797 | (void) PTMakePoint(pos.x + i * charxsize, pos.y, &p2); | |
798 | e1->ptlist = p2; | |
799 | } /* end if TEXT */ | |
800 | else | |
801 | { | |
802 | if (e1->type == ARC) /* arcs require special handling */ | |
803 | if (e1->size > 0) /* circles are OK */ | |
804 | if (scalex * scaley < 0) /* both directions OK */ | |
805 | { /* swap starting and ending points of arc */ | |
806 | p1 = PTNextPoint(e1->ptlist); | |
807 | p2 = PTNextPoint(p1); | |
808 | pt.x = p1->x; | |
809 | pt.y = p1->y; | |
810 | p1->x = p2->x; | |
811 | p1->y = p2->y; | |
812 | p2->x = pt.x; | |
813 | p2->y = pt.y; | |
814 | } | |
815 | DISScreenAdd(e1, (linemask | setmask)); | |
816 | } /* end else */ | |
817 | e1 = DBNextofSet(e1); | |
818 | } /* end while */ | |
819 | CHANGED = TRUE; | |
820 | } /* end LGMirror */ | |
821 | ||
70170e36 | 822 | |
1acf8029 DS |
823 | LGPath(line) |
824 | char *line; | |
825 | /* | |
826 | * This routine looks at the command line for parameters to set | |
827 | * the current search path. | |
828 | */ | |
829 | ||
830 | { | |
831 | char path[100]; | |
832 | ||
833 | if ( *line == '\0' ) TxPutMsg(PGetPath()); /* no arguments */ | |
834 | else | |
835 | { | |
836 | SEARCH = TRUE; | |
837 | (void) sscanf(line, "%s", path); | |
838 | PSetPath(path); | |
839 | } | |
840 | Consume = FALSE; | |
841 | } /* end LGFont */ |