4 * \brief Main program, initializes some stuff and handles user input.
8 * <h1><b>Copyright.</b></h1>\n
10 * PCB, interactive printed circuit board design
12 * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Contact addresses for paper mail and Email:
29 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
30 * Thomas.Nau@rz.uni-ulm.de
45 #include <time.h> /* Seed for srand() */
51 #include "crosshair.h"
58 #include "lrealpath.h"
59 #include "free_atexit.h"
62 #include "pcb-printf.h"
65 #include "hid/common/actions.h"
67 /* This next one is so we can print the help messages. */
68 #include "hid/hidint.h"
74 #ifdef HAVE_LIBDMALLOC
78 #define PCBLIBPATH ".:" PCBLIBDIR
82 extern void stroke_init (void);
87 * \brief Initialize signal and error handlers.
93 signal(SIGHUP, CatchSignal);
94 signal(SIGQUIT, CatchSignal);
95 signal(SIGABRT, CatchSignal);
96 signal(SIGSEGV, CatchSignal);
97 signal(SIGTERM, CatchSignal);
98 signal(SIGINT, CatchSignal);
101 /* calling external program by popen() may cause a PIPE signal,
105 signal (SIGPIPE
, SIG_IGN
);
110 /* ----------------------------------------------------------------------
111 | command line and rc file processing.
113 static char *command_line_pcb
;
116 * \brief Print the copyright notice.
122 " COPYRIGHT for %s version %s\n\n"
123 " PCB, interactive printed circuit board design\n"
124 " Copyright (C) 1994,1995,1996,1997 Thomas Nau\n"
125 " Copyright (C) 1998, 1999, 2000 Harry Eaton\n\n"
126 " This program is free software; you can redistribute it and/or modify\n"
127 " it under the terms of the GNU General Public License as published by\n"
128 " the Free Software Foundation; either version 2 of the License, or\n"
129 " (at your option) any later version.\n\n"
130 " This program is distributed in the hope that it will be useful,\n"
131 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
132 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
133 " GNU General Public License for more details.\n\n"
134 " You should have received a copy of the GNU General Public License\n"
135 " along with this program; if not, write to the Free Software\n"
136 " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
142 u (const char *fmt
, ...)
146 vfprintf (stderr
, fmt
, ap
);
147 fputc ('\n', stderr
);
151 typedef struct UsageNotes
{
152 struct UsageNotes
*next
;
156 static UsageNotes
*usage_notes
= NULL
;
159 usage_attr (HID_Attribute
* a
)
162 const Unit
*unit_list
;
163 static char buf
[200];
165 if (a
->help_text
== ATTR_UNDOCUMENTED
)
174 sprintf (buf
, "--%s <num>", a
->name
);
177 sprintf (buf
, "--%s <measure>", a
->name
);
180 sprintf (buf
, "--%s <string>", a
->name
);
183 sprintf (buf
, "--%s", a
->name
);
187 sprintf (buf
, "--%s ", a
->name
);
188 if (a
->type
== HID_Mixed
)
189 strcat (buf
, " <val>");
190 for (i
= 0; a
->enumerations
[i
]; i
++)
192 strcat (buf
, i
? "|" : "<");
193 strcat (buf
, a
->enumerations
[i
]);
198 sprintf (buf
, "--%s <path>", a
->name
);
201 unit_list
= get_unit_list ();
203 sprintf (buf
, "--%s ", a
->name
);
204 for (i
= 0; i
< n
; i
++)
206 strcat (buf
, i
? "|" : "<");
207 strcat (buf
, unit_list
[i
].suffix
);
213 if (strlen (buf
) <= 30)
216 fprintf (stderr
, " %-30s\t%s\n", buf
, a
->help_text
);
218 fprintf (stderr
, " %-30s\n", buf
);
220 else if (a
->help_text
&& strlen (a
->help_text
) + strlen (buf
) < 72)
221 fprintf (stderr
, " %s\t%s\n", buf
, a
->help_text
);
222 else if (a
->help_text
)
223 fprintf (stderr
, " %s\n\t\t\t%s\n", buf
, a
->help_text
);
225 fprintf (stderr
, " %s\n", buf
);
231 HID_Attribute
*attributes
;
232 int i
, n_attributes
= 0;
237 fprintf (stderr
, "\n%s gui options:\n", h
->name
);
238 attributes
= h
->get_export_options (&n_attributes
);
242 fprintf (stderr
, "\n%s options:\n", h
->name
);
244 attributes
= exporter
->get_export_options (&n_attributes
);
248 note
= (UsageNotes
*)malloc (sizeof (UsageNotes
));
249 note
->next
= usage_notes
;
250 note
->seen
= attributes
;
253 for (i
= 0; i
< n_attributes
; i
++)
254 usage_attr (attributes
+ i
);
260 HID
**hl
= hid_enumerate ();
264 int n_printer
= 0, n_gui
= 0, n_exporter
= 0;
266 for (i
= 0; hl
[i
]; i
++)
276 u ("PCB Printed Circuit Board editing program, http://pcb.geda-project.org");
277 u ("%s [-h|-V|--copyright]\t\t\tHelp, version, copyright", Progname
);
278 u ("%s [gui options] <pcb file>\t\tto edit", Progname
);
279 u ("Available GUI hid%s:", n_gui
== 1 ? "" : "s");
280 for (i
= 0; hl
[i
]; i
++)
282 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
283 u ("%s -p [printing options] <pcb file>\tto print", Progname
);
284 u ("Available printing hid%s:", n_printer
== 1 ? "" : "s");
285 for (i
= 0; hl
[i
]; i
++)
287 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
288 u ("%s -x hid [export options] <pcb file>\tto export", Progname
);
289 u ("Available export hid%s:", n_exporter
== 1 ? "" : "s");
290 for (i
= 0; hl
[i
]; i
++)
292 fprintf (stderr
, "\t%-8s %s\n", hl
[i
]->name
, hl
[i
]->description
);
294 for (i
= 0; hl
[i
]; i
++)
297 for (i
= 0; hl
[i
]; i
++)
300 for (i
= 0; hl
[i
]; i
++)
304 u ("\nCommon options:");
305 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
307 for (note
= usage_notes
; note
&& note
->seen
!= ha
->attributes
; note
= note
->next
)
311 for (i
= 0; i
< ha
->n
; i
++)
313 usage_attr (ha
->attributes
+ i
);
321 print_defaults_1 (HID_Attribute
* a
, void *value
)
328 /* Remember, at this point we've parsed the command line, so they
329 may be in the global variable instead of the default_val. */
333 i
= value
? *(int *) value
: a
->default_val
.int_value
;
334 fprintf (stderr
, "%s %d\n", a
->name
, i
);
337 i
= value
? *(char *) value
: a
->default_val
.int_value
;
338 fprintf (stderr
, "%s %s\n", a
->name
, i
? "yes" : "no");
341 d
= value
? *(double *) value
: a
->default_val
.real_value
;
342 fprintf (stderr
, "%s %g\n", a
->name
, d
);
345 c
= value
? *(Coord
*) value
: a
->default_val
.coord_value
;
346 pcb_fprintf (stderr
, "%s %$mS\n", a
->name
, c
);
350 s
= value
? *(char **) value
: a
->default_val
.str_value
;
351 fprintf (stderr
, "%s \"%s\"\n", a
->name
, s
);
354 i
= value
? *(int *) value
: a
->default_val
.int_value
;
355 fprintf (stderr
, "%s %s\n", a
->name
, a
->enumerations
[i
]);
359 ((HID_Attr_Val
*)value
)->int_value
: a
->default_val
.int_value
;
361 ((HID_Attr_Val
*)value
)->real_value
: a
->default_val
.real_value
;
362 fprintf (stderr
, "%s %g%s\n", a
->name
, d
, a
->enumerations
[i
]);
367 i
= value
? *(int *) value
: a
->default_val
.int_value
;
368 fprintf (stderr
, "%s %s\n", a
->name
, get_unit_list()[i
].suffix
);
375 HID
**hl
= hid_enumerate ();
379 for (hi
= 0; hl
[hi
]; hi
++)
385 fprintf (stderr
, "\ngui defaults:\n");
386 for (ha
= hid_attr_nodes
; ha
; ha
= ha
->next
)
387 for (i
= 0; i
< ha
->n
; i
++)
388 print_defaults_1 (ha
->attributes
+ i
, ha
->attributes
[i
].value
);
392 fprintf (stderr
, "\n%s defaults:\n", h
->name
);
394 e
= exporter
->get_export_options (&n
);
397 for (i
= 0; i
< n
; i
++)
398 print_defaults_1 (e
+ i
, 0);
404 #define SSET(F,D,N,H) { N, H, \
405 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
406 #define ISET(F,D,N,H) { N, H, \
407 HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }
408 #define BSET(F,D,N,H) { N, H, \
409 HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }
410 #define RSET(F,D,N,H) { N, H, \
411 HID_Real, 0, 0, { 0, 0, D }, 0, &Settings.F }
412 #define CSET(F,D,N,H) { N, H, \
413 HID_Coord, 0, 0, { 0, 0, 0, D }, 0, &Settings.F }
415 #define COLOR(F,D,N,H) { N, H, \
416 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
417 #define LAYERCOLOR(N,D) { "layer-color-" #N, "Color for layer " #N, \
418 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }
419 #define LAYERNAME(N,D) { "layer-name-" #N, "Name for layer " #N, \
420 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }
421 #define LAYERSELCOLOR(N) { "layer-selected-color-" #N, "Color for layer " #N " when selected", \
422 HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }
424 static int show_help
= 0;
425 static int show_version
= 0;
426 static int show_copyright
= 0;
427 static int show_defaults
= 0;
428 static int show_actions
= 0;
429 static int do_dump_actions
= 0;
430 static char *grid_units
;
431 static Increments increment_mm
= { 0 };
432 static Increments increment_mil
= { 0 };
434 void save_increments (const Increments
*mm
, const Increments
*mil
)
436 memcpy (&increment_mm
, mm
, sizeof (*mm
));
437 memcpy (&increment_mil
, mil
, sizeof (*mil
));
440 HID_Attribute main_attribute_list
[] = {
442 /* %start-doc options "1 General Options"
445 Show help on command line options.
449 {"help", "Show help on command line options", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
452 /* %start-doc options "1 General Options"
459 {"version", "Show version", HID_Boolean
, 0, 0, {0, 0, 0}, 0, &show_version
},
461 /* %start-doc options "1 General Options"
464 Be verbose on stdout.
468 {"verbose", "Be verbose on stdout", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
471 /* %start-doc options "1 General Options"
478 {"copyright", "Show Copyright", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
481 /* %start-doc options "1 General Options"
483 @item --show-defaults
484 Show option defaults.
488 {"show-defaults", "Show option defaults", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
491 /* %start-doc options "1 General Options"
494 Show available actions and exit.
498 {"show-actions", "Show available actions", HID_Boolean
, 0, 0, {0, 0, 0}, 0,
501 /* %start-doc options "1 General Options"
504 Dump actions (for documentation).
508 {"dump-actions", "Dump actions (for documentation)", HID_Boolean
, 0, 0,
509 {0, 0, 0}, 0, &do_dump_actions
},
511 /* %start-doc options "1 General Options"
513 @item --grid-units-mm <string>
514 Set default grid units. Can be mm or mil. Defaults to mil.
518 {"grid-units", "Default grid units (mm|mil)", HID_String
, 0, 0, {0, "mil", 0},
521 /* %start-doc options "1 General Options"
523 @item --clear-increment-mm <string>
524 Set default clear increment (amount to change when user presses k or K)
525 when user is using a metric grid unit.
529 {"clear-increment-mm", "Default clear increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
530 0, &increment_mm
.clear
},
532 /* %start-doc options "1 General Options"
534 @item --grid-increment-mm <string>
535 Set default grid increment (amount to change when user presses g or G)
536 when user is using a metric grid unit.
540 {"grid-increment-mm", "Default grid increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
541 0, &increment_mm
.grid
},
543 /* %start-doc options "1 General Options"
545 @item --line-increment-mm <string>
546 Set default line increment (amount to change when user presses l or L)
547 when user is using a metric grid unit.
551 {"line-increment-mm", "Default line increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
552 0, &increment_mm
.line
},
554 /* %start-doc options "1 General Options"
556 @item --size-increment-mm <string>
557 Set default size increment (amount to change when user presses s or S)
558 when user is using a metric grid unit.
562 {"size-increment-mm", "Default size increment amount (metric)", HID_Coord
, 0, 0, {0, 0, 0},
563 0, &increment_mm
.size
},
565 /* %start-doc options "1 General Options"
567 @item --clear-increment-mil <string>
568 Set default clear increment (amount to change when user presses k or K)
569 when user is using an imperial grid unit.
573 {"clear-increment-mil", "Default clear increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
574 0, &increment_mil
.clear
},
576 /* %start-doc options "1 General Options"
578 @item --grid-increment-mil <string>
579 Set default grid increment (amount to change when user presses g or G)
580 when user is using a imperial grid unit.
584 {"grid-increment-mil", "Default grid increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
585 0, &increment_mil
.grid
},
587 /* %start-doc options "1 General Options"
589 @item --line-increment-mil <string>
590 Set default line increment (amount to change when user presses l or L)
591 when user is using a imperial grid unit.
595 {"line-increment-mil", "Default line increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
596 0, &increment_mil
.line
},
598 /* %start-doc options "1 General Options"
600 @item --size-increment-mil <string>
601 Set default size increment (amount to change when user presses s or S)
602 when user is using a imperial grid unit.
606 {"size-increment-mil", "Default size increment amount (imperial)", HID_Coord
, 0, 0, {0, 0, 0},
607 0, &increment_mil
.size
},
609 /* %start-doc options "3 Colors"
611 @item --black-color <string>
612 Color value for black. Default: @samp{#000000}
616 COLOR (BlackColor
, "#000000", "black-color", "color value of 'black'"),
618 /* %start-doc options "3 Colors"
620 @item --black-color <string>
621 Color value for white. Default: @samp{#ffffff}
625 COLOR (WhiteColor
, "#ffffff", "white-color", "color value of 'white'"),
627 /* %start-doc options "3 Colors"
629 @item --background-color <string>
630 Background color of the canvas. Default: @samp{#e5e5e5}
634 COLOR (BackgroundColor
, "#e5e5e5", "background-color",
635 "color for background"),
637 /* %start-doc options "3 Colors"
639 @item --crosshair-color <string>
640 Color of the crosshair. Default: @samp{#ff0000}
644 COLOR (CrosshairColor
, "#ff0000", "crosshair-color",
645 "color for the crosshair"),
647 /* %start-doc options "3 Colors"
649 @item --cross-color <string>
650 Color of the cross. Default: @samp{#cdcd00}
654 COLOR (CrossColor
, "#cdcd00", "cross-color", "color of the cross"),
656 /* %start-doc options "3 Colors"
658 @item --via-color <string>
659 Color of vias. Default: @samp{#7f7f7f}
663 COLOR (ViaColor
, "#7f7f7f", "via-color", "color of vias"),
665 /* %start-doc options "3 Colors"
667 @item --via-selected-color <string>
668 Color of selected vias. Default: @samp{#00ffff}
672 COLOR (ViaSelectedColor
, "#00ffff", "via-selected-color",
673 "color for selected vias"),
675 /* %start-doc options "3 Colors"
677 @item --pin-color <string>
678 Color of pins. Default: @samp{#4d4d4d}
682 COLOR (PinColor
, "#4d4d4d", "pin-color", "color of pins"),
684 /* %start-doc options "3 Colors"
686 @item --pin-selected-color <string>
687 Color of selected pins. Default: @samp{#00ffff}
691 COLOR (PinSelectedColor
, "#00ffff", "pin-selected-color",
692 "color of selected pins"),
694 /* %start-doc options "3 Colors"
696 @item --pin-name-color <string>
697 Color of pin names and pin numbers. Default: @samp{#ff0000}
701 COLOR (PinNameColor
, "#ff0000", "pin-name-color",
702 "color for pin names and pin numbers"),
704 /* %start-doc options "3 Colors"
706 @item --element-color <string>
707 Color of components. Default: @samp{#000000}
711 COLOR (ElementColor
, "#000000", "element-color", "color of components"),
713 /* %start-doc options "3 Colors"
715 @item --rat-color <string>
716 Color of ratlines. Default: @samp{#b8860b}
720 COLOR (RatColor
, "#b8860b", "rat-color", "color of ratlines"),
722 /* %start-doc options "3 Colors"
724 @item --invisible-objects-color <string>
725 Color of invisible objects. Default: @samp{#cccccc}
729 COLOR (InvisibleObjectsColor
, "#cccccc", "invisible-objects-color",
730 "color of invisible objects"),
732 /* %start-doc options "3 Colors"
734 @item --invisible-mark-color <string>
735 Color of invisible marks. Default: @samp{#cccccc}
739 COLOR (InvisibleMarkColor
, "#cccccc", "invisible-mark-color",
740 "color of invisible marks"),
742 /* %start-doc options "3 Colors"
744 @item --element-selected-color <string>
745 Color of selected components. Default: @samp{#00ffff}
749 COLOR (ElementSelectedColor
, "#00ffff", "element-selected-color",
750 "color of selected components"),
752 /* %start-doc options "3 Colors"
754 @item --rat-selected-color <string>
755 Color of selected rats. Default: @samp{#00ffff}
759 COLOR (RatSelectedColor
, "#00ffff", "rat-selected-color",
760 "color of selected rats"),
762 /* %start-doc options "3 Colors"
764 @item --connected-color <string>
765 Color to indicate physical connections. Default: @samp{#00ff00}
769 COLOR (ConnectedColor
, "#00ff00", "connected-color",
770 "color to indicate physically connected objects"),
772 /* %start-doc options "3 Colors"
774 @item --found-color <string>
775 Color to indicate logical connections. Default: @samp{#ff00ff}
779 COLOR (FoundColor
, "#ff00ff", "found-color",
780 "color to indicate logically connected objects"),
782 /* %start-doc options "3 Colors"
784 @item --off-limit-color <string>
785 Color of off-canvas area. Default: @samp{#cccccc}
789 COLOR (OffLimitColor
, "#cccccc", "off-limit-color",
790 "color of off-canvas area"),
792 /* %start-doc options "3 Colors"
794 @item --grid-color <string>
795 Color of the grid. Default: @samp{#ff0000}
799 COLOR (GridColor
, "#ff0000", "grid-color", "color of the grid"),
801 /* %start-doc options "3 Colors"
803 @item --layer-color-<n> <string>
804 Color of layer @code{<n>}, where @code{<n>} is an integer from 1 to 16.
808 LAYERCOLOR (1, "#8b2323"),
809 LAYERCOLOR (2, "#3a5fcd"),
810 LAYERCOLOR (3, "#104e8b"),
811 LAYERCOLOR (4, "#cd3700"),
812 LAYERCOLOR (5, "#548b54"),
813 LAYERCOLOR (6, "#8b7355"),
814 LAYERCOLOR (7, "#00868b"),
815 LAYERCOLOR (8, "#228b22"),
816 LAYERCOLOR (9, "#8b2323"),
817 LAYERCOLOR (10, "#3a5fcd"),
818 LAYERCOLOR (11, "#104e8b"),
819 LAYERCOLOR (12, "#cd3700"),
820 LAYERCOLOR (13, "#548b54"),
821 LAYERCOLOR (14, "#8b7355"),
822 LAYERCOLOR (15, "#00868b"),
823 LAYERCOLOR (16, "#228b22"),
824 /* %start-doc options "3 Colors"
826 @item --layer-selected-color-<n> <string>
827 Color of layer @code{<n>}, when selected. @code{<n>} is an integer from 1 to 16.
848 /* %start-doc options "3 Colors"
850 @item --warn-color <string>
851 Color of offending objects during DRC. Default value is @code{"#ff8000"}
855 COLOR (WarnColor
, "#ff8000", "warn-color", "color of offending objects during DRC"),
857 /* %start-doc options "3 Colors"
859 @item --mask-color <string>
860 Color of the mask layer. Default value is @code{"#ff0000"}
864 COLOR (MaskColor
, "#ff0000", "mask-color", "color for solder mask"),
867 /* %start-doc options "5 Sizes"
868 All parameters should be given with an unit. If no unit is given, 1/100 mil
869 (cmil) will be used. Write units without space to the
870 number like @code{3mm}, not @code{3 mm}.
894 @item --via-thickness <num>
895 Default diameter of vias. Default value is @code{60mil}.
899 CSET (ViaThickness
, MIL_TO_COORD(60), "via-thickness",
900 "default diameter of vias in 1/100 mil"),
902 /* %start-doc options "5 Sizes"
904 @item --via-drilling-hole <num>
905 Default diameter of holes. Default value is @code{28mil}.
909 CSET (ViaDrillingHole
, MIL_TO_COORD(28), "via-drilling-hole",
910 "default diameter of holes"),
912 /* %start-doc options "5 Sizes"
914 @item --line-thickness <num>
915 Default thickness of new lines. Default value is @code{10mil}.
919 CSET (LineThickness
, MIL_TO_COORD(10), "line-thickness",
920 "initial thickness of new lines"),
922 /* %start-doc options "5 Sizes"
924 @item --rat-thickness <num><unit>
925 Thickness of rats. If no unit is given, PCB units are assumed (i.e. 100
926 means "1 nm"). This option allows for a special unit @code{px} which
927 sets the rat thickness to a fixed value in terms of screen pixels.
928 Maximum fixed thickness is 100px. Minimum saling rat thickness is 101nm.
929 Default value is @code{10mil}.
933 CSET (RatThickness
, MIL_TO_COORD(10), "rat-thickness", "thickness of rat lines"),
935 /* %start-doc options "5 Sizes"
937 @item --keepaway <num>
938 Default minimum distance between a track and adjacent copper.
939 Default value is @code{10mil}.
943 CSET (Keepaway
, MIL_TO_COORD(10), "keepaway", "minimum distance between adjacent copper"),
945 /* %start-doc options "5 Sizes"
947 @item --default-PCB-width <num>
948 Default width of the canvas. Default value is @code{6000mil}.
952 CSET (MaxWidth
, MIL_TO_COORD(6000), "default-PCB-width",
953 "default width of the canvas"),
955 /* %start-doc options "5 Sizes"
957 @item --default-PCB-height <num>
958 Default height of the canvas. Default value is @code{5000mil}.
962 CSET (MaxHeight
, MIL_TO_COORD(5000), "default-PCB-height",
963 "default height of the canvas"),
965 /* %start-doc options "5 Sizes"
967 @item --text-scale <num>
968 Default text scale. This value is in percent. Default value is @code{100}.
972 ISET (TextScale
, 100, "text-scale", "default text scale in percent"),
974 /* %start-doc options "5 Sizes"
976 @item --alignment-distance <num>
977 Specifies the distance between the board outline and alignment targets.
978 Default value is @code{2mil}.
982 CSET (AlignmentDistance
, MIL_TO_COORD(2), "alignment-distance",
983 "distance between the boards outline and alignment targets"),
985 /* %start-doc options "7 DRC Options"
986 All parameters should be given with an unit. If no unit is given, 1/100 mil
987 (cmil) will be used for backward compability. Valid units are given in section
993 /* %start-doc options "7 DRC Options"
996 Minimum spacing. Default value is @code{10mil}.
1000 CSET (Bloat
, MIL_TO_COORD(10), "bloat", "DRC minimum spacing in 1/100 mil"),
1002 /* %start-doc options "7 DRC Options"
1004 @item --shrink <num>
1005 Minimum touching overlap. Default value is @code{10mil}.
1009 CSET (Shrink
, MIL_TO_COORD(10), "shrink", "DRC minimum overlap in 1/100 mils"),
1011 /* %start-doc options "7 DRC Options"
1013 @item --min-width <num>
1014 Minimum width of copper. Default value is @code{10mil}.
1018 CSET (minWid
, MIL_TO_COORD(10), "min-width", "DRC minimum copper spacing"),
1020 /* %start-doc options "7 DRC Options"
1022 @item --min-silk <num>
1023 Minimum width of lines in silk. Default value is @code{10mil}.
1027 CSET (minSlk
, MIL_TO_COORD(10), "min-silk", "DRC minimum silk width"),
1029 /* %start-doc options "7 DRC Options"
1031 @item --min-drill <num>
1032 Minimum diameter of holes. Default value is @code{15mil}.
1036 CSET (minDrill
, MIL_TO_COORD(15), "min-drill", "DRC minimum drill diameter"),
1038 /* %start-doc options "7 DRC Options"
1040 @item --min-ring <num>
1041 Minimum width of annular ring. Default value is @code{10mil}.
1045 CSET (minRing
, MIL_TO_COORD(10), "min-ring", "DRC minimum annular ring"),
1048 /* %start-doc options "5 Sizes"
1051 Initial grid size. Default value is @code{10mil}.
1055 CSET (Grid
, MIL_TO_COORD(10), "grid", "Initial grid size in 1/100 mil"),
1057 /* %start-doc options "5 Sizes"
1059 @item --minimum polygon area <num>
1060 Minimum polygon area.
1064 RSET (IsleArea
, MIL_TO_COORD(100) * MIL_TO_COORD(100), "minimum polygon area", 0),
1067 /* %start-doc options "1 General Options"
1069 @item --backup-interval
1070 Time between automatic backups in seconds. Set to @code{0} to disable.
1071 The default value is @code{60}.
1075 ISET (BackupInterval
, 60, "backup-interval",
1076 "Time between automatic backups in seconds. Set to 0 to disable"),
1078 /* %start-doc options "4 Layer Names"
1080 @item --layer-name-1 <string>
1081 Name of the 1st Layer. Default is @code{"top"}.
1085 LAYERNAME (1, "top"),
1087 /* %start-doc options "4 Layer Names"
1089 @item --layer-name-2 <string>
1090 Name of the 2nd Layer. Default is @code{"ground"}.
1094 LAYERNAME (2, "ground"),
1096 /* %start-doc options "4 Layer Names"
1098 @item --layer-name-3 <string>
1099 Name of the 3nd Layer. Default is @code{"signal2"}.
1103 LAYERNAME (3, "signal2"),
1105 /* %start-doc options "4 Layer Names"
1107 @item --layer-name-4 <string>
1108 Name of the 4rd Layer. Default is @code{"signal3"}.
1112 LAYERNAME (4, "signal3"),
1114 /* %start-doc options "4 Layer Names"
1116 @item --layer-name-5 <string>
1117 Name of the 5rd Layer. Default is @code{"power"}.
1121 LAYERNAME (5, "power"),
1123 /* %start-doc options "4 Layer Names"
1125 @item --layer-name-6 <string>
1126 Name of the 6rd Layer. Default is @code{"bottom"}.
1130 LAYERNAME (6, "bottom"),
1132 /* %start-doc options "4 Layer Names"
1134 @item --layer-name-7 <string>
1135 Name of the 7rd Layer. Default is @code{"outline"}.
1139 LAYERNAME (7, "outline"),
1141 /* %start-doc options "4 Layer Names"
1143 @item --layer-name-8 <string>
1144 Name of the 8rd Layer. Default is @code{"spare"}.
1148 LAYERNAME (8, "spare"),
1150 /* %start-doc options "1 General Options"
1152 @item --groups <string>
1153 Layer group string. Defaults to @code{"1,c:2:3:4:5:6,s:7:8"}.
1157 SSET (Groups
, "1,c:2:3:4:5:6,s:7:8", "groups", "Layer group string"),
1160 /* %start-doc options "6 Commands"
1161 pcb uses external commands for input output operations. These commands can be
1162 configured at start-up to meet local requirements. The command string may include
1163 special sequences @code{%f}, @code{%p} or @code{%a}. These are replaced when the
1164 command is called. The sequence @code{%f} is replaced by the file name,
1165 @code{%p} gets the path and @code{%a} indicates a package name.
1169 /* %start-doc options "6 Commands"
1171 @item --font-command <string>
1172 Command to load a font.
1176 SSET (FontCommand
, "", "font-command", "Command to load a font"),
1178 /* %start-doc options "6 Commands"
1180 @item --file-command <string>
1181 Command to read a file.
1185 SSET (FileCommand
, "", "file-command", "Command to read a file"),
1187 /* %start-doc options "6 Commands"
1189 @item --element-command <string>
1190 Command to read a footprint. @*
1191 Defaults to @code{"M4PATH='%p';export M4PATH;echo 'include(%f)' | m4"}
1195 SSET (ElementCommand
,
1196 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4
,
1197 "element-command", "Command to read a footprint"),
1199 /* %start-doc options "6 Commands"
1201 @item --print-file <string>
1202 Command to print to a file.
1206 SSET (PrintFile
, "%f.output", "print-file", "Command to print to a file"),
1208 /* %start-doc options "6 Commands"
1210 @item --lib-command-dir <string>
1211 Path to the command that queries the library.
1215 SSET (LibraryCommandDir
, PCBLIBDIR
, "lib-command-dir",
1216 "Path to the command that queries the library"),
1218 /* %start-doc options "6 Commands"
1220 @item --lib-command <string>
1221 Command to query the library. @*
1222 Defaults to @code{"QueryLibrary.sh '%p' '%f' %a"}
1226 SSET (LibraryCommand
, "QueryLibrary.sh '%p' '%f' %a",
1227 "lib-command", "Command to query the library"),
1229 /* %start-doc options "6 Commands"
1231 @item --lib-contents-command <string>
1232 Command to query the contents of the library. @*
1233 Defaults to @code{"ListLibraryContents.sh %p %f"} or,
1234 on Windows builds, an empty string (to disable this feature).
1238 SSET (LibraryContentsCommand
,
1242 "ListLibraryContents.sh '%p' '%f'",
1244 "lib-contents-command", "Command to query the contents of the library"),
1246 /* %start-doc options "5 Paths"
1248 @item --lib-newlib <string>
1249 Top level directory for the newlib style library.
1253 SSET (LibraryTree
, PCBTREEPATH
, "lib-newlib",
1254 "Top level directory for the newlib style library"),
1256 /* %start-doc options "6 Commands"
1258 @item --save-command <string>
1259 Command to save to a file.
1263 SSET (SaveCommand
, "", "save-command", "Command to save to a file"),
1265 /* %start-doc options "5 Paths"
1267 @item --lib-name <string>
1268 The default filename for the library.
1272 SSET (LibraryFilename
, LIBRARYFILENAME
, "lib-name",
1273 "The default filename for the library"),
1275 /* %start-doc options "5 Paths"
1277 @item --default-font <string>
1278 The name of the default font.
1282 SSET (FontFile
, "default_font", "default-font",
1283 "File name of default font"),
1285 /* %start-doc options "1 General Options"
1287 @item --route-styles <string>
1288 A string that defines the route styles. Defaults to @*
1289 @code{"Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000
1290 :Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"}
1294 SSET (Routes
, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
1295 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
1296 "A string that defines the route styles"),
1298 /* %start-doc options "5 Paths"
1300 @item --file-path <string>
1301 A colon separated list of directories or commands (starts with '|'). The path
1302 is passed to the program specified in @option{--file-command} together with the selected
1307 SSET (FilePath
, "", "file-path", 0),
1309 /* %start-doc options "6 Commands"
1311 @item --rat-command <string>
1312 Command for reading a netlist. Sequence @code{%f} is replaced by the netlist filename.
1316 SSET (RatCommand
, "", "rat-command", "Command for reading a netlist"),
1318 /* %start-doc options "5 Paths"
1320 @item --font-path <string>
1321 A colon separated list of directories to search the default font. Defaults to
1322 the default library path.
1326 SSET (FontPath
, PCBLIBPATH
, "font-path",
1327 "Colon separated list of directories to search the default font"),
1329 /* %start-doc options "1 General Options"
1331 @item --element-path <string>
1332 A colon separated list of directories or commands (starts with '|').
1333 The path is passed to the program specified in @option{--element-command}.
1337 SSET(ElementPath
, PCBLIBPATH
, "element-path",
1338 "A colon separated list of directories or commands (starts with '|')"),
1340 /* %start-doc options "5 Paths"
1342 @item --lib-path <string>
1343 A colon separated list of directories that will be passed to the commands specified
1344 by @option{--element-command} and @option{--element-contents-command}.
1348 SSET (LibraryPath
, PCBLIBPATH
, "lib-path",
1349 "A colon separated list of directories"),
1351 /* %start-doc options "1 General Options"
1353 @item --action-script <string>
1354 If set, this file is executed at startup.
1358 SSET (ScriptFilename
, 0, "action-script",
1359 "If set, this file is executed at startup"),
1361 /* %start-doc options "1 General Options"
1363 @item --action-string <string>
1364 If set, this string of actions is executed at startup.
1368 SSET (ActionString
, 0, "action-string",
1369 "If set, this is executed at startup"),
1371 /* %start-doc options "1 General Options"
1373 @item --fab-author <string>
1374 Name of author to be put in the Gerber files.
1378 SSET (FabAuthor
, "", "fab-author",
1379 "Name of author to be put in the Gerber files"),
1381 /* %start-doc options "1 General Options"
1383 @item --layer-stack <string>
1384 Initial layer stackup, for setting up an export. A comma separated list of layer
1385 names, layer numbers and layer groups.
1389 SSET (InitialLayerStack
, "", "layer-stack",
1390 "Initial layer stackup, for setting up an export."),
1392 SSET (MakeProgram
, NULL
, "make-program",
1393 "Sets the name and optionally full path to a make(3) program"),
1394 SSET (GnetlistProgram
, NULL
, "gnetlist",
1395 "Sets the name and optionally full path to the gnetlist(3) program"),
1397 /* %start-doc options "2 General GUI Options"
1399 @item --pinout-offset-x <num>
1400 Horizontal offset of the pin number display. Defaults to @code{100mil}.
1404 CSET (PinoutOffsetX
, MIL_TO_COORD(1), "pinout-offset-x",
1405 "Horizontal offset of the pin number display in mil"),
1407 /* %start-doc options "2 General GUI Options"
1409 @item --pinout-offset-y <num>
1410 Vertical offset of the pin number display. Defaults to @code{100mil}.
1414 CSET (PinoutOffsetY
, MIL_TO_COORD(1), "pinout-offset-y",
1415 "Vertical offset of the pin number display in mil"),
1417 /* %start-doc options "2 General GUI Options"
1419 @item --pinout-text-offset-x <num>
1420 Horizontal offset of the pin name display. Defaults to @code{800mil}.
1424 CSET (PinoutTextOffsetX
, MIL_TO_COORD(8), "pinout-text-offset-x",
1425 "Horizontal offset of the pin name display in mil"),
1427 /* %start-doc options "2 General GUI Options"
1429 @item --pinout-text-offset-y <num>
1430 Vertical offset of the pin name display. Defaults to @code{-100mil}.
1434 CSET (PinoutTextOffsetY
, MIL_TO_COORD(-1), "pinout-text-offset-y",
1435 "Vertical offset of the pin name display in mil"),
1437 /* %start-doc options "2 General GUI Options"
1440 If set, draw the grid at start-up.
1444 BSET (DrawGrid
, 0, "draw-grid", "If set, draw the grid at start-up"),
1446 /* %start-doc options "2 General GUI Options"
1449 If set, new lines clear polygons.
1453 BSET (ClearLine
, 1, "clear-line", "If set, new lines clear polygons"),
1455 /* %start-doc options "2 General GUI Options"
1458 If set, new polygons are full ones.
1462 BSET (FullPoly
, 0, "full-poly", 0),
1464 /* %start-doc options "2 General GUI Options"
1466 @item --unique-names
1467 If set, you will not be permitted to change the name of an component to match that
1468 of another component.
1472 BSET (UniqueNames
, 1, "unique-names", "Prevents identical component names"),
1474 /* %start-doc options "2 General GUI Options"
1477 If set, pin centers and pad end points are treated as additional grid points
1478 that the cursor can snap to.
1482 BSET (SnapPin
, 1, "snap-pin",
1483 "If set, the cursor snaps to pads and pin centers"),
1485 /* %start-doc options "1 General Options"
1487 @item --save-last-command
1488 If set, the last user command is saved.
1492 BSET (SaveLastCommand
, 0, "save-last-command", 0),
1494 /* %start-doc options "1 General Options"
1497 If set, all data which would otherwise be lost are saved in a temporary file
1498 @file{/tmp/PCB.%i.save} . Sequence @samp{%i} is replaced by the process ID.
1502 BSET (SaveInTMP
, 0, "save-in-tmp",
1503 "When set, all data which would otherwise be lost are saved in /tmp"),
1505 /* %start-doc options "1 General Options"
1507 @item --save-metric-only
1508 If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm.
1512 BSET (SaveMetricOnly
, 0, "save-metric-only",
1513 "If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm."),
1515 /* %start-doc options "2 General GUI Options"
1517 @item --all-direction-lines
1518 Allow all directions, when drawing new lines.
1522 BSET (AllDirectionLines
, 0, "all-direction-lines",
1523 "Allow all directions, when drawing new lines"),
1525 /* %start-doc options "2 General GUI Options"
1528 Pinout shows number.
1532 BSET (ShowNumber
, 0, "show-number", "Pinout shows number"),
1534 /* %start-doc options "1 General Options"
1536 @item --reset-after-element
1537 If set, all found connections are reset before a new component is scanned.
1541 BSET (ResetAfterElement
, 1, "reset-after-element",
1542 "If set, all found connections are reset before a new component is scanned"),
1544 /* %start-doc options "1 General Options"
1546 @item --ring-bell-finished
1547 Execute the bell command when all rats are routed.
1551 BSET (RingBellWhenFinished
, 0, "ring-bell-finished",
1552 "Execute the bell command when all rats are routed"),
1555 REGISTER_ATTRIBUTES (main_attribute_list
)
1556 /* ----------------------------------------------------------------------
1557 * post-process settings.
1559 static void settings_post_process ()
1563 if (Settings
.LibraryCommand
!= NULL
&&
1564 Settings
.LibraryCommand
[0] != '\0' &&
1565 Settings
.LibraryCommand
[0] != PCB_DIR_SEPARATOR_C
&&
1566 Settings
.LibraryCommand
[0] != '.')
1568 Settings
.LibraryCommand
1570 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
1571 Settings
.LibraryCommand
,
1574 if (Settings
.LibraryContentsCommand
!= NULL
&&
1575 Settings
.LibraryContentsCommand
[0] != '\0' &&
1576 Settings
.LibraryContentsCommand
[0] != PCB_DIR_SEPARATOR_C
&&
1577 Settings
.LibraryContentsCommand
[0] != '.')
1579 Settings
.LibraryContentsCommand
1581 Concat (Settings
.LibraryCommandDir
, PCB_DIR_SEPARATOR_S
,
1582 Settings
.LibraryContentsCommand
, NULL
);
1585 if (Settings
.LineThickness
> MAX_LINESIZE
1586 || Settings
.LineThickness
< MIN_LINESIZE
)
1587 Settings
.LineThickness
= MIL_TO_COORD(10);
1589 if (Settings
.ViaThickness
> MAX_PINORVIASIZE
1590 || Settings
.ViaThickness
< MIN_PINORVIASIZE
)
1591 Settings
.ViaThickness
= MIL_TO_COORD(40);
1593 if (Settings
.ViaDrillingHole
<= 0)
1594 Settings
.ViaDrillingHole
=
1595 DEFAULT_DRILLINGHOLE
* Settings
.ViaThickness
/ 100;
1597 Settings
.MaxWidth
= CLAMP (Settings
.MaxWidth
, MIN_SIZE
, MAX_COORD
);
1598 Settings
.MaxHeight
= CLAMP (Settings
.MaxHeight
, MIN_SIZE
, MAX_COORD
);
1600 ParseRouteString (Settings
.Routes
, &Settings
.RouteStyle
[0], "cmil");
1603 * Make sure we have settings for some various programs we may wish
1606 if (Settings
.MakeProgram
== NULL
) {
1607 tmps
= getenv ("PCB_MAKE_PROGRAM");
1609 Settings
.MakeProgram
= strdup (tmps
);
1611 if (Settings
.MakeProgram
== NULL
) {
1612 Settings
.MakeProgram
= strdup ("make");
1615 if (Settings
.GnetlistProgram
== NULL
) {
1616 tmps
= getenv ("PCB_GNETLIST");
1618 Settings
.GnetlistProgram
= strdup (tmps
);
1620 if (Settings
.GnetlistProgram
== NULL
) {
1621 Settings
.GnetlistProgram
= strdup ("gnetlist");
1625 Settings
.grid_unit
= get_unit_struct (grid_units
);
1626 if (!grid_units
|| Settings
.grid_unit
== NULL
)
1627 Settings
.grid_unit
= get_unit_struct ("mil");
1629 copy_nonzero_increments (get_increments_struct (METRIC
), &increment_mm
);
1630 copy_nonzero_increments (get_increments_struct (IMPERIAL
), &increment_mil
);
1632 Settings
.increments
= get_increments_struct (Settings
.grid_unit
->family
);
1636 * \brief Print help or version messages.
1641 printf ("PCB version %s\n", VERSION
);
1645 /* ----------------------------------------------------------------------
1646 * Figure out the canonical name of the executed program
1647 * and fix up the defaults for various paths
1649 char *bindir
= NULL
;
1650 char *exec_prefix
= NULL
;
1651 char *pcblibdir
= NULL
;
1652 char *pcblibpath
= NULL
;
1653 char *pcbtreedir
= NULL
;
1654 char *pcbtreepath
= NULL
;
1655 char *homedir
= NULL
;
1658 * \brief See if argv0 has enough of a path to let lrealpath give the
1661 * This should be the case if you invoke pcb with something like
1662 * /usr/local/bin/pcb or ./pcb or ./foo/pcb but if you just use pcb and
1663 * it exists in your path, you'll just get back pcb again.
1666 InitPaths (char *argv0
)
1672 int found_bindir
= 0;
1675 for (i
= 0; i
< strlen (argv0
) ; i
++)
1677 if (argv0
[i
] == PCB_DIR_SEPARATOR_C
)
1682 printf ("InitPaths (%s): haspath = %d\n", argv0
, haspath
);
1687 bindir
= strdup (lrealpath (argv0
));
1692 char *path
, *p
, *tmps
;
1696 tmps
= getenv ("PATH");
1700 path
= strdup (tmps
);
1702 /* search through the font path for a font file */
1703 for (p
= strtok (path
, PCB_PATH_DELIMETER
); p
&& *p
;
1704 p
= strtok (NULL
, PCB_PATH_DELIMETER
))
1707 printf ("Looking for %s in %s\n", argv0
, p
);
1709 if ( (tmps
= (char *)malloc ( (strlen (argv0
) + strlen (p
) + 2) * sizeof (char))) == NULL
)
1711 fprintf (stderr
, "InitPaths(): malloc failed\n");
1714 sprintf (tmps
, "%s%s%s", p
, PCB_DIR_SEPARATOR_S
, argv0
);
1715 r
= stat (tmps
, &sb
);
1719 printf ("Found it: \"%s\"\n", tmps
);
1721 bindir
= lrealpath (tmps
);
1733 printf ("InitPaths(): bindir = \"%s\"\n", bindir
);
1738 /* strip off the executible name leaving only the path */
1740 t1
= strchr (bindir
, PCB_DIR_SEPARATOR_C
);
1741 while (t1
!= NULL
&& *t1
!= '\0')
1744 t1
= strchr (t2
+ 1, PCB_DIR_SEPARATOR_C
);
1750 printf ("After stripping off the executible name, we found\n");
1751 printf ("bindir = \"%s\"\n", bindir
);
1756 /* we have failed to find out anything from argv[0] so fall back to the original
1759 bindir
= strdup (BINDIR
);
1762 /* now find the path to exec_prefix */
1763 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_EXECPREFIX
) + 1;
1764 if ( (exec_prefix
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1766 fprintf (stderr
, "InitPaths(): malloc failed\n");
1769 sprintf (exec_prefix
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1770 BINDIR_TO_EXECPREFIX
);
1772 /* now find the path to PCBLIBDIR */
1773 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBLIBDIR
) + 1;
1774 if ( (pcblibdir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1776 fprintf (stderr
, "InitPaths(): malloc failed\n");
1779 sprintf (pcblibdir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1780 BINDIR_TO_PCBLIBDIR
);
1782 /* and the path to PCBTREEDIR */
1783 l
= strlen (bindir
) + 1 + strlen (BINDIR_TO_PCBTREEDIR
) + 1;
1784 if ( (pcbtreedir
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1786 fprintf (stderr
, "InitPaths(): malloc failed\n");
1789 sprintf (pcbtreedir
, "%s%s%s", bindir
, PCB_DIR_SEPARATOR_S
,
1790 BINDIR_TO_PCBTREEDIR
);
1792 /* and the search path including PCBLIBDIR */
1793 l
= strlen (pcblibdir
) + 3;
1794 if ( (pcblibpath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1796 fprintf (stderr
, "InitPaths(): malloc failed\n");
1799 sprintf (pcblibpath
, ".%s%s", PCB_PATH_DELIMETER
, pcblibdir
);
1801 /* and the newlib search path */
1802 l
= strlen (pcblibdir
) + 1 + strlen (pcbtreedir
)
1803 + strlen ("pcblib-newlib") + 2;
1804 if ( (pcbtreepath
= (char *) malloc (l
* sizeof (char) )) == NULL
)
1806 fprintf (stderr
, "InitPaths(): malloc failed\n");
1809 sprintf (pcbtreepath
, "%s%s%s%spcblib-newlib", pcbtreedir
,
1810 PCB_PATH_DELIMETER
, pcblibdir
,
1811 PCB_DIR_SEPARATOR_S
);
1814 printf ("bindir = %s\n", bindir
);
1815 printf ("pcblibdir = %s\n", pcblibdir
);
1816 printf ("pcblibpath = %s\n", pcblibpath
);
1817 printf ("pcbtreedir = %s\n", pcbtreedir
);
1818 printf ("pcbtreepath = %s\n", pcbtreepath
);
1821 l
= sizeof (main_attribute_list
) / sizeof (main_attribute_list
[0]);
1822 for (i
= 0; i
< l
; i
++)
1824 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-command-dir") == 0)
1826 main_attribute_list
[i
].default_val
.str_value
= pcblibdir
;
1829 if ( (NSTRCMP (main_attribute_list
[i
].name
, "font-path") == 0)
1830 || (NSTRCMP (main_attribute_list
[i
].name
, "element-path") == 0)
1831 || (NSTRCMP (main_attribute_list
[i
].name
, "lib-path") == 0) )
1833 main_attribute_list
[i
].default_val
.str_value
= pcblibpath
;
1836 if (NSTRCMP (main_attribute_list
[i
].name
, "lib-newlib") == 0)
1838 main_attribute_list
[i
].default_val
.str_value
= pcbtreepath
;
1846 tmps
= getenv ("HOME");
1849 tmps
= getenv ("USERPROFILE");
1853 homedir
= strdup (tmps
);
1861 /* ----------------------------------------------------------------------
1865 char *program_name
= 0;
1866 char *program_basename
= 0;
1867 char *program_directory
= 0;
1869 #include "dolists.h"
1872 * \brief Free up memory allocated to the PCB.
1874 * Why bother when we're about to exit ?\n
1875 * Because it removes some false positives from heap bug detectors such
1879 pcb_main_uninit (void)
1883 if (gui
->uninit
!= NULL
)
1890 FreePCBMemory (PCB
);
1893 for (i
= 0; i
< MAX_LAYER
; i
++)
1894 free (Settings
.DefaultLayerName
[i
]);
1896 if (Settings
.FontFile
!= NULL
)
1898 free (Settings
.FontFile
);
1899 Settings
.FontFile
= NULL
;
1902 uninit_strflags_buf ();
1906 * \brief Main program.
1910 * - make program name available for error handlers
1911 * - evaluate special options
1912 * - initialize toplevel shell and resources
1913 * - create an empty PCB with default symbols
1914 * - initialize all other widgets
1915 * - update screen and get size of drawing area
1916 * - evaluate command-line arguments
1917 * - register 'call on exit()' function
1920 main (int argc
, char *argv
[])
1924 #include "core_lists.h"
1926 InitPaths (argv
[0]);
1928 bindtextdomain (GETTEXT_PACKAGE
, LOCALEDIR
);
1929 textdomain (GETTEXT_PACKAGE
);
1930 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
1933 setlocale (LC_ALL
, "");
1934 setlocale (LC_NUMERIC
, "C");
1937 srand ( time(NULL
) ); /* Set seed for rand() */
1943 hid_load_settings ();
1945 program_name
= argv
[0];
1946 program_basename
= strrchr (program_name
, PCB_DIR_SEPARATOR_C
);
1947 if (program_basename
)
1949 program_directory
= strdup (program_name
);
1950 *strrchr (program_directory
, PCB_DIR_SEPARATOR_C
) = 0;
1955 program_directory
= ".";
1956 program_basename
= program_name
;
1958 Progname
= program_basename
;
1960 /* Print usage or version if requested. Then exit. */
1962 (strcmp (argv
[1], "-h") == 0 ||
1963 strcmp (argv
[1], "-?") == 0 ||
1964 strcmp (argv
[1], "--help") == 0))
1966 if (argc
> 1 && strcmp (argv
[1], "-V") == 0)
1968 /* Export pcb from command line if requested. */
1969 if (argc
> 1 && strcmp (argv
[1], "-p") == 0)
1971 exporter
= gui
= hid_find_printer ();
1975 else if (argc
> 2 && strcmp (argv
[1], "-x") == 0)
1977 exporter
= gui
= hid_find_exporter (argv
[2]);
1981 /* Otherwise start GUI. */
1983 gui
= hid_find_gui ();
1985 /* Exit with error if GUI failed to start. */
1989 /* Set up layers. */
1990 for (i
= 0; i
< MAX_LAYER
; i
++)
1993 sprintf (buf
, "signal%d", i
+ 1);
1994 Settings
.DefaultLayerName
[i
] = strdup (buf
);
1995 Settings
.LayerColor
[i
] = "#c49350";
1996 Settings
.LayerSelectedColor
[i
] = "#00ffff";
1999 gui
->parse_arguments (&argc
, &argv
);
2001 if (show_help
|| (argc
> 1 && argv
[1][0] == '-'))
2010 settings_post_process ();
2019 if (do_dump_actions
)
2021 extern void dump_actions (void);
2026 /* Create a new PCB object in memory */
2027 PCB
= CreateNewPCB ();
2028 ParseGroupString (Settings
.Groups
, &PCB
->LayerGroups
, &PCB
->Data
->LayerN
);
2029 /* Add silk layers to newly created PCB */
2030 CreateNewPCBPost (PCB
, 1);
2032 command_line_pcb
= argv
[1];
2034 ResetStackAndVisibility ();
2040 SetMode (ARROW_MODE
);
2042 if (command_line_pcb
)
2044 /* keep filename even if initial load command failed;
2045 * file might not exist
2047 if (LoadPCB (command_line_pcb
))
2048 PCB
->Filename
= strdup (command_line_pcb
);
2051 if (Settings
.InitialLayerStack
2052 && Settings
.InitialLayerStack
[0])
2054 LayerStringToLayerStack (Settings
.InitialLayerStack
);
2057 /* This must be called before any other atexit functions
2058 * are registered, as it configures an atexit function to
2059 * clean up and free various items of allocated memory,
2060 * and must be the last last atexit function to run.
2064 /* Register a function to be called when the program terminates.
2065 * This makes sure that data is saved even if LEX/YACC routines
2066 * abort the program.
2067 * If the OS doesn't have at least one of them,
2068 * the critical sections will be handled by parse_l.l
2070 atexit (EmergencySave
);
2072 /* read the library file and display it if it's not empty
2074 if (!ReadLibraryContents () && Library
.MenuN
)
2075 hid_action ("LibraryChanged");
2077 #ifdef HAVE_LIBSTROKE
2081 if (Settings
.ScriptFilename
)
2083 Message (_("Executing startup script file %s\n"),
2084 Settings
.ScriptFilename
);
2085 hid_actionl ("ExecuteFile", Settings
.ScriptFilename
, NULL
);
2087 if (Settings
.ActionString
)
2089 Message (_("Executing startup action %s\n"), Settings
.ActionString
);
2090 hid_parse_actions (Settings
.ActionString
);
2093 if (gui
->printer
|| gui
->exporter
)
2106 printf ("Settings.LibraryCommandDir = \"%s\"\n",
2107 Settings
.LibraryCommandDir
);
2108 printf ("Settings.FontPath = \"%s\"\n",
2110 printf ("Settings.ElementPath = \"%s\"\n",
2111 Settings
.ElementPath
);
2112 printf ("Settings.LibraryPath = \"%s\"\n",
2113 Settings
.LibraryPath
);
2114 printf ("Settings.LibraryTree = \"%s\"\n",
2115 Settings
.LibraryTree
);
2116 printf ("Settings.MakeProgram = \"%s\"\n",
2117 UNKNOWN (Settings
.MakeProgram
));
2118 printf ("Settings.GnetlistProgram = \"%s\"\n",
2119 UNKNOWN (Settings
.GnetlistProgram
));