6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Contact addresses for paper mail and Email:
24 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
25 * Thomas.Nau@rz.uni-ulm.de
30 /* main program, initializes some stuff and handles user input
48 #include "crosshair.h"
55 #include "lrealpath.h"
57 /* This next one is so we can print the help messages. */
58 #include "hid/hidint.h"
68 #ifdef HAVE_LIBDMALLOC
75 #define PCBLIBPATH ".:" PCBLIBDIR
79 extern void stroke_init (void);
83 /* ----------------------------------------------------------------------
84 * initialize signal and error handlers
90 signal(SIGHUP, CatchSignal);
91 signal(SIGQUIT, CatchSignal);
92 signal(SIGABRT, CatchSignal);
93 signal(SIGSEGV, CatchSignal);
94 signal(SIGTERM, CatchSignal);
95 signal(SIGINT, CatchSignal);
98 /* calling external program by popen() may cause a PIPE signal,
102 signal (SIGPIPE
, SIG_IGN
);
107 /* ----------------------------------------------------------------------
108 | command line and rc file processing.
110 static char *command_line_pcb
;
116 " COPYRIGHT for %s version %s\n\n"
117 " PCB, interactive printed circuit board design\n"
118 " Copyright (C) 1994,1995,1996,1997 Thomas Nau\n"
119 " Copyright (C) 1998, 1999, 2000 Harry Eaton\n\n"
120 " This program is free software; you can redistribute it and/or modify\n"
121 " it under the terms of the GNU General Public License as published by\n"
122 " the Free Software Foundation; either version 2 of the License, or\n"
123 " (at your option) any later version.\n\n"
124 " This program is distributed in the hope that it will be useful,\n"
125 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
126 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
127 " GNU General Public License for more details.\n\n"
128 " You should have received a copy of the GNU General Public License\n"
129 " along with this program; if not, write to the Free Software\n"
130 " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
136 u (const char *fmt
, ...)
140 vfprintf (stderr
, fmt
, ap
);
141 fputc ('\n', stderr
);
146 usage_attr (HID_Attribute
* a
)
149 static char buf
[200];
151 if (a
->help_text
== ATTR_UNDOCUMENTED
)
160 sprintf (buf
, "--%s <num>", a
->name
);
163 sprintf (buf
, "--%s <string>", a
->name
);
166 sprintf (buf
, "--%s", a
->name
);
170 sprintf (buf
, "--%s ", a
->name
);
171 if (a
->type
== HID_Mixed
)
172 strcat (buf
, " <val>");
173 for (i
= 0; a
->enumerations
[i
]; i
++)
175 strcat (buf
, i
? "|" : "<");
176 strcat (buf
, a
->enumerations
[i
]);
181 sprintf (buf
, "--%s <path>", a
->name
);
185 if (strlen (buf
) <= 30)
188 fprintf (stderr
, " %-30s\t%s\n", buf
, a
->help_text
);
190 fprintf (stderr
, " %-30s\n", buf
);
192 else if (a
->help_text
&& strlen (a
->help_text
) + strlen (buf
) < 72)
193 fprintf (stderr
, " %s\t%s\n", buf
, a
->help_text
);
194 else if (a
->help_text
)
195 fprintf (stderr
, " %s\n\t\t\t%s\n", buf
, a
->help_text
);
197 fprintf (stderr
, " %s\n", buf
);
208 HID
**hl
= hid_enumerate ();
210 fprintf (stderr
, "\ngui options:\n");
211 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
213 for (i
= 0; hl
[i
]; i
++)
214 if (ha
->attributes
== hl
[i
]->get_export_options (0))
216 for (i
= 0; i
< ha
->n
; i
++)
217 usage_attr (ha
->attributes
+ i
);
222 fprintf (stderr
, "\n%s options:\n", h
->name
);
224 e
= h
->get_export_options (&n
);
227 for (i
= 0; i
< n
; i
++)
235 HID
**hl
= hid_enumerate ();
237 int n_printer
= 0, n_gui
= 0, n_exporter
= 0;
239 for (i
= 0; hl
[i
]; i
++)
249 u ("PCB Printed Circuit Board editing program, http://pcb.sourceforge.net");
250 u ("%s [-h|-V|--copyright]\t\t\tHelp, version, copyright", Progname
);
251 u ("%s [gui options] <pcb file>\t\tto edit", Progname
);
252 u ("Available GUI hid%s:", n_gui
== 1 ? "" : "s");
253 for (i
= 0; hl
[i
]; i
++)
255 fprintf (stderr
, "\t%s\t%s\n", hl
[i
]->name
, hl
[i
]->description
);
256 u ("%s -p [printing options] <pcb file>\tto print", Progname
);
257 u ("Available printing hid%s:", n_printer
== 1 ? "" : "s");
258 for (i
= 0; hl
[i
]; i
++)
260 fprintf (stderr
, "\t%s\t%s\n", hl
[i
]->name
, hl
[i
]->description
);
261 u ("%s -x hid [export options] <pcb file>\tto export", Progname
);
262 u ("Available export hid%s:", n_exporter
== 1 ? "" : "s");
263 for (i
= 0; hl
[i
]; i
++)
265 fprintf (stderr
, "\t%s\t%s\n", hl
[i
]->name
, hl
[i
]->description
);
267 for (i
= 0; hl
[i
]; i
++)
270 for (i
= 0; hl
[i
]; i
++)
273 for (i
= 0; hl
[i
]; i
++)
280 print_defaults_1 (HID_Attribute
* a
, void *value
)
286 /* Remember, at this point we've parsed the command line, so they
287 may be in the global variable instead of the default_val. */
291 i
= value
? *(int *) value
: a
->default_val
.int_value
;
292 fprintf (stderr
, "%s %d\n", a
->name
, i
);
295 i
= value
? *(char *) value
: a
->default_val
.int_value
;
296 fprintf (stderr
, "%s %s\n", a
->name
, i
? "yes" : "no");
299 d
= value
? *(double *) value
: a
->default_val
.real_value
;
300 fprintf (stderr
, "%s %g\n", a
->name
, d
);
304 s
= value
? *(char **) value
: a
->default_val
.str_value
;
305 fprintf (stderr
, "%s \"%s\"\n", a
->name
, s
);
308 i
= value
? *(int *) value
: a
->default_val
.int_value
;
309 fprintf (stderr
, "%s %s\n", a
->name
, a
->enumerations
[i
]);
312 i
= value
? *(int *) value
: a
->default_val
.int_value
;
313 d
= value
? *(double *) value
: a
->default_val
.real_value
;
314 fprintf (stderr
, "%s %g%s\n", a
->name
, d
, a
->enumerations
[i
]);
324 HID
**hl
= hid_enumerate ();
328 for (hi
= 0; hl
[hi
]; hi
++)
334 fprintf (stderr
, "\ngui defaults:\n");
335 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
336 for (i
= 0; i
< ha
->n
; i
++)
337 print_defaults_1 (ha
->attributes
+ i
, ha
->attributes
[i
].value
);
341 fprintf (stderr
, "\n%s defaults:\n", h
->name
);
342 e
= h
->get_export_options (&n
);
344 for (i
= 0; i
< n
; i
++)
345 print_defaults_1 (e
+ i
, 0);
351 /* in hid/common/actions.c */
352 extern void print_actions ();
355 #define SSET(F,D,N,H) { N, H, \
356 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
357 #define ISET(F,D,N,H) { N, H, \
358 HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }
359 #define BSET(F,D,N,H) { N, H, \
360 HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }
361 #define RSET(F,D,N,H) { N, H, \
362 HID_Real, 0, 0, { 0, 0, D }, 0, &Settings.F }
364 #define COLOR(F,D,N,H) { N, H, \
365 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
366 #define LAYERCOLOR(N,D) { "layer-color-" #N, "Color for layer " #N, \
367 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }
368 #define LAYERNAME(N,D) { "layer-name-" #N, "Name for layer " #N, \
369 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }
370 #define LAYERSELCOLOR(N) { "layer-selected-color-" #N, "Color for layer " #N " when selected", \
371 HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }
373 static int show_help
= 0;
374 static int show_version
= 0;
375 static int show_copyright
= 0;
376 static int show_defaults
= 0;
377 static int show_actions
= 0;
378 static int do_dump_actions
= 0;
380 HID_Attribute main_attribute_list
[] = {
381 {"help", "Show Help", HID_Boolean
, 0, 0, {0, 0, 0}, 0, &show_help
},
382 {"version", "Show Version", HID_Boolean
, 0, 0, {0, 0, 0}, 0, &show_version
},
383 {"verbose", "Be verbose", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
385 {"copyright", "Show Copyright", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
387 {"show-defaults", "Show option defaults", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
389 {"show-actions", "Show actions", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
391 {"dump-actions", "Dump actions (for documentation)", HID_Boolean
, 0, 0,
395 BSET (grid_units_mm
, 0, "grid-units-mm", 0),
397 COLOR (BlackColor
, "#000000", "black-color", "color for black"),
398 COLOR (WhiteColor
, "#ffffff", "white-color", "color for white"),
399 COLOR (BackgroundColor
, "#e5e5e5", "background-color",
400 "color for background"),
401 COLOR (CrosshairColor
, "#ff0000", "crosshair-color",
402 "color for the crosshair"),
403 COLOR (CrossColor
, "#cdcd00", "cross-color", "color for cross"),
404 COLOR (ViaColor
, "#7f7f7f", "via-color", "color for vias"),
405 COLOR (ViaSelectedColor
, "#00ffff", "via-selected-color",
406 "color for selected vias"),
407 COLOR (PinColor
, "#4d4d4d", "pin-color", "color for pins"),
408 COLOR (PinSelectedColor
, "#00ffff", "pin-selected-color",
409 "color for selected pins"),
410 COLOR (PinNameColor
, "#ff0000", "pin-name-color",
411 "color for pin names and numbers"),
412 COLOR (ElementColor
, "#000000", "element-color", "color for elements"),
413 COLOR (RatColor
, "#b8860b", "rat-color", "color for ratlines"),
414 COLOR (InvisibleObjectsColor
, "#cccccc", "invisible-objects-color",
415 "color for invisible objects"),
416 COLOR (InvisibleMarkColor
, "#cccccc", "invisible-mark-color",
417 "color for invisible marks"),
418 COLOR (ElementSelectedColor
, "#00ffff", "element-selected-color",
419 "color for selected elements"),
420 COLOR (RatSelectedColor
, "#00ffff", "rat-selected-color",
421 "color for selected rats"),
422 COLOR (ConnectedColor
, "#00ff00", "connected-color",
423 "color for connections"),
424 COLOR (OffLimitColor
, "#cccccc", "off-limit-color",
425 "color for off-limits areas"),
426 COLOR (GridColor
, "#ff0000", "grid-color", "color for the grid"),
427 LAYERCOLOR (1, "#8b2323"),
428 LAYERCOLOR (2, "#3a5fcd"),
429 LAYERCOLOR (3, "#104e8b"),
430 LAYERCOLOR (4, "#cd3700"),
431 LAYERCOLOR (5, "#548b54"),
432 LAYERCOLOR (6, "#8b7355"),
433 LAYERCOLOR (7, "#00868b"),
434 LAYERCOLOR (8, "#228b22"),
435 LAYERCOLOR (9, "#8b2323"),
436 LAYERCOLOR (10, "#3a5fcd"),
437 LAYERCOLOR (11, "#104e8b"),
438 LAYERCOLOR (12, "#cd3700"),
439 LAYERCOLOR (13, "#548b54"),
440 LAYERCOLOR (14, "#8b7355"),
441 LAYERCOLOR (15, "#00868b"),
442 LAYERCOLOR (16, "#228b22"),
459 COLOR (WarnColor
, "#ff8000", "warn-color", "color for warnings"),
460 COLOR (MaskColor
, "#ff0000", "mask-color", "color for solder mask"),
462 ISET (ViaThickness
, 6000, "via-thickness", 0),
463 ISET (ViaDrillingHole
, 2800, "via-drilling-hole", 0),
464 ISET (LineThickness
, 1000, "line-thickness",
465 "Initial thickness of new lines."),
466 ISET (RatThickness
, 1000, "rat-thickness", 0),
467 ISET (Keepaway
, 1000, "keepaway", 0),
468 ISET (MaxWidth
, 600000, "default-PCB-width", 0),
469 ISET (MaxHeight
, 500000, "default-PCB-height", 0),
470 ISET (TextScale
, 100, "text-scale", 0),
471 ISET (AlignmentDistance
, 200, "alignment-distance", 0),
472 ISET (Bloat
, 1000, "bloat", 0),
473 ISET (Shrink
, 1000, "shrink", 0),
474 ISET (minWid
, 1000, "min-width", "DRC minimum copper spacing"),
475 ISET (minSlk
, 1000, "min-silk", "DRC minimum silk width"),
476 ISET (minDrill
, 1500, "min-drill", "DRC minimum drill diameter"),
477 ISET (minRing
, 1000, "min-ring", "DRC minimum annular ring"),
479 RSET (Grid
, 1000, "grid", 0),
480 RSET (grid_increment_mm
, 0.1, "grid-increment-mm", 0),
481 RSET (grid_increment_mil
, 5.0, "grid-increment-mil", 0),
482 RSET (size_increment_mm
, 0.2, "size-increment-mm", 0),
483 RSET (size_increment_mil
, 10.0, "size-increment-mil", 0),
484 RSET (line_increment_mm
, 0.1, "line-increment-mm", 0),
485 RSET (line_increment_mil
, 5.0, "line-increment-mil", 0),
486 RSET (clear_increment_mm
, 0.05, "clear-increment-mm", 0),
487 RSET (clear_increment_mil
, 2.0, "clear-increment-mil", 0),
488 RSET (IsleArea
, 200000000, "minimum polygon area", 0),
490 ISET (BackupInterval
, 60, "backup-interval", 0),
492 LAYERNAME (1, "component"),
493 LAYERNAME (2, "solder"),
494 LAYERNAME (3, "GND"),
495 LAYERNAME (4, "power"),
496 LAYERNAME (5, "signal1"),
497 LAYERNAME (6, "signal2"),
498 LAYERNAME (7, "signal3"),
499 LAYERNAME (8, "signal4"),
501 SSET (FontCommand
, "",
503 SSET (FileCommand
, "", "file-command", "Command to read a file."),
504 SSET (ElementCommand
,
505 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4
,
506 "element-command", 0),
507 SSET (PrintFile
, "%f.output", "print-file", 0),
508 SSET (LibraryCommandDir
, PCBLIBDIR
, "lib-command-dir", 0),
509 SSET (LibraryCommand
, "QueryLibrary.sh '%p' '%f' %a",
511 SSET (LibraryContentsCommand
, "ListLibraryContents.sh '%p' '%f'",
512 "lib-contents-command", 0),
513 SSET (LibraryTree
, PCBTREEPATH
, "lib-newlib",
514 "Top level directory for the newlib style library"),
515 SSET (SaveCommand
, "", "save-command", 0),
516 SSET (LibraryFilename
, LIBRARYFILENAME
, "lib-name", 0),
517 SSET (FontFile
, "default_font", "default-font",
518 "File name of default font."),
519 SSET (Groups
, "1,c:2,s:3:4:5:6:7:8", "groups", 0),
520 SSET (Routes
, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
521 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
523 SSET (FilePath
, "", "file-path", 0),
524 SSET (RatCommand
, "", "rat-command", 0),
525 SSET (FontPath
, PCBLIBPATH
, "font-path", 0),
526 SSET (ElementPath
, PCBLIBPATH
, "element-path", 0),
527 SSET (LibraryPath
, PCBLIBPATH
, "lib-path", 0),
528 SSET (MenuFile
, "pcb-menu.res", "menu-file", 0),
529 SSET (ScriptFilename
, 0, "action-script",
530 "If set, this file is executed at startup."),
531 SSET (ActionString
, 0, "action-string",
532 "If set, this is executed at startup."),
533 SSET (FabAuthor
, "", "fab-author", 0),
534 SSET (InitialLayerStack
, "", "layer-stack",
535 "Initial layer stackup, for setting up an export."),
537 ISET (PinoutOffsetX
, 100, "pinout-offset-x", 0),
538 ISET (PinoutOffsetY
, 100, "pinout-offset-y", 0),
539 ISET (PinoutTextOffsetX
, 800, "pinout-text-offset-x", 0),
540 ISET (PinoutTextOffsetY
, -100, "pinout-text-offset-y", 0),
542 BSET (DrawGrid
, 0, "draw-grid", "default to drawing the grid at startup"),
543 BSET (ClearLine
, 1, "clear-line", 0),
544 BSET (FullPoly
, 0, "full-poly", 0),
545 BSET (UniqueNames
, 1, "unique-names", 0),
546 BSET (SnapPin
, 1, "snap-pin", 0),
547 BSET (SaveLastCommand
, 0, "save-last-command", 0),
548 BSET (SaveInTMP
, 0, "save-in-tmp", 0),
549 BSET (AllDirectionLines
, 0, "all-direction-lines", 0),
550 BSET (ShowNumber
, 0, "show-number", 0),
551 BSET (ResetAfterElement
, 1, "reset-after-element", 0),
552 BSET (RingBellWhenFinished
, 0, "ring-bell-finished", 0),
555 REGISTER_ATTRIBUTES (main_attribute_list
)
556 /* ----------------------------------------------------------------------
557 * post-process settings.
559 static void settings_post_process ()
561 if (Settings
.LibraryCommand
[0] != PCB_DIR_SEPARATOR_C
&& Settings
.LibraryCommand
[0] != '.')
563 Settings
.LibraryCommand
565 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
566 Settings
.LibraryCommand
,
569 if (Settings
.LibraryContentsCommand
[0] != PCB_DIR_SEPARATOR_C
570 && Settings
.LibraryContentsCommand
[0] != '.')
572 Settings
.LibraryContentsCommand
574 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
575 Settings
.LibraryContentsCommand
, NULL
);
578 if (Settings
.LineThickness
> MAX_LINESIZE
579 || Settings
.LineThickness
< MIN_LINESIZE
)
580 Settings
.LineThickness
= 1000;
582 if (Settings
.ViaThickness
> MAX_PINORVIASIZE
583 || Settings
.ViaThickness
< MIN_PINORVIASIZE
)
584 Settings
.ViaThickness
= 4000;
586 if (Settings
.ViaDrillingHole
<= 0)
587 Settings
.ViaDrillingHole
=
588 DEFAULT_DRILLINGHOLE
* Settings
.ViaThickness
/ 100;
590 Settings
.MaxWidth
= MIN (MAX_COORD
, MAX (Settings
.MaxWidth
, MIN_SIZE
));
591 Settings
.MaxHeight
= MIN (MAX_COORD
, MAX (Settings
.MaxHeight
, MIN_SIZE
));
593 ParseRouteString (Settings
.Routes
, &Settings
.RouteStyle
[0], 1);
597 /* ----------------------------------------------------------------------
598 * Print help or version messages.
604 printf ("PCB version %s\n", VERSION
);
608 /* ----------------------------------------------------------------------
609 * Figure out the canonical name of the executed program
610 * and fix up the defaults for various paths
613 char *exec_prefix
= NULL
;
614 char *pcblibdir
= NULL
;
615 char *pcblibpath
= NULL
;
616 char *pcbtreedir
= NULL
;
617 char *pcbtreepath
= NULL
;
618 char *homedir
= NULL
;
621 InitPaths (char *argv0
)
627 int found_bindir
= 0;
629 /* see if argv0 has enough of a path to let lrealpath give the
630 * real path. This should be the case if you invoke pcb with
631 * something like /usr/local/bin/pcb or ./pcb or ./foo/pcb
632 * but if you just use pcb and it exists in your path, you'll
633 * just get back pcb again.
637 for (i
= 0; i
< strlen (argv0
) ; i
++)
639 if (argv0
[i
] == PCB_DIR_SEPARATOR_C
)
644 printf ("InitPaths (%s): haspath = %d\n", argv0
, haspath
);
649 bindir
= strdup (lrealpath (argv0
));
654 char *path
, *p
, *tmps
;
658 tmps
= getenv ("PATH");
662 path
= strdup (tmps
);
664 /* search through the font path for a font file */
665 for (p
= strtok (path
, PCB_PATH_DELIMETER
); p
&& *p
;
666 p
= strtok (NULL
, PCB_PATH_DELIMETER
))
669 printf ("Looking for %s in %s\n", argv0
, p
);
671 if ( (tmps
= malloc ( (strlen (argv0
) + strlen (p
) + 2) * sizeof (char))) == NULL
)
673 fprintf (stderr
, "InitPaths(): malloc failed\n");
676 sprintf (tmps
, "%s%s%s", p
, PCB_DIR_SEPARATOR_S
, argv0
);
677 r
= stat (tmps
, &sb
);
681 printf ("Found it: \"%s\"\n", tmps
);
683 bindir
= lrealpath (tmps
);
695 printf ("InitPaths(): bindir = \"%s\"\n", bindir
);
700 /* strip off the executible name leaving only the path */
702 t1
= strchr (bindir
, PCB_DIR_SEPARATOR_C
);
703 while (t1
!= NULL
&& *t1
!= '\0')
706 t1
= strchr (t2
+ 1, PCB_DIR_SEPARATOR_C
);
712 printf ("After stripping off the executible name, we found\n");
713 printf ("bindir = \"%s\"\n", bindir
);
718 /* we have failed to find out anything from argv[0] so fall back to the original
721 bindir
= strdup (BINDIR
);
724 /* now find the path to exec_prefix */
725 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_EXECPREFIX
) + 1;
726 if ( (exec_prefix
= (char *) malloc (l
* sizeof (char) )) == NULL
)
728 fprintf (stderr
, "InitPaths(): malloc failed\n");
731 sprintf (exec_prefix
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
732 BINDIR_TO_EXECPREFIX
);
734 /* now find the path to PCBLIBDIR */
735 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBLIBDIR
) + 1;
736 if ( (pcblibdir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
738 fprintf (stderr
, "InitPaths(): malloc failed\n");
741 sprintf (pcblibdir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
742 BINDIR_TO_PCBLIBDIR
);
744 /* and the path to PCBTREEDIR */
745 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBTREEDIR
) + 1;
746 if ( (pcbtreedir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
748 fprintf (stderr
, "InitPaths(): malloc failed\n");
751 sprintf (pcbtreedir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
752 BINDIR_TO_PCBTREEDIR
);
754 /* and the search path including PCBLIBDIR */
755 l
= strlen (pcblibdir
) + 3;
756 if ( (pcblibpath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
758 fprintf (stderr
, "InitPaths(): malloc failed\n");
761 sprintf (pcblibpath
, ".%s%s", PCB_PATH_DELIMETER
, pcblibdir
);
763 /* and the newlib search path */
764 l
= strlen (pcblibdir
) + 1 + strlen (pcbtreedir
)
765 + strlen ("pcblib-newlib") + 2;
766 if ( (pcbtreepath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
768 fprintf (stderr
, "InitPaths(): malloc failed\n");
771 sprintf (pcbtreepath
, "%s%s%s%spcblib-newlib", pcbtreedir
,
772 PCB_PATH_DELIMETER
, pcblibdir
,
773 PCB_DIR_SEPARATOR_S
);
776 printf ("bindir = %s\n", bindir
);
777 printf ("pcblibdir = %s\n", pcblibdir
);
778 printf ("pcblibpath = %s\n", pcblibpath
);
779 printf ("pcbtreedir = %s\n", pcbtreedir
);
780 printf ("pcbtreepath = %s\n", pcbtreepath
);
783 l
= sizeof (main_attribute_list
) / sizeof (main_attribute_list
[0]);
784 for (i
= 0; i
< l
; i
++)
786 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-command-dir") == 0)
788 main_attribute_list
[i
].default_val
.str_value
= pcblibdir
;
791 if ( (NSTRCMP (main_attribute_list
[i
].name
, "font-path") == 0)
792 || (NSTRCMP (main_attribute_list
[i
].name
, "element-path") == 0)
793 || (NSTRCMP (main_attribute_list
[i
].name
, "lib-path") == 0) )
795 main_attribute_list
[i
].default_val
.str_value
= pcblibpath
;
798 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-newlib") == 0)
800 main_attribute_list
[i
].default_val
.str_value
= pcbtreepath
;
808 tmps
= getenv ("HOME");
811 tmps
= getenv ("USERPROFILE");
815 homedir
= strdup (tmps
);
823 /* ----------------------------------------------------------------------
827 char *program_name
= 0;
828 char *program_basename
= 0;
829 char *program_directory
= 0;
834 main (int argc
, char *argv
[])
839 * - make program name available for error handlers
840 * - evaluate special options
841 * - initialize toplevel shell and resources
842 * - create an empty PCB with default symbols
843 * - initialize all other widgets
844 * - update screen and get size of drawing area
845 * - evaluate command-line arguments
846 * - register 'call on exit()' function
849 #include "core_lists.h"
853 bindtextdomain (GETTEXT_PACKAGE
, LOCALEDIR
);
854 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
858 hid_load_settings ();
860 program_name
= argv
[0];
861 program_basename
= strrchr (program_name
, PCB_DIR_SEPARATOR_C
);
862 if (program_basename
)
864 program_directory
= strdup (program_name
);
865 *strrchr (program_directory
, PCB_DIR_SEPARATOR_C
) = 0;
870 program_directory
= ".";
871 program_basename
= program_name
;
873 Progname
= program_basename
;
875 if (argc
> 1 && strcmp (argv
[1], "-h") == 0)
877 if (argc
> 1 && strcmp (argv
[1], "-V") == 0)
879 if (argc
> 1 && strcmp (argv
[1], "-p") == 0)
881 exporter
= gui
= hid_find_printer ();
885 else if (argc
> 2 && strcmp (argv
[1], "-x") == 0)
887 exporter
= gui
= hid_find_exporter (argv
[2]);
892 gui
= hid_find_gui ();
897 for (i
= 0; i
< MAX_LAYER
; i
++)
900 sprintf (buf
, "signal%d", i
+ 1);
901 Settings
.DefaultLayerName
[i
] = MyStrdup (buf
, "DefaultLayerNames");
902 Settings
.LayerColor
[i
] = "#c49350";
903 Settings
.LayerSelectedColor
[i
] = "#00ffff";
906 gui
->parse_arguments (&argc
, &argv
);
908 if (show_help
|| (argc
> 1 && argv
[1][0] == '-'))
917 Output
.bgGC
= gui
->make_gc ();
918 Output
.fgGC
= gui
->make_gc ();
919 Output
.pmGC
= gui
->make_gc ();
920 Output
.GridGC
= gui
->make_gc ();
922 settings_post_process ();
933 extern void dump_actions (void);
938 PCB
= CreateNewPCB (True
);
939 PCB
->Data
->LayerN
= DEF_LAYER
;
940 ParseGroupString (Settings
.Groups
, &PCB
->LayerGroups
, DEF_LAYER
);
941 CreateNewPCBPost (PCB
, 1);
943 command_line_pcb
= argv
[1];
945 ResetStackAndVisibility ();
947 CreateDefaultFont ();
952 SetMode (ARROW_MODE
);
954 if (command_line_pcb
)
956 /* keep filename even if initial load command failed;
957 * file might not exist
959 if (LoadPCB (command_line_pcb
))
960 PCB
->Filename
= MyStrdup (command_line_pcb
, "main()");
963 if (Settings
.InitialLayerStack
964 && Settings
.InitialLayerStack
[0])
966 LayerStringToLayerStack (Settings
.InitialLayerStack
);
969 if (gui
->printer
|| gui
->exporter
)
976 LoadBackgroundImage (Settings.BackgroundImage); */
978 /* Register a function to be called when the program terminates.
979 * This makes sure that data is saved even if LEX/YACC routines
981 * If the OS doesn't have at least one of them,
982 * the critical sections will be handled by parse_l.l
984 atexit (EmergencySave
);
986 /* read the library file and display it if it's not empty
988 if (!ReadLibraryContents () && Library
.MenuN
)
989 hid_action ("LibraryChanged");
991 #ifdef HAVE_LIBSTROKE
995 * Set this flag to zero. Then if we have a startup
996 * action which includes Quit(), the flag will be set
997 * to -1 and we can avoid ever calling gtk_main();
999 Settings
.init_done
= 0;
1001 if (Settings
.ScriptFilename
)
1003 Message (_("Executing startup script file %s\n"),
1004 Settings
.ScriptFilename
);
1005 hid_actionl ("ExecuteFile", Settings
.ScriptFilename
, NULL
);
1007 if (Settings
.ActionString
)
1009 Message (_("Executing startup action %s\n"), Settings
.ActionString
);
1010 hid_parse_actions (Settings
.ActionString
, 0);
1013 if (Settings
.init_done
== 0)
1015 Settings
.init_done
= 1;
1023 printf ("Settings.LibraryCommandDir = \"%s\"\n",
1024 Settings
.LibraryCommandDir
);
1025 printf ("Settings.FontPath = \"%s\"\n",
1027 printf ("Settings.ElementPath = \"%s\"\n",
1028 Settings
.ElementPath
);
1029 printf ("Settings.LibraryPath = \"%s\"\n",
1030 Settings
.LibraryPath
);
1031 printf ("Settings.LibraryTree = \"%s\"\n",
1032 Settings
.LibraryTree
);