(no commit message)
[geda-pcb/pcjc2.git] / src / main.c
bloba6b22ade51efedf1fd27f7504d34100348ef491e
1 /*
2 * COPYRIGHT
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
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #ifdef HAVE_LOCALE_H
35 #include <locale.h> /* setlocale() and LC_ALL */
36 #endif
37 #include <stdlib.h>
38 #ifdef HAVE_STRING_H
39 #include <string.h>
40 #endif
41 #include <signal.h>
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <time.h> /* Seed for srand() */
46 #include "global.h"
47 #include "data.h"
48 #include "buffer.h"
49 #include "create.h"
50 #include "crosshair.h"
51 #include "draw.h"
52 #include "error.h"
53 #include "file.h"
54 #include "set.h"
55 #include "action.h"
56 #include "misc.h"
57 #include "lrealpath.h"
58 #include "free_atexit.h"
59 #include "polygon.h"
60 #include "pcb-printf.h"
62 #include "hid/common/actions.h"
64 /* This next one is so we can print the help messages. */
65 #include "hid/hidint.h"
67 #ifdef HAVE_DBUS
68 #include "dbus.h"
69 #endif
71 #if ENABLE_NLS
72 #include <libintl.h>
73 #endif
75 #ifdef HAVE_LIBDMALLOC
76 #include <dmalloc.h>
77 #endif
79 #define PCBLIBPATH ".:" PCBLIBDIR
82 #ifdef HAVE_LIBSTROKE
83 extern void stroke_init (void);
84 #endif
87 /* ----------------------------------------------------------------------
88 * initialize signal and error handlers
90 static void
91 InitHandler (void)
94 signal(SIGHUP, CatchSignal);
95 signal(SIGQUIT, CatchSignal);
96 signal(SIGABRT, CatchSignal);
97 signal(SIGSEGV, CatchSignal);
98 signal(SIGTERM, CatchSignal);
99 signal(SIGINT, CatchSignal);
102 /* calling external program by popen() may cause a PIPE signal,
103 * so we ignore it
105 #ifdef SIGPIPE
106 signal (SIGPIPE, SIG_IGN);
107 #endif
111 /* ----------------------------------------------------------------------
112 | command line and rc file processing.
114 static char *command_line_pcb;
116 void
117 copyright (void)
119 printf ("\n"
120 " COPYRIGHT for %s version %s\n\n"
121 " PCB, interactive printed circuit board design\n"
122 " Copyright (C) 1994,1995,1996,1997 Thomas Nau\n"
123 " Copyright (C) 1998, 1999, 2000 Harry Eaton\n\n"
124 " This program is free software; you can redistribute it and/or modify\n"
125 " it under the terms of the GNU General Public License as published by\n"
126 " the Free Software Foundation; either version 2 of the License, or\n"
127 " (at your option) any later version.\n\n"
128 " This program is distributed in the hope that it will be useful,\n"
129 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
130 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
131 " GNU General Public License for more details.\n\n"
132 " You should have received a copy of the GNU General Public License\n"
133 " along with this program; if not, write to the Free Software\n"
134 " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
135 Progname, VERSION);
136 exit (0);
139 static inline void
140 u (const char *fmt, ...)
142 va_list ap;
143 va_start (ap, fmt);
144 vfprintf (stderr, fmt, ap);
145 fputc ('\n', stderr);
146 va_end (ap);
149 typedef struct UsageNotes {
150 struct UsageNotes *next;
151 HID_Attribute *seen;
152 } UsageNotes;
154 static UsageNotes *usage_notes = NULL;
156 static void
157 usage_attr (HID_Attribute * a)
159 int i, n;
160 const Unit *unit_list;
161 static char buf[200];
163 if (a->help_text == ATTR_UNDOCUMENTED)
164 return;
166 switch (a->type)
168 case HID_Label:
169 return;
170 case HID_Integer:
171 case HID_Real:
172 sprintf (buf, "--%s <num>", a->name);
173 break;
174 case HID_Coord:
175 sprintf (buf, "--%s <measure>", a->name);
176 break;
177 case HID_String:
178 sprintf (buf, "--%s <string>", a->name);
179 break;
180 case HID_Boolean:
181 sprintf (buf, "--%s", a->name);
182 break;
183 case HID_Mixed:
184 case HID_Enum:
185 sprintf (buf, "--%s ", a->name);
186 if (a->type == HID_Mixed)
187 strcat (buf, " <val>");
188 for (i = 0; a->enumerations[i]; i++)
190 strcat (buf, i ? "|" : "<");
191 strcat (buf, a->enumerations[i]);
193 strcat (buf, ">");
194 break;
195 case HID_Path:
196 sprintf (buf, "--%s <path>", a->name);
197 break;
198 case HID_Unit:
199 unit_list = get_unit_list ();
200 n = get_n_units ();
201 sprintf (buf, "--%s ", a->name);
202 for (i = 0; i < n; i++)
204 strcat (buf, i ? "|" : "<");
205 strcat (buf, unit_list[i].suffix);
207 strcat (buf, ">");
208 break;
211 if (strlen (buf) <= 30)
213 if (a->help_text)
214 fprintf (stderr, " %-30s\t%s\n", buf, a->help_text);
215 else
216 fprintf (stderr, " %-30s\n", buf);
218 else if (a->help_text && strlen (a->help_text) + strlen (buf) < 72)
219 fprintf (stderr, " %s\t%s\n", buf, a->help_text);
220 else if (a->help_text)
221 fprintf (stderr, " %s\n\t\t\t%s\n", buf, a->help_text);
222 else
223 fprintf (stderr, " %s\n", buf);
226 static void
227 usage_hid (HID * h)
229 HID_Attribute *attributes;
230 int i, n_attributes = 0;
231 UsageNotes *note;
233 if (h->gui)
235 fprintf (stderr, "\n%s gui options:\n", h->name);
236 attributes = h->get_export_options (&n_attributes);
238 else
240 fprintf (stderr, "\n%s options:\n", h->name);
241 exporter = h;
242 attributes = exporter->get_export_options (&n_attributes);
243 exporter = NULL;
246 note = (UsageNotes *)malloc (sizeof (UsageNotes));
247 note->next = usage_notes;
248 note->seen = attributes;
249 usage_notes = note;
251 for (i = 0; i < n_attributes; i++)
252 usage_attr (attributes + i);
255 static void
256 usage (void)
258 HID **hl = hid_enumerate ();
259 HID_AttrNode *ha;
260 UsageNotes *note;
261 int i;
262 int n_printer = 0, n_gui = 0, n_exporter = 0;
264 for (i = 0; hl[i]; i++)
266 if (hl[i]->gui)
267 n_gui++;
268 if (hl[i]->printer)
269 n_printer++;
270 if (hl[i]->exporter)
271 n_exporter++;
274 u ("PCB Printed Circuit Board editing program, http://pcb.geda-project.org");
275 u ("%s [-h|-V|--copyright]\t\t\tHelp, version, copyright", Progname);
276 u ("%s [gui options] <pcb file>\t\tto edit", Progname);
277 u ("Available GUI hid%s:", n_gui == 1 ? "" : "s");
278 for (i = 0; hl[i]; i++)
279 if (hl[i]->gui)
280 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
281 u ("%s -p [printing options] <pcb file>\tto print", Progname);
282 u ("Available printing hid%s:", n_printer == 1 ? "" : "s");
283 for (i = 0; hl[i]; i++)
284 if (hl[i]->printer)
285 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
286 u ("%s -x hid [export options] <pcb file>\tto export", Progname);
287 u ("Available export hid%s:", n_exporter == 1 ? "" : "s");
288 for (i = 0; hl[i]; i++)
289 if (hl[i]->exporter)
290 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
292 for (i = 0; hl[i]; i++)
293 if (hl[i]->gui)
294 usage_hid (hl[i]);
295 for (i = 0; hl[i]; i++)
296 if (hl[i]->printer)
297 usage_hid (hl[i]);
298 for (i = 0; hl[i]; i++)
299 if (hl[i]->exporter)
300 usage_hid (hl[i]);
302 u ("\nCommon options:");
303 for (ha = hid_attr_nodes; ha; ha = ha->next)
305 for (note = usage_notes; note && note->seen != ha->attributes; note = note->next)
307 if (note)
308 continue;
309 for (i = 0; i < ha->n; i++)
311 usage_attr (ha->attributes + i);
315 exit (1);
318 static void
319 print_defaults_1 (HID_Attribute * a, void *value)
321 int i;
322 Coord c;
323 double d;
324 const char *s;
326 /* Remember, at this point we've parsed the command line, so they
327 may be in the global variable instead of the default_val. */
328 switch (a->type)
330 case HID_Integer:
331 i = value ? *(int *) value : a->default_val.int_value;
332 fprintf (stderr, "%s %d\n", a->name, i);
333 break;
334 case HID_Boolean:
335 i = value ? *(char *) value : a->default_val.int_value;
336 fprintf (stderr, "%s %s\n", a->name, i ? "yes" : "no");
337 break;
338 case HID_Real:
339 d = value ? *(double *) value : a->default_val.real_value;
340 fprintf (stderr, "%s %g\n", a->name, d);
341 break;
342 case HID_Coord:
343 c = value ? *(Coord *) value : a->default_val.coord_value;
344 pcb_fprintf (stderr, "%s %$mS\n", a->name, c);
345 break;
346 case HID_String:
347 case HID_Path:
348 s = value ? *(char **) value : a->default_val.str_value;
349 fprintf (stderr, "%s \"%s\"\n", a->name, s);
350 break;
351 case HID_Enum:
352 i = value ? *(int *) value : a->default_val.int_value;
353 fprintf (stderr, "%s %s\n", a->name, a->enumerations[i]);
354 break;
355 case HID_Mixed:
356 i = value ?
357 ((HID_Attr_Val*)value)->int_value : a->default_val.int_value;
358 d = value ?
359 ((HID_Attr_Val*)value)->real_value : a->default_val.real_value;
360 fprintf (stderr, "%s %g%s\n", a->name, d, a->enumerations[i]);
361 break;
362 case HID_Label:
363 break;
364 case HID_Unit:
365 i = value ? *(int *) value : a->default_val.int_value;
366 fprintf (stderr, "%s %s\n", a->name, get_unit_list()[i].suffix);
370 static void
371 print_defaults ()
373 HID **hl = hid_enumerate ();
374 HID_Attribute *e;
375 int i, n, hi;
377 for (hi = 0; hl[hi]; hi++)
379 HID *h = hl[hi];
380 if (h->gui)
382 HID_AttrNode *ha;
383 fprintf (stderr, "\ngui defaults:\n");
384 for (ha = hid_attr_nodes; ha; ha = ha->next)
385 for (i = 0; i < ha->n; i++)
386 print_defaults_1 (ha->attributes + i, ha->attributes[i].value);
388 else
390 fprintf (stderr, "\n%s defaults:\n", h->name);
391 exporter = h;
392 e = exporter->get_export_options (&n);
393 exporter = NULL;
394 if (e)
395 for (i = 0; i < n; i++)
396 print_defaults_1 (e + i, 0);
399 exit (1);
402 #define SSET(F,D,N,H) { N, H, \
403 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
404 #define ISET(F,D,N,H) { N, H, \
405 HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }
406 #define BSET(F,D,N,H) { N, H, \
407 HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }
408 #define RSET(F,D,N,H) { N, H, \
409 HID_Real, 0, 0, { 0, 0, D }, 0, &Settings.F }
410 #define CSET(F,D,N,H) { N, H, \
411 HID_Coord, 0, 0, { 0, 0, 0, D }, 0, &Settings.F }
413 #define COLOR(F,D,N,H) { N, H, \
414 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
415 #define LAYERCOLOR(N,D) { "layer-color-" #N, "Color for layer " #N, \
416 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }
417 #define LAYERNAME(N,D) { "layer-name-" #N, "Name for layer " #N, \
418 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }
419 #define LAYERSELCOLOR(N) { "layer-selected-color-" #N, "Color for layer " #N " when selected", \
420 HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }
422 static int show_help = 0;
423 static int show_version = 0;
424 static int show_copyright = 0;
425 static int show_defaults = 0;
426 static int show_actions = 0;
427 static int do_dump_actions = 0;
428 static char *grid_units;
429 static Increments increment_mm = { 0 };
430 static Increments increment_mil = { 0 };
432 void save_increments (const Increments *mm, const Increments *mil)
434 memcpy (&increment_mm, mm, sizeof (*mm));
435 memcpy (&increment_mil, mil, sizeof (*mil));
438 HID_Attribute main_attribute_list[] = {
440 /* %start-doc options "1 General Options"
441 @ftable @code
442 @item --help
443 Show help on command line options.
444 @end ftable
445 %end-doc
447 {"help", "Show help on command line options", HID_Boolean, 0, 0, {0, 0, 0}, 0,
448 &show_help},
450 /* %start-doc options "1 General Options"
451 @ftable @code
452 @item --version
453 Show version.
454 @end ftable
455 %end-doc
457 {"version", "Show version", HID_Boolean, 0, 0, {0, 0, 0}, 0, &show_version},
459 /* %start-doc options "1 General Options"
460 @ftable @code
461 @item --verbose
462 Be verbose on stdout.
463 @end ftable
464 %end-doc
466 {"verbose", "Be verbose on stdout", HID_Boolean, 0, 0, {0, 0, 0}, 0,
467 &Settings.verbose},
469 /* %start-doc options "1 General Options"
470 @ftable @code
471 @item --copyright
472 Show copyright.
473 @end ftable
474 %end-doc
476 {"copyright", "Show Copyright", HID_Boolean, 0, 0, {0, 0, 0}, 0,
477 &show_copyright},
479 /* %start-doc options "1 General Options"
480 @ftable @code
481 @item --show-defaults
482 Show option defaults.
483 @end ftable
484 %end-doc
486 {"show-defaults", "Show option defaults", HID_Boolean, 0, 0, {0, 0, 0}, 0,
487 &show_defaults},
489 /* %start-doc options "1 General Options"
490 @ftable @code
491 @item --show-actions
492 Show available actions and exit.
493 @end ftable
494 %end-doc
496 {"show-actions", "Show available actions", HID_Boolean, 0, 0, {0, 0, 0}, 0,
497 &show_actions},
499 /* %start-doc options "1 General Options"
500 @ftable @code
501 @item --dump-actions
502 Dump actions (for documentation).
503 @end ftable
504 %end-doc
506 {"dump-actions", "Dump actions (for documentation)", HID_Boolean, 0, 0,
507 {0, 0, 0}, 0, &do_dump_actions},
509 /* %start-doc options "1 General Options"
510 @ftable @code
511 @item --grid-units-mm <string>
512 Set default grid units. Can be mm or mil. Defaults to mil.
513 @end ftable
514 %end-doc
516 {"grid-units", "Default grid units (mm|mil)", HID_String, 0, 0, {0, "mil", 0},
517 0, &grid_units},
519 /* %start-doc options "1 General Options"
520 @ftable @code
521 @item --clear-increment-mm <string>
522 Set default clear increment (amount to change when user presses k or K)
523 when user is using a metric grid unit.
524 @end ftable
525 %end-doc
527 {"clear-increment-mm", "Default clear increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
528 0, &increment_mm.clear},
530 /* %start-doc options "1 General Options"
531 @ftable @code
532 @item --grid-increment-mm <string>
533 Set default grid increment (amount to change when user presses g or G)
534 when user is using a metric grid unit.
535 @end ftable
536 %end-doc
538 {"grid-increment-mm", "Default grid increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
539 0, &increment_mm.grid},
541 /* %start-doc options "1 General Options"
542 @ftable @code
543 @item --line-increment-mm <string>
544 Set default line increment (amount to change when user presses l or L)
545 when user is using a metric grid unit.
546 @end ftable
547 %end-doc
549 {"line-increment-mm", "Default line increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
550 0, &increment_mm.line},
552 /* %start-doc options "1 General Options"
553 @ftable @code
554 @item --size-increment-mm <string>
555 Set default size increment (amount to change when user presses s or S)
556 when user is using a metric grid unit.
557 @end ftable
558 %end-doc
560 {"size-increment-mm", "Default size increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
561 0, &increment_mm.size},
563 /* %start-doc options "1 General Options"
564 @ftable @code
565 @item --clear-increment-mil <string>
566 Set default clear increment (amount to change when user presses k or K)
567 when user is using an imperial grid unit.
568 @end ftable
569 %end-doc
571 {"clear-increment-mil", "Default clear increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
572 0, &increment_mil.clear},
574 /* %start-doc options "1 General Options"
575 @ftable @code
576 @item --grid-increment-mil <string>
577 Set default grid increment (amount to change when user presses g or G)
578 when user is using a imperial grid unit.
579 @end ftable
580 %end-doc
582 {"grid-increment-mil", "Default grid increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
583 0, &increment_mil.grid},
585 /* %start-doc options "1 General Options"
586 @ftable @code
587 @item --line-increment-mil <string>
588 Set default line increment (amount to change when user presses l or L)
589 when user is using a imperial grid unit.
590 @end ftable
591 %end-doc
593 {"line-increment-mil", "Default line increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
594 0, &increment_mil.line},
596 /* %start-doc options "1 General Options"
597 @ftable @code
598 @item --size-increment-mil <string>
599 Set default size increment (amount to change when user presses s or S)
600 when user is using a imperial grid unit.
601 @end ftable
602 %end-doc
604 {"size-increment-mil", "Default size increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
605 0, &increment_mil.size},
607 /* %start-doc options "3 Colors"
608 @ftable @code
609 @item --black-color <string>
610 Color value for black. Default: @samp{#000000}
611 @end ftable
612 %end-doc
614 COLOR (BlackColor, "#000000", "black-color", "color value of 'black'"),
616 /* %start-doc options "3 Colors"
617 @ftable @code
618 @item --black-color <string>
619 Color value for white. Default: @samp{#ffffff}
620 @end ftable
621 %end-doc
623 COLOR (WhiteColor, "#ffffff", "white-color", "color value of 'white'"),
625 /* %start-doc options "3 Colors"
626 @ftable @code
627 @item --background-color <string>
628 Background color of the canvas. Default: @samp{#e5e5e5}
629 @end ftable
630 %end-doc
632 COLOR (BackgroundColor, "#e5e5e5", "background-color",
633 "color for background"),
635 /* %start-doc options "3 Colors"
636 @ftable @code
637 @item --crosshair-color <string>
638 Color of the crosshair. Default: @samp{#ff0000}
639 @end ftable
640 %end-doc
642 COLOR (CrosshairColor, "#ff0000", "crosshair-color",
643 "color for the crosshair"),
645 /* %start-doc options "3 Colors"
646 @ftable @code
647 @item --cross-color <string>
648 Color of the cross. Default: @samp{#cdcd00}
649 @end ftable
650 %end-doc
652 COLOR (CrossColor, "#cdcd00", "cross-color", "color of the cross"),
654 /* %start-doc options "3 Colors"
655 @ftable @code
656 @item --via-color <string>
657 Color of vias. Default: @samp{#7f7f7f}
658 @end ftable
659 %end-doc
661 COLOR (ViaColor, "#7f7f7f", "via-color", "color of vias"),
663 /* %start-doc options "3 Colors"
664 @ftable @code
665 @item --via-selected-color <string>
666 Color of selected vias. Default: @samp{#00ffff}
667 @end ftable
668 %end-doc
670 COLOR (ViaSelectedColor, "#00ffff", "via-selected-color",
671 "color for selected vias"),
673 /* %start-doc options "3 Colors"
674 @ftable @code
675 @item --pin-color <string>
676 Color of pins. Default: @samp{#4d4d4d}
677 @end ftable
678 %end-doc
680 COLOR (PinColor, "#4d4d4d", "pin-color", "color of pins"),
682 /* %start-doc options "3 Colors"
683 @ftable @code
684 @item --pin-selected-color <string>
685 Color of selected pins. Default: @samp{#00ffff}
686 @end ftable
687 %end-doc
689 COLOR (PinSelectedColor, "#00ffff", "pin-selected-color",
690 "color of selected pins"),
692 /* %start-doc options "3 Colors"
693 @ftable @code
694 @item --pin-name-color <string>
695 Color of pin names and pin numbers. Default: @samp{#ff0000}
696 @end ftable
697 %end-doc
699 COLOR (PinNameColor, "#ff0000", "pin-name-color",
700 "color for pin names and pin numbers"),
702 /* %start-doc options "3 Colors"
703 @ftable @code
704 @item --element-color <string>
705 Color of components. Default: @samp{#000000}
706 @end ftable
707 %end-doc
709 COLOR (ElementColor, "#000000", "element-color", "color of components"),
711 /* %start-doc options "3 Colors"
712 @ftable @code
713 @item --rat-color <string>
714 Color of ratlines. Default: @samp{#b8860b}
715 @end ftable
716 %end-doc
718 COLOR (RatColor, "#b8860b", "rat-color", "color of ratlines"),
720 /* %start-doc options "3 Colors"
721 @ftable @code
722 @item --invisible-objects-color <string>
723 Color of invisible objects. Default: @samp{#cccccc}
724 @end ftable
725 %end-doc
727 COLOR (InvisibleObjectsColor, "#cccccc", "invisible-objects-color",
728 "color of invisible objects"),
730 /* %start-doc options "3 Colors"
731 @ftable @code
732 @item --invisible-mark-color <string>
733 Color of invisible marks. Default: @samp{#cccccc}
734 @end ftable
735 %end-doc
737 COLOR (InvisibleMarkColor, "#cccccc", "invisible-mark-color",
738 "color of invisible marks"),
740 /* %start-doc options "3 Colors"
741 @ftable @code
742 @item --element-selected-color <string>
743 Color of selected components. Default: @samp{#00ffff}
744 @end ftable
745 %end-doc
747 COLOR (ElementSelectedColor, "#00ffff", "element-selected-color",
748 "color of selected components"),
750 /* %start-doc options "3 Colors"
751 @ftable @code
752 @item --rat-selected-color <string>
753 Color of selected rats. Default: @samp{#00ffff}
754 @end ftable
755 %end-doc
757 COLOR (RatSelectedColor, "#00ffff", "rat-selected-color",
758 "color of selected rats"),
760 /* %start-doc options "3 Colors"
761 @ftable @code
762 @item --connected-color <string>
763 Color to indicate physical connections. Default: @samp{#00ff00}
764 @end ftable
765 %end-doc
767 COLOR (ConnectedColor, "#00ff00", "connected-color",
768 "color to indicate physically connected objects"),
770 /* %start-doc options "3 Colors"
771 @ftable @code
772 @item --found-color <string>
773 Color to indicate logical connections. Default: @samp{#ff00ff}
774 @end ftable
775 %end-doc
777 COLOR (FoundColor, "#ff00ff", "found-color",
778 "color to indicate logically connected objects"),
780 /* %start-doc options "3 Colors"
781 @ftable @code
782 @item --off-limit-color <string>
783 Color of off-canvas area. Default: @samp{#cccccc}
784 @end ftable
785 %end-doc
787 COLOR (OffLimitColor, "#cccccc", "off-limit-color",
788 "color of off-canvas area"),
790 /* %start-doc options "3 Colors"
791 @ftable @code
792 @item --grid-color <string>
793 Color of the grid. Default: @samp{#ff0000}
794 @end ftable
795 %end-doc
797 COLOR (GridColor, "#ff0000", "grid-color", "color of the grid"),
799 /* %start-doc options "3 Colors"
800 @ftable @code
801 @item --layer-color-<n> <string>
802 Color of layer @code{<n>}, where @code{<n>} is an integer from 1 to 16.
803 @end ftable
804 %end-doc
806 LAYERCOLOR (1, "#8b2323"),
807 LAYERCOLOR (2, "#3a5fcd"),
808 LAYERCOLOR (3, "#104e8b"),
809 LAYERCOLOR (4, "#cd3700"),
810 LAYERCOLOR (5, "#548b54"),
811 LAYERCOLOR (6, "#8b7355"),
812 LAYERCOLOR (7, "#00868b"),
813 LAYERCOLOR (8, "#228b22"),
814 LAYERCOLOR (9, "#8b2323"),
815 LAYERCOLOR (10, "#3a5fcd"),
816 LAYERCOLOR (11, "#104e8b"),
817 LAYERCOLOR (12, "#cd3700"),
818 LAYERCOLOR (13, "#548b54"),
819 LAYERCOLOR (14, "#8b7355"),
820 LAYERCOLOR (15, "#00868b"),
821 LAYERCOLOR (16, "#228b22"),
822 /* %start-doc options "3 Colors"
823 @ftable @code
824 @item --layer-selected-color-<n> <string>
825 Color of layer @code{<n>}, when selected. @code{<n>} is an integer from 1 to 16.
826 @end ftable
827 %end-doc
829 LAYERSELCOLOR (1),
830 LAYERSELCOLOR (2),
831 LAYERSELCOLOR (3),
832 LAYERSELCOLOR (4),
833 LAYERSELCOLOR (5),
834 LAYERSELCOLOR (6),
835 LAYERSELCOLOR (7),
836 LAYERSELCOLOR (8),
837 LAYERSELCOLOR (9),
838 LAYERSELCOLOR (10),
839 LAYERSELCOLOR (11),
840 LAYERSELCOLOR (12),
841 LAYERSELCOLOR (13),
842 LAYERSELCOLOR (14),
843 LAYERSELCOLOR (15),
844 LAYERSELCOLOR (16),
846 /* %start-doc options "3 Colors"
847 @ftable @code
848 @item --warn-color <string>
849 Color of offending objects during DRC. Default value is @code{"#ff8000"}
850 @end ftable
851 %end-doc
853 COLOR (WarnColor, "#ff8000", "warn-color", "color of offending objects during DRC"),
855 /* %start-doc options "3 Colors"
856 @ftable @code
857 @item --mask-color <string>
858 Color of the mask layer. Default value is @code{"#ff0000"}
859 @end ftable
860 %end-doc
862 COLOR (MaskColor, "#ff0000", "mask-color", "color for solder mask"),
865 /* %start-doc options "5 Sizes"
866 All parameters should be given with an unit. If no unit is given, 1/100 mil
867 (cmil) will be used. Write units without space to the
868 number like @code{3mm}, not @code{3 mm}.
869 Valid Units are:
870 @table @samp
871 @item km
872 Kilometer
873 @item m
874 Meter
875 @item cm
876 Centimeter
877 @item mm
878 Millimeter
879 @item um
880 Micrometer
881 @item nm
882 Nanometer
883 @item in
884 Inch (1in = 0.0254m)
885 @item mil
886 Mil (1000mil = 1in)
887 @item cmil
888 Centimil (1/100 mil)
889 @end table
891 @ftable @code
892 @item --via-thickness <num>
893 Default diameter of vias. Default value is @code{60mil}.
894 @end ftable
895 %end-doc
897 CSET (ViaThickness, MIL_TO_COORD(60), "via-thickness",
898 "default diameter of vias in 1/100 mil"),
900 /* %start-doc options "5 Sizes"
901 @ftable @code
902 @item --via-drilling-hole <num>
903 Default diameter of holes. Default value is @code{28mil}.
904 @end ftable
905 %end-doc
907 CSET (ViaDrillingHole, MIL_TO_COORD(28), "via-drilling-hole",
908 "default diameter of holes"),
910 /* %start-doc options "5 Sizes"
911 @ftable @code
912 @item --line-thickness <num>
913 Default thickness of new lines. Default value is @code{10mil}.
914 @end ftable
915 %end-doc
917 CSET (LineThickness, MIL_TO_COORD(10), "line-thickness",
918 "initial thickness of new lines"),
920 /* %start-doc options "5 Sizes"
921 @ftable @code
922 @item --rat-thickness <num><unit>
923 Thickness of rats. If no unit is given, PCB units are assumed (i.e. 100
924 means "1 nm"). This option allows for a special unit @code{px} which
925 sets the rat thickness to a fixed value in terms of screen pixels.
926 Maximum fixed thickness is 100px. Minimum saling rat thickness is 101nm.
927 Default value is @code{10mil}.
928 @end ftable
929 %end-doc
931 CSET (RatThickness, MIL_TO_COORD(10), "rat-thickness", "thickness of rat lines"),
933 /* %start-doc options "5 Sizes"
934 @ftable @code
935 @item --keepaway <num>
936 Default minimum distance between a track and adjacent copper.
937 Default value is @code{10mil}.
938 @end ftable
939 %end-doc
941 CSET (Keepaway, MIL_TO_COORD(10), "keepaway", "minimum distance between adjacent copper"),
943 /* %start-doc options "5 Sizes"
944 @ftable @code
945 @item --default-PCB-width <num>
946 Default width of the canvas. Default value is @code{6000mil}.
947 @end ftable
948 %end-doc
950 CSET (MaxWidth, MIL_TO_COORD(6000), "default-PCB-width",
951 "default width of the canvas"),
953 /* %start-doc options "5 Sizes"
954 @ftable @code
955 @item --default-PCB-height <num>
956 Default height of the canvas. Default value is @code{5000mil}.
957 @end ftable
958 %end-doc
960 CSET (MaxHeight, MIL_TO_COORD(5000), "default-PCB-height",
961 "default height of the canvas"),
963 /* %start-doc options "5 Sizes"
964 @ftable @code
965 @item --text-scale <num>
966 Default text scale. This value is in percent. Default value is @code{100}.
967 @end ftable
968 %end-doc
970 ISET (TextScale, 100, "text-scale", "default text scale in percent"),
972 /* %start-doc options "5 Sizes"
973 @ftable @code
974 @item --alignment-distance <num>
975 Specifies the distance between the board outline and alignment targets.
976 Default value is @code{2mil}.
977 @end ftable
978 %end-doc
980 CSET (AlignmentDistance, MIL_TO_COORD(2), "alignment-distance",
981 "distance between the boards outline and alignment targets"),
983 /* %start-doc options "7 DRC Options"
984 All parameters should be given with an unit. If no unit is given, 1/100 mil
985 (cmil) will be used for backward compability. Valid units are given in section
986 @ref{Sizes}.
987 %end-doc
991 /* %start-doc options "7 DRC Options"
992 @ftable @code
993 @item --bloat <num>
994 Minimum spacing. Default value is @code{10mil}.
995 @end ftable
996 %end-doc
998 CSET (Bloat, MIL_TO_COORD(10), "bloat", "DRC minimum spacing in 1/100 mil"),
1000 /* %start-doc options "7 DRC Options"
1001 @ftable @code
1002 @item --shrink <num>
1003 Minimum touching overlap. Default value is @code{10mil}.
1004 @end ftable
1005 %end-doc
1007 CSET (Shrink, MIL_TO_COORD(10), "shrink", "DRC minimum overlap in 1/100 mils"),
1009 /* %start-doc options "7 DRC Options"
1010 @ftable @code
1011 @item --min-width <num>
1012 Minimum width of copper. Default value is @code{10mil}.
1013 @end ftable
1014 %end-doc
1016 CSET (minWid, MIL_TO_COORD(10), "min-width", "DRC minimum copper spacing"),
1018 /* %start-doc options "7 DRC Options"
1019 @ftable @code
1020 @item --min-silk <num>
1021 Minimum width of lines in silk. Default value is @code{10mil}.
1022 @end ftable
1023 %end-doc
1025 CSET (minSlk, MIL_TO_COORD(10), "min-silk", "DRC minimum silk width"),
1027 /* %start-doc options "7 DRC Options"
1028 @ftable @code
1029 @item --min-drill <num>
1030 Minimum diameter of holes. Default value is @code{15mil}.
1031 @end ftable
1032 %end-doc
1034 CSET (minDrill, MIL_TO_COORD(15), "min-drill", "DRC minimum drill diameter"),
1036 /* %start-doc options "7 DRC Options"
1037 @ftable @code
1038 @item --min-ring <num>
1039 Minimum width of annular ring. Default value is @code{10mil}.
1040 @end ftable
1041 %end-doc
1043 CSET (minRing, MIL_TO_COORD(10), "min-ring", "DRC minimum annular ring"),
1046 /* %start-doc options "5 Sizes"
1047 @ftable @code
1048 @item --grid <num>
1049 Initial grid size. Default value is @code{10mil}.
1050 @end ftable
1051 %end-doc
1053 CSET (Grid, MIL_TO_COORD(10), "grid", "Initial grid size in 1/100 mil"),
1055 /* %start-doc options "5 Sizes"
1056 @ftable @code
1057 @item --minimum polygon area <num>
1058 Minimum polygon area.
1059 @end ftable
1060 %end-doc
1062 RSET (IsleArea, MIL_TO_COORD(100) * MIL_TO_COORD(100), "minimum polygon area", 0),
1065 /* %start-doc options "1 General Options"
1066 @ftable @code
1067 @item --backup-interval
1068 Time between automatic backups in seconds. Set to @code{0} to disable.
1069 The default value is @code{60}.
1070 @end ftable
1071 %end-doc
1073 ISET (BackupInterval, 60, "backup-interval",
1074 "Time between automatic backups in seconds. Set to 0 to disable"),
1076 /* %start-doc options "4 Layer Names"
1077 @ftable @code
1078 @item --layer-name-1 <string>
1079 Name of the 1st Layer. Default is @code{"top"}.
1080 @end ftable
1081 %end-doc
1083 LAYERNAME (1, "top"),
1085 /* %start-doc options "4 Layer Names"
1086 @ftable @code
1087 @item --layer-name-2 <string>
1088 Name of the 2nd Layer. Default is @code{"ground"}.
1089 @end ftable
1090 %end-doc
1092 LAYERNAME (2, "ground"),
1094 /* %start-doc options "4 Layer Names"
1095 @ftable @code
1096 @item --layer-name-3 <string>
1097 Name of the 3nd Layer. Default is @code{"signal2"}.
1098 @end ftable
1099 %end-doc
1101 LAYERNAME (3, "signal2"),
1103 /* %start-doc options "4 Layer Names"
1104 @ftable @code
1105 @item --layer-name-4 <string>
1106 Name of the 4rd Layer. Default is @code{"signal3"}.
1107 @end ftable
1108 %end-doc
1110 LAYERNAME (4, "signal3"),
1112 /* %start-doc options "4 Layer Names"
1113 @ftable @code
1114 @item --layer-name-5 <string>
1115 Name of the 5rd Layer. Default is @code{"power"}.
1116 @end ftable
1117 %end-doc
1119 LAYERNAME (5, "power"),
1121 /* %start-doc options "4 Layer Names"
1122 @ftable @code
1123 @item --layer-name-6 <string>
1124 Name of the 6rd Layer. Default is @code{"bottom"}.
1125 @end ftable
1126 %end-doc
1128 LAYERNAME (6, "bottom"),
1130 /* %start-doc options "4 Layer Names"
1131 @ftable @code
1132 @item --layer-name-7 <string>
1133 Name of the 7rd Layer. Default is @code{"outline"}.
1134 @end ftable
1135 %end-doc
1137 LAYERNAME (7, "outline"),
1139 /* %start-doc options "4 Layer Names"
1140 @ftable @code
1141 @item --layer-name-8 <string>
1142 Name of the 8rd Layer. Default is @code{"spare"}.
1143 @end ftable
1144 %end-doc
1146 LAYERNAME (8, "spare"),
1148 /* %start-doc options "1 General Options"
1149 @ftable @code
1150 @item --groups <string>
1151 Layer group string. Defaults to @code{"1,c:2:3:4:5:6,s:7:8"}.
1152 @end ftable
1153 %end-doc
1155 SSET (Groups, "1,c:2:3:4:5:6,s:7:8", "groups", "Layer group string"),
1158 /* %start-doc options "6 Commands"
1159 pcb uses external commands for input output operations. These commands can be
1160 configured at start-up to meet local requirements. The command string may include
1161 special sequences @code{%f}, @code{%p} or @code{%a}. These are replaced when the
1162 command is called. The sequence @code{%f} is replaced by the file name,
1163 @code{%p} gets the path and @code{%a} indicates a package name.
1164 %end-doc
1167 /* %start-doc options "6 Commands"
1168 @ftable @code
1169 @item --font-command <string>
1170 Command to load a font.
1171 @end ftable
1172 %end-doc
1174 SSET (FontCommand, "", "font-command", "Command to load a font"),
1176 /* %start-doc options "6 Commands"
1177 @ftable @code
1178 @item --file-command <string>
1179 Command to read a file.
1180 @end ftable
1181 %end-doc
1183 SSET (FileCommand, "", "file-command", "Command to read a file"),
1185 /* %start-doc options "6 Commands"
1186 @ftable @code
1187 @item --element-command <string>
1188 Command to read a footprint. @*
1189 Defaults to @code{"M4PATH='%p';export M4PATH;echo 'include(%f)' | m4"}
1190 @end ftable
1191 %end-doc
1193 SSET (ElementCommand,
1194 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4,
1195 "element-command", "Command to read a footprint"),
1197 /* %start-doc options "6 Commands"
1198 @ftable @code
1199 @item --print-file <string>
1200 Command to print to a file.
1201 @end ftable
1202 %end-doc
1204 SSET (PrintFile, "%f.output", "print-file", "Command to print to a file"),
1206 /* %start-doc options "6 Commands"
1207 @ftable @code
1208 @item --lib-command-dir <string>
1209 Path to the command that queries the library.
1210 @end ftable
1211 %end-doc
1213 SSET (LibraryCommandDir, PCBLIBDIR, "lib-command-dir",
1214 "Path to the command that queries the library"),
1216 /* %start-doc options "6 Commands"
1217 @ftable @code
1218 @item --lib-command <string>
1219 Command to query the library. @*
1220 Defaults to @code{"QueryLibrary.sh '%p' '%f' %a"}
1221 @end ftable
1222 %end-doc
1224 SSET (LibraryCommand, "QueryLibrary.sh '%p' '%f' %a",
1225 "lib-command", "Command to query the library"),
1227 /* %start-doc options "6 Commands"
1228 @ftable @code
1229 @item --lib-contents-command <string>
1230 Command to query the contents of the library. @*
1231 Defaults to @code{"ListLibraryContents.sh %p %f"} or,
1232 on Windows builds, an empty string (to disable this feature).
1233 @end ftable
1234 %end-doc
1236 SSET (LibraryContentsCommand,
1237 #ifdef __WIN32__
1239 #else
1240 "ListLibraryContents.sh '%p' '%f'",
1241 #endif
1242 "lib-contents-command", "Command to query the contents of the library"),
1244 /* %start-doc options "5 Paths"
1245 @ftable @code
1246 @item --lib-newlib <string>
1247 Top level directory for the newlib style library.
1248 @end ftable
1249 %end-doc
1251 SSET (LibraryTree, PCBTREEPATH, "lib-newlib",
1252 "Top level directory for the newlib style library"),
1254 /* %start-doc options "6 Commands"
1255 @ftable @code
1256 @item --save-command <string>
1257 Command to save to a file.
1258 @end ftable
1259 %end-doc
1261 SSET (SaveCommand, "", "save-command", "Command to save to a file"),
1263 /* %start-doc options "5 Paths"
1264 @ftable @code
1265 @item --lib-name <string>
1266 The default filename for the library.
1267 @end ftable
1268 %end-doc
1270 SSET (LibraryFilename, LIBRARYFILENAME, "lib-name",
1271 "The default filename for the library"),
1273 /* %start-doc options "5 Paths"
1274 @ftable @code
1275 @item --default-font <string>
1276 The name of the default font.
1277 @end ftable
1278 %end-doc
1280 SSET (FontFile, "default_font", "default-font",
1281 "File name of default font"),
1283 /* %start-doc options "1 General Options"
1284 @ftable @code
1285 @item --route-styles <string>
1286 A string that defines the route styles. Defaults to @*
1287 @code{"Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000
1288 :Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"}
1289 @end ftable
1290 %end-doc
1292 SSET (Routes, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
1293 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
1294 "A string that defines the route styles"),
1296 /* %start-doc options "5 Paths"
1297 @ftable @code
1298 @item --file-path <string>
1299 A colon separated list of directories or commands (starts with '|'). The path
1300 is passed to the program specified in @option{--file-command} together with the selected
1301 filename.
1302 @end ftable
1303 %end-doc
1305 SSET (FilePath, "", "file-path", 0),
1307 /* %start-doc options "6 Commands"
1308 @ftable @code
1309 @item --rat-command <string>
1310 Command for reading a netlist. Sequence @code{%f} is replaced by the netlist filename.
1311 @end ftable
1312 %end-doc
1314 SSET (RatCommand, "", "rat-command", "Command for reading a netlist"),
1316 /* %start-doc options "5 Paths"
1317 @ftable @code
1318 @item --font-path <string>
1319 A colon separated list of directories to search the default font. Defaults to
1320 the default library path.
1321 @end ftable
1322 %end-doc
1324 SSET (FontPath, PCBLIBPATH, "font-path",
1325 "Colon separated list of directories to search the default font"),
1327 /* %start-doc options "1 General Options"
1328 @ftable @code
1329 @item --element-path <string>
1330 A colon separated list of directories or commands (starts with '|').
1331 The path is passed to the program specified in @option{--element-command}.
1332 @end ftable
1333 %end-doc
1335 SSET(ElementPath, PCBLIBPATH, "element-path",
1336 "A colon separated list of directories or commands (starts with '|')"),
1338 /* %start-doc options "5 Paths"
1339 @ftable @code
1340 @item --lib-path <string>
1341 A colon separated list of directories that will be passed to the commands specified
1342 by @option{--element-command} and @option{--element-contents-command}.
1343 @end ftable
1344 %end-doc
1346 SSET (LibraryPath, PCBLIBPATH, "lib-path",
1347 "A colon separated list of directories"),
1349 /* %start-doc options "1 General Options"
1350 @ftable @code
1351 @item --action-script <string>
1352 If set, this file is executed at startup.
1353 @end ftable
1354 %end-doc
1356 SSET (ScriptFilename, 0, "action-script",
1357 "If set, this file is executed at startup"),
1359 /* %start-doc options "1 General Options"
1360 @ftable @code
1361 @item --action-string <string>
1362 If set, this string of actions is executed at startup.
1363 @end ftable
1364 %end-doc
1366 SSET (ActionString, 0, "action-string",
1367 "If set, this is executed at startup"),
1369 /* %start-doc options "1 General Options"
1370 @ftable @code
1371 @item --fab-author <string>
1372 Name of author to be put in the Gerber files.
1373 @end ftable
1374 %end-doc
1376 SSET (FabAuthor, "", "fab-author",
1377 "Name of author to be put in the Gerber files"),
1379 /* %start-doc options "1 General Options"
1380 @ftable @code
1381 @item --layer-stack <string>
1382 Initial layer stackup, for setting up an export. A comma separated list of layer
1383 names, layer numbers and layer groups.
1384 @end ftable
1385 %end-doc
1387 SSET (InitialLayerStack, "", "layer-stack",
1388 "Initial layer stackup, for setting up an export."),
1390 SSET (MakeProgram, NULL, "make-program",
1391 "Sets the name and optionally full path to a make(3) program"),
1392 SSET (GnetlistProgram, NULL, "gnetlist",
1393 "Sets the name and optionally full path to the gnetlist(3) program"),
1395 /* %start-doc options "2 General GUI Options"
1396 @ftable @code
1397 @item --pinout-offset-x <num>
1398 Horizontal offset of the pin number display. Defaults to @code{100mil}.
1399 @end ftable
1400 %end-doc
1402 CSET (PinoutOffsetX, MIL_TO_COORD(1), "pinout-offset-x",
1403 "Horizontal offset of the pin number display in mil"),
1405 /* %start-doc options "2 General GUI Options"
1406 @ftable @code
1407 @item --pinout-offset-y <num>
1408 Vertical offset of the pin number display. Defaults to @code{100mil}.
1409 @end ftable
1410 %end-doc
1412 CSET (PinoutOffsetY, MIL_TO_COORD(1), "pinout-offset-y",
1413 "Vertical offset of the pin number display in mil"),
1415 /* %start-doc options "2 General GUI Options"
1416 @ftable @code
1417 @item --pinout-text-offset-x <num>
1418 Horizontal offset of the pin name display. Defaults to @code{800mil}.
1419 @end ftable
1420 %end-doc
1422 CSET (PinoutTextOffsetX, MIL_TO_COORD(8), "pinout-text-offset-x",
1423 "Horizontal offset of the pin name display in mil"),
1425 /* %start-doc options "2 General GUI Options"
1426 @ftable @code
1427 @item --pinout-text-offset-y <num>
1428 Vertical offset of the pin name display. Defaults to @code{-100mil}.
1429 @end ftable
1430 %end-doc
1432 CSET (PinoutTextOffsetY, MIL_TO_COORD(-1), "pinout-text-offset-y",
1433 "Vertical offset of the pin name display in mil"),
1435 /* %start-doc options "2 General GUI Options"
1436 @ftable @code
1437 @item --draw-grid
1438 If set, draw the grid at start-up.
1439 @end ftable
1440 %end-doc
1442 BSET (DrawGrid, 0, "draw-grid", "If set, draw the grid at start-up"),
1444 /* %start-doc options "2 General GUI Options"
1445 @ftable @code
1446 @item --clear-line
1447 If set, new lines clear polygons.
1448 @end ftable
1449 %end-doc
1451 BSET (ClearLine, 1, "clear-line", "If set, new lines clear polygons"),
1453 /* %start-doc options "2 General GUI Options"
1454 @ftable @code
1455 @item --full-poly
1456 If set, new polygons are full ones.
1457 @end ftable
1458 %end-doc
1460 BSET (FullPoly, 0, "full-poly", 0),
1462 /* %start-doc options "2 General GUI Options"
1463 @ftable @code
1464 @item --unique-names
1465 If set, you will not be permitted to change the name of an component to match that
1466 of another component.
1467 @end ftable
1468 %end-doc
1470 BSET (UniqueNames, 1, "unique-names", "Prevents identical component names"),
1472 /* %start-doc options "2 General GUI Options"
1473 @ftable @code
1474 @item --snap-pin
1475 If set, pin centers and pad end points are treated as additional grid points
1476 that the cursor can snap to.
1477 @end ftable
1478 %end-doc
1480 BSET (SnapPin, 1, "snap-pin",
1481 "If set, the cursor snaps to pads and pin centers"),
1483 /* %start-doc options "1 General Options"
1484 @ftable @code
1485 @item --save-last-command
1486 If set, the last user command is saved.
1487 @end ftable
1488 %end-doc
1490 BSET (SaveLastCommand, 0, "save-last-command", 0),
1492 /* %start-doc options "1 General Options"
1493 @ftable @code
1494 @item --save-in-tmp
1495 If set, all data which would otherwise be lost are saved in a temporary file
1496 @file{/tmp/PCB.%i.save} . Sequence @samp{%i} is replaced by the process ID.
1497 @end ftable
1498 %end-doc
1500 BSET (SaveInTMP, 0, "save-in-tmp",
1501 "When set, all data which would otherwise be lost are saved in /tmp"),
1503 /* %start-doc options "1 General Options"
1504 @ftable @code
1505 @item --save-metric-only
1506 If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm.
1507 @end ftable
1508 %end-doc
1510 BSET (SaveMetricOnly, 0, "save-metric-only",
1511 "If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm."),
1513 /* %start-doc options "2 General GUI Options"
1514 @ftable @code
1515 @item --all-direction-lines
1516 Allow all directions, when drawing new lines.
1517 @end ftable
1518 %end-doc
1520 BSET (AllDirectionLines, 0, "all-direction-lines",
1521 "Allow all directions, when drawing new lines"),
1523 /* %start-doc options "2 General GUI Options"
1524 @ftable @code
1525 @item --show-number
1526 Pinout shows number.
1527 @end ftable
1528 %end-doc
1530 BSET (ShowNumber, 0, "show-number", "Pinout shows number"),
1532 /* %start-doc options "1 General Options"
1533 @ftable @code
1534 @item --reset-after-element
1535 If set, all found connections are reset before a new component is scanned.
1536 @end ftable
1537 %end-doc
1539 BSET (ResetAfterElement, 1, "reset-after-element",
1540 "If set, all found connections are reset before a new component is scanned"),
1542 /* %start-doc options "1 General Options"
1543 @ftable @code
1544 @item --ring-bell-finished
1545 Execute the bell command when all rats are routed.
1546 @end ftable
1547 %end-doc
1549 BSET (RingBellWhenFinished, 0, "ring-bell-finished",
1550 "Execute the bell command when all rats are routed"),
1553 REGISTER_ATTRIBUTES (main_attribute_list)
1554 /* ----------------------------------------------------------------------
1555 * post-process settings.
1557 static void settings_post_process ()
1559 char *tmps;
1561 if (Settings.LibraryCommand != NULL &&
1562 Settings.LibraryCommand[0] != '\0' &&
1563 Settings.LibraryCommand[0] != PCB_DIR_SEPARATOR_C &&
1564 Settings.LibraryCommand[0] != '.')
1566 Settings.LibraryCommand
1568 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1569 Settings.LibraryCommand,
1570 NULL);
1572 if (Settings.LibraryContentsCommand != NULL &&
1573 Settings.LibraryContentsCommand[0] != '\0' &&
1574 Settings.LibraryContentsCommand[0] != PCB_DIR_SEPARATOR_C &&
1575 Settings.LibraryContentsCommand[0] != '.')
1577 Settings.LibraryContentsCommand
1579 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1580 Settings.LibraryContentsCommand, NULL);
1583 if (Settings.LineThickness > MAX_LINESIZE
1584 || Settings.LineThickness < MIN_LINESIZE)
1585 Settings.LineThickness = MIL_TO_COORD(10);
1587 if (Settings.ViaThickness > MAX_PINORVIASIZE
1588 || Settings.ViaThickness < MIN_PINORVIASIZE)
1589 Settings.ViaThickness = MIL_TO_COORD(40);
1591 if (Settings.ViaDrillingHole <= 0)
1592 Settings.ViaDrillingHole =
1593 DEFAULT_DRILLINGHOLE * Settings.ViaThickness / 100;
1595 Settings.MaxWidth = CLAMP (Settings.MaxWidth, MIN_SIZE, MAX_COORD);
1596 Settings.MaxHeight = CLAMP (Settings.MaxHeight, MIN_SIZE, MAX_COORD);
1598 ParseRouteString (Settings.Routes, &Settings.RouteStyle[0], "cmil");
1601 * Make sure we have settings for some various programs we may wish
1602 * to call
1604 if (Settings.MakeProgram == NULL) {
1605 tmps = getenv ("PCB_MAKE_PROGRAM");
1606 if (tmps != NULL)
1607 Settings.MakeProgram = strdup (tmps);
1609 if (Settings.MakeProgram == NULL) {
1610 Settings.MakeProgram = strdup ("make");
1613 if (Settings.GnetlistProgram == NULL) {
1614 tmps = getenv ("PCB_GNETLIST");
1615 if (tmps != NULL)
1616 Settings.GnetlistProgram = strdup (tmps);
1618 if (Settings.GnetlistProgram == NULL) {
1619 Settings.GnetlistProgram = strdup ("gnetlist");
1622 if (grid_units)
1623 Settings.grid_unit = get_unit_struct (grid_units);
1624 if (!grid_units || Settings.grid_unit == NULL)
1625 Settings.grid_unit = get_unit_struct ("mil");
1627 copy_nonzero_increments (get_increments_struct (METRIC), &increment_mm);
1628 copy_nonzero_increments (get_increments_struct (IMPERIAL), &increment_mil);
1630 Settings.increments = get_increments_struct (Settings.grid_unit->family);
1633 /* ----------------------------------------------------------------------
1634 * Print help or version messages.
1637 static void
1638 print_version ()
1640 printf ("PCB version %s\n", VERSION);
1641 exit (0);
1644 /* ----------------------------------------------------------------------
1645 * Figure out the canonical name of the executed program
1646 * and fix up the defaults for various paths
1648 char *bindir = NULL;
1649 char *exec_prefix = NULL;
1650 char *pcblibdir = NULL;
1651 char *pcblibpath = NULL;
1652 char *pcbtreedir = NULL;
1653 char *pcbtreepath = NULL;
1654 char *homedir = NULL;
1656 static void
1657 InitPaths (char *argv0)
1659 size_t l;
1660 int i;
1661 int haspath;
1662 char *t1, *t2;
1663 int found_bindir = 0;
1665 /* see if argv0 has enough of a path to let lrealpath give the
1666 * real path. This should be the case if you invoke pcb with
1667 * something like /usr/local/bin/pcb or ./pcb or ./foo/pcb
1668 * but if you just use pcb and it exists in your path, you'll
1669 * just get back pcb again.
1672 haspath = 0;
1673 for (i = 0; i < strlen (argv0) ; i++)
1675 if (argv0[i] == PCB_DIR_SEPARATOR_C)
1676 haspath = 1;
1679 #ifdef DEBUG
1680 printf ("InitPaths (%s): haspath = %d\n", argv0, haspath);
1681 #endif
1683 if (haspath)
1685 bindir = strdup (lrealpath (argv0));
1686 found_bindir = 1;
1688 else
1690 char *path, *p, *tmps;
1691 struct stat sb;
1692 int r;
1694 tmps = getenv ("PATH");
1696 if (tmps != NULL)
1698 path = strdup (tmps);
1700 /* search through the font path for a font file */
1701 for (p = strtok (path, PCB_PATH_DELIMETER); p && *p;
1702 p = strtok (NULL, PCB_PATH_DELIMETER))
1704 #ifdef DEBUG
1705 printf ("Looking for %s in %s\n", argv0, p);
1706 #endif
1707 if ( (tmps = (char *)malloc ( (strlen (argv0) + strlen (p) + 2) * sizeof (char))) == NULL )
1709 fprintf (stderr, "InitPaths(): malloc failed\n");
1710 exit (1);
1712 sprintf (tmps, "%s%s%s", p, PCB_DIR_SEPARATOR_S, argv0);
1713 r = stat (tmps, &sb);
1714 if (r == 0)
1716 #ifdef DEBUG
1717 printf ("Found it: \"%s\"\n", tmps);
1718 #endif
1719 bindir = lrealpath (tmps);
1720 found_bindir = 1;
1721 free (tmps);
1722 break;
1724 free (tmps);
1726 free (path);
1730 #ifdef DEBUG
1731 printf ("InitPaths(): bindir = \"%s\"\n", bindir);
1732 #endif
1734 if (found_bindir)
1736 /* strip off the executible name leaving only the path */
1737 t2 = NULL;
1738 t1 = strchr (bindir, PCB_DIR_SEPARATOR_C);
1739 while (t1 != NULL && *t1 != '\0')
1741 t2 = t1;
1742 t1 = strchr (t2 + 1, PCB_DIR_SEPARATOR_C);
1744 if (t2 != NULL)
1745 *t2 = '\0';
1747 #ifdef DEBUG
1748 printf ("After stripping off the executible name, we found\n");
1749 printf ("bindir = \"%s\"\n", bindir);
1750 #endif
1752 else
1754 /* we have failed to find out anything from argv[0] so fall back to the original
1755 * install prefix
1757 bindir = strdup (BINDIR);
1760 /* now find the path to exec_prefix */
1761 l = strlen (bindir) + 1 + strlen (BINDIR_TO_EXECPREFIX) + 1;
1762 if ( (exec_prefix = (char *) malloc (l * sizeof (char) )) == NULL )
1764 fprintf (stderr, "InitPaths(): malloc failed\n");
1765 exit (1);
1767 sprintf (exec_prefix, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1768 BINDIR_TO_EXECPREFIX);
1770 /* now find the path to PCBLIBDIR */
1771 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBLIBDIR) + 1;
1772 if ( (pcblibdir = (char *) malloc (l * sizeof (char) )) == NULL )
1774 fprintf (stderr, "InitPaths(): malloc failed\n");
1775 exit (1);
1777 sprintf (pcblibdir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1778 BINDIR_TO_PCBLIBDIR);
1780 /* and the path to PCBTREEDIR */
1781 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBTREEDIR) + 1;
1782 if ( (pcbtreedir = (char *) malloc (l * sizeof (char) )) == NULL )
1784 fprintf (stderr, "InitPaths(): malloc failed\n");
1785 exit (1);
1787 sprintf (pcbtreedir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1788 BINDIR_TO_PCBTREEDIR);
1790 /* and the search path including PCBLIBDIR */
1791 l = strlen (pcblibdir) + 3;
1792 if ( (pcblibpath = (char *) malloc (l * sizeof (char) )) == NULL )
1794 fprintf (stderr, "InitPaths(): malloc failed\n");
1795 exit (1);
1797 sprintf (pcblibpath, ".%s%s", PCB_PATH_DELIMETER, pcblibdir);
1799 /* and the newlib search path */
1800 l = strlen (pcblibdir) + 1 + strlen (pcbtreedir)
1801 + strlen ("pcblib-newlib") + 2;
1802 if ( (pcbtreepath = (char *) malloc (l * sizeof (char) )) == NULL )
1804 fprintf (stderr, "InitPaths(): malloc failed\n");
1805 exit (1);
1807 sprintf (pcbtreepath, "%s%s%s%spcblib-newlib", pcbtreedir,
1808 PCB_PATH_DELIMETER, pcblibdir,
1809 PCB_DIR_SEPARATOR_S);
1811 #ifdef DEBUG
1812 printf ("bindir = %s\n", bindir);
1813 printf ("pcblibdir = %s\n", pcblibdir);
1814 printf ("pcblibpath = %s\n", pcblibpath);
1815 printf ("pcbtreedir = %s\n", pcbtreedir);
1816 printf ("pcbtreepath = %s\n", pcbtreepath);
1817 #endif
1819 l = sizeof (main_attribute_list) / sizeof (main_attribute_list[0]);
1820 for (i = 0; i < l ; i++)
1822 if (NSTRCMP (main_attribute_list[i].name, "lib-command-dir") == 0)
1824 main_attribute_list[i].default_val.str_value = pcblibdir;
1827 if ( (NSTRCMP (main_attribute_list[i].name, "font-path") == 0)
1828 || (NSTRCMP (main_attribute_list[i].name, "element-path") == 0)
1829 || (NSTRCMP (main_attribute_list[i].name, "lib-path") == 0) )
1831 main_attribute_list[i].default_val.str_value = pcblibpath;
1834 if (NSTRCMP (main_attribute_list[i].name, "lib-newlib") == 0)
1836 main_attribute_list[i].default_val.str_value = pcbtreepath;
1842 char *tmps;
1844 tmps = getenv ("HOME");
1846 if (tmps == NULL) {
1847 tmps = getenv ("USERPROFILE");
1850 if (tmps != NULL) {
1851 homedir = strdup (tmps);
1852 } else {
1853 homedir = NULL;
1859 /* ----------------------------------------------------------------------
1860 * main program
1863 char *program_name = 0;
1864 char *program_basename = 0;
1865 char *program_directory = 0;
1867 #include "dolists.h"
1870 main (int argc, char *argv[])
1872 int i;
1874 /* init application:
1875 * - make program name available for error handlers
1876 * - evaluate special options
1877 * - initialize toplevel shell and resources
1878 * - create an empty PCB with default symbols
1879 * - initialize all other widgets
1880 * - update screen and get size of drawing area
1881 * - evaluate command-line arguments
1882 * - register 'call on exit()' function
1885 #include "core_lists.h"
1886 setbuf (stdout, 0);
1887 InitPaths (argv[0]);
1889 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1890 textdomain(GETTEXT_PACKAGE);
1891 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
1892 setlocale(LC_ALL,"");
1894 srand ( time(NULL) ); /* Set seed for rand() */
1896 initialize_units();
1897 polygon_init ();
1898 hid_init ();
1900 hid_load_settings ();
1902 program_name = argv[0];
1903 program_basename = strrchr (program_name, PCB_DIR_SEPARATOR_C);
1904 if (program_basename)
1906 program_directory = strdup (program_name);
1907 *strrchr (program_directory, PCB_DIR_SEPARATOR_C) = 0;
1908 program_basename++;
1910 else
1912 program_directory = ".";
1913 program_basename = program_name;
1915 Progname = program_basename;
1917 /* Print usage or version if requested. Then exit. */
1918 if (argc > 1 &&
1919 (strcmp (argv[1], "-h") == 0 ||
1920 strcmp (argv[1], "-?") == 0 ||
1921 strcmp (argv[1], "--help") == 0))
1922 usage ();
1923 if (argc > 1 && strcmp (argv[1], "-V") == 0)
1924 print_version ();
1925 /* Export pcb from command line if requested. */
1926 if (argc > 1 && strcmp (argv[1], "-p") == 0)
1928 exporter = gui = hid_find_printer ();
1929 argc--;
1930 argv++;
1932 else if (argc > 2 && strcmp (argv[1], "-x") == 0)
1934 exporter = gui = hid_find_exporter (argv[2]);
1935 argc -= 2;
1936 argv += 2;
1938 /* Otherwise start GUI. */
1939 else
1940 gui = hid_find_gui ();
1942 /* Exit with error if GUI failed to start. */
1943 if (!gui)
1944 exit (1);
1946 /* Set up layers. */
1947 for (i = 0; i < MAX_LAYER; i++)
1949 char buf[20];
1950 sprintf (buf, "signal%d", i + 1);
1951 Settings.DefaultLayerName[i] = strdup (buf);
1952 Settings.LayerColor[i] = "#c49350";
1953 Settings.LayerSelectedColor[i] = "#00ffff";
1956 gui->parse_arguments (&argc, &argv);
1958 if (show_help || (argc > 1 && argv[1][0] == '-'))
1959 usage ();
1960 if (show_version)
1961 print_version ();
1962 if (show_defaults)
1963 print_defaults ();
1964 if (show_copyright)
1965 copyright ();
1967 settings_post_process ();
1970 if (show_actions)
1972 print_actions ();
1973 exit (0);
1976 if (do_dump_actions)
1978 extern void dump_actions (void);
1979 dump_actions ();
1980 exit (0);
1983 /* Create a new PCB object in memory */
1984 PCB = CreateNewPCB (true);
1985 ParseGroupString (Settings.Groups, &PCB->LayerGroups, &PCB->Data->LayerN);
1986 /* Add silk layers to newly created PCB */
1987 CreateNewPCBPost (PCB, 1);
1988 if (argc > 1)
1989 command_line_pcb = argv[1];
1991 ResetStackAndVisibility ();
1993 if (gui->gui)
1994 InitCrosshair ();
1995 InitHandler ();
1996 InitBuffers ();
1997 SetMode (ARROW_MODE);
1999 if (command_line_pcb)
2001 /* keep filename even if initial load command failed;
2002 * file might not exist
2004 if (LoadPCB (command_line_pcb))
2005 PCB->Filename = strdup (command_line_pcb);
2008 if (Settings.InitialLayerStack
2009 && Settings.InitialLayerStack[0])
2011 LayerStringToLayerStack (Settings.InitialLayerStack);
2014 /* This must be called before any other atexit functions
2015 * are registered, as it configures an atexit function to
2016 * clean up and free various items of allocated memory,
2017 * and must be the last last atexit function to run.
2019 leaky_init ();
2021 /* Register a function to be called when the program terminates.
2022 * This makes sure that data is saved even if LEX/YACC routines
2023 * abort the program.
2024 * If the OS doesn't have at least one of them,
2025 * the critical sections will be handled by parse_l.l
2027 atexit (EmergencySave);
2029 /* read the library file and display it if it's not empty
2031 if (!ReadLibraryContents () && Library.MenuN)
2032 hid_action ("LibraryChanged");
2034 #ifdef HAVE_LIBSTROKE
2035 stroke_init ();
2036 #endif
2038 if (Settings.ScriptFilename)
2040 Message (_("Executing startup script file %s\n"),
2041 Settings.ScriptFilename);
2042 hid_actionl ("ExecuteFile", Settings.ScriptFilename, NULL);
2044 if (Settings.ActionString)
2046 Message (_("Executing startup action %s\n"), Settings.ActionString);
2047 hid_parse_actions (Settings.ActionString);
2050 if (gui->printer || gui->exporter)
2052 // Workaround to fix batch output for non-C locales
2053 setlocale(LC_NUMERIC,"C");
2054 gui->do_export (0);
2055 exit (0);
2058 #if HAVE_DBUS
2059 pcb_dbus_setup();
2060 #endif
2062 EnableAutosave ();
2064 #ifdef DEBUG
2065 printf ("Settings.LibraryCommandDir = \"%s\"\n",
2066 Settings.LibraryCommandDir);
2067 printf ("Settings.FontPath = \"%s\"\n",
2068 Settings.FontPath);
2069 printf ("Settings.ElementPath = \"%s\"\n",
2070 Settings.ElementPath);
2071 printf ("Settings.LibraryPath = \"%s\"\n",
2072 Settings.LibraryPath);
2073 printf ("Settings.LibraryTree = \"%s\"\n",
2074 Settings.LibraryTree);
2075 printf ("Settings.MakeProgram = \"%s\"\n",
2076 UNKNOWN (Settings.MakeProgram));
2077 printf ("Settings.GnetlistProgram = \"%s\"\n",
2078 UNKNOWN (Settings.GnetlistProgram));
2079 #endif
2081 gui->do_export (0);
2082 #if HAVE_DBUS
2083 pcb_dbus_finish();
2084 #endif
2086 return (0);