1 /*
2 * Author: William Chia-Wei Cheng (bill.cheng@acm.org)
3 *
4 * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5 *
6 * This file may be distributed under the terms of the Q Public License
7 * as defined by Trolltech AS of Norway and appearing in the file
8 * LICENSE.QPL included in the packaging of this file.
9 *
10 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * @(#)$Header: /mm2/home/cvs/bc-src/tgif/file.c,v 1.69 2011/05/16 16:21:57 william Exp $
19 */
20
21 #define _INCLUDE_FROM_FILE_C_
22
23 #include "tgifdefs.h"
24 #include "expfdefs.h"
25 #include "cmdids.h"
26
27 #include "align.e"
28 #include "arc.e"
29 #include "attr.e"
30 #include "auxtext.e"
31 #include "box.e"
32 #include "button.e"
33 #include "choice.e"
34 #include "cmd.e"
35 #include "color.e"
36 #include "cutpaste.e"
37 #include "cursor.e"
38 #include "dialog.e"
39 #include "drawing.e"
40 #include "dup.e"
41 #include "edit.e"
42 #include "eps.e"
43 #include "exec.e"
44 #include "file.e"
45 #include "font.e"
46 #include "grid.e"
47 #include "group.e"
48 #include "imgproc.e"
49 #include "import.e"
50 #include "ini.e"
51 #include "mainloop.e"
52 #include "mainmenu.e"
53 #include "mark.e"
54 #include "menu.e"
55 #include "menuinfo.e"
56 #include "miniline.e"
57 #include "move.e"
58 #include "msg.e"
59 #include "names.e"
60 #include "navigate.e"
61 #include "obj.e"
62 #include "oval.e"
63 #include "page.e"
64 #include "pattern.e"
65 #include "poly.e"
66 #include "polygon.e"
67 #include "prtgif.e"
68 #include "ps.e"
69 #include "raster.e"
70 #include "rcbox.e"
71 #include "rect.e"
72 #include "remote.e"
73 #include "ruler.e"
74 #include "scroll.e"
75 #include "select.e"
76 #include "setup.e"
77 #include "shape.e"
78 #include "special.e"
79 #include "spline.e"
80 #include "stk.e"
81 #include "stretch.e"
82 #include "strtbl.e"
83 #include "text.e"
84 #include "util.e"
85 #include "version.e"
86 #include "wb.e"
87 #include "xbitmap.e"
88 #include "xpixmap.e"
89 #include "xprtfltr.e"
90
91 #ifdef _METRIC_PIX_PER_INCH
92 #define METRIC_PIX_PER_INCH 127
93 #endif /* _METRIC_PIX_PER_INCH */
94
95 #define CUR_VERSION 37
96
97 int PRTGIF=FALSE;
98 int prTgifFoundColorInfo=FALSE;
99 char curFileName[MAXPATHLENGTH+1];
100 int curFileDefined=FALSE;
101 int fileVersion=INVALID;
102 int curFileWriteVersion=CUR_VERSION;
103 int importingFile=FALSE;
104 int mergingFile=FALSE;
105 int serializingFile=FALSE;
106 int deserializingFile=FALSE;
107 int psDotsPerInch=72;
108 float printMag=(float)100.0;
109 int saveTmpOnReturn=TRUE;
110 int warpToWinCenter=TRUE;
111 float tiledPageScaling=(float)0.9;
112
113 char *psXOffStr[MAXPAGESTYLES] = {"0","0"};
114 float psXOff[MAXPAGESTYLES] = { 0, 0 };
115 char * * psYOffStr=NULL;
116 float * psYOff=NULL;
117 float * psPageWidthInInch=NULL;
118 float * psPageHeightInInch=NULL;
119
120 char printCommand[MAXSTRING+1];
121 char outputDir[MAXPATHLENGTH+1];
122
123 char * savedComments=NULL;
124 int savedCommentsLen=0;
125 int saveCommentsInSaveNew=TRUE;
126 int usePsAdobeString=FALSE;
127 char adobeString[80], epsfString[80];
128
129 int readingPageNum=0;
130 int loadedCurPageNum=0;
131
132 int writeFileFailed=FALSE;
133 int foundGoodStateObject=FALSE;
134
135 int cmdLineHasPageNum=FALSE;
136 int cmdLinePageNum=(-1);
137 char cmdLinePageNumStr[80];
138
139 int cmdLineOneFilePerPage=FALSE;
140 int cmdLineA4=FALSE;
141 int cmdLineLetter=FALSE;
142 int cmdLineNoShowPageInEPS=FALSE;
143 int cmdLineColor=FALSE;
144 int cmdLineRequestedColor=FALSE;
145
146 int cmdLineDumpURL=FALSE;
147 int cmdLineDumpURLWithHeader=FALSE;
148 int cmdLineDumpURLHeaderOnly=FALSE;
149 int cmdLineDumpURLShowStatus=FALSE;
150
151 int cmdLineDosEpsFilter=FALSE;
152 int cmdLinePreviewOnly=FALSE;
153
154 int cmdLinePsSetup=FALSE;
155
156 int tmpFileMode=PSFILE_MOD;
157 char cmdLineTmpFileModeStr[MAXSTRING];
158
159 int cmdLineOpenDisplay=FALSE;
160 int cmdLineStdOut=FALSE;
161 int cmdLineWhereToPrint=INVALID;
162 int cmdLineTiffEPSI=INVALID;
163 int cmdLinePdfSetPageDevice=INVALID;
164
165 char cmdLineFileToExec[MAXSTRING];
166 char cmdLineProducedBy[MAXSTRING];
167 char cmdLineOpenFile[MAXSTRING];
168 char cmdLineJpegToPpm6Cmd[MAXSTRING];
169
170 int cmdLineQuiet=FALSE;
171
172 char cmdLineCustomPatternDir[MAXSTRING];
173 char customPatDir[MAXSTRING];
174
175 int generateTiffEPSI=FALSE;
176 int showPageInEPS=TRUE;
177
178 int gnQuit=FALSE;
179
180 int myFileBgPixel=INVALID, myFileFgPixel=INVALID;
181 char *myFileBgColorStr=NULL, *myFileFgColorStr=NULL;
182 XColor myFileBgColor;
183 int myFileBgPixmapW=(-1), myFileBgPixmapH=(-1);
184 Pixmap myFileBgPixmap=None;
185 char *myFileBgGifURL=NULL;
186 char gszProducedBy[MAXSTRING];
187
188 int dumpOneFilePerPage=FALSE;
189
190 int bufferAsFileForWhiteBoard=FALSE;
191
192 int flushColormapOnOpen=FALSE;
193
194 struct BBRec *gpExportClipBBox=NULL;
195
196 int gnNumFilePSFontAliases=0;
197 KeyValInfo *gaFilePSFontAliases=NULL;
198
199 SpecifyPagesInfo gPagesToPrintSpec;
200
201 GenerateByInfo gGenerateByInfo;
202
203 static int pdfSetPageDevice=INVALID;
204
205 static int psRegMarksInTiledPageMode=INVALID;
206 static float psRegMarksGray=(float)0.95;
207
208 static int importingPageNum=(-1);
209 static char importingPageName[MAXSTRING+1];
210
211 static int unsavableFile=FALSE;
212
213 static char *gpszPsSetup=NULL;
214 static int psSetupStatus=INVALID;
215 static int psDistillerNoImageCompress=INVALID;
216
217 struct DocFontRec {
218 char name[80];
219 int len;
220 struct DocFontRec *next;
221 };
222
223 static struct DocFontRec *firstDocFont=NULL;
224
MkTempFile(buf,buf_sz,psz_dir,psz_prefix)225 char *MkTempFile(buf, buf_sz, psz_dir, psz_prefix)
226 char *buf, *psz_dir, *psz_prefix;
227 int buf_sz;
228 {
229 int mkstemp_succes=FALSE;
230
231 #ifdef _TGIF_DBG /* debug, do not translate */
232 TgAssert(buf_sz > sizeof(char*),
233 "buf_sz <= sizeof(char*) in MkTempFile()", NULL);
234 #endif /* _TGIF_DBG */
235
236 #ifndef _DONT_USE_MKTEMP
237 sprintf(buf, "%s%sXXXXXX", psz_dir, psz_prefix);
238 mktemp(buf);
239 #else /* _DONT_USE_MKTEMP */
240 {
241 int fd=(-1);
242
243 sprintf(buf, "%s%sXXXXXX", psz_dir, psz_prefix);
244 if ((fd=mkstemp(buf)) == (-1)) {
245 /*
246 * UtilStrCpyN(buf, buf_sz, (char*)tempnam(psz_dir, psz_prefix));
247 */
248 sprintf(buf, "%s%sXXXXXX", psz_dir, psz_prefix);
249 sprintf(gszMsgBox, TgLoadString(STID_CANT_OBTAIN_TMP_FILE_NAME),
250 buf);
251 if (PRTGIF) {
252 fprintf(stderr, "%s\n", gszMsgBox);
253 } else {
254 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
255 }
256 return NULL;
257 } else {
258 close(fd);
259 mkstemp_succes = TRUE;
260 }
261 }
262 #endif /* ~_DONT_USE_MKTEMP */
263
264 if (!mkstemp_succes) {
265 #ifdef O_EXCL
266 int fd=open(buf, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR);
267
268 if (fd == -1) {
269 /* barf loudly that someone is trying to hack the box */
270 sprintf(gszMsgBox, TgLoadString(STID_RACE_IN_CREATE_TMP_FILE), buf);
271 if (PRTGIF) {
272 fprintf(stderr, "%s\n", gszMsgBox);
273 } else {
274 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
275 }
276 return NULL;
277 } else {
278 close(fd);
279 }
280 #endif /* O_EXCL */
281 }
282 unlink(buf);
283
284 return buf;
285 }
286
IsFiletUnSavable()287 int IsFiletUnSavable()
288 {
289 return unsavableFile;
290 }
291
SetUnSavableFile(unsavable)292 void SetUnSavableFile(unsavable)
293 int unsavable;
294 {
295 if (!unsavableFile && unsavable) {
296 Msg(TgLoadString(STID_FILE_IS_MARKED_UNSAVABLE));
297 }
298 unsavableFile = unsavable;
299 }
300
UpdateDocumentFonts(ps_font_name)301 void UpdateDocumentFonts(ps_font_name)
302 char *ps_font_name;
303 {
304 int len=strlen(ps_font_name);
305 struct DocFontRec *df_ptr;
306
307 for (df_ptr=firstDocFont; df_ptr != NULL; df_ptr=df_ptr->next) {
308 if (df_ptr->len == len && strcmp(df_ptr->name, ps_font_name) == 0) {
309 return;
310 }
311 }
312 df_ptr = (struct DocFontRec *)malloc(sizeof(struct DocFontRec));
313 if (df_ptr == NULL) FailAllocMessage();
314 memset(df_ptr, 0, sizeof(struct DocFontRec));
315 df_ptr->len = len;
316 UtilStrCpyN(df_ptr->name, sizeof(df_ptr->name), ps_font_name);
317 df_ptr->next = firstDocFont;
318 firstDocFont = df_ptr;
319 }
320
321 static
DumpDocumentFonts(dump_fp)322 void DumpDocumentFonts(dump_fp)
323 FILE *dump_fp;
324 {
325 struct DocFontRec *next_df=NULL;
326
327 if (fprintf(dump_fp, "%%%%DocumentFonts: ") == EOF) {
328 writeFileFailed = TRUE;
329 }
330 for ( ; firstDocFont != NULL; firstDocFont=next_df) {
331 next_df = firstDocFont->next;
332 if (fprintf(dump_fp, "%s", firstDocFont->name) == EOF) {
333 writeFileFailed = TRUE;
334 }
335 if (next_df != NULL) {
336 if (fprintf(dump_fp, "\n%%%%+ ") == EOF) {
337 writeFileFailed = TRUE;
338 }
339 }
340 free(firstDocFont);
341 }
342 if (fprintf(dump_fp, "\n") == EOF) writeFileFailed = TRUE;
343 }
344
345 #define LANGUAGELEVEL 0
346 #define EXTENSIONS 1
347 #define DOCUMENTFONTS 2
348 #define DOCUMENTNEEDEDRESOURCES 3
349 #define DOCUMENTNEEDEDFONTS 4
350
351 #define MAXPROPAGATEDEPSINFO 5
352
353 struct tagPropagatedEPSInfoRec {
354 char *name;
355 int status;
356 } gstPropagatedEPSInfo[] = {
357 { "%%LanguageLevel", LANGUAGELEVEL },
358 { "%%Extensions", EXTENSIONS },
359 { "%%DocumentFonts", DOCUMENTFONTS },
360 { "%%DocumentNeededResources", DOCUMENTNEEDEDRESOURCES },
361 { "%%DocumentNeededFonts", DOCUMENTNEEDEDFONTS },
362 { NULL, INVALID }
363 };
364
365 static KeyValInfo *gPropagatedEPSInfo[MAXPROPAGATEDEPSINFO];
366 static int maxLanguageLevel=0;
367
368 static
FindPropagatedEPSInfo(buf)369 int FindPropagatedEPSInfo(buf)
370 char *buf;
371 {
372 struct tagPropagatedEPSInfoRec *ppei=gstPropagatedEPSInfo;
373
374 for (ppei=gstPropagatedEPSInfo; ppei->name != NULL; ppei++) {
375 if (strcmp(buf, ppei->name) == 0) {
376 return ppei->status;
377 }
378 }
379 return INVALID;
380 }
381
382 static
CleanUpPropagatedEPSInfo()383 void CleanUpPropagatedEPSInfo()
384 {
385 int i=0;
386
387 maxLanguageLevel = 0;
388 for (i=0; i < MAXPROPAGATEDEPSINFO; i++) {
389 KeyValInfo *pkvi=NULL, *p_next_kvi=NULL;
390
391 for (pkvi=gPropagatedEPSInfo[i]; pkvi != NULL; pkvi=p_next_kvi) {
392 p_next_kvi = pkvi->next;
393 UtilFree(pkvi->value);
394 free(pkvi);
395 }
396 }
397 memset(gPropagatedEPSInfo, 0, MAXPROPAGATEDEPSINFO*sizeof(KeyValInfo*));
398 }
399
400 static
DumpPropagatedEPSInfo(dump_fp)401 void DumpPropagatedEPSInfo(dump_fp)
402 FILE *dump_fp;
403 {
404 int i=0;
405
406 if (maxLanguageLevel > 0) {
407 if (fprintf(dump_fp, "%%%%LanguageLevel: %1d\n", maxLanguageLevel) ==
408 EOF) {
409 writeFileFailed = TRUE;
410 }
411 }
412 for (i=0; i < MAXPROPAGATEDEPSINFO; i++) {
413 if (gPropagatedEPSInfo[i] != NULL) {
414 KeyValInfo *pkvi=NULL, *p_next_kvi=NULL;
415
416 if (fprintf(dump_fp, "%s: ", gstPropagatedEPSInfo[i].name) == EOF) {
417 writeFileFailed = TRUE;
418 }
419 for (pkvi=gPropagatedEPSInfo[i]; pkvi != NULL; pkvi=p_next_kvi) {
420 p_next_kvi = pkvi->next;
421 if (fprintf(dump_fp, "%s", pkvi->value) == EOF) {
422 writeFileFailed = TRUE;
423 }
424 if (p_next_kvi != NULL) {
425 if (fprintf(dump_fp, "\n%%%%+ ") == EOF) {
426 writeFileFailed = TRUE;
427 }
428 }
429 UtilFree(pkvi->value);
430 free(pkvi);
431 }
432 if (fprintf(dump_fp, "\n") == EOF) writeFileFailed = TRUE;
433 gPropagatedEPSInfo[i] = NULL;
434 }
435 }
436 }
437
438 static
DoUpdatePropagatedEPSInfo(index,psz_value)439 void DoUpdatePropagatedEPSInfo(index, psz_value)
440 int index;
441 char *psz_value;
442 {
443 int len=strlen(psz_value);
444 KeyValInfo *pkvi=NULL, *p_last_kvi=NULL;
445
446 for (pkvi=gPropagatedEPSInfo[index]; pkvi != NULL; pkvi=pkvi->next) {
447 if (pkvi->key == ((char*)(long)len) &&
448 strcmp(pkvi->value, psz_value) == 0) {
449 return;
450 }
451 p_last_kvi = pkvi;
452 }
453 pkvi = (KeyValInfo *)malloc(sizeof(KeyValInfo));
454 if (pkvi == NULL) FailAllocMessage();
455 memset(pkvi, 0, sizeof(KeyValInfo));
456 pkvi->key = ((char*)(long)len);
457 pkvi->value = UtilStrDup(psz_value);
458 if (pkvi->value == NULL) FailAllocMessage();
459 if (p_last_kvi == NULL) {
460 gPropagatedEPSInfo[index] = pkvi;
461 } else {
462 p_last_kvi->next = pkvi;
463 }
464 }
465
UpdatePropagatedEPSInfo(line,pn_status)466 void UpdatePropagatedEPSInfo(line, pn_status)
467 char *line;
468 int *pn_status;
469 {
470 int propagated_eps_status=INVALID, level=0;
471 char *arg=NULL;
472
473 if (*pn_status == INVALID) {
474 arg = strchr(line, ':');
475
476 if (arg == NULL) return;
477 *arg++ = '\0';
478 propagated_eps_status = FindPropagatedEPSInfo(line);
479 if (propagated_eps_status == INVALID) return;
480 } else {
481 propagated_eps_status = (*pn_status);
482 arg = (&line[3]);
483 }
484 #ifdef _TGIF_DBG /* debug, do not translate */
485 TgAssert(propagated_eps_status != INVALID,
486 "propagated_eps_status != INVALID in UpdatePropagatedEPSInfo()",
487 NULL);
488 #endif /* _TGIF_DBG */
489 UtilTrimBlanks(arg);
490 if (arg[0] == '(' && UtilStrICmp(arg, "(atend)") == 0) {
491 *pn_status = INVALID;
492 return;
493 }
494 switch (propagated_eps_status) {
495 case LANGUAGELEVEL:
496 if (sscanf(arg, "%d", &level) == 1) {
497 if (level > maxLanguageLevel) {
498 maxLanguageLevel = level;
499 }
500 }
501 break;
502 case EXTENSIONS:
503 case DOCUMENTNEEDEDFONTS:
504 case DOCUMENTNEEDEDRESOURCES:
505 DoUpdatePropagatedEPSInfo(propagated_eps_status, arg);
506 break;
507 case DOCUMENTFONTS:
508 UpdateDocumentFonts(arg);
509 break;
510 }
511 *pn_status = propagated_eps_status;
512 }
513
514 static int dontUseShortHandPS=INVALID;
515 static int dontCondense=INVALID;
516 static int stripSimpleComments=INVALID;
517
SetCmdLineDontCondense()518 void SetCmdLineDontCondense()
519 {
520 dontUseShortHandPS = TRUE;
521 dontCondense = TRUE;
522 stripSimpleComments = FALSE;
523 }
524
SetCmdLineCondensedPS()525 void SetCmdLineCondensedPS()
526 {
527 dontUseShortHandPS = FALSE;
528 dontCondense = FALSE;
529 stripSimpleComments = TRUE;
530 }
531
532 static char gszResidual[80];
533 static int gnResidualLen=0;
534
535 static
DumpResidual(write_fp)536 void DumpResidual(write_fp)
537 FILE *write_fp;
538 {
539 if (gnResidualLen > 0) {
540 if (fputs(gszResidual, write_fp) == EOF) writeFileFailed = TRUE;
541 if (fputs("\n", write_fp) == EOF) writeFileFailed = TRUE;
542 *gszResidual = '\0';
543 gnResidualLen = 0;
544 }
545 }
546
547 static
AddToResidual(write_fp,buf)548 void AddToResidual(write_fp, buf)
549 FILE *write_fp;
550 char *buf;
551 {
552 int len=strlen(buf);
553
554 if (len <= 0) return;
555
556 if (len+gnResidualLen >= 77) {
557 DumpResidual(write_fp);
558 if (len >= 77) {
559 if (fputs(buf, write_fp) == EOF) writeFileFailed = TRUE;
560 if (fputs("\n", write_fp) == EOF) writeFileFailed = TRUE;
561 return;
562 }
563 }
564 if (gnResidualLen == 0) {
565 sprintf(&gszResidual[gnResidualLen], "%s", buf);
566 gnResidualLen += len;
567 } else {
568 sprintf(&gszResidual[gnResidualLen], " %s", buf);
569 gnResidualLen += len+1;
570 }
571 }
572
573 static
GetPostScriptToken(read_fname,pszStart,ppszEnd)574 char *GetPostScriptToken(read_fname, pszStart, ppszEnd)
575 char *read_fname, *pszStart, **ppszEnd;
576 {
577 char *psz=NULL;
578
579 *ppszEnd = NULL;
580 while (*pszStart == ' ' || *pszStart == '\t') pszStart++;
581 if (*pszStart == '\0') return NULL;
582 if (*pszStart == '%') return NULL;
583 if (*pszStart == '(') {
584 for (psz=pszStart; *psz != ')' && *psz != '\0'; psz++) {
585 if (*psz == '\\') {
586 psz++;
587 if (*psz >= '0' && *psz <= '7') {
588 psz++;
589 psz++;
590 }
591 }
592 }
593 if (*psz == ')') {
594 *ppszEnd = (&psz[1]);
595 } else {
596 /* no problem - Adobe Illustrator 6.0 does this a lot */
597 }
598 } else {
599 for (psz=pszStart;
600 *psz!='\0' && *psz!=' ' && *psz!='\t' && *psz!='(' && *psz!='%';
601 psz++) {
602 }
603 if (*psz == '%') {
604 *psz = '\0';
605 }
606 if (*psz != '\0') {
607 *ppszEnd = psz;
608 }
609 }
610 return pszStart;
611 }
612
613 static
CondenseAndCopyPostScriptFile(read_fp,write_fp,read_fname,condense)614 void CondenseAndCopyPostScriptFile(read_fp, write_fp, read_fname, condense)
615 FILE *read_fp, *write_fp;
616 char *read_fname;
617 int condense;
618 {
619 if (condense) {
620 char *buf;
621 int previewing=FALSE, begin_preview_len=strlen("%%BeginPreview:");
622
623 if (stripSimpleComments == INVALID) stripSimpleComments = FALSE;
624 *gszResidual = '\0';
625 gnResidualLen = 0;
626 while ((buf=UtilGetALine(read_fp)) != NULL) {
627 if (*buf == '%') {
628 if (strncmp(buf, "%%BeginPreview:", begin_preview_len) == 0) {
629 previewing = TRUE;
630 } else if (strncmp(buf, "%%EndPreview", begin_preview_len-3) == 0) {
631 previewing = FALSE;
632 }
633 if (!stripSimpleComments || buf[1] == '%' || buf[1] == '!' ||
634 previewing) {
635 DumpResidual(write_fp);
636 AddToResidual(write_fp, buf);
637 DumpResidual(write_fp);
638 }
639 } else {
640 char *psz=NULL, *pszStart=buf, *pszEnd=NULL;
641
642 while ((psz=GetPostScriptToken(read_fname, pszStart, &pszEnd)) !=
643 NULL) {
644 char saved_ch='\0';
645
646 if (pszEnd != NULL) {
647 saved_ch = (*pszEnd);
648 *pszEnd = '\0';
649 }
650 AddToResidual(write_fp, psz);
651 if (pszEnd == NULL) {
652 break;
653 }
654 *pszEnd = saved_ch;
655 pszStart = pszEnd;
656 pszEnd = NULL;
657 }
658 }
659 UtilFree(buf);
660 }
661 DumpResidual(write_fp);
662 } else {
663 char tmp_str[MAXSTRING<<1];
664
665 while (fgets(tmp_str, MAXSTRING, read_fp) != NULL) {
666 if (fputs(tmp_str, write_fp) == EOF) {
667 writeFileFailed = TRUE;
668 }
669 }
670 }
671 }
672
673 static
CondensePostScriptFile(read_fname,buf_sz)674 int CondensePostScriptFile(read_fname, buf_sz)
675 char *read_fname;
676 int buf_sz;
677 {
678 char write_fname[MAXSTRING+1];
679 FILE *read_fp=NULL, *write_fp=NULL;
680
681 if (MkTempFile(write_fname, sizeof(write_fname), tmpDir, TOOL_NAME) ==
682 NULL) {
683 return FALSE;
684 }
685 if ((read_fp=fopen(read_fname, "r")) == NULL) {
686 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FOR_READ_PRINT),
687 read_fname);
688 if (PRTGIF) {
689 fprintf(stderr, "%s\n", gszMsgBox);
690 } else {
691 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
692 }
693 return FALSE;
694 }
695 if ((write_fp=fopen(write_fname, "w")) == NULL) {
696 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FOR_WRITE_PRINT),
697 write_fname);
698 if (PRTGIF) {
699 fprintf(stderr, "%s\n", gszMsgBox);
700 } else {
701 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
702 }
703 fclose(read_fp);
704 return FALSE;
705 }
706 CondenseAndCopyPostScriptFile(read_fp, write_fp, read_fname, TRUE);
707 fclose(read_fp);
708 fclose(write_fp);
709 unlink(read_fname);
710 UtilStrCpyN(read_fname, buf_sz, write_fname);
711
712 return TRUE;
713 }
714
715 static
CopyAFile(file1,file2,condense)716 int CopyAFile(file1, file2, condense)
717 char *file1, *file2;
718 int condense;
719 {
720 char tmp_str[MAXSTRING<<1], *rest;
721 FILE *fp1, *fp2;
722
723 if ((fp1=fopen(file1, "r")) == NULL) {
724 sprintf(tmp_str, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING), file1);
725 if (PRTGIF) {
726 fprintf(stderr, "%s\n", tmp_str);
727 } else {
728 MsgBox(tmp_str, TOOL_NAME, INFO_MB);
729 }
730 return FALSE;
731 }
732 if (file2 == NULL) {
733 /* PRTGIF && cmdLineStdOut */
734 fp2 = stdout;
735 } else {
736 int short_name=FALSE;
737
738 if ((short_name=IsPrefix(bootDir, file2, &rest))) ++rest;
739 if ((fp2=fopen(file2, "w")) == NULL) {
740 if (PRTGIF) {
741 sprintf(tmp_str, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_WRITING),
742 file2);
743 fprintf(stderr, "%s\n", tmp_str);
744 } else {
745 if (short_name) {
746 sprintf(tmp_str, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_WRITING),
747 rest);
748 } else {
749 sprintf(tmp_str, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_WRITING),
750 file2);
751 }
752 MsgBox(tmp_str, TOOL_NAME, INFO_MB);
753 }
754 fclose(fp1);
755 return FALSE;
756 }
757 }
758 writeFileFailed = FALSE;
759 CondenseAndCopyPostScriptFile(fp1, fp2, file1, (condense && !dontCondense));
760 fclose(fp1);
761 if (file2 != NULL) fclose(fp2);
762 if (writeFileFailed) {
763 writeFileFailed = FALSE;
764 if (file2 == NULL) {
765 strcpy(tmp_str, TgLoadString(STID_FAIL_TO_WRITE_TO_STDOUT));
766 if (PRTGIF) {
767 fprintf(stderr, "%s\n", tmp_str);
768 } else {
769 MsgBox(tmp_str, TOOL_NAME, INFO_MB);
770 }
771 } else {
772 FailToWriteFileMessage(file2);
773 }
774 return FALSE;
775 }
776 return TRUE;
777 }
778
FindProgramInPath(cmd,msg,no_msg)779 int FindProgramInPath(cmd, msg, no_msg)
780 char *cmd, *msg;
781 int no_msg;
782 {
783 char *psz=strchr(cmd, ' '), szPath[MAXPATHLENGTH];
784
785 if (psz != NULL) *psz = '\0';
786 UtilStrCpyN(szPath, sizeof(szPath), cmd);
787 if (psz != NULL) *psz = ' ';
788
789 if (*szPath == '\0') {
790 /* no program specified, assume it's okay */
791 return TRUE;
792 } else if (*szPath == DIR_SEP) {
793 if (UtilPathExists(szPath)) return TRUE;
794 } else {
795 char *env=NULL;
796
797 psz = getenv("PATH");
798 if (psz == NULL) {
799 /* cannot get the PATH environment, assume it's okay */
800 return TRUE;
801 }
802 env = UtilStrDup(psz);
803 if (env == NULL) FailAllocMessage();
804 for (psz=strtok(env, ":"); psz != NULL; psz=strtok(NULL, ":")) {
805 sprintf(gszMsgBox, "%s%c%s", psz, DIR_SEP, szPath);
806 if (UtilPathExists(gszMsgBox)) {
807 UtilFree(env);
808 return TRUE;
809 }
810 }
811 UtilFree(env);
812 }
813 if (no_msg) {
814 return FALSE;
815 }
816 if (msg == NULL || *msg == '\0') {
817 sprintf(gszMsgBox, TgLoadString(*szPath==DIR_SEP ?
818 STID_CANNOT_FIND_CMD_EXEC : STID_CANNOT_FIND_CMD_IN_PATH_EXEC),
819 szPath, cmd);
820 } else {
821 sprintf(gszMsgBox, TgLoadString(*szPath==DIR_SEP ?
822 STID_CANT_FIND_CMD_MSG_EXEC : STID_CANT_FIND_CMD_INPATH_MSG_EXEC),
823 szPath, msg, cmd);
824 }
825 if (PRTGIF) {
826 fprintf(stderr, "%s [no]\n", gszMsgBox);
827 return FALSE;
828 }
829 return (MsgBox(gszMsgBox, TOOL_NAME, YNC_MB)==MB_ID_YES);
830 }
831
ExecuteCmd(cmd,done_msg)832 int ExecuteCmd(cmd, done_msg)
833 char *cmd;
834 int done_msg;
835 {
836 int watch_cursor=watchCursorOnMainWindow;
837 char tmp_str[MAXSTRING+1];
838 FILE *fp=NULL;
839
840 EndMeasureTooltip(FALSE);
841 if (!FindProgramInPath(cmd, NULL, FALSE)) return FALSE;
842 sprintf(gszMsgBox, TgLoadCachedString(CSTID_EXECUTING_GIVEN_PROGRAM), cmd);
843 SetStringStatus(gszMsgBox);
844 if (!PRTGIF) XSync(mainDisplay, False);
845 if ((fp=(FILE*)popen(cmd, "r")) == NULL) return FALSE;
846
847 if (!watch_cursor) {
848 SetWatchCursor(drawWindow);
849 SetWatchCursor(mainWindow);
850 }
851 while (fgets(tmp_str, MAXSTRING, fp) != NULL) {
852 if (PRTGIF) {
853 fprintf(stderr, "%s", tmp_str);
854 } else {
855 Msg(tmp_str);
856 }
857 }
858 pclose(fp);
859 if (!watch_cursor) {
860 SetDefaultCursor(mainWindow);
861 ShowCursor();
862 }
863 if (done_msg) {
864 SetStringStatus(TgLoadCachedString(CSTID_DOTS_DONE));
865 }
866 return TRUE;
867 }
868
CleanUpComments()869 void CleanUpComments()
870 {
871 if (savedComments != NULL) {
872 free(savedComments);
873 savedComments = NULL;
874 savedCommentsLen = 0;
875 }
876 }
877
ClearFileInfo(clean_up_comments)878 void ClearFileInfo(clean_up_comments)
879 int clean_up_comments;
880 /*
881 * This function is called everything a new file is initialized.
882 */
883 {
884 *curFileName = '\0';
885 curFileDefined = FALSE;
886 if (!curDirIsLocal) strcpy(curDir, curLocalDir);
887 curDirIsLocal = TRUE;
888 *curLocalDir = '\0';
889 *curSymDir = '\0';
890
891 if (clean_up_comments) {
892 CleanUpComments();
893 }
894 *gszHhtmlExportTemplate = '\0';
895
896 SetUnSavableFile(FALSE);
897 memset(&gGenerateByInfo, 0, sizeof(GenerateByInfo));
898 }
899
OkayToCreateFile(FileName)900 int OkayToCreateFile(FileName)
901 char *FileName;
902 {
903 FILE *fp;
904
905 if ((fp=fopen(FileName, "r")) == NULL) return TRUE;
906 fclose(fp);
907 sprintf(gszMsgBox, TgLoadString(STID_FILE_EXISTS_OK_OVERWRITE_YNC),
908 FileName);
909 switch (MsgBox(gszMsgBox, TOOL_NAME, YNC_MB)) {
910 case MB_ID_YES: break;
911 case MB_ID_NO: return FALSE;
912 case MB_ID_CANCEL: return FALSE;
913 }
914 unlink(FileName);
915 return TRUE;
916 }
917
SaveObj(FP,ObjPtr,Level)918 void SaveObj(FP, ObjPtr, Level)
919 FILE *FP;
920 struct ObjRec *ObjPtr;
921 int Level;
922 {
923 switch (ObjPtr->type) {
924 case OBJ_POLY: SavePolyObj(FP, ObjPtr); break;
925 case OBJ_BOX: SaveBoxObj(FP, ObjPtr); break;
926 case OBJ_OVAL: SaveOvalObj(FP, ObjPtr); break;
927 case OBJ_TEXT: SaveTextObj(FP, ObjPtr); break;
928 case OBJ_POLYGON: SavePolygonObj(FP, ObjPtr); break;
929 case OBJ_ARC: SaveArcObj(FP, ObjPtr); break;
930 case OBJ_RCBOX: SaveRCBoxObj(FP, ObjPtr); break;
931 case OBJ_XBM: SaveXBmObj(FP, ObjPtr); break;
932 case OBJ_XPM: SaveXPmObj(FP, ObjPtr); break;
933 case OBJ_GROUP: SaveGroupObj(FP, ObjPtr, Level); break;
934 case OBJ_SYM: SaveCompObj(FP, ObjPtr, Level); break;
935 case OBJ_ICON: SaveIconObj(FP, ObjPtr, Level); break;
936 case OBJ_PIN: SavePinObj(FP, ObjPtr, Level); break;
937 /* reserved */
938 case OBJ_SS: SaveSimpleStringObj(FP, ObjPtr); break;
939 }
940 }
941
FileNameHasExtension(file_name,file_type,pn_gzipped,pn_no_name)942 int FileNameHasExtension(file_name, file_type, pn_gzipped, pn_no_name)
943 char *file_name;
944 int file_type, *pn_gzipped, *pn_no_name;
945 {
946 static char stszObjFileExt[20], stszGzObjFileExt[20];
947 static char stszSymFileExt[20];
948 static char stszPinFileExt[20];
949 static int initialized=FALSE;
950 char *psz=NULL;
951
952 if (!initialized) {
953 sprintf(stszObjFileExt, ".%s", OBJ_FILE_EXT);
954 sprintf(stszGzObjFileExt, ".%s.gz", OBJ_FILE_EXT);
955 sprintf(stszSymFileExt, ".%s", SYM_FILE_EXT);
956 sprintf(stszPinFileExt, ".%s", PIN_FILE_EXT);
957 initialized = TRUE;
958 }
959 if (pn_gzipped != NULL) *pn_gzipped = FALSE;
960 switch (file_type) {
961 case OBJ_FILE_TYPE:
962 if ((psz=strstr(file_name, ".obj")) != NULL &&
963 strcmp(psz, ".obj") == 0) {
964 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
965 return TRUE;
966 } else if ((psz=strstr(file_name, ".obj.gz")) != NULL &&
967 strcmp(psz, ".obj.gz") == 0) {
968 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
969 if (pn_gzipped != NULL) *pn_gzipped = TRUE;
970 return TRUE;
971 } else if ((psz=strstr(file_name, ".tgo")) != NULL &&
972 strcmp(psz, ".tgo") == 0) {
973 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
974 return TRUE;
975 } else if ((psz=strstr(file_name, ".tgo.gz")) != NULL &&
976 strcmp(psz, ".tgo.gz") == 0) {
977 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
978 if (pn_gzipped != NULL) *pn_gzipped = TRUE;
979 return TRUE;
980 } else if ((psz=strstr(file_name, stszObjFileExt)) != NULL &&
981 strcmp(psz, stszObjFileExt) == 0) {
982 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
983 return TRUE;
984 } else if ((psz=strstr(file_name, stszGzObjFileExt)) != NULL &&
985 strcmp(psz, stszGzObjFileExt) == 0) {
986 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
987 if (pn_gzipped != NULL) *pn_gzipped = TRUE;
988 return TRUE;
989 }
990 break;
991 case SYM_FILE_TYPE:
992 if ((psz=strstr(file_name, ".sym")) != NULL &&
993 strcmp(psz, ".sym") == 0) {
994 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
995 return TRUE;
996 } else if ((psz=strstr(file_name, ".tgs")) != NULL &&
997 strcmp(psz, ".tgs") == 0) {
998 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
999 return TRUE;
1000 } else if ((psz=strstr(file_name, stszSymFileExt)) != NULL &&
1001 strcmp(psz, stszSymFileExt) == 0) {
1002 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
1003 return TRUE;
1004 }
1005 break;
1006 case PIN_FILE_TYPE:
1007 if ((psz=strstr(file_name, ".pin")) != NULL &&
1008 strcmp(psz, ".pin") == 0) {
1009 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
1010 return TRUE;
1011 } else if ((psz=strstr(file_name, ".tgp")) != NULL &&
1012 strcmp(psz, ".tgp") == 0) {
1013 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
1014 return TRUE;
1015 } else if ((psz=strstr(file_name, stszPinFileExt)) != NULL &&
1016 strcmp(psz, stszPinFileExt) == 0) {
1017 if (pn_no_name != NULL) *pn_no_name = (psz == file_name);
1018 return TRUE;
1019 }
1020 break;
1021 }
1022 if (pn_no_name != NULL) *pn_no_name = (*file_name == '\0');
1023
1024 return FALSE;
1025 }
1026
RemoveFileNameExtension(file_name)1027 void RemoveFileNameExtension(file_name)
1028 char *file_name;
1029 {
1030 static char stszObjFileExt[20], stszGzObjFileExt[20];
1031 static char stszSymFileExt[20];
1032 static char stszPinFileExt[20];
1033 static int initialized=FALSE;
1034 char *psz=NULL;
1035 int len=strlen(file_name);
1036
1037 if (!initialized) {
1038 sprintf(stszObjFileExt, ".%s", OBJ_FILE_EXT);
1039 sprintf(stszGzObjFileExt, ".%s.gz", OBJ_FILE_EXT);
1040 sprintf(stszSymFileExt, ".%s", SYM_FILE_EXT);
1041 sprintf(stszPinFileExt, ".%s", PIN_FILE_EXT);
1042 initialized = TRUE;
1043 }
1044 if ((psz=strstr(file_name, ".obj")) != NULL &&
1045 strcmp(psz, ".obj") == 0) {
1046 file_name[len-strlen(".obj")] = '\0';
1047 } else if ((psz=strstr(file_name, ".obj.gz")) != NULL &&
1048 strcmp(psz, ".obj.gz") == 0) {
1049 file_name[len-strlen(".obj.gz")] = '\0';
1050 } else if ((psz=strstr(file_name, ".tgo")) != NULL &&
1051 strcmp(psz, ".tgo") == 0) {
1052 file_name[len-strlen(".tgo")] = '\0';
1053 } else if ((psz=strstr(file_name, ".tgo.gz")) != NULL &&
1054 strcmp(psz, ".tgo.gz") == 0) {
1055 file_name[len-strlen(".tgo.gz")] = '\0';
1056 } else if ((psz=strstr(file_name, stszObjFileExt)) != NULL &&
1057 strcmp(psz, stszObjFileExt) == 0) {
1058 file_name[len-strlen(stszObjFileExt)] = '\0';
1059 } else if ((psz=strstr(file_name, stszGzObjFileExt)) != NULL &&
1060 strcmp(psz, stszGzObjFileExt) == 0) {
1061 file_name[len-strlen(stszGzObjFileExt)] = '\0';
1062 } else if ((psz=strstr(file_name, ".sym")) != NULL &&
1063 strcmp(psz, ".sym") == 0) {
1064 file_name[len-strlen(".sym")] = '\0';
1065 } else if ((psz=strstr(file_name, ".tgs")) != NULL &&
1066 strcmp(psz, ".tgs") == 0) {
1067 file_name[len-strlen(".tgs")] = '\0';
1068 } else if ((psz=strstr(file_name, stszSymFileExt)) != NULL &&
1069 strcmp(psz, stszSymFileExt) == 0) {
1070 file_name[len-strlen(stszSymFileExt)] = '\0';
1071 } else if ((psz=strstr(file_name, ".pin")) != NULL &&
1072 strcmp(psz, ".pin") == 0) {
1073 file_name[len-strlen(".pin")] = '\0';
1074 } else if ((psz=strstr(file_name, ".tgp")) != NULL &&
1075 strcmp(psz, ".tgp") == 0) {
1076 file_name[len-strlen(".tgp")] = '\0';
1077 } else if ((psz=strstr(file_name, stszPinFileExt)) != NULL &&
1078 strcmp(psz, stszPinFileExt) == 0) {
1079 file_name[len-strlen(stszPinFileExt)] = '\0';
1080 }
1081 }
1082
FixDecimalPoint(buf)1083 int FixDecimalPoint(buf)
1084 char *buf;
1085 {
1086 char *psz=strchr(buf, ','), *psz2=NULL;
1087
1088 if (psz == NULL) {
1089 return TRUE;
1090 }
1091 psz2 = strchr(&psz[1], ',');
1092 if (psz2 == NULL) {
1093 *psz = '.';
1094 return TRUE;
1095 }
1096 return FALSE;
1097 }
1098
Save(FP,BotObjPtr,Level,PageNumber)1099 void Save(FP, BotObjPtr, Level, PageNumber)
1100 FILE *FP;
1101 struct ObjRec *BotObjPtr;
1102 int Level, PageNumber;
1103 {
1104 int watch_cursor=watchCursorOnMainWindow;
1105 struct ObjRec *obj_ptr=NULL;
1106
1107 if (BotObjPtr != NULL && !copyInDrawTextMode) {
1108 SetCurChoice(NOTHING);
1109
1110 if (!watch_cursor) {
1111 SetWatchCursor(drawWindow);
1112 SetWatchCursor(mainWindow);
1113 }
1114 }
1115 if (Level == 0 && PageNumber == 1) {
1116 char font_str[MAXSTRING], print_mag_str[MAXSTRING];
1117
1118 ResetXPmErrorMessage();
1119 GetPSFontStr(curFont, curStyle, font_str);
1120 SetFullVersionString();
1121 /* do not translate -- program constants */
1122 if (fprintf(FP, "%%TGIF %s\n", fullVersionString) == EOF) {
1123 writeFileFailed = TRUE;
1124 }
1125 snprintf(print_mag_str, sizeof(print_mag_str), "%.3f", printMag);
1126 if (!FixDecimalPoint(print_mag_str)) {
1127 /* do not translate -- program constants */
1128 sprintf(gszMsgBox, TgLoadString(STID_BAD_GIVEN_LINE_WRITTEN),
1129 "print_mag");
1130 if (PRTGIF) {
1131 fprintf(stderr, "%s\n", gszMsgBox);
1132 } else {
1133 Msg(gszMsgBox);
1134 }
1135 writeFileFailed = TRUE;
1136 }
1137 if (fprintf(FP, "state(%1d,%1d,%s,", pageStyle, CUR_VERSION,
1138 print_mag_str) == EOF) {
1139 writeFileFailed = TRUE;
1140 }
1141 if (fprintf(FP, "%1d,%1d,%1d,", drawOrigX, drawOrigY, zoomScale) == EOF) {
1142 writeFileFailed = TRUE;
1143 }
1144 if (fprintf(FP, "%1d,%1d,%1d,", xyEnglishGrid, snapOn, colorIndex) ==
1145 EOF) {
1146 writeFileFailed = TRUE;
1147 }
1148 if (fprintf(FP, "%1d,%1d,%1d,", horiAlign, vertAlign, lineWidth) == EOF) {
1149 writeFileFailed = TRUE;
1150 }
1151 if (fprintf(FP, "%1d,%1d,%1d,%1d,", curSpline, lineStyle, objFill,
1152 penPat) == EOF) {
1153 writeFileFailed = TRUE;
1154 }
1155 if (fprintf(FP, "%1d,'%s',%1d,%1d,", textJust,
1156 /* font_str starts with the '/' character */
1157 &font_str[1], curStyle, GetCurSzUnit()) == EOF) {
1158 writeFileFailed = TRUE;
1159 }
1160 if (fprintf(FP, "%1d,%1d,%1d,", 0, curDash, gridSystem) == EOF) {
1161 writeFileFailed = TRUE;
1162 }
1163 if (fprintf(FP, "%1d,%1d,%1d,", xyMetricGrid, textVSpace, zoomedIn) ==
1164 EOF) {
1165 writeFileFailed = TRUE;
1166 }
1167 if (fprintf(FP, "%1d,%1d,%1d,", gridShown, moveMode, ROTATE0) == EOF) {
1168 writeFileFailed = TRUE;
1169 }
1170 if (fprintf(FP, "%1d,%1d,", rcbRadius, useGray) == EOF) {
1171 writeFileFailed = TRUE;
1172 }
1173 if (fprintf(FP, "%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d).\n",
1174 pageLayoutMode,
1175 (pageLayoutMode == PAGE_STACK) ? curPageNum : paperCol,
1176 (pageLayoutMode == PAGE_STACK) ? lastPageNum : paperRow,
1177 pageLineShownInTileMode, colorDump,
1178 round(((float)onePageWidth)*printMag/100.0),
1179 round(((float)onePageHeight)*printMag/100.0),
1180 stretchableText, textRotation, rotationIncrement,
1181 transPat) == EOF) {
1182 writeFileFailed = TRUE;
1183 }
1184 if ((BotObjPtr != NULL || tgifObj != NULL) && !copyInDrawTextMode &&
1185 !serializingFile) {
1186 char script_frac_str[MAXSTRING];
1187
1188 if (fprintf(FP, "%%\n") == EOF) {
1189 writeFileFailed = TRUE;
1190 }
1191 if (fprintf(FP, "%% @%s%s\n", "(#)$H", "eader$") == EOF) {
1192 writeFileFailed = TRUE;
1193 }
1194 if (fprintf(FP, "%% %s\n", "%W%") == EOF) {
1195 writeFileFailed = TRUE;
1196 }
1197 if (fprintf(FP, "%%\n") == EOF) {
1198 writeFileFailed = TRUE;
1199 }
1200 if (savedComments != NULL) {
1201 if (fputs(savedComments, FP) == EOF) {
1202 writeFileFailed = TRUE;
1203 }
1204 }
1205 if (tgifObj->lattr != NULL) {
1206 if (fprintf(FP, "file_attr(") == EOF) writeFileFailed = TRUE;
1207 SaveAttrs(FP, tgifObj->lattr);
1208 if (fprintf(FP, ").\n") == EOF) writeFileFailed = TRUE;
1209 }
1210 GetUnitSpec(gszMsgBox);
1211 if (fprintf(FP, "unit(\"") == EOF) writeFileFailed = TRUE;
1212 SaveString(FP, gszMsgBox);
1213 if (fprintf(FP, "\").\n") == EOF) writeFileFailed = TRUE;
1214 if (shapeShadowInResource ||
1215 shapeShadowDx != 0 || shapeShadowDy != 0) {
1216 if (fprintf(FP, "shapeshadow(%1d,%1d).\n", shapeShadowDx,
1217 shapeShadowDy) == EOF) {
1218 writeFileFailed = TRUE;
1219 }
1220 }
1221 SaveColors(FP);
1222 if (slideShowInfoValid) {
1223 if (fprintf(FP, "slideshow_info('%s',%1d,%1d).\n",
1224 (slideShowBorderColor==NULL ? "" : slideShowBorderColor),
1225 slideShowXOffset, slideShowYOffset) == EOF) {
1226 writeFileFailed = TRUE;
1227 }
1228 }
1229 UtilStrCpyN(script_frac_str, sizeof(script_frac_str), scriptFractionStr);
1230 if (!FixDecimalPoint(script_frac_str)) {
1231 /* do not translate -- program constants */
1232 sprintf(gszMsgBox, TgLoadString(STID_BAD_GIVEN_LINE_WRITTEN),
1233 "script_frac");
1234 if (PRTGIF) {
1235 fprintf(stderr, "%s\n", gszMsgBox);
1236 } else {
1237 Msg(gszMsgBox);
1238 }
1239 writeFileFailed = TRUE;
1240 }
1241 if (fprintf(FP, "script_frac(\"%s\").\n", script_frac_str) == EOF) {
1242 writeFileFailed = TRUE;
1243 }
1244 if (fprintf(FP, "fg_bg_colors('%s','%s').\n",
1245 colorMenuItems[colorIndex], (*defaultBgColorStr=='\0' ?
1246 myBgColorStr : defaultBgColorStr)) == EOF) {
1247 /*
1248 * The above should use colorMenuItmes[bgColorIndex]
1249 * and not myBgColorStr.
1250 */
1251 writeFileFailed = TRUE;
1252 }
1253 if (*gszHhtmlExportTemplate != '\0') {
1254 if (fprintf(FP, "html_export_template(\"%s\").\n",
1255 gszHhtmlExportTemplate) == EOF) {
1256 writeFileFailed = TRUE;
1257 }
1258 }
1259 SaveDontReencode(FP);
1260 SavePSFontAliases(FP);
1261 SaveDoubleByteModBytes(FP);
1262 if (fprintf(FP, "objshadow_info('%s',%1d,%1d).\n",
1263 objShadowColorStr, objShadowXOffset, objShadowYOffset) == EOF) {
1264 writeFileFailed = TRUE;
1265 }
1266 if (fprintf(FP, "rotate_pivot(%1d,%1d,%1d,%1d).\n",
1267 autoRotatePivot, rotatePivotAbsXYValid, rotatePivotAbsX,
1268 rotatePivotAbsY) == EOF) {
1269 writeFileFailed = TRUE;
1270 }
1271 if (fprintf(FP, "spline_tightness(%1d).\n", tighterStructSplines) ==
1272 EOF) {
1273 writeFileFailed = TRUE;
1274 }
1275 if (rightMarginEnabled != INVALID) {
1276 if (fprintf(FP, "right_margin(%1d,%1d).\n", rightMarginEnabled,
1277 rightMargin) == EOF) {
1278 writeFileFailed = TRUE;
1279 }
1280 }
1281 if (threshFillReplaceEnabled) {
1282 if (fprintf(FP, "threshold_fill_replace(%1d,%1d,%1d).\n",
1283 fillReplaceRedThresh, fillReplaceGreenThresh,
1284 fillReplaceBlueThresh) == EOF) {
1285 writeFileFailed = TRUE;
1286 }
1287 }
1288 SavePSCharSubs(FP);
1289 SavePSFontNeedCharSubs(FP);
1290 }
1291 }
1292 if (Level == 0 && BotObjPtr != NULL && !copyInDrawTextMode) {
1293 if (fprintf(FP, "page(%1d,\"", PageNumber) == EOF) writeFileFailed = TRUE;
1294 SaveString(FP, ((pageLayoutMode==PAGE_TILE || curPage->name==NULL) ? "" :
1295 curPage->name));
1296 if (fprintf(FP, "\",%1d,'%s').\n", curPage->layer_on,
1297 ((pageLayoutMode==PAGE_TILE || curPage->page_file_name==NULL) ? "" :
1298 curPage->page_file_name)) == EOF) {
1299 writeFileFailed = TRUE;
1300 }
1301 }
1302
1303 for (obj_ptr=BotObjPtr; obj_ptr != NULL; obj_ptr=obj_ptr->prev) {
1304 SaveObj(FP, obj_ptr, Level);
1305 if (obj_ptr->prev == NULL) {
1306 if (Level == 0) {
1307 if (fprintf(FP, ".\n") == EOF) writeFileFailed = TRUE;
1308 } else {
1309 if (fprintf(FP, "\n") == EOF) writeFileFailed = TRUE;
1310 }
1311 } else {
1312 if (Level == 0) {
1313 if (fprintf(FP, ".\n") == EOF) writeFileFailed = TRUE;
1314 } else {
1315 if (fprintf(FP, ",\n") == EOF) writeFileFailed = TRUE;
1316 }
1317 }
1318 }
1319 if (BotObjPtr != NULL && !copyInDrawTextMode) {
1320 if (!watch_cursor) {
1321 SetDefaultCursor(mainWindow);
1322 ShowCursor();
1323 }
1324 }
1325 }
1326
SaveTmpFile(NewFileName)1327 int SaveTmpFile(NewFileName)
1328 char *NewFileName;
1329 /* return TRUE if file successfully saved */
1330 {
1331 char new_file_name[MAXPATHLENGTH+1], *rest=NULL;
1332 FILE *fp=NULL;
1333 int count=0, file_type=INVALID, short_name, watch_cursor=FALSE;
1334 struct PageRec *saved_cur_page;
1335 struct ObjRec *obj_ptr;
1336 struct ObjRec *obj_ptr1=NULL, *obj_ptr2=NULL;
1337 struct AttrRec *attr_ptr;
1338
1339 UtilStrCpyN(new_file_name, sizeof(new_file_name), NewFileName);
1340
1341 saved_cur_page = curPage;
1342 for (curPage=firstPage; curPage != NULL; curPage=curPage->next) {
1343 for (obj_ptr=curPage->top; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
1344 if (obj_ptr->type == OBJ_SYM) {
1345 if (obj_ptr1 == NULL) {
1346 obj_ptr1 = obj_ptr;
1347 } else if (obj_ptr2 == NULL) {
1348 obj_ptr2 = obj_ptr;
1349 }
1350 count++;
1351 }
1352 }
1353 }
1354 curPage = saved_cur_page;
1355
1356 switch (count) {
1357 case 0:
1358 sprintf(new_file_name, "%s.%s", NewFileName, OBJ_FILE_EXT);
1359 file_type = OBJ_FILE_TYPE;
1360 break;
1361 case 1:
1362 if (lastPageNum != 1) {
1363 MsgBox(TgLoadString(STID_ONE_PAGE_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
1364 return INVALID;
1365 }
1366 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) != NULL &&
1367 strcmp(attr_ptr->attr_value.s, "tgif_pin") == 0) {
1368 sprintf(new_file_name, "%s.%s", NewFileName, PIN_FILE_EXT);
1369 file_type = PIN_FILE_TYPE;
1370 } else {
1371 sprintf(new_file_name, "%s.%s", NewFileName, SYM_FILE_EXT);
1372 file_type = SYM_FILE_TYPE;
1373 }
1374 break;
1375 case 2:
1376 if (lastPageNum != 1) {
1377 MsgBox(TgLoadString(STID_ONE_PAGE_PIN_ABORT_SAVE), TOOL_NAME, INFO_MB);
1378 return INVALID;
1379 }
1380 sprintf(new_file_name, "%s.%s", NewFileName, PIN_FILE_EXT);
1381 file_type = PIN_FILE_TYPE;
1382 break;
1383 default:
1384 MsgBox(TgLoadString(STID_TOO_MANY_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
1385 return INVALID;
1386 }
1387
1388 unlink(new_file_name);
1389
1390 if ((short_name=IsPrefix(bootDir, new_file_name, &rest))) ++rest;
1391 if ((fp=fopen(new_file_name, "w")) == NULL) {
1392 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
1393 (short_name ? rest : new_file_name));
1394 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1395 return INVALID;
1396 }
1397 sprintf(gszMsgBox, TgLoadString(STID_SAVE_TMP_FILE_DOTS),
1398 (short_name ? rest : new_file_name));
1399 Msg(gszMsgBox);
1400
1401 watch_cursor = watchCursorOnMainWindow;
1402 if (!watch_cursor) {
1403 SetWatchCursor(drawWindow);
1404 SetWatchCursor(mainWindow);
1405 }
1406 writeFileFailed = FALSE;
1407 MakeQuiescent();
1408 saved_cur_page = curPage;
1409 for (curPage=firstPage, count=1; curPage != NULL;
1410 curPage=curPage->next, count++) {
1411 topObj = curPage->top;
1412 botObj = curPage->bot;
1413 Save(fp, botObj, 0, count);
1414 }
1415 curPage = saved_cur_page;
1416 topObj = curPage->top;
1417 botObj = curPage->bot;
1418 fclose(fp);
1419 if (!watch_cursor) {
1420 SetDefaultCursor(mainWindow);
1421 ShowCursor();
1422 }
1423 if (writeFileFailed) {
1424 writeFileFailed = FALSE;
1425 FailToWriteFileMessage(new_file_name);
1426 } else {
1427 sprintf(gszMsgBox, TgLoadString(STID_TMP_FILE_SAVED),
1428 (short_name ? rest : new_file_name));
1429 Msg(gszMsgBox);
1430 }
1431
1432 if (tmpFileMode != 0 && chmod(new_file_name, tmpFileMode)) {
1433 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD),
1434 (short_name ? rest : new_file_name), tmpFileMode);
1435 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1436 }
1437 SetCurChoice(curChoiceBeforeMakeQuiescent);
1438
1439 return file_type;
1440 }
1441
SaveNewFile(SaveSelectedOnly,pszNewFile)1442 void SaveNewFile(SaveSelectedOnly, pszNewFile)
1443 int SaveSelectedOnly;
1444 char *pszNewFile;
1445 {
1446 char new_file_name[MAXPATHLENGTH+1], gzipped_fname[MAXPATHLENGTH+1];
1447 char new_full_name[MAXPATHLENGTH+1], tmp_str[MAXPATHLENGTH+1], *rest=NULL;
1448 char saved_cur_dir[MAXPATHLENGTH+1], saved_cur_file_name[MAXPATHLENGTH+1];
1449 char obj_ext_str[MAXSTRING+1], gz_obj_ext_str[MAXSTRING+1];
1450 char sym_ext_str[MAXSTRING+1], pin_ext_str[MAXSTRING+1];
1451 int saved_cur_file_defined=FALSE, no_name=FALSE, gzipped=FALSE, file_type=0;
1452 int count=0, len, short_name=FALSE, ok=TRUE, watch_cursor=FALSE;
1453 struct ObjRec *obj_ptr=NULL, *saved_top_obj=NULL, *saved_bot_obj=NULL;
1454 struct ObjRec *obj_ptr1=NULL, *obj_ptr2=NULL;
1455 struct SelRec *top_sel_ptr=NULL, *bot_sel_ptr=NULL;
1456 struct SelRec *sel_ptr=NULL, *next_sel=NULL;
1457 struct PageRec *saved_cur_page=NULL;
1458 struct AttrRec *attr_ptr=NULL;
1459 FILE *fp=NULL;
1460
1461 file_type = OBJ_FILE_TYPE;
1462 *gzipped_fname = '\0';
1463
1464 if (SaveSelectedOnly && pszNewFile == NULL && topSel == NULL) {
1465 MsgBox("No objects selected!\n\nNothing saved!", TOOL_NAME, INFO_MB);
1466 return;
1467 }
1468 if (SaveSelectedOnly && pszNewFile != NULL) {
1469 UtilStrCpyN(new_file_name, sizeof(new_file_name), pszNewFile);
1470 } else if (pszNewFile != NULL && strcmp(pszNewFile, "-1") != 0) {
1471 UtilStrCpyN(new_file_name, sizeof(new_file_name), pszNewFile);
1472 len = strlen(new_file_name);
1473 if (len > 0 && new_file_name[len-1] == ')') {
1474 new_file_name[len-1] = '\0';
1475 }
1476 } else {
1477 sprintf(gszMsgBox, TgLoadString(STID_WORKING_DIRECTORY_IS),
1478 (curDirIsLocal ? curDir : curLocalDir));
1479 *new_file_name = '\0';
1480 Dialog(TgLoadString(STID_ENTER_NEW_FNAME_ACCEPT_CANCEL), gszMsgBox,
1481 new_file_name);
1482 }
1483 UtilTrimBlanks(new_file_name);
1484 if (*new_file_name == '\0') return;
1485 len = strlen(new_file_name);
1486
1487 if (SaveSelectedOnly) {
1488 for (sel_ptr=topSel; sel_ptr != NULL; sel_ptr=sel_ptr->next) {
1489 if (sel_ptr->obj->type == OBJ_SYM) {
1490 if (obj_ptr1 == NULL) {
1491 obj_ptr1 = sel_ptr->obj;
1492 } else if (obj_ptr2 == NULL) {
1493 obj_ptr2 = sel_ptr->obj;
1494 }
1495 count++;
1496 }
1497 }
1498 } else {
1499 saved_cur_page = curPage;
1500 for (curPage=firstPage; curPage != NULL; curPage=curPage->next) {
1501 for (obj_ptr=curPage->top; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
1502 if (obj_ptr->type == OBJ_SYM) {
1503 if (obj_ptr1 == NULL) {
1504 obj_ptr1 = obj_ptr;
1505 } else if (obj_ptr2 == NULL) {
1506 obj_ptr2 = obj_ptr;
1507 }
1508 count++;
1509 }
1510 }
1511 }
1512 curPage = saved_cur_page;
1513 }
1514 sprintf(obj_ext_str, ".%s", OBJ_FILE_EXT);
1515 sprintf(gz_obj_ext_str, ".%s.gz", OBJ_FILE_EXT);
1516 sprintf(sym_ext_str, ".%s", SYM_FILE_EXT);
1517 sprintf(pin_ext_str, ".%s", PIN_FILE_EXT);
1518
1519 if (count > 2) {
1520 MsgBox(TgLoadString(STID_TOO_MANY_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
1521 return;
1522 }
1523 if (count >= 1 && lastPageNum != 1) {
1524 MsgBox(TgLoadString(count==1 ? STID_ONE_PAGE_SYM_ABORT_SAVE :
1525 STID_ONE_PAGE_PIN_ABORT_SAVE), TOOL_NAME, INFO_MB);
1526 return;
1527 }
1528 switch (count) {
1529 case 0:
1530 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, &gzipped,
1531 &no_name)) {
1532 /* don't modify */
1533 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
1534 &no_name)) {
1535 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_NO_SYM_FOUND), TOOL_NAME,
1536 INFO_MB);
1537 return;
1538 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
1539 &no_name)) {
1540 MsgBox(TgLoadString(STID_CANT_SAVE_PIN_NO_SYM_FOUND), TOOL_NAME,
1541 INFO_MB);
1542 return;
1543 } else {
1544 strcat(new_file_name, obj_ext_str);
1545 }
1546 file_type = OBJ_FILE_TYPE;
1547 break;
1548 case 1:
1549 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) != NULL &&
1550 strcmp(attr_ptr->attr_value.s, "tgif_pin") == 0) {
1551 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL,
1552 &no_name)) {
1553 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
1554 INFO_MB);
1555 return;
1556 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
1557 &no_name)) {
1558 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_SAVE_AS_PIN), TOOL_NAME,
1559 INFO_MB);
1560 return;
1561 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
1562 &no_name)) {
1563 /* don't modify */
1564 } else {
1565 strcat(new_file_name, pin_ext_str);
1566 }
1567 file_type = PIN_FILE_TYPE;
1568 } else {
1569 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL,
1570 &no_name)) {
1571 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
1572 INFO_MB);
1573 return;
1574 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
1575 &no_name)) {
1576 /* don't modify */
1577 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
1578 &no_name)) {
1579 MsgBox(TgLoadString(STID_CANT_SAVE_PIN_ONE_SYM_FOUND), TOOL_NAME,
1580 INFO_MB);
1581 return;
1582 } else {
1583 strcat(new_file_name, sym_ext_str);
1584 }
1585 file_type = SYM_FILE_TYPE;
1586 }
1587 break;
1588 case 2:
1589 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL, &no_name)) {
1590 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_TWO_SYM_FOUND), TOOL_NAME,
1591 INFO_MB);
1592 return;
1593 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
1594 &no_name)) {
1595 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_TWO_SYM_FOUND), TOOL_NAME,
1596 INFO_MB);
1597 return;
1598 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
1599 &no_name)) {
1600 /* don't modify */
1601 } else {
1602 strcat(new_file_name, pin_ext_str);
1603 }
1604 if (obj_ptr2->fattr != NULL) {
1605 obj_ptr = obj_ptr2;
1606 obj_ptr2 = obj_ptr1;
1607 obj_ptr1 = obj_ptr;
1608 }
1609 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) == NULL) {
1610 MsgBox(TgLoadString(STID_CANT_FIND_TYPE_ATTR_NOT_SAVED), TOOL_NAME,
1611 INFO_MB);
1612 return;
1613 }
1614 if (strcmp(attr_ptr->attr_value.s, "tgif_pin") != 0) {
1615 sprintf(gszMsgBox, TgLoadString(STID_SYM_TYPE_WRONG_PIN_NOT_SAVED),
1616 "tgif_pin");
1617 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1618 return;
1619 }
1620 file_type = PIN_FILE_TYPE;
1621 break;
1622 default: return;
1623 }
1624 if (no_name) {
1625 MsgBox(TgLoadString(STID_NO_FILE_NAME_FILE_NOT_SAVED), TOOL_NAME,
1626 INFO_MB);
1627 return;
1628 }
1629 if (*new_file_name == DIR_SEP) {
1630 UtilStrCpyN(new_full_name, sizeof(new_full_name), new_file_name);
1631 } else if (curDirIsLocal) {
1632 sprintf(new_full_name, "%s%c%s", curDir, DIR_SEP, new_file_name);
1633 } else {
1634 sprintf(new_full_name, "%s%c%s", curLocalDir, DIR_SEP, new_file_name);
1635 }
1636 if (file_type == OBJ_FILE_TYPE && gzipped) {
1637 char tmp_fname[MAXPATHLENGTH];
1638
1639 if (MkTempFile(tmp_fname, sizeof(tmp_fname), tmpDir, TOOL_NAME) == NULL) {
1640 return;
1641 }
1642 strcpy(gzipped_fname, new_full_name);
1643 strcpy(new_full_name, tmp_fname);
1644 }
1645 if (!OkayToCreateFile((*gzipped_fname=='\0') ? new_full_name :
1646 gzipped_fname)) {
1647 if (*gzipped_fname != '\0') unlink(new_full_name);
1648 return;
1649 }
1650 if (*gzipped_fname == '\0') {
1651 if ((short_name=IsPrefix(bootDir, new_full_name, &rest))) ++rest;
1652 } else {
1653 if ((short_name=IsPrefix(bootDir, gzipped_fname, &rest))) ++rest;
1654 }
1655 if ((fp=fopen(new_full_name, "w")) == NULL) {
1656 if (short_name) {
1657 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
1658 rest);
1659 } else {
1660 if (*gzipped_fname == '\0') {
1661 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
1662 new_full_name);
1663 } else {
1664 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
1665 gzipped_fname);
1666 }
1667 }
1668 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1669 if (*gzipped_fname != '\0') unlink(new_full_name);
1670 return;
1671 }
1672 if (!SaveSelectedOnly) BeforeNavigate();
1673
1674 if (SaveSelectedOnly) {
1675 PushPageInfo();
1676 if (pageLayoutMode == PAGE_STACK) {
1677 paperCol = paperRow = curPageNum = lastPageNum = 1;
1678 }
1679 if (curDirIsLocal) {
1680 strcpy(saved_cur_dir, curDir);
1681 } else {
1682 strcpy(saved_cur_dir, curLocalDir);
1683 }
1684 strcpy(saved_cur_file_name, curFileName);
1685 saved_cur_file_defined = curFileDefined;
1686 saved_top_obj = topObj;
1687 saved_bot_obj = botObj;
1688
1689 if (topSel == NULL) {
1690 topObj = botObj = NULL;
1691 } else {
1692 JustDupSelObj(&top_sel_ptr, &bot_sel_ptr);
1693 topObj = top_sel_ptr->obj;
1694 botObj = bot_sel_ptr->obj;
1695 }
1696 firstPage = lastPage = curPage =
1697 (struct PageRec *)malloc(sizeof(struct PageRec));
1698 if (firstPage == NULL) FailAllocMessage();
1699 memset(firstPage, 0, sizeof(struct PageRec));
1700 firstPage->layer_on = TRUE;
1701 firstPage->top = topObj;
1702 firstPage->bot = botObj;
1703 firstPage->next = firstPage->prev = NULL;
1704 if (pageLayoutMode == PAGE_STACK) {
1705 firstPage->draw_orig_x = drawOrigX;
1706 firstPage->draw_orig_y = drawOrigY;
1707 firstPage->zoom_scale = zoomScale;
1708 firstPage->zoomed_in = zoomedIn;
1709 curPageNum = lastPageNum = 1;
1710 }
1711 for (sel_ptr=topSel, obj_ptr=topObj; obj_ptr!=NULL;
1712 sel_ptr=sel_ptr->next, obj_ptr=obj_ptr->next) {
1713 CopyObjId(sel_ptr->obj, obj_ptr);
1714 CopyObjLocks(sel_ptr->obj, obj_ptr);
1715 }
1716 }
1717
1718 if (curDirIsLocal) {
1719 strcpy(tmp_str, curDir);
1720 } else {
1721 strcpy(tmp_str, curLocalDir);
1722 }
1723 if (*gzipped_fname == '\0') {
1724 SetCurDir(new_full_name);
1725 } else {
1726 SetCurDir(gzipped_fname);
1727 }
1728 curFileDefined = TRUE;
1729 if (cmdLineMerge) {
1730 cmdLineMerge = FALSE;
1731 }
1732 switch (count) {
1733 case 0:
1734 *curSymDir = '\0';
1735 if ((strcmp(tmp_str, (curDirIsLocal ? curDir : curLocalDir)) != 0) ||
1736 (!NameInCurDir(curFileName))) {
1737 UpdateDirInfo();
1738 }
1739 break;
1740 default:
1741 strcpy(curSymDir, (curDirIsLocal ? curDir : curLocalDir));
1742 if (!DirInSymPath(curDirIsLocal ? curDir : curLocalDir)) {
1743 UpdateSymInfo();
1744 }
1745 break;
1746 }
1747 if (short_name) {
1748 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), rest);
1749 } else {
1750 if (*gzipped_fname == '\0') {
1751 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), new_full_name);
1752 } else {
1753 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), gzipped_fname);
1754 }
1755 }
1756 Msg(gszMsgBox);
1757
1758 if (!saveCommentsInSaveNew) CleanUpComments();
1759 watch_cursor = watchCursorOnMainWindow;
1760 if (!watch_cursor) {
1761 SetWatchCursor(drawWindow);
1762 SetWatchCursor(mainWindow);
1763 }
1764 writeFileFailed = FALSE;
1765 saved_cur_page = curPage;
1766 for (curPage=firstPage, count=1; curPage != NULL;
1767 curPage=curPage->next, count++) {
1768 topObj = curPage->top;
1769 botObj = curPage->bot;
1770 Save(fp, botObj, 0, count);
1771 }
1772 curPage = saved_cur_page;
1773 topObj = curPage->top;
1774 botObj = curPage->bot;
1775 fclose(fp);
1776 if (!watch_cursor) {
1777 SetDefaultCursor(mainWindow);
1778 ShowCursor();
1779 }
1780 if (writeFileFailed) {
1781 writeFileFailed = FALSE;
1782 FailToWriteFileMessage(new_full_name);
1783 ok = FALSE;
1784 } else {
1785 if (*gzipped_fname != '\0') {
1786 if (!GzipFile(new_full_name, gzipped_fname)) {
1787 sprintf(gszMsgBox, TgLoadString(STID_PROBLEM_ZIPPING_PLEASE_SAVE),
1788 new_full_name, gzipped_fname, new_full_name);
1789 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1790 ok = FALSE;
1791 }
1792 unlink(new_full_name);
1793 strcpy(new_full_name, gzipped_fname);
1794 }
1795 if (ok) {
1796 sprintf(gszMsgBox, TgLoadString(STID_FILE_SAVED),
1797 (short_name ? rest : new_full_name));
1798 Msg(gszMsgBox);
1799 } else {
1800 sprintf(gszMsgBox, TgLoadString(STID_FILE_NOT_SAVED),
1801 (short_name ? rest : new_full_name));
1802 Msg(gszMsgBox);
1803 }
1804 }
1805 if (SaveSelectedOnly) {
1806 CleanUpPage();
1807 for (sel_ptr=top_sel_ptr; sel_ptr != NULL; sel_ptr=next_sel) {
1808 next_sel = sel_ptr->next;
1809 free(sel_ptr);
1810 }
1811
1812 topObj = saved_top_obj;
1813 botObj = saved_bot_obj;
1814 if (curDirIsLocal) {
1815 strcpy(curDir, saved_cur_dir);
1816 } else {
1817 strcpy(curLocalDir, saved_cur_dir);
1818 }
1819 strcpy(curFileName, saved_cur_file_name);
1820 curFileDefined = saved_cur_file_defined;
1821 PopPageInfo();
1822 } else if (ok) {
1823 SetFileModified(FALSE);
1824 RedrawTitleWindow();
1825 SetUnSavableFile(FALSE);
1826 }
1827 if (!SaveSelectedOnly && !PRTGIF) CommitNavigate();
1828 }
1829
SaveSymInLibrary()1830 void SaveSymInLibrary()
1831 {
1832 char new_file_name[MAXPATHLENGTH+1];
1833 char new_full_name[MAXPATHLENGTH+1], dir_name[MAXPATHLENGTH+1];
1834 char saved_dir[MAXPATHLENGTH+1], saved_file[MAXPATHLENGTH+1];
1835 char saved_sym_dir[MAXPATHLENGTH+1], *rest=NULL;
1836 char sym_ext_str[MAXSTRING+1], pin_ext_str[MAXSTRING+1], *c_ptr;
1837 FILE *fp;
1838 int count=0, short_name, watch_cursor=FALSE;
1839 int saved_cur_file_defined, file_type=INVALID;
1840 struct ObjRec *obj_ptr;
1841 struct PageRec *saved_cur_page;
1842 struct ObjRec *obj_ptr1=NULL, *obj_ptr2=NULL;
1843 struct AttrRec *attr_ptr;
1844
1845 saved_cur_page = curPage;
1846 for (curPage=firstPage; curPage != NULL; curPage=curPage->next) {
1847 for (obj_ptr=curPage->top; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
1848 if (obj_ptr->type == OBJ_SYM) {
1849 if (obj_ptr1 == NULL) {
1850 obj_ptr1 = obj_ptr;
1851 } else if (obj_ptr2 == NULL) {
1852 obj_ptr2 = obj_ptr;
1853 }
1854 count++;
1855 }
1856 }
1857 }
1858 curPage = saved_cur_page;
1859
1860 switch (count) {
1861 case 0:
1862 MsgBox(TgLoadString(STID_NO_SYM_FOUND_SYM_NOT_SAVED), TOOL_NAME, INFO_MB);
1863 return;
1864 case 1:
1865 if (lastPageNum != 1) {
1866 MsgBox(TgLoadString(STID_ONE_PAGE_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
1867 return;
1868 }
1869 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) != NULL &&
1870 strcmp(attr_ptr->attr_value.s, "tgif_pin") == 0) {
1871 file_type = PIN_FILE_TYPE;
1872 } else {
1873 file_type = SYM_FILE_TYPE;
1874 }
1875 break;
1876 case 2:
1877 if (lastPageNum != 1) {
1878 MsgBox(TgLoadString(STID_ONE_PAGE_PIN_ABORT_SAVE), TOOL_NAME, INFO_MB);
1879 return;
1880 }
1881 if (obj_ptr2->fattr != NULL) {
1882 obj_ptr = obj_ptr2;
1883 obj_ptr2 = obj_ptr1;
1884 obj_ptr1 = obj_ptr;
1885 }
1886 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) == NULL) {
1887 MsgBox(TgLoadString(STID_CANT_FIND_TYPE_ATTR_NOT_SAVED), TOOL_NAME,
1888 INFO_MB);
1889 return;
1890 }
1891 if (strcmp(attr_ptr->attr_value.s, "tgif_pin") != 0) {
1892 sprintf(gszMsgBox, TgLoadString(STID_SYM_TYPE_WRONG_PIN_NOT_SAVED),
1893 "tgif_pin");
1894 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1895 return;
1896 }
1897 file_type = PIN_FILE_TYPE;
1898 break;
1899 default:
1900 MsgBox(TgLoadString(STID_TOO_MANY_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
1901 return;
1902 }
1903 MakeQuiescent();
1904
1905 sprintf(sym_ext_str, ".%s", SYM_FILE_EXT);
1906 sprintf(pin_ext_str, ".%s", PIN_FILE_EXT);
1907
1908 if (*curFileName == '\0') {
1909 int no_name=FALSE;
1910
1911 *new_file_name = '\0';
1912 Dialog(TgLoadString(STID_ENTER_NEW_FILE_NAME),
1913 TgLoadCachedString(CSTID_DLG_ACCEPT_CANCEL), new_file_name);
1914 UtilTrimBlanks(new_file_name);
1915 if (*new_file_name == '\0') return;
1916
1917 if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL, &no_name)) {
1918 /* do nothing */
1919 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
1920 &no_name)) {
1921 /* do nothing */
1922 } else if (count == 1) {
1923 if (file_type == SYM_FILE_TYPE) {
1924 strcat(new_file_name, sym_ext_str);
1925 } else {
1926 strcat(new_file_name, pin_ext_str);
1927 }
1928 } else {
1929 strcat(new_file_name, pin_ext_str);
1930 }
1931 if (no_name) {
1932 MsgBox(TgLoadString(STID_NO_FILE_NAME_FILE_NOT_SAVED), TOOL_NAME,
1933 INFO_MB);
1934 return;
1935 }
1936 } else {
1937 c_ptr = UtilStrRChr(curFileName, DIR_SEP);
1938 strcpy(new_file_name, (c_ptr==NULL) ? curFileName : ++c_ptr);
1939 }
1940 if (SelectSymDir(dir_name) == INVALID) {
1941 Msg("");
1942 return;
1943 }
1944 if (strcmp(dir_name, ".") == 0) {
1945 sprintf(new_full_name, "%s%c%s", (curDirIsLocal ? curDir : curLocalDir),
1946 DIR_SEP, new_file_name);
1947 } else {
1948 sprintf(new_full_name, "%s%c%s", dir_name, DIR_SEP, new_file_name);
1949 }
1950
1951 if (!OkayToCreateFile(new_full_name)) return;
1952
1953 if ((short_name=IsPrefix(bootDir, new_full_name, &rest))) ++rest;
1954 if ((fp=fopen(new_full_name, "w")) == NULL) {
1955 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
1956 (short_name ? rest : new_full_name));
1957 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
1958 return;
1959 }
1960
1961 strcpy(saved_dir, (curDirIsLocal ? curDir : curLocalDir));
1962 strcpy(saved_file, curFileName);
1963 strcpy(saved_sym_dir, curSymDir);
1964 saved_cur_file_defined = curFileDefined;
1965 SetCurDir(new_full_name);
1966 curFileDefined = TRUE;
1967
1968 strcpy(curSymDir, (curDirIsLocal ? curDir : curLocalDir));
1969 if (!DirInSymPath(curDirIsLocal ? curDir : curLocalDir)) UpdateSymInfo();
1970
1971 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS),
1972 (short_name ? rest : new_full_name));
1973 Msg(gszMsgBox);
1974
1975 if (!saveCommentsInSaveNew) CleanUpComments();
1976 watch_cursor = watchCursorOnMainWindow;
1977 if (!watch_cursor) {
1978 SetWatchCursor(drawWindow);
1979 SetWatchCursor(mainWindow);
1980 }
1981 writeFileFailed = FALSE;
1982 saved_cur_page = curPage;
1983 for (curPage=firstPage, count=1; curPage != NULL;
1984 curPage=curPage->next, count++) {
1985 topObj = curPage->top;
1986 botObj = curPage->bot;
1987 Save(fp, botObj, 0, count);
1988 }
1989 curPage = saved_cur_page;
1990 topObj = curPage->top;
1991 botObj = curPage->bot;
1992 fclose(fp);
1993 if (!watch_cursor) {
1994 SetDefaultCursor(mainWindow);
1995 ShowCursor();
1996 }
1997 if (writeFileFailed) {
1998 writeFileFailed = FALSE;
1999 FailToWriteFileMessage(new_full_name);
2000 } else {
2001 sprintf(gszMsgBox, TgLoadString(STID_FILE_SAVED),
2002 (short_name ? rest : new_full_name));
2003 Msg(gszMsgBox);
2004 }
2005
2006 if (curDirIsLocal) {
2007 strcpy(curDir, saved_dir);
2008 } else {
2009 strcpy(curLocalDir, saved_dir);
2010 }
2011 strcpy(curFileName, saved_file);
2012 strcpy(curSymDir, saved_sym_dir);
2013 curFileDefined = saved_cur_file_defined;
2014
2015 RedrawTitleWindow();
2016 SetCurChoice(curChoiceBeforeMakeQuiescent);
2017 }
2018
SaveFile()2019 void SaveFile()
2020 {
2021 int count=0, short_name, file_type=INVALID, no_name=FALSE;
2022 struct ObjRec *obj_ptr=NULL;
2023 FILE *fp=NULL;
2024 char ext[MAXPATHLENGTH+1], gzipped_fname[MAXPATHLENGTH+1];
2025 char full_name[MAXPATHLENGTH+1], *rest=NULL, *psz=NULL;
2026 struct PageRec *saved_cur_page=NULL;
2027 struct ObjRec *obj_ptr1=NULL, *obj_ptr2=NULL;
2028 struct AttrRec *attr_ptr=NULL;
2029 int watch_cursor=FALSE, gzipped=FALSE;
2030
2031 *gzipped_fname = '\0';
2032 if (!curFileDefined || !curDirIsLocal) {
2033 SaveNewFile(FALSE, NULL);
2034 return;
2035 }
2036 if (unsavableFile) {
2037 if (MsgBox(TgLoadString(STID_Q_FILE_UNSAVABLE_SAVE_NEW_YNC), TOOL_NAME,
2038 YNC_MB) == MB_ID_YES) {
2039 SaveNewFile(FALSE, NULL);
2040 }
2041 return;
2042 }
2043 if ((psz=UtilStrRChr(curFileName, '.')) == NULL) {
2044 sprintf(gszMsgBox, TgLoadString(STID_CANT_FIND_DOT_IN_SAVEFILE),
2045 "SaveFile()");
2046 TgAssert(FALSE, gszMsgBox, NULL);
2047 return;
2048 }
2049 if (strcmp(psz, ".gz") == 0) {
2050 char *dot_ptr=psz;
2051
2052 gzipped = TRUE;
2053 *dot_ptr = '\0';
2054 if ((psz=UtilStrRChr(curFileName, '.')) == NULL) {
2055 sprintf(gszMsgBox, TgLoadString(STID_CANT_FIND_DOT_IN_SAVEFILE),
2056 "SaveFile()");
2057 TgAssert(FALSE, gszMsgBox, NULL);
2058 *dot_ptr = '.';
2059 return;
2060 }
2061 UtilStrCpyN(ext, sizeof(ext), psz);
2062 *dot_ptr = '.';
2063 } else {
2064 UtilStrCpyN(ext, sizeof(ext), psz);
2065 }
2066 saved_cur_page = curPage;
2067 for (curPage=firstPage; curPage != NULL; curPage=curPage->next) {
2068 for (obj_ptr=curPage->top; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
2069 if (obj_ptr->type == OBJ_SYM) {
2070 if (obj_ptr1 == NULL) {
2071 obj_ptr1 = obj_ptr;
2072 } else if (obj_ptr2 == NULL) {
2073 obj_ptr2 = obj_ptr;
2074 }
2075 count++;
2076 }
2077 }
2078 }
2079 curPage = saved_cur_page;
2080
2081 switch (count) {
2082 case 0:
2083 if (FileNameHasExtension(ext, SYM_FILE_TYPE, NULL, &no_name)) {
2084 MsgBox(TgLoadString(STID_NO_SYM_FOUND_SYM_NOT_SAVED), TOOL_NAME,
2085 INFO_MB);
2086 return;
2087 } else if (FileNameHasExtension(ext, PIN_FILE_TYPE, NULL, &no_name)) {
2088 MsgBox(TgLoadString(STID_NO_SYM_FOUND_PIN_NOT_SAVED), TOOL_NAME,
2089 INFO_MB);
2090 return;
2091 }
2092 file_type = OBJ_FILE_TYPE;
2093 break;
2094 case 1:
2095 if (FileNameHasExtension(ext, OBJ_FILE_TYPE, NULL, &no_name)) {
2096 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
2097 INFO_MB);
2098 return;
2099 }
2100 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) != NULL &&
2101 strcmp(attr_ptr->attr_value.s, "tgif_pin") == 0) {
2102 if (FileNameHasExtension(ext, SYM_FILE_TYPE, NULL, &no_name)) {
2103 sprintf(gszMsgBox, TgLoadString(STID_SYM_TYPE_IS_SHOULD_SAVE_PIN),
2104 "tgif_pin");
2105 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2106 return;
2107 }
2108 file_type = PIN_FILE_TYPE;
2109 } else {
2110 if (FileNameHasExtension(ext, PIN_FILE_TYPE, NULL, &no_name)) {
2111 MsgBox(TgLoadString(STID_CANT_SAVE_PIN_ONE_SYM_FOUND), TOOL_NAME,
2112 INFO_MB);
2113 return;
2114 }
2115 file_type = SYM_FILE_TYPE;
2116 }
2117 break;
2118 case 2:
2119 if (FileNameHasExtension(ext, OBJ_FILE_TYPE, NULL, &no_name)) {
2120 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
2121 INFO_MB);
2122 return;
2123 } else if (FileNameHasExtension(ext, SYM_FILE_TYPE, NULL, &no_name)) {
2124 MsgBox(TgLoadString(STID_TOO_MANY_SYM_ABORT_SAVE), TOOL_NAME,
2125 INFO_MB);
2126 return;
2127 }
2128 file_type = PIN_FILE_TYPE;
2129 break;
2130 default:
2131 MsgBox(TgLoadString(STID_TOO_MANY_SYM_FILE_NOT_SAVED), TOOL_NAME,
2132 INFO_MB);
2133 return;
2134 }
2135 if (file_type == SYM_FILE_TYPE || file_type == PIN_FILE_TYPE) {
2136 sprintf(full_name, "%s%c%s", curSymDir, DIR_SEP, curFileName);
2137 } else {
2138 sprintf(full_name, "%s%c%s", curDir, DIR_SEP, curFileName);
2139 }
2140 if (file_type == OBJ_FILE_TYPE && gzipped) {
2141 char tmp_fname[MAXPATHLENGTH];
2142
2143 if (MkTempFile(tmp_fname, sizeof(tmp_fname), tmpDir, TOOL_NAME) == NULL) {
2144 return;
2145 }
2146 strcpy(gzipped_fname, full_name);
2147 strcpy(full_name, tmp_fname);
2148 }
2149 if (*gzipped_fname == '\0') {
2150 if ((short_name=IsPrefix(bootDir, full_name, &rest))) ++rest;
2151 } else {
2152 if ((short_name=IsPrefix(bootDir, gzipped_fname, &rest))) ++rest;
2153 }
2154 if ((fp=fopen(full_name, "w")) == NULL) {
2155 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
2156 (short_name ? rest : full_name));
2157 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2158 if (*gzipped_fname != '\0') unlink(full_name);
2159 return;
2160 }
2161 if (short_name) {
2162 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), rest);
2163 } else {
2164 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS),
2165 (*gzipped_fname == '\0' ? full_name : gzipped_fname));
2166 }
2167 Msg(gszMsgBox);
2168
2169 watch_cursor = watchCursorOnMainWindow;
2170 if (!watch_cursor) {
2171 SetWatchCursor(drawWindow);
2172 SetWatchCursor(mainWindow);
2173 }
2174 writeFileFailed = FALSE;
2175 MakeQuiescent();
2176 saved_cur_page = curPage;
2177 for (curPage=firstPage, count=1; curPage != NULL;
2178 curPage=curPage->next, count++) {
2179 topObj = curPage->top;
2180 botObj = curPage->bot;
2181 Save(fp, botObj, 0, count);
2182 }
2183 curPage = saved_cur_page;
2184 topObj = curPage->top;
2185 botObj = curPage->bot;
2186
2187 fclose(fp);
2188
2189 if (!watch_cursor) {
2190 SetDefaultCursor(mainWindow);
2191 ShowCursor();
2192 }
2193 if (writeFileFailed) {
2194 writeFileFailed = FALSE;
2195 FailToWriteFileMessage(full_name);
2196 } else {
2197 if (*gzipped_fname != '\0') {
2198 if (!GzipFile(full_name, gzipped_fname)) {
2199 sprintf(gszMsgBox, TgLoadString(STID_PROBLEM_ZIPPING_PLEASE_SAVE),
2200 full_name, gzipped_fname, full_name);
2201 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2202 unlink(full_name);
2203 return;
2204 }
2205 unlink(full_name);
2206 strcpy(full_name, gzipped_fname);
2207 }
2208 sprintf(gszMsgBox, TgLoadString(STID_FILE_SAVED),
2209 (short_name ? rest : full_name));
2210 Msg(gszMsgBox);
2211 SetFileModified(FALSE);
2212 if (!NameInCurDir(curFileName)) UpdateDirInfo();
2213 }
2214 SetCurChoice(curChoiceBeforeMakeQuiescent);
2215 }
2216
SavePages(pSpecifyPagesInfo)2217 void SavePages(pSpecifyPagesInfo)
2218 SpecifyPagesInfo *pSpecifyPagesInfo;
2219 {
2220 char new_file_name[MAXPATHLENGTH+1], gzipped_fname[MAXPATHLENGTH+1];
2221 char new_full_name[MAXPATHLENGTH+1], *rest=NULL;
2222 char obj_ext_str[MAXSTRING+1], gz_obj_ext_str[MAXSTRING+1];
2223 char sym_ext_str[MAXSTRING+1], pin_ext_str[MAXSTRING+1];
2224 int no_name=FALSE, gzipped=FALSE, file_type=0, page_num=0;
2225 int count=0, len, short_name=FALSE, ok=TRUE, watch_cursor=FALSE;
2226 struct ObjRec *obj_ptr=NULL;
2227 struct ObjRec *obj_ptr1=NULL, *obj_ptr2=NULL;
2228 struct PageRec *saved_cur_page=NULL;
2229 struct AttrRec *attr_ptr=NULL;
2230 FILE *fp=NULL;
2231
2232 file_type = OBJ_FILE_TYPE;
2233 *gzipped_fname = '\0';
2234
2235 sprintf(gszMsgBox, TgLoadString(STID_WORKING_DIRECTORY_IS),
2236 (curDirIsLocal ? curDir : curLocalDir));
2237 *new_file_name = '\0';
2238 Dialog(TgLoadString(STID_ENTER_NEW_FNAME_ACCEPT_CANCEL), gszMsgBox,
2239 new_file_name);
2240
2241 UtilTrimBlanks(new_file_name);
2242 if (*new_file_name == '\0') return;
2243 len = strlen(new_file_name);
2244
2245 saved_cur_page = curPage;
2246 for (page_num=0, curPage=firstPage; curPage != NULL;
2247 curPage=curPage->next, page_num++) {
2248 if (pSpecifyPagesInfo->page_specified[page_num]) {
2249 for (obj_ptr=curPage->top; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
2250 if (obj_ptr->type == OBJ_SYM) {
2251 if (obj_ptr1 == NULL) {
2252 obj_ptr1 = obj_ptr;
2253 } else if (obj_ptr2 == NULL) {
2254 obj_ptr2 = obj_ptr;
2255 }
2256 count++;
2257 }
2258 }
2259 }
2260 }
2261 curPage = saved_cur_page;
2262
2263 sprintf(obj_ext_str, ".%s", OBJ_FILE_EXT);
2264 sprintf(gz_obj_ext_str, ".%s.gz", OBJ_FILE_EXT);
2265 sprintf(sym_ext_str, ".%s", SYM_FILE_EXT);
2266 sprintf(pin_ext_str, ".%s", PIN_FILE_EXT);
2267
2268 if (count > 2) {
2269 MsgBox(TgLoadString(STID_TOO_MANY_SYM_ABORT_SAVE), TOOL_NAME, INFO_MB);
2270 return;
2271 }
2272 if (count >= 1 && pSpecifyPagesInfo->num_pages_specified != 1) {
2273 MsgBox(TgLoadString(count==1 ? STID_ONE_PAGE_SYM_ABORT_SAVE :
2274 STID_ONE_PAGE_PIN_ABORT_SAVE), TOOL_NAME, INFO_MB);
2275 return;
2276 }
2277 switch (count) {
2278 case 0:
2279 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, &gzipped,
2280 &no_name)) {
2281 /* don't modify */
2282 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
2283 &no_name)) {
2284 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_NO_SYM_FOUND), TOOL_NAME,
2285 INFO_MB);
2286 return;
2287 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
2288 &no_name)) {
2289 MsgBox(TgLoadString(STID_CANT_SAVE_PIN_NO_SYM_FOUND), TOOL_NAME,
2290 INFO_MB);
2291 return;
2292 } else {
2293 strcat(new_file_name, obj_ext_str);
2294 }
2295 file_type = OBJ_FILE_TYPE;
2296 break;
2297 case 1:
2298 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) != NULL &&
2299 strcmp(attr_ptr->attr_value.s, "tgif_pin") == 0) {
2300 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL,
2301 &no_name)) {
2302 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
2303 INFO_MB);
2304 return;
2305 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
2306 &no_name)) {
2307 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_SAVE_AS_PIN), TOOL_NAME,
2308 INFO_MB);
2309 return;
2310 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
2311 &no_name)) {
2312 /* don't modify */
2313 } else {
2314 strcat(new_file_name, pin_ext_str);
2315 }
2316 file_type = PIN_FILE_TYPE;
2317 } else {
2318 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL,
2319 &no_name)) {
2320 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_ONE_SYM_FOUND), TOOL_NAME,
2321 INFO_MB);
2322 return;
2323 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
2324 &no_name)) {
2325 /* don't modify */
2326 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
2327 &no_name)) {
2328 MsgBox(TgLoadString(STID_CANT_SAVE_PIN_ONE_SYM_FOUND), TOOL_NAME,
2329 INFO_MB);
2330 return;
2331 } else {
2332 strcat(new_file_name, sym_ext_str);
2333 }
2334 file_type = SYM_FILE_TYPE;
2335 }
2336 break;
2337 case 2:
2338 if (FileNameHasExtension(new_file_name, OBJ_FILE_TYPE, NULL, &no_name)) {
2339 MsgBox(TgLoadString(STID_CANT_SAVE_OJB_TWO_SYM_FOUND), TOOL_NAME,
2340 INFO_MB);
2341 return;
2342 } else if (FileNameHasExtension(new_file_name, SYM_FILE_TYPE, NULL,
2343 &no_name)) {
2344 MsgBox(TgLoadString(STID_CANT_SAVE_SYM_TWO_SYM_FOUND), TOOL_NAME,
2345 INFO_MB);
2346 return;
2347 } else if (FileNameHasExtension(new_file_name, PIN_FILE_TYPE, NULL,
2348 &no_name)) {
2349 /* don't modify */
2350 } else {
2351 strcat(new_file_name, pin_ext_str);
2352 }
2353 if (obj_ptr2->fattr != NULL) {
2354 obj_ptr = obj_ptr2;
2355 obj_ptr2 = obj_ptr1;
2356 obj_ptr1 = obj_ptr;
2357 }
2358 if ((attr_ptr=FindAttrWithName(obj_ptr1, "type=", NULL)) == NULL) {
2359 MsgBox(TgLoadString(STID_CANT_FIND_TYPE_ATTR_NOT_SAVED), TOOL_NAME,
2360 INFO_MB);
2361 return;
2362 }
2363 if (strcmp(attr_ptr->attr_value.s, "tgif_pin") != 0) {
2364 sprintf(gszMsgBox, TgLoadString(STID_SYM_TYPE_WRONG_PIN_NOT_SAVED),
2365 "tgif_pin");
2366 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2367 return;
2368 }
2369 file_type = PIN_FILE_TYPE;
2370 break;
2371 default: return;
2372 }
2373 if (no_name) {
2374 MsgBox(TgLoadString(STID_NO_FILE_NAME_FILE_NOT_SAVED), TOOL_NAME,
2375 INFO_MB);
2376 return;
2377 }
2378 if (*new_file_name == DIR_SEP) {
2379 strcpy(new_full_name, new_file_name);
2380 } else if (curDirIsLocal) {
2381 sprintf(new_full_name, "%s%c%s", curDir, DIR_SEP, new_file_name);
2382 } else {
2383 sprintf(new_full_name, "%s%c%s", curLocalDir, DIR_SEP, new_file_name);
2384 }
2385 if (file_type == OBJ_FILE_TYPE && gzipped) {
2386 char tmp_fname[MAXPATHLENGTH];
2387
2388 if (MkTempFile(tmp_fname, sizeof(tmp_fname), tmpDir, TOOL_NAME) == NULL) {
2389 return;
2390 }
2391 strcpy(gzipped_fname, new_full_name);
2392 strcpy(new_full_name, tmp_fname);
2393 }
2394 if (!OkayToCreateFile((*gzipped_fname=='\0') ? new_full_name :
2395 gzipped_fname)) {
2396 if (*gzipped_fname != '\0') unlink(new_full_name);
2397 return;
2398 }
2399 if (*gzipped_fname == '\0') {
2400 if ((short_name=IsPrefix(bootDir, new_full_name, &rest))) ++rest;
2401 } else {
2402 if ((short_name=IsPrefix(bootDir, gzipped_fname, &rest))) ++rest;
2403 }
2404 if ((fp=fopen(new_full_name, "w")) == NULL) {
2405 if (short_name) {
2406 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
2407 rest);
2408 } else {
2409 if (*gzipped_fname == '\0') {
2410 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
2411 new_full_name);
2412 } else {
2413 sprintf(gszMsgBox, TgLoadString(STID_CANT_OPEN_WRITE_FILE_NOT_SAVE),
2414 gzipped_fname);
2415 }
2416 }
2417 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2418 if (*gzipped_fname != '\0') unlink(new_full_name);
2419 return;
2420 }
2421 if (short_name) {
2422 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), rest);
2423 } else {
2424 if (*gzipped_fname == '\0') {
2425 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), new_full_name);
2426 } else {
2427 sprintf(gszMsgBox, TgLoadString(STID_SAVING_DOTS), gzipped_fname);
2428 }
2429 }
2430 Msg(gszMsgBox);
2431
2432 if (!saveCommentsInSaveNew) CleanUpComments();
2433 watch_cursor = watchCursorOnMainWindow;
2434 if (!watch_cursor) {
2435 SetWatchCursor(drawWindow);
2436 SetWatchCursor(mainWindow);
2437 }
2438 writeFileFailed = FALSE;
2439 saved_cur_page = curPage;
2440 for (page_num=0, curPage=firstPage, count=1; curPage != NULL;
2441 curPage=curPage->next, page_num++) {
2442 if (pSpecifyPagesInfo->page_specified[page_num]) {
2443 int saved_cur_page_num=curPageNum, saved_last_page_num=lastPageNum;
2444 int need_to_restore_page_nums=FALSE;
2445
2446 topObj = curPage->top;
2447 botObj = curPage->bot;
2448 if (count == 1) {
2449 curPageNum = 1;
2450 lastPageNum = pSpecifyPagesInfo->num_pages_specified;
2451 need_to_restore_page_nums = TRUE;
2452 }
2453 Save(fp, botObj, 0, count++);
2454 if (need_to_restore_page_nums) {
2455 curPageNum = saved_cur_page_num;
2456 lastPageNum = saved_last_page_num;
2457 }
2458 }
2459 }
2460 curPage = saved_cur_page;
2461 topObj = curPage->top;
2462 botObj = curPage->bot;
2463 fclose(fp);
2464 if (!watch_cursor) {
2465 SetDefaultCursor(mainWindow);
2466 ShowCursor();
2467 }
2468 if (writeFileFailed) {
2469 writeFileFailed = FALSE;
2470 FailToWriteFileMessage(new_full_name);
2471 ok = FALSE;
2472 } else {
2473 if (*gzipped_fname != '\0') {
2474 if (!GzipFile(new_full_name, gzipped_fname)) {
2475 sprintf(gszMsgBox, TgLoadString(STID_PROBLEM_ZIPPING_PLEASE_SAVE),
2476 new_full_name, gzipped_fname, new_full_name);
2477 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2478 ok = FALSE;
2479 }
2480 unlink(new_full_name);
2481 strcpy(new_full_name, gzipped_fname);
2482 }
2483 if (ok) {
2484 if (pSpecifyPagesInfo->num_pages_specified > 1) {
2485 sprintf(gszMsgBox, TgLoadString(STID_MANY_PAGES_SAVED_INTO_GIVEN),
2486 pSpecifyPagesInfo->num_pages_specified,
2487 (short_name ? rest : new_full_name));
2488 } else {
2489 sprintf(gszMsgBox, TgLoadString(STID_ONE_PAGE_SAVED_INTO_GIVEN),
2490 (short_name ? rest : new_full_name));
2491 }
2492 Msg(gszMsgBox);
2493 } else {
2494 sprintf(gszMsgBox, TgLoadString(STID_FILE_NOT_SAVED),
2495 (short_name ? rest : new_full_name));
2496 Msg(gszMsgBox);
2497 }
2498 }
2499 }
2500
ParseStr(Str,C,Left,LeftSz)2501 char *ParseStr(Str, C, Left, LeftSz)
2502 char *Str, *Left;
2503 int C, LeftSz;
2504 {
2505 register char *s=Str, *l=Left;
2506 register int len=0;
2507 int max_len=LeftSz-1;
2508 char the_char=(char)C;
2509
2510 while (*s != '\0' && *s != the_char) {
2511 if (len < max_len) {
2512 *l++ = *s++;
2513 len++;
2514 } else {
2515 break;
2516 }
2517 }
2518
2519 if (*s == the_char) s++;
2520 *l = '\0';
2521
2522 while (len >= 2 && *Left == '\'' && *(--l) == '\'') {
2523 char *c_ptr, *c_ptr1;
2524
2525 *l-- = '\0';
2526 len -= 2;
2527 c_ptr = &Left[1];
2528 c_ptr1 = Left;
2529 while (*c_ptr != '\0') *c_ptr1++ = *c_ptr++;
2530 *c_ptr1 = '\0';
2531 }
2532 return s;
2533 }
2534
FindChar(C,Str)2535 char *FindChar(C, Str)
2536 int C;
2537 char *Str;
2538 /* returns the address of the character right after C of the string Str */
2539 {
2540 register char *s=Str, the_char=(char)C;
2541
2542 while (*s != '\0' && *s != the_char) s++;
2543
2544 if (*s == the_char) s++;
2545 return s;
2546 }
2547
SaveCreatorID(FP,obj_ptr,psz_prefix)2548 void SaveCreatorID(FP, obj_ptr, psz_prefix)
2549 FILE *FP;
2550 struct ObjRec *obj_ptr;
2551 char *psz_prefix;
2552 {
2553 char buf[MAXSTRING];
2554
2555 if (obj_ptr->creator_full_id == NULL) {
2556 sprintf(buf, "%1d/%s", obj_ptr->id, gszLocalPID);
2557 } else {
2558 strcpy(buf, obj_ptr->creator_full_id);
2559 }
2560 if (fprintf(FP, "\n%s\"", psz_prefix) == EOF) writeFileFailed = TRUE;
2561 SaveString(FP, buf);
2562 if (fprintf(FP, "\",") == EOF) writeFileFailed = TRUE;
2563 }
2564
ReadCreatorID(FP,ObjPtr)2565 int ReadCreatorID(FP, ObjPtr)
2566 FILE *FP;
2567 struct ObjRec **ObjPtr;
2568 {
2569 int ok=TRUE;
2570 char *c_ptr=NULL, *line=NULL, full_id[MAXSTRING];
2571
2572 if ((line=UtilGetALine(FP)) == NULL) {
2573 sprintf(gszMsgBox, TgLoadString(STID_UNEXPECTED_EOF_IN_ABORT_READ),
2574 scanFileName, scanLineNum, "ReadCreatorID()");
2575 if (PRTGIF) {
2576 fprintf(stderr, "%s\n", gszMsgBox);
2577 } else {
2578 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2579 }
2580 return FALSE;
2581 }
2582 scanLineNum++;
2583 c_ptr = FindChar((int)'"', line);
2584 c_ptr = ParseStr(c_ptr, (int)'"', full_id, sizeof(full_id));
2585 if (c_ptr == NULL) {
2586 sprintf(gszMsgBox, TgLoadString(STID_BAD_FIELD_IN_FUNC_ABORT_READ),
2587 scanFileName, scanLineNum, "creator_full_id", "ReadCreatorID()");
2588 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
2589 ok = FALSE;
2590 }
2591 (*ObjPtr)->creator_full_id = UtilStrDup(full_id);
2592 if ((*ObjPtr)->creator_full_id == NULL) FailAllocMessage();
2593 free(line);
2594 return ok;
2595 }
2596
2597 static
NumFieldsToFontStr(buf)2598 int NumFieldsToFontStr(buf)
2599 char *buf;
2600 /* 300.000,0,0,0,16,1,0,1,1,0,0,1,0,1,0,'...' */
2601 {
2602 char *psz=NULL, *psz_single_quote=strchr(buf, '\'');
2603 int count=0;
2604
2605 if (psz_single_quote == NULL) {
2606 return (-1);
2607 }
2608 *psz_single_quote = '\0';
2609 for (psz=strchr(buf, ','); psz != NULL; psz=strchr(&psz[1], ',')) {
2610 count++;
2611 }
2612 *psz_single_quote = '\'';
2613
2614 return count;
2615 }
2616
2617 static int gnCannotFindColorMsg=FALSE;
2618
2619 static
ReadState(Inbuf)2620 int ReadState(Inbuf)
2621 char *Inbuf;
2622 {
2623 char *s, font_str[MAXSTRING], sb_font_str[MAXSTRING];
2624 int page_style, forced_use_gray=FALSE, compat_dpi, font_sz=0, sz_unit=0;
2625 int page_arg1=0, page_arg2=0, rotate=ROTATE0;
2626 int one_page_width=0, one_page_height=0;
2627
2628 *font_str = *sb_font_str = '\0';
2629 s = FindChar((int)'(', Inbuf);
2630 if (sscanf(s, "%d", &page_style) != 1) return FALSE;
2631 s = FindChar((int)',', s);
2632 if (*s == '\0') {
2633 fileVersion = INVALID;
2634 } else if (sscanf(s, "%d", &fileVersion) != 1) {
2635 return FALSE;
2636 }
2637
2638 if (fileVersion > CUR_VERSION) return FALSE;
2639
2640 gnCannotFindColorMsg = FALSE;
2641
2642 if (!importingFile && !mergingFile) {
2643 if (fileVersion <= 13) {
2644 switch (page_style) {
2645 case PORTRAIT: printMag = (float)100.0; break;
2646 case LANDSCAPE: printMag = (float)100.0; break;
2647 case HIGHPORT: printMag = (float)50.0; page_style = PORTRAIT; break;
2648 case HIGHLAND: printMag = (float)50.0; page_style = LANDSCAPE; break;
2649 case SLIDEPORT: printMag = (float)200.0; page_style = PORTRAIT; break;
2650 case SLIDELAND: printMag = (float)200.0; page_style = LANDSCAPE; break;
2651 default:
2652 sprintf(gszMsgBox, TgLoadString(STID_UNRECOG_PAGE_STYLE),
2653 page_style);
2654 TwoLineMsg(gszMsgBox, TgLoadString(STID_PORTRAIT_STYLE_ASSUMED));
2655 page_style = PORTRAIT;
2656 printMag = (float)100.0;
2657 break;
2658 }
2659 } else {
2660 int num_fields_to_font_str=0;
2661
2662 if (page_style != PORTRAIT && page_style != LANDSCAPE) {
2663 sprintf(gszMsgBox, TgLoadString(STID_UNRECOG_PAGE_STYLE),
2664 page_style);
2665 TwoLineMsg(gszMsgBox, TgLoadString(STID_PORTRAIT_STYLE_ASSUMED));
2666 page_style = PORTRAIT;
2667 }
2668 s = FindChar((int)',', s);
2669 /* begin locale bug fix kluge */
2670 num_fields_to_font_str = NumFieldsToFontStr(s);
2671 if (num_fields_to_font_str == (-1)) {
2672 /* cannot find single quote */
2673 } else if (num_fields_to_font_str == 15) {
2674 /* normal case */
2675 } else if (num_fields_to_font_str == 16) {
2676 /* extra one, must be the locale bug, fix it! */
2677 char *psz_comma=strchr(s, ',');
2678
2679 *psz_comma = '.';
2680 } else {
2681 /* don't know what happened */
2682 }
2683 /* end locale bug fix kluge */
2684 sscanf(s, "%f", &printMag);
2685 }
2686 pageStyle = page_style;
2687 }
2688
2689 if (PRTGIF && useGray) forced_use_gray = TRUE;
2690 if (importingFile || mergingFile) return TRUE;
2691
2692 page_arg1 = page_arg2 = 1;
2693 one_page_width = onePageWidth;
2694 one_page_height = onePageHeight;
2695
2696 if (fileVersion >= 2) {
2697 compat_dpi = FONT_DPI_75;
2698 curDash = 0;
2699 gridSystem = ENGLISH_GRID;
2700 xyMetricGrid = DEFAULT_METRIC_GRID;
2701 textVSpace = 0;
2702 zoomedIn = FALSE;
2703 rcbRadius = DEF_RCB_RADIUS;
2704 pageLayoutMode = PAGE_STACK;
2705 paperCol = paperRow = 1;
2706 curPageNum = lastPageNum = 1;
2707 pageLineShownInTileMode = TRUE;
2708
2709 if (usePaperSizeStoredInFile) ResetOnePageSize();
2710
2711 s = FindChar((int)',', s);
2712
2713 InitScan(s, "\t\n, ");
2714
2715 if (fileVersion <= 3) {
2716 GETINT("state", drawOrigX, "X Draw Origin");
2717 GETINT("state", drawOrigY, "Y Draw Origin");
2718 GETINT("state", zoomScale, "Zoom scale");
2719 GETINT("state", xyEnglishGrid, "English Grid");
2720 GETINT("state", snapOn, "Grid");
2721 GETINT("state", colorIndex, "Color");
2722 GETINT("state", horiAlign, "Horizontal Align");
2723 GETINT("state", vertAlign, "Vertical Align");
2724 GETINT("state", lineWidth, "Line Width");
2725 GETINT("state", lineStyle, "Line Style");
2726 GETINT("state", objFill, "Fill Pattern");
2727 GETINT("state", penPat, "Pen Pattern");
2728 GETINT("state", textJust, "Text Justify");
2729 GETINT("state", curFont, "Font Name");
2730 GETINT("state", curStyle, "Font Style");
2731 GETINT("state", font_sz, "Font Size");
2732
2733 if (lineWidth == LINE_CURVED) {
2734 lineWidth = 0;
2735 curSpline = LT_SPLINE;
2736 } else {
2737 curSpline = LT_STRAIGHT;
2738 }
2739 } else if (fileVersion <= 7) {
2740 GETINT("state", drawOrigX, "X Draw Origin");
2741 GETINT("state", drawOrigY, "Y Draw Origin");
2742 GETINT("state", zoomScale, "Zoom scale");
2743 GETINT("state", xyEnglishGrid, "English Grid");
2744 GETINT("state", snapOn, "Grid");
2745 GETINT("state", colorIndex, "Color");
2746 GETINT("state", horiAlign, "Horizontal Align");
2747 GETINT("state", vertAlign, "Vertical Align");
2748 GETINT("state", lineWidth, "Line Width");
2749 GETINT("state", curSpline, "Spline");
2750 GETINT("state", lineStyle, "Line Style");
2751 GETINT("state", objFill, "Fill Pattern");
2752 GETINT("state", penPat, "Pen Pattern");
2753 GETINT("state", textJust, "Text Justify");
2754 GETINT("state", curFont, "Font Name");
2755 GETINT("state", curStyle, "Font Style");
2756 GETINT("state", font_sz, "Font Size");
2757 } else if (fileVersion <= 8) {
2758 GETINT("state", drawOrigX, "X Draw Origin");
2759 GETINT("state", drawOrigY, "Y Draw Origin");
2760 GETINT("state", zoomScale, "Zoom scale");
2761 GETINT("state", xyEnglishGrid, "English Grid");
2762 GETINT("state", snapOn, "Grid");
2763 GETINT("state", colorIndex, "Color");
2764 GETINT("state", horiAlign, "Horizontal Align");
2765 GETINT("state", vertAlign, "Vertical Align");
2766 GETINT("state", lineWidth, "Line Width");
2767 GETINT("state", curSpline, "Spline");
2768 GETINT("state", lineStyle, "Line Style");
2769 GETINT("state", objFill, "Fill Pattern");
2770 GETINT("state", penPat, "Pen Pattern");
2771 GETINT("state", textJust, "Text Justify");
2772 GETINT("state", curFont, "Font Name");
2773 GETINT("state", curStyle, "Font Style");
2774 GETINT("state", font_sz, "Font Size");
2775 GETINT("state", compat_dpi, "Font DPI");
2776 } else if (fileVersion <= 11) {
2777 GETINT("state", drawOrigX, "X Draw Origin");
2778 GETINT("state", drawOrigY, "Y Draw Origin");
2779 GETINT("state", zoomScale, "Zoom scale");
2780 GETINT("state", xyEnglishGrid, "English Grid");
2781 GETINT("state", snapOn, "Grid");
2782 GETINT("state", colorIndex, "Color");
2783 GETINT("state", horiAlign, "Horizontal Align");
2784 GETINT("state", vertAlign, "Vertical Align");
2785 GETINT("state", lineWidth, "Line Width");
2786 GETINT("state", curSpline, "Spline");
2787 GETINT("state", lineStyle, "Line Style");
2788 GETINT("state", objFill, "Fill Pattern");
2789 GETINT("state", penPat, "Pen Pattern");
2790 GETINT("state", textJust, "Text Justify");
2791 GETINT("state", curFont, "Font Name");
2792 GETINT("state", curStyle, "Font Style");
2793 GETINT("state", font_sz, "Font Size");
2794 GETINT("state", compat_dpi, "Font DPI");
2795 GETINT("state", curDash, "Dash Style");
2796 } else if (fileVersion <= 12) {
2797 GETINT("state", drawOrigX, "X Draw Origin");
2798 GETINT("state", drawOrigY, "Y Draw Origin");
2799 GETINT("state", zoomScale, "Zoom scale");
2800 GETINT("state", xyEnglishGrid, "English Grid");
2801 GETINT("state", snapOn, "Grid");
2802 GETINT("state", colorIndex, "Color");
2803 GETINT("state", horiAlign, "Horizontal Align");
2804 GETINT("state", vertAlign, "Vertical Align");
2805 GETINT("state", lineWidth, "Line Width");
2806 GETINT("state", curSpline, "Spline");
2807 GETINT("state", lineStyle, "Line Style");
2808 GETINT("state", objFill, "Fill Pattern");
2809 GETINT("state", penPat, "Pen Pattern");
2810 GETINT("state", textJust, "Text Justify");
2811 GETINT("state", curFont, "Font Name");
2812 GETINT("state", curStyle, "Font Style");
2813 GETINT("state", font_sz, "Font Size");
2814 GETINT("state", compat_dpi, "Font DPI");
2815 GETINT("state", curDash, "Dash Style");
2816 GETINT("state", gridSystem, "Grid System");
2817 GETINT("state", xyMetricGrid, "Metric Grid");
2818 } else if (fileVersion <= 18) {
2819 GETINT("state", drawOrigX, "X Draw Origin");
2820 GETINT("state", drawOrigY, "Y Draw Origin");
2821 GETINT("state", zoomScale, "Zoom scale");
2822 GETINT("state", xyEnglishGrid, "English Grid");
2823 GETINT("state", snapOn, "Grid");
2824 GETINT("state", colorIndex, "Color");
2825 GETINT("state", horiAlign, "Horizontal Align");
2826 GETINT("state", vertAlign, "Vertical Align");
2827 GETINT("state", lineWidth, "Line Width");
2828 GETINT("state", curSpline, "Spline");
2829 GETINT("state", lineStyle, "Line Style");
2830 GETINT("state", objFill, "Fill Pattern");
2831 GETINT("state", penPat, "Pen Pattern");
2832 GETINT("state", textJust, "Text Justify");
2833 GETINT("state", curFont, "Font Name");
2834 GETINT("state", curStyle, "Font Style");
2835 GETINT("state", font_sz, "Font Size");
2836 GETINT("state", compat_dpi, "Font DPI");
2837 GETINT("state", curDash, "Dash Style");
2838 GETINT("state", gridSystem, "Grid System");
2839 GETINT("state", xyMetricGrid, "Metric Grid");
2840 GETINT("state", textVSpace, "Text Vertical Spacing");
2841 } else if (fileVersion <= 19) {
2842 GETINT("state", drawOrigX, "X Draw Origin");
2843 GETINT("state", drawOrigY, "Y Draw Origin");
2844 GETINT("state", zoomScale, "Zoom scale");
2845 GETINT("state", xyEnglishGrid, "English Grid");
2846 GETINT("state", snapOn, "Grid");
2847 GETINT("state", colorIndex, "Color");
2848 GETINT("state", horiAlign, "Horizontal Align");
2849 GETINT("state", vertAlign, "Vertical Align");
2850 GETINT("state", lineWidth, "Line Width");
2851 GETINT("state", curSpline, "Spline");
2852 GETINT("state", lineStyle, "Line Style");
2853 GETINT("state", objFill, "Fill Pattern");
2854 GETINT("state", penPat, "Pen Pattern");
2855 GETINT("state", textJust, "Text Justify");
2856 GETINT("state", curFont, "Font Name");
2857 GETINT("state", curStyle, "Font Style");
2858 GETINT("state", font_sz, "Font Size");
2859 GETINT("state", compat_dpi, "Font DPI");
2860 GETINT("state", curDash, "Dash Style");
2861 GETINT("state", gridSystem, "Grid System");
2862 GETINT("state", xyMetricGrid, "Metric Grid");
2863 GETINT("state", textVSpace, "Text Vertical Spacing");
2864 GETINT("state", zoomedIn, "Zoomed In");
2865 } else if (fileVersion <= 21) {
2866 GETINT("state", drawOrigX, "X Draw Origin");
2867 GETINT("state", drawOrigY, "Y Draw Origin");
2868 GETINT("state", zoomScale, "Zoom scale");
2869 GETINT("state", xyEnglishGrid, "English Grid");
2870 GETINT("state", snapOn, "Grid");
2871 GETINT("state", colorIndex, "Color");
2872 GETINT("state", horiAlign, "Horizontal Align");
2873 GETINT("state", vertAlign, "Vertical Align");
2874 GETINT("state", lineWidth, "Line Width");
2875 GETINT("state", curSpline, "Spline");
2876 GETINT("state", lineStyle, "Line Style");
2877 GETINT("state", objFill, "Fill Pattern");
2878 GETINT("state", penPat, "Pen Pattern");
2879 GETINT("state", textJust, "Text Justify");
2880 GETINT("state", curFont, "Font Name");
2881 GETINT("state", curStyle, "Font Style");
2882 GETINT("state", font_sz, "Font Size");
2883 GETINT("state", compat_dpi, "Font DPI");
2884 GETINT("state", curDash, "Dash Style");
2885 GETINT("state", gridSystem, "Grid System");
2886 GETINT("state", xyMetricGrid, "Metric Grid");
2887 GETINT("state", textVSpace, "Text Vertical Spacing");
2888 GETINT("state", zoomedIn, "Zoomed In");
2889 GETINT("state", gridShown, "Grid Shown");
2890 GETINT("state", moveMode, "Move Mode");
2891 } else if (fileVersion <= 26) {
2892 GETINT("state", drawOrigX, "X Draw Origin");
2893 GETINT("state", drawOrigY, "Y Draw Origin");
2894 GETINT("state", zoomScale, "Zoom scale");
2895 GETINT("state", xyEnglishGrid, "English Grid");
2896 GETINT("state", snapOn, "Grid");
2897 GETINT("state", colorIndex, "Color");
2898 GETINT("state", horiAlign, "Horizontal Align");
2899 GETINT("state", vertAlign, "Vertical Align");
2900 GETINT("state", lineWidth, "Line Width");
2901 GETINT("state", curSpline, "Spline");
2902 GETINT("state", lineStyle, "Line Style");
2903 GETINT("state", objFill, "Fill Pattern");
2904 GETINT("state", penPat, "Pen Pattern");
2905 GETINT("state", textJust, "Text Justify");
2906 GETINT("state", curFont, "Font Name");
2907 GETINT("state", curStyle, "Font Style");
2908 GETINT("state", font_sz, "Font Size");
2909 GETINT("state", compat_dpi, "Font DPI");
2910 GETINT("state", curDash, "Dash Style");
2911 GETINT("state", gridSystem, "Grid System");
2912 GETINT("state", xyMetricGrid, "Metric Grid");
2913 GETINT("state", textVSpace, "Text Vertical Spacing");
2914 GETINT("state", zoomedIn, "Zoomed In");
2915 GETINT("state", gridShown, "Grid Shown");
2916 GETINT("state", moveMode, "Move Mode");
2917 GETINT("state", rotate, "Text Rotation");
2918 GETINT("state", rcbRadius, "RCBox Radius");
2919 } else if (fileVersion <= 27) {
2920 GETINT("state", drawOrigX, "X Draw Origin");
2921 GETINT("state", drawOrigY, "Y Draw Origin");
2922 GETINT("state", zoomScale, "Zoom scale");
2923 GETINT("state", xyEnglishGrid, "English Grid");
2924 GETINT("state", snapOn, "Grid");
2925 GETINT("state", colorIndex, "Color");
2926 GETINT("state", horiAlign, "Horizontal Align");
2927 GETINT("state", vertAlign, "Vertical Align");
2928 GETINT("state", lineWidth, "Line Width");
2929 GETINT("state", curSpline, "Spline");
2930 GETINT("state", lineStyle, "Line Style");
2931 GETINT("state", objFill, "Fill Pattern");
2932 GETINT("state", penPat, "Pen Pattern");
2933 GETINT("state", textJust, "Text Justify");
2934 GETINT("state", curFont, "Font Name");
2935 GETINT("state", curStyle, "Font Style");
2936 GETINT("state", font_sz, "Font Size");
2937 GETINT("state", compat_dpi, "Font DPI");
2938 GETINT("state", curDash, "Dash Style");
2939 GETINT("state", gridSystem, "Grid System");
2940 GETINT("state", xyMetricGrid, "Metric Grid");
2941 GETINT("state", textVSpace, "Text Vertical Spacing");
2942 GETINT("state", zoomedIn, "Zoomed In");
2943 GETINT("state", gridShown, "Grid Shown");
2944 GETINT("state", moveMode, "Move Mode");
2945 GETINT("state", rotate, "Text Rotation");
2946 GETINT("state", rcbRadius, "RCBox Radius");
2947 GETINT("state", useGray, "Use Gray Scale");
2948 } else if (fileVersion <= 28) {
2949 /* Matsuda's Version */
2950 GETINT("state", drawOrigX, "X Draw Origin");
2951 GETINT("state", drawOrigY, "Y Draw Origin");
2952 GETINT("state", zoomScale, "Zoom scale");
2953 GETINT("state", xyEnglishGrid, "English Grid");
2954 GETINT("state", snapOn, "Grid");
2955 GETINT("state", colorIndex, "Color");
2956 GETINT("state", horiAlign, "Horizontal Align");
2957 GETINT("state", vertAlign, "Vertical Align");
2958 GETINT("state", lineWidth, "Line Width");
2959 GETINT("state", curSpline, "Spline");
2960 GETINT("state", lineStyle, "Line Style");
2961 GETINT("state", objFill, "Fill Pattern");
2962 GETINT("state", penPat, "Pen Pattern");
2963 GETINT("state", textJust, "Text Justify");
2964 GETINT("state", curFont, "Font Name");
2965 GETINT("state", curStyle, "Font Style");
2966 GETINT("state", font_sz, "Font Size");
2967 GETINT("state", compat_dpi, "Font DPI");
2968 GETINT("state", curDash, "Dash Style");
2969 GETINT("state", gridSystem, "Grid System");
2970 GETINT("state", xyMetricGrid, "Metric Grid");
2971 GETINT("state", textVSpace, "Text Vertical Spacing");
2972 GETINT("state", zoomedIn, "Zoomed In");
2973 GETINT("state", gridShown, "Grid Shown");
2974 GETINT("state", moveMode, "Move Mode");
2975 GETINT("state", rotate, "Text Rotation");
2976 GETINT("state", rcbRadius, "RCBox Radius");
2977 GETINT("state", useGray, "Use Gray Scale");
2978 GETINT("state", paperCol, "Num Columns");
2979 GETINT("state", paperRow, "Num Rows");
2980 GETINT("state", curPageNum, "Current Page Number");
2981 GETINT("state", lastPageNum, "Last Page Number");
2982 } else if (fileVersion <= 29) {
2983 GETINT("state", drawOrigX, "X Draw Origin");
2984 GETINT("state", drawOrigY, "Y Draw Origin");
2985 GETINT("state", zoomScale, "Zoom scale");
2986 GETINT("state", xyEnglishGrid, "English Grid");
2987 GETINT("state", snapOn, "Grid");
2988 GETINT("state", colorIndex, "Color");
2989 GETINT("state", horiAlign, "Horizontal Align");
2990 GETINT("state", vertAlign, "Vertical Align");
2991 GETINT("state", lineWidth, "Line Width");
2992 GETINT("state", curSpline, "Spline");
2993 GETINT("state", lineStyle, "Line Style");
2994 GETINT("state", objFill, "Fill Pattern");
2995 GETINT("state", penPat, "Pen Pattern");
2996 GETINT("state", textJust, "Text Justify");
2997 GETINT("state", curFont, "Font Name");
2998 GETINT("state", curStyle, "Font Style");
2999 GETINT("state", font_sz, "Font Size");
3000 GETINT("state", compat_dpi, "Font DPI");
3001 GETINT("state", curDash, "Dash Style");
3002 GETINT("state", gridSystem, "Grid System");
3003 GETINT("state", xyMetricGrid, "Metric Grid");
3004 GETINT("state", textVSpace, "Text Vertical Spacing");
3005 GETINT("state", zoomedIn, "Zoomed In");
3006 GETINT("state", gridShown, "Grid Shown");
3007 GETINT("state", moveMode, "Move Mode");
3008 GETINT("state", rotate, "Text Rotation");
3009 GETINT("state", rcbRadius, "RCBox Radius");
3010 GETINT("state", useGray, "Use Gray Scale");
3011 GETINT("state", pageLayoutMode,"Page Layout Mode");
3012 GETINT("state", page_arg1, "Page Layout Subarg 1");
3013 GETINT("state", page_arg2, "Page Layout Subarg 2");
3014 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3015 } else if (fileVersion <= 30) {
3016 GETINT("state", drawOrigX, "X Draw Origin");
3017 GETINT("state", drawOrigY, "Y Draw Origin");
3018 GETINT("state", zoomScale, "Zoom scale");
3019 GETINT("state", xyEnglishGrid, "English Grid");
3020 GETINT("state", snapOn, "Grid");
3021 GETINT("state", colorIndex, "Color");
3022 GETINT("state", horiAlign, "Horizontal Align");
3023 GETINT("state", vertAlign, "Vertical Align");
3024 GETINT("state", lineWidth, "Line Width");
3025 GETINT("state", curSpline, "Spline");
3026 GETINT("state", lineStyle, "Line Style");
3027 GETINT("state", objFill, "Fill Pattern");
3028 GETINT("state", penPat, "Pen Pattern");
3029 GETINT("state", textJust, "Text Justify");
3030 GETSTR("state", font_str, "Font Name String");
3031 GETINT("state", curStyle, "Font Style");
3032 GETINT("state", font_sz, "Font Size");
3033 GETINT("state", compat_dpi, "Font DPI");
3034 GETINT("state", curDash, "Dash Style");
3035 GETINT("state", gridSystem, "Grid System");
3036 GETINT("state", xyMetricGrid, "Metric Grid");
3037 GETINT("state", textVSpace, "Text Vertical Spacing");
3038 GETINT("state", zoomedIn, "Zoomed In");
3039 GETINT("state", gridShown, "Grid Shown");
3040 GETINT("state", moveMode, "Move Mode");
3041 GETINT("state", rotate, "Text Rotation");
3042 GETINT("state", rcbRadius, "RCBox Radius");
3043 GETINT("state", useGray, "Use Gray Scale");
3044 GETINT("state", pageLayoutMode,"Page Layout Mode");
3045 GETINT("state", page_arg1, "Page Layout Subarg 1");
3046 GETINT("state", page_arg2, "Page Layout Subarg 2");
3047 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3048 } else if (fileVersion <= 31) {
3049 GETINT("state", drawOrigX, "X Draw Origin");
3050 GETINT("state", drawOrigY, "Y Draw Origin");
3051 GETINT("state", zoomScale, "Zoom scale");
3052 GETINT("state", xyEnglishGrid, "English Grid");
3053 GETINT("state", snapOn, "Grid");
3054 GETINT("state", colorIndex, "Color");
3055 GETINT("state", horiAlign, "Horizontal Align");
3056 GETINT("state", vertAlign, "Vertical Align");
3057 GETINT("state", lineWidth, "Line Width");
3058 GETINT("state", curSpline, "Spline");
3059 GETINT("state", lineStyle, "Line Style");
3060 GETINT("state", objFill, "Fill Pattern");
3061 GETINT("state", penPat, "Pen Pattern");
3062 GETINT("state", textJust, "Text Justify");
3063 GETSTR("state", font_str, "Font Name String");
3064 GETINT("state", curStyle, "Font Style");
3065 GETINT("state", font_sz, "Font Size");
3066 GETINT("state", compat_dpi, "Font DPI");
3067 GETINT("state", curDash, "Dash Style");
3068 GETINT("state", gridSystem, "Grid System");
3069 GETINT("state", xyMetricGrid, "Metric Grid");
3070 GETINT("state", textVSpace, "Text Vertical Spacing");
3071 GETINT("state", zoomedIn, "Zoomed In");
3072 GETINT("state", gridShown, "Grid Shown");
3073 GETINT("state", moveMode, "Move Mode");
3074 GETINT("state", rotate, "Text Rotation");
3075 GETINT("state", rcbRadius, "RCBox Radius");
3076 GETINT("state", useGray, "Use Gray Scale");
3077 GETINT("state", pageLayoutMode,"Page Layout Mode");
3078 GETINT("state", page_arg1, "Page Layout Subarg 1");
3079 GETINT("state", page_arg2, "Page Layout Subarg 2");
3080 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3081 GETINT("state", colorDump, "Print In Color");
3082 } else if (fileVersion <= 32) {
3083 GETINT("state", drawOrigX, "X Draw Origin");
3084 GETINT("state", drawOrigY, "Y Draw Origin");
3085 GETINT("state", zoomScale, "Zoom scale");
3086 GETINT("state", xyEnglishGrid, "English Grid");
3087 GETINT("state", snapOn, "Grid");
3088 GETINT("state", colorIndex, "Color");
3089 GETINT("state", horiAlign, "Horizontal Align");
3090 GETINT("state", vertAlign, "Vertical Align");
3091 GETINT("state", lineWidth, "Line Width");
3092 GETINT("state", curSpline, "Spline");
3093 GETINT("state", lineStyle, "Line Style");
3094 GETINT("state", objFill, "Fill Pattern");
3095 GETINT("state", penPat, "Pen Pattern");
3096 GETINT("state", textJust, "Text Justify");
3097 GETSTR("state", font_str, "Font Name String");
3098 GETINT("state", curStyle, "Font Style");
3099 GETINT("state", font_sz, "Font Size");
3100 GETINT("state", compat_dpi, "Font DPI");
3101 GETINT("state", curDash, "Dash Style");
3102 GETINT("state", gridSystem, "Grid System");
3103 GETINT("state", xyMetricGrid, "Metric Grid");
3104 GETINT("state", textVSpace, "Text Vertical Spacing");
3105 GETINT("state", zoomedIn, "Zoomed In");
3106 GETINT("state", gridShown, "Grid Shown");
3107 GETINT("state", moveMode, "Move Mode");
3108 GETINT("state", rotate, "Text Rotation");
3109 GETINT("state", rcbRadius, "RCBox Radius");
3110 GETINT("state", useGray, "Use Gray Scale");
3111 GETINT("state", pageLayoutMode, "Page Layout Mode");
3112 GETINT("state", page_arg1, "Page Layout Subarg 1");
3113 GETINT("state", page_arg2, "Page Layout Subarg 2");
3114 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3115 GETINT("state", colorDump, "Print In Color");
3116 GETINT("state", one_page_width, "One Page Width");
3117 GETINT("state", one_page_height,"One Page Height");
3118 } else if (fileVersion <= 34) {
3119 GETINT("state", drawOrigX, "X Draw Origin");
3120 GETINT("state", drawOrigY, "Y Draw Origin");
3121 GETINT("state", zoomScale, "Zoom scale");
3122 GETINT("state", xyEnglishGrid, "English Grid");
3123 GETINT("state", snapOn, "Grid");
3124 GETINT("state", colorIndex, "Color");
3125 GETINT("state", horiAlign, "Horizontal Align");
3126 GETINT("state", vertAlign, "Vertical Align");
3127 GETINT("state", lineWidth, "Line Width");
3128 GETINT("state", curSpline, "Spline");
3129 GETINT("state", lineStyle, "Line Style");
3130 GETINT("state", objFill, "Fill Pattern");
3131 GETINT("state", penPat, "Pen Pattern");
3132 GETINT("state", textJust, "Text Justify");
3133 GETSTR("state", font_str, "Font Name String");
3134 GETINT("state", curStyle, "Font Style");
3135 GETINT("state", font_sz, "Font Size");
3136 GETINT("state", compat_dpi, "Font DPI");
3137 GETINT("state", curDash, "Dash Style");
3138 GETINT("state", gridSystem, "Grid System");
3139 GETINT("state", xyMetricGrid, "Metric Grid");
3140 GETINT("state", textVSpace, "Text Vertical Spacing");
3141 GETINT("state", zoomedIn, "Zoomed In");
3142 GETINT("state", gridShown, "Grid Shown");
3143 GETINT("state", moveMode, "Move Mode");
3144 GETINT("state", rotate, "Text Rotation");
3145 GETINT("state", rcbRadius, "RCBox Radius");
3146 GETINT("state", useGray, "Use Gray Scale");
3147 GETINT("state", pageLayoutMode, "Page Layout Mode");
3148 GETINT("state", page_arg1, "Page Layout Subarg 1");
3149 GETINT("state", page_arg2, "Page Layout Subarg 2");
3150 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3151 GETINT("state", colorDump, "Print In Color");
3152 GETINT("state", one_page_width, "One Page Width");
3153 GETINT("state", one_page_height,"One Page Height");
3154 GETINT("state", stretchableText,"Stretchable Text");
3155 GETINT("state", textRotation, "Text Rotation");
3156 GETINT("state", rotationIncrement,"Rotation Increment");
3157 } else if (fileVersion <= 35) {
3158 GETINT("state", drawOrigX, "X Draw Origin");
3159 GETINT("state", drawOrigY, "Y Draw Origin");
3160 GETINT("state", zoomScale, "Zoom scale");
3161 GETINT("state", xyEnglishGrid, "English Grid");
3162 GETINT("state", snapOn, "Grid");
3163 GETINT("state", colorIndex, "Color");
3164 GETINT("state", horiAlign, "Horizontal Align");
3165 GETINT("state", vertAlign, "Vertical Align");
3166 GETINT("state", lineWidth, "Line Width");
3167 GETINT("state", curSpline, "Spline");
3168 GETINT("state", lineStyle, "Line Style");
3169 GETINT("state", objFill, "Fill Pattern");
3170 GETINT("state", penPat, "Pen Pattern");
3171 GETINT("state", textJust, "Text Justify");
3172 GETSTR("state", font_str, "Font Name String");
3173 GETINT("state", curStyle, "Font Style");
3174 GETINT("state", font_sz, "Font Size");
3175 GETINT("state", compat_dpi, "Font DPI");
3176 GETINT("state", curDash, "Dash Style");
3177 GETINT("state", gridSystem, "Grid System");
3178 GETINT("state", xyMetricGrid, "Metric Grid");
3179 GETINT("state", textVSpace, "Text Vertical Spacing");
3180 GETINT("state", zoomedIn, "Zoomed In");
3181 GETINT("state", gridShown, "Grid Shown");
3182 GETINT("state", moveMode, "Move Mode");
3183 GETINT("state", rotate, "Text Rotation");
3184 GETINT("state", rcbRadius, "RCBox Radius");
3185 GETINT("state", useGray, "Use Gray Scale");
3186 GETINT("state", pageLayoutMode, "Page Layout Mode");
3187 GETINT("state", page_arg1, "Page Layout Subarg 1");
3188 GETINT("state", page_arg2, "Page Layout Subarg 2");
3189 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3190 GETINT("state", colorDump, "Print In Color");
3191 GETINT("state", one_page_width, "One Page Width");
3192 GETINT("state", one_page_height,"One Page Height");
3193 GETINT("state", stretchableText,"Stretchable Text");
3194 GETINT("state", textRotation, "Text Rotation");
3195 GETINT("state", rotationIncrement,"Rotation Increment");
3196 GETINT("state", transPat, "Pattern Transparency");
3197 } else {
3198 GETINT("state", drawOrigX, "X Draw Origin");
3199 GETINT("state", drawOrigY, "Y Draw Origin");
3200 GETINT("state", zoomScale, "Zoom scale");
3201 GETINT("state", xyEnglishGrid, "English Grid");
3202 GETINT("state", snapOn, "Grid");
3203 GETINT("state", colorIndex, "Color");
3204 GETINT("state", horiAlign, "Horizontal Align");
3205 GETINT("state", vertAlign, "Vertical Align");
3206 GETINT("state", lineWidth, "Line Width");
3207 GETINT("state", curSpline, "Spline");
3208 GETINT("state", lineStyle, "Line Style");
3209 GETINT("state", objFill, "Fill Pattern");
3210 GETINT("state", penPat, "Pen Pattern");
3211 GETINT("state", textJust, "Text Justify");
3212 GETSTR("state", font_str, "Font Name String");
3213 GETINT("state", curStyle, "Font Style");
3214 GETINT("state", sz_unit, "Font Size Unit");
3215 GETINT("state", compat_dpi, "Font DPI");
3216 GETINT("state", curDash, "Dash Style");
3217 GETINT("state", gridSystem, "Grid System");
3218 GETINT("state", xyMetricGrid, "Metric Grid");
3219 GETINT("state", textVSpace, "Text Vertical Spacing");
3220 GETINT("state", zoomedIn, "Zoomed In");
3221 GETINT("state", gridShown, "Grid Shown");
3222 GETINT("state", moveMode, "Move Mode");
3223 GETINT("state", rotate, "Text Rotation");
3224 GETINT("state", rcbRadius, "RCBox Radius");
3225 GETINT("state", useGray, "Use Gray Scale");
3226 GETINT("state", pageLayoutMode, "Page Layout Mode");
3227 GETINT("state", page_arg1, "Page Layout Subarg 1");
3228 GETINT("state", page_arg2, "Page Layout Subarg 2");
3229 GETINT("state", pageLineShownInTileMode,"Page Lines Shown");
3230 GETINT("state", colorDump, "Print In Color");
3231 GETINT("state", one_page_width, "One Page Width");
3232 GETINT("state", one_page_height,"One Page Height");
3233 GETINT("state", stretchableText,"Stretchable Text");
3234 GETINT("state", textRotation, "Text Rotation");
3235 GETINT("state", rotationIncrement,"Rotation Increment");
3236 GETINT("state", transPat, "Pattern Transparency");
3237 }
3238 if (fileVersion <= 28) readingPageNum++;
3239 if (fileVersion <= 29) {
3240 VerifyCompatibleFontIndex(&curFont);
3241 font_sz = GetCompatibleSize(compat_dpi, font_sz);
3242 curSzUnit = FontSizeToSzUnit(font_sz);
3243 if (PRTGIF) {
3244 PrTgifInitBaseFonts();
3245 }
3246 } else {
3247 char *psz=NULL;
3248 int len=strlen(font_str);
3249
3250 if (fileVersion <= 35) {
3251 curSzUnit = FontSizeToSzUnit(font_sz);
3252 } else {
3253 curSzUnit = sz_unit;
3254 }
3255 if (len > 1 && *font_str == '\'' && font_str[len-1] == '\'') {
3256 char *psz1=(&font_str[1]);
3257
3258 font_str[len-1] = '\0';
3259 psz = font_str;
3260 while (*psz1 != '\0') *psz++ = *psz1++;
3261 *psz = '\0';
3262 }
3263 if ((psz=strchr(font_str, '%')) != NULL) {
3264 *psz++ = '\0';
3265 /* Ex., ignore last '%' if font_str eq "Courier%". */
3266 if (*psz != '\0') {
3267 strcpy(sb_font_str, font_str);
3268 strcpy(font_str, psz);
3269 }
3270 }
3271 curFont = GetFontIndex(font_str, curStyle, TRUE);
3272 if (curFont == INVALID && (!PRTGIF || cmdLineOpenDisplay)) {
3273 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_FIND_FONT_USE_ALT),
3274 font_str, "Times");
3275 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
3276 curFont = FONT_TIM;
3277 }
3278 }
3279 switch (pageLayoutMode) {
3280 case PAGE_STACK:
3281 curPageNum = page_arg1;
3282 lastPageNum = page_arg2;
3283 paperCol = paperRow = 1;
3284 pageLineShownInTileMode = TRUE;
3285 break;
3286 case PAGE_TILE:
3287 paperCol = page_arg1;
3288 paperRow = page_arg2;
3289 curPageNum = lastPageNum = 1;
3290 break;
3291 }
3292 loadedCurPageNum = curPageNum;
3293 InitPage();
3294 curPageNum = loadedCurPageNum;
3295
3296 if (fileVersion <= 13) {
3297 switch (gridSystem) {
3298 case ENGLISH_GRID:
3299 drawOrigX += HALF_INCH;
3300 drawOrigY += HALF_INCH;
3301 break;
3302 case METRIC_GRID:
3303 drawOrigX += 2.5*ONE_CM;
3304 drawOrigY += 2.5*ONE_CM;
3305 break;
3306 }
3307 }
3308 if ((usePaperSizeStoredInFile || PRTGIF) && fileVersion >= 32) {
3309 if (pageStyle == LANDSCAPE) {
3310 onePageWidth = one_page_height;
3311 onePageHeight = one_page_width;
3312 } else {
3313 onePageWidth = one_page_width;
3314 onePageHeight = one_page_height;
3315 }
3316 SetPSPageWidthHeight();
3317 if (PRTGIF) {
3318 UpdPageStyle(pageStyle);
3319 }
3320 }
3321 if (PRTGIF && !cmdLineOpenDisplay) {
3322 if (forced_use_gray) useGray = TRUE;
3323 return TRUE;
3324 }
3325 if (rotate != 0) {
3326 switch (rotate) {
3327 case ROTATE0: textRotation = 0; break;
3328 case ROTATE90: textRotation = (90<<6); break;
3329 case ROTATE180: textRotation = (180<<6); break;
3330 case ROTATE270: textRotation = (270<<6); break;
3331 }
3332 rotationIncrement = (90<<6);
3333 rotate = ROTATE0;
3334 }
3335 if (colorIndex >= maxColors) {
3336 fprintf(stderr, TgLoadString(STID_CANT_FIND_COLOR_NUM_USE_CUR),
3337 colorIndex, colorMenuItems[defaultColorIndex]);
3338 fprintf(stderr, "\n");
3339 colorIndex = defaultColorIndex;
3340 gnCannotFindColorMsg = TRUE;
3341 }
3342 SetCanvasFont();
3343 /*
3344 * if (!PRTGIF && SzUnitToFontSize(curSzUnit) != canvasFontSize) {
3345 * curFont = actualCurFont;
3346 * curSzUnit = actualCurSzUnit;
3347 * SetFileModified(TRUE);
3348 * }
3349 */
3350 }
3351 /*
3352 * Move from below. Hope this won't change anything!
3353 */
3354 UpdDrawWinWH();
3355 UpdPageStyle(pageStyle);
3356 if (PRTGIF && !cmdLineOpenDisplay) return TRUE;
3357
3358 if (lineWidth >= maxLineWidths) {
3359 fprintf(stderr, TgLoadString(STID_LINEWIDTH_IDX_RANGE_SET_TO_0),
3360 lineWidth);
3361 fprintf(stderr, "\n");
3362 lineWidth = 0;
3363 }
3364
3365 RedrawScrollBars();
3366 ShowPage();
3367 ShowPageLayout();
3368 UpdDrawWinBBox();
3369
3370 SetDefaultDrawWinClipRecs();
3371
3372 DrawPaperBoundary(drawWindow);
3373 RedrawGridLines(drawWindow);
3374 RedrawPageLines(drawWindow);
3375 RedrawRulers();
3376 RedrawChoiceWindow();
3377
3378 return TRUE;
3379 }
3380
3381 static
ReadObjAttrs(MinFileVersion,FP,ObjPtr)3382 void ReadObjAttrs(MinFileVersion, FP, ObjPtr)
3383 int MinFileVersion;
3384 FILE *FP;
3385 struct ObjRec **ObjPtr;
3386 {
3387 struct AttrRec *top_attr=NULL, *bot_attr=NULL, *attr_ptr;
3388
3389 if (fileVersion <= MinFileVersion) return;
3390
3391 while (ReadAttr(FP, &attr_ptr)) {
3392 attr_ptr->owner = *ObjPtr;
3393 attr_ptr->prev = NULL;
3394 attr_ptr->next = top_attr;
3395 if (top_attr == NULL) {
3396 bot_attr = attr_ptr;
3397 } else {
3398 top_attr->prev = attr_ptr;
3399 }
3400 top_attr = attr_ptr;
3401 }
3402 if (bot_attr != NULL) bot_attr->next = NULL;
3403 if (*ObjPtr == NULL) {
3404 DelAllAttrs(top_attr);
3405 } else {
3406 (*ObjPtr)->fattr = top_attr;
3407 (*ObjPtr)->lattr = bot_attr;
3408 }
3409 }
3410
3411 static
ReadPageObj(Inbuf,ppsz_page_name)3412 int ReadPageObj(Inbuf, ppsz_page_name)
3413 char *Inbuf, **ppsz_page_name;
3414 {
3415 int page_num=0, reading_page_num=0;
3416 char *s=NULL, *c_ptr=NULL;
3417
3418 if (ppsz_page_name != NULL) *ppsz_page_name = NULL;
3419 s = FindChar((int)'(', Inbuf);
3420 if (sscanf(s, "%d", &page_num) != 1) {
3421 sprintf(gszMsgBox, TgLoadString(STID_BAD_FIELD_IN_OBJ_ABORT_READ),
3422 scanFileName, scanLineNum, "page_num", "page");
3423 if (PRTGIF) {
3424 fprintf(stderr, "%s\n", gszMsgBox);
3425 } else {
3426 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
3427 }
3428 return FALSE;
3429 }
3430 reading_page_num = page_num;
3431 if (!importingFile) {
3432 char saved_ch='\0';
3433
3434 for (curPage=firstPage; page_num != 1 && curPage != NULL;
3435 curPage=curPage->next, page_num--) {
3436 }
3437 if (curPage == NULL) {
3438 if (!mergingFile) {
3439 sprintf(gszMsgBox, TgLoadString(STID_BAD_INPUT_WHILE_READ_PAGE),
3440 page_num);
3441 if (PRTGIF) {
3442 fprintf(stderr, "%s\n", gszMsgBox);
3443 } else {
3444 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
3445 }
3446 return FALSE;
3447 }
3448 AddPageAfter();
3449 }
3450 s = FindChar((int)',', s);
3451 c_ptr = FindChar((int)'"', s);
3452 s = ReadString(c_ptr);
3453 saved_ch = *(--s);
3454 *s = '\0';
3455 if (*c_ptr != '\0') {
3456 curPage->name = UtilStrDup(c_ptr);
3457 if (curPage->name == NULL) FailAllocMessage();
3458 }
3459 *s++ = saved_ch;
3460 InitScan(s, "\t\n, )");
3461
3462 topObj = curPage->top;
3463 botObj = curPage->bot;
3464
3465 curPage->layer_on = TRUE;
3466 if (fileVersion <= 32) {
3467 } else {
3468 int layer_on=TRUE;
3469 char page_file_name[MAXSTRING];
3470
3471 if (GETINT("page", layer_on, "color layer on") == INVALID) {
3472 return FALSE;
3473 }
3474 curPage->layer_on = layer_on;
3475 /*
3476 * This is a hack! If the file version becomes >= 38, this code
3477 * must be removed!
3478 */
3479 if (GETSTR("page", page_file_name, "page_file_name") == INVALID) {
3480 /* should not get here because we should have read in: "." */
3481 return FALSE;
3482 } else if (strcmp(page_file_name, ".") == 0) {
3483 *page_file_name = '\0';
3484 } else if (*page_file_name == '\'') {
3485 UtilRemoveQuotes(page_file_name);
3486 }
3487 if (*page_file_name != '\0') {
3488 char *psz=strchr(page_file_name, ' ');
3489
3490 if (psz != NULL) {
3491 char truncated_name[MAXSTRING];
3492
3493 *psz = *truncated_name = '\0';
3494 UtilStrCpyN(truncated_name, sizeof(truncated_name),
3495 page_file_name);
3496 *psz = ' ';
3497 sprintf(gszMsgBox,
3498 TgLoadString(STID_BAD_PAGE_FILE_NAME_TRUNC_TO),
3499 page_file_name, truncated_name);
3500 if (PRTGIF) {
3501 fprintf(stderr, "%s\n", gszMsgBox);
3502 } else {
3503 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
3504 }
3505 strcpy(page_file_name, truncated_name);
3506 }
3507 curPage->page_file_name = UtilStrDup(page_file_name);
3508 if (curPage->page_file_name == NULL) FailAllocMessage();
3509 }
3510 }
3511 } else {
3512 s = FindChar((int)',', s);
3513 c_ptr = FindChar((int)'"', s);
3514 s = ReadString(c_ptr);
3515 *(--s) = '\0';
3516 if (*c_ptr != '\0' && ppsz_page_name != NULL) {
3517 *ppsz_page_name = UtilStrDup(c_ptr);
3518 if (*ppsz_page_name == NULL) FailAllocMessage();
3519 }
3520 }
3521 readingPageNum++;
3522 if (readingPageNum < reading_page_num) {
3523 readingPageNum = reading_page_num;
3524 }
3525 return TRUE;
3526 }
3527
3528 static
ReadUnitObj(Inbuf)3529 int ReadUnitObj(Inbuf)
3530 char *Inbuf;
3531 {
3532 if (!importingFile) {
3533 char *s=FindChar((int)'(', Inbuf), *c_ptr;
3534
3535 c_ptr = FindChar((int)'"', s);
3536 s = ReadString(c_ptr);
3537 *(--s) = '\0';
3538 if (SetUnit(c_ptr)) {
3539 return TRUE;
3540 } else {
3541 return FALSE;
3542 }
3543 }
3544 return TRUE;
3545 }
3546
3547 static
ReadGeneratedBy(Inbuf)3548 int ReadGeneratedBy(Inbuf)
3549 char *Inbuf;
3550 {
3551 int ok=TRUE;
3552 char *s=FindChar((int)'(', Inbuf);
3553
3554 memset(&gGenerateByInfo, 0, sizeof(GenerateByInfo));
3555
3556 if (s == NULL) {
3557 ok = FALSE;
3558 } else {
3559 GenerateByInfo *pgbi=(&gGenerateByInfo);
3560
3561 InitScan(s, "\t\n, ");
3562
3563 if (GETSTR("generated_by", pgbi->name, "name") == INVALID ||
3564 GETINT("generated_by", pgbi->version, "version") == INVALID ||
3565 GETSTR("generated_by", pgbi->version_str, "version_str") == INVALID) {
3566 ok = FALSE;
3567 memset(&gGenerateByInfo, 0, sizeof(GenerateByInfo));
3568 } else {
3569 UtilRemoveQuotes(pgbi->name);
3570 UtilRemoveQuotes(pgbi->version_str);
3571 }
3572 }
3573 if (!ok) {
3574 fprintf(stderr, TgLoadCachedString(CSTID_MALFORMED_LINE_NUM_IN_FILE),
3575 scanLineNum, scanFileName);
3576 fprintf(stderr, "\n");
3577 }
3578 return TRUE;
3579 }
3580
3581 static
ReadScriptFracObj(Inbuf)3582 int ReadScriptFracObj(Inbuf)
3583 char *Inbuf;
3584 {
3585 if (!importingFile) {
3586 char *s=FindChar((int)'(', Inbuf), *c_ptr=NULL;
3587
3588 c_ptr = FindChar((int)'"', s);
3589 s = ReadString(c_ptr);
3590 *(--s) = '\0';
3591 if (!FixDecimalPoint(c_ptr)) {
3592 #ifdef _TGIF_DBG /* debug, do not translate */
3593 fprintf(stderr, "FixDecimalPoint() failed in ReadScriptFracObj().\n");
3594 #endif /* _TGIF_DBG */
3595 }
3596 if (SetScriptFractionValue(c_ptr)) {
3597 return TRUE;
3598 } else {
3599 return FALSE;
3600 }
3601 }
3602 return TRUE;
3603 }
3604
3605 static
ReadRightMarginObj(Inbuf)3606 int ReadRightMarginObj(Inbuf)
3607 char *Inbuf;
3608 {
3609 if (!importingFile) {
3610 int right_margin_enabled=FALSE, right_margin=0;
3611 char *s=FindChar((int)'(', Inbuf);
3612
3613 InitScan(s, "\t\n, )");
3614 GETINT("right_margin", right_margin_enabled, "Right Margin Enabled");
3615 GETINT("right_margin", right_margin, "Right Margin");
3616
3617 rightMarginEnabled = right_margin_enabled;
3618 rightMargin = right_margin;
3619 rightMarginActive = rightMarginEnabled;
3620
3621 if (!PRTGIF) RedrawHRulerWindow();
3622 }
3623 return TRUE;
3624 }
3625
3626 static
ReadThreshFillReplaceObj(Inbuf)3627 int ReadThreshFillReplaceObj(Inbuf)
3628 char *Inbuf;
3629 {
3630 if (!importingFile) {
3631 int do_msg=FALSE;
3632 int saved_thresh_fill_replace_enabled=threshFillReplaceEnabled;
3633 int saved_r=fillReplaceRedThresh, r=0;
3634 int saved_g=fillReplaceGreenThresh, g=0;
3635 int saved_b=fillReplaceBlueThresh, b=0;
3636 char *s=FindChar((int)'(', Inbuf);
3637
3638 InitScan(s, "\t\n, )");
3639 GETINT("threshold_fill_replace", r, "Red Threshold");
3640 GETINT("threshold_fill_replace", g, "Green Threshold");
3641 GETINT("threshold_fill_replace", b, "Blue Threshold");
3642
3643 do_msg = (saved_thresh_fill_replace_enabled && (saved_r != r ||
3644 saved_g != g || saved_b != b));
3645
3646 threshFillReplaceEnabled = TRUE;
3647 fillReplaceRedThresh = r;
3648 fillReplaceGreenThresh = g;
3649 fillReplaceBlueThresh = b;
3650
3651 if (!PRTGIF && do_msg) {
3652 sprintf(gszMsgBox, TgLoadString(STID_FLOOD_REPLACE_ENABLED),
3653 fillReplaceRedThresh, fillReplaceGreenThresh,
3654 fillReplaceBlueThresh);
3655 Msg(gszMsgBox);
3656 }
3657 }
3658 return TRUE;
3659 }
3660
3661 #define GETSSVALUE(val,name) ScanValue("%d", &(val), name, "shapeshadow")
3662
3663 static
ReadShapeShadowObj(Inbuf)3664 int ReadShapeShadowObj(Inbuf)
3665 char *Inbuf;
3666 {
3667 if (!importingFile) {
3668 char *s=FindChar((int)'(', Inbuf);
3669 int dx=0, dy=0;
3670
3671 InitScan(s, "\t\n, ");
3672
3673 if (GETSSVALUE(dx, "dx") == INVALID ||
3674 GETSSVALUE(dy, "dy") == INVALID) {
3675 return FALSE;
3676 }
3677 shapeShadowDx = dx;
3678 shapeShadowDy = dy;
3679 }
3680 return TRUE;
3681 }
3682
3683 static
ReadFgBgColors(Inbuf)3684 int ReadFgBgColors(Inbuf)
3685 char *Inbuf;
3686 {
3687 if (!importingFile && !PRTGIF) {
3688 int new_alloc=FALSE, bg_color_index=INVALID;
3689 char *s=FindChar((int)'(', Inbuf), fg_color_str[40], bg_color_str[40];
3690
3691 s = ParseStr(s, (int)',', fg_color_str, sizeof(fg_color_str));
3692 s = ParseStr(s, (int)')', bg_color_str, sizeof(bg_color_str));
3693 UtilTrimBlanks(fg_color_str);
3694 UtilTrimBlanks(bg_color_str);
3695 allocColorFailed = FALSE;
3696 colorIndex = QuickFindColorIndex(NULL, fg_color_str, &new_alloc,
3697 TRUE);
3698 if (gnCannotFindColorMsg && !allocColorFailed) {
3699 sprintf(gszMsgBox, TgLoadString(STID_CUR_COLOR_CORRECTED_TO_BE),
3700 colorMenuItems[colorIndex]);
3701 fprintf(stderr, " %s\n", gszMsgBox);
3702 }
3703 bg_color_index = QuickFindColorIndex(NULL, bg_color_str, &new_alloc,
3704 FALSE);
3705 if (bg_color_index == INVALID) {
3706 sprintf(gszMsgBox, TgLoadString(STID_FAIL_ALLOC_BGCOLOR_USE_DEF),
3707 bg_color_str, defaultBgColorStr);
3708 fprintf(stderr, "%s\n", gszMsgBox);
3709 } else {
3710 strcpy(defaultBgColorStr, bg_color_str);
3711 defaultBgColorIndex = bg_color_index;
3712 }
3713 }
3714 return TRUE;
3715 }
3716
3717 static
FreeBufAndReturn(buf,rc)3718 int FreeBufAndReturn(buf, rc)
3719 char *buf;
3720 int rc;
3721 {
3722 if (buf != NULL) free(buf);
3723 return rc;
3724 }
3725
ReadObj(FP,ObjPtr)3726 int ReadObj(FP, ObjPtr)
3727 FILE *FP;
3728 struct ObjRec **ObjPtr;
3729 {
3730 char *line, obj_name[80];
3731 int read_state_ok;
3732
3733 *ObjPtr = NULL;
3734 while ((line=UtilGetALine(FP)) != NULL) {
3735 scanLineNum++;
3736 if (*line == ']') return FreeBufAndReturn(line, FALSE);
3737
3738 if (*line == '%') {
3739 if (!importingFile && line[1]=='%') {
3740 int line_len=strlen(line);
3741
3742 if (savedComments == NULL) {
3743 if ((savedComments=(char*)malloc((line_len+2)*sizeof(char)))
3744 == NULL) {
3745 FailAllocMessage();
3746 }
3747 *savedComments = '\0';
3748 } else {
3749 if ((savedComments=(char*)realloc(savedComments,
3750 savedCommentsLen+line_len+2)) == NULL) {
3751 FailAllocMessage();
3752 }
3753 savedComments[savedCommentsLen] = '\0';
3754 }
3755 strcat(savedComments, line);
3756 savedCommentsLen += line_len;
3757 savedComments[savedCommentsLen++] = '\n';
3758 savedComments[savedCommentsLen] = '\0';
3759 }
3760 /* do not translate -- program constants */
3761 if (strncmp(line, "%TGWB end - ", strlen("%TGWB end - ")) == 0) {
3762 return FreeBufAndReturn(line, FALSE);
3763 }
3764 free(line);
3765 continue;
3766 }
3767 /* do not translate -- program constants */
3768 if (ParseStr(line, (int)'(', obj_name, sizeof(obj_name)) == NULL) {
3769 } else if (strcmp(obj_name, "poly") == 0) {
3770 ReadPolyObj(FP, line, ObjPtr);
3771 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3772 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3773 ReadObjAttrs(INVALID, FP, ObjPtr);
3774 if (RetractedArrowAttr(*ObjPtr) ||
3775 AutoRetractedArrowAttr(*ObjPtr, TRUE)) {
3776 /* fake the undoingOrRedoing so that no */
3777 /* actual auto-adjusting is done */
3778 undoingOrRedoing = TRUE;
3779 AdjObjSplineVs(*ObjPtr);
3780 undoingOrRedoing = FALSE;
3781 }
3782 AdjObjBBox(*ObjPtr);
3783 return FreeBufAndReturn(line, TRUE);
3784 } else if (strcmp(obj_name, "box") == 0) {
3785 ReadBoxObj(FP, line, ObjPtr);
3786 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3787 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3788 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3789 AdjObjBBox(*ObjPtr);
3790 return FreeBufAndReturn(line, TRUE);
3791 } else if (strcmp(obj_name, "oval") == 0) {
3792 ReadOvalObj(FP, line, ObjPtr);
3793 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3794 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3795 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3796 AdjObjBBox(*ObjPtr);
3797 return FreeBufAndReturn(line, TRUE);
3798 } else if (strcmp(obj_name, "text") == 0) {
3799 ReadTextObj(FP, line, ObjPtr);
3800 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3801 return FreeBufAndReturn(line, TRUE);
3802 } else if (strcmp(obj_name, "polygon") == 0) {
3803 ReadPolygonObj(FP, line, ObjPtr);
3804 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3805 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3806 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3807 AdjObjBBox(*ObjPtr);
3808 return FreeBufAndReturn(line, TRUE);
3809 } else if (strcmp(obj_name, "arc") == 0) {
3810 ReadArcObj(FP, line, ObjPtr);
3811 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3812 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3813 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3814 AdjObjBBox(*ObjPtr);
3815 return FreeBufAndReturn(line, TRUE);
3816 } else if (strcmp(obj_name, "rcbox") == 0) {
3817 ReadRCBoxObj(FP, line, ObjPtr);
3818 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3819 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3820 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3821 AdjObjBBox(*ObjPtr);
3822 return FreeBufAndReturn(line, TRUE);
3823 } else if (strcmp(obj_name, "xbm") == 0) {
3824 ReadXBmObj(FP, line, ObjPtr);
3825 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3826 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3827 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3828 AdjObjBBox(*ObjPtr);
3829 return FreeBufAndReturn(line, TRUE);
3830 } else if (strcmp(obj_name, "xpm") == 0) {
3831 ReadXPmObj(FP, line, ObjPtr);
3832 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3833 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3834 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3835 AdjObjBBox(*ObjPtr);
3836 return FreeBufAndReturn(line, TRUE);
3837 } else if (strcmp(obj_name, "jpeg") == 0) {
3838 ReadJpegObj(FP, line, ObjPtr);
3839 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3840 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3841 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3842 AdjObjBBox(*ObjPtr);
3843 return FreeBufAndReturn(line, TRUE);
3844 } else if (strcmp(obj_name, "ppm_true") == 0) {
3845 ReadPpmTrueObj(FP, line, ObjPtr);
3846 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3847 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3848 ReadObjAttrs(START_HAVING_ATTRS-1, FP, ObjPtr);
3849 AdjObjBBox(*ObjPtr);
3850 return FreeBufAndReturn(line, TRUE);
3851 } else if (strcmp(obj_name, "group") == 0) {
3852 ReadGroupObj(FP, OBJ_GROUP, ObjPtr);
3853 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3854 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3855 ReadObjAttrs(INVALID, FP, ObjPtr);
3856 AdjObjBBox(*ObjPtr);
3857 return FreeBufAndReturn(line, TRUE);
3858 } else if (strcmp(obj_name, "sym") == 0) {
3859 ReadGroupObj(FP, OBJ_SYM, ObjPtr);
3860 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3861 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3862 ReadObjAttrs(INVALID, FP, ObjPtr);
3863 AdjObjBBox(*ObjPtr);
3864 return FreeBufAndReturn(line, TRUE);
3865 } else if (strcmp(obj_name, "icon") == 0) {
3866 ReadGroupObj(FP, OBJ_ICON, ObjPtr);
3867 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3868 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3869 ReadObjAttrs(INVALID, FP, ObjPtr);
3870 AdjObjBBox(*ObjPtr);
3871 return FreeBufAndReturn(line, TRUE);
3872 } else if (strcmp(obj_name, "pin") == 0) {
3873 ReadGroupObj(FP, OBJ_PIN, ObjPtr);
3874 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3875 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3876 ReadObjAttrs(INVALID, FP, ObjPtr);
3877 AdjObjBBox(*ObjPtr);
3878 return FreeBufAndReturn(line, TRUE);
3879 } else if (strcmp(obj_name, "simple_string") == 0) {
3880 /* reserved */
3881 ReadSimpleStringObj(FP, line, ObjPtr);
3882 if (*ObjPtr == NULL) return FreeBufAndReturn(line, FALSE);
3883 if (deserializingFile) ReadCreatorID(FP, ObjPtr);
3884 return FreeBufAndReturn(line, TRUE);
3885 } else if (strcmp(obj_name, "page") == 0) {
3886 int ok;
3887 char *page_name=NULL;
3888
3889 *ObjPtr = NULL;
3890 if (importingFile && !importingIconFile) {
3891 if (importingPageNum == (-1) && *importingPageName == '\0') {
3892 if (readingPageNum == 1) {
3893 /* as if read to the end of file */
3894 if (!PRTGIF && !pastingFile) {
3895 MsgBox(TgLoadString(STID_ONLY_PAGE_1_IMPORTED), TOOL_NAME,
3896 INFO_MB);
3897 }
3898 return FreeBufAndReturn(line, FALSE);
3899 }
3900 } else {
3901 if (readingPageNum == importingPageNum) {
3902 /* as if read to the end of file */
3903 if (!PRTGIF && !pastingFile) {
3904 sprintf(gszMsgBox,
3905 TgLoadString(STID_ONLY_GIVEN_PAGE_IMPORTED),
3906 importingPageNum);
3907 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
3908 }
3909 return FreeBufAndReturn(line, FALSE);
3910 }
3911 }
3912 }
3913 ok = ReadPageObj(line, &page_name);
3914 if (importingFile && !importingIconFile &&
3915 importingPageNum == (-1) && *importingPageName != '\0' &&
3916 page_name != NULL && strcmp(page_name,importingPageName)==0) {
3917 *importingPageName = '\0';
3918 importingPageNum = readingPageNum;
3919 }
3920 if (page_name != NULL) free(page_name);
3921 return FreeBufAndReturn(line, ok);
3922 } else if (strcmp(obj_name, "state") == 0) {
3923 if ((read_state_ok=ReadState(line)) == TRUE) {
3924 foundGoodStateObject = TRUE;
3925 }
3926 *ObjPtr = NULL;
3927 return FreeBufAndReturn(line, (read_state_ok) ? TRUE : INVALID);
3928 } else if (strcmp(obj_name, "file_attr") == 0) {
3929 if (mergingFile) {
3930 struct AttrRec *saved_first_attr=NULL, *saved_last_attr=NULL;
3931
3932 saved_first_attr = tgifObj->fattr;
3933 saved_last_attr = tgifObj->lattr;
3934 tgifObj->fattr = NULL;
3935 tgifObj->lattr = NULL;
3936
3937 ReadObjAttrs(START_HAVING_ATTRS-1, FP, &tgifObj);
3938
3939 if (tgifObj->fattr == NULL) {
3940 /* this file has no file attribute -- which should not happen */
3941 tgifObj->fattr = saved_first_attr;
3942 tgifObj->lattr = saved_last_attr;
3943 } else if (saved_last_attr == NULL) {
3944 /* this is this first file that has file attributes, keep it */
3945 } else {
3946 tgifObj->fattr->prev = saved_last_attr;
3947 saved_last_attr->next = tgifObj->fattr;
3948 tgifObj->fattr = saved_first_attr;
3949 }
3950 } else if (importingFile && !importingIconFile) {
3951 struct AttrRec *saved_first_attr=NULL, *saved_last_attr=NULL;
3952
3953 saved_first_attr = tgifObj->fattr;
3954 saved_last_attr = tgifObj->lattr;
3955 tgifObj->fattr = NULL;
3956 tgifObj->lattr = NULL;
3957
3958 ReadObjAttrs(START_HAVING_ATTRS-1, FP, &tgifObj);
3959 DelAllAttrs(tgifObj->fattr);
3960
3961 tgifObj->fattr = saved_first_attr;
3962 tgifObj->lattr = saved_last_attr;
3963 } else {
3964 ReadObjAttrs(START_HAVING_ATTRS-1, FP, &tgifObj);
3965 }
3966 return FreeBufAndReturn(line, TRUE);
3967 } else if (strcmp(obj_name, "unit") == 0) {
3968 int ok=ReadUnitObj(line);
3969
3970 *ObjPtr = NULL;
3971 return FreeBufAndReturn(line, ok);
3972 } else if (strcmp(obj_name, "generated_by") == 0) {
3973 int ok=ReadGeneratedBy(line);
3974
3975 *ObjPtr = NULL;
3976 return FreeBufAndReturn(line, ok);
3977 } else if (strcmp(obj_name, "shapeshadow") == 0) {
3978 int ok=ReadShapeShadowObj(line);
3979
3980 *ObjPtr = NULL;
3981 return FreeBufAndReturn(line, ok);
3982 } else if (strcmp(obj_name, "color_info") == 0) {
3983 int ok=ReadColors(FP, line);
3984
3985 *ObjPtr = NULL;
3986 return FreeBufAndReturn(line, ok);
3987 } else if (strcmp(obj_name, "cmdx") == 0) {
3988 int ok=ReadExtendedCmd(FP, line);
3989
3990 *ObjPtr = NULL;
3991 return FreeBufAndReturn(line, ok);
3992 } else if (strcmp(obj_name, "cmdxinfo") == 0) {
3993 int ok=ReadExtendedCmdInfo(FP, line);
3994
3995 *ObjPtr = NULL;
3996 return FreeBufAndReturn(line, ok);
3997 } else if (strcmp(obj_name, "cmd") == 0) {
3998 int ok=ReadCmd(FP, line);
3999
4000 *ObjPtr = NULL;
4001 return FreeBufAndReturn(line, ok);
4002 } else if (strcmp(obj_name, "before_image") == 0) {
4003 int ok=ReadBeforeImage(FP, line);
4004
4005 *ObjPtr = NULL;
4006 return FreeBufAndReturn(line, ok);
4007 } else if (strcmp(obj_name, "after_positions") == 0) {
4008 int ok=ReadAfterPositions(FP, line);
4009
4010 *ObjPtr = NULL;
4011 return FreeBufAndReturn(line, ok);
4012 } else if (strcmp(obj_name, "after_image") == 0) {
4013 int ok=ReadAfterImage(FP, line);
4014
4015 *ObjPtr = NULL;
4016 return FreeBufAndReturn(line, ok);
4017 } else if (strcmp(obj_name, "slideshow_info") == 0) {
4018 int ok=ReadSlideShowInfo(line);
4019
4020 *ObjPtr = NULL;
4021 return FreeBufAndReturn(line, ok);
4022 } else if (strcmp(obj_name, "script_frac") == 0) {
4023 int ok=ReadScriptFracObj(line);
4024
4025 *ObjPtr = NULL;
4026 return FreeBufAndReturn(line, ok);
4027 } else if (strcmp(obj_name, "fg_bg_colors") == 0) {
4028 int ok=ReadFgBgColors(line);
4029
4030 *ObjPtr = NULL;
4031 return FreeBufAndReturn(line, ok);
4032 } else if (strcmp(obj_name, "html_export_template") == 0) {
4033 int ok=ReadHtmlExportTemplate(line);
4034
4035 *ObjPtr = NULL;
4036 return FreeBufAndReturn(line, ok);
4037 } else if (strcmp(obj_name, "objshadow_info") == 0) {
4038 int ok=ReadObjectShadowInfo(line);
4039
4040 *ObjPtr = NULL;
4041 return FreeBufAndReturn(line, ok);
4042 } else if (strcmp(obj_name, "rotate_pivot") == 0) {
4043 int ok=ReadRotatePivotInfo(line);
4044
4045 *ObjPtr = NULL;
4046 return FreeBufAndReturn(line, ok);
4047 } else if (strcmp(obj_name, "spline_tightness") == 0) {
4048 int ok=ReadSplineTightness(line);
4049
4050 *ObjPtr = NULL;
4051 return FreeBufAndReturn(line, ok);
4052 } else if (strcmp(obj_name, "right_margin") == 0) {
4053 int ok=ReadRightMarginObj(line);
4054
4055 *ObjPtr = NULL;
4056 return FreeBufAndReturn(line, ok);
4057 } else if (strcmp(obj_name, "threshold_fill_replace") == 0) {
4058 int ok=ReadThreshFillReplaceObj(line);
4059
4060 *ObjPtr = NULL;
4061 return FreeBufAndReturn(line, ok);
4062 } else if (strcmp(obj_name, "dont_reencode") == 0) {
4063 int ok=ReadDontReencode(line);
4064
4065 *ObjPtr = NULL;
4066 return FreeBufAndReturn(line, ok);
4067 } else if (strcmp(obj_name, "ps_font_aliases") == 0) {
4068 int ok=ReadPSFontAliases(FP, line);
4069
4070 *ObjPtr = NULL;
4071 return FreeBufAndReturn(line, ok);
4072 } else if (strcmp(obj_name, "ps_char_subs") == 0) {
4073 int ok=ReadPSCharSubs(FP, line);
4074
4075 *ObjPtr = NULL;
4076 return FreeBufAndReturn(line, ok);
4077 } else if (strcmp(obj_name, "ps_font_need_char_subs") == 0) {
4078 int ok=ReadPSFontNeedCharSubs(FP, line);
4079
4080 *ObjPtr = NULL;
4081 return FreeBufAndReturn(line, ok);
4082 }
4083 free(line);
4084 }
4085 return FALSE;
4086 }
4087
AdjForOldVersion(obj_ptr)4088 void AdjForOldVersion(obj_ptr)
4089 struct ObjRec *obj_ptr;
4090 {
4091 if (fileVersion <= 13) {
4092 switch (gridSystem) {
4093 case ENGLISH_GRID:
4094 MoveObj(obj_ptr, (int)(HALF_INCH), (int)(HALF_INCH));
4095 break;
4096 case METRIC_GRID:
4097 MoveObj(obj_ptr, (int)(2.5*ONE_CM), (int)(2.5*ONE_CM));
4098 break;
4099 }
4100 }
4101 }
4102
DownloadRemoteFile(file_name,ppsz_content_type,ppsz_page_spec,pn_is_html,return_tmp_fname,psz_final_url,cb_final_url)4103 int DownloadRemoteFile(file_name, ppsz_content_type, ppsz_page_spec,
4104 pn_is_html, return_tmp_fname, psz_final_url, cb_final_url)
4105 char *file_name, **ppsz_content_type, **ppsz_page_spec, *return_tmp_fname,
4106 *psz_final_url;
4107 int *pn_is_html, cb_final_url;
4108 /* file_name is assumed to be remote */
4109 {
4110 int ok=TRUE;
4111 char remote_fname[MAXPATHLENGTH+1], *tmp_remote_fname=NULL;
4112
4113 if (!FileIsRemote(file_name)) return FALSE;
4114
4115 *remote_fname = '\0';
4116 if (ppsz_page_spec != NULL) *ppsz_page_spec = NULL;
4117 if (pn_is_html != NULL) *pn_is_html = FALSE;
4118 if (!FormNewFileName(curDir, file_name, NULL, remote_fname,
4119 ppsz_page_spec)) {
4120 sprintf(gszMsgBox, TgLoadString(STID_INVALID_REMOTE_FNAME), file_name);
4121 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4122 ok = FALSE;
4123 } else {
4124 int remote_buf_sz=0;
4125 char *remote_buf=NULL;
4126
4127 SaveStatusStrings();
4128 ok = LoadRemoteFileInMem(remote_fname, &remote_buf, ppsz_content_type,
4129 &remote_buf_sz, pn_is_html, navigateRefresh, psz_final_url,
4130 cb_final_url);
4131 RestoreStatusStrings();
4132 if (ok && remote_buf != NULL) {
4133 if ((tmp_remote_fname=WriteRemoteFileIntoTemp(remote_buf,
4134 remote_buf_sz, NULL)) == NULL) {
4135 ok = FALSE;
4136 }
4137 }
4138 if (remote_buf != NULL) FreeRemoteBuf(remote_buf);
4139 }
4140 if (tmp_remote_fname != NULL) {
4141 strcpy(return_tmp_fname, tmp_remote_fname);
4142 FreeRemoteBuf(tmp_remote_fname);
4143 }
4144 return ok;
4145 }
4146
ImportGivenFile(file_name,group_and_lock,highlight)4147 int ImportGivenFile(file_name, group_and_lock, highlight)
4148 char *file_name;
4149 int group_and_lock, highlight;
4150 /* returns TRUE if ok */
4151 /* returns FALSE if file_name looks ok, only have temporary problems */
4152 /* returns BAD if file_name is bad */
4153 {
4154 struct ObjRec *obj_ptr, *saved_top_obj, *saved_bot_obj;
4155 char *rest, remote_fname[MAXPATHLENGTH+1], *remote_buf=NULL;
4156 char gzipped_fname[MAXPATHLENGTH+1], *tmp_remote_fname=NULL, *page_spec=NULL;
4157 char tmp_filename[MAXPATHLENGTH+1], tmp_filefullpath[MAXPATHLENGTH+1];
4158 int short_name=FALSE, read_status=0, remote_buf_sz=0;
4159 int tmp_linenum, file_is_remote=FALSE, interrupted;
4160 FILE *fp=NULL;
4161 XEvent ev;
4162
4163 *gzipped_fname = '\0';
4164 if (FileIsRemote(file_name)) {
4165 int rc=TRUE;
4166
4167 if (!FormNewFileName(curDir, file_name, NULL, remote_fname, &page_spec)) {
4168 sprintf(gszMsgBox, TgLoadString(STID_INVALID_REMOTE_FNAME), file_name);
4169 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4170 rc = BAD;
4171 } else {
4172 int is_html=FALSE;;
4173
4174 SaveStatusStrings();
4175 rc = LoadRemoteFileInMem(remote_fname, &remote_buf, NULL,
4176 &remote_buf_sz, &is_html, TRUE, NULL, 0);
4177 RestoreStatusStrings();
4178 if (rc && remote_buf != NULL) {
4179 if ((tmp_remote_fname=WriteRemoteFileIntoTemp(remote_buf,
4180 remote_buf_sz, NULL)) != NULL) {
4181 file_is_remote = TRUE;
4182 } else {
4183 rc = FALSE;
4184 }
4185 }
4186 }
4187 if (!file_is_remote) {
4188 if (remote_buf != NULL) FreeRemoteBuf(remote_buf);
4189 return rc;
4190 }
4191 } else {
4192 int gzipped=FALSE;
4193
4194 if (FileNameHasExtension(file_name, OBJ_FILE_TYPE, &gzipped, NULL) &&
4195 gzipped) {
4196 char *tmp_fname=NULL;
4197
4198 if ((tmp_fname=GunzipFileIntoTemp(file_name)) == NULL) {
4199 return BAD;
4200 } else {
4201 strcpy(gzipped_fname, file_name);
4202 strcpy(file_name, tmp_fname);
4203 free(tmp_fname);
4204 }
4205 }
4206 }
4207 XSync(mainDisplay, False);
4208 if (XCheckMaskEvent(mainDisplay, ExposureMask, &ev)) {
4209 ExposeEventHandler(&ev, TRUE);
4210 }
4211 if (file_is_remote) {
4212 if ((fp=fopen(tmp_remote_fname, "r")) == NULL) {
4213 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_READ_TMP_FILE),
4214 tmp_remote_fname);
4215 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4216 unlink(tmp_remote_fname);
4217 FreeRemoteBuf(remote_buf);
4218 FreeRemoteBuf(tmp_remote_fname);
4219 /* temporary problem */
4220 return FALSE;
4221 }
4222 } else {
4223 if (*gzipped_fname == '\0') {
4224 if ((short_name=IsPrefix(bootDir, file_name, &rest))) ++rest;
4225 } else {
4226 if ((short_name=IsPrefix(bootDir, gzipped_fname, &rest))) ++rest;
4227 }
4228 if ((fp=fopen(file_name, "r")) == NULL) {
4229 if (short_name) {
4230 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_IMPORT_FILE), rest);
4231 } else {
4232 if (*gzipped_fname == '\0') {
4233 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_IMPORT_FILE),
4234 file_name);
4235 } else {
4236 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_IMPORT_FILE),
4237 gzipped_fname);
4238 }
4239 }
4240 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4241 if (*gzipped_fname != '\0') unlink(file_name);
4242 /* temporary problem -- may be the file does not exist yet */
4243 return FALSE;
4244 }
4245 }
4246 strcpy(tmp_filefullpath, scanFileFullPath);
4247 strcpy(tmp_filename, scanFileName);
4248 tmp_linenum = scanLineNum;
4249 UtilStrCpyN(scanFileFullPath, sizeof(scanFileFullPath), file_name);
4250 if (file_is_remote) {
4251 strcpy(scanFileName, tmp_remote_fname);
4252 } else {
4253 strcpy(scanFileName, (short_name ? rest : file_name));
4254 }
4255 scanLineNum = 0;
4256
4257 saved_top_obj = topObj;
4258 saved_bot_obj = botObj;
4259 curPage->top = curPage->bot = topObj = botObj = NULL;
4260
4261 if (file_is_remote) {
4262 sprintf(gszMsgBox, TgLoadCachedString(CSTID_IMPORTING_FILE),
4263 remote_fname);
4264 } else {
4265 if (short_name) {
4266 sprintf(gszMsgBox, TgLoadCachedString(CSTID_IMPORTING_FILE), rest);
4267 } else {
4268 if (*gzipped_fname == '\0') {
4269 sprintf(gszMsgBox, TgLoadCachedString(CSTID_IMPORTING_FILE),
4270 file_name);
4271 } else {
4272 sprintf(gszMsgBox, TgLoadCachedString(CSTID_IMPORTING_FILE),
4273 gzipped_fname);
4274 }
4275 }
4276 }
4277 Msg(gszMsgBox);
4278
4279 SetWatchCursor(drawWindow);
4280 SetWatchCursor(mainWindow);
4281
4282 numRedrawBBox = 0;
4283 readingPageNum = loadedCurPageNum = 0;
4284 foundGoodStateObject = FALSE;
4285 ShowInterrupt(1);
4286 interrupted = FALSE;
4287 importingPageNum = (-1);
4288 *importingPageName = '\0';
4289 if (page_spec != NULL) {
4290 if (*page_spec == '#') {
4291 importingPageNum = atoi(&page_spec[1]);
4292 if (importingPageNum < 1) {
4293 importingPageNum = (-1);
4294 sprintf(gszMsgBox, TgLoadString(STID_INVALID_PAGE_NUM), page_spec);
4295 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4296 }
4297 } else {
4298 strcpy(importingPageName, page_spec);
4299 }
4300 }
4301 if (importingPageNum == (-1) && *importingPageName == '\0') {
4302 while (!interrupted && (read_status=ReadObj(fp, &obj_ptr)) == TRUE) {
4303 if (obj_ptr != NULL) {
4304 obj_ptr->tmp_parent = NULL;
4305 AdjForOldVersion(obj_ptr);
4306 UnlockAnObj(obj_ptr);
4307 AddObj(NULL, topObj, obj_ptr);
4308 if (!interrupted &&
4309 (PointInBBox(obj_ptr->x, obj_ptr->y, drawWinBBox) ||
4310 BBoxIntersect(obj_ptr->bbox, drawWinBBox))) {
4311 if (!DrawObj(drawWindow, obj_ptr)) interrupted = TRUE;
4312 if (CheckInterrupt(TRUE)) interrupted = TRUE;
4313 }
4314 }
4315 }
4316 } else if (importingPageNum == (-1)) {
4317 while (!interrupted && (read_status=ReadObj(fp, &obj_ptr)) == TRUE) {
4318 if (obj_ptr != NULL) {
4319 obj_ptr->tmp_parent = NULL;
4320 if (importingPageNum == (-1)) {
4321 FreeObj(obj_ptr);
4322 if (!interrupted && CheckInterrupt(TRUE)) interrupted = TRUE;
4323 } else {
4324 AdjForOldVersion(obj_ptr);
4325 UnlockAnObj(obj_ptr);
4326 AddObj(NULL, topObj, obj_ptr);
4327 if (!interrupted &&
4328 (PointInBBox(obj_ptr->x, obj_ptr->y, drawWinBBox) ||
4329 BBoxIntersect(obj_ptr->bbox, drawWinBBox))) {
4330 if (!DrawObj(drawWindow, obj_ptr)) interrupted = TRUE;
4331 if (CheckInterrupt(TRUE)) interrupted = TRUE;
4332 }
4333 }
4334 }
4335 }
4336 } else {
4337 while (!interrupted && (read_status=ReadObj(fp, &obj_ptr)) == TRUE) {
4338 if (obj_ptr != NULL) {
4339 obj_ptr->tmp_parent = NULL;
4340 if (importingPageNum != readingPageNum) {
4341 FreeObj(obj_ptr);
4342 if (!interrupted && CheckInterrupt(TRUE)) interrupted = TRUE;
4343 } else {
4344 AdjForOldVersion(obj_ptr);
4345 UnlockAnObj(obj_ptr);
4346 AddObj(NULL, topObj, obj_ptr);
4347 if (!interrupted &&
4348 (PointInBBox(obj_ptr->x, obj_ptr->y, drawWinBBox) ||
4349 BBoxIntersect(obj_ptr->bbox, drawWinBBox))) {
4350 if (!DrawObj(drawWindow, obj_ptr)) interrupted = TRUE;
4351 if (CheckInterrupt(TRUE)) interrupted = TRUE;
4352 }
4353 }
4354 }
4355 }
4356 }
4357 if (!PRTGIF && colorLayers && needToRedrawColorWindow) {
4358 RedrawColorWindow();
4359 }
4360 if (interrupted) {
4361 MsgBox(TgLoadString(STID_USER_INTR_ABORT_DRAW), TOOL_NAME, INFO_MB);
4362 }
4363 HideInterrupt();
4364
4365 if (fp != NULL) fclose(fp);
4366 if (*gzipped_fname != '\0') {
4367 unlink(file_name);
4368 strcpy(file_name, gzipped_fname);
4369 }
4370 strcpy(scanFileFullPath, tmp_filefullpath);
4371 strcpy(scanFileName, tmp_filename);
4372 scanLineNum = tmp_linenum;
4373
4374 if (read_status == INVALID) {
4375 if (fileVersion > CUR_VERSION) {
4376 sprintf(gszMsgBox, TgLoadString(STID_FILE_VER_ABORT_IMPORT),
4377 fileVersion, TOOL_NAME, homePageURL);
4378 } else {
4379 sprintf(gszMsgBox, TgLoadString(STID_FILE_CORRUPTED_ABORT_IMPORT));
4380 }
4381 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4382 SetDefaultCursor(mainWindow);
4383 ShowCursor();
4384 if (file_is_remote) {
4385 unlink(tmp_remote_fname);
4386 FreeRemoteBuf(remote_buf);
4387 FreeRemoteBuf(tmp_remote_fname);
4388 }
4389 /* temporary problem -- may be the file will be fixed later */
4390 return FALSE;
4391 }
4392 if (file_is_remote) {
4393 if (!foundGoodStateObject) PasteString(remote_buf, TRUE, TRUE);
4394
4395 unlink(tmp_remote_fname);
4396 FreeRemoteBuf(remote_buf);
4397 FreeRemoteBuf(tmp_remote_fname);
4398 }
4399
4400 if (topObj != NULL) SetFileModified(TRUE);
4401 justDupped = FALSE;
4402
4403 if (group_and_lock && topObj != NULL) {
4404 if (topObj != botObj || topObj->type==OBJ_POLY ||
4405 topObj->type==OBJ_POLYGON) {
4406 struct ObjRec *top_obj=topObj, *bot_obj=botObj;
4407
4408 SelAllObj(FALSE, FALSE);
4409 curPage->top = curPage->bot = topObj = botObj = NULL;
4410 CreateGroupObj(top_obj, bot_obj);
4411 RemoveAllSel();
4412 }
4413 topObj->locked = TRUE;
4414 }
4415 SelAllObj(FALSE, FALSE);
4416
4417 if (botObj != NULL) {
4418 botObj->next = saved_top_obj;
4419 } else {
4420 topObj = saved_top_obj;
4421 }
4422 if (saved_top_obj != NULL) {
4423 saved_top_obj->prev = botObj;
4424 botObj = saved_bot_obj;
4425 }
4426 curPage->top = topObj;
4427 curPage->bot = botObj;
4428
4429 if (!(file_is_remote && !foundGoodStateObject) && topSel != NULL) {
4430 PrepareToRecord(CMD_NEW, NULL, NULL, 0);
4431 RecordCmd(CMD_NEW, NULL, topSel, botSel, numObjSelected);
4432 }
4433 if (highlight) HighLightForward();
4434
4435 if (!importFromLibrary && !file_is_remote && !importingFromExec) {
4436 SetCurImportDir(file_name);
4437 }
4438 if (file_is_remote) {
4439 sprintf(gszMsgBox, TgLoadString(STID_FILE_IMPORTED), remote_fname);
4440 } else {
4441 if (short_name) {
4442 sprintf(gszMsgBox, TgLoadString(STID_FILE_IMPORTED), rest);
4443 } else {
4444 sprintf(gszMsgBox, TgLoadString(STID_FILE_IMPORTED), file_name);
4445 }
4446 }
4447 Msg(gszMsgBox);
4448 SetDefaultCursor(mainWindow);
4449 ShowCursor();
4450 if (page_spec != NULL) free(page_spec);
4451 return TRUE;
4452 }
4453
ImportFile()4454 void ImportFile()
4455 {
4456 char file_name[MAXPATHLENGTH+1];
4457
4458 MakeQuiescent();
4459
4460 importingFile = TRUE;
4461 if (importFromLibrary) {
4462 char name[MAXSTRING+1], path[MAXSTRING+1];
4463
4464 if (SelectFromLibrary(TgLoadString(STID_SEL_AN_OBJ_FILE_TO_IMPORT),
4465 OBJ_FILE_EXT, name, path) == INVALID) {
4466 importingFile = FALSE;
4467 return;
4468 }
4469 sprintf(file_name, "%s%c%s", path, DIR_SEP, name);
4470 } else if (SelectFileNameToImport(
4471 TgLoadString(STID_SEL_AN_OBJ_FILE_TO_IMPORT),
4472 OBJ_FILE_EXT, file_name) == INVALID) {
4473 importingFile = FALSE;
4474 return;
4475 }
4476 ImportGivenFile(file_name, FALSE, TRUE);
4477 importingFile = FALSE;
4478 SetCurChoice(curChoiceBeforeMakeQuiescent);
4479 }
4480
ClearBgColorInfo(nRedraw)4481 int ClearBgColorInfo(nRedraw)
4482 int nRedraw;
4483 {
4484 myFileBgPixel = myFileFgPixel = INVALID;
4485 if (myFileFgColorStr != NULL) {
4486 free(myFileFgColorStr);
4487 myFileFgColorStr = NULL;
4488 }
4489 if (myFileBgColorStr != NULL) {
4490 free(myFileBgColorStr);
4491 myFileBgColorStr = NULL;
4492 XSetWindowBackground(mainDisplay, drawWindow, myBgPixel);
4493 if (nRedraw) {
4494 ClearAndRedrawDrawWindow();
4495 }
4496 RecalcXorPixels();
4497 return TRUE;
4498 }
4499 return FALSE;
4500 }
4501
ClearBgPixmapInfo(nRedraw)4502 int ClearBgPixmapInfo(nRedraw)
4503 int nRedraw;
4504 {
4505 int changed=FALSE;
4506
4507 if (myFileBgGifURL != NULL) {
4508 free(myFileBgGifURL);
4509 myFileBgGifURL = NULL;
4510 changed = TRUE;
4511 }
4512 myFileBgPixmapW = myFileBgPixmapH = (-1);
4513 if (myFileBgPixmap != None) {
4514 XFreePixmap(mainDisplay, myFileBgPixmap);
4515 myFileBgPixmap = None;
4516 XSetWindowBackgroundPixmap(mainDisplay, drawWindow, None);
4517 changed = TRUE;
4518 }
4519 if (changed && nRedraw) {
4520 ClearAndRedrawDrawWindow();
4521 }
4522 return changed;
4523 }
4524
SetFileBgColor()4525 int SetFileBgColor()
4526 /* assumes myFileBgColorStr is set */
4527 {
4528 int new_alloc=FALSE;
4529 int index=QuickFindColorIndex(NULL, myFileBgColorStr, &new_alloc, TRUE);
4530
4531 if (index != INVALID) {
4532 myFileBgPixel = colorPixels[index];
4533 myFileBgColor.pixel = colorPixels[index];
4534 myFileBgColor.red = tgifColors[index].red;
4535 myFileBgColor.green = tgifColors[index].green;
4536 myFileBgColor.blue = tgifColors[index].blue;
4537 XSetWindowBackground(mainDisplay, drawWindow, colorPixels[index]);
4538 RecalcXorPixels();
4539 return TRUE;
4540 }
4541 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_ALLOC_BGCOLOR_USE_DEF),
4542 myFileBgColorStr);
4543 Msg(gszMsgBox);
4544 return FALSE;
4545 }
4546
SetFileFgColor()4547 int SetFileFgColor()
4548 /* assumes myFileFgColorStr is set */
4549 {
4550 int new_alloc=FALSE;
4551 int index=QuickFindColorIndex(NULL, myFileFgColorStr, &new_alloc, TRUE);
4552
4553 if (index != INVALID) {
4554 myFileFgPixel = colorPixels[index];
4555 return TRUE;
4556 }
4557 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_ALLOC_FGCOLOR_USE_DEF),
4558 myFileFgColorStr);
4559 Msg(gszMsgBox);
4560 return FALSE;
4561 }
4562
SetFileBgPixmap()4563 int SetFileBgPixmap()
4564 {
4565 int ok=TRUE;
4566 char tmp_xpm_fname[MAXPATHLENGTH+1];
4567
4568 if (myFileBgGifURL == NULL) return FALSE;
4569
4570 *tmp_xpm_fname = '\0';
4571 if (FileIsRemote(myFileBgGifURL)) {
4572 char tmp_gif_fname[MAXPATHLENGTH+1], *content_type=NULL, *page_spec=NULL;
4573 int is_html=FALSE;
4574
4575 *tmp_gif_fname = '\0';
4576 if (DownloadRemoteFile(myFileBgGifURL, &content_type, &page_spec,
4577 &is_html, tmp_gif_fname, NULL, 0)) {
4578 if (page_spec != NULL || is_html) {
4579 sprintf(gszMsgBox, TgLoadString(STID_INVALID_REMOTE_FNAME),
4580 myFileBgGifURL);
4581 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4582 ok = FALSE;
4583 } else {
4584 SetWatchCursor(drawWindow);
4585 SetWatchCursor(mainWindow);
4586 SaveStatusStrings();
4587 ok = ConvertGifToXpm(tmp_gif_fname, tmp_xpm_fname,
4588 sizeof(tmp_xpm_fname));
4589 RestoreStatusStrings();
4590 SetDefaultCursor(mainWindow);
4591 ShowCursor();
4592 }
4593 } else {
4594 ok = FALSE;
4595 }
4596 if (content_type != NULL) FreeRemoteBuf(content_type);
4597 if (page_spec != NULL) UtilFree(page_spec);
4598 if (*tmp_gif_fname != '\0') unlink(tmp_gif_fname);
4599 } else {
4600 SetWatchCursor(drawWindow);
4601 SetWatchCursor(mainWindow);
4602 SaveStatusStrings();
4603 ok = ConvertGifToXpm(myFileBgGifURL, tmp_xpm_fname,
4604 sizeof(tmp_xpm_fname));
4605 RestoreStatusStrings();
4606 SetDefaultCursor(mainWindow);
4607 ShowCursor();
4608 }
4609 if (ok) {
4610 int image_w, image_h, w, h, ncolors=0;
4611 int chars_per_pixel=0, first_pixel_is_bg=FALSE, *pixels=NULL;
4612 char *color_char=NULL, **color_str=NULL, *xpm_data=NULL;
4613 Pixmap pixmap=None, bitmap=None;
4614 XImage *image=NULL, *bitmap_image=NULL;
4615
4616 SetWatchCursor(drawWindow);
4617 SetWatchCursor(mainWindow);
4618 if (!MyReadPixmapFile(tmp_xpm_fname, &image_w, &image_h, &w, &h, &pixmap,
4619 &image, &bitmap, &bitmap_image, &ncolors, &chars_per_pixel,
4620 &first_pixel_is_bg, &color_char, &color_str, &pixels,
4621 &xpm_data) == BitmapSuccess) {
4622 ok = FALSE;
4623 }
4624 SetDefaultCursor(mainWindow);
4625 ShowCursor();
4626 unlink(tmp_xpm_fname);
4627 if (bitmap != None) XFreePixmap(mainDisplay, bitmap);
4628 if (image != NULL) XDestroyImage(image);
4629 if (bitmap_image != NULL) XDestroyImage(bitmap_image);
4630 if (color_char != NULL) free(color_char);
4631 if (color_str != NULL) {
4632 int i;
4633
4634 for (i=0; i < ncolors; i++) free(color_str[i]);
4635 free(color_str);
4636 }
4637 if (ok) {
4638 myFileBgPixmapW = image_w;
4639 myFileBgPixmapH = image_h;
4640 myFileBgPixmap = pixmap;
4641 XSetWindowBackgroundPixmap(mainDisplay, drawWindow, myFileBgPixmap);
4642 }
4643 }
4644 if (!ok) {
4645 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_SET_BGXPM_TO),
4646 myFileBgGifURL);
4647 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4648 }
4649 return ok;
4650 }
4651
CheckFileAttrsInLoad()4652 void CheckFileAttrsInLoad()
4653 {
4654 struct AttrRec *attr_ptr;
4655 int changed=FALSE;
4656
4657 if ((attr_ptr=FindFileAttrWithName("bg_color=")) != NULL) {
4658 struct AttrRec *fg_attr_ptr;
4659 int ok=TRUE;
4660
4661 if ((fg_attr_ptr=FindFileAttrWithName("fg_color=")) != NULL) {
4662 if (myFileFgColorStr == NULL ||
4663 strcmp(fg_attr_ptr->attr_value.s, myFileFgColorStr) != 0) {
4664 myFileFgColorStr = UtilStrDup(fg_attr_ptr->attr_value.s);
4665 if (myFileFgColorStr == NULL) FailAllocMessage();
4666 if (!SetFileFgColor()) {
4667 ClearBgColorInfo(TRUE);
4668 ok = FALSE;
4669 }
4670 }
4671 }
4672 if (ok && (myFileBgColorStr == NULL ||
4673 strcmp(attr_ptr->attr_value.s, myFileBgColorStr) != 0)) {
4674 myFileBgColorStr = UtilStrDup(attr_ptr->attr_value.s);
4675 if (myFileBgColorStr == NULL) FailAllocMessage();
4676 if (SetFileBgColor()) {
4677 ClearAndRedrawDrawWindow();
4678 } else {
4679 ClearBgColorInfo(TRUE);
4680 }
4681 }
4682 return;
4683 } else {
4684 changed = ClearBgColorInfo(FALSE);
4685 }
4686 /*
4687 * Can't really get this to work because of scrolling and zooming.
4688 */
4689 /*
4690 if ((attr_ptr=FindFileAttrWithName("bg_gif=")) != NULL) {
4691 if (myFileBgGifURL == NULL ||
4692 strcmp(attr_ptr->attr_value.s, myFileBgGifURL) != 0) {
4693 if (myFileBgPixmap != None) XFreePixmap(mainDisplay, myFileBgPixmap);
4694 myFileBgPixmap = None;
4695 myFileBgPixmapW = myFileBgPixmapH = (-1);
4696 if (myFileBgGifURL != NULL) free(myFileBgGifURL);
4697 myFileBgGifURL = UtilStrDup(attr_ptr->attr_value.s);
4698 if (myFileBgGifURL == NULL) FailAllocMessage();
4699 if (SetFileBgPixmap()) {
4700 ClearAndRedrawDrawWindow();
4701 } else {
4702 ClearBgPixmapInfo(TRUE);
4703 }
4704 }
4705 return;
4706 } else {
4707 if (!changed) {
4708 changed = ClearBgPixmapInfo(FALSE);
4709 } else {
4710 ClearBgPixmapInfo(FALSE);
4711 }
4712 }
4713 */
4714 if (changed) {
4715 if (myFileBgPixmap == None) {
4716 XSetWindowBackground(mainDisplay, drawWindow, myBgPixel);
4717 }
4718 ClearAndRedrawDrawWindow();
4719 }
4720 }
4721
LoadFile(FullName,ObjFile,GzippedObjFile)4722 int LoadFile(FullName, ObjFile, GzippedObjFile)
4723 char *FullName;
4724 int ObjFile; /* equals TRUE if the file is an OBJ file */
4725 /* equals FALSE if the file is a SYM or PIN file */
4726 /* equals -1 if the file is an temporary OBJ file */
4727 {
4728 struct ObjRec *obj_ptr=NULL;
4729 char tmp_filename[MAXPATHLENGTH+1], tmp_filefullpath[MAXPATHLENGTH+1];
4730 char file_name[MAXPATHLENGTH+1], saved_cur_dir[MAXPATHLENGTH+1], *rest=NULL;
4731 char gzipped_fname[MAXPATHLENGTH+1];
4732 int read_status=0, short_name=FALSE, tmp_linenum=0, interrupted=FALSE;
4733 int done_clear_all_wb=FALSE;
4734 FILE *fp=NULL;
4735 XEvent ev;
4736
4737 *gzipped_fname = '\0';
4738 if (ObjFile != FALSE) {
4739 strcpy(saved_cur_dir, curDir);
4740 } else {
4741 strcpy(saved_cur_dir, curSymDir);
4742 }
4743 if (GzippedObjFile) {
4744 char *tmp_fname=NULL;
4745
4746 if ((tmp_fname=GunzipFileIntoTemp(FullName)) == NULL) {
4747 return FALSE;
4748 } else {
4749 strcpy(gzipped_fname, FullName);
4750 strcpy(file_name, tmp_fname);
4751 free(tmp_fname);
4752 }
4753 } else {
4754 strcpy(file_name, FullName);
4755 }
4756 if (*gzipped_fname == '\0') {
4757 if ((short_name=IsPrefix(bootDir, file_name, &rest))) ++rest;
4758 } else {
4759 if ((short_name=IsPrefix(bootDir, gzipped_fname, &rest))) ++rest;
4760 }
4761 if ((fp=fopen(file_name, "r")) == NULL) {
4762 if (short_name) {
4763 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING),
4764 rest);
4765 } else {
4766 if (*gzipped_fname == '\0') {
4767 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING),
4768 file_name);
4769 } else {
4770 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING),
4771 gzipped_fname);
4772 }
4773 }
4774 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4775 if (*gzipped_fname != '\0') unlink(file_name);
4776 return FALSE;
4777 }
4778 if (!navigatingBackAndForth) BeforeNavigate();
4779
4780 ClearFileInfo(TRUE);
4781 if (usePaperSizeStoredInFile) ResetOnePageSize();
4782
4783 strcpy(tmp_filefullpath, scanFileFullPath);
4784 strcpy(tmp_filename, scanFileName);
4785 tmp_linenum = scanLineNum;
4786 UtilStrCpyN(scanFileFullPath, sizeof(scanFileFullPath), FullName);
4787 strcpy(scanFileName, (short_name ? rest : file_name));
4788 scanLineNum = 0;
4789
4790 TieLooseEnds();
4791 CleanUpDrawingWindow();
4792 SetFileModified(FALSE);
4793
4794 XSync(mainDisplay, False);
4795 while (XCheckWindowEvent(mainDisplay, drawWindow, ExposureMask, &ev)) ;
4796
4797 SaveStatusStrings();
4798
4799 if (short_name) {
4800 sprintf(gszMsgBox, TgLoadCachedString(CSTID_LOADING_FILE), rest);
4801 } else {
4802 if (*gzipped_fname == '\0') {
4803 sprintf(gszMsgBox, TgLoadCachedString(CSTID_LOADING_FILE), file_name);
4804 } else {
4805 sprintf(gszMsgBox, TgLoadCachedString(CSTID_LOADING_FILE),
4806 gzipped_fname);
4807 }
4808 }
4809 SetStringStatus(gszMsgBox);
4810 SetWatchCursor(drawWindow);
4811 SetWatchCursor(mainWindow);
4812
4813 if (flushColormapOnOpen) {
4814 if (FlushColormap()) {
4815 Msg(TgLoadString(STID_COLORMAP_FLUSHED));
4816 }
4817 }
4818 XClearWindow(mainDisplay, drawWindow);
4819 somethingHighLighted = FALSE;
4820
4821 numRedrawBBox = 0;
4822 ShowInterrupt(1);
4823 interrupted = FALSE;
4824 readingPageNum = loadedCurPageNum = 0;
4825 foundGoodStateObject = FALSE;
4826 while ((read_status=ReadObj(fp, &obj_ptr)) == TRUE) {
4827 if (foundGoodStateObject && !done_clear_all_wb) {
4828 done_clear_all_wb = TRUE;
4829 if (gstWBInfo.do_whiteboard) {
4830 RecordWBClearAll();
4831 }
4832 }
4833 if (obj_ptr != NULL) {
4834 obj_ptr->tmp_parent = NULL;
4835 AdjForOldVersion(obj_ptr);
4836 AddObj(NULL, topObj, obj_ptr);
4837 if (!interrupted && readingPageNum == loadedCurPageNum &&
4838 (PointInBBox(obj_ptr->x, obj_ptr->y, drawWinBBox) ||
4839 BBoxIntersect(obj_ptr->bbox, drawWinBBox))) {
4840 if (!DrawObj(drawWindow, obj_ptr)) interrupted = TRUE;
4841 if (CheckInterrupt(TRUE)) interrupted = TRUE;
4842 }
4843 }
4844 }
4845 fclose(fp);
4846 if (*gzipped_fname != '\0') unlink(file_name);
4847
4848 if (!PRTGIF && colorLayers && needToRedrawColorWindow) {
4849 RedrawColorWindow();
4850 }
4851 if (interrupted) {
4852 MsgBox(TgLoadString(STID_USER_INTR_ABORT_DRAW), TOOL_NAME, INFO_MB);
4853 }
4854 HideInterrupt();
4855
4856 strcpy(scanFileFullPath, tmp_filefullpath);
4857 strcpy(scanFileName, tmp_filename);
4858 scanLineNum = tmp_linenum;
4859
4860 if (read_status == INVALID) {
4861 if (fileVersion > CUR_VERSION) {
4862 sprintf(gszMsgBox, TgLoadString(STID_FILE_VER_ABORT_OPEN),
4863 fileVersion, TOOL_NAME, homePageURL);
4864 } else {
4865 sprintf(gszMsgBox, TgLoadString(STID_FILE_CORRUPTED_ABORT_OPEN));
4866 }
4867 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
4868 DrawPaperBoundary(drawWindow);
4869 RedrawGridLines(drawWindow);
4870 SetDefaultCursor(mainWindow);
4871 ShowCursor();
4872
4873 RestoreStatusStrings();
4874
4875 return FALSE;
4876 }
4877 if (ObjFile == TRUE) {
4878 if (*gzipped_fname == '\0') {
4879 SetCurDir(file_name);
4880 } else {
4881 SetCurDir(gzipped_fname);
4882 }
4883 *curSymDir = '\0';
4884 } else if (ObjFile == FALSE) {
4885 SetCurSymDir(file_name);
4886 }
4887 curFileDefined = TRUE;
4888
4889 if (loadedCurPageNum > 0 && curPage != NULL) {
4890 GotoPageNum(loadedCurPageNum);
4891 }
4892 CheckFileAttrsInLoad();
4893
4894 if (loadedCurPageNum <= 0 || curPage == NULL) {
4895 DelAllPages();
4896 loadedCurPageNum = curPageNum = lastPageNum = 1;
4897 InitPage();
4898 DrawPaperBoundary(drawWindow);
4899 RedrawGridLines(drawWindow);
4900 RedrawPageLines(drawWindow);
4901 RedrawChoiceWindow();
4902 }
4903
4904 if (ObjFile != FALSE) {
4905 if (strcmp(saved_cur_dir, curDir) != 0 && DirInSymPath(".")) {
4906 UpdateSymInfo();
4907 }
4908 } else {
4909 if (strcmp(saved_cur_dir, curSymDir) != 0 && DirInSymPath(".")) {
4910 UpdateSymInfo();
4911 }
4912 }
4913
4914 if (short_name) {
4915 sprintf(gszMsgBox, TgLoadCachedString(CSTID_CUR_FILE_IS), rest);
4916 } else {
4917 sprintf(gszMsgBox, TgLoadCachedString(CSTID_CUR_FILE_IS),
4918 (*gzipped_fname == '\0' ? file_name : gzipped_fname));
4919 }
4920 Msg(gszMsgBox);
4921 RestoreStatusStrings();
4922
4923 RedrawTitleWindow();
4924 justDupped = FALSE;
4925 SetDefaultCursor(mainWindow);
4926 RedrawHRulerWindow();
4927 ShowCursor();
4928
4929 if (!gstWBInfo.do_whiteboard) {
4930 CleanUpCmds();
4931 }
4932 UpdateAllPinnedMenus();
4933
4934 if (!navigatingBackAndForth && !PRTGIF) CommitNavigate();
4935 return foundGoodStateObject;
4936 }
4937
DumpPatFill(FP,Fill,BBox,Indent,EndOfLine)4938 void DumpPatFill(FP, Fill, BBox, Indent, EndOfLine)
4939 FILE *FP;
4940 int Fill, Indent, EndOfLine;
4941 struct BBRec BBox;
4942 {
4943 int ltx=0, lty=0, rbx=0, rby=0, cellw=0, cellh=0;
4944 struct BBRec bbox;
4945
4946 GetPatternCellsize(Fill, &cellw, &cellh);
4947 if ((cellw&0x7) != 0) {
4948 sprintf(gszMsgBox, "cellw = %1d in DumpPatFill()\n", cellw);
4949 TgAssert(FALSE, gszMsgBox, NULL);
4950 }
4951 /* if ((cellw % 8) != 0) cellw += (8-(cellw%8)); */
4952
4953 bbox.ltx = BBox.ltx-1; bbox.lty = BBox.lty-1;
4954 bbox.rbx = BBox.rbx+1; bbox.rby = BBox.rby+1;
4955
4956 ltx = ((bbox.ltx % cellw) == 0) ? bbox.ltx :
4957 ((bbox.ltx > 0) ? ((int)(bbox.ltx / cellw))*cellw :
4958 ((int)(bbox.ltx / cellw)-1)*cellw);
4959 lty = ((bbox.lty % cellh) == 0) ? bbox.lty :
4960 ((bbox.lty > 0) ? ((int)(bbox.lty / cellh))*cellh :
4961 ((int)(bbox.lty / cellh)-1)*cellh);
4962 rbx = ((bbox.rbx % cellw) == 0) ? bbox.rbx :
4963 ((bbox.rbx > 0) ? ((int)(bbox.rbx / cellw)+1)*cellw :
4964 ((int)(bbox.rbx / cellw))*cellw);
4965 rby = ((bbox.rby % cellh) == 0) ? bbox.rby :
4966 ((bbox.rby > 0) ? ((int)(bbox.rby / cellh)+1)*cellh :
4967 ((int)(bbox.rby / cellh))*cellh);
4968
4969 if (fprintf(FP, "%spat%1d %1d %1d %1d %1d %1d %1d TGPF%s",
4970 GetIndentString(Indent), Fill, cellw, cellh,
4971 ltx, lty, rbx-ltx, rby-lty, (EndOfLine?"\n":"")) == EOF) {
4972 writeFileFailed = TRUE;
4973 }
4974 }
4975
DumpSymOutline(FP,ObjPtr)4976 void DumpSymOutline(FP, ObjPtr)
4977 FILE *FP;
4978 register struct ObjRec *ObjPtr;
4979 {
4980 int ltx, lty, rbx, rby;
4981
4982 ltx = ObjPtr->obbox.ltx - QUARTER_INCH + 1;
4983 lty = ObjPtr->obbox.lty - QUARTER_INCH + 1;
4984 rbx = ObjPtr->obbox.rbx + QUARTER_INCH - 1;
4985 rby = ObjPtr->obbox.rby + QUARTER_INCH - 1;
4986
4987 fprintf(FP, "%s\n", gPsCmd[PS_GSAVE]);
4988 fprintf(FP, " 0 %s\n", gPsCmd[PS_SETGRAY]);
4989 fprintf(FP, " [4 4] 0 %s\n", gPsCmd[PS_SETDASH]);
4990 fprintf(FP, " %s\n %1d %1d %s ",
4991 gPsCmd[PS_NEWPATH], ltx, lty, gPsCmd[PS_MOVETO]);
4992 fprintf(FP, "%1d %1d %s ", rbx, lty, gPsCmd[PS_LINETO]);
4993 fprintf(FP, "%1d %1d %s ", rbx, rby, gPsCmd[PS_LINETO]);
4994 fprintf(FP, "%1d %1d %s\n", ltx, rby, gPsCmd[PS_LINETO]);
4995 fprintf(FP, " %s %s\n", gPsCmd[PS_CLOSEPATH], gPsCmd[PS_STROKE]);
4996 fprintf(FP, "%s\n", gPsCmd[PS_GRESTORE]);
4997 }
4998
4999 static int printingFirstPageNum=1;
5000 static int printingPageNum=1, printingPageRow=1, printingPageCol=1;
5001 static int printingLastPageNum=0;
5002 static int dumpOnePageInTileMode=FALSE;
5003 static int dumpOnePageInStackMode=FALSE;
5004 static int dumpPages=FALSE;
5005 static int dumpPageNum=0;
5006
5007 static FILE *dumpFP=NULL;
5008 static char tmpFile[MAXSTRING+1];
5009 static int llxTotal=0, llyTotal=0, urxTotal=0, uryTotal=0;
5010 static int totalBBoxValid=FALSE;
5011
5012 static int msgAboutTiledPageScalingSeen=FALSE;
5013
5014 static
DumpAttrs(FP,AttrPtr)5015 void DumpAttrs(FP, AttrPtr)
5016 FILE *FP;
5017 register struct AttrRec *AttrPtr;
5018 {
5019 for ( ; AttrPtr != NULL; AttrPtr=AttrPtr->prev) {
5020 if (!AttrPtr->shown) {
5021 continue;
5022 }
5023 /* do not translate -- program constants */
5024 if (!AttrPtr->nameshown && *AttrPtr->attr_name.s == '!' &&
5025 strcmp(AttrPtr->attr_name.s, "!PAGE_NUM=") == 0) {
5026 if (pageLayoutMode == PAGE_STACK) {
5027 MiniLineInfo *pMiniLine=AttrPtr->obj->detail.t->minilines.first;
5028 char *c_ptr;
5029
5030 if (pMiniLine != NULL &&
5031 pMiniLine->first_block == pMiniLine->last_block &&
5032 (strstr(pMiniLine->first_block->seg->dyn_str.s,
5033 "!(STACKED_PAGE_NUM)") != NULL ||
5034 strstr(pMiniLine->first_block->seg->dyn_str.s,
5035 "!(STACKED_NUM_PAGES)") != NULL)) {
5036 char *psz_saved=NULL, *c_ptr1=NULL;
5037 int page_num_str_len=strlen("!(STACKED_PAGE_NUM)");
5038 int num_pages_str_len=strlen("!(STACKED_NUM_PAGES)");
5039
5040 psz_saved = UtilStrDup(pMiniLine->first_block->seg->dyn_str.s);
5041 if (psz_saved == NULL) FailAllocMessage();
5042 while ((c_ptr=strstr(pMiniLine->first_block->seg->dyn_str.s,
5043 "!(STACKED_PAGE_NUM)")) != NULL) {
5044 c_ptr1 = &c_ptr[page_num_str_len];
5045 sprintf(c_ptr, "%1d", printingPageNum);
5046 c_ptr = &c_ptr[strlen(c_ptr)];
5047 while (*c_ptr1 != '\0') *c_ptr++ = *c_ptr1++;
5048 *c_ptr = '\0';
5049 }
5050 while ((c_ptr=strstr(pMiniLine->first_block->seg->dyn_str.s,
5051 "!(STACKED_NUM_PAGES)")) != NULL) {
5052 c_ptr1 = &c_ptr[num_pages_str_len];
5053 sprintf(c_ptr, "%1d", lastPageNum);
5054 c_ptr = &c_ptr[strlen(c_ptr)];
5055 while (*c_ptr1 != '\0') *c_ptr++ = *c_ptr1++;
5056 *c_ptr = '\0';
5057 }
5058 DumpTextObj(FP, AttrPtr->obj);
5059 DynStrSet(&pMiniLine->first_block->seg->dyn_str, psz_saved);
5060 UtilFree(psz_saved);
5061 } else {
5062 DumpTextObj(FP, AttrPtr->obj);
5063 }
5064 } else {
5065 /* pageLayoutMode == PAGE_TILE */
5066 MiniLineInfo *pMiniLine=AttrPtr->obj->detail.t->minilines.first;
5067 char *c_ptr=NULL;
5068
5069 if (pMiniLine != NULL) {
5070 char *psz_saved=NULL, *c_ptr1=NULL, *c_ptr2=NULL;
5071
5072 psz_saved = UtilStrDup(pMiniLine->first_block->seg->dyn_str.s);
5073 if (psz_saved == NULL) FailAllocMessage();
5074 for (c_ptr=pMiniLine->first_block->seg->dyn_str.s;
5075 *c_ptr != '\0'; c_ptr++) {
5076 int len=strlen("!(TILED_PAGE_ROW)");
5077
5078 if (*c_ptr == '!' &&
5079 (strncmp(c_ptr, "!(TILED_PAGE_ROW)", len) == 0 ||
5080 strncmp(c_ptr, "!(TILED_PAGE_COL)", len) == 0)) {
5081 if (strncmp(c_ptr, "!(TILED_PAGE_ROW)", len) == 0) {
5082 sprintf(c_ptr, "%1d", printingPageRow);
5083 } else {
5084 sprintf(c_ptr, "%1d", printingPageCol);
5085 }
5086 c_ptr1 = &c_ptr[len];
5087 c_ptr = c_ptr2 = &c_ptr[strlen(c_ptr)];
5088 while (*c_ptr1 != '\0') *c_ptr2++ = *c_ptr1++;
5089 *c_ptr2 = '\0';
5090 c_ptr--;
5091 }
5092 }
5093 DumpTextObj(FP, AttrPtr->obj);
5094 DynStrSet(&pMiniLine->first_block->seg->dyn_str, psz_saved);
5095 UtilFree(psz_saved);
5096 } else {
5097 DumpTextObj(FP, AttrPtr->obj);
5098 }
5099 }
5100 } else {
5101 DumpTextObj(FP, AttrPtr->obj);
5102 }
5103 }
5104 }
5105
5106 static
DumpAnObj(FP,ObjPtr)5107 void DumpAnObj(FP, ObjPtr)
5108 FILE *FP;
5109 register struct ObjRec *ObjPtr;
5110 {
5111 switch (ObjPtr->type) {
5112 case OBJ_POLY:
5113 if (!colorLayers ||
5114 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5115 DumpPolyObj(FP, ObjPtr);
5116 DumpAttrs(FP, ObjPtr->lattr);
5117 }
5118 break;
5119 case OBJ_BOX:
5120 if (!colorLayers ||
5121 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5122 DumpBoxObj(FP, ObjPtr);
5123 DumpAttrs(FP, ObjPtr->lattr);
5124 }
5125 break;
5126 case OBJ_OVAL:
5127 if (!colorLayers ||
5128 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5129 DumpOvalObj(FP, ObjPtr);
5130 DumpAttrs(FP, ObjPtr->lattr);
5131 }
5132 break;
5133 case OBJ_TEXT:
5134 if (!colorLayers ||
5135 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5136 DumpTextObj(FP, ObjPtr);
5137 }
5138 break;
5139 case OBJ_POLYGON:
5140 if (!colorLayers ||
5141 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5142 DumpPolygonObj(FP, ObjPtr);
5143 DumpAttrs(FP, ObjPtr->lattr);
5144 }
5145 break;
5146 case OBJ_ARC:
5147 if (!colorLayers ||
5148 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5149 DumpArcObj(FP, ObjPtr);
5150 DumpAttrs(FP, ObjPtr->lattr);
5151 }
5152 break;
5153 case OBJ_RCBOX:
5154 if (!colorLayers ||
5155 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5156 DumpRCBoxObj(FP, ObjPtr);
5157 DumpAttrs(FP, ObjPtr->lattr);
5158 }
5159 break;
5160 case OBJ_XBM:
5161 if (!colorLayers ||
5162 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5163 DumpXBmObj(FP, ObjPtr);
5164 DumpAttrs(FP, ObjPtr->lattr);
5165 }
5166 break;
5167 case OBJ_XPM:
5168 if (!colorLayers ||
5169 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5170 DumpXPmObj(FP, ObjPtr);
5171 DumpAttrs(FP, ObjPtr->lattr);
5172 }
5173 break;
5174 case OBJ_SYM:
5175 case OBJ_ICON:
5176 case OBJ_GROUP:
5177 if (!colorLayers ||
5178 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5179 struct ObjRec *obj_ptr=ObjPtr->detail.r->last;
5180
5181 for ( ; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
5182 obj_ptr->tmp_parent = ObjPtr;
5183 DumpAnObj(FP, obj_ptr);
5184 }
5185 DumpAttrs(FP, ObjPtr->lattr);
5186 if (ObjPtr->type == OBJ_SYM) DumpSymOutline(FP, ObjPtr);
5187 }
5188 break;
5189 case OBJ_PIN:
5190 if (!colorLayers ||
5191 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5192 struct ObjRec *obj_ptr=GetPinObj(ObjPtr);
5193
5194 obj_ptr->tmp_parent = ObjPtr;
5195 DumpAnObj(FP, obj_ptr);
5196
5197 DumpAttrs(FP, ObjPtr->lattr);
5198 }
5199 break;
5200 }
5201 }
5202
5203 static int llxPage=0, llyPage=0, urxPage=0, uryPage=0;
5204 static int minimalEPS=INVALID;
5205
5206 #define ALL_BBOX 0
5207 #define PAGE_BBOX 1
5208
DumpBBox(fp,page_only,page_bbox)5209 int DumpBBox(fp, page_only, page_bbox)
5210 FILE *fp;
5211 int page_only;
5212 struct BBRec *page_bbox;
5213 {
5214 struct ObjRec *obj_ptr=NULL;
5215 int ltx=0, lty=0, rbx=0, rby=0, rc=TRUE;
5216 double llx1=0, lly1=0, urx1=0, ury1=0;
5217
5218 if ((obj_ptr = topObj) == NULL) {
5219 ltx = lty = rbx = rby = 0;
5220 if (!(pageLayoutMode == PAGE_STACK &&
5221 printingFirstPageNum != printingLastPageNum)) {
5222 strcpy(gszMsgBox, TgLoadString(STID_WARN_PS_BBOX_EMPTY));
5223 if (PRTGIF) {
5224 fprintf(stderr, "%s\n", gszMsgBox);
5225 } else {
5226 Msg(gszMsgBox);
5227 }
5228 }
5229 rc = FALSE;
5230 } else if (pageLayoutMode == PAGE_STACK || page_bbox == NULL) {
5231 ltx = obj_ptr->bbox.ltx; lty = obj_ptr->bbox.lty;
5232 rbx = obj_ptr->bbox.rbx; rby = obj_ptr->bbox.rby;
5233
5234 for (obj_ptr=topObj->next; obj_ptr != NULL; obj_ptr=obj_ptr->next) {
5235 if (obj_ptr->bbox.ltx < ltx) ltx = obj_ptr->bbox.ltx;
5236 if (obj_ptr->bbox.lty < lty) lty = obj_ptr->bbox.lty;
5237 if (obj_ptr->bbox.rbx > rbx) rbx = obj_ptr->bbox.rbx;
5238 if (obj_ptr->bbox.rby > rby) rby = obj_ptr->bbox.rby;
5239 }
5240 } else {
5241 int found=FALSE;
5242
5243 for (obj_ptr=botObj; obj_ptr != NULL; obj_ptr=obj_ptr->prev) {
5244 if (Inside(obj_ptr->bbox, *page_bbox) ||
5245 BBoxIntersect(obj_ptr->bbox, *page_bbox)) {
5246 if (found) {
5247 if (obj_ptr->bbox.ltx < ltx) ltx = obj_ptr->bbox.ltx;
5248 if (obj_ptr->bbox.lty < lty) lty = obj_ptr->bbox.lty;
5249 if (obj_ptr->bbox.rbx > rbx) rbx = obj_ptr->bbox.rbx;
5250 if (obj_ptr->bbox.rby > rby) rby = obj_ptr->bbox.rby;
5251 } else {
5252 found = TRUE;
5253 ltx = obj_ptr->bbox.ltx; lty = obj_ptr->bbox.lty;
5254 rbx = obj_ptr->bbox.rbx; rby = obj_ptr->bbox.rby;
5255 }
5256 }
5257 }
5258 if (!found) {
5259 rc = FALSE;
5260 ltx = lty = rbx = rby = 0;
5261 } else if (page_bbox != NULL) {
5262 struct BBRec bbox, bbox1;
5263
5264 bbox.ltx = ltx; bbox.lty = lty; bbox.rbx = rbx; bbox.rby = rby;
5265 if (IntersectRect(bbox, *page_bbox, &bbox1)) {
5266 ltx = bbox1.ltx-page_bbox->ltx; lty = bbox1.lty-page_bbox->lty;
5267 rbx = bbox1.rbx-page_bbox->ltx; rby = bbox1.rby-page_bbox->lty;
5268 }
5269 }
5270 }
5271 switch (pageStyle) {
5272 case PORTRAIT:
5273 llx1 = (double)(1.0*ltx*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5274 psXOff[pageStyle]*psDotsPerInch);
5275 lly1 = (double)(-1.0*rby*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5276 psYOff[pageStyle]*psDotsPerInch);
5277 urx1 = (double)(1.0*rbx*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5278 psXOff[pageStyle]*psDotsPerInch);
5279 ury1 = (double)(-1.0*lty*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5280 psYOff[pageStyle]*psDotsPerInch);
5281 break;
5282 case LANDSCAPE:
5283 llx1 = (double)(1.0*lty*psDotsPerInch/PIX_PER_INCH*printMag/100 -
5284 psYOff[pageStyle]*psDotsPerInch);
5285 lly1 = (double)(1.0*ltx*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5286 psXOff[pageStyle]*psDotsPerInch);
5287 urx1 = (double)(1.0*rby*psDotsPerInch/PIX_PER_INCH*printMag/100 -
5288 psYOff[pageStyle]*psDotsPerInch);
5289 ury1 = (double)(1.0*rbx*psDotsPerInch/PIX_PER_INCH*printMag/100 +
5290 psXOff[pageStyle]*psDotsPerInch);
5291 break;
5292 default:
5293 fprintf(stderr, TgLoadString(STID_UNRECOG_PAGE_STYLE), pageStyle);
5294 fprintf(stderr, "\n");
5295 break;
5296 }
5297
5298 if (rc) {
5299 llxPage = (llx1 >= 0.0) ? ((int)llx1)-1 : (-((int)(-llx1)))-1;
5300 llyPage = (lly1 >= 0.0) ? ((int)lly1)-1 : (-((int)(-lly1)))-1;
5301 urxPage = (urx1 >= 0.0) ? ((int)urx1)+1 : (-((int)(0.999-urx1)))+1;
5302 uryPage = (ury1 >= 0.0) ? ((int)ury1)+1 : (-((int)(0.999-ury1)))+1;
5303 } else {
5304 llxPage = llyPage = urxPage = uryPage = 0;
5305 }
5306 if (!page_only || !minimalEPS) {
5307 fprintf(fp,"%%%%%sBoundingBox: %1d %1d %1d %1d\n",
5308 (page_only ? "Page" : ""), llxPage, llyPage, urxPage, uryPage);
5309 }
5310 return rc;
5311 }
5312
ModifyOutputFileName(FileName)5313 void ModifyOutputFileName(FileName)
5314 char *FileName;
5315 {
5316 char *psz=NULL, s[MAXPATHLENGTH<<1];
5317
5318 if (*outputDir == '\0') return;
5319
5320 strcpy(s, FileName);
5321 psz = UtilStrRChr(s, DIR_SEP);
5322 if (psz != NULL) {
5323 sprintf(FileName, "%s%c%s", outputDir, DIR_SEP, ++psz);
5324 } else {
5325 sprintf(FileName, "%s%c%s", outputDir, DIR_SEP, s);
5326 }
5327 }
5328
5329 static
DumpTextObjInAscii(FP,ObjPtr)5330 void DumpTextObjInAscii(FP, ObjPtr)
5331 FILE *FP;
5332 register struct ObjRec *ObjPtr;
5333 {
5334 struct TextRec *text_ptr=ObjPtr->detail.t;
5335 MiniLinesInfo *minilines=(&text_ptr->minilines);
5336
5337 if (text_ptr->pen == NONEPAT) return;
5338 DumpMiniLinesInAscii(FP, minilines, &totalBBoxValid);
5339 if (fprintf(FP, "\n") == EOF) writeFileFailed = TRUE;
5340 }
5341
5342 static
DumpAttrsInAscii(FP,AttrPtr)5343 void DumpAttrsInAscii(FP, AttrPtr)
5344 FILE *FP;
5345 register struct AttrRec *AttrPtr;
5346 {
5347 for ( ; AttrPtr != NULL; AttrPtr=AttrPtr->prev) {
5348 if (!AttrPtr->shown) {
5349 continue;
5350 }
5351 /* do not translate -- program constants */
5352 if (!AttrPtr->nameshown && *AttrPtr->attr_name.s == '!' &&
5353 strcmp(AttrPtr->attr_name.s, "!PAGE_NUM=") == 0) {
5354 if (pageLayoutMode == PAGE_STACK) {
5355 MiniLineInfo *pMiniLine=AttrPtr->obj->detail.t->minilines.first;
5356 char *c_ptr;
5357
5358 if (pMiniLine != NULL &&
5359 pMiniLine->first_block == pMiniLine->last_block &&
5360 (strstr(pMiniLine->first_block->seg->dyn_str.s,
5361 "!(STACKED_PAGE_NUM)") != NULL ||
5362 strstr(pMiniLine->first_block->seg->dyn_str.s,
5363 "!(STACKED_NUM_PAGES)") != NULL)) {
5364 char *psz_saved=NULL, *c_ptr1;
5365 int page_num_str_len=strlen("!(STACKED_PAGE_NUM)");
5366 int num_pages_str_len=strlen("!(STACKED_NUM_PAGES)");
5367
5368 psz_saved = UtilStrDup(pMiniLine->first_block->seg->dyn_str.s);
5369 if (psz_saved == NULL) FailAllocMessage();
5370 while ((c_ptr=strstr(pMiniLine->first_block->seg->dyn_str.s,
5371 "!(STACKED_PAGE_NUM)")) != NULL) {
5372 c_ptr1 = &c_ptr[page_num_str_len];
5373 sprintf(c_ptr, "%1d", printingPageNum);
5374 c_ptr = &c_ptr[strlen(c_ptr)];
5375 while (*c_ptr1 != '\0') *c_ptr++ = *c_ptr1++;
5376 *c_ptr = '\0';
5377 }
5378 while ((c_ptr=strstr(pMiniLine->first_block->seg->dyn_str.s,
5379 "!(STACKED_NUM_PAGES)")) != NULL) {
5380 c_ptr1 = &c_ptr[num_pages_str_len];
5381 sprintf(c_ptr, "%1d", lastPageNum);
5382 c_ptr = &c_ptr[strlen(c_ptr)];
5383 while (*c_ptr1 != '\0') *c_ptr++ = *c_ptr1++;
5384 *c_ptr = '\0';
5385 }
5386 DumpTextObjInAscii(FP, AttrPtr->obj);
5387 DynStrSet(&pMiniLine->first_block->seg->dyn_str, psz_saved);
5388 UtilFree(psz_saved);
5389 } else {
5390 DumpTextObjInAscii(FP, AttrPtr->obj);
5391 }
5392 } else {
5393 MiniLineInfo *pMiniLine=AttrPtr->obj->detail.t->minilines.first;
5394 char *c_ptr;
5395
5396 if (pMiniLine != NULL) {
5397 char *psz_saved, *c_ptr1, *c_ptr2;
5398
5399 psz_saved = UtilStrDup(pMiniLine->first_block->seg->dyn_str.s);
5400 if (psz_saved == NULL) FailAllocMessage();
5401 for (c_ptr=pMiniLine->first_block->seg->dyn_str.s;
5402 *c_ptr != '\0'; c_ptr++) {
5403 int len=strlen("!(TILED_PAGE_ROW)");
5404
5405 if (*c_ptr == '!' &&
5406 (strncmp(c_ptr, "!(TILED_PAGE_ROW)", len) == 0 ||
5407 strncmp(c_ptr, "!(TILED_PAGE_COL)", len) == 0)) {
5408 if (strncmp(c_ptr, "!(TILED_PAGE_ROW)", len) == 0) {
5409 sprintf(c_ptr, "%1d", printingPageRow);
5410 } else {
5411 sprintf(c_ptr, "%1d", printingPageCol);
5412 }
5413 c_ptr1 = &c_ptr[len];
5414 c_ptr = c_ptr2 = &c_ptr[strlen(c_ptr)];
5415 while (*c_ptr1 != '\0') *c_ptr2++ = *c_ptr1++;
5416 *c_ptr2 = '\0';
5417 c_ptr--;
5418 }
5419 }
5420 DumpTextObjInAscii(FP, AttrPtr->obj);
5421 DynStrSet(&pMiniLine->first_block->seg->dyn_str, psz_saved);
5422 UtilFree(psz_saved);
5423 } else {
5424 DumpTextObjInAscii(FP, AttrPtr->obj);
5425 }
5426 }
5427 } else {
5428 DumpTextObjInAscii(FP, AttrPtr->obj);
5429 }
5430 }
5431 }
5432
5433 static
DumpAnObjInAscii(FP,ObjPtr)5434 void DumpAnObjInAscii(FP, ObjPtr)
5435 FILE *FP;
5436 register struct ObjRec *ObjPtr;
5437 {
5438 switch (ObjPtr->type) {
5439 case OBJ_POLY:
5440 case OBJ_BOX:
5441 case OBJ_OVAL:
5442 case OBJ_POLYGON:
5443 case OBJ_ARC:
5444 case OBJ_RCBOX:
5445 case OBJ_XBM:
5446 case OBJ_XPM:
5447 if (!colorLayers ||
5448 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5449 DumpAttrsInAscii(FP, ObjPtr->lattr);
5450 }
5451 break;
5452 case OBJ_TEXT:
5453 if (!colorLayers ||
5454 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5455 DumpTextObjInAscii(FP, ObjPtr);
5456 }
5457 break;
5458 case OBJ_SYM:
5459 case OBJ_ICON:
5460 case OBJ_GROUP:
5461 if (!colorLayers ||
5462 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5463 struct ObjRec *obj_ptr=ObjPtr->detail.r->last;
5464
5465 for ( ; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
5466 obj_ptr->tmp_parent = ObjPtr;
5467 DumpAnObjInAscii(FP, obj_ptr);
5468 }
5469 DumpAttrsInAscii(FP, ObjPtr->lattr);
5470 }
5471 break;
5472 case OBJ_PIN:
5473 if (!colorLayers ||
5474 ObjPtr->tmp_parent!=NULL || ObjInVisibleLayer(ObjPtr)) {
5475 struct ObjRec *obj_ptr=GetPinObj(ObjPtr);
5476
5477 obj_ptr->tmp_parent = ObjPtr;
5478 DumpAnObjInAscii(FP, obj_ptr);
5479
5480 DumpAttrsInAscii(FP, ObjPtr->lattr);
5481 }
5482 break;
5483 }
5484 }
5485
5486 static
SetPortName(name,buf,buf_sz,pn_buf_index)5487 int SetPortName(name, buf, buf_sz, pn_buf_index)
5488 char *name, *buf;
5489 int buf_sz, *pn_buf_index;
5490 {
5491 int len=strlen(name)+1, index=(*pn_buf_index);
5492
5493 if (index+len+1 > buf_sz) {
5494 sprintf(gszMsgBox, TgLoadCachedString(CSTID_PORTNAME_TOO_LONG_SKIPPED),
5495 buf);
5496 if (PRTGIF) {
5497 fprintf(stderr, "%s\n", gszMsgBox);
5498 } else {
5499 Msg(gszMsgBox);
5500 }
5501 return FALSE;
5502 }
5503 buf[index] = '!';
5504 strcpy(&buf[index+1], name);
5505 (*pn_buf_index) = index+len;
5506 buf[(*pn_buf_index)] = '\0';
5507
5508 return TRUE;
5509 }
5510
5511 static
DumpNetlListLine(FP,port_name,pMiniLine)5512 void DumpNetlListLine(FP, port_name, pMiniLine)
5513 FILE *FP;
5514 char *port_name;
5515 MiniLineInfo *pMiniLine;
5516 {
5517 int need_to_free_tmp_buf=FALSE;
5518 char *tmp_buf=ConvertMiniLineToString(pMiniLine, &need_to_free_tmp_buf);
5519 char *c_ptr=strchr(tmp_buf, '=');
5520
5521 if (fprintf(FP, "\"%s\",\t\"%s\"\n", port_name, ++c_ptr) == EOF) {
5522 writeFileFailed = TRUE;
5523 }
5524 if (need_to_free_tmp_buf) UtilFree(tmp_buf);
5525 }
5526
5527 static
DumpNetListForAPort(FP,ObjPtr,buf,buf_sz,pn_buf_index)5528 void DumpNetListForAPort(FP, ObjPtr, buf, buf_sz, pn_buf_index)
5529 FILE *FP;
5530 struct ObjRec *ObjPtr;
5531 char *buf;
5532 int buf_sz, *pn_buf_index;
5533 {
5534 struct AttrRec *attr_ptr=FindObjAttrWithName(ObjPtr, "name=");
5535 int ok=TRUE;
5536
5537 if (attr_ptr != NULL) {
5538 if (BlankStr(attr_ptr->attr_value.s)) {
5539 /* do not translate -- program constants */
5540 ok = SetPortName("(unknown)", buf, buf_sz, pn_buf_index);
5541 } else {
5542 ok = SetPortName(attr_ptr->attr_value.s, buf, buf_sz,
5543 pn_buf_index);
5544 }
5545 }
5546 if (ok) {
5547 attr_ptr = FindAttrWithName(ObjPtr, "signal_name=", NULL);
5548 DumpNetlListLine(FP, buf, attr_ptr->obj->detail.t->minilines.first);
5549 }
5550 }
5551
5552 static
DoDumpNetListForAnObj(FP,ObjPtr)5553 void DoDumpNetListForAnObj(FP, ObjPtr)
5554 FILE *FP;
5555 struct ObjRec *ObjPtr;
5556 {
5557 struct ObjRec *obj_ptr=NULL;
5558 struct AttrRec *attr_ptr=NULL;
5559 char port_name[MAXSTRING];
5560
5561 switch (ObjPtr->type) {
5562 case OBJ_SYM:
5563 case OBJ_ICON:
5564 if ((attr_ptr=FindObjAttrWithName(ObjPtr, "name=")) != NULL) {
5565 int index=0, ok=TRUE;
5566
5567 if (BlankStr(attr_ptr->attr_value.s)) {
5568 /* do not translate -- program constants */
5569 ok = SetPortName("(unknown)", port_name, sizeof(port_name), &index);
5570 } else {
5571 ok = SetPortName(attr_ptr->attr_value.s, port_name,
5572 sizeof(port_name), &index);
5573 }
5574 if (ok) {
5575 if (ObjIsAPort(ObjPtr)) {
5576 attr_ptr = FindAttrWithName(ObjPtr, "signal_name=", NULL);
5577 DumpNetlListLine(FP, port_name,
5578 attr_ptr->obj->detail.t->minilines.first);
5579 } else {
5580 for (obj_ptr=ObjPtr->detail.r->last; obj_ptr != NULL;
5581 obj_ptr=obj_ptr->prev) {
5582 obj_ptr->tmp_parent = ObjPtr;
5583 if (obj_ptr->type != OBJ_TEXT && ObjIsAPort(obj_ptr)) {
5584 int saved_index=index;
5585
5586 port_name[saved_index] = '\0';
5587 DumpNetListForAPort(FP, obj_ptr, port_name,
5588 sizeof(port_name), &index);
5589 index = saved_index;
5590 }
5591 }
5592 }
5593 }
5594 }
5595 break;
5596 case OBJ_GROUP:
5597 for (obj_ptr=ObjPtr->detail.r->last; obj_ptr != NULL;
5598 obj_ptr=obj_ptr->prev) {
5599 obj_ptr->tmp_parent = ObjPtr;
5600 DoDumpNetListForAnObj(FP, obj_ptr);
5601 }
5602 break;
5603 case OBJ_PIN:
5604 obj_ptr = GetPinObj(ObjPtr);
5605 if ((attr_ptr=FindObjAttrWithName(obj_ptr, "name=")) != NULL) {
5606 int index=0, ok=TRUE;
5607
5608 if (BlankStr(attr_ptr->attr_value.s)) {
5609 /* do not translate -- program constants */
5610 ok = SetPortName("(unknown)", port_name, sizeof(port_name), &index);
5611 } else {
5612 ok = SetPortName(attr_ptr->attr_value.s, port_name,
5613 sizeof(port_name), &index);
5614 }
5615 if (ok) {
5616 if (ObjIsAPort(obj_ptr)) {
5617 attr_ptr = FindAttrWithName(obj_ptr, "signal_name=", NULL);
5618 DumpNetlListLine(FP, port_name,
5619 attr_ptr->obj->detail.t->minilines.first);
5620 }
5621 }
5622 }
5623 break;
5624 }
5625 }
5626
5627 static
DumpComponentAttrs(FP,ObjPtr)5628 void DumpComponentAttrs(FP, ObjPtr)
5629 FILE *FP;
5630 struct ObjRec *ObjPtr;
5631 {
5632 struct AttrRec *attr_ptr=NULL;
5633
5634 for (attr_ptr=ObjPtr->fattr; attr_ptr != NULL; attr_ptr=attr_ptr->next) {
5635 if (strcmp(attr_ptr->attr_name.s, "name=") != 0 &&
5636 strcmp(attr_ptr->attr_name.s, "type=") != 0) {
5637 int need_to_free_tmp_buf=FALSE;
5638 char *tmp_buf;
5639
5640 tmp_buf = ConvertAttrNameFirstMiniLineToString(attr_ptr,
5641 &need_to_free_tmp_buf);
5642 if (fprintf(FP, "\t%s\n", tmp_buf) == EOF) writeFileFailed = TRUE;
5643 if (need_to_free_tmp_buf) UtilFree(tmp_buf);
5644 }
5645 }
5646 }
5647
5648 static
DoDumpComponentForAnObj(FP,ObjPtr)5649 void DoDumpComponentForAnObj(FP, ObjPtr)
5650 FILE *FP;
5651 struct ObjRec *ObjPtr;
5652 {
5653 struct ObjRec *obj_ptr=NULL;
5654 struct AttrRec *attr_ptr=NULL;
5655
5656 switch (ObjPtr->type) {
5657 case OBJ_SYM:
5658 case OBJ_ICON:
5659 if ((attr_ptr=FindObjAttrWithName(ObjPtr, "name=")) != NULL) {
5660 char *comp_name=NULL;
5661
5662 if (BlankStr(attr_ptr->attr_value.s)) {
5663 /* do not translate -- program constants */
5664 comp_name = "(unknown)";
5665 } else {
5666 comp_name = attr_ptr->attr_value.s;
5667 }
5668 attr_ptr = FindAttrWithName(ObjPtr, "type=", NULL);
5669 if (attr_ptr != NULL) {
5670 char *comp_type=attr_ptr->attr_value.s;
5671
5672 if (fprintf(FP, "%s: %s\n", comp_name, comp_type) == EOF) {
5673 writeFileFailed = TRUE;
5674 }
5675 DumpComponentAttrs(FP, ObjPtr);
5676 }
5677 }
5678 break;
5679 case OBJ_GROUP:
5680 for (obj_ptr=ObjPtr->detail.r->last; obj_ptr != NULL;
5681 obj_ptr=obj_ptr->prev) {
5682 obj_ptr->tmp_parent = ObjPtr;
5683 DoDumpComponentForAnObj(FP, obj_ptr);
5684 }
5685 break;
5686 case OBJ_PIN:
5687 obj_ptr = GetPinObj(ObjPtr);
5688 if ((attr_ptr=FindObjAttrWithName(obj_ptr, "name=")) != NULL) {
5689 char *comp_name=NULL;
5690
5691 if (BlankStr(attr_ptr->attr_value.s)) {
5692 /* do not translate -- program constants */
5693 comp_name = "(unknown)";
5694 } else {
5695 comp_name = attr_ptr->attr_value.s;
5696 }
5697 attr_ptr = FindAttrWithName(obj_ptr, "type=", NULL);
5698 if (attr_ptr != NULL) {
5699 char *comp_type=attr_ptr->attr_value.s;
5700
5701 if (fprintf(FP, "%s: %s\n", comp_name, comp_type) == EOF) {
5702 writeFileFailed = TRUE;
5703 }
5704 DumpComponentAttrs(FP, ObjPtr);
5705 }
5706 }
5707 break;
5708 }
5709 }
5710
5711 static
DumpNetListForAnObj(FP,ObjPtr)5712 void DumpNetListForAnObj(FP, ObjPtr)
5713 FILE *FP;
5714 struct ObjRec *ObjPtr;
5715 {
5716 connectingPortsFromInternalCommand = FALSE;
5717 if (preDumpSetup) {
5718 /* dumping components */
5719 DoDumpComponentForAnObj(FP, ObjPtr);
5720 } else {
5721 /* dumping netlist */
5722 DoDumpNetListForAnObj(FP, ObjPtr);
5723 }
5724 connectingPortsFromInternalCommand = TRUE;
5725 }
5726
5727 #define WRITEBYTE(fp,byte) fputc((byte),(fp))
5728
5729 static
WriteWord(fp,word)5730 void WriteWord(fp, word)
5731 FILE *fp;
5732 unsigned short word;
5733 {
5734 WRITEBYTE(fp, word&0xff);
5735 WRITEBYTE(fp, ((unsigned short)(word&0xff00))>>8);
5736 }
5737
5738 static
WriteDoubleWord(fp,dword)5739 void WriteDoubleWord(fp, dword)
5740 FILE *fp;
5741 unsigned long dword;
5742 {
5743 WRITEBYTE(fp, dword&0xff);
5744 WRITEBYTE(fp, (dword&0xff00)>>8);
5745 WRITEBYTE(fp, (dword&0xff0000)>>16);
5746 WRITEBYTE(fp, (dword&0xff000000)>>24);
5747 }
5748
5749 static char psBopHook[MAXSTRING], psEopHook[MAXSTRING];
5750 static int psBopHookStatus=INVALID, psEopHookStatus=INVALID;
5751 static int noOrientationIfPdfSetPageDevice=INVALID;
5752 static int colorBgInPrintingColorPS=INVALID;
5753 static char xbmToTiffCmd[MAXSTRING+1];
5754 static char psToPdfCmd[MAXSTRING+1];
5755 static char epsToTmpSvgCmd[(MAXSTRING<<1)+1];
5756 static char tmpSvgToSvgCmd[(MAXSTRING<<1)+1];
5757 static char epsiExportExtension[MAXSTRING];
5758 static int overrideEPSIExportExtension=INVALID;
5759 static char pdfExportExtension[MAXSTRING];
5760 static char tmpSvgExportExtension[MAXSTRING];
5761 static int numberFileInPrintOnePage=INVALID;
5762
5763 static char defXbmToTiffCmd[]="xbmtopbm %s | pnmtotiff -none > %s";
5764 static char defPsToPdfCmd[]="ps2pdf \"%s\" \"%s\"";
5765 static char defEpsToTmpSvgCmd[]="pstoedit -dt -f sk \"%s\" \"%s\"";
5766 static char defTmpSvgToSvgCmd[]="uniconvertor \"%s\" \"%s\"";
5767
5768 /*
5769 * 1) pstoedit -dt -f sk FILE.eps FILE.sk
5770 * skconvert FILE.sk FILE.svg
5771 *
5772 * 2) pstoedit -dt -f sk FILE.eps FILE.sk
5773 * uniconvertor FILE.sk FILE.svg
5774 *
5775 * 3) pstoedit -dt -f ps2ai FILE.eps FILE.ai
5776 * uniconvertor FILE.ai FILE.svg
5777 */
5778
SetPsSetup(buf)5779 void SetPsSetup(buf)
5780 char *buf;
5781 {
5782 gpszPsSetup = UtilStrDup(buf);
5783 if (gpszPsSetup == NULL) FailAllocMessage();
5784 psSetupStatus = TRUE;
5785 }
5786
SetBopHook(buf)5787 void SetBopHook(buf)
5788 char *buf;
5789 {
5790 UtilStrCpyN(psBopHook, sizeof(psBopHook), buf);
5791 psBopHookStatus = TRUE;
5792 }
5793
SetEopHook(buf)5794 void SetEopHook(buf)
5795 char *buf;
5796 {
5797 UtilStrCpyN(psEopHook, sizeof(psEopHook), buf);
5798 psEopHookStatus = TRUE;
5799 }
5800
5801 static
CleanUpDumpInitDefaults()5802 void CleanUpDumpInitDefaults()
5803 {
5804 *psBopHook = *psEopHook = '\0';
5805 psBopHookStatus = psEopHookStatus = INVALID;
5806 minimalEPS = INVALID;
5807 noOrientationIfPdfSetPageDevice = INVALID;
5808 colorBgInPrintingColorPS = INVALID;
5809 *xbmToTiffCmd = '\0';
5810 *psToPdfCmd = '\0';
5811 *epsToTmpSvgCmd = '\0';
5812 *tmpSvgToSvgCmd = '\0';
5813 *epsiExportExtension = '\0';
5814 *pdfExportExtension = '\0';
5815 *tmpSvgExportExtension = '\0';
5816 overrideEPSIExportExtension = INVALID;
5817 numberFileInPrintOnePage = INVALID;
5818 }
5819
GetCmdUsingDefAndXDef(buf,buf_sz,def_cmd,option,verify_count,msg_box_if_error)5820 int GetCmdUsingDefAndXDef(buf, buf_sz, def_cmd, option, verify_count,
5821 msg_box_if_error)
5822 char *buf, *def_cmd, *option;
5823 int buf_sz, verify_count, msg_box_if_error;
5824 {
5825 char *c_ptr=NULL;
5826
5827 UtilStrCpyN(buf, buf_sz, def_cmd);
5828 if (!PRTGIF || cmdLineOpenDisplay) {
5829 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,option)) != NULL) {
5830 UtilStrCpyN(buf, buf_sz, c_ptr);
5831 if (verify_count > 0) {
5832 int count=0;
5833
5834 for (c_ptr=strstr(buf,"%s"); c_ptr!=NULL;
5835 c_ptr=strstr(++c_ptr,"%s")) {
5836 count++;
5837 }
5838 if (count != verify_count) {
5839 sprintf(gszMsgBox, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
5840 TOOL_NAME, option, buf, def_cmd);
5841 fprintf(stderr, "%s\n", gszMsgBox);
5842 if (!PRTGIF && msg_box_if_error) {
5843 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
5844 }
5845 UtilStrCpyN(buf, buf_sz, def_cmd);
5846 return FALSE;
5847 }
5848 }
5849 }
5850 }
5851 return TRUE;
5852 }
5853
5854 static
GenDumpInitDefaults()5855 void GenDumpInitDefaults()
5856 {
5857 static int init_other_xdefs=FALSE;
5858 char *c_ptr;
5859
5860 if (minimalEPS == INVALID) {
5861 minimalEPS = !usePsAdobeString;
5862 #ifdef _MINIMAL_EPS
5863 minimalEPS = (_MINIMAL_EPS != 0);
5864 #endif /* _MINIMAL_EPS */
5865 if (!PRTGIF || cmdLineOpenDisplay) {
5866 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"MinimalEPS")) != NULL) {
5867 minimalEPS = (UtilStrICmp(c_ptr, "true") == 0);
5868 }
5869 }
5870 }
5871 if (noOrientationIfPdfSetPageDevice == INVALID) {
5872 noOrientationIfPdfSetPageDevice = FALSE;
5873 if (!PRTGIF) {
5874 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
5875 "NoOrientationIfPdfSetPageDevice")) != NULL &&
5876 UtilStrICmp(c_ptr, "true") == 0) {
5877 noOrientationIfPdfSetPageDevice = TRUE;
5878 }
5879 }
5880 }
5881 if (colorBgInPrintingColorPS == INVALID) {
5882 colorBgInPrintingColorPS = FALSE;
5883 if (!PRTGIF) {
5884 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
5885 "ColorBgInPrintingColorPS")) != NULL &&
5886 UtilStrICmp(c_ptr, "true") == 0) {
5887 colorBgInPrintingColorPS = TRUE;
5888 }
5889 }
5890 }
5891 if (psBopHookStatus == INVALID) {
5892 *psBopHook = '\0';
5893 if (!PRTGIF) {
5894 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PSBopHook")) != NULL) {
5895 UtilStrCpyN(psBopHook, sizeof(psBopHook), c_ptr);
5896 psBopHookStatus = TRUE;
5897 } else {
5898 psBopHookStatus = FALSE;
5899 }
5900 }
5901 }
5902 if (psEopHookStatus == INVALID) {
5903 *psEopHook = '\0';
5904 if (!PRTGIF) {
5905 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PSEopHook")) != NULL) {
5906 UtilStrCpyN(psEopHook, sizeof(psEopHook), c_ptr);
5907 psEopHookStatus = TRUE;
5908 } else {
5909 psEopHookStatus = FALSE;
5910 }
5911 }
5912 }
5913 if (psSetupStatus == INVALID) {
5914 psSetupStatus = TRUE;
5915 if (gpszPsSetup == NULL && (!PRTGIF || cmdLineOpenDisplay) &&
5916 (c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "AdditionalPSSetup")) !=
5917 NULL) {
5918 SetPsSetup(c_ptr);
5919 }
5920 }
5921 if (psDistillerNoImageCompress == INVALID) {
5922 psDistillerNoImageCompress = FALSE;
5923 if (!PRTGIF || cmdLineOpenDisplay) {
5924 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
5925 "PSDistillerNoImageCompress")) !=
5926 NULL && UtilStrICmp(c_ptr, "true") == 0) {
5927 psDistillerNoImageCompress = TRUE;
5928 }
5929 }
5930 }
5931 if (!init_other_xdefs) {
5932 init_other_xdefs = TRUE;
5933
5934 if (PRTGIF) {
5935 generateTiffEPSI = cmdLineTiffEPSI;
5936 strcpy(xbmToTiffCmd, defXbmToTiffCmd);
5937 } else {
5938 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "TiffEPSI")) != NULL) {
5939 if (UtilStrICmp(c_ptr, "true") == 0) {
5940 fprintf(stderr, TgLoadString(STID_TIFFEPSI_DIRECTLY_SUPPORTED),
5941 TOOL_NAME, "TiffEPSI", TOOL_NAME);
5942 fprintf(stderr, "\n");
5943 }
5944 }
5945 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "XbmToTiff")) != NULL) {
5946 int count=0;
5947
5948 UtilStrCpyN(xbmToTiffCmd, sizeof(xbmToTiffCmd), c_ptr);
5949 for (c_ptr=strstr(xbmToTiffCmd,"%s"); c_ptr!=NULL;
5950 c_ptr=strstr(++c_ptr,"%s")) {
5951 count++;
5952 }
5953 if (count != 1 && count != 2) {
5954 sprintf(gszMsgBox, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
5955 TOOL_NAME, "XbmToTiff", xbmToTiffCmd, defXbmToTiffCmd);
5956 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
5957 strcpy(xbmToTiffCmd, defXbmToTiffCmd);
5958 }
5959 } else {
5960 strcpy(xbmToTiffCmd, defXbmToTiffCmd);
5961 }
5962 }
5963 strcpy(pdfExportExtension, "pdf");
5964 if (!PRTGIF || cmdLineOpenDisplay) {
5965 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PdfFileExtension")) !=
5966 NULL) {
5967 UtilStrCpyN(pdfExportExtension, sizeof(pdfExportExtension), c_ptr);
5968 UtilTrimBlanks(pdfExportExtension);
5969 if (*pdfExportExtension == '\0') {
5970 fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
5971 TOOL_NAME, "PdfFileExtension", pdfExportExtension, "pdf");
5972 fprintf(stderr, "\n");
5973 strcpy(pdfExportExtension, "pdf");
5974 }
5975 }
5976 }
5977 strcpy(tmpSvgExportExtension, "sk");
5978 if (!PRTGIF || cmdLineOpenDisplay) {
5979 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"TmpSvgFileExtension")) !=
5980 NULL) {
5981 UtilStrCpyN(tmpSvgExportExtension, sizeof(tmpSvgExportExtension),
5982 c_ptr);
5983 UtilTrimBlanks(tmpSvgExportExtension);
5984 if (*tmpSvgExportExtension == '\0') {
5985 fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
5986 TOOL_NAME, "TmpSvgFileExtension", tmpSvgExportExtension,
5987 "sk");
5988 fprintf(stderr, "\n");
5989 strcpy(tmpSvgExportExtension, "sk");
5990 }
5991 }
5992 }
5993 if (!GetCmdUsingDefAndXDef(psToPdfCmd, sizeof(psToPdfCmd), defPsToPdfCmd,
5994 "PsToPdf", 2, TRUE)) {
5995 }
5996 if (!GetCmdUsingDefAndXDef(epsToTmpSvgCmd, sizeof(epsToTmpSvgCmd),
5997 defEpsToTmpSvgCmd, "EpsToTmpSvg", 2, TRUE)) {
5998 }
5999 if (!GetCmdUsingDefAndXDef(tmpSvgToSvgCmd, sizeof(tmpSvgToSvgCmd),
6000 defTmpSvgToSvgCmd, "TmpSvgToSvg", 2, TRUE)) {
6001 }
6002 strcpy(gszProducedBy, TgLoadCachedString(CSTID_PARANED_UNKNOWN));
6003 if (!PRTGIF || cmdLineOpenDisplay) {
6004 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"ProducedBy")) != NULL) {
6005 UtilStrCpyN(gszProducedBy, sizeof(gszProducedBy), c_ptr);
6006 }
6007 } else if (*cmdLineProducedBy != '\0') {
6008 UtilStrCpyN(gszProducedBy, sizeof(gszProducedBy), cmdLineProducedBy);
6009 }
6010 pdfSetPageDevice = INVALID;
6011 if (!PRTGIF || cmdLineOpenDisplay) {
6012 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME, "PdfSetPageDevice")) !=
6013 NULL) {
6014 if (UtilStrICmp(c_ptr, "true") == 0) {
6015 pdfSetPageDevice = TRUE;
6016 } else if (UtilStrICmp(c_ptr, "false") == 0) {
6017 pdfSetPageDevice = FALSE;
6018 } else {
6019 fprintf(stderr, TgLoadString(STID_INVALID_XDEF_IGNORED),
6020 TOOL_NAME, "PdfSetPageDevice", c_ptr);
6021 fprintf(stderr, "\n");
6022 }
6023 } else if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,
6024 "LandscapePdfSetPageDevice")) != NULL) {
6025 if (UtilStrICmp(c_ptr, "true") == 0) {
6026 fprintf(stderr, TgLoadString(STID_OBSOLETE_XDEF_REPLACED),
6027 TOOL_NAME, "LandscapePdfSetPageDevice",
6028 TOOL_NAME, "PdfSetPageDevice", "true");
6029 fprintf(stderr, "\n");
6030 pdfSetPageDevice = TRUE;
6031 } else if (UtilStrICmp(c_ptr, "false") == 0) {
6032 fprintf(stderr, TgLoadString(STID_OBSOLETE_XDEF_REPLACED),
6033 TOOL_NAME, "LandscapePdfSetPageDevice",
6034 TOOL_NAME, "PdfSetPageDevice", "false");
6035 fprintf(stderr, "\n");
6036 pdfSetPageDevice = FALSE;
6037 } else {
6038 fprintf(stderr, TgLoadString(STID_INVALID_XDEF_IGNORED),
6039 TOOL_NAME, "LandscapePdfSetPageDevice");
6040 fprintf(stderr, "\n");
6041 }
6042 }
6043 }
6044 }
6045 if (overrideEPSIExportExtension == INVALID) {
6046 *epsiExportExtension = '\0';
6047 overrideEPSIExportExtension = FALSE;
6048 if (!PRTGIF) {
6049 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"EPSIExportExtension")) !=
6050 NULL) {
6051 UtilStrCpyN(epsiExportExtension, sizeof(epsiExportExtension),
6052 c_ptr);
6053 if (strchr(epsiExportExtension, '.') != NULL ||
6054 strchr(epsiExportExtension, ' ') != NULL) {
6055 fprintf(stderr, TgLoadString(STID_INVALID_XDEF),
6056 TOOL_NAME, "EPSIExportExtension", epsiExportExtension);
6057 fprintf(stderr, "\n");
6058 *epsiExportExtension = '\0';
6059 }
6060 }
6061 }
6062 }
6063 if (numberFileInPrintOnePage == INVALID) {
6064 numberFileInPrintOnePage = FALSE;
6065 if (PRTGIF) {
6066 if (cmdLineOneFilePerPage) numberFileInPrintOnePage = TRUE;
6067 } else {
6068 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
6069 "NumberFileInPrintOnePage")) != NULL &&
6070 UtilStrICmp(c_ptr, "true") == 0) {
6071 numberFileInPrintOnePage = TRUE;
6072 }
6073 }
6074 }
6075 if (dontUseShortHandPS == INVALID) {
6076 dontUseShortHandPS = FALSE;
6077 if (!PRTGIF || cmdLineOpenDisplay) {
6078 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"DontUseShortHandPS")) !=
6079 NULL && UtilStrICmp(c_ptr, "true") == 0) {
6080 dontUseShortHandPS = TRUE;
6081 }
6082 }
6083 }
6084 if (dontCondense == INVALID) {
6085 dontCondense = TRUE;
6086 if (!PRTGIF || cmdLineOpenDisplay) {
6087 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"DontCondensePSFile")) !=
6088 NULL && UtilStrICmp(c_ptr, "false") == 0) {
6089 dontCondense = FALSE;
6090 }
6091 }
6092 }
6093 if (stripSimpleComments == INVALID) {
6094 stripSimpleComments = FALSE;
6095 if (!PRTGIF || cmdLineOpenDisplay) {
6096 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME,
6097 "StripCondensedPSComments")) != NULL &&
6098 UtilStrICmp(c_ptr, "false") != 0) {
6099 static int shown_once=FALSE;
6100
6101 if (!shown_once) {
6102 sprintf(gszMsgBox, TgLoadString(STID_NAMED_XDEF_IS_OBSOLETE),
6103 TOOL_NAME, "StripCondensedPSComments");
6104 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6105 shown_once = TRUE;
6106 }
6107 }
6108 }
6109 }
6110 if (psRegMarksInTiledPageMode == INVALID) {
6111 psRegMarksInTiledPageMode = FALSE;
6112 psRegMarksGray = 0.95;
6113 if (!PRTGIF || cmdLineOpenDisplay) {
6114 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,
6115 "PsRegMarksInTiledPageMode")) != NULL &&
6116 UtilStrICmp(c_ptr, "true") == 0) {
6117 psRegMarksInTiledPageMode = TRUE;
6118 }
6119 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PsRegMarksGray")) !=
6120 NULL) {
6121 psRegMarksGray = (float)atof(c_ptr);
6122 if (psRegMarksGray < 0.0 || psRegMarksGray > 1.0) {
6123 fprintf(stderr, TgLoadString(STID_INVALID_XDEF_USE_ALT_STR),
6124 TOOL_NAME, "PsRegMarksGray", c_ptr, "0.95");
6125 psRegMarksGray = 0.95;
6126 }
6127 }
6128 }
6129 }
6130 }
6131
6132 static
GenTiffFile(tmp_fname,epsi_fname,condense,condensed_already)6133 void GenTiffFile(tmp_fname, epsi_fname, condense, condensed_already)
6134 char *tmp_fname, *epsi_fname;
6135 int condense, condensed_already;
6136 {
6137 register int i;
6138 char tiff_fname[MAXPATHLENGTH+1], xbm_fname[MAXPATHLENGTH+1];
6139 char cmd[MAXPATHLENGTH+1], buf[1024], *c_ptr=NULL;
6140 int bytes_read=0, count=0, tiff_fd=(-1), epsi_fd=(-1);
6141 FILE *tmp_fp=NULL, *epsi_fp=NULL, *pfp=NULL;
6142 long tmp_bytes=0L, tiff_bytes=0L;
6143 struct stat stat_buf;
6144
6145 strcpy(buf, curFileName);
6146 GetRealBaseName(buf);
6147 sprintf(xbm_fname, "%s%c%s", curDir, DIR_SEP, buf);
6148 i = strlen(xbm_fname);
6149 sprintf(&xbm_fname[i], ".%s", XBM_FILE_EXT);
6150 ModifyOutputFileName(xbm_fname);
6151
6152 sprintf(tiff_fname, "%s%c%s", curDir, DIR_SEP, buf);
6153 i = strlen(tiff_fname);
6154 sprintf(&tiff_fname[i], ".tif");
6155 ModifyOutputFileName(tiff_fname);
6156
6157 count = 0;
6158 for (c_ptr=strstr(xbmToTiffCmd,"%s"); c_ptr!=NULL;
6159 c_ptr=strstr(++c_ptr,"%s")) {
6160 count++;
6161 }
6162 if (count == 1) {
6163 sprintf(cmd, xbmToTiffCmd, xbm_fname);
6164 } else {
6165 sprintf(cmd, xbmToTiffCmd, xbm_fname, tiff_fname);
6166 }
6167 unlink(tiff_fname);
6168 if (!FindProgramInPath(cmd, NULL, FALSE)) {
6169 return;
6170 }
6171 sprintf(gszMsgBox, TgLoadCachedString(CSTID_EXECUTING_GIVEN_PROGRAM), cmd);
6172 SetStringStatus(gszMsgBox);
6173 XSync(mainDisplay, False);
6174 if ((pfp=(FILE*)popen(cmd, "r")) == NULL) {
6175 sprintf(gszMsgBox, TgLoadString(STID_FAIL_EXEC_PROG_EPSI_NOT_GEN), cmd);
6176 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6177 return;
6178 }
6179 while (fgets(buf, sizeof(buf), pfp) != NULL) {
6180 Msg(buf);
6181 }
6182 pclose(pfp);
6183 SetStringStatus(TgLoadCachedString(CSTID_DOTS_DONE));
6184
6185 if (stat(tmp_fname, &stat_buf) != 0) {
6186 sprintf(gszMsgBox, TgLoadString(STID_FAIL_GET_FINFO_EPSI_NOT_GEN),
6187 tmp_fname);
6188 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6189 return;
6190 }
6191 tmp_bytes = (long)stat_buf.st_size;
6192 if (stat(tiff_fname, &stat_buf) != 0) {
6193 sprintf(gszMsgBox, TgLoadString(STID_FAIL_GET_FINFO_EPSI_NOT_GEN),
6194 tiff_fname);
6195 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6196 return;
6197 }
6198 tiff_bytes = (long)stat_buf.st_size;
6199
6200 if ((tmp_fp=fopen(tmp_fname, "r")) == NULL) {
6201 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING),
6202 tmp_fname);
6203 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6204 return;
6205 }
6206 if ((tiff_fd=open(tiff_fname, O_RDONLY)) == (-1)) {
6207 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_READING),
6208 tiff_fname);
6209 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6210 fclose(tmp_fp);
6211 return;
6212 }
6213 if (PRTGIF && cmdLineStdOut) {
6214 epsi_fp = stdout;
6215 } else if ((epsi_fp=fopen(epsi_fname, "w")) == NULL) {
6216 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_WRITING),
6217 tiff_fname);
6218 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6219 fclose(tmp_fp);
6220 close(tiff_fd);
6221 unlink(tiff_fname);
6222 return;
6223 }
6224 WRITEBYTE(epsi_fp, 0xc5);
6225 WRITEBYTE(epsi_fp, 0xd0);
6226 WRITEBYTE(epsi_fp, 0xd3);
6227 WRITEBYTE(epsi_fp, 0xc6);
6228 WriteDoubleWord(epsi_fp, 0x0000001e);
6229 WriteDoubleWord(epsi_fp, tmp_bytes);
6230 WriteDoubleWord(epsi_fp, 0L);
6231 WriteDoubleWord(epsi_fp, 0L);
6232 WriteDoubleWord(epsi_fp, tmp_bytes+0x1e);
6233 WriteDoubleWord(epsi_fp, tiff_bytes);
6234 WriteWord(epsi_fp, 0xffff);
6235
6236 if (!writeFileFailed) {
6237 CondenseAndCopyPostScriptFile(tmp_fp, epsi_fp, tmp_fname,
6238 (!condensed_already && condense && !dontCondense));
6239 }
6240 fclose(tmp_fp);
6241 if (!(PRTGIF && cmdLineStdOut)) fclose(epsi_fp);
6242 if (writeFileFailed) {
6243 writeFileFailed = FALSE;
6244 if (PRTGIF && cmdLineStdOut) {
6245 fprintf(stderr, "%s\n", TgLoadString(STID_FAIL_TO_WRITE_TO_STDOUT));
6246 } else {
6247 FailToWriteFileMessage(epsi_fname);
6248 }
6249 close(tiff_fd);
6250 unlink(tiff_fname);
6251 return;
6252 }
6253 if (PRTGIF && cmdLineStdOut) {
6254 epsi_fd = 1;
6255 } else if ((epsi_fd=open(epsi_fname, O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR)) ==
6256 (-1)) {
6257 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_FILE_FOR_APPEND),
6258 epsi_fname);
6259 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6260 close(tiff_fd);
6261 unlink(tiff_fname);
6262 return;
6263 }
6264 while ((bytes_read=read(tiff_fd, buf, sizeof(buf))) > 0) {
6265 if (write(epsi_fd, buf, bytes_read) <= 0) {
6266 writeFileFailed = TRUE;
6267 break;
6268 }
6269 }
6270 if (writeFileFailed) {
6271 writeFileFailed = FALSE;
6272 FailToWriteFileMessage(epsi_fname);
6273 }
6274 if (!(PRTGIF && cmdLineStdOut)) close(epsi_fd);
6275 close(tiff_fd);
6276 unlink(tiff_fname);
6277 }
6278
6279 static int psA4PaperSize=FALSE;
6280
6281 static
InitNeedA4()6282 void InitNeedA4()
6283 {
6284 static int nInitialized=FALSE;
6285
6286 if (nInitialized) return;
6287 nInitialized = TRUE;
6288 if (cmdLineA4) {
6289 psA4PaperSize = TRUE;
6290 } else if (!PRTGIF) {
6291 char *c_ptr;
6292
6293 if ((c_ptr=XGetDefault(mainDisplay,TOOL_NAME,"PSA4PaperSize")) != NULL &&
6294 UtilStrICmp(c_ptr, "true") == 0) {
6295 psA4PaperSize = TRUE;
6296 }
6297 }
6298 }
6299
6300 static
NeedA4()6301 int NeedA4()
6302 {
6303 int width_to_match, height_to_match;
6304
6305 InitNeedA4();
6306 if (!psA4PaperSize) return FALSE;
6307 width_to_match = (int)(825.0*PIX_PER_INCH/printMag);
6308 height_to_match = (int)(117.0*PIX_PER_INCH*10.0/printMag);
6309 if (onePageWidth == width_to_match && onePageHeight == height_to_match) {
6310 return TRUE;
6311 }
6312 width_to_match = (int)(21000.0*PIX_PER_MM/printMag);
6313 height_to_match = (int)(29700.0*PIX_PER_MM/printMag);
6314 return (onePageWidth == width_to_match && onePageHeight == height_to_match);
6315 }
6316
SetOutputFileName(ps_file,file_ext,pn_short_name,ppsz_rest)6317 void SetOutputFileName(ps_file, file_ext, pn_short_name, ppsz_rest)
6318 char *ps_file, *file_ext, **ppsz_rest;
6319 int *pn_short_name;
6320 {
6321 if (PRTGIF) {
6322 char *psz_file=(*ppsz_rest);
6323
6324 if (cmdLineOneFilePerPage) {
6325 if (curPage != NULL && curPage->page_file_name != NULL &&
6326 *curPage->page_file_name != '\0') {
6327 sprintf(ps_file, "%s.%s", curPage->page_file_name, file_ext);
6328 } else {
6329 sprintf(ps_file, "%s-%1d.%s", psz_file, cmdLinePageNum, file_ext);
6330 }
6331 } else {
6332 sprintf(ps_file, "%s.%s", psz_file, file_ext);
6333 }
6334 } else {
6335 int len=0, use_page_num=FALSE;
6336 char *psz=NULL;
6337
6338 if (dumpOneFilePerPage ||
6339 (dumpOnePageInStackMode && numberFileInPrintOnePage)) {
6340 if (curPage != NULL && curPage->page_file_name != NULL &&
6341 *curPage->page_file_name != '\0') {
6342 sprintf(ps_file, "%s%c%s.", curDir, DIR_SEP,
6343 curPage->page_file_name);
6344 } else {
6345 sprintf(ps_file, "%s%c%s", curDir, DIR_SEP, curFileName);
6346 use_page_num = TRUE;
6347 }
6348 } else {
6349 sprintf(ps_file, "%s%c%s", curDir, DIR_SEP, curFileName);
6350 }
6351 len = strlen(ps_file);
6352 if (len > 3 && strcmp(&ps_file[len-3], ".gz") == 0) {
6353 ps_file[len-3] = '\0';
6354 len -= 3;
6355 }
6356 if ((psz=UtilStrRChr(ps_file, '.')) == NULL) {
6357 sprintf(gszMsgBox, TgLoadString(STID_CANT_FIND_DOT_IN_SAVEFILE),
6358 "SetOutputFileName()");
6359 TgAssert(FALSE, gszMsgBox, NULL);
6360 }
6361 if (use_page_num) {
6362 sprintf(psz, "-%1d.%s", curPageNum, file_ext);
6363 } else {
6364 sprintf(psz, ".%s", file_ext);
6365 }
6366 }
6367 ModifyOutputFileName(ps_file);
6368
6369 if (!PRTGIF && pn_short_name != NULL && ppsz_rest != NULL) {
6370 if (((*pn_short_name)=IsPrefix(bootDir, ps_file, ppsz_rest))) {
6371 *ppsz_rest = (&(*ppsz_rest)[1]);
6372 }
6373 }
6374 }
6375
6376 static
DumpRegMark(fp,pstem)6377 void DumpRegMark(fp, pstem)
6378 FILE *fp;
6379 float *pstem;
6380 {
6381 float fval=(*pstem);
6382
6383 fprintf(dumpFP, " %s ", gPsCmd[PS_GSAVE]);
6384 fprintf(dumpFP, "%.3f 0 %s ", -fval, gPsCmd[PS_RMOVETO]);
6385 fprintf(dumpFP, "2 %.3f %s 0 %s ", fval, gPsCmd[PS_MUL], gPsCmd[PS_RLINETO]);
6386 fprintf(dumpFP, "%s %s\n", gPsCmd[PS_STROKE], gPsCmd[PS_GRESTORE]);
6387 fprintf(dumpFP, " %s ", gPsCmd[PS_GSAVE]);
6388 fprintf(dumpFP, "0 %.3f %s ", -fval, gPsCmd[PS_RMOVETO]);
6389 fprintf(dumpFP, "0 2 %.3f %s %s ", fval, gPsCmd[PS_MUL], gPsCmd[PS_RLINETO]);
6390 fprintf(dumpFP, "%s %s\n", gPsCmd[PS_STROKE], gPsCmd[PS_GRESTORE]);
6391 }
6392
6393 static
FixUpSVGLine(out_fp,dup_buf)6394 int FixUpSVGLine(out_fp, dup_buf)
6395 FILE *out_fp;
6396 char *dup_buf;
6397 {
6398 char *psz=NULL, *psz_start=&dup_buf[5];
6399 int found_xmlns=FALSE;
6400
6401 while (psz_start != NULL) {
6402 char saved_ch='\0', key[MAXSTRING];
6403
6404 /* skip all the blank characters */
6405 while (*psz_start == ' ' || *psz_start == '\t') psz_start++;
6406
6407 *key = '\0';
6408 for (psz=psz_start; *psz != '>'; psz++) {
6409 /* looking for key */
6410 saved_ch = '\0';
6411 if (*psz == ' ' || *psz == '\t' || *psz == '=' || *psz == '>') {
6412 saved_ch = *psz;
6413 *psz = '\0';
6414 UtilStrCpyN(key, sizeof(key), psz_start);
6415 *psz = saved_ch;
6416 break;
6417 }
6418 }
6419 if (*key == '\0') {
6420 /* no key, this should not happen, may be malformed, give up */
6421 break;
6422 } else if (saved_ch != '=') {
6423 /* saved_ch is either '\0' or a blank character, key with no value */
6424 psz_start = ++psz;
6425 } else {
6426 int find_double_quote=FALSE;
6427 char value[MAXSTRING];
6428
6429 *value = '\0';
6430 /* looking for value */
6431 psz_start = ++psz;
6432 if (*psz_start == '"') {
6433 find_double_quote = TRUE;
6434 psz_start++;
6435 }
6436 if (find_double_quote) {
6437 for (psz=psz_start; *psz != '"' && *psz != '>'; psz++) ;
6438
6439 if (*psz == '>') {
6440 /* may be malformed, give up */
6441 break;
6442 } else if (*psz == '"') {
6443 saved_ch = *psz;
6444 *psz = '\0';
6445 UtilStrCpyN(value, sizeof(value), psz_start);
6446 *psz = saved_ch;
6447 }
6448 } else {
6449 for (psz=psz_start; *psz != '>'; psz++) {
6450 saved_ch = '\0';
6451 if (*psz == ' ' || *psz == '\t' || *psz == '>') {
6452 saved_ch = *psz;
6453 *psz = '\0';
6454 UtilStrCpyN(value, sizeof(value), psz_start);
6455 *psz = saved_ch;
6456 break;
6457 }
6458 }
6459 if (*key == '\0') {
6460 /* no value, this should not happen, may be malformed, give up */
6461 break;
6462 }
6463 }
6464 /* found both key and value */
6465 if (UtilStrICmp(key, "xmlns") == 0) {
6466 found_xmlns = TRUE;
6467 break;
6468 }
6469 psz_start = ++psz;
6470 }
6471 }
6472 if (found_xmlns) {
6473 fprintf(out_fp, "%s\n", dup_buf);
6474 } else {
6475 int len=strlen(dup_buf);
6476
6477 dup_buf[len-1] = '\0';
6478 fprintf(out_fp, "%s xmlns=\"http://www.w3.org/2000/svg\">\n", dup_buf);
6479 dup_buf[len-1] = '>';
6480 }
6481 return TRUE;
6482 }
6483
6484 static
FixUpSVGFile(tmpsvg_fname,svg_fname)6485 int FixUpSVGFile(tmpsvg_fname, svg_fname)
6486 char *tmpsvg_fname, *svg_fname;
6487 {
6488 FILE *in_fp=fopen(tmpsvg_fname, "r"), *out_fp=NULL;
6489 char *buf=NULL;
6490 int line_num=0, fixed=FALSE;
6491
6492 if (in_fp == NULL) {
6493 return FailToOpenMessage(tmpsvg_fname, "r", NULL);
6494 }
6495 out_fp = fopen(svg_fname, "w");
6496 if (out_fp == NULL) {
6497 return FailToOpenMessage(tmpsvg_fname, "w", NULL);
6498 }
6499 while ((buf=UtilGetALine(in_fp)) != NULL) {
6500 line_num++;
6501 if (!fixed && buf[0] == '<') {
6502 if (UtilStrNCaseCmp(buf, "<svg ", 5) == 0) {
6503 int len=0;
6504
6505 UtilTrimBlanks(buf);
6506 len = strlen(buf);
6507 if (len > 0 && buf[len-1] == '>') {
6508 char *dup_buf=UtilStrDup(buf);
6509
6510 if (dup_buf == NULL) {
6511 FailAllocMessage();
6512 UtilFree(buf);
6513 fclose(in_fp);
6514 fclose(out_fp);
6515 return FALSE;
6516 }
6517 if (FixUpSVGLine(out_fp, dup_buf)) {
6518 fixed = TRUE;
6519 } else {
6520 fprintf(out_fp, "%s\n", buf);
6521 }
6522 UtilFree(dup_buf);
6523 } else {
6524 fprintf(out_fp, "%s\n", buf);
6525 }
6526 } else {
6527 fprintf(out_fp, "%s\n", buf);
6528 }
6529 } else {
6530 fprintf(out_fp, "%s\n", buf);
6531 }
6532 UtilFree(buf);
6533 }
6534 fclose(in_fp);
6535 fclose(out_fp);
6536
6537 return TRUE;
6538 }
6539
6540 static
DoGenDump(FileName)6541 int DoGenDump(FileName)
6542 char *FileName;
6543 {
6544 static char loc_time[MAXSTRING+1];
6545
6546 struct ObjRec *obj_ptr=NULL;
6547 char cmd[(MAXSTRING<<1)+1], tmp_str[MAXSTRING+1], ps_file[MAXSTRING+1];
6548 char *rest=NULL, *file_ext=NULL, *output_type=NULL;
6549 int i, len, short_name=FALSE, export_cap=0;
6550 time_t tloc;
6551
6552 if (!curDirIsLocal) {
6553 MsgBox(TgLoadString(STID_CANNOT_PRINT_REMOTE_FILE), TOOL_NAME, INFO_MB);
6554 return FALSE;
6555 }
6556 GenDumpInitDefaults();
6557
6558 if (botObj==NULL && ((pageLayoutMode==PAGE_STACK &&
6559 dumpOnePageInStackMode) || pageLayoutMode==PAGE_TILE)) {
6560 int rc=FALSE;
6561
6562 if (PRTGIF && cmdLineOneFilePerPage) {
6563 sprintf(gszMsgBox, TgLoadString(STID_NO_OBJ_TO_PRINT_ON_PAGE),
6564 cmdLinePageNum);
6565 rc = TRUE;
6566 } else if (!PRTGIF && dumpOneFilePerPage) {
6567 sprintf(gszMsgBox, TgLoadString(STID_NO_OBJ_TO_PRINT_ON_PAGE),
6568 curPageNum);
6569 rc = TRUE;
6570 }
6571 if (preDumpSetup && rc) {
6572 return rc;
6573 }
6574 if (rc) {
6575 if (PRTGIF) {
6576 fprintf(stderr, "%s\n", gszMsgBox);
6577 } else {
6578 Msg(gszMsgBox);
6579 }
6580 } else {
6581 strcpy(gszMsgBox, TgLoadString(STID_NO_OBJ_TO_PRINT));
6582 if (PRTGIF) {
6583 fprintf(stderr, "%s\n", gszMsgBox);
6584 } else {
6585 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6586 }
6587 }
6588 return rc;
6589 }
6590 if (whereToPrint != PRINTER) {
6591 if (!PRTGIF && !curFileDefined) {
6592 sprintf(gszMsgBox, TgLoadString(STID_NO_CUR_FILE_CANNOT_GEN_FORMAT),
6593 GetExportName(whereToPrint, EXPORT_THIS));
6594 if (PRTGIF) {
6595 fprintf(stderr, "%s\n", gszMsgBox);
6596 } else {
6597 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6598 }
6599 return FALSE;
6600 }
6601 }
6602 if (!PRTGIF && printingPageNum==printingFirstPageNum && !preDumpSetup) {
6603 Msg(TgLoadString(STID_GENERATING_PRINT_FILE_DOTS));
6604 }
6605 if (whereToPrint >= MAXDEFWHERETOPRINT) {
6606 export_cap = GetExportFilterCapability(whereToPrint);
6607 }
6608 if (whereToPrint == XBM_FILE || whereToPrint == GIF_FILE ||
6609 whereToPrint == HTML_FILE || whereToPrint == PNG_FILE ||
6610 whereToPrint == JPEG_FILE || whereToPrint == PPM_FILE) {
6611 if (topObj == NULL) {
6612 sprintf(gszMsgBox, TgLoadString(STID_NO_OBJ_TO_EXPORT));
6613 if (PRTGIF) {
6614 fprintf(stderr, "%s\n", gszMsgBox);
6615 } else {
6616 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
6617 }
6618 } else {
6619 int saved_colordump=colorDump, watch_cursor=watchCursorOnMainWindow;
6620 int dump_ppm_preferred=FALSE;
6621
6622 if (!watch_cursor) {
6623 SetWatchCursor(drawWindow);
6624 SetWatchCursor(mainWindow);
6625 }
6626 if (whereToPrint == GIF_FILE || whereToPrint == HTML_FILE ||
6627 whereToPrint == PNG_FILE || whereToPrint == JPEG_FILE) {
6628 colorDump = TRUE;
6629 }
6630 dump_ppm_preferred = colorDump && fullTrueColorMode &&
6631 (whereToPrint==GIF_FILE || whereToPrint==HTML_FILE ||
6632 whereToPrint==PNG_FILE || whereToPrint==JPEG_FILE ||
6633 whereToPrint==PPM_FILE || whereToPrint==XBM_FILE);
6634
6635 DumpXBitmapFile(FALSE, dump_ppm_preferred, dumpOneFilePerPage ||
6636 (dumpOnePageInStackMode && numberFileInPrintOnePage));
6637 colorDump = saved_colordump;
6638 if (!watch_cursor) {
6639 SetDefaultCursor(mainWindow);
6640 ShowCursor();
6641 }
6642 }
6643 return TRUE;
6644 }
6645 /*
6646 * At this point, whereToPrint can only be PostScript, ASCII Text, NetList,
6647 * or external export type (if whereToPrint >= MAXDEFWHERETOPRINT).
6648 */
6649 if (printingPageNum == printingFirstPageNum) {
6650 if (MkTempFile(tmpFile, sizeof(tmpFile), tmpDir, TOOL_NAME) == NULL) {
6651 return FALSE;
6652 }
6653 if ((dumpFP=fopen(tmpFile, "w")) == NULL) {
6654 sprintf(tmp_str, TgLoadString(STID_CANNOT_OPEN_FOR_WRITE_PRINT),
6655 tmpFile);
6656 if (PRTGIF) {
6657 fprintf(stderr, "%s\n", tmp_str);
6658 } else {
6659 MsgBox(tmp_str, TOOL_NAME, INFO_MB);
6660 }
6661 return FALSE;
6662 }
6663 if (PRTGIF && !cmdLineStdOut) {
6664 if (!cmdLineQuiet) {
6665 fprintf(stderr, TgLoadString(STID_WRITING_TO_DOTS), tmpFile);
6666 fprintf(stderr, "\n");
6667 }
6668 }
6669 writeFileFailed = FALSE;
6670 ResetGrayDetection();
6671 }
6672 if (whereToPrint < MAXDEFWHERETOPRINT &&
6673 printingPageNum == printingFirstPageNum &&
6674 whereToPrint != TEXT_FILE && whereToPrint != NETLIST_FILE) {
6675 PSUseShortHand();
6676 if (dontUseShortHandPS) {
6677 PSDontUseShortHand();
6678 }
6679 if (usePsAdobeString) {
6680 switch (whereToPrint) {
6681 case PRINTER:
6682 case PS_FILE:
6683 case PDF_FILE:
6684 if (*adobeString == '\0') {
6685 if (fprintf(dumpFP, "%%!PS-Adobe-2.0\n") == EOF) {
6686 writeFileFailed = TRUE;
6687 }
6688 } else if (fprintf(dumpFP,"%%!PS-Adobe-%s\n",adobeString) == EOF) {
6689 writeFileFailed = TRUE;
6690 }
6691 break;
6692 case LATEX_FIG:
6693 case EPSI_FILE:
6694 case SVG_FILE:
6695 if (*adobeString == '\0') {
6696 if (fprintf(dumpFP, "%%!PS-Adobe-2.0 EPSF-1.2\n") == EOF) {
6697 writeFileFailed = TRUE;
6698 }
6699 } else if (*epsfString == '\0') {
6700 if (fprintf(dumpFP, "%%!PS-Adobe-%s\n", adobeString) == EOF) {
6701 writeFileFailed = TRUE;
6702 }
6703 } else {
6704 if (fprintf(dumpFP, "%%!PS-Adobe-%s EPSF-%s\n",
6705 adobeString, epsfString) == EOF) {
6706 writeFileFailed = TRUE;
6707 }
6708 }
6709 break;
6710 }
6711 } else {
6712 if (preDumpSetup) PSUsePSAdobe();
6713 if (fprintf(dumpFP, "%%!\n") == EOF) {
6714 writeFileFailed = TRUE;
6715 }
6716 }
6717 if (pageLayoutMode == PAGE_STACK &&
6718 printingFirstPageNum == printingLastPageNum) {
6719 DumpBBox(dumpFP, ALL_BBOX, NULL);
6720 } else if (fprintf(dumpFP,"%%%%BoundingBox: (atend)\n") == EOF) {
6721 writeFileFailed = TRUE;
6722 }
6723 if (PRTGIF && !cmdLineOpenDisplay) {
6724 if (fprintf(dumpFP, "%%%%Title: %s\n", FileName) == EOF) {
6725 writeFileFailed = TRUE;
6726 }
6727 } else if (curFileDefined) {
6728 int gzipped=FALSE;
6729
6730 strcpy(tmp_str, curFileName);
6731 if (FileNameHasExtension(tmp_str, OBJ_FILE_TYPE, &gzipped, NULL) &&
6732 gzipped) {
6733 char *psz=UtilStrRChr(tmp_str, '.');
6734
6735 if (psz != NULL) *psz = '\0';
6736 }
6737 len = strlen(tmp_str);
6738 for (i=len-1; tmp_str[i] != '.'; i--) ;
6739 tmp_str[i] = '\0';
6740 if (fprintf(dumpFP, "%%%%Title: %s\n", tmp_str) == EOF) {
6741 writeFileFailed = TRUE;
6742 }
6743 } else if (fprintf(dumpFP, "%%%%Title: [Unnamed]\n") == EOF) {
6744 writeFileFailed = TRUE;
6745 }
6746 time(&tloc);
6747 strcpy(loc_time, ctime(&tloc));
6748 loc_time[24] = '\0';
6749 if (fprintf(dumpFP, "%%%%CreationDate: %s\n", loc_time) == EOF) {
6750 writeFileFailed = TRUE;
6751 }
6752 SetFullVersionString();
6753 if (fprintf(dumpFP, "%%%%Creator: %s written by %s\n", fullToolName,
6754 "William Chia-Wei Cheng (bill.cheng@acm.org)") == EOF) {
6755 writeFileFailed = TRUE;
6756 }
6757 if (fprintf(dumpFP, "%%%%ProducedBy: %s\n", gszProducedBy) == EOF) {
6758 writeFileFailed = TRUE;
6759 }
6760 if (whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6761 whereToPrint != SVG_FILE) {
6762 if (!(pdfSetPageDevice && noOrientationIfPdfSetPageDevice)) {
6763 if (fprintf(dumpFP, "%%%%Orientation: %s\n",
6764 (pageStyle==PORTRAIT ? "Portrait" : "Landscape")) == EOF) {
6765 writeFileFailed = TRUE;
6766 }
6767 }
6768 }
6769 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6770 whereToPrint != SVG_FILE) || !minimalEPS) {
6771 int total_pages=0;
6772
6773 if (dumpOnePageInStackMode || dumpOnePageInTileMode ||
6774 whereToPrint == LATEX_FIG || whereToPrint == EPSI_FILE ||
6775 whereToPrint == SVG_FILE) {
6776 total_pages = 1;
6777 } else if (pageLayoutMode == PAGE_STACK) {
6778 total_pages = (dumpPages ? gPagesToPrintSpec.num_pages_specified :
6779 lastPageNum);
6780 } else {
6781 total_pages = paperCol * paperRow;
6782 }
6783 if (fprintf(dumpFP, "%%%%Pages: %1d\n", total_pages) == EOF) {
6784 writeFileFailed = TRUE;
6785 }
6786 if (fprintf(dumpFP, "%%%%DocumentFonts: (atend)\n") == EOF) {
6787 writeFileFailed = TRUE;
6788 }
6789 if (NeedA4()) {
6790 if (fprintf(dumpFP, "%%%%DocumentPaperSizes: a4\n") == EOF) {
6791 writeFileFailed = TRUE;
6792 }
6793 }
6794 if (fprintf(dumpFP, "%%%%EndComments\n") == EOF) {
6795 writeFileFailed = TRUE;
6796 }
6797 }
6798 if (whereToPrint == EPSI_FILE && !generateTiffEPSI) {
6799 SaveStatusStrings();
6800 SetStringStatus(TgLoadString(STID_GENERATING_PREVIEW_BITMAP));
6801 GenPreviewBitmap(dumpFP, llxPage, llyPage, urxPage, uryPage);
6802 RestoreStatusStrings();
6803 }
6804
6805 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6806 whereToPrint != SVG_FILE) || !minimalEPS) {
6807 if (fprintf(dumpFP, "%%%%BeginProlog\n") == EOF) {
6808 writeFileFailed = TRUE;
6809 }
6810 }
6811
6812 DumpPSMacro(dumpFP);
6813
6814 PrepareEightBitFontInfo();
6815 DumpEightBitFontInfo(dumpFP);
6816
6817 if (fprintf(dumpFP, "end\n\n") == EOF) writeFileFailed = TRUE;
6818 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6819 whereToPrint != SVG_FILE) || !minimalEPS) {
6820 int need_a4=NeedA4(), need_page_size=FALSE, need_setup=FALSE;
6821
6822 #ifndef _NO_LANDSCAPE_PDF_SETPAGEDEVICE
6823 if (whereToPrint == PDF_FILE) {
6824 need_page_size = TRUE;
6825 }
6826 #endif /* ~_NO_LANDSCAPE_PDF_SETPAGEDEVICE */
6827 if (whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6828 whereToPrint != SVG_FILE) {
6829 if (pdfSetPageDevice == INVALID) {
6830 if (cmdLinePdfSetPageDevice == INVALID) {
6831 /* do nothing */
6832 } else if (cmdLinePdfSetPageDevice) {
6833 need_page_size = TRUE;
6834 } else {
6835 need_page_size = FALSE;
6836 }
6837 } else if (pdfSetPageDevice) {
6838 if (cmdLinePdfSetPageDevice == FALSE) {
6839 need_page_size = FALSE;
6840 } else {
6841 need_page_size = TRUE;
6842 }
6843 } else {
6844 if (cmdLinePdfSetPageDevice == TRUE) {
6845 need_page_size = TRUE;
6846 } else {
6847 need_page_size = FALSE;
6848 }
6849 }
6850 }
6851 if (fprintf(dumpFP, "%%%%EndProlog\n") == EOF) writeFileFailed = TRUE;
6852 need_setup = (psDistillerNoImageCompress == TRUE ||
6853 gpszPsSetup != NULL || need_a4 || need_page_size);
6854 if (need_setup) {
6855 if (fprintf(dumpFP, "%%%%BeginSetup\n") == EOF) {
6856 writeFileFailed = TRUE;
6857 }
6858 }
6859 if (need_a4) {
6860 if (fprintf(dumpFP, "%%%%PaperSize: a4\n") == EOF ||
6861 fprintf(dumpFP, "%%%%BeginPaperSize: a4\n") == EOF ||
6862 fprintf(dumpFP, "%%%%EndPaperSize\n") == EOF) {
6863 writeFileFailed = TRUE;
6864 }
6865 }
6866 if (need_page_size) {
6867 double scale=((double)printMag)*((double)72.0)/((double)100.0);
6868 double w=((double)onePageWidth)/((double)PIX_PER_INCH)*scale;
6869 double h=((double)onePageHeight)/((double)PIX_PER_INCH)*scale;
6870
6871 if (pageStyle == LANDSCAPE) {
6872 fprintf(dumpFP, "<< /PageSize [%1d %1d] ", round(h), round(w));
6873 fprintf(dumpFP,
6874 "/ImagingBBox null /Orientation 3 >> setpagedevice\n");
6875 } else {
6876 fprintf(dumpFP, "<< /PageSize [%1d %1d] ", round(w), round(h));
6877 fprintf(dumpFP,
6878 "/ImagingBBox null /Orientation 0 >> setpagedevice\n");
6879 }
6880 }
6881 if (psDistillerNoImageCompress == TRUE) {
6882 fprintf(dumpFP, "%s\n", "systemdict /setdistillerparams known");
6883 fprintf(dumpFP, " { << %s %s\n",
6884 "/AutoFilterGrayImages false",
6885 "/AutoFilterColorImages false");
6886 fprintf(dumpFP, " %s %s\n",
6887 "/ColorImageFilter /FlateEncode",
6888 "/GrayImageFilter /FlateEncode >>");
6889 fprintf(dumpFP, " %s\n", "setdistillerparams");
6890 fprintf(dumpFP, " %s\n", "} if");
6891 }
6892 if (gpszPsSetup != NULL) {
6893 if (fprintf(dumpFP, "%s\n", gpszPsSetup) == EOF) {
6894 writeFileFailed = TRUE;
6895 }
6896 }
6897 if (need_setup) {
6898 if (fprintf(dumpFP, "%%%%EndSetup\n") == EOF) {
6899 writeFileFailed = TRUE;
6900 }
6901 }
6902 }
6903 }
6904 if (whereToPrint == NETLIST_FILE && !preDumpSetup &&
6905 printingPageNum == printingFirstPageNum) {
6906 if (fprintf(dumpFP, "PORTNAME\tSIGNALNAME\n") == EOF) {
6907 writeFileFailed = TRUE;
6908 }
6909 }
6910 if (pageLayoutMode == PAGE_STACK || (pageLayoutMode == PAGE_TILE &&
6911 ((paperCol == 1 && paperRow == 1) ||
6912 ((whereToPrint == LATEX_FIG || whereToPrint == EPSI_FILE ||
6913 whereToPrint == SVG_FILE) &&
6914 !dumpOnePageInTileMode)))) {
6915 printingPageRow = printingPageCol = 1;
6916 if (whereToPrint >= MAXDEFWHERETOPRINT) {
6917 if (!ExportVectorFile(dumpFP, dumpOneFilePerPage ||
6918 (dumpOnePageInStackMode && numberFileInPrintOnePage),
6919 printingPageNum, printingFirstPageNum, printingPageRow,
6920 printingPageCol)) {
6921 return FALSE;
6922 }
6923 } else if (whereToPrint == TEXT_FILE) {
6924 if (printingPageNum != printingFirstPageNum) {
6925 fprintf(dumpFP, "\014\n");
6926 }
6927 for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
6928 obj_ptr->tmp_parent = NULL;
6929 DumpAnObjInAscii(dumpFP, obj_ptr);
6930 }
6931 } else if (whereToPrint == NETLIST_FILE) {
6932 for (obj_ptr=botObj; obj_ptr != NULL; obj_ptr=obj_ptr->prev) {
6933 obj_ptr->tmp_parent = NULL;
6934 DumpNetListForAnObj(dumpFP, obj_ptr);
6935 }
6936 } else {
6937 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
6938 whereToPrint != SVG_FILE) || !minimalEPS) {
6939 if (dumpPages) {
6940 fprintf(dumpFP, "%%%%Page: %1d %1d\n\n",
6941 printingPageNum, dumpPageNum);
6942 } else {
6943 fprintf(dumpFP, "%%%%Page: %1d %1d\n\n",
6944 printingPageNum-printingFirstPageNum+1,
6945 printingPageNum-printingFirstPageNum+1);
6946 }
6947 }
6948 if (!minimalEPS) {
6949 DumpBBox(dumpFP, PAGE_BBOX, NULL);
6950 }
6951 if (totalBBoxValid) {
6952 if (topObj != NULL) {
6953 if (llxPage < llxTotal) llxTotal = llxPage;
6954 if (llyPage < llyTotal) llyTotal = llyPage;
6955 if (urxPage > urxTotal) urxTotal = urxPage;
6956 if (uryPage > uryTotal) uryTotal = uryPage;
6957 }
6958 } else if (topObj != NULL) {
6959 totalBBoxValid = TRUE;
6960 llxTotal = llxPage; llyTotal = llyPage;
6961 urxTotal = urxPage; uryTotal = uryPage;
6962 }
6963 if (psBopHookStatus == TRUE && (whereToPrint == PRINTER ||
6964 whereToPrint == PS_FILE || whereToPrint == PDF_FILE)) {
6965 fprintf(dumpFP, "userdict /%s known { %s } if\n\n",
6966 psBopHook, psBopHook);
6967 }
6968 fprintf(dumpFP, "tgifdict begin\n");
6969 fprintf(dumpFP, "/tgifsavedpage save def\n\n");
6970
6971 fprintf(dumpFP, "1 %s\n", gPsCmd[PS_SETMITERLIMIT]);
6972 fprintf(dumpFP, "1 %s\n\n", gPsCmd[PS_SETLINEWIDTH]);
6973 fprintf(dumpFP, "0 %s\n\n", gPsCmd[PS_SETGRAY]);
6974
6975 if (pageStyle == LANDSCAPE) {
6976 fprintf(dumpFP, "90 %s\n", gPsCmd[PS_ROTATE]);
6977 }
6978 fprintf(dumpFP, "%1d %s %s %1d %s %s %s\n", psDotsPerInch,
6979 psXOffStr[pageStyle], gPsCmd[PS_MUL], psDotsPerInch,
6980 psYOffStr[pageStyle], gPsCmd[PS_MUL], gPsCmd[PS_TRANSLATE]);
6981
6982 #ifndef METRIC_PIX_PER_INCH
6983 fprintf(dumpFP, "%1d %1d %s %.3f %s 100 %s %s %s %s\n\n",
6984 psDotsPerInch, PIX_PER_INCH, gPsCmd[PS_DIV], printMag,
6985 gPsCmd[PS_MUL], gPsCmd[PS_DIV], gPsCmd[PS_DUP],
6986 gPsCmd[PS_NEG], gPsCmd[PS_SCALE]);
6987 #else /* METRIC_PIX_PER_INCH */
6988 fprintf(dumpFP, "%1d %1d %s %.3f %s 100 %s %s %s %s\n\n",
6989 psDotsPerInch, (gridSystem==ENGLISH_GRID ? PIX_PER_INCH :
6990 METRIC_PIX_PER_INCH), gPsCmd[PS_DIV], printMag,
6991 gPsCmd[PS_MUL], gPsCmd[PS_DIV], gPsCmd[PS_DUP],
6992 gPsCmd[PS_NEG], gPsCmd[PS_SCALE]);
6993 #endif /* ~METRIC_PIX_PER_INCH */
6994
6995 fprintf(dumpFP, "%s\n\n", gPsCmd[PS_GSAVE]);
6996
6997 if (needsTgifOrigCTM) {
6998 fprintf(dumpFP, "/tgiforigctm matrix currentmatrix def\n\n");
6999 }
7000 if (colorDump && colorBgInPrintingColorPS &&
7001 (whereToPrint == PS_FILE || whereToPrint == PDF_FILE ||
7002 whereToPrint == PRINTER)) {
7003 fprintf(dumpFP, "%% Background\n");
7004 if (myBgColor.red==0 && myBgColor.green==0 && myBgColor.blue==0) {
7005 fprintf(dumpFP, "0 %s\n", gPsCmd[PS_SETGRAY]);
7006 } else if (myBgColor.red==maxRGB && myBgColor.green==maxRGB &&
7007 myBgColor.blue==maxRGB) {
7008 fprintf(dumpFP, "1 %s\n", gPsCmd[PS_SETGRAY]);
7009 } else {
7010 fprintf(dumpFP, "%.3f %.3f %.3f %s\n",
7011 ((float)myBgColor.red/maxRGB),
7012 ((float)myBgColor.green/maxRGB),
7013 ((float)myBgColor.blue/maxRGB), gPsCmd[PS_SETRGBCOLOR]);
7014 }
7015 fprintf(dumpFP, "%s\n", gPsCmd[PS_NEWPATH]);
7016 fprintf(dumpFP,
7017 " 0 0 %s 0 %d %s %d %d %s %d 0 %s\n",
7018 gPsCmd[PS_MOVETO], onePageHeight, gPsCmd[PS_LINETO],
7019 onePageWidth, onePageHeight, gPsCmd[PS_LINETO],
7020 onePageWidth, gPsCmd[PS_LINETO]);
7021 fprintf(dumpFP, "%s %s\n\n", gPsCmd[PS_CLOSEPATH], gPsCmd[PS_FILL]);
7022 }
7023
7024 for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
7025 obj_ptr->tmp_parent = NULL;
7026 DumpAnObj(dumpFP, obj_ptr);
7027 }
7028 fprintf(dumpFP, "%s\n", gPsCmd[PS_GRESTORE]);
7029 fprintf(dumpFP, "tgifsavedpage restore\n");
7030 fprintf(dumpFP, "end\n");
7031
7032 switch (whereToPrint) {
7033 case PRINTER:
7034 case PS_FILE:
7035 case PDF_FILE:
7036 if (psEopHookStatus == TRUE) {
7037 fprintf(dumpFP, "userdict /%s known { %s } if\n",
7038 psEopHook, psEopHook);
7039 }
7040 fprintf(dumpFP, "showpage\n\n");
7041 break;
7042 case EPSI_FILE:
7043 case LATEX_FIG:
7044 case SVG_FILE:
7045 if (showPageInEPS) {
7046 fprintf(dumpFP, "showpage\n");
7047 }
7048 fprintf(dumpFP, "\n");
7049 break;
7050 }
7051 }
7052 } else if (whereToPrint >= MAXDEFWHERETOPRINT) {
7053 if (!ExportVectorFile(dumpFP, dumpOneFilePerPage ||
7054 (dumpOnePageInStackMode && numberFileInPrintOnePage),
7055 printingPageNum, printingFirstPageNum, printingPageRow,
7056 printingPageCol)) {
7057 return FALSE;
7058 }
7059 } else if (whereToPrint == TEXT_FILE) {
7060 for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
7061 obj_ptr->tmp_parent = NULL;
7062 DumpAnObjInAscii(dumpFP, obj_ptr);
7063 }
7064 } else if (whereToPrint == NETLIST_FILE) {
7065 for (obj_ptr=botObj; obj_ptr != NULL; obj_ptr=obj_ptr->prev) {
7066 obj_ptr->tmp_parent = NULL;
7067 DumpNetListForAnObj(dumpFP, obj_ptr);
7068 }
7069 } else {
7070 int row, col;
7071 float one=(float)atof("1.0"), f_rbx, f_rby, x_dist, y_dist;
7072
7073 if (tiledPageScaling == one && !msgAboutTiledPageScalingSeen) {
7074 char msg1[MAXSTRING+1];
7075
7076 msgAboutTiledPageScalingSeen = TRUE;
7077 sprintf(gszMsgBox, TgLoadString(STID_OUTPUT_TRUNC_IN_PRINT_TILED),
7078 TOOL_NAME, "TiledPageScaling");
7079 sprintf(msg1, " %s", TgLoadString(STID_RECOMMEND_REDUCING_SETTING));
7080 if (PRTGIF) {
7081 fprintf(stderr, "%s\n", gszMsgBox);
7082 fprintf(stderr, "%s\n", msg1);
7083 } else {
7084 TwoLineMsg(gszMsgBox, msg1);
7085 }
7086 }
7087 f_rbx = (float)(((float)PIX_PER_INCH) * 100.0 / printMag *
7088 psPageWidthInInch[pageStyle]);
7089 f_rby = (float)(((float)PIX_PER_INCH) * 100.0 / printMag *
7090 psPageHeightInInch[pageStyle]);
7091 x_dist = (float)(((float)PIX_PER_INCH) * psPageWidthInInch[pageStyle] *
7092 (1.0-tiledPageScaling) * 50.0 / printMag);
7093 y_dist = (float)(((float)PIX_PER_INCH) * psPageHeightInInch[pageStyle] *
7094 (1.0-tiledPageScaling) * 50.0 / printMag);
7095
7096 for (row = 0; row < paperRow; row++) {
7097 printingPageRow = row+1;
7098 for (col = 0; col < paperCol; col++) {
7099 struct BBRec page_bbox;
7100 float real_ltx, real_lty;
7101
7102 if (dumpOnePageInTileMode &&
7103 row*paperCol+col+1 != printingPageNum) {
7104 continue;
7105 }
7106 printingPageCol = col+1;
7107 page_bbox.ltx = col * onePageWidth;
7108 page_bbox.lty = row * onePageHeight;
7109 page_bbox.rbx = page_bbox.ltx + onePageWidth;
7110 page_bbox.rby = page_bbox.lty + onePageHeight;
7111
7112 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
7113 whereToPrint != SVG_FILE) || !minimalEPS) {
7114 if (dumpOnePageInTileMode) {
7115 fprintf(dumpFP, "%%%%Page: 1 1\n\n");
7116 } else {
7117 fprintf(dumpFP, "%%%%Page: %1d %1d\n\n",
7118 col+1+row*paperCol, col+1+row*paperCol);
7119 }
7120 }
7121 if (DumpBBox(dumpFP, PAGE_BBOX, &page_bbox)) {
7122 if (totalBBoxValid) {
7123 if (topObj != NULL) {
7124 if (llxPage < llxTotal) llxTotal = llxPage;
7125 if (llyPage < llyTotal) llyTotal = llyPage;
7126 if (urxPage > urxTotal) urxTotal = urxPage;
7127 if (uryPage > uryTotal) uryTotal = uryPage;
7128 }
7129 } else if (topObj != NULL) {
7130 totalBBoxValid = TRUE;
7131 llxTotal = llxPage; llyTotal = llyPage;
7132 urxTotal = urxPage; uryTotal = uryPage;
7133 }
7134 }
7135 if (psBopHookStatus == TRUE && (whereToPrint == PRINTER ||
7136 whereToPrint == PS_FILE || whereToPrint == PDF_FILE)) {
7137 fprintf(dumpFP, "userdict /%s known { %s } if\n\n",
7138 psBopHook, psBopHook);
7139 }
7140 fprintf(dumpFP, "tgifdict begin\n");
7141 fprintf(dumpFP, "/tgifsavedpage save def\n\n");
7142 fprintf(dumpFP, "1 %s\n", gPsCmd[PS_SETMITERLIMIT]);
7143 fprintf(dumpFP, "1 %s\n\n", gPsCmd[PS_SETLINEWIDTH]);
7144 fprintf(dumpFP, "0 %s\n\n", gPsCmd[PS_SETGRAY]);
7145
7146 if (pageStyle == LANDSCAPE) {
7147 fprintf(dumpFP, "90 %s\n", gPsCmd[PS_ROTATE]);
7148 }
7149 fprintf(dumpFP, "%1d %s %s %1d %s %s %s\n",
7150 psDotsPerInch, psXOffStr[pageStyle], gPsCmd[PS_MUL],
7151 psDotsPerInch, psYOffStr[pageStyle], gPsCmd[PS_MUL],
7152 gPsCmd[PS_TRANSLATE]);
7153
7154 #ifndef METRIC_PIX_PER_INCH
7155 fprintf(dumpFP, "%1d %1d %s %.3f %s 100 %s %s %s %s\n\n",
7156 psDotsPerInch, PIX_PER_INCH, gPsCmd[PS_DIV], printMag,
7157 gPsCmd[PS_MUL], gPsCmd[PS_DIV], gPsCmd[PS_DUP],
7158 gPsCmd[PS_NEG], gPsCmd[PS_SCALE]);
7159 #else /* METRIC_PIX_PER_INCH */
7160 fprintf(dumpFP, "%1d %1d %s %.3f %s 100 %s %s %s %s\n\n",
7161 psDotsPerInch, (gridSystem==ENGLISH_GRID ? PIX_PER_INCH :
7162 METRIC_PIX_PER_INCH), gPsCmd[PS_DIV], printMag,
7163 gPsCmd[PS_MUL], gPsCmd[PS_DIV], gPsCmd[PS_DUP],
7164 gPsCmd[PS_NEG], gPsCmd[PS_SCALE]);
7165 #endif /* ~METRIC_PIX_PER_INCH */
7166
7167 fprintf(dumpFP, "%s\n\n", gPsCmd[PS_GSAVE]);
7168
7169 fprintf(dumpFP, "%% SETUP CLIP FOR PAGE\n\n");
7170 fprintf(dumpFP, "%.3f %.3f %s\n", x_dist, y_dist,
7171 gPsCmd[PS_TRANSLATE]);
7172 fprintf(dumpFP, "%.3f %.3f %s\n", tiledPageScaling,
7173 tiledPageScaling, gPsCmd[PS_SCALE]);
7174
7175 fprintf(dumpFP, "-%1d -%1d %s\n", page_bbox.ltx,
7176 page_bbox.lty, gPsCmd[PS_TRANSLATE]);
7177 real_ltx = (float)(((float)col) *
7178 ((float)psPageWidthInInch[pageStyle]) *
7179 ((float)PIX_PER_INCH) * 100.0 / printMag);
7180 real_lty = (float)(((float)row) *
7181 ((float)psPageHeightInInch[pageStyle]) *
7182 ((float)PIX_PER_INCH) * 100.0 / printMag);
7183 if (psRegMarksInTiledPageMode && tiledPageScaling < (float)1.0) {
7184 float stem=((float)(min(x_dist,y_dist)))*((float)0.5);
7185
7186 fprintf(dumpFP, "%s\n", gPsCmd[PS_GSAVE]);
7187 fprintf(dumpFP, " 0.1 %s %.3f %s\n", gPsCmd[PS_SETLINEWIDTH],
7188 psRegMarksGray, gPsCmd[PS_SETGRAY]);
7189
7190 fprintf(dumpFP, " %s %.3f %.3f %s\n", gPsCmd[PS_NEWPATH],
7191 real_ltx, real_lty, gPsCmd[PS_MOVETO]);
7192 DumpRegMark(dumpFP, &stem);
7193 fprintf(dumpFP, " %.3f 0 %s\n", f_rbx, gPsCmd[PS_RMOVETO]);
7194 DumpRegMark(dumpFP, &stem);
7195 fprintf(dumpFP, " 0 %.3f %s\n", f_rby, gPsCmd[PS_RMOVETO]);
7196 DumpRegMark(dumpFP, &stem);
7197 fprintf(dumpFP, " -%.3f 0 %s\n", f_rbx, gPsCmd[PS_RMOVETO]);
7198 DumpRegMark(dumpFP, &stem);
7199
7200 fprintf(dumpFP, "%s\n", gPsCmd[PS_GRESTORE]);
7201 }
7202 fprintf(dumpFP, "%s\n", gPsCmd[PS_NEWPATH]);
7203 fprintf(dumpFP, " %.3f %.3f %s\n", real_ltx, real_lty,
7204 gPsCmd[PS_MOVETO]);
7205 fprintf(dumpFP, " %.3f 0 %s\n", f_rbx, gPsCmd[PS_RLINETO]);
7206 fprintf(dumpFP, " 0 %.3f %s\n", f_rby, gPsCmd[PS_RLINETO]);
7207 fprintf(dumpFP, " -%.3f 0 %s\n", f_rbx, gPsCmd[PS_RLINETO]);
7208 fprintf(dumpFP, "%s %s %s\n\n", gPsCmd[PS_CLOSEPATH],
7209 gPsCmd[PS_CLIP], gPsCmd[PS_NEWPATH]);
7210
7211 if (needsTgifOrigCTM) {
7212 fprintf(dumpFP, "/tgiforigctm matrix currentmatrix def\n\n");
7213 }
7214 if (colorDump && colorBgInPrintingColorPS &&
7215 (whereToPrint == PS_FILE || whereToPrint == PDF_FILE ||
7216 whereToPrint == PRINTER)) {
7217 fprintf(dumpFP, "%% Background\n");
7218 if (myBgColor.red==0 && myBgColor.green==0 &&
7219 myBgColor.blue==0) {
7220 fprintf(dumpFP, "0 %s\n", gPsCmd[PS_SETGRAY]);
7221 } else if (myBgColor.red==maxRGB && myBgColor.green==maxRGB &&
7222 myBgColor.blue==maxRGB) {
7223 fprintf(dumpFP, "1 %s\n", gPsCmd[PS_SETGRAY]);
7224 } else {
7225 fprintf(dumpFP, "%.3f %.3f %.3f %s\n",
7226 ((float)myBgColor.red/maxRGB),
7227 ((float)myBgColor.green/maxRGB),
7228 ((float)myBgColor.blue/maxRGB), gPsCmd[PS_SETRGBCOLOR]);
7229 }
7230 fprintf(dumpFP, "%s\n", gPsCmd[PS_NEWPATH]);
7231 fprintf(dumpFP, " %.3f %.3f %s\n", real_ltx, real_lty,
7232 gPsCmd[PS_MOVETO]);
7233 fprintf(dumpFP, " %.3f 0 %s\n", f_rbx, gPsCmd[PS_LINETO]);
7234 fprintf(dumpFP, " 0 %.3f %s\n", f_rby, gPsCmd[PS_LINETO]);
7235 fprintf(dumpFP, " -%.3f 0 %s\n", f_rbx, gPsCmd[PS_LINETO]);
7236 fprintf(dumpFP, "%s %s %s\n\n", gPsCmd[PS_CLOSEPATH],
7237 gPsCmd[PS_FILL], gPsCmd[PS_NEWPATH]);
7238 }
7239 for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev) {
7240 if (Inside(obj_ptr->bbox, page_bbox) ||
7241 BBoxIntersect(obj_ptr->bbox, page_bbox)) {
7242 obj_ptr->tmp_parent = NULL;
7243 DumpAnObj(dumpFP, obj_ptr);
7244 }
7245 }
7246 fprintf(dumpFP, "%s\n", gPsCmd[PS_GRESTORE]);
7247 fprintf(dumpFP, "tgifsavedpage restore\n");
7248 fprintf(dumpFP, "end\n");
7249
7250 switch (whereToPrint) {
7251 case PRINTER:
7252 case PS_FILE:
7253 case PDF_FILE:
7254 if (psEopHookStatus == TRUE) {
7255 fprintf(dumpFP, "userdict /%s known { %s } if\n",
7256 psEopHook, psEopHook);
7257 }
7258 fprintf(dumpFP, "showpage\n\n");
7259 break;
7260 case EPSI_FILE:
7261 case LATEX_FIG:
7262 case SVG_FILE:
7263 if (showPageInEPS) {
7264 fprintf(dumpFP, "showpage\n");
7265 }
7266 fprintf(dumpFP, "\n");
7267 break;
7268 }
7269 }
7270 }
7271 }
7272 if (dumpPages) {
7273 if (dumpPageNum != gPagesToPrintSpec.num_pages_specified) {
7274 return TRUE;
7275 }
7276 } else if (printingPageNum != printingLastPageNum) {
7277 return TRUE;
7278 }
7279 if (whereToPrint < MAXDEFWHERETOPRINT && whereToPrint != TEXT_FILE &&
7280 whereToPrint != NETLIST_FILE) {
7281 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
7282 whereToPrint != SVG_FILE) || !minimalEPS) {
7283 if (fprintf(dumpFP, "%%%%Trailer\n") == EOF) {
7284 writeFileFailed = TRUE;
7285 }
7286 }
7287 if (pageLayoutMode!=PAGE_STACK ||
7288 printingFirstPageNum!=printingLastPageNum) {
7289 if (fprintf(dumpFP, "%%%%BoundingBox: %1d %1d %1d %1d\n",
7290 llxTotal, llyTotal, urxTotal, uryTotal) == EOF) {
7291 writeFileFailed = TRUE;
7292 }
7293 }
7294 if (fprintf(dumpFP, "%%MatchingCreationDate: %s\n", loc_time) == EOF) {
7295 writeFileFailed = TRUE;
7296 }
7297 if ((whereToPrint != LATEX_FIG && whereToPrint != EPSI_FILE &&
7298 whereToPrint != SVG_FILE) || !minimalEPS) {
7299 DumpDocumentFonts(dumpFP);
7300 DumpPropagatedEPSInfo(dumpFP);
7301 if (fprintf(dumpFP, "%%%%EOF\n") == EOF) writeFileFailed = TRUE;
7302 }
7303 }
7304 fclose(dumpFP);
7305 dumpFP = NULL;
7306
7307 EndGrayDetection();
7308
7309 if (whereToPrint < MAXDEFWHERETOPRINT && whereToPrint != TEXT_FILE &&
7310 whereToPrint != NETLIST_FILE && !totalBBoxValid) {
7311 strcpy(gszMsgBox, TgLoadString(STID_NO_OBJ_TO_PRINT));
7312 if (PRTGIF) {
7313 fprintf(stderr, "%s\n", gszMsgBox);
7314 } else {
7315 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7316 }
7317 return FALSE;
7318 }
7319 if (writeFileFailed) {
7320 writeFileFailed = FALSE;
7321 FailToWriteFileMessage(tmpFile);
7322 #ifdef KEEP_WHEN_PRINT
7323 if (whereToPrint != PRINTER) unlink(tmpFile);
7324 #else
7325 unlink(tmpFile);
7326 #endif
7327 return FALSE;
7328 }
7329 if (preDumpSetup && whereToPrint != NETLIST_FILE) {
7330 unlink(tmpFile);
7331 return TRUE;
7332 }
7333 switch (whereToPrint) {
7334 case PRINTER:
7335 #ifdef VMS
7336 #define PRINT_TRAILER ""
7337 #else
7338 #define PRINT_TRAILER " 2>&1"
7339 #endif
7340 if (PRTGIF) {
7341 /* do not translate -- program constants */
7342 if (strstr(printCommand, "%s") == NULL) {
7343 if (lastFile) {
7344 sprintf(cmd, "%s %s", printCommand, tmpFile);
7345 } else {
7346 sprintf(cmd, "%s -h %s", printCommand, tmpFile);
7347 }
7348 } else {
7349 sprintf(cmd, printCommand, tmpFile);
7350 }
7351 if (strcmp(printCommand, "cat") != 0) {
7352 strcat(cmd, PRINT_TRAILER);
7353 }
7354 fprintf(stderr, "%s\n", cmd);
7355 } else {
7356 if (strstr(printCommand, "%s") == NULL) {
7357 sprintf(cmd, "%s %s", printCommand, tmpFile);
7358 } else {
7359 sprintf(cmd, printCommand, tmpFile);
7360 }
7361 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_WITH_GIVEN_CMD),
7362 printCommand);
7363 if (strcmp(printCommand, "cat") != 0) {
7364 strcat(cmd, PRINT_TRAILER);
7365 }
7366 Msg(gszMsgBox);
7367 }
7368 if (strcmp(printCommand, "cat") == 0) {
7369 /*
7370 * Well, you can't really "cat" to a printer (without piping to
7371 * anything else), so you must mean "catting" to stdout!
7372 */
7373 FILE *pfp=NULL;
7374
7375 sprintf(gszMsgBox, TgLoadCachedString(CSTID_EXECUTING_GIVEN_PROGRAM),
7376 cmd);
7377 SetStringStatus(gszMsgBox);
7378 if (!PRTGIF) XSync(mainDisplay, False);
7379 if ((pfp=(FILE*)popen(cmd, "r")) == NULL) return FALSE;
7380
7381 while (fgets(gszMsgBox, sizeof(gszMsgBox)-1, pfp) != NULL) {
7382 printf("%s", gszMsgBox);
7383 }
7384 pclose(pfp);
7385 SetStringStatus(TgLoadCachedString(CSTID_DOTS_DONE));
7386 } else if (!ExecuteCmd(cmd, FALSE)) {
7387 if (PRTGIF) {
7388 fprintf(stderr, TgLoadString(STID_CANNOT_EXEC_ABORT_PRINT), cmd);
7389 fprintf(stderr, "\n");
7390 } else {
7391 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_EXEC_ABORT_PRINT), cmd);
7392 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7393 }
7394 unlink(tmpFile);
7395 return FALSE;
7396 }
7397 if (PRTGIF) {
7398 fprintf(stderr, TgLoadString(STID_NAMED_FILE_PRINTED), tmpFile);
7399 fprintf(stderr, "\n");
7400 } else {
7401 Msg(TgLoadString(STID_PRINT_COMPLETED));
7402 }
7403 break;
7404 case EPSI_FILE:
7405 case LATEX_FIG:
7406 case SVG_FILE:
7407 case PS_FILE:
7408 case PDF_FILE:
7409 switch (whereToPrint) {
7410 case EPSI_FILE:
7411 if (*epsiExportExtension == '\0') {
7412 file_ext = EPSF_FILE_EXT;
7413 } else {
7414 file_ext = epsiExportExtension;
7415 }
7416 output_type = "EPSI";
7417 break;
7418 case LATEX_FIG:
7419 file_ext = EPSF_FILE_EXT;
7420 output_type = "EPS";
7421 break;
7422 case SVG_FILE:
7423 file_ext = EPSF_FILE_EXT;
7424 output_type = "SVG";
7425 break;
7426 case PS_FILE:
7427 file_ext = PS_FILE_EXT;
7428 output_type = "PostScript";
7429 break;
7430 case PDF_FILE:
7431 file_ext = "p~f";
7432 output_type = "PDF";
7433 break;
7434 }
7435 if (PRTGIF) {
7436 SetOutputFileName(ps_file, file_ext, NULL, &FileName);
7437 } else {
7438 if (!curFileDefined) {
7439 sprintf(gszMsgBox, TgLoadString(STID_NO_CUR_FILE_CANNOT_GEN_FORMAT),
7440 output_type);
7441 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7442 unlink(tmpFile);
7443 return FALSE;
7444 }
7445 SetOutputFileName(ps_file, file_ext, &short_name, &rest);
7446 if (short_name && *outputDir=='\0') {
7447 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7448 rest);
7449 } else {
7450 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7451 ps_file);
7452 }
7453 Msg(gszMsgBox);
7454 }
7455 if (whereToPrint == EPSI_FILE && generateTiffEPSI) {
7456 int saved_colordump=colorDump, consensed_already=FALSE, ok=TRUE;
7457
7458 SaveStatusStrings();
7459 SetStringStatus(TgLoadString(STID_GENERATING_TIFF_PREVIEW_BMP));
7460
7461 colorDump = FALSE;
7462 DumpXBitmapFile(FALSE, FALSE, FALSE);
7463 colorDump = saved_colordump;
7464
7465 if (psUseShortHand && !dontCondense) {
7466 if (CondensePostScriptFile(tmpFile, sizeof(tmpFile))) {
7467 consensed_already = TRUE;
7468 } else {
7469 ok = FALSE;
7470 }
7471 }
7472 if (ok) {
7473 GenTiffFile(tmpFile, ps_file, psUseShortHand, consensed_already);
7474 }
7475 RestoreStatusStrings();
7476 unlink(tmpFile);
7477 } else if (whereToPrint == PDF_FILE) {
7478 char real_ps_file[MAXSTRING+1];
7479
7480 if (!CopyAFile(tmpFile, (PRTGIF && cmdLineStdOut) ? NULL : ps_file,
7481 psUseShortHand)) {
7482 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_NOT_GENERATED),
7483 output_type);
7484 if (PRTGIF) {
7485 fprintf(stderr, "%s\n", gszMsgBox);
7486 } else {
7487 Msg(gszMsgBox);
7488 }
7489 unlink(tmpFile);
7490 return FALSE;
7491 }
7492 UtilStrCpyN(real_ps_file, sizeof(real_ps_file), ps_file);
7493 if (PRTGIF) {
7494 SetOutputFileName(ps_file, pdfExportExtension, NULL, &FileName);
7495 } else {
7496 SetOutputFileName(ps_file, pdfExportExtension, &short_name,
7497 &rest);
7498 if (short_name && *outputDir=='\0') {
7499 sprintf(gszMsgBox,
7500 TgLoadString(STID_CONVERTING_INTO_NAMED_FILE), rest);
7501 } else {
7502 sprintf(gszMsgBox,
7503 TgLoadString(STID_CONVERTING_INTO_NAMED_FILE), ps_file);
7504 }
7505 Msg(gszMsgBox);
7506 }
7507 /* actually, ps_file contains the full path to the PDF file */
7508 sprintf(cmd, psToPdfCmd, real_ps_file, ps_file);
7509 if (!ExecuteCmd(cmd, FALSE)) {
7510 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_EXEC_FORMAT_NOT_GEN),
7511 cmd, output_type);
7512 if (PRTGIF) {
7513 fprintf(stderr, "%s\n", gszMsgBox);
7514 } else {
7515 Msg(gszMsgBox);
7516 }
7517 unlink(real_ps_file);
7518 unlink(tmpFile);
7519 return FALSE;
7520 }
7521 unlink(real_ps_file);
7522 } else if (whereToPrint == SVG_FILE) {
7523 char sk_fname[MAXPATHLENGTH], svg_fname[MAXPATHLENGTH];
7524 char eps_fname[MAXPATHLENGTH];
7525
7526 /* ps_file contains the full path to an EPS file */
7527 *sk_fname = *svg_fname = *eps_fname = '\0';
7528 snprintf(sk_fname, sizeof(sk_fname), "%s.sk", tmpFile);
7529 snprintf(svg_fname, sizeof(svg_fname), "%s.svg", tmpFile);
7530 snprintf(eps_fname, sizeof(eps_fname), "%s.eps", tmpFile);
7531 unlink(sk_fname);
7532 unlink(svg_fname);
7533 unlink(eps_fname);
7534
7535 if (!CopyAFile(tmpFile, (PRTGIF && cmdLineStdOut) ? NULL : eps_fname,
7536 psUseShortHand)) {
7537 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_NOT_GENERATED),
7538 output_type);
7539 if (PRTGIF) {
7540 fprintf(stderr, "%s\n", gszMsgBox);
7541 } else {
7542 Msg(gszMsgBox);
7543 }
7544 unlink(tmpFile);
7545 return FALSE;
7546 }
7547 if (PRTGIF) {
7548 SetOutputFileName(ps_file, "svg", NULL, &FileName);
7549 } else {
7550 SetOutputFileName(ps_file, "svg", &short_name, &rest);
7551 if (short_name && *outputDir=='\0') {
7552 sprintf(gszMsgBox,
7553 TgLoadString(STID_CONVERTING_INTO_NAMED_FILE), rest);
7554 } else {
7555 sprintf(gszMsgBox,
7556 TgLoadString(STID_CONVERTING_INTO_NAMED_FILE), ps_file);
7557 }
7558 Msg(gszMsgBox);
7559 }
7560 sprintf(cmd, epsToTmpSvgCmd, eps_fname, sk_fname);
7561 if (!ExecuteCmd(cmd, FALSE)) {
7562 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_EXEC_FORMAT_NOT_GEN),
7563 cmd, output_type);
7564 if (PRTGIF) {
7565 fprintf(stderr, "%s\n", gszMsgBox);
7566 } else {
7567 Msg(gszMsgBox);
7568 }
7569 unlink(eps_fname);
7570 unlink(tmpFile);
7571 return FALSE;
7572 }
7573 unlink(eps_fname);
7574
7575 sprintf(cmd, tmpSvgToSvgCmd, sk_fname, svg_fname);
7576 if (!ExecuteCmd(cmd, FALSE)) {
7577 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_EXEC_FORMAT_NOT_GEN),
7578 cmd, output_type);
7579 if (PRTGIF) {
7580 fprintf(stderr, "%s\n", gszMsgBox);
7581 } else {
7582 Msg(gszMsgBox);
7583 }
7584 unlink(sk_fname);
7585 unlink(tmpFile);
7586 return FALSE;
7587 }
7588 unlink(sk_fname);
7589
7590 if (!FixUpSVGFile(svg_fname, ps_file)) {
7591 unlink(svg_fname);
7592 unlink(tmpFile);
7593 return FALSE;
7594 }
7595 unlink(svg_fname);
7596 /* at this point, ps_file contains the full path to the SVG file */
7597 } else {
7598 if (!CopyAFile(tmpFile, (PRTGIF && cmdLineStdOut) ? NULL : ps_file,
7599 psUseShortHand)) {
7600 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_NOT_GENERATED),
7601 output_type);
7602 if (PRTGIF) {
7603 fprintf(stderr, "%s\n", gszMsgBox);
7604 } else {
7605 Msg(gszMsgBox);
7606 }
7607 unlink(tmpFile);
7608 return FALSE;
7609 }
7610 }
7611 if (tmpFileMode != 0 && chmod(ps_file, tmpFileMode)) {
7612 if (PRTGIF) {
7613 fprintf(stderr, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7614 tmpFileMode);
7615 fprintf(stderr, "\n");
7616 } else {
7617 if (short_name && *outputDir=='\0') {
7618 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), rest,
7619 tmpFileMode);
7620 } else {
7621 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7622 tmpFileMode);
7623 }
7624 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7625 }
7626 }
7627 if (PRTGIF) {
7628 if (!cmdLineStdOut && !cmdLineQuiet) {
7629 fprintf(stderr, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7630 output_type, ps_file);
7631 fprintf(stderr, "\n");
7632 }
7633 } else {
7634 if (short_name && *outputDir=='\0') {
7635 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7636 output_type, rest);
7637 } else {
7638 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7639 output_type, ps_file);
7640 }
7641 Msg(gszMsgBox);
7642 }
7643 break;
7644 case TEXT_FILE:
7645 if (PRTGIF) {
7646 SetOutputFileName(ps_file, TEXT_FILE_EXT, NULL, &FileName);
7647 } else {
7648 if (!curFileDefined) {
7649 sprintf(gszMsgBox, TgLoadString(STID_NO_CUR_FILE_CANNOT_GEN_TEXT));
7650 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7651 unlink(tmpFile);
7652 return FALSE;
7653 }
7654 SetOutputFileName(ps_file, TEXT_FILE_EXT, &short_name, &rest);
7655 if (short_name && *outputDir=='\0') {
7656 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7657 rest);
7658 } else {
7659 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7660 ps_file);
7661 }
7662 Msg(gszMsgBox);
7663 }
7664 if (!CopyAFile(tmpFile, (PRTGIF && cmdLineStdOut) ? NULL : ps_file,
7665 FALSE)) {
7666 if (PRTGIF) {
7667 fprintf(stderr, "%s\n", TgLoadString(STID_TEXT_OUTPUT_NOT_GEN));
7668 } else {
7669 Msg(TgLoadString(STID_TEXT_OUTPUT_NOT_GEN));
7670 }
7671 unlink(tmpFile);
7672 return FALSE;
7673 }
7674 if (tmpFileMode != 0 && chmod(ps_file, tmpFileMode)) {
7675 if (PRTGIF) {
7676 fprintf(stderr, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7677 tmpFileMode);
7678 } else {
7679 if (short_name && *outputDir=='\0') {
7680 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), rest,
7681 tmpFileMode);
7682 } else {
7683 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7684 tmpFileMode);
7685 }
7686 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7687 }
7688 }
7689 if (PRTGIF) {
7690 if (!cmdLineStdOut && !cmdLineQuiet) {
7691 fprintf(stderr, TgLoadString(STID_TEXT_PRINTED_INTO_NAMED_FILE),
7692 ps_file);
7693 fprintf(stderr, "\n");
7694 }
7695 } else {
7696 if (short_name && *outputDir=='\0') {
7697 sprintf(gszMsgBox, TgLoadString(STID_TEXT_PRINTED_INTO_NAMED_FILE),
7698 rest);
7699 } else {
7700 sprintf(gszMsgBox, TgLoadString(STID_TEXT_PRINTED_INTO_NAMED_FILE),
7701 ps_file);
7702 }
7703 Msg(gszMsgBox);
7704 }
7705 break;
7706 default:
7707 /*
7708 * whereToPrint >= MAXDEFWHERETOPRINT or whereToPrint == NETLIST_FILE
7709 */
7710 if (PRTGIF) {
7711 SetOutputFileName(ps_file, GetExportExt(whereToPrint), NULL,
7712 &FileName);
7713 } else {
7714 if (!curFileDefined) {
7715 sprintf(gszMsgBox, TgLoadString(STID_NO_CUR_FILE_CANNOT_GEN_FORMAT),
7716 GetExportName(whereToPrint, EXPORT_THIS));
7717 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7718 unlink(tmpFile);
7719 return FALSE;
7720 }
7721 SetOutputFileName(ps_file, GetExportExt(whereToPrint), &short_name,
7722 &rest);
7723 if (short_name && *outputDir=='\0') {
7724 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7725 rest);
7726 } else {
7727 sprintf(gszMsgBox, TgLoadString(STID_PRINTING_INTO_NAMED_FILE),
7728 ps_file);
7729 }
7730 Msg(gszMsgBox);
7731 }
7732 if (!CopyAFile(tmpFile, (PRTGIF && cmdLineStdOut) ? NULL : ps_file,
7733 FALSE)) {
7734 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_NOT_GENERATED),
7735 GetExportName(whereToPrint, EXPORT_THIS));
7736 if (PRTGIF) {
7737 fprintf(stderr, "%s\n", gszMsgBox);
7738 } else {
7739 Msg(gszMsgBox);
7740 }
7741 unlink(tmpFile);
7742 return FALSE;
7743 }
7744 if (tmpFileMode != 0 && chmod(ps_file, tmpFileMode)) {
7745 if (PRTGIF) {
7746 fprintf(stderr, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7747 tmpFileMode);
7748 } else {
7749 if (short_name && *outputDir=='\0') {
7750 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), rest,
7751 tmpFileMode);
7752 } else {
7753 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_CHMOD), ps_file,
7754 tmpFileMode);
7755 }
7756 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
7757 }
7758 }
7759 if (PRTGIF) {
7760 if (!cmdLineStdOut && !cmdLineQuiet) {
7761 fprintf(stderr, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7762 GetExportName(whereToPrint, EXPORT_THIS), ps_file);
7763 fprintf(stderr, "\n");
7764 }
7765 } else {
7766 if (short_name && *outputDir=='\0') {
7767 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7768 GetExportName(whereToPrint, EXPORT_THIS), rest);
7769 } else {
7770 sprintf(gszMsgBox, TgLoadString(STID_FORMAT_FILE_PRINTED_INTO),
7771 GetExportName(whereToPrint, EXPORT_THIS), ps_file);
7772 }
7773 Msg(gszMsgBox);
7774 }
7775 break;
7776 }
7777 #ifdef KEEP_WHEN_PRINT
7778 if (whereToPrint != PRINTER) {
7779 unlink(tmpFile);
7780 }
7781 #else
7782 unlink(tmpFile);
7783 #endif
7784 return TRUE;
7785 }
7786
7787 static
GenDump(FileName)7788 int GenDump(FileName)
7789 char *FileName;
7790 {
7791 int rc=INVALID, saved_where_to_print=whereToPrint;
7792 static int saved_dont_condense=INVALID;
7793
7794 if (preDumpSetup) {
7795 CleanUpPropagatedEPSInfo();
7796 saved_dont_condense = dontCondense;
7797 hasReadHexString = FALSE;
7798 }
7799 xpmHasTooManyColorsForPrinting = FALSE;
7800 if (whereToPrint == TIFFEPSI_FILE) {
7801 whereToPrint = EPSI_FILE;
7802 generateTiffEPSI = TRUE;
7803 }
7804 SaveStatusStrings();
7805 rc = DoGenDump(FileName);
7806 RestoreStatusStrings();
7807 if (saved_where_to_print == TIFFEPSI_FILE) {
7808 whereToPrint = TIFFEPSI_FILE;
7809 generateTiffEPSI = FALSE;
7810 }
7811 if (preDumpSetup && hasReadHexString) {
7812 if (!dontCondense) {
7813 strcpy(gszMsgBox, TgLoadString(STID_WONT_CONDENSE_READHEXSTRING));
7814 if (PRTGIF) {
7815 fprintf(stderr, "%s\n", gszMsgBox);
7816 } else {
7817 Msg(gszMsgBox);
7818 }
7819 }
7820 dontCondense = TRUE;
7821 }
7822 if (!preDumpSetup && xpmHasTooManyColorsForPrinting) {
7823 MsgBox(TgLoadString(STID_TOO_MANY_COLOR_FOR_XPM_EXPORT), TOOL_NAME,
7824 INFO_MB);
7825 }
7826 if (!preDumpSetup) {
7827 if (hasReadHexString) {
7828 dontCondense = saved_dont_condense;
7829 hasReadHexString = FALSE;
7830 }
7831 CleanUpPropagatedEPSInfo();
7832 }
7833 return rc;
7834 }
7835
Dump(FileName)7836 void Dump(FileName)
7837 char *FileName;
7838 {
7839 int ok=TRUE;
7840 struct PageRec *saved_cur_page;
7841
7842 if ((whereToPrint == LATEX_FIG || whereToPrint == EPSI_FILE ||
7843 whereToPrint == TIFFEPSI_FILE || whereToPrint == SVG_FILE) &&
7844 pageLayoutMode == PAGE_TILE && (paperCol != 1 || paperRow != 1)) {
7845 strcpy(gszMsgBox, TgLoadString(STID_CANNOT_PRINT_EPS_TILED_PAGE));
7846 if (PRTGIF) {
7847 fprintf(stderr, "%s\n", gszMsgBox);
7848 } else {
7849 MsgBox(TgLoadString(STID_CANNOT_PRINT_EPS_TILED_PAGE), TOOL_NAME,
7850 INFO_MB);
7851 }
7852 return;
7853 }
7854 if (PRTGIF) {
7855 RemoveFileNameExtension(FileName);
7856 if (cmdLineOneFilePerPage ||
7857 (cmdLineHasPageNum && pageLayoutMode==PAGE_STACK &&
7858 (whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
7859 whereToPrint==PRINTER))) {
7860 totalBBoxValid = FALSE;
7861 printingFirstPageNum = printingPageNum = printingLastPageNum =
7862 curPageNum;
7863 dumpOnePageInStackMode = TRUE;
7864 }
7865 } else {
7866 HighLightReverse();
7867 SetWatchCursor(drawWindow);
7868 SetWatchCursor(mainWindow);
7869 }
7870 totalBBoxValid = FALSE;
7871 if (whereToPrint == PRINTER || whereToPrint == PS_FILE ||
7872 whereToPrint == PDF_FILE || whereToPrint == TEXT_FILE ||
7873 whereToPrint == NETLIST_FILE || (whereToPrint >= MAXDEFWHERETOPRINT &&
7874 (GetExportFilterCapability(whereToPrint) & TGEF_CAP_MULTI_PAGE) !=
7875 0)) {
7876 if (PRTGIF && (cmdLineOneFilePerPage || (cmdLineHasPageNum &&
7877 pageLayoutMode==PAGE_STACK && (whereToPrint==PS_FILE ||
7878 whereToPrint==PDF_FILE || whereToPrint==PRINTER)))) {
7879 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
7880 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
7881 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
7882 whereToPrint==NETLIST_FILE || whereToPrint==SVG_FILE) {
7883 ResetPSInfo();
7884 CacheColorsForPrinting();
7885
7886 ok = GenDump(FileName);
7887
7888 DoneResetPSInfo();
7889 }
7890 if (ok) GenDump(FileName);
7891 CleanUpCachedColorsForPrinting();
7892 } else {
7893 XColor *saved_tgif_colors=tgifColors;
7894
7895 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
7896
7897 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
7898 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
7899 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
7900 whereToPrint==NETLIST_FILE || whereToPrint==SVG_FILE) {
7901 ResetPSInfo();
7902 CacheColorsForPrinting();
7903
7904 printingFirstPageNum = 1;
7905 printingPageNum = 1;
7906 printingLastPageNum = lastPageNum;
7907 saved_cur_page = curPage;
7908 SaveStatusStrings();
7909 for (curPage=firstPage; ok && curPage != NULL;
7910 curPage=curPage->next, printingPageNum++) {
7911 topObj = curPage->top;
7912 botObj = curPage->bot;
7913 sprintf(gszMsgBox, TgLoadString(STID_PREPROCESS_PAGE_OF),
7914 printingPageNum, lastPageNum);
7915 SetStringStatus(gszMsgBox);
7916 ok = GenDump(FileName);
7917 }
7918 RestoreStatusStrings();
7919 curPage = saved_cur_page;
7920 topObj = curPage->top;
7921 botObj = curPage->bot;
7922
7923 DoneResetPSInfo();
7924 }
7925 printingFirstPageNum = 1;
7926 printingPageNum = 1;
7927 printingLastPageNum = lastPageNum;
7928 saved_cur_page = curPage;
7929 SaveStatusStrings();
7930 for (curPage=firstPage; ok && curPage != NULL;
7931 curPage=curPage->next, printingPageNum++) {
7932 topObj = curPage->top;
7933 botObj = curPage->bot;
7934 sprintf(gszMsgBox, TgLoadString(STID_GENERATING_PAGE_OF),
7935 printingPageNum, lastPageNum);
7936 SetStringStatus(gszMsgBox);
7937 ok = GenDump(FileName);
7938 }
7939 CleanUpCachedColorsForPrinting();
7940 RestoreStatusStrings();
7941 curPage = saved_cur_page;
7942 topObj = curPage->top;
7943 botObj = curPage->bot;
7944
7945 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
7946 }
7947 } else {
7948 XColor *saved_tgif_colors=tgifColors;
7949
7950 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
7951
7952 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
7953 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
7954 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
7955 whereToPrint==SVG_FILE) {
7956 ResetPSInfo();
7957 CacheColorsForPrinting();
7958
7959 printingFirstPageNum = 1;
7960 printingPageNum = 1;
7961 printingLastPageNum = 1;
7962 ok = GenDump(FileName);
7963
7964 DoneResetPSInfo();
7965 }
7966 printingFirstPageNum = 1;
7967 printingPageNum = 1;
7968 printingLastPageNum = 1;
7969 if (ok) GenDump(FileName);
7970 CleanUpCachedColorsForPrinting();
7971
7972 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
7973 }
7974 if (PRTGIF) {
7975 if (cmdLineOneFilePerPage || (cmdLineHasPageNum &&
7976 pageLayoutMode==PAGE_STACK && (whereToPrint==PS_FILE ||
7977 whereToPrint==PDF_FILE || whereToPrint==PRINTER))) {
7978 dumpOnePageInStackMode = FALSE;
7979 }
7980 } else {
7981 SetDefaultCursor(mainWindow);
7982 ShowCursor();
7983 HighLightForward();
7984 }
7985 }
7986
DumpPages()7987 void DumpPages()
7988 {
7989 struct PageRec *saved_cur_page=NULL;
7990 int ok=TRUE;
7991 XColor *saved_tgif_colors=tgifColors;
7992
7993 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
7994
7995 SetWatchCursor(drawWindow);
7996 SetWatchCursor(mainWindow);
7997
7998 ResetPSInfo();
7999 CacheColorsForPrinting();
8000
8001 printingFirstPageNum = INVALID;
8002 printingPageNum = 1;
8003 printingLastPageNum = lastPageNum;
8004 saved_cur_page = curPage;
8005 totalBBoxValid = FALSE;
8006 SaveStatusStrings();
8007 for (curPage=firstPage; ok && curPage != NULL; curPage=curPage->next,
8008 printingPageNum++) {
8009 if (gPagesToPrintSpec.page_specified[printingPageNum-1]) {
8010 if (printingFirstPageNum == INVALID) {
8011 printingFirstPageNum = printingPageNum;
8012 }
8013 topObj = curPage->top;
8014 botObj = curPage->bot;
8015 sprintf(gszMsgBox, TgLoadString(STID_PREPROCESS_PAGE_OF),
8016 printingPageNum, lastPageNum);
8017 SetStringStatus(gszMsgBox);
8018 ok = GenDump("");
8019 }
8020 }
8021 RestoreStatusStrings();
8022 curPage = saved_cur_page;
8023 topObj = curPage->top;
8024 botObj = curPage->bot;
8025
8026 DoneResetPSInfo();
8027
8028 dumpPages = TRUE;
8029 dumpPageNum = 0;
8030 printingFirstPageNum = INVALID;
8031 printingPageNum = 1;
8032 printingLastPageNum = lastPageNum;
8033 saved_cur_page = curPage;
8034 totalBBoxValid = FALSE;
8035 SaveStatusStrings();
8036 for (curPage=firstPage; ok && curPage != NULL; curPage=curPage->next,
8037 printingPageNum++) {
8038 if (gPagesToPrintSpec.page_specified[printingPageNum-1]) {
8039 if (printingFirstPageNum == INVALID) {
8040 printingFirstPageNum = printingPageNum;
8041 }
8042 dumpPageNum++;
8043 topObj = curPage->top;
8044 botObj = curPage->bot;
8045 sprintf(gszMsgBox, TgLoadString(STID_GENERATING_PAGE_OF),
8046 printingPageNum, lastPageNum);
8047 SetStringStatus(gszMsgBox);
8048 ok = GenDump("");
8049 }
8050 }
8051 CleanUpCachedColorsForPrinting();
8052 RestoreStatusStrings();
8053 curPage = saved_cur_page;
8054 topObj = curPage->top;
8055 botObj = curPage->bot;
8056
8057 dumpPages = FALSE;
8058 dumpPageNum = INVALID;
8059
8060 SetDefaultCursor(mainWindow);
8061 ShowCursor();
8062
8063 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8064 }
8065
DumpOnePageInTileMode(row,col)8066 void DumpOnePageInTileMode(row, col)
8067 int row, col;
8068 {
8069 int ok=TRUE;
8070 XColor *saved_tgif_colors=tgifColors;
8071
8072 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
8073
8074 SetWatchCursor(drawWindow);
8075 SetWatchCursor(mainWindow);
8076
8077 totalBBoxValid = FALSE;
8078 printingFirstPageNum = printingPageNum = printingLastPageNum =
8079 row*paperCol+col+1;
8080 dumpOnePageInTileMode = TRUE;
8081 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
8082 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
8083 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
8084 whereToPrint==SVG_FILE) {
8085 ResetPSInfo();
8086 CacheColorsForPrinting();
8087 ok = GenDump("");
8088 DoneResetPSInfo();
8089 }
8090 if (ok) GenDump("");
8091 CleanUpCachedColorsForPrinting();
8092 dumpOnePageInTileMode = FALSE;
8093
8094 SetDefaultCursor(mainWindow);
8095 ShowCursor();
8096
8097 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8098 }
8099
DumpOnePageInStackMode()8100 void DumpOnePageInStackMode()
8101 {
8102 int ok=TRUE;
8103 XColor *saved_tgif_colors=tgifColors;
8104
8105 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
8106
8107 SetWatchCursor(drawWindow);
8108 SetWatchCursor(mainWindow);
8109
8110 totalBBoxValid = FALSE;
8111 printingFirstPageNum = printingPageNum = printingLastPageNum = curPageNum;
8112 dumpOnePageInStackMode = TRUE;
8113 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
8114 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
8115 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
8116 whereToPrint==SVG_FILE) {
8117 ResetPSInfo();
8118 CacheColorsForPrinting();
8119 ok = GenDump("");
8120 DoneResetPSInfo();
8121 }
8122 if (ok) GenDump("");
8123 CleanUpCachedColorsForPrinting();
8124 dumpOnePageInStackMode = FALSE;
8125
8126 SetDefaultCursor(mainWindow);
8127 ShowCursor();
8128
8129 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8130 }
8131
DumpOneFilePerPage()8132 void DumpOneFilePerPage()
8133 {
8134 int ok=TRUE, saved_cur_page_num=curPageNum;
8135 XColor *saved_tgif_colors=tgifColors;
8136
8137 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
8138
8139 SetWatchCursor(drawWindow);
8140 SetWatchCursor(mainWindow);
8141
8142 dumpOneFilePerPage = TRUE;
8143 dumpOnePageInStackMode = TRUE;
8144 for (curPageNum=1; ok && curPageNum <= lastPageNum; curPageNum++) {
8145 totalBBoxValid = FALSE;
8146 GotoPageNum(curPageNum);
8147 ShowPage();
8148 XSync(mainDisplay, False);
8149
8150 printingFirstPageNum = printingPageNum = printingLastPageNum = curPageNum;
8151 if (gPagesToPrintSpec.page_specified[curPageNum-1]) {
8152 if (whereToPrint==LATEX_FIG || whereToPrint==PS_FILE ||
8153 whereToPrint==PDF_FILE || whereToPrint==EPSI_FILE ||
8154 whereToPrint==TIFFEPSI_FILE || whereToPrint==SVG_FILE) {
8155 ResetPSInfo();
8156 CacheColorsForPrinting();
8157 ok = GenDump("");
8158 DoneResetPSInfo();
8159 if (ok) ok = GenDump("");
8160 CleanUpCachedColorsForPrinting();
8161 } else {
8162 ok = GenDump("");
8163 }
8164 }
8165 }
8166 dumpOnePageInStackMode = FALSE;
8167 dumpOneFilePerPage = FALSE;
8168
8169 SetDefaultCursor(mainWindow);
8170 ShowCursor();
8171
8172 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8173
8174 if (!ok && curPageNum <= lastPageNum) {
8175 if (curPageNum == lastPageNum) {
8176 sprintf(gszMsgBox, TgLoadString(STID_GIVEN_PAGE_NOT_GENERATED),
8177 lastPageNum);
8178 } else {
8179 sprintf(gszMsgBox, TgLoadString(STID_PAGE_RANGE_NOT_GENERATED),
8180 curPageNum, lastPageNum);
8181 }
8182 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
8183 }
8184 if (saved_cur_page_num != curPageNum) {
8185 GotoPageNum(saved_cur_page_num);
8186 ClearAndRedrawDrawWindow();
8187 ShowPage();
8188 }
8189 }
8190
PrintWithCommand(FileName)8191 void PrintWithCommand(FileName)
8192 char *FileName;
8193 {
8194 struct PageRec *saved_cur_page=NULL;
8195 int ok=TRUE;
8196 XColor *saved_tgif_colors=tgifColors;
8197
8198 if (whereToPrint != PRINTER) {
8199 MsgBox(TgLoadString(STID_PRINTWITHCMD_WORKS_PRINTER), TOOL_NAME, INFO_MB);
8200 return;
8201 }
8202 Dialog(TgLoadString(STID_ENTER_PRINT_CMD_NAME),
8203 TgLoadCachedString(CSTID_DLG_ACCEPT_CANCEL), printCommand);
8204 if (*printCommand == '\0') return;
8205
8206 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
8207
8208 SetWatchCursor(drawWindow);
8209 SetWatchCursor(mainWindow);
8210
8211 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
8212 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
8213 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
8214 whereToPrint==SVG_FILE) {
8215 ResetPSInfo();
8216 CacheColorsForPrinting();
8217
8218 printingPageNum = 1;
8219 printingLastPageNum = lastPageNum;
8220 saved_cur_page = curPage;
8221 totalBBoxValid = FALSE;
8222 SaveStatusStrings();
8223 for (curPage=firstPage; ok && curPage != NULL; curPage=curPage->next,
8224 printingPageNum++) {
8225 topObj = curPage->top;
8226 botObj = curPage->bot;
8227 sprintf(gszMsgBox, TgLoadString(STID_PREPROCESS_PAGE_OF),
8228 printingPageNum, lastPageNum);
8229 SetStringStatus(gszMsgBox);
8230 ok = GenDump(FileName);
8231 }
8232 RestoreStatusStrings();
8233 curPage = saved_cur_page;
8234 topObj = curPage->top;
8235 botObj = curPage->bot;
8236
8237 DoneResetPSInfo();
8238 }
8239 printingPageNum = 1;
8240 printingLastPageNum = lastPageNum;
8241 saved_cur_page = curPage;
8242 totalBBoxValid = FALSE;
8243 SaveStatusStrings();
8244 for (curPage=firstPage; ok && curPage != NULL; curPage=curPage->next,
8245 printingPageNum++) {
8246 topObj = curPage->top;
8247 botObj = curPage->bot;
8248 sprintf(gszMsgBox, TgLoadString(STID_GENERATING_PAGE_OF), printingPageNum,
8249 lastPageNum);
8250 SetStringStatus(gszMsgBox);
8251 ok = GenDump(FileName);
8252 }
8253 CleanUpCachedColorsForPrinting();
8254 RestoreStatusStrings();
8255 curPage = saved_cur_page;
8256 topObj = curPage->top;
8257 botObj = curPage->bot;
8258
8259 SetDefaultCursor(mainWindow);
8260 ShowCursor();
8261
8262 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8263 }
8264
PrintSelectedObjs()8265 void PrintSelectedObjs()
8266 {
8267 struct SelRec *top_sel_ptr, *bot_sel_ptr, *sel_ptr, *next_sel;
8268 struct ObjRec *saved_top_obj, *saved_bot_obj, *obj_ptr;
8269
8270 if (topSel == NULL) {
8271 MsgBox(TgLoadString(STID_NO_OBJ_SEL_NOTHING_TO_PRINT), TOOL_NAME,
8272 INFO_MB);
8273 return;
8274 }
8275 HighLightReverse();
8276 PushPageInfo();
8277 saved_top_obj = topObj;
8278 saved_bot_obj = botObj;
8279
8280 JustDupSelObj(&top_sel_ptr, &bot_sel_ptr);
8281 curPage->top = topObj = top_sel_ptr->obj;
8282 curPage->bot = botObj = bot_sel_ptr->obj;
8283 for (sel_ptr=topSel, obj_ptr=topObj; obj_ptr!=NULL;
8284 sel_ptr=sel_ptr->next, obj_ptr=obj_ptr->next) {
8285 CopyObjId(sel_ptr->obj, obj_ptr);
8286 CopyObjLocks(sel_ptr->obj, obj_ptr);
8287 }
8288
8289 if (pageLayoutMode == PAGE_STACK) {
8290 DumpOnePageInStackMode();
8291 } else {
8292 int ok=TRUE;
8293 XColor *saved_tgif_colors=tgifColors;
8294
8295 if (printUsingRequestedColor) tgifColors = tgifRequestedColors;
8296
8297 printingFirstPageNum = 1;
8298 printingPageNum = 1;
8299 printingLastPageNum = 1;
8300 totalBBoxValid = FALSE;
8301 if (whereToPrint==PRINTER || whereToPrint==LATEX_FIG ||
8302 whereToPrint==PS_FILE || whereToPrint==PDF_FILE ||
8303 whereToPrint==EPSI_FILE || whereToPrint==TIFFEPSI_FILE ||
8304 whereToPrint==SVG_FILE) {
8305 ResetPSInfo();
8306 CacheColorsForPrinting();
8307 ok = GenDump("");
8308 DoneResetPSInfo();
8309 }
8310 if (ok) GenDump("");
8311 CleanUpCachedColorsForPrinting();
8312
8313 if (printUsingRequestedColor) tgifColors = saved_tgif_colors;
8314 }
8315 DelAllObj();
8316 for (sel_ptr = top_sel_ptr; sel_ptr != NULL; sel_ptr = next_sel) {
8317 next_sel = sel_ptr->next;
8318 free(sel_ptr);
8319 }
8320 PopPageInfo();
8321 curPage->top = topObj = saved_top_obj;
8322 curPage->bot = botObj = saved_bot_obj;
8323 RedrawAnArea(botObj, selLtX-GRID_ABS_SIZE(1), selLtY-GRID_ABS_SIZE(1),
8324 selRbX+GRID_ABS_SIZE(1), selRbY+GRID_ABS_SIZE(1));
8325 HighLightForward();
8326 }
8327
SetPrintReduction()8328 void SetPrintReduction()
8329 {
8330 float fval=(float)0;
8331 double right_margin=(double)0;
8332 char buf[MAXSTRING+1];
8333
8334 *buf = '\0';
8335 Dialog(TgLoadString(STID_SPECIFY_PERCENT_REDUCTION),
8336 TgLoadCachedString(CSTID_DLG_ACCEPT_CANCEL), buf);
8337 if (*buf == '\0') return;
8338
8339 if (sscanf(buf, "%f", &fval) != 1) {
8340 sprintf(gszMsgBox, TgLoadString(STID_INVALID_REDUCTION), buf);
8341 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
8342 return;
8343 }
8344 if (rightMarginEnabled == TRUE) {
8345 right_margin = rightMargin * ((double)printMag) / ((double)100);
8346 }
8347 printMag = fval;
8348 if (UpdPageStyle(pageStyle)) {
8349 UpdDrawWinBBox();
8350 AdjSplineVs();
8351 ClearAndRedrawDrawWindow();
8352 }
8353 if (rightMarginEnabled == TRUE) {
8354 rightMargin = right_margin * ((double)100) / ((double)printMag);
8355 }
8356 RedrawScrollBars();
8357 RedrawRulers();
8358 RedrawTitleWindow();
8359 SetFileModified(TRUE);
8360
8361 FormatFloat(&printMag, buf);
8362 if (printMag <= 100.0) {
8363 sprintf(gszMsgBox, TgLoadString(STID_NEW_REDUCTION_IS_PERCENT), buf);
8364 } else {
8365 sprintf(gszMsgBox, TgLoadString(STID_NEW_ENLARGEMENT_IS_PERCENT), buf);
8366 }
8367 Msg(gszMsgBox);
8368 }
8369
8370 static
DoNewProc(clear_all_wb)8371 void DoNewProc(clear_all_wb)
8372 int clear_all_wb;
8373 {
8374 if (!gstWBInfo.do_whiteboard) {
8375 CleanUpCmds();
8376 }
8377 CleanUpDrawingWindow();
8378 ClearFileInfo(TRUE);
8379 ClearAndRedrawDrawWindow();
8380
8381 CheckFileAttrsInLoad();
8382
8383 Msg(TgLoadString(STID_EDITING_NO_FILE));
8384 if (gstWBInfo.do_whiteboard) {
8385 if (clear_all_wb) {
8386 RecordWBClearAll();
8387 }
8388 } else {
8389 objId = 0;
8390 }
8391 RedrawTitleWindow();
8392 DelAllPages();
8393 lastPageNum = 1;
8394 InitPage();
8395 ShowPage();
8396
8397 rightMargin = defRightMargin;
8398 rightMarginEnabled = defRightMarginEnabled;
8399 rightMarginActive = (rightMarginEnabled == TRUE);
8400 RedrawHRulerWindow();
8401 }
8402
NewProc()8403 void NewProc()
8404 {
8405 if (gstWBInfo.do_whiteboard) {
8406 XBell(mainDisplay, 0);
8407 if (MsgBox(TgLoadString(STID_OK_TO_CLEAR_WHITEBOARD), TOOL_NAME,
8408 YNC_MB) != MB_ID_YES) {
8409 return;
8410 }
8411 TieLooseEnds();
8412 SetFileModified(FALSE);
8413 } else {
8414 while (!DirIsRemote(curDir) && fileModified && !IsFiletUnSavable()) {
8415 XBell(mainDisplay, 0);
8416 switch (MsgBox(TgLoadString(STID_FILE_MOD_SAVE_BEFORE_CLEAR),
8417 TOOL_NAME, YNC_MB)) {
8418 case MB_ID_YES: SaveFile(); break;
8419 case MB_ID_NO: TieLooseEnds(); SetFileModified(FALSE); break;
8420 case MB_ID_CANCEL: return;
8421 }
8422 }
8423 if (!DirIsRemote(curDir) && fileModified && IsFiletUnSavable()) {
8424 TieLooseEnds();
8425 SetFileModified(FALSE);
8426 }
8427 }
8428 if (inHyperSpace && !inSlideShow) ToggleHyperSpace(FALSE);
8429
8430 DoNewProc(TRUE);
8431 }
8432
BeforeOpenURL(pn_do_not_save)8433 int BeforeOpenURL(pn_do_not_save)
8434 int *pn_do_not_save;
8435 {
8436 int do_not_save=FALSE;
8437
8438 if (inSlideShow) {
8439 XBell(mainDisplay, 0);
8440 MsgBox(TgLoadString(STID_CANNOT_OPEN_IN_SLIDESHOW), TOOL_NAME, INFO_MB);
8441 return FALSE;
8442 } else if (gstWBInfo.do_whiteboard) {
8443 XBell(mainDisplay, 0);
8444 if (MsgBox(TgLoadString(STID_OK_TO_CLEAR_WHITEBOARD), TOOL_NAME,
8445 YNC_MB) != MB_ID_YES) {
8446 return FALSE;
8447 }
8448 } else {
8449 while (!DirIsRemote(curDir) && fileModified && !IsFiletUnSavable()) {
8450 XBell(mainDisplay, 0);
8451 switch (MsgBox(TgLoadString(STID_FILE_MOD_SAVE_BEFORE_OPEN), TOOL_NAME,
8452 YNC_MB)) {
8453 case MB_ID_YES: SaveFile(); break;
8454 case MB_ID_NO: do_not_save = TRUE; SetFileModified(FALSE); break;
8455 case MB_ID_CANCEL: return FALSE;
8456 }
8457 }
8458 if (!DirIsRemote(curDir) && fileModified && IsFiletUnSavable()) {
8459 do_not_save = TRUE;
8460 SetFileModified(FALSE);
8461 }
8462 }
8463 if (pn_do_not_save != NULL) *pn_do_not_save = do_not_save;
8464
8465 return TRUE;
8466 }
8467
OpenURL(file_name,do_not_save,pn_need_to_check_auto_exec)8468 void OpenURL(file_name, do_not_save, pn_need_to_check_auto_exec)
8469 char *file_name;
8470 int do_not_save, *pn_need_to_check_auto_exec;
8471 {
8472 int need_to_check_auto_exec=FALSE;
8473
8474 if (gstWBInfo.do_whiteboard) {
8475 DoNewProc(FALSE);
8476 }
8477 SetWatchCursor(drawWindow);
8478 SetWatchCursor(mainWindow);
8479
8480 if (FileIsRemote(file_name)) {
8481 char remote_fname[MAXPATHLENGTH+1];
8482 char *page_spec=NULL;
8483
8484 if (!FormNewFileName(curDir, file_name, NULL, remote_fname,
8485 &page_spec)) {
8486 sprintf(gszMsgBox, TgLoadString(STID_INVALID_REMOTE_FNAME),
8487 file_name);
8488 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
8489 if (do_not_save) SetFileModified(TRUE);
8490 } else {
8491 char *buf=NULL, *content_type=NULL, final_url[MAXPATHLENGTH+1];
8492 int rc, buf_sz=0, is_html=FALSE;
8493
8494 *final_url = '\0';
8495 SaveStatusStrings();
8496 rc = LoadRemoteFileInMem(remote_fname, &buf, &content_type,
8497 &buf_sz, &is_html, TRUE, final_url, sizeof(final_url));
8498 RestoreStatusStrings();
8499 if (rc && buf != NULL) {
8500 if (*final_url != '\0') {
8501 UtilStrCpyN(remote_fname, sizeof(remote_fname), final_url);
8502 }
8503 if (LoadRemoteFileFromMem(remote_fname, buf, content_type,
8504 buf_sz, is_html)) {
8505 need_to_check_auto_exec = TRUE;
8506 }
8507 } else if (do_not_save) {
8508 SetFileModified(TRUE);
8509 }
8510 if (content_type != NULL) FreeRemoteBuf(content_type);
8511 if (buf != NULL) FreeRemoteBuf(buf);
8512 if (page_spec != NULL) {
8513 int new_page_num=(-1);
8514
8515 need_to_check_auto_exec = FALSE;
8516 if (!GetPageNumFromPageSpec(page_spec, &new_page_num)) {
8517 sprintf(gszMsgBox,
8518 TgLoadString(STID_INVALID_PAGE_SPECIFIED_FOR),
8519 file_name);
8520 MsgBox(gszMsgBox, TOOL_NAME, INFO_MB);
8521 } else if (new_page_num != curPageNum) {
8522 BeforeNavigate();
8523 GotoPageNum(new_page_num);
8524 ShowPage();
8525 ClearAndRedrawDrawWindow();
8526 RedrawTitleWindow();
8527 RedrawRulers();
8528 RedrawScrollBars();
8529 justDupped = FALSE;
8530 }
8531 }
8532 }
8533 if (page_spec != NULL) free(page_spec);
8534 } else {
8535 int gzipped=FALSE, obj_file=FALSE;
8536
8537 obj_file = FileNameHasExtension(file_name, OBJ_FILE_TYPE, &gzipped,
8538 NULL);
8539 if (!LoadFile(file_name, obj_file, obj_file && gzipped)) {
8540 if (do_not_save) {
8541 SetFileModified(TRUE);
8542 }
8543 } else {
8544 need_to_check_auto_exec = TRUE;
8545 }
8546 }
8547 SetDefaultCursor(mainWindow);
8548 ShowCursor();
8549 if (gstWBInfo.do_whiteboard && (topObj != NULL || tgifObj->fattr != NULL)) {
8550 #ifdef _TGIF_WB2_NO_DELAY_BUG
8551 sleep(1);
8552 #endif /* ~_TGIF_WB2_NO_DELAY_BUG */
8553 /*
8554 * In slideshow mode, SelAllObj() will *not* select anything!
8555 * Since we really want the objects to be selected (because
8556 * we want to record them), we must set ignore_slideshow
8557 * to TRUE when we call SelAllObj().
8558 */
8559 if (tgifObj->fattr != NULL) {
8560 StartCompositeCmd();
8561 }
8562 if (topObj != NULL) {
8563 SelAllObj(FALSE, TRUE);
8564 PrepareToRecord(CMD_NEW, NULL, NULL, 0);
8565 RecordCmd(CMD_NEW, NULL, topSel, botSel, numObjSelected);
8566 RemoveAllSel();
8567 }
8568 if (tgifObj->fattr != NULL) {
8569 struct AttrRec *saved_fattr=tgifObj->fattr;
8570 struct AttrRec *saved_lattr=tgifObj->lattr;
8571
8572 tgifObj->fattr = tgifObj->lattr = NULL;
8573
8574 AddObj(NULL, topObj, tgifObj);
8575 AddNewSelObj(topObj);
8576 PrepareToReplaceAnObj(tgifObj);
8577
8578 tgifObj->fattr = saved_fattr;
8579 tgifObj->lattr = saved_lattr;
8580
8581 recordCmdIncludeTgifObj = TRUE;
8582 RecordReplaceAnObj(tgifObj);
8583 recordCmdIncludeTgifObj = FALSE;
8584
8585 UnlinkObj(topObj);
8586 FreeTopSel();
8587
8588 EndCompositeCmd();
8589 }
8590 }
8591 if (pn_need_to_check_auto_exec != NULL) {
8592 *pn_need_to_check_auto_exec = need_to_check_auto_exec;
8593 }
8594 }
8595
AfterOpenURL(need_to_check_auto_exec)8596 void AfterOpenURL(need_to_check_auto_exec)
8597 int need_to_check_auto_exec;
8598 {
8599 if (need_to_check_auto_exec) {
8600 struct AttrRec *exec_attr=FindFileAttrWithName("auto_exec=");
8601
8602 if (exec_attr != NULL) {
8603 DoExecLoop(NULL, exec_attr);
8604 }
8605 }
8606 }
8607
OpenProc(psz_fname_spec)8608 void OpenProc(psz_fname_spec)
8609 char *psz_fname_spec;
8610 {
8611 char file_name[MAXPATHLENGTH+1];
8612 int do_not_save=FALSE, need_to_check_auto_exec=FALSE;
8613
8614 if (!BeforeOpenURL(&do_not_save)) {
8615 return;
8616 }
8617 if (psz_fname_spec != NULL && strcmp(psz_fname_spec, "-1") != 0) {
8618 int len=strlen(psz_fname_spec);
8619 char new_full_name[MAXPATHLENGTH<<2];
8620
8621 if (len > 0 && psz_fname_spec[len-1] == ')') {
8622 psz_fname_spec[len-1] = '\0';
8623 UtilStrCpyN(file_name, sizeof(file_name), psz_fname_spec);
8624 psz_fname_spec[len-1] = ')';
8625 } else {
8626 UtilStrCpyN(file_name, sizeof(file_name), psz_fname_spec);
8627 }
8628 if (FileIsRemote(file_name)) {
8629 OpenURL(file_name, do_not_save, &need_to_check_auto_exec);
8630 } else {
8631 if (*file_name == DIR_SEP) {
8632 strcpy(new_full_name, file_name);
8633 } else if (curDirIsLocal) {
8634 sprintf(new_full_name, "%s%c%s", curDir, DIR_SEP, file_name);
8635 } else {
8636 sprintf(new_full_name, "%s%c%s", curLocalDir, DIR_SEP, file_name);
8637 }
8638 OpenURL(new_full_name, do_not_save, &need_to_check_auto_exec);
8639 }
8640 } else {
8641 if (SelectFileName(TgLoadString(STID_SELECT_A_FILE_TO_OPEN), file_name) !=
8642 INVALID) {
8643 OpenURL(file_name, do_not_save, &need_to_check_auto_exec);
8644 } else if (do_not_save) {
8645 SetFileModified(TRUE);
8646 }
8647 }
8648 AfterOpenURL(need_to_check_auto_exec);
8649 }
8650
SetTemplate()8651 void SetTemplate()
8652 {
8653 char file_name[MAXPATHLENGTH+1], *rest=NULL;
8654 int short_name, rc;
8655 FILE *fp=NULL;
8656 struct AttrRec *attr_ptr=NULL;
8657 struct SelRec *saved_top_sel=NULL, *saved_bot_sel=NULL;
8658
8659 if (gstWBInfo.do_whiteboard) {
8660 /*
8661 * Now it's allowed.
8662 *
8663 * MsgBox(TgLoadString(STID_SETTEMPLATE_IN_WB), TOOL_NAME, INFO_MB);
8664 * return;
8665 */
8666 }
8667 MakeQuiescent();
8668
8669 if (importFromLibrary) {
8670 char name[MAXSTRING+1], path[MAXSTRING+1];
8671
8672 if (SelectFromLibrary(TgLoadString(STID_SEL_AN_OBJ_FILE_TO_IMPORT),
8673 OBJ_FILE_EXT, name, path) == INVALID) {
8674 return;
8675 }
8676 sprintf(file_name, "%s%c%s", path, DIR_SEP, name);
8677 } else {
8678 sprintf(gszMsgBox, TgLoadString(STID_SELECT_FILE_AS_TEMPLATE));
8679 if (SelectFileNameToImport(gszMsgBox, OBJ_FILE_EXT, file_name) ==
8680 INVALID) {
8681 return;
8682 } else if (FileIsRemote(file_name)) {
8683 MsgBox(TgLoadString(STID_NOT_SUP_REMOTE_TEMPLATE_FILE), TOOL_NAME,
8684 INFO_MB);
8685 return;
8686 }
8687 }
8688 if (FileIsRemote(file_name)) {
8689 MsgBox(TgLoadString(STID_NOT_SUP_REMOTE_TEMPLATE_FILE), TOOL_NAME,
8690 INFO_MB);
8691 return;
8692 }
8693 if ((short_name=IsPrefix(bootDir, file_name, &rest))) ++rest;
8694 if ((fp=fopen(file_name, "r")) == NULL) {
8695 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_OPEN_STILL_TEMPLATE),
8696 (short_name ? rest : file_name));
8697 if (MsgBox(gszMsgBox, TOOL_NAME, YNC_MB) != MB_ID_YES) {
8698 return;
8699 }
8700 } else {
8701 fclose(fp);
8702 }
8703 StartCompositeCmd();
8704 importingFile = TRUE;
8705 rc = ImportGivenFile(file_name, TRUE, TRUE);
8706 importingFile = FALSE;
8707 if (rc == BAD) {
8708 EndCompositeCmd();
8709 return;
8710 } else if (rc == FALSE) {
8711 sprintf(gszMsgBox, TgLoadString(STID_STILL_USE_AS_TEMPLATE),
8712 (short_name ? rest : file_name));
8713 if (MsgBox(gszMsgBox, TOOL_NAME, YNC_MB) != MB_ID_YES) {
8714 EndCompositeCmd();
8715 return;
8716 }
8717 }
8718 HighLightReverse();
8719 saved_top_sel = topSel;
8720 saved_bot_sel = botSel;
8721 topSel = botSel = NULL;
8722 UpdSelBBox();
8723
8724 if ((attr_ptr=FindAttrWithName(tgifObj, "template=", NULL)) != NULL) {
8725 ReplaceAttrFirstValue(tgifObj, attr_ptr, short_name ? rest : file_name);
8726 } else {
8727 int x=tgifObj->obbox.ltx, y=tgifObj->obbox.rby;
8728
8729 AddObj(NULL, topObj, tgifObj);
8730 UpdSelBBox();
8731
8732 PrepareToReplaceAnObj(tgifObj);
8733 attr_ptr = AddAttrByNameAndValue(tgifObj, "template=",
8734 short_name ? rest : file_name);
8735 attr_ptr->shown = TRUE;
8736 attr_ptr->obj->color = colorIndex;
8737 if (mainDisplay != NULL) {
8738 UtilStrCpyN(attr_ptr->obj->color_str, sizeof(attr_ptr->obj->color_str),
8739 colorMenuItems[colorIndex]);
8740 }
8741 MoveObj(attr_ptr->obj, x-attr_ptr->obj->x, y-attr_ptr->obj->y);
8742 UpdTextBBox(attr_ptr->obj);
8743 AdjObjBBox(tgifObj);
8744
8745 recordCmdIncludeTgifObj = TRUE;
8746 RecordReplaceAnObj(tgifObj);
8747 recordCmdIncludeTgifObj = FALSE;
8748
8749 RemoveAllSel();
8750 UnlinkObj(topObj);
8751 UpdSelBBox();
8752
8753 SetFileModified(TRUE);
8754 justDupped = FALSE;
8755 }
8756 EndCompositeCmd();
8757 sprintf(gszMsgBox, TgLoadString(STID_TEMPLATE_SET_TO),
8758 (short_name ? rest : file_name));
8759 Msg(gszMsgBox);
8760 topSel = saved_top_sel;
8761 botSel = saved_bot_sel;
8762 UpdSelBBox();
8763 HighLightForward();
8764 SetCurChoice(curChoiceBeforeMakeQuiescent);
8765 }
8766
8767 /* do not translate -- program constants */
8768 char * fileMenuStr[] =
8769 { "New ^n",
8770 "Open ^o",
8771 "Save ^s",
8772 "SaveNew ^#s",
8773 "Import #p",
8774 "ImportXBitmap ^#.",
8775 "ImportXPixmap ^#,",
8776 "ImportEPSFile #(",
8777 "ImportGIFFile ",
8778 "ImportOtherFile ",
8779 "EmbedEPSFile ",
8780 "BrowseXBitmap ",
8781 "BrowseXPixmap ",
8782 "BrowseOther ",
8783 "ChangeDomain ^c",
8784 "Print ^p",
8785 "PrintWithCmd ^-",
8786 "PrintSelectedObjs ",
8787 "PrintOnePage ",
8788 "SetExportPixelTrim",
8789 "InputPolyPts ",
8790 "InputPolygonPts ",
8791 "SetTemplate ",
8792 "Solve #s",
8793 "Simulate #y",
8794 "Probe #b",
8795 "Animate ^z",
8796 "Escape #x",
8797 "SaveSelectedAs #~",
8798 "SaveSymInLibrary ",
8799 "Quit ^q",
8800 NULL
8801 };
8802
QuitProc()8803 int QuitProc()
8804 {
8805 int do_not_save=FALSE;
8806
8807 while (!DirIsRemote(curDir) && fileModified && !IsFiletUnSavable()) {
8808 XBell(mainDisplay, 0);
8809 switch (MsgBox(TgLoadString(STID_FILE_MOD_SAVE_BEFORE_QUIT), TOOL_NAME,
8810 YNC_MB)) {
8811 case MB_ID_YES: SaveFile(); break;
8812 case MB_ID_NO: do_not_save = TRUE; SetFileModified(FALSE); break;
8813 case MB_ID_CANCEL: return INVALID;
8814 }
8815 }
8816 if (!DirIsRemote(curDir) && fileModified && IsFiletUnSavable()) {
8817 do_not_save = TRUE;
8818 SetFileModified(FALSE);
8819 }
8820 if (AncesterModified()) {
8821 switch (MsgBox(TgLoadString(STID_ANCESTER_MOD_STILL_QUIT), TOOL_NAME,
8822 YNC_MB)) {
8823 case MB_ID_YES: return FILE_QUIT;
8824 case MB_ID_NO:
8825 if (do_not_save) SetFileModified(TRUE);
8826 return INVALID;
8827 case MB_ID_CANCEL:
8828 if (do_not_save) SetFileModified(TRUE);
8829 return INVALID;
8830 }
8831 }
8832 gnQuit = TRUE;
8833 return FILE_QUIT;
8834 }
8835
SolveProc()8836 int SolveProc()
8837 {
8838 if (!saveTmpOnReturn) return FILE_SOLVE;
8839
8840 switch (SaveTmpFile("tmpmodel")) {
8841 case OBJ_FILE_TYPE: return FILE_SOLVE;
8842 case SYM_FILE_TYPE: return INVALID;
8843 case PIN_FILE_TYPE: return INVALID;
8844 case INVALID: return INVALID;
8845 }
8846 return INVALID;
8847 }
8848
SimulateProc()8849 int SimulateProc()
8850 {
8851 if (!saveTmpOnReturn) return FILE_SIMULATE;
8852
8853 switch (SaveTmpFile("tmpmodel")) {
8854 case OBJ_FILE_TYPE: return FILE_SIMULATE;
8855 case SYM_FILE_TYPE: return INVALID;
8856 case PIN_FILE_TYPE: return INVALID;
8857 case INVALID: return INVALID;
8858 }
8859 return INVALID;
8860 }
8861
ProbeProc()8862 int ProbeProc()
8863 {
8864 if (!saveTmpOnReturn) return FILE_PROBE;
8865
8866 switch (SaveTmpFile("tmpmodel")) {
8867 case OBJ_FILE_TYPE: return FILE_PROBE;
8868 case SYM_FILE_TYPE: return INVALID;
8869 case PIN_FILE_TYPE: return INVALID;
8870 case INVALID: return INVALID;
8871 }
8872 return INVALID;
8873 }
8874
AnimateProc()8875 int AnimateProc()
8876 {
8877 if (!saveTmpOnReturn) return FILE_ANIMATE;
8878
8879 switch (SaveTmpFile("tmpmodel")) {
8880 case OBJ_FILE_TYPE: return FILE_ANIMATE;
8881 case SYM_FILE_TYPE: return INVALID;
8882 case PIN_FILE_TYPE: return INVALID;
8883 case INVALID: return INVALID;
8884 }
8885 return INVALID;
8886 }
8887
EscapeProc()8888 int EscapeProc()
8889 {
8890 return FILE_ESCAPE;
8891 }
8892
RefreshFileMenu(menu)8893 int RefreshFileMenu(menu)
8894 TgMenu *menu;
8895 {
8896 int ok=TRUE, allow_print_pages=TRUE;
8897
8898 /* Print/Export In Color */
8899 ok &= TgSetMenuItemCheckById(menu, CMDID_TOGGLEBWCOLORPS, colorDump);
8900
8901 /* Print With Cmd */
8902 ok &= TgEnableMenuItemById(menu, CMDID_PRINTWITHCMD,
8903 (whereToPrint==PRINTER));
8904
8905 /*
8906 * Print Pages - only allows PRINTER, PS_FILE, PDF_FILE, or user supplied
8907 * export filters
8908 */
8909 if (pageLayoutMode == PAGE_TILE) {
8910 allow_print_pages = FALSE;
8911 } else {
8912 switch (whereToPrint) {
8913 case LATEX_FIG:
8914 case XBM_FILE:
8915 case TEXT_FILE:
8916 case NETLIST_FILE:
8917 case EPSI_FILE:
8918 case GIF_FILE:
8919 case HTML_FILE:
8920 case TIFFEPSI_FILE:
8921 case PNG_FILE:
8922 case JPEG_FILE:
8923 case PPM_FILE:
8924 case SVG_FILE:
8925 allow_print_pages = FALSE;
8926 break;
8927 default: break;
8928 }
8929 }
8930 ok &= TgEnableMenuItemById(menu, CMDID_PRINTPAGES, allow_print_pages);
8931
8932 /* Print One File Per Page */
8933 ok &= TgEnableMenuItemById(menu, CMDID_PRINTONEFILEPERPAGE,
8934 (pageLayoutMode == PAGE_STACK && whereToPrint != PRINTER));
8935
8936 return ok;
8937 }
8938
CreateFileMenu(parent_menu,x,y,menu_info,status_str_xlated)8939 TgMenu *CreateFileMenu(parent_menu, x, y, menu_info, status_str_xlated)
8940 TgMenu *parent_menu;
8941 int x, y;
8942 TgMenuInfo *menu_info;
8943 int status_str_xlated; /* ignored, always 0 */
8944 {
8945 TgMenu *menu=TgCreateMenuFromMenuInfo(parent_menu, x, y, menu_info, FALSE);
8946
8947 if (menu != NULL) {
8948 if (!RefreshFileMenu(menu)) {
8949 return TgDestroyMenu(menu, TRUE);
8950 }
8951 menu->refresh_proc = ((RefreshMenuFunc*)RefreshFileMenu);
8952 }
8953 return menu;
8954 }
8955
FileMenu(X,Y,TrackMenubar)8956 int FileMenu(X, Y, TrackMenubar)
8957 int X, Y, TrackMenubar;
8958 {
8959 int rc=INVALID;
8960 TgMenu *menu=(fileMenuInfo.create_proc)(NULL, X, Y, &fileMenuInfo, INVALID);
8961
8962 activeMenu = MENU_FILE;
8963 if (menu != NULL) {
8964 menu->track_menubar = TrackMenubar;
8965
8966 rc = TgMenuLoop(menu);
8967 TgDestroyMenu(menu, TRUE);
8968 }
8969 return rc;
8970 }
8971
CreateRecentFilesMenu(parent_menu,x,y,menu_info,status_str_xlated)8972 TgMenu *CreateRecentFilesMenu(parent_menu, x, y, menu_info, status_str_xlated)
8973 TgMenu *parent_menu;
8974 int x, y;
8975 TgMenuInfo *menu_info;
8976 int status_str_xlated; /* ignored, always 0 */
8977 {
8978 int i=0, count=0;
8979 TgMenu *menu=NULL;
8980 TgMenuInfo stMenuInfo;
8981 TgMenuItemInfo *item_info=NULL;
8982 KeyValInfo *pkvi=NULL;
8983
8984 memcpy(&stMenuInfo, menu_info, sizeof(TgMenuInfo));
8985 pkvi = RecentFilesListing(&count);
8986
8987 if (pkvi == NULL || count == 0) {
8988 count = 0;
8989 stMenuInfo.items = (TgMenuItemInfo*)malloc((1+1)*sizeof(TgMenuItemInfo));
8990 if (stMenuInfo.items == NULL) FailAllocMessage();
8991 memset(stMenuInfo.items, 0, (1+1)*sizeof(TgMenuItemInfo));
8992
8993 item_info = stMenuInfo.items;
8994 item_info->menu_str = UtilStrDup(TgLoadCachedString(CSTID_PARANED_EMPTY));
8995 if (item_info->menu_str == NULL) FailAllocMessage();
8996 item_info->shortcut_str = NULL;
8997 item_info->status_str = UtilStrDup("");
8998 if (item_info->status_str == NULL) FailAllocMessage();
8999 item_info->submenu_info = NULL;
9000 item_info->cmdid = CMDID_RECENTLYUSEDFILES;
9001 stMenuInfo.items[1].cmdid = INVALID;
9002 } else {
9003 stMenuInfo.items = (TgMenuItemInfo*)malloc(
9004 (count+1)*sizeof(TgMenuItemInfo));
9005 if (stMenuInfo.items == NULL) FailAllocMessage();
9006 memset(stMenuInfo.items, 0, (count+1)*sizeof(TgMenuItemInfo));
9007
9008 for (item_info=stMenuInfo.items, i=0; i < count; item_info++, i++) {
9009 sprintf(gszMsgBox, "%2d. %s", i+1, pkvi[i].key);
9010 item_info->menu_str = UtilStrDup(gszMsgBox);
9011 if (item_info->menu_str == NULL) FailAllocMessage();
9012 item_info->shortcut_str = NULL;
9013 sprintf(gszMsgBox, TgLoadCachedString(CSTID_OPEN_FILE),
9014 pkvi[i].value);
9015 item_info->status_str = UtilStrDup(gszMsgBox);
9016 if (item_info->status_str == NULL) FailAllocMessage();
9017 item_info->submenu_info = NULL;
9018 item_info->cmdid = CMDID_RECENTLYUSEDFILES;
9019 }
9020 stMenuInfo.items[count].cmdid = INVALID;
9021 }
9022 /* the status_str has actual file names, no tralslation needed */
9023 menu = TgCreateMenuFromMenuInfo(parent_menu, x, y, &stMenuInfo, TRUE);
9024 if (count == 0) {
9025 UtilFree(stMenuInfo.items->status_str);
9026 memset(stMenuInfo.items, 0, (1+1)*sizeof(TgMenuItemInfo));
9027 } else {
9028 for (item_info=stMenuInfo.items, i=0; i < count; item_info++, i++) {
9029 UtilFree(item_info->status_str);
9030 }
9031 memset(stMenuInfo.items, 0, (count+1)*sizeof(TgMenuItemInfo));
9032 }
9033 free(stMenuInfo.items);
9034 stMenuInfo.items = NULL;
9035 if (menu != NULL) {
9036 if (count == 0) {
9037 TgEnableMenuItemByIndex(menu, 0, FALSE);
9038 menu->menuitems[0].menu_str_allocated = TRUE;
9039 } else {
9040 for (i=0; i < count; i++) {
9041 menu->menuitems[i].menu_str_allocated = TRUE;
9042 }
9043 }
9044 }
9045 FreeRecentFilesListing(pkvi, count);
9046
9047 return menu;
9048 }
9049
ReadFileIntoBuf(fname,pn_buf_sz)9050 char *ReadFileIntoBuf(fname, pn_buf_sz)
9051 char *fname;
9052 unsigned int *pn_buf_sz;
9053 {
9054 struct stat stat_buf;
9055
9056 if (stat(fname, &stat_buf) == 0) {
9057 char *psz=NULL, buf[0x10000], *psz_return=NULL;
9058 FILE *fp=NULL;
9059 unsigned int bytes_to_read=0, file_size=0, bytes_read=0, total_read=0;
9060
9061 if ((fp=fopen(fname, "r")) == NULL) {
9062 FailToOpenMessage(fname, "r", NULL);
9063 return NULL;
9064 }
9065 file_size = (unsigned int)(stat_buf.st_size);
9066 psz = psz_return = (char*)malloc(file_size);
9067 if (psz_return == NULL) FailAllocMessage();
9068
9069 bytes_to_read = min(file_size, sizeof(buf));
9070 while ((bytes_read=fread(psz, sizeof(char), bytes_to_read, fp)) > 0) {
9071 total_read += bytes_read;
9072 psz += bytes_read;
9073 file_size -= bytes_read;
9074 bytes_to_read = min(file_size, sizeof(buf));
9075 if (bytes_to_read == 0) break;
9076 }
9077 fclose(fp);
9078 if (total_read == (unsigned int)(stat_buf.st_size)) {
9079 if (pn_buf_sz != NULL) *pn_buf_sz = total_read;
9080 }
9081 return psz_return;
9082 }
9083 return NULL;
9084 }
9085
WriteBufIntoTmpFile(buf,buf_sz,tmp_fname,tmp_fname_sz)9086 int WriteBufIntoTmpFile(buf, buf_sz, tmp_fname, tmp_fname_sz)
9087 char *buf, *tmp_fname;
9088 int buf_sz, tmp_fname_sz;
9089 {
9090 FILE *fp=NULL;
9091
9092 if (MkTempFile(tmp_fname, tmp_fname_sz, tmpDir, TOOL_NAME) == NULL) {
9093 return FALSE;
9094 }
9095 if ((fp=fopen(tmp_fname, "w")) == NULL) {
9096 return FailToOpenMessage(tmp_fname, "w", NULL);
9097 }
9098 if ((int)fwrite(buf, sizeof(char), buf_sz, fp) != buf_sz) {
9099 fclose(fp);
9100 return FailToWriteFileMessage(tmp_fname);
9101 }
9102 fclose(fp);
9103
9104 return TRUE;
9105 }
9106
CleanUpFiles()9107 void CleanUpFiles()
9108 {
9109 UtilFree(gpszPsSetup);
9110 gpszPsSetup = NULL;
9111
9112 ClearBgColorInfo(FALSE);
9113 ClearBgPixmapInfo(FALSE);
9114
9115 CleanUpDumpInitDefaults();
9116 ClearFileInfo(TRUE);
9117 if (usePaperSizeStoredInFile) ResetOnePageSize();
9118 fileModified = FALSE;
9119 }
9120