4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
28 /* main program, initializes some stuff and handles user input
41 #include <time.h> /* Seed for srand() */
47 #include "crosshair.h"
54 #include "lrealpath.h"
55 #include "free_atexit.h"
58 #include "pcb-printf.h"
60 #include "hid/common/actions.h"
62 /* This next one is so we can print the help messages. */
63 #include "hid/hidint.h"
69 #ifdef HAVE_LIBDMALLOC
73 #define PCBLIBPATH ".:" PCBLIBDIR
77 extern void stroke_init (void);
81 /* ----------------------------------------------------------------------
82 * initialize signal and error handlers
88 signal(SIGHUP, CatchSignal);
89 signal(SIGQUIT, CatchSignal);
90 signal(SIGABRT, CatchSignal);
91 signal(SIGSEGV, CatchSignal);
92 signal(SIGTERM, CatchSignal);
93 signal(SIGINT, CatchSignal);
96 /* calling external program by popen() may cause a PIPE signal,
100 signal (SIGPIPE
, SIG_IGN
);
105 /* ----------------------------------------------------------------------
106 | command line and rc file processing.
108 static char *command_line_pcb
;
114 " COPYRIGHT for %s version %s\n\n"
115 " PCB, interactive printed circuit board design\n"
116 " Copyright (C) 1994,1995,1996,1997 Thomas Nau\n"
117 " Copyright (C) 1998, 1999, 2000 Harry Eaton\n\n"
118 " This program is free software; you can redistribute it and/or modify\n"
119 " it under the terms of the GNU General Public License as published by\n"
120 " the Free Software Foundation; either version 2 of the License, or\n"
121 " (at your option) any later version.\n\n"
122 " This program is distributed in the hope that it will be useful,\n"
123 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
124 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
125 " GNU General Public License for more details.\n\n"
126 " You should have received a copy of the GNU General Public License\n"
127 " along with this program; if not, write to the Free Software\n"
128 " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
134 u (const char *fmt
, ...)
138 vfprintf (stderr
, fmt
, ap
);
139 fputc ('\n', stderr
);
143 typedef struct UsageNotes
{
144 struct UsageNotes
*next
;
148 static UsageNotes
*usage_notes
= NULL
;
151 usage_attr (HID_Attribute
* a
)
154 const Unit
*unit_list
;
155 static char buf
[200];
157 if (a
->help_text
== ATTR_UNDOCUMENTED
)
166 sprintf (buf
, "--%s <num>", a
->name
);
169 sprintf (buf
, "--%s <measure>", a
->name
);
172 sprintf (buf
, "--%s <string>", a
->name
);
175 sprintf (buf
, "--%s", a
->name
);
179 sprintf (buf
, "--%s ", a
->name
);
180 if (a
->type
== HID_Mixed
)
181 strcat (buf
, " <val>");
182 for (i
= 0; a
->enumerations
[i
]; i
++)
184 strcat (buf
, i
? "|" : "<");
185 strcat (buf
, a
->enumerations
[i
]);
190 sprintf (buf
, "--%s <path>", a
->name
);
193 unit_list
= get_unit_list ();
195 sprintf (buf
, "--%s ", a
->name
);
196 for (i
= 0; i
< n
; i
++)
198 strcat (buf
, i
? "|" : "<");
199 strcat (buf
, unit_list
[i
].suffix
);
205 if (strlen (buf
) <= 30)
208 fprintf (stderr
, " %-30s\t%s\n", buf
, a
->help_text
);
210 fprintf (stderr
, " %-30s\n", buf
);
212 else if (a
->help_text
&& strlen (a
->help_text
) + strlen (buf
) < 72)
213 fprintf (stderr
, " %s\t%s\n", buf
, a
->help_text
);
214 else if (a
->help_text
)
215 fprintf (stderr
, " %s\n\t\t\t%s\n", buf
, a
->help_text
);
217 fprintf (stderr
, " %s\n", buf
);
223 HID_Attribute
*attributes
;
224 int i
, n_attributes
= 0;
229 fprintf (stderr
, "\n%s gui options:\n", h
->name
);
230 attributes
= h
->get_export_options (&n_attributes
);
234 fprintf (stderr
, "\n%s options:\n", h
->name
);
236 attributes
= exporter
->get_export_options (&n_attributes
);
240 note
= (UsageNotes
*)malloc (sizeof (UsageNotes
));
241 note
->next
= usage_notes
;
242 note
->seen
= attributes
;
245 for (i
= 0; i
< n_attributes
; i
++)
246 usage_attr (attributes
+ i
);
252 HID
**hl
= hid_enumerate ();
256 int n_printer
= 0, n_gui
= 0, n_exporter
= 0;
258 for (i
= 0; hl
[i
]; i
++)
268 u ("PCB Printed Circuit Board editing program, http://pcb.geda-project.org");
269 u ("%s [-h|-V|--copyright]\t\t\tHelp, version, copyright", Progname
);
270 u ("%s [gui options] <pcb file>\t\tto edit", Progname
);
271 u ("Available GUI hid%s:", n_gui
== 1 ? "" : "s");
272 for (i
= 0; hl
[i
]; i
++)
274 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
275 u ("%s -p [printing options] <pcb file>\tto print", Progname
);
276 u ("Available printing hid%s:", n_printer
== 1 ? "" : "s");
277 for (i
= 0; hl
[i
]; i
++)
279 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
280 u ("%s -x hid [export options] <pcb file>\tto export", Progname
);
281 u ("Available export hid%s:", n_exporter
== 1 ? "" : "s");
282 for (i
= 0; hl
[i
]; i
++)
284 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
286 for (i
= 0; hl
[i
]; i
++)
289 for (i
= 0; hl
[i
]; i
++)
292 for (i
= 0; hl
[i
]; i
++)
296 u ("\nCommon options:");
297 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
299 for (note
= usage_notes
; note
&& note
->seen
!= ha
->attributes
; note
= note
->next
)
303 for (i
= 0; i
< ha
->n
; i
++)
305 usage_attr (ha
->attributes
+ i
);
313 print_defaults_1 (HID_Attribute
* a
, void *value
)
320 /* Remember, at this point we've parsed the command line, so they
321 may be in the global variable instead of the default_val. */
325 i
= value
? *(int *) value
: a
->default_val
.int_value
;
326 fprintf (stderr
, "%s %d\n", a
->name
, i
);
329 i
= value
? *(char *) value
: a
->default_val
.int_value
;
330 fprintf (stderr
, "%s %s\n", a
->name
, i
? "yes" : "no");
333 d
= value
? *(double *) value
: a
->default_val
.real_value
;
334 fprintf (stderr
, "%s %g\n", a
->name
, d
);
337 c
= value
? *(Coord
*) value
: a
->default_val
.coord_value
;
338 pcb_fprintf (stderr
, "%s %$mS\n", a
->name
, c
);
342 s
= value
? *(char **) value
: a
->default_val
.str_value
;
343 fprintf (stderr
, "%s \"%s\"\n", a
->name
, s
);
346 i
= value
? *(int *) value
: a
->default_val
.int_value
;
347 fprintf (stderr
, "%s %s\n", a
->name
, a
->enumerations
[i
]);
351 ((HID_Attr_Val
*)value
)->int_value
: a
->default_val
.int_value
;
353 ((HID_Attr_Val
*)value
)->real_value
: a
->default_val
.real_value
;
354 fprintf (stderr
, "%s %g%s\n", a
->name
, d
, a
->enumerations
[i
]);
359 i
= value
? *(int *) value
: a
->default_val
.int_value
;
360 fprintf (stderr
, "%s %s\n", a
->name
, get_unit_list()[i
].suffix
);
367 HID
**hl
= hid_enumerate ();
371 for (hi
= 0; hl
[hi
]; hi
++)
377 fprintf (stderr
, "\ngui defaults:\n");
378 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
379 for (i
= 0; i
< ha
->n
; i
++)
380 print_defaults_1 (ha
->attributes
+ i
, ha
->attributes
[i
].value
);
384 fprintf (stderr
, "\n%s defaults:\n", h
->name
);
386 e
= exporter
->get_export_options (&n
);
389 for (i
= 0; i
< n
; i
++)
390 print_defaults_1 (e
+ i
, 0);
396 #define SSET(F,D,N,H) { N, H, \
397 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
398 #define ISET(F,D,N,H) { N, H, \
399 HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }
400 #define BSET(F,D,N,H) { N, H, \
401 HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }
402 #define RSET(F,D,N,H) { N, H, \
403 HID_Real, 0, 0, { 0, 0, D }, 0, &Settings.F }
404 #define CSET(F,D,N,H) { N, H, \
405 HID_Coord, 0, 0, { 0, 0, 0, D }, 0, &Settings.F }
407 #define COLOR(F,D,N,H) { N, H, \
408 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
409 #define LAYERCOLOR(N,D) { "layer-color-" #N, "Color for layer " #N, \
410 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }
411 #define LAYERNAME(N,D) { "layer-name-" #N, "Name for layer " #N, \
412 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }
413 #define LAYERSELCOLOR(N) { "layer-selected-color-" #N, "Color for layer " #N " when selected", \
414 HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }
416 static int show_help
= 0;
417 static int show_version
= 0;
418 static int show_copyright
= 0;
419 static int show_defaults
= 0;
420 static int show_actions
= 0;
421 static int do_dump_actions
= 0;
422 static char *grid_units
;
423 static Increments increment_mm
= { 0 };
424 static Increments increment_mil
= { 0 };
426 void save_increments (const Increments
*mm
, const Increments
*mil
)
428 memcpy (&increment_mm
, mm
, sizeof (*mm
));
429 memcpy (&increment_mil
, mil
, sizeof (*mil
));
432 HID_Attribute main_attribute_list
[] = {
434 /* %start-doc options "1 General Options"
437 Show help on command line options.
441 {"help", "Show help on command line options", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
444 /* %start-doc options "1 General Options"
451 {"version", "Show version", HID_Boolean
, 0, 0, {0, 0, 0}, 0, &show_version
},
453 /* %start-doc options "1 General Options"
456 Be verbose on stdout.
460 {"verbose", "Be verbose on stdout", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
463 /* %start-doc options "1 General Options"
470 {"copyright", "Show Copyright", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
473 /* %start-doc options "1 General Options"
475 @item --show-defaults
476 Show option defaults.
480 {"show-defaults", "Show option defaults", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
483 /* %start-doc options "1 General Options"
486 Show available actions and exit.
490 {"show-actions", "Show available actions", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
493 /* %start-doc options "1 General Options"
496 Dump actions (for documentation).
500 {"dump-actions", "Dump actions (for documentation)", HID_Boolean
, 0, 0,
501 {0, 0, 0}, 0, &do_dump_actions
},
503 /* %start-doc options "1 General Options"
505 @item --grid-units-mm <string>
506 Set default grid units. Can be mm or mil. Defaults to mil.
510 {"grid-units", "Default grid units (mm|mil)", HID_String
, 0, 0, {0, "mil", 0},
513 /* %start-doc options "1 General Options"
515 @item --clear-increment-mm <string>
516 Set default clear increment (amount to change when user presses k or K)
517 when user is using a metric grid unit.
521 {"clear-increment-mm", "Default clear increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
522 0, &increment_mm
.clear
},
524 /* %start-doc options "1 General Options"
526 @item --grid-increment-mm <string>
527 Set default grid increment (amount to change when user presses g or G)
528 when user is using a metric grid unit.
532 {"grid-increment-mm", "Default grid increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
533 0, &increment_mm
.grid
},
535 /* %start-doc options "1 General Options"
537 @item --line-increment-mm <string>
538 Set default line increment (amount to change when user presses l or L)
539 when user is using a metric grid unit.
543 {"line-increment-mm", "Default line increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
544 0, &increment_mm
.line
},
546 /* %start-doc options "1 General Options"
548 @item --size-increment-mm <string>
549 Set default size increment (amount to change when user presses s or S)
550 when user is using a metric grid unit.
554 {"size-increment-mm", "Default size increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
555 0, &increment_mm
.size
},
557 /* %start-doc options "1 General Options"
559 @item --clear-increment-mil <string>
560 Set default clear increment (amount to change when user presses k or K)
561 when user is using an imperial grid unit.
565 {"clear-increment-mil", "Default clear increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
566 0, &increment_mil
.clear
},
568 /* %start-doc options "1 General Options"
570 @item --grid-increment-mil <string>
571 Set default grid increment (amount to change when user presses g or G)
572 when user is using a imperial grid unit.
576 {"grid-increment-mil", "Default grid increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
577 0, &increment_mil
.grid
},
579 /* %start-doc options "1 General Options"
581 @item --line-increment-mil <string>
582 Set default line increment (amount to change when user presses l or L)
583 when user is using a imperial grid unit.
587 {"line-increment-mil", "Default line increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
588 0, &increment_mil
.line
},
590 /* %start-doc options "1 General Options"
592 @item --size-increment-mil <string>
593 Set default size increment (amount to change when user presses s or S)
594 when user is using a imperial grid unit.
598 {"size-increment-mil", "Default size increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
599 0, &increment_mil
.size
},
601 /* %start-doc options "3 Colors"
603 @item --black-color <string>
604 Color value for black. Default: @samp{#000000}
608 COLOR (BlackColor
, "#000000", "black-color", "color value of 'black'"),
610 /* %start-doc options "3 Colors"
612 @item --black-color <string>
613 Color value for white. Default: @samp{#ffffff}
617 COLOR (WhiteColor
, "#ffffff", "white-color", "color value of 'white'"),
619 /* %start-doc options "3 Colors"
621 @item --background-color <string>
622 Background color of the canvas. Default: @samp{#e5e5e5}
626 COLOR (BackgroundColor
, "#e5e5e5", "background-color",
627 "color for background"),
629 /* %start-doc options "3 Colors"
631 @item --crosshair-color <string>
632 Color of the crosshair. Default: @samp{#ff0000}
636 COLOR (CrosshairColor
, "#ff0000", "crosshair-color",
637 "color for the crosshair"),
639 /* %start-doc options "3 Colors"
641 @item --cross-color <string>
642 Color of the cross. Default: @samp{#cdcd00}
646 COLOR (CrossColor
, "#cdcd00", "cross-color", "color of the cross"),
648 /* %start-doc options "3 Colors"
650 @item --via-color <string>
651 Color of vias. Default: @samp{#7f7f7f}
655 COLOR (ViaColor
, "#7f7f7f", "via-color", "color of vias"),
657 /* %start-doc options "3 Colors"
659 @item --via-selected-color <string>
660 Color of selected vias. Default: @samp{#00ffff}
664 COLOR (ViaSelectedColor
, "#00ffff", "via-selected-color",
665 "color for selected vias"),
667 /* %start-doc options "3 Colors"
669 @item --pin-color <string>
670 Color of pins. Default: @samp{#4d4d4d}
674 COLOR (PinColor
, "#4d4d4d", "pin-color", "color of pins"),
676 /* %start-doc options "3 Colors"
678 @item --pin-selected-color <string>
679 Color of selected pins. Default: @samp{#00ffff}
683 COLOR (PinSelectedColor
, "#00ffff", "pin-selected-color",
684 "color of selected pins"),
686 /* %start-doc options "3 Colors"
688 @item --pin-name-color <string>
689 Color of pin names and pin numbers. Default: @samp{#ff0000}
693 COLOR (PinNameColor
, "#ff0000", "pin-name-color",
694 "color for pin names and pin numbers"),
696 /* %start-doc options "3 Colors"
698 @item --element-color <string>
699 Color of components. Default: @samp{#000000}
703 COLOR (ElementColor
, "#000000", "element-color", "color of components"),
705 /* %start-doc options "3 Colors"
707 @item --rat-color <string>
708 Color of ratlines. Default: @samp{#b8860b}
712 COLOR (RatColor
, "#b8860b", "rat-color", "color of ratlines"),
714 /* %start-doc options "3 Colors"
716 @item --invisible-objects-color <string>
717 Color of invisible objects. Default: @samp{#cccccc}
721 COLOR (InvisibleObjectsColor
, "#cccccc", "invisible-objects-color",
722 "color of invisible objects"),
724 /* %start-doc options "3 Colors"
726 @item --invisible-mark-color <string>
727 Color of invisible marks. Default: @samp{#cccccc}
731 COLOR (InvisibleMarkColor
, "#cccccc", "invisible-mark-color",
732 "color of invisible marks"),
734 /* %start-doc options "3 Colors"
736 @item --element-selected-color <string>
737 Color of selected components. Default: @samp{#00ffff}
741 COLOR (ElementSelectedColor
, "#00ffff", "element-selected-color",
742 "color of selected components"),
744 /* %start-doc options "3 Colors"
746 @item --rat-selected-color <string>
747 Color of selected rats. Default: @samp{#00ffff}
751 COLOR (RatSelectedColor
, "#00ffff", "rat-selected-color",
752 "color of selected rats"),
754 /* %start-doc options "3 Colors"
756 @item --connected-color <string>
757 Color to indicate physical connections. Default: @samp{#00ff00}
761 COLOR (ConnectedColor
, "#00ff00", "connected-color",
762 "color to indicate physically connected objects"),
764 /* %start-doc options "3 Colors"
766 @item --found-color <string>
767 Color to indicate logical connections. Default: @samp{#ff00ff}
771 COLOR (FoundColor
, "#ff00ff", "found-color",
772 "color to indicate logically connected objects"),
774 /* %start-doc options "3 Colors"
776 @item --off-limit-color <string>
777 Color of off-canvas area. Default: @samp{#cccccc}
781 COLOR (OffLimitColor
, "#cccccc", "off-limit-color",
782 "color of off-canvas area"),
784 /* %start-doc options "3 Colors"
786 @item --grid-color <string>
787 Color of the grid. Default: @samp{#ff0000}
791 COLOR (GridColor
, "#ff0000", "grid-color", "color of the grid"),
793 /* %start-doc options "3 Colors"
795 @item --layer-color-<n> <string>
796 Color of layer @code{<n>}, where @code{<n>} is an integer from 1 to 16.
800 LAYERCOLOR (1, "#8b2323"),
801 LAYERCOLOR (2, "#3a5fcd"),
802 LAYERCOLOR (3, "#104e8b"),
803 LAYERCOLOR (4, "#cd3700"),
804 LAYERCOLOR (5, "#548b54"),
805 LAYERCOLOR (6, "#8b7355"),
806 LAYERCOLOR (7, "#00868b"),
807 LAYERCOLOR (8, "#228b22"),
808 LAYERCOLOR (9, "#8b2323"),
809 LAYERCOLOR (10, "#3a5fcd"),
810 LAYERCOLOR (11, "#104e8b"),
811 LAYERCOLOR (12, "#cd3700"),
812 LAYERCOLOR (13, "#548b54"),
813 LAYERCOLOR (14, "#8b7355"),
814 LAYERCOLOR (15, "#00868b"),
815 LAYERCOLOR (16, "#228b22"),
816 /* %start-doc options "3 Colors"
818 @item --layer-selected-color-<n> <string>
819 Color of layer @code{<n>}, when selected. @code{<n>} is an integer from 1 to 16.
840 /* %start-doc options "3 Colors"
842 @item --warn-color <string>
843 Color of offending objects during DRC. Default value is @code{"#ff8000"}
847 COLOR (WarnColor
, "#ff8000", "warn-color", "color of offending objects during DRC"),
849 /* %start-doc options "3 Colors"
851 @item --mask-color <string>
852 Color of the mask layer. Default value is @code{"#ff0000"}
856 COLOR (MaskColor
, "#ff0000", "mask-color", "color for solder mask"),
859 /* %start-doc options "5 Sizes"
860 All parameters should be given with an unit. If no unit is given, 1/100 mil
861 (cmil) will be used. Write units without space to the
862 number like @code{3mm}, not @code{3 mm}.
886 @item --via-thickness <num>
887 Default diameter of vias. Default value is @code{60mil}.
891 CSET (ViaThickness
, MIL_TO_COORD(60), "via-thickness",
892 "default diameter of vias in 1/100 mil"),
894 /* %start-doc options "5 Sizes"
896 @item --via-drilling-hole <num>
897 Default diameter of holes. Default value is @code{28mil}.
901 CSET (ViaDrillingHole
, MIL_TO_COORD(28), "via-drilling-hole",
902 "default diameter of holes"),
904 /* %start-doc options "5 Sizes"
906 @item --line-thickness <num>
907 Default thickness of new lines. Default value is @code{10mil}.
911 CSET (LineThickness
, MIL_TO_COORD(10), "line-thickness",
912 "initial thickness of new lines"),
914 /* %start-doc options "5 Sizes"
916 @item --rat-thickness <num><unit>
917 Thickness of rats. If no unit is given, PCB units are assumed (i.e. 100
918 means "1 nm"). This option allows for a special unit @code{px} which
919 sets the rat thickness to a fixed value in terms of screen pixels.
920 Maximum fixed thickness is 100px. Minimum saling rat thickness is 101nm.
921 Default value is @code{10mil}.
925 CSET (RatThickness
, MIL_TO_COORD(10), "rat-thickness", "thickness of rat lines"),
927 /* %start-doc options "5 Sizes"
929 @item --keepaway <num>
930 Default minimum distance between a track and adjacent copper.
931 Default value is @code{10mil}.
935 CSET (Keepaway
, MIL_TO_COORD(10), "keepaway", "minimum distance between adjacent copper"),
937 /* %start-doc options "5 Sizes"
939 @item --default-PCB-width <num>
940 Default width of the canvas. Default value is @code{6000mil}.
944 CSET (MaxWidth
, MIL_TO_COORD(6000), "default-PCB-width",
945 "default width of the canvas"),
947 /* %start-doc options "5 Sizes"
949 @item --default-PCB-height <num>
950 Default height of the canvas. Default value is @code{5000mil}.
954 CSET (MaxHeight
, MIL_TO_COORD(5000), "default-PCB-height",
955 "default height of the canvas"),
957 /* %start-doc options "5 Sizes"
959 @item --text-scale <num>
960 Default text scale. This value is in percent. Default value is @code{100}.
964 ISET (TextScale
, 100, "text-scale", "default text scale in percent"),
966 /* %start-doc options "5 Sizes"
968 @item --alignment-distance <num>
969 Specifies the distance between the board outline and alignment targets.
970 Default value is @code{2mil}.
974 CSET (AlignmentDistance
, MIL_TO_COORD(2), "alignment-distance",
975 "distance between the boards outline and alignment targets"),
977 /* %start-doc options "7 DRC Options"
978 All parameters should be given with an unit. If no unit is given, 1/100 mil
979 (cmil) will be used for backward compability. Valid units are given in section
985 /* %start-doc options "7 DRC Options"
988 Minimum spacing. Default value is @code{10mil}.
992 CSET (Bloat
, MIL_TO_COORD(10), "bloat", "DRC minimum spacing in 1/100 mil"),
994 /* %start-doc options "7 DRC Options"
997 Minimum touching overlap. Default value is @code{10mil}.
1001 CSET (Shrink
, MIL_TO_COORD(10), "shrink", "DRC minimum overlap in 1/100 mils"),
1003 /* %start-doc options "7 DRC Options"
1005 @item --min-width <num>
1006 Minimum width of copper. Default value is @code{10mil}.
1010 CSET (minWid
, MIL_TO_COORD(10), "min-width", "DRC minimum copper spacing"),
1012 /* %start-doc options "7 DRC Options"
1014 @item --min-silk <num>
1015 Minimum width of lines in silk. Default value is @code{10mil}.
1019 CSET (minSlk
, MIL_TO_COORD(10), "min-silk", "DRC minimum silk width"),
1021 /* %start-doc options "7 DRC Options"
1023 @item --min-drill <num>
1024 Minimum diameter of holes. Default value is @code{15mil}.
1028 CSET (minDrill
, MIL_TO_COORD(15), "min-drill", "DRC minimum drill diameter"),
1030 /* %start-doc options "7 DRC Options"
1032 @item --min-ring <num>
1033 Minimum width of annular ring. Default value is @code{10mil}.
1037 CSET (minRing
, MIL_TO_COORD(10), "min-ring", "DRC minimum annular ring"),
1040 /* %start-doc options "5 Sizes"
1043 Initial grid size. Default value is @code{10mil}.
1047 CSET (Grid
, MIL_TO_COORD(10), "grid", "Initial grid size in 1/100 mil"),
1049 /* %start-doc options "5 Sizes"
1051 @item --minimum polygon area <num>
1052 Minimum polygon area.
1056 RSET (IsleArea
, MIL_TO_COORD(100) * MIL_TO_COORD(100), "minimum polygon area", 0),
1059 /* %start-doc options "1 General Options"
1061 @item --backup-interval
1062 Time between automatic backups in seconds. Set to @code{0} to disable.
1063 The default value is @code{60}.
1067 ISET (BackupInterval
, 60, "backup-interval",
1068 "Time between automatic backups in seconds. Set to 0 to disable"),
1070 /* %start-doc options "4 Layer Names"
1072 @item --layer-name-1 <string>
1073 Name of the 1st Layer. Default is @code{"top"}.
1077 LAYERNAME (1, "top"),
1079 /* %start-doc options "4 Layer Names"
1081 @item --layer-name-2 <string>
1082 Name of the 2nd Layer. Default is @code{"ground"}.
1086 LAYERNAME (2, "ground"),
1088 /* %start-doc options "4 Layer Names"
1090 @item --layer-name-3 <string>
1091 Name of the 3nd Layer. Default is @code{"signal2"}.
1095 LAYERNAME (3, "signal2"),
1097 /* %start-doc options "4 Layer Names"
1099 @item --layer-name-4 <string>
1100 Name of the 4rd Layer. Default is @code{"signal3"}.
1104 LAYERNAME (4, "signal3"),
1106 /* %start-doc options "4 Layer Names"
1108 @item --layer-name-5 <string>
1109 Name of the 5rd Layer. Default is @code{"power"}.
1113 LAYERNAME (5, "power"),
1115 /* %start-doc options "4 Layer Names"
1117 @item --layer-name-6 <string>
1118 Name of the 6rd Layer. Default is @code{"bottom"}.
1122 LAYERNAME (6, "bottom"),
1124 /* %start-doc options "4 Layer Names"
1126 @item --layer-name-7 <string>
1127 Name of the 7rd Layer. Default is @code{"outline"}.
1131 LAYERNAME (7, "outline"),
1133 /* %start-doc options "4 Layer Names"
1135 @item --layer-name-8 <string>
1136 Name of the 8rd Layer. Default is @code{"spare"}.
1140 LAYERNAME (8, "spare"),
1142 /* %start-doc options "1 General Options"
1144 @item --groups <string>
1145 Layer group string. Defaults to @code{"1,c:2:3:4:5:6,s:7:8"}.
1149 SSET (Groups
, "1,c:2:3:4:5:6,s:7:8", "groups", "Layer group string"),
1152 /* %start-doc options "6 Commands"
1153 pcb uses external commands for input output operations. These commands can be
1154 configured at start-up to meet local requirements. The command string may include
1155 special sequences @code{%f}, @code{%p} or @code{%a}. These are replaced when the
1156 command is called. The sequence @code{%f} is replaced by the file name,
1157 @code{%p} gets the path and @code{%a} indicates a package name.
1161 /* %start-doc options "6 Commands"
1163 @item --font-command <string>
1164 Command to load a font.
1168 SSET (FontCommand
, "", "font-command", "Command to load a font"),
1170 /* %start-doc options "6 Commands"
1172 @item --file-command <string>
1173 Command to read a file.
1177 SSET (FileCommand
, "", "file-command", "Command to read a file"),
1179 /* %start-doc options "6 Commands"
1181 @item --element-command <string>
1182 Command to read a footprint. @*
1183 Defaults to @code{"M4PATH='%p';export M4PATH;echo 'include(%f)' | m4"}
1187 SSET (ElementCommand
,
1188 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4
,
1189 "element-command", "Command to read a footprint"),
1191 /* %start-doc options "6 Commands"
1193 @item --print-file <string>
1194 Command to print to a file.
1198 SSET (PrintFile
, "%f.output", "print-file", "Command to print to a file"),
1200 /* %start-doc options "6 Commands"
1202 @item --lib-command-dir <string>
1203 Path to the command that queries the library.
1207 SSET (LibraryCommandDir
, PCBLIBDIR
, "lib-command-dir",
1208 "Path to the command that queries the library"),
1210 /* %start-doc options "6 Commands"
1212 @item --lib-command <string>
1213 Command to query the library. @*
1214 Defaults to @code{"QueryLibrary.sh '%p' '%f' %a"}
1218 SSET (LibraryCommand
, "QueryLibrary.sh '%p' '%f' %a",
1219 "lib-command", "Command to query the library"),
1221 /* %start-doc options "6 Commands"
1223 @item --lib-contents-command <string>
1224 Command to query the contents of the library. @*
1225 Defaults to @code{"ListLibraryContents.sh %p %f"} or,
1226 on Windows builds, an empty string (to disable this feature).
1230 SSET (LibraryContentsCommand
,
1234 "ListLibraryContents.sh '%p' '%f'",
1236 "lib-contents-command", "Command to query the contents of the library"),
1238 /* %start-doc options "5 Paths"
1240 @item --lib-newlib <string>
1241 Top level directory for the newlib style library.
1245 SSET (LibraryTree
, PCBTREEPATH
, "lib-newlib",
1246 "Top level directory for the newlib style library"),
1248 /* %start-doc options "6 Commands"
1250 @item --save-command <string>
1251 Command to save to a file.
1255 SSET (SaveCommand
, "", "save-command", "Command to save to a file"),
1257 /* %start-doc options "5 Paths"
1259 @item --lib-name <string>
1260 The default filename for the library.
1264 SSET (LibraryFilename
, LIBRARYFILENAME
, "lib-name",
1265 "The default filename for the library"),
1267 /* %start-doc options "5 Paths"
1269 @item --default-font <string>
1270 The name of the default font.
1274 SSET (FontFile
, "default_font", "default-font",
1275 "File name of default font"),
1277 /* %start-doc options "1 General Options"
1279 @item --route-styles <string>
1280 A string that defines the route styles. Defaults to @*
1281 @code{"Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000
1282 :Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"}
1286 SSET (Routes
, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
1287 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
1288 "A string that defines the route styles"),
1290 /* %start-doc options "5 Paths"
1292 @item --file-path <string>
1293 A colon separated list of directories or commands (starts with '|'). The path
1294 is passed to the program specified in @option{--file-command} together with the selected
1299 SSET (FilePath
, "", "file-path", 0),
1301 /* %start-doc options "6 Commands"
1303 @item --rat-command <string>
1304 Command for reading a netlist. Sequence @code{%f} is replaced by the netlist filename.
1308 SSET (RatCommand
, "", "rat-command", "Command for reading a netlist"),
1310 /* %start-doc options "5 Paths"
1312 @item --font-path <string>
1313 A colon separated list of directories to search the default font. Defaults to
1314 the default library path.
1318 SSET (FontPath
, PCBLIBPATH
, "font-path",
1319 "Colon separated list of directories to search the default font"),
1321 /* %start-doc options "1 General Options"
1323 @item --element-path <string>
1324 A colon separated list of directories or commands (starts with '|').
1325 The path is passed to the program specified in @option{--element-command}.
1329 SSET(ElementPath
, PCBLIBPATH
, "element-path",
1330 "A colon separated list of directories or commands (starts with '|')"),
1332 /* %start-doc options "5 Paths"
1334 @item --lib-path <string>
1335 A colon separated list of directories that will be passed to the commands specified
1336 by @option{--element-command} and @option{--element-contents-command}.
1340 SSET (LibraryPath
, PCBLIBPATH
, "lib-path",
1341 "A colon separated list of directories"),
1343 /* %start-doc options "1 General Options"
1345 @item --action-script <string>
1346 If set, this file is executed at startup.
1350 SSET (ScriptFilename
, 0, "action-script",
1351 "If set, this file is executed at startup"),
1353 /* %start-doc options "1 General Options"
1355 @item --action-string <string>
1356 If set, this string of actions is executed at startup.
1360 SSET (ActionString
, 0, "action-string",
1361 "If set, this is executed at startup"),
1363 /* %start-doc options "1 General Options"
1365 @item --fab-author <string>
1366 Name of author to be put in the Gerber files.
1370 SSET (FabAuthor
, "", "fab-author",
1371 "Name of author to be put in the Gerber files"),
1373 /* %start-doc options "1 General Options"
1375 @item --layer-stack <string>
1376 Initial layer stackup, for setting up an export. A comma separated list of layer
1377 names, layer numbers and layer groups.
1381 SSET (InitialLayerStack
, "", "layer-stack",
1382 "Initial layer stackup, for setting up an export."),
1384 SSET (MakeProgram
, NULL
, "make-program",
1385 "Sets the name and optionally full path to a make(3) program"),
1386 SSET (GnetlistProgram
, NULL
, "gnetlist",
1387 "Sets the name and optionally full path to the gnetlist(3) program"),
1389 /* %start-doc options "2 General GUI Options"
1391 @item --pinout-offset-x <num>
1392 Horizontal offset of the pin number display. Defaults to @code{100mil}.
1396 CSET (PinoutOffsetX
, MIL_TO_COORD(1), "pinout-offset-x",
1397 "Horizontal offset of the pin number display in mil"),
1399 /* %start-doc options "2 General GUI Options"
1401 @item --pinout-offset-y <num>
1402 Vertical offset of the pin number display. Defaults to @code{100mil}.
1406 CSET (PinoutOffsetY
, MIL_TO_COORD(1), "pinout-offset-y",
1407 "Vertical offset of the pin number display in mil"),
1409 /* %start-doc options "2 General GUI Options"
1411 @item --pinout-text-offset-x <num>
1412 Horizontal offset of the pin name display. Defaults to @code{800mil}.
1416 CSET (PinoutTextOffsetX
, MIL_TO_COORD(8), "pinout-text-offset-x",
1417 "Horizontal offset of the pin name display in mil"),
1419 /* %start-doc options "2 General GUI Options"
1421 @item --pinout-text-offset-y <num>
1422 Vertical offset of the pin name display. Defaults to @code{-100mil}.
1426 CSET (PinoutTextOffsetY
, MIL_TO_COORD(-1), "pinout-text-offset-y",
1427 "Vertical offset of the pin name display in mil"),
1429 /* %start-doc options "2 General GUI Options"
1432 If set, draw the grid at start-up.
1436 BSET (DrawGrid
, 0, "draw-grid", "If set, draw the grid at start-up"),
1438 /* %start-doc options "2 General GUI Options"
1441 If set, new lines clear polygons.
1445 BSET (ClearLine
, 1, "clear-line", "If set, new lines clear polygons"),
1447 /* %start-doc options "2 General GUI Options"
1450 If set, new polygons are full ones.
1454 BSET (FullPoly
, 0, "full-poly", 0),
1456 /* %start-doc options "2 General GUI Options"
1458 @item --unique-names
1459 If set, you will not be permitted to change the name of an component to match that
1460 of another component.
1464 BSET (UniqueNames
, 1, "unique-names", "Prevents identical component names"),
1466 /* %start-doc options "2 General GUI Options"
1469 If set, pin centers and pad end points are treated as additional grid points
1470 that the cursor can snap to.
1474 BSET (SnapPin
, 1, "snap-pin",
1475 "If set, the cursor snaps to pads and pin centers"),
1477 /* %start-doc options "1 General Options"
1479 @item --save-last-command
1480 If set, the last user command is saved.
1484 BSET (SaveLastCommand
, 0, "save-last-command", 0),
1486 /* %start-doc options "1 General Options"
1489 If set, all data which would otherwise be lost are saved in a temporary file
1490 @file{/tmp/PCB.%i.save} . Sequence @samp{%i} is replaced by the process ID.
1494 BSET (SaveInTMP
, 0, "save-in-tmp",
1495 "When set, all data which would otherwise be lost are saved in /tmp"),
1497 /* %start-doc options "1 General Options"
1499 @item --save-metric-only
1500 If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm.
1504 BSET (SaveMetricOnly
, 0, "save-metric-only",
1505 "If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm."),
1507 /* %start-doc options "2 General GUI Options"
1509 @item --all-direction-lines
1510 Allow all directions, when drawing new lines.
1514 BSET (AllDirectionLines
, 0, "all-direction-lines",
1515 "Allow all directions, when drawing new lines"),
1517 /* %start-doc options "2 General GUI Options"
1520 Pinout shows number.
1524 BSET (ShowNumber
, 0, "show-number", "Pinout shows number"),
1526 /* %start-doc options "1 General Options"
1528 @item --reset-after-element
1529 If set, all found connections are reset before a new component is scanned.
1533 BSET (ResetAfterElement
, 1, "reset-after-element",
1534 "If set, all found connections are reset before a new component is scanned"),
1536 /* %start-doc options "1 General Options"
1538 @item --ring-bell-finished
1539 Execute the bell command when all rats are routed.
1543 BSET (RingBellWhenFinished
, 0, "ring-bell-finished",
1544 "Execute the bell command when all rats are routed"),
1547 REGISTER_ATTRIBUTES (main_attribute_list
)
1548 /* ----------------------------------------------------------------------
1549 * post-process settings.
1551 static void settings_post_process ()
1555 if (Settings
.LibraryCommand
!= NULL
&&
1556 Settings
.LibraryCommand
[0] != '\0' &&
1557 Settings
.LibraryCommand
[0] != PCB_DIR_SEPARATOR_C
&&
1558 Settings
.LibraryCommand
[0] != '.')
1560 Settings
.LibraryCommand
1562 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
1563 Settings
.LibraryCommand
,
1566 if (Settings
.LibraryContentsCommand
!= NULL
&&
1567 Settings
.LibraryContentsCommand
[0] != '\0' &&
1568 Settings
.LibraryContentsCommand
[0] != PCB_DIR_SEPARATOR_C
&&
1569 Settings
.LibraryContentsCommand
[0] != '.')
1571 Settings
.LibraryContentsCommand
1573 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
1574 Settings
.LibraryContentsCommand
, NULL
);
1577 if (Settings
.LineThickness
> MAX_LINESIZE
1578 || Settings
.LineThickness
< MIN_LINESIZE
)
1579 Settings
.LineThickness
= MIL_TO_COORD(10);
1581 if (Settings
.ViaThickness
> MAX_PINORVIASIZE
1582 || Settings
.ViaThickness
< MIN_PINORVIASIZE
)
1583 Settings
.ViaThickness
= MIL_TO_COORD(40);
1585 if (Settings
.ViaDrillingHole
<= 0)
1586 Settings
.ViaDrillingHole
=
1587 DEFAULT_DRILLINGHOLE
* Settings
.ViaThickness
/ 100;
1589 Settings
.MaxWidth
= CLAMP (Settings
.MaxWidth
, MIN_SIZE
, MAX_COORD
);
1590 Settings
.MaxHeight
= CLAMP (Settings
.MaxHeight
, MIN_SIZE
, MAX_COORD
);
1592 ParseRouteString (Settings
.Routes
, &Settings
.RouteStyle
[0], "cmil");
1595 * Make sure we have settings for some various programs we may wish
1598 if (Settings
.MakeProgram
== NULL
) {
1599 tmps
= getenv ("PCB_MAKE_PROGRAM");
1601 Settings
.MakeProgram
= strdup (tmps
);
1603 if (Settings
.MakeProgram
== NULL
) {
1604 Settings
.MakeProgram
= strdup ("make");
1607 if (Settings
.GnetlistProgram
== NULL
) {
1608 tmps
= getenv ("PCB_GNETLIST");
1610 Settings
.GnetlistProgram
= strdup (tmps
);
1612 if (Settings
.GnetlistProgram
== NULL
) {
1613 Settings
.GnetlistProgram
= strdup ("gnetlist");
1617 Settings
.grid_unit
= get_unit_struct (grid_units
);
1618 if (!grid_units
|| Settings
.grid_unit
== NULL
)
1619 Settings
.grid_unit
= get_unit_struct ("mil");
1621 copy_nonzero_increments (get_increments_struct (METRIC
), &increment_mm
);
1622 copy_nonzero_increments (get_increments_struct (IMPERIAL
), &increment_mil
);
1624 Settings
.increments
= get_increments_struct (Settings
.grid_unit
->family
);
1627 /* ----------------------------------------------------------------------
1628 * Print help or version messages.
1634 printf ("PCB version %s\n", VERSION
);
1638 /* ----------------------------------------------------------------------
1639 * Figure out the canonical name of the executed program
1640 * and fix up the defaults for various paths
1642 char *bindir
= NULL
;
1643 char *exec_prefix
= NULL
;
1644 char *pcblibdir
= NULL
;
1645 char *pcblibpath
= NULL
;
1646 char *pcbtreedir
= NULL
;
1647 char *pcbtreepath
= NULL
;
1648 char *homedir
= NULL
;
1651 InitPaths (char *argv0
)
1657 int found_bindir
= 0;
1659 /* see if argv0 has enough of a path to let lrealpath give the
1660 * real path. This should be the case if you invoke pcb with
1661 * something like /usr/local/bin/pcb or ./pcb or ./foo/pcb
1662 * but if you just use pcb and it exists in your path, you'll
1663 * just get back pcb again.
1667 for (i
= 0; i
< strlen (argv0
) ; i
++)
1669 if (argv0
[i
] == PCB_DIR_SEPARATOR_C
)
1674 printf ("InitPaths (%s): haspath = %d\n", argv0
, haspath
);
1679 bindir
= strdup (lrealpath (argv0
));
1684 char *path
, *p
, *tmps
;
1688 tmps
= getenv ("PATH");
1692 path
= strdup (tmps
);
1694 /* search through the font path for a font file */
1695 for (p
= strtok (path
, PCB_PATH_DELIMETER
); p
&& *p
;
1696 p
= strtok (NULL
, PCB_PATH_DELIMETER
))
1699 printf ("Looking for %s in %s\n", argv0
, p
);
1701 if ( (tmps
= (char *)malloc ( (strlen (argv0
) + strlen (p
) + 2) * sizeof (char))) == NULL
)
1703 fprintf (stderr
, "InitPaths(): malloc failed\n");
1706 sprintf (tmps
, "%s%s%s", p
, PCB_DIR_SEPARATOR_S
, argv0
);
1707 r
= stat (tmps
, &sb
);
1711 printf ("Found it: \"%s\"\n", tmps
);
1713 bindir
= lrealpath (tmps
);
1725 printf ("InitPaths(): bindir = \"%s\"\n", bindir
);
1730 /* strip off the executible name leaving only the path */
1732 t1
= strchr (bindir
, PCB_DIR_SEPARATOR_C
);
1733 while (t1
!= NULL
&& *t1
!= '\0')
1736 t1
= strchr (t2
+ 1, PCB_DIR_SEPARATOR_C
);
1742 printf ("After stripping off the executible name, we found\n");
1743 printf ("bindir = \"%s\"\n", bindir
);
1748 /* we have failed to find out anything from argv[0] so fall back to the original
1751 bindir
= strdup (BINDIR
);
1754 /* now find the path to exec_prefix */
1755 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_EXECPREFIX
) + 1;
1756 if ( (exec_prefix
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1758 fprintf (stderr
, "InitPaths(): malloc failed\n");
1761 sprintf (exec_prefix
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1762 BINDIR_TO_EXECPREFIX
);
1764 /* now find the path to PCBLIBDIR */
1765 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBLIBDIR
) + 1;
1766 if ( (pcblibdir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1768 fprintf (stderr
, "InitPaths(): malloc failed\n");
1771 sprintf (pcblibdir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1772 BINDIR_TO_PCBLIBDIR
);
1774 /* and the path to PCBTREEDIR */
1775 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBTREEDIR
) + 1;
1776 if ( (pcbtreedir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1778 fprintf (stderr
, "InitPaths(): malloc failed\n");
1781 sprintf (pcbtreedir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1782 BINDIR_TO_PCBTREEDIR
);
1784 /* and the search path including PCBLIBDIR */
1785 l
= strlen (pcblibdir
) + 3;
1786 if ( (pcblibpath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1788 fprintf (stderr
, "InitPaths(): malloc failed\n");
1791 sprintf (pcblibpath
, ".%s%s", PCB_PATH_DELIMETER
, pcblibdir
);
1793 /* and the newlib search path */
1794 l
= strlen (pcblibdir
) + 1 + strlen (pcbtreedir
)
1795 + strlen ("pcblib-newlib") + 2;
1796 if ( (pcbtreepath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1798 fprintf (stderr
, "InitPaths(): malloc failed\n");
1801 sprintf (pcbtreepath
, "%s%s%s%spcblib-newlib", pcbtreedir
,
1802 PCB_PATH_DELIMETER
, pcblibdir
,
1803 PCB_DIR_SEPARATOR_S
);
1806 printf ("bindir = %s\n", bindir
);
1807 printf ("pcblibdir = %s\n", pcblibdir
);
1808 printf ("pcblibpath = %s\n", pcblibpath
);
1809 printf ("pcbtreedir = %s\n", pcbtreedir
);
1810 printf ("pcbtreepath = %s\n", pcbtreepath
);
1813 l
= sizeof (main_attribute_list
) / sizeof (main_attribute_list
[0]);
1814 for (i
= 0; i
< l
; i
++)
1816 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-command-dir") == 0)
1818 main_attribute_list
[i
].default_val
.str_value
= pcblibdir
;
1821 if ( (NSTRCMP (main_attribute_list
[i
].name
, "font-path") == 0)
1822 || (NSTRCMP (main_attribute_list
[i
].name
, "element-path") == 0)
1823 || (NSTRCMP (main_attribute_list
[i
].name
, "lib-path") == 0) )
1825 main_attribute_list
[i
].default_val
.str_value
= pcblibpath
;
1828 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-newlib") == 0)
1830 main_attribute_list
[i
].default_val
.str_value
= pcbtreepath
;
1838 tmps
= getenv ("HOME");
1841 tmps
= getenv ("USERPROFILE");
1845 homedir
= strdup (tmps
);
1853 /* ----------------------------------------------------------------------
1857 char *program_name
= 0;
1858 char *program_basename
= 0;
1859 char *program_directory
= 0;
1861 #include "dolists.h"
1864 main (int argc
, char *argv
[])
1868 /* init application:
1869 * - make program name available for error handlers
1870 * - evaluate special options
1871 * - initialize toplevel shell and resources
1872 * - create an empty PCB with default symbols
1873 * - initialize all other widgets
1874 * - update screen and get size of drawing area
1875 * - evaluate command-line arguments
1876 * - register 'call on exit()' function
1879 #include "core_lists.h"
1881 InitPaths (argv
[0]);
1883 bindtextdomain (GETTEXT_PACKAGE
, LOCALEDIR
);
1884 textdomain (GETTEXT_PACKAGE
);
1885 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
1888 setlocale (LC_ALL
, "");
1889 setlocale (LC_NUMERIC
, "C");
1892 srand ( time(NULL
) ); /* Set seed for rand() */
1898 hid_load_settings ();
1900 program_name
= argv
[0];
1901 program_basename
= strrchr (program_name
, PCB_DIR_SEPARATOR_C
);
1902 if (program_basename
)
1904 program_directory
= strdup (program_name
);
1905 *strrchr (program_directory
, PCB_DIR_SEPARATOR_C
) = 0;
1910 program_directory
= ".";
1911 program_basename
= program_name
;
1913 Progname
= program_basename
;
1915 /* Print usage or version if requested. Then exit. */
1917 (strcmp (argv
[1], "-h") == 0 ||
1918 strcmp (argv
[1], "-?") == 0 ||
1919 strcmp (argv
[1], "--help") == 0))
1921 if (argc
> 1 && strcmp (argv
[1], "-V") == 0)
1923 /* Export pcb from command line if requested. */
1924 if (argc
> 1 && strcmp (argv
[1], "-p") == 0)
1926 exporter
= gui
= hid_find_printer ();
1930 else if (argc
> 2 && strcmp (argv
[1], "-x") == 0)
1932 exporter
= gui
= hid_find_exporter (argv
[2]);
1936 /* Otherwise start GUI. */
1938 gui
= hid_find_gui ();
1940 /* Exit with error if GUI failed to start. */
1944 /* Set up layers. */
1945 for (i
= 0; i
< MAX_LAYER
; i
++)
1948 sprintf (buf
, "signal%d", i
+ 1);
1949 Settings
.DefaultLayerName
[i
] = strdup (buf
);
1950 Settings
.LayerColor
[i
] = "#c49350";
1951 Settings
.LayerSelectedColor
[i
] = "#00ffff";
1954 gui
->parse_arguments (&argc
, &argv
);
1956 if (show_help
|| (argc
> 1 && argv
[1][0] == '-'))
1965 settings_post_process ();
1974 if (do_dump_actions
)
1976 extern void dump_actions (void);
1981 /* Create a new PCB object in memory */
1982 PCB
= CreateNewPCB ();
1983 ParseGroupString (Settings
.Groups
, &PCB
->LayerGroups
, &PCB
->Data
->LayerN
);
1984 /* Add silk layers to newly created PCB */
1985 CreateNewPCBPost (PCB
, 1);
1987 command_line_pcb
= argv
[1];
1989 ResetStackAndVisibility ();
1994 SetMode (ARROW_MODE
);
1996 if (command_line_pcb
)
1998 /* keep filename even if initial load command failed;
1999 * file might not exist
2001 if (LoadPCB (command_line_pcb
))
2002 PCB
->Filename
= strdup (command_line_pcb
);
2005 if (Settings
.InitialLayerStack
2006 && Settings
.InitialLayerStack
[0])
2008 LayerStringToLayerStack (Settings
.InitialLayerStack
);
2011 /* This must be called before any other atexit functions
2012 * are registered, as it configures an atexit function to
2013 * clean up and free various items of allocated memory,
2014 * and must be the last last atexit function to run.
2018 /* Register a function to be called when the program terminates.
2019 * This makes sure that data is saved even if LEX/YACC routines
2020 * abort the program.
2021 * If the OS doesn't have at least one of them,
2022 * the critical sections will be handled by parse_l.l
2024 atexit (EmergencySave
);
2026 /* read the library file and display it if it's not empty
2028 if (!ReadLibraryContents () && Library
.MenuN
)
2029 hid_action ("LibraryChanged");
2031 #ifdef HAVE_LIBSTROKE
2035 if (Settings
.ScriptFilename
)
2037 Message (_("Executing startup script file %s\n"),
2038 Settings
.ScriptFilename
);
2039 hid_actionl ("ExecuteFile", Settings
.ScriptFilename
, NULL
);
2041 if (Settings
.ActionString
)
2043 Message (_("Executing startup action %s\n"), Settings
.ActionString
);
2044 hid_parse_actions (Settings
.ActionString
);
2047 if (gui
->printer
|| gui
->exporter
)
2060 printf ("Settings.LibraryCommandDir = \"%s\"\n",
2061 Settings
.LibraryCommandDir
);
2062 printf ("Settings.FontPath = \"%s\"\n",
2064 printf ("Settings.ElementPath = \"%s\"\n",
2065 Settings
.ElementPath
);
2066 printf ("Settings.LibraryPath = \"%s\"\n",
2067 Settings
.LibraryPath
);
2068 printf ("Settings.LibraryTree = \"%s\"\n",
2069 Settings
.LibraryTree
);
2070 printf ("Settings.MakeProgram = \"%s\"\n",
2071 UNKNOWN (Settings
.MakeProgram
));
2072 printf ("Settings.GnetlistProgram = \"%s\"\n",
2073 UNKNOWN (Settings
.GnetlistProgram
));