Collapse giant default increment table into only two
[geda-pcb/whiteaudio.git] / src / main.c
blob62e44195a06d9df647f38cc95b72b30597f816f3
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.gpleda.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;
430 HID_Attribute main_attribute_list[] = {
432 /* %start-doc options "1 General Options"
433 @ftable @code
434 @item --help
435 Show help on command line options.
436 @end ftable
437 %end-doc
439 {"help", "Show help on command line options", HID_Boolean, 0, 0, {0, 0, 0}, 0,
440 &show_help},
442 /* %start-doc options "1 General Options"
443 @ftable @code
444 @item --version
445 Show version.
446 @end ftable
447 %end-doc
449 {"version", "Show version", HID_Boolean, 0, 0, {0, 0, 0}, 0, &show_version},
451 /* %start-doc options "1 General Options"
452 @ftable @code
453 @item --verbose
454 Be verbose on stdout.
455 @end ftable
456 %end-doc
458 {"verbose", "Be verbose on stdout", HID_Boolean, 0, 0, {0, 0, 0}, 0,
459 &Settings.verbose},
461 /* %start-doc options "1 General Options"
462 @ftable @code
463 @item --copyright
464 Show copyright.
465 @end ftable
466 %end-doc
468 {"copyright", "Show Copyright", HID_Boolean, 0, 0, {0, 0, 0}, 0,
469 &show_copyright},
471 /* %start-doc options "1 General Options"
472 @ftable @code
473 @item --show-defaults
474 Show option defaults.
475 @end ftable
476 %end-doc
478 {"show-defaults", "Show option defaults", HID_Boolean, 0, 0, {0, 0, 0}, 0,
479 &show_defaults},
481 /* %start-doc options "1 General Options"
482 @ftable @code
483 @item --show-actions
484 Show available actions and exit.
485 @end ftable
486 %end-doc
488 {"show-actions", "Show available actions", HID_Boolean, 0, 0, {0, 0, 0}, 0,
489 &show_actions},
491 /* %start-doc options "1 General Options"
492 @ftable @code
493 @item --dump-actions
494 Dump actions (for documentation).
495 @end ftable
496 %end-doc
498 {"dump-actions", "Dump actions (for documentation)", HID_Boolean, 0, 0,
499 {0, 0, 0}, 0, &do_dump_actions},
501 /* %start-doc options "1 General Options"
502 @ftable @code
503 @item --grid-units-mm <string>
504 Set default grid units. Can be mm or mil. Defaults to mil.
505 @end ftable
506 %end-doc
508 {"grid-units", "Default grid units (mm|mil)", HID_String, 0, 0, {0, "mil", 0},
509 0, &grid_units},
511 /* %start-doc options "3 Colors"
512 @ftable @code
513 @item --black-color <string>
514 Color value for black. Default: @samp{#000000}
515 @end ftable
516 %end-doc
518 COLOR (BlackColor, "#000000", "black-color", "color value of 'black'"),
520 /* %start-doc options "3 Colors"
521 @ftable @code
522 @item --black-color <string>
523 Color value for white. Default: @samp{#ffffff}
524 @end ftable
525 %end-doc
527 COLOR (WhiteColor, "#ffffff", "white-color", "color value of 'white'"),
529 /* %start-doc options "3 Colors"
530 @ftable @code
531 @item --background-color <string>
532 Background color of the canvas. Default: @samp{#e5e5e5}
533 @end ftable
534 %end-doc
536 COLOR (BackgroundColor, "#e5e5e5", "background-color",
537 "color for background"),
539 /* %start-doc options "3 Colors"
540 @ftable @code
541 @item --crosshair-color <string>
542 Color of the crosshair. Default: @samp{#ff0000}
543 @end ftable
544 %end-doc
546 COLOR (CrosshairColor, "#ff0000", "crosshair-color",
547 "color for the crosshair"),
549 /* %start-doc options "3 Colors"
550 @ftable @code
551 @item --cross-color <string>
552 Color of the cross. Default: @samp{#cdcd00}
553 @end ftable
554 %end-doc
556 COLOR (CrossColor, "#cdcd00", "cross-color", "color of the cross"),
558 /* %start-doc options "3 Colors"
559 @ftable @code
560 @item --via-color <string>
561 Color of vias. Default: @samp{#7f7f7f}
562 @end ftable
563 %end-doc
565 COLOR (ViaColor, "#7f7f7f", "via-color", "color of vias"),
567 /* %start-doc options "3 Colors"
568 @ftable @code
569 @item --via-selected-color <string>
570 Color of selected vias. Default: @samp{#00ffff}
571 @end ftable
572 %end-doc
574 COLOR (ViaSelectedColor, "#00ffff", "via-selected-color",
575 "color for selected vias"),
577 /* %start-doc options "3 Colors"
578 @ftable @code
579 @item --pin-color <string>
580 Color of pins. Default: @samp{#4d4d4d}
581 @end ftable
582 %end-doc
584 COLOR (PinColor, "#4d4d4d", "pin-color", "color of pins"),
586 /* %start-doc options "3 Colors"
587 @ftable @code
588 @item --pin-selected-color <string>
589 Color of selected pins. Default: @samp{#00ffff}
590 @end ftable
591 %end-doc
593 COLOR (PinSelectedColor, "#00ffff", "pin-selected-color",
594 "color of selected pins"),
596 /* %start-doc options "3 Colors"
597 @ftable @code
598 @item --pin-name-color <string>
599 Color of pin names and pin numbers. Default: @samp{#ff0000}
600 @end ftable
601 %end-doc
603 COLOR (PinNameColor, "#ff0000", "pin-name-color",
604 "color for pin names and pin numbers"),
606 /* %start-doc options "3 Colors"
607 @ftable @code
608 @item --element-color <string>
609 Color of components. Default: @samp{#000000}
610 @end ftable
611 %end-doc
613 COLOR (ElementColor, "#000000", "element-color", "color of components"),
615 /* %start-doc options "3 Colors"
616 @ftable @code
617 @item --rat-color <string>
618 Color of ratlines. Default: @samp{#b8860b}
619 @end ftable
620 %end-doc
622 COLOR (RatColor, "#b8860b", "rat-color", "color of ratlines"),
624 /* %start-doc options "3 Colors"
625 @ftable @code
626 @item --invisible-objects-color <string>
627 Color of invisible objects. Default: @samp{#cccccc}
628 @end ftable
629 %end-doc
631 COLOR (InvisibleObjectsColor, "#cccccc", "invisible-objects-color",
632 "color of invisible objects"),
634 /* %start-doc options "3 Colors"
635 @ftable @code
636 @item --invisible-mark-color <string>
637 Color of invisible marks. Default: @samp{#cccccc}
638 @end ftable
639 %end-doc
641 COLOR (InvisibleMarkColor, "#cccccc", "invisible-mark-color",
642 "color of invisible marks"),
644 /* %start-doc options "3 Colors"
645 @ftable @code
646 @item --element-selected-color <string>
647 Color of selected components. Default: @samp{#00ffff}
648 @end ftable
649 %end-doc
651 COLOR (ElementSelectedColor, "#00ffff", "element-selected-color",
652 "color of selected components"),
654 /* %start-doc options "3 Colors"
655 @ftable @code
656 @item --rat-selected-color <string>
657 Color of selected rats. Default: @samp{#00ffff}
658 @end ftable
659 %end-doc
661 COLOR (RatSelectedColor, "#00ffff", "rat-selected-color",
662 "color of selected rats"),
664 /* %start-doc options "3 Colors"
665 @ftable @code
666 @item --connected-color <string>
667 Color to indicate connections. Default: @samp{#00ff00}
668 @end ftable
669 %end-doc
671 COLOR (ConnectedColor, "#00ff00", "connected-color",
672 "color to indicate connections"),
674 /* %start-doc options "3 Colors"
675 @ftable @code
676 @item --off-limit-color <string>
677 Color of off-canvas area. Default: @samp{#cccccc}
678 @end ftable
679 %end-doc
681 COLOR (OffLimitColor, "#cccccc", "off-limit-color",
682 "color of off-canvas area"),
684 /* %start-doc options "3 Colors"
685 @ftable @code
686 @item --grid-color <string>
687 Color of the grid. Default: @samp{#ff0000}
688 @end ftable
689 %end-doc
691 COLOR (GridColor, "#ff0000", "grid-color", "color of the grid"),
693 /* %start-doc options "3 Colors"
694 @ftable @code
695 @item --layer-color-<n> <string>
696 Color of layer @code{<n>}, where @code{<n>} is an integer from 1 to 16.
697 @end ftable
698 %end-doc
700 LAYERCOLOR (1, "#8b2323"),
701 LAYERCOLOR (2, "#3a5fcd"),
702 LAYERCOLOR (3, "#104e8b"),
703 LAYERCOLOR (4, "#cd3700"),
704 LAYERCOLOR (5, "#548b54"),
705 LAYERCOLOR (6, "#8b7355"),
706 LAYERCOLOR (7, "#00868b"),
707 LAYERCOLOR (8, "#228b22"),
708 LAYERCOLOR (9, "#8b2323"),
709 LAYERCOLOR (10, "#3a5fcd"),
710 LAYERCOLOR (11, "#104e8b"),
711 LAYERCOLOR (12, "#cd3700"),
712 LAYERCOLOR (13, "#548b54"),
713 LAYERCOLOR (14, "#8b7355"),
714 LAYERCOLOR (15, "#00868b"),
715 LAYERCOLOR (16, "#228b22"),
716 /* %start-doc options "3 Colors"
717 @ftable @code
718 @item --layer-selected-color-<n> <string>
719 Color of layer @code{<n>}, when selected. @code{<n>} is an integer from 1 to 16.
720 @end ftable
721 %end-doc
723 LAYERSELCOLOR (1),
724 LAYERSELCOLOR (2),
725 LAYERSELCOLOR (3),
726 LAYERSELCOLOR (4),
727 LAYERSELCOLOR (5),
728 LAYERSELCOLOR (6),
729 LAYERSELCOLOR (7),
730 LAYERSELCOLOR (8),
731 LAYERSELCOLOR (9),
732 LAYERSELCOLOR (10),
733 LAYERSELCOLOR (11),
734 LAYERSELCOLOR (12),
735 LAYERSELCOLOR (13),
736 LAYERSELCOLOR (14),
737 LAYERSELCOLOR (15),
738 LAYERSELCOLOR (16),
740 /* %start-doc options "3 Colors"
741 @ftable @code
742 @item --warn-color <string>
743 Color of offending objects during DRC. Default value is @code{"#ff8000"}
744 @end ftable
745 %end-doc
747 COLOR (WarnColor, "#ff8000", "warn-color", "color of offending objects during DRC"),
749 /* %start-doc options "3 Colors"
750 @ftable @code
751 @item --mask-color <string>
752 Color of the mask layer. Default value is @code{"#ff0000"}
753 @end ftable
754 %end-doc
756 COLOR (MaskColor, "#ff0000", "mask-color", "color for solder mask"),
759 /* %start-doc options "5 Sizes"
760 All parameters should be given with an unit. If no unit is given, 1/100 mil
761 (cmil) will be used. Write units without space to the
762 number like @code{3mm}, not @code{3 mm}.
763 Valid Units are:
764 @table @samp
765 @item km
766 Kilometer
767 @item m
768 Meter
769 @item cm
770 Centimeter
771 @item mm
772 Millimeter
773 @item um
774 Micrometer
775 @item nm
776 Nanometer
777 @item in
778 Inch (1in = 0.0254m)
779 @item mil
780 Mil (1000mil = 1in)
781 @item cmil
782 Centimil (1/100 mil)
783 @end table
785 @ftable @code
786 @item --via-thickness <num>
787 Default diameter of vias. Default value is @code{60mil}.
788 @end ftable
789 %end-doc
791 CSET (ViaThickness, MIL_TO_COORD(60), "via-thickness",
792 "default diameter of vias in 1/100 mil"),
794 /* %start-doc options "5 Sizes"
795 @ftable @code
796 @item --via-drilling-hole <num>
797 Default diameter of holes. Default value is @code{28mil}.
798 @end ftable
799 %end-doc
801 CSET (ViaDrillingHole, MIL_TO_COORD(28), "via-drilling-hole",
802 "default diameter of holes"),
804 /* %start-doc options "5 Sizes"
805 @ftable @code
806 @item --line-thickness <num>
807 Default thickness of new lines. Default value is @code{10mil}.
808 @end ftable
809 %end-doc
811 CSET (LineThickness, MIL_TO_COORD(10), "line-thickness",
812 "initial thickness of new lines"),
814 /* %start-doc options "5 Sizes"
815 @ftable @code
816 @item --rat-thickness <num><unit>
817 Thickness of rats. If no unit is given, PCB units are assumed (i.e. 100
818 means "1 nm"). This option allows for a special unit @code{px} which
819 sets the rat thickness to a fixed value in terms of screen pixels.
820 Maximum fixed thickness is 100px. Minimum saling rat thickness is 101nm.
821 Default value is @code{10mil}.
822 @end ftable
823 %end-doc
825 CSET (RatThickness, MIL_TO_COORD(10), "rat-thickness", "thickness of rat lines"),
827 /* %start-doc options "5 Sizes"
828 @ftable @code
829 @item --keepaway <num>
830 Default minimum distance between a track and adjacent copper.
831 Default value is @code{10mil}.
832 @end ftable
833 %end-doc
835 CSET (Keepaway, MIL_TO_COORD(10), "keepaway", "minimum distance between adjacent copper"),
837 /* %start-doc options "5 Sizes"
838 @ftable @code
839 @item --default-PCB-width <num>
840 Default width of the canvas. Default value is @code{6000mil}.
841 @end ftable
842 %end-doc
844 CSET (MaxWidth, MIL_TO_COORD(6000), "default-PCB-width",
845 "default width of the canvas"),
847 /* %start-doc options "5 Sizes"
848 @ftable @code
849 @item --default-PCB-height <num>
850 Default height of the canvas. Default value is @code{5000mil}.
851 @end ftable
852 %end-doc
854 CSET (MaxHeight, MIL_TO_COORD(5000), "default-PCB-height",
855 "default height of the canvas"),
857 /* %start-doc options "5 Sizes"
858 @ftable @code
859 @item --text-scale <num>
860 Default text scale. This value is in percent. Default value is @code{100}.
861 @end ftable
862 %end-doc
864 ISET (TextScale, 100, "text-scale", "default text scale in percent"),
866 /* %start-doc options "5 Sizes"
867 @ftable @code
868 @item --alignment-distance <num>
869 Specifies the distance between the board outline and alignment targets.
870 Default value is @code{2mil}.
871 @end ftable
872 %end-doc
874 CSET (AlignmentDistance, MIL_TO_COORD(2), "alignment-distance",
875 "distance between the boards outline and alignment targets"),
877 /* %start-doc options "7 DRC Options"
878 All parameters should be given with an unit. If no unit is given, 1/100 mil
879 (cmil) will be used for backward compability. Valid units are given in section
880 @ref{Sizes}.
881 %end-doc
885 /* %start-doc options "7 DRC Options"
886 @ftable @code
887 @item --bloat <num>
888 Minimum spacing. Default value is @code{10mil}.
889 @end ftable
890 %end-doc
892 CSET (Bloat, MIL_TO_COORD(10), "bloat", "DRC minimum spacing in 1/100 mil"),
894 /* %start-doc options "7 DRC Options"
895 @ftable @code
896 @item --shrink <num>
897 Minimum touching overlap. Default value is @code{10mil}.
898 @end ftable
899 %end-doc
901 CSET (Shrink, MIL_TO_COORD(10), "shrink", "DRC minimum overlap in 1/100 mils"),
903 /* %start-doc options "7 DRC Options"
904 @ftable @code
905 @item --min-width <num>
906 Minimum width of copper. Default value is @code{10mil}.
907 @end ftable
908 %end-doc
910 CSET (minWid, MIL_TO_COORD(10), "min-width", "DRC minimum copper spacing"),
912 /* %start-doc options "7 DRC Options"
913 @ftable @code
914 @item --min-silk <num>
915 Minimum width of lines in silk. Default value is @code{10mil}.
916 @end ftable
917 %end-doc
919 CSET (minSlk, MIL_TO_COORD(10), "min-silk", "DRC minimum silk width"),
921 /* %start-doc options "7 DRC Options"
922 @ftable @code
923 @item --min-drill <num>
924 Minimum diameter of holes. Default value is @code{15mil}.
925 @end ftable
926 %end-doc
928 CSET (minDrill, MIL_TO_COORD(15), "min-drill", "DRC minimum drill diameter"),
930 /* %start-doc options "7 DRC Options"
931 @ftable @code
932 @item --min-ring <num>
933 Minimum width of annular ring. Default value is @code{10mil}.
934 @end ftable
935 %end-doc
937 CSET (minRing, MIL_TO_COORD(10), "min-ring", "DRC minimum annular ring"),
940 /* %start-doc options "5 Sizes"
941 @ftable @code
942 @item --grid <num>
943 Initial grid size. Default value is @code{10mil}.
944 @end ftable
945 %end-doc
947 CSET (Grid, MIL_TO_COORD(10), "grid", "Initial grid size in 1/100 mil"),
949 /* %start-doc options "5 Sizes"
950 @ftable @code
951 @item --minimum polygon area <num>
952 Minimum polygon area.
953 @end ftable
954 %end-doc
956 RSET (IsleArea, MIL_TO_COORD(100) * MIL_TO_COORD(100), "minimum polygon area", 0),
959 /* %start-doc options "1 General Options"
960 @ftable @code
961 @item --backup-interval
962 Time between automatic backups in seconds. Set to @code{0} to disable.
963 The default value is @code{60}.
964 @end ftable
965 %end-doc
967 ISET (BackupInterval, 60, "backup-interval",
968 "Time between automatic backups in seconds. Set to 0 to disable"),
970 /* %start-doc options "4 Layer Names"
971 @ftable @code
972 @item --layer-name-1 <string>
973 Name of the 1st Layer. Default is @code{"top"}.
974 @end ftable
975 %end-doc
977 LAYERNAME (1, "top"),
979 /* %start-doc options "4 Layer Names"
980 @ftable @code
981 @item --layer-name-2 <string>
982 Name of the 2nd Layer. Default is @code{"ground"}.
983 @end ftable
984 %end-doc
986 LAYERNAME (2, "ground"),
988 /* %start-doc options "4 Layer Names"
989 @ftable @code
990 @item --layer-name-3 <string>
991 Name of the 3nd Layer. Default is @code{"signal2"}.
992 @end ftable
993 %end-doc
995 LAYERNAME (3, "signal2"),
997 /* %start-doc options "4 Layer Names"
998 @ftable @code
999 @item --layer-name-4 <string>
1000 Name of the 4rd Layer. Default is @code{"signal3"}.
1001 @end ftable
1002 %end-doc
1004 LAYERNAME (4, "signal3"),
1006 /* %start-doc options "4 Layer Names"
1007 @ftable @code
1008 @item --layer-name-5 <string>
1009 Name of the 5rd Layer. Default is @code{"power"}.
1010 @end ftable
1011 %end-doc
1013 LAYERNAME (5, "power"),
1015 /* %start-doc options "4 Layer Names"
1016 @ftable @code
1017 @item --layer-name-6 <string>
1018 Name of the 6rd Layer. Default is @code{"bottom"}.
1019 @end ftable
1020 %end-doc
1022 LAYERNAME (6, "bottom"),
1024 /* %start-doc options "4 Layer Names"
1025 @ftable @code
1026 @item --layer-name-7 <string>
1027 Name of the 7rd Layer. Default is @code{"outline"}.
1028 @end ftable
1029 %end-doc
1031 LAYERNAME (7, "outline"),
1033 /* %start-doc options "4 Layer Names"
1034 @ftable @code
1035 @item --layer-name-8 <string>
1036 Name of the 8rd Layer. Default is @code{"spare"}.
1037 @end ftable
1038 %end-doc
1040 LAYERNAME (8, "spare"),
1042 /* %start-doc options "1 General Options"
1043 @ftable @code
1044 @item --groups <string>
1045 Layer group string. Defaults to @code{"1,c:2:3:4:5:6,s:7:8"}.
1046 @end ftable
1047 %end-doc
1049 SSET (Groups, "1,c:2:3:4:5:6,s:7:8", "groups", "Layer group string"),
1052 /* %start-doc options "6 Commands"
1053 pcb uses external commands for input output operations. These commands can be
1054 configured at start-up to meet local requirements. The command string may include
1055 special sequences @code{%f}, @code{%p} or @code{%a}. These are replaced when the
1056 command is called. The sequence @code{%f} is replaced by the file name,
1057 @code{%p} gets the path and @code{%a} indicates a package name.
1058 %end-doc
1061 /* %start-doc options "6 Commands"
1062 @ftable @code
1063 @item --font-command <string>
1064 Command to load a font.
1065 @end ftable
1066 %end-doc
1068 SSET (FontCommand, "", "font-command", "Command to load a font"),
1070 /* %start-doc options "6 Commands"
1071 @ftable @code
1072 @item --file-command <string>
1073 Command to read a file.
1074 @end ftable
1075 %end-doc
1077 SSET (FileCommand, "", "file-command", "Command to read a file"),
1079 /* %start-doc options "6 Commands"
1080 @ftable @code
1081 @item --element-command <string>
1082 Command to read a footprint. @*
1083 Defaults to @code{"M4PATH='%p';export M4PATH;echo 'include(%f)' | m4"}
1084 @end ftable
1085 %end-doc
1087 SSET (ElementCommand,
1088 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4,
1089 "element-command", "Command to read a footprint"),
1091 /* %start-doc options "6 Commands"
1092 @ftable @code
1093 @item --print-file <string>
1094 Command to print to a file.
1095 @end ftable
1096 %end-doc
1098 SSET (PrintFile, "%f.output", "print-file", "Command to print to a file"),
1100 /* %start-doc options "6 Commands"
1101 @ftable @code
1102 @item --lib-command-dir <string>
1103 Path to the command that queries the library.
1104 @end ftable
1105 %end-doc
1107 SSET (LibraryCommandDir, PCBLIBDIR, "lib-command-dir",
1108 "Path to the command that queries the library"),
1110 /* %start-doc options "6 Commands"
1111 @ftable @code
1112 @item --lib-command <string>
1113 Command to query the library. @*
1114 Defaults to @code{"QueryLibrary.sh '%p' '%f' %a"}
1115 @end ftable
1116 %end-doc
1118 SSET (LibraryCommand, "QueryLibrary.sh '%p' '%f' %a",
1119 "lib-command", "Command to query the library"),
1121 /* %start-doc options "6 Commands"
1122 @ftable @code
1123 @item --lib-contents-command <string>
1124 Command to query the contents of the library. @*
1125 Defaults to @code{"ListLibraryContents.sh %p %f"} or,
1126 on Windows builds, an empty string (to disable this feature).
1127 @end ftable
1128 %end-doc
1130 SSET (LibraryContentsCommand,
1131 #ifdef __WIN32__
1133 #else
1134 "ListLibraryContents.sh '%p' '%f'",
1135 #endif
1136 "lib-contents-command", "Command to query the contents of the library"),
1138 /* %start-doc options "5 Paths"
1139 @ftable @code
1140 @item --lib-newlib <string>
1141 Top level directory for the newlib style library.
1142 @end ftable
1143 %end-doc
1145 SSET (LibraryTree, PCBTREEPATH, "lib-newlib",
1146 "Top level directory for the newlib style library"),
1148 /* %start-doc options "6 Commands"
1149 @ftable @code
1150 @item --save-command <string>
1151 Command to save to a file.
1152 @end ftable
1153 %end-doc
1155 SSET (SaveCommand, "", "save-command", "Command to save to a file"),
1157 /* %start-doc options "5 Paths"
1158 @ftable @code
1159 @item --lib-name <string>
1160 The default filename for the library.
1161 @end ftable
1162 %end-doc
1164 SSET (LibraryFilename, LIBRARYFILENAME, "lib-name",
1165 "The default filename for the library"),
1167 /* %start-doc options "5 Paths"
1168 @ftable @code
1169 @item --default-font <string>
1170 The name of the default font.
1171 @end ftable
1172 %end-doc
1174 SSET (FontFile, "default_font", "default-font",
1175 "File name of default font"),
1177 /* %start-doc options "1 General Options"
1178 @ftable @code
1179 @item --route-styles <string>
1180 A string that defines the route styles. Defaults to @*
1181 @code{"Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000
1182 :Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"}
1183 @end ftable
1184 %end-doc
1186 SSET (Routes, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
1187 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
1188 "A string that defines the route styles"),
1190 /* %start-doc options "5 Paths"
1191 @ftable @code
1192 @item --file-path <string>
1193 A colon separated list of directories or commands (starts with '|'). The path
1194 is passed to the program specified in @option{--file-command} together with the selected
1195 filename.
1196 @end ftable
1197 %end-doc
1199 SSET (FilePath, "", "file-path", 0),
1201 /* %start-doc options "6 Commands"
1202 @ftable @code
1203 @item --rat-command <string>
1204 Command for reading a netlist. Sequence @code{%f} is replaced by the netlist filename.
1205 @end ftable
1206 %end-doc
1208 SSET (RatCommand, "", "rat-command", "Command for reading a netlist"),
1210 /* %start-doc options "5 Paths"
1211 @ftable @code
1212 @item --font-path <string>
1213 A colon separated list of directories to search the default font. Defaults to
1214 the default library path.
1215 @end ftable
1216 %end-doc
1218 SSET (FontPath, PCBLIBPATH, "font-path",
1219 "Colon separated list of directories to search the default font"),
1221 /* %start-doc options "1 General Options"
1222 @ftable @code
1223 @item --element-path <string>
1224 A colon separated list of directories or commands (starts with '|').
1225 The path is passed to the program specified in @option{--element-command}.
1226 @end ftable
1227 %end-doc
1229 SSET(ElementPath, PCBLIBPATH, "element-path",
1230 "A colon separated list of directories or commands (starts with '|')"),
1232 /* %start-doc options "5 Paths"
1233 @ftable @code
1234 @item --lib-path <string>
1235 A colon separated list of directories that will be passed to the commands specified
1236 by @option{--element-command} and @option{--element-contents-command}.
1237 @end ftable
1238 %end-doc
1240 SSET (LibraryPath, PCBLIBPATH, "lib-path",
1241 "A colon separated list of directories"),
1243 /* %start-doc options "1 General Options"
1244 @ftable @code
1245 @item --action-script <string>
1246 If set, this file is executed at startup.
1247 @end ftable
1248 %end-doc
1250 SSET (ScriptFilename, 0, "action-script",
1251 "If set, this file is executed at startup"),
1253 /* %start-doc options "1 General Options"
1254 @ftable @code
1255 @item --action-string <string>
1256 If set, this string of actions is executed at startup.
1257 @end ftable
1258 %end-doc
1260 SSET (ActionString, 0, "action-string",
1261 "If set, this is executed at startup"),
1263 /* %start-doc options "1 General Options"
1264 @ftable @code
1265 @item --fab-author <string>
1266 Name of author to be put in the Gerber files.
1267 @end ftable
1268 %end-doc
1270 SSET (FabAuthor, "", "fab-author",
1271 "Name of author to be put in the Gerber files"),
1273 /* %start-doc options "1 General Options"
1274 @ftable @code
1275 @item --layer-stack <string>
1276 Initial layer stackup, for setting up an export. A comma separated list of layer
1277 names, layer numbers and layer groups.
1278 @end ftable
1279 %end-doc
1281 SSET (InitialLayerStack, "", "layer-stack",
1282 "Initial layer stackup, for setting up an export."),
1284 SSET (MakeProgram, NULL, "make-program",
1285 "Sets the name and optionally full path to a make(3) program"),
1286 SSET (GnetlistProgram, NULL, "gnetlist",
1287 "Sets the name and optionally full path to the gnetlist(3) program"),
1289 /* %start-doc options "2 General GUI Options"
1290 @ftable @code
1291 @item --pinout-offset-x <num>
1292 Horizontal offset of the pin number display. Defaults to @code{100mil}.
1293 @end ftable
1294 %end-doc
1296 CSET (PinoutOffsetX, MIL_TO_COORD(1), "pinout-offset-x",
1297 "Horizontal offset of the pin number display in mil"),
1299 /* %start-doc options "2 General GUI Options"
1300 @ftable @code
1301 @item --pinout-offset-y <num>
1302 Vertical offset of the pin number display. Defaults to @code{100mil}.
1303 @end ftable
1304 %end-doc
1306 CSET (PinoutOffsetY, MIL_TO_COORD(1), "pinout-offset-y",
1307 "Vertical offset of the pin number display in mil"),
1309 /* %start-doc options "2 General GUI Options"
1310 @ftable @code
1311 @item --pinout-text-offset-x <num>
1312 Horizontal offset of the pin name display. Defaults to @code{800mil}.
1313 @end ftable
1314 %end-doc
1316 CSET (PinoutTextOffsetX, MIL_TO_COORD(8), "pinout-text-offset-x",
1317 "Horizontal offset of the pin name display in mil"),
1319 /* %start-doc options "2 General GUI Options"
1320 @ftable @code
1321 @item --pinout-text-offset-y <num>
1322 Vertical offset of the pin name display. Defaults to @code{-100mil}.
1323 @end ftable
1324 %end-doc
1326 CSET (PinoutTextOffsetY, MIL_TO_COORD(-1), "pinout-text-offset-y",
1327 "Vertical offset of the pin name display in mil"),
1329 /* %start-doc options "2 General GUI Options"
1330 @ftable @code
1331 @item --draw-grid
1332 If set, draw the grid at start-up.
1333 @end ftable
1334 %end-doc
1336 BSET (DrawGrid, 0, "draw-grid", "If set, draw the grid at start-up"),
1338 /* %start-doc options "2 General GUI Options"
1339 @ftable @code
1340 @item --clear-line
1341 If set, new lines clear polygons.
1342 @end ftable
1343 %end-doc
1345 BSET (ClearLine, 1, "clear-line", "If set, new lines clear polygons"),
1347 /* %start-doc options "2 General GUI Options"
1348 @ftable @code
1349 @item --full-poly
1350 If set, new polygons are full ones.
1351 @end ftable
1352 %end-doc
1354 BSET (FullPoly, 0, "full-poly", 0),
1356 /* %start-doc options "2 General GUI Options"
1357 @ftable @code
1358 @item --unique-names
1359 If set, you will not be permitted to change the name of an component to match that
1360 of another component.
1361 @end ftable
1362 %end-doc
1364 BSET (UniqueNames, 1, "unique-names", "Prevents identical component names"),
1366 /* %start-doc options "2 General GUI Options"
1367 @ftable @code
1368 @item --snap-pin
1369 If set, pin centers and pad end points are treated as additional grid points
1370 that the cursor can snap to.
1371 @end ftable
1372 %end-doc
1374 BSET (SnapPin, 1, "snap-pin",
1375 "If set, the cursor snaps to pads and pin centers"),
1377 /* %start-doc options "1 General Options"
1378 @ftable @code
1379 @item --save-last-command
1380 If set, the last user command is saved.
1381 @end ftable
1382 %end-doc
1384 BSET (SaveLastCommand, 0, "save-last-command", 0),
1386 /* %start-doc options "1 General Options"
1387 @ftable @code
1388 @item --save-in-tmp
1389 If set, all data which would otherwise be lost are saved in a temporary file
1390 @file{/tmp/PCB.%i.save} . Sequence @samp{%i} is replaced by the process ID.
1391 @end ftable
1392 %end-doc
1394 BSET (SaveInTMP, 0, "save-in-tmp",
1395 "When set, all data which would otherwise be lost are saved in /tmp"),
1397 /* %start-doc options "2 General GUI Options"
1398 @ftable @code
1399 @item --all-direction-lines
1400 Allow all directions, when drawing new lines.
1401 @end ftable
1402 %end-doc
1404 BSET (AllDirectionLines, 0, "all-direction-lines",
1405 "Allow all directions, when drawing new lines"),
1407 /* %start-doc options "2 General GUI Options"
1408 @ftable @code
1409 @item --show-number
1410 Pinout shows number.
1411 @end ftable
1412 %end-doc
1414 BSET (ShowNumber, 0, "show-number", "Pinout shows number"),
1416 /* %start-doc options "1 General Options"
1417 @ftable @code
1418 @item --reset-after-element
1419 If set, all found connections are reset before a new component is scanned.
1420 @end ftable
1421 %end-doc
1423 BSET (ResetAfterElement, 1, "reset-after-element",
1424 "If set, all found connections are reset before a new component is scanned"),
1426 /* %start-doc options "1 General Options"
1427 @ftable @code
1428 @item --ring-bell-finished
1429 Execute the bell command when all rats are routed.
1430 @end ftable
1431 %end-doc
1433 BSET (RingBellWhenFinished, 0, "ring-bell-finished",
1434 "Execute the bell command when all rats are routed"),
1437 REGISTER_ATTRIBUTES (main_attribute_list)
1438 /* ----------------------------------------------------------------------
1439 * post-process settings.
1441 static void settings_post_process ()
1443 char *tmps;
1445 if (Settings.LibraryCommand != NULL &&
1446 Settings.LibraryCommand[0] != '\0' &&
1447 Settings.LibraryCommand[0] != PCB_DIR_SEPARATOR_C &&
1448 Settings.LibraryCommand[0] != '.')
1450 Settings.LibraryCommand
1452 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1453 Settings.LibraryCommand,
1454 NULL);
1456 if (Settings.LibraryContentsCommand != NULL &&
1457 Settings.LibraryContentsCommand[0] != '\0' &&
1458 Settings.LibraryContentsCommand[0] != PCB_DIR_SEPARATOR_C &&
1459 Settings.LibraryContentsCommand[0] != '.')
1461 Settings.LibraryContentsCommand
1463 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1464 Settings.LibraryContentsCommand, NULL);
1467 if (Settings.LineThickness > MAX_LINESIZE
1468 || Settings.LineThickness < MIN_LINESIZE)
1469 Settings.LineThickness = MIL_TO_COORD(10);
1471 if (Settings.ViaThickness > MAX_PINORVIASIZE
1472 || Settings.ViaThickness < MIN_PINORVIASIZE)
1473 Settings.ViaThickness = MIL_TO_COORD(40);
1475 if (Settings.ViaDrillingHole <= 0)
1476 Settings.ViaDrillingHole =
1477 DEFAULT_DRILLINGHOLE * Settings.ViaThickness / 100;
1479 Settings.MaxWidth = CLAMP (Settings.MaxWidth, MIN_SIZE, MAX_COORD);
1480 Settings.MaxHeight = CLAMP (Settings.MaxHeight, MIN_SIZE, MAX_COORD);
1482 ParseRouteString (Settings.Routes, &Settings.RouteStyle[0], "cmil");
1485 * Make sure we have settings for some various programs we may wish
1486 * to call
1488 if (Settings.MakeProgram == NULL) {
1489 tmps = getenv ("PCB_MAKE_PROGRAM");
1490 if (tmps != NULL)
1491 Settings.MakeProgram = strdup (tmps);
1493 if (Settings.MakeProgram == NULL) {
1494 Settings.MakeProgram = strdup ("make");
1497 if (Settings.GnetlistProgram == NULL) {
1498 tmps = getenv ("PCB_GNETLIST");
1499 if (tmps != NULL)
1500 Settings.GnetlistProgram = strdup (tmps);
1502 if (Settings.GnetlistProgram == NULL) {
1503 Settings.GnetlistProgram = strdup ("gnetlist");
1506 if (grid_units)
1507 Settings.grid_unit = get_unit_struct (grid_units);
1508 if (!grid_units || Settings.grid_unit == NULL)
1509 Settings.grid_unit = get_unit_struct ("mil");
1511 Settings.increments = get_increments_struct (Settings.grid_unit->family);
1514 /* ----------------------------------------------------------------------
1515 * Print help or version messages.
1518 static void
1519 print_version ()
1521 printf ("PCB version %s\n", VERSION);
1522 exit (0);
1525 /* ----------------------------------------------------------------------
1526 * Figure out the canonical name of the executed program
1527 * and fix up the defaults for various paths
1529 char *bindir = NULL;
1530 char *exec_prefix = NULL;
1531 char *pcblibdir = NULL;
1532 char *pcblibpath = NULL;
1533 char *pcbtreedir = NULL;
1534 char *pcbtreepath = NULL;
1535 char *homedir = NULL;
1537 static void
1538 InitPaths (char *argv0)
1540 size_t l;
1541 int i;
1542 int haspath;
1543 char *t1, *t2;
1544 int found_bindir = 0;
1546 /* see if argv0 has enough of a path to let lrealpath give the
1547 * real path. This should be the case if you invoke pcb with
1548 * something like /usr/local/bin/pcb or ./pcb or ./foo/pcb
1549 * but if you just use pcb and it exists in your path, you'll
1550 * just get back pcb again.
1553 haspath = 0;
1554 for (i = 0; i < strlen (argv0) ; i++)
1556 if (argv0[i] == PCB_DIR_SEPARATOR_C)
1557 haspath = 1;
1560 #ifdef DEBUG
1561 printf ("InitPaths (%s): haspath = %d\n", argv0, haspath);
1562 #endif
1564 if (haspath)
1566 bindir = strdup (lrealpath (argv0));
1567 found_bindir = 1;
1569 else
1571 char *path, *p, *tmps;
1572 struct stat sb;
1573 int r;
1575 tmps = getenv ("PATH");
1577 if (tmps != NULL)
1579 path = strdup (tmps);
1581 /* search through the font path for a font file */
1582 for (p = strtok (path, PCB_PATH_DELIMETER); p && *p;
1583 p = strtok (NULL, PCB_PATH_DELIMETER))
1585 #ifdef DEBUG
1586 printf ("Looking for %s in %s\n", argv0, p);
1587 #endif
1588 if ( (tmps = (char *)malloc ( (strlen (argv0) + strlen (p) + 2) * sizeof (char))) == NULL )
1590 fprintf (stderr, "InitPaths(): malloc failed\n");
1591 exit (1);
1593 sprintf (tmps, "%s%s%s", p, PCB_DIR_SEPARATOR_S, argv0);
1594 r = stat (tmps, &sb);
1595 if (r == 0)
1597 #ifdef DEBUG
1598 printf ("Found it: \"%s\"\n", tmps);
1599 #endif
1600 bindir = lrealpath (tmps);
1601 found_bindir = 1;
1602 free (tmps);
1603 break;
1605 free (tmps);
1607 free (path);
1611 #ifdef DEBUG
1612 printf ("InitPaths(): bindir = \"%s\"\n", bindir);
1613 #endif
1615 if (found_bindir)
1617 /* strip off the executible name leaving only the path */
1618 t2 = NULL;
1619 t1 = strchr (bindir, PCB_DIR_SEPARATOR_C);
1620 while (t1 != NULL && *t1 != '\0')
1622 t2 = t1;
1623 t1 = strchr (t2 + 1, PCB_DIR_SEPARATOR_C);
1625 if (t2 != NULL)
1626 *t2 = '\0';
1628 #ifdef DEBUG
1629 printf ("After stripping off the executible name, we found\n");
1630 printf ("bindir = \"%s\"\n", bindir);
1631 #endif
1633 else
1635 /* we have failed to find out anything from argv[0] so fall back to the original
1636 * install prefix
1638 bindir = strdup (BINDIR);
1641 /* now find the path to exec_prefix */
1642 l = strlen (bindir) + 1 + strlen (BINDIR_TO_EXECPREFIX) + 1;
1643 if ( (exec_prefix = (char *) malloc (l * sizeof (char) )) == NULL )
1645 fprintf (stderr, "InitPaths(): malloc failed\n");
1646 exit (1);
1648 sprintf (exec_prefix, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1649 BINDIR_TO_EXECPREFIX);
1651 /* now find the path to PCBLIBDIR */
1652 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBLIBDIR) + 1;
1653 if ( (pcblibdir = (char *) malloc (l * sizeof (char) )) == NULL )
1655 fprintf (stderr, "InitPaths(): malloc failed\n");
1656 exit (1);
1658 sprintf (pcblibdir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1659 BINDIR_TO_PCBLIBDIR);
1661 /* and the path to PCBTREEDIR */
1662 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBTREEDIR) + 1;
1663 if ( (pcbtreedir = (char *) malloc (l * sizeof (char) )) == NULL )
1665 fprintf (stderr, "InitPaths(): malloc failed\n");
1666 exit (1);
1668 sprintf (pcbtreedir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1669 BINDIR_TO_PCBTREEDIR);
1671 /* and the search path including PCBLIBDIR */
1672 l = strlen (pcblibdir) + 3;
1673 if ( (pcblibpath = (char *) malloc (l * sizeof (char) )) == NULL )
1675 fprintf (stderr, "InitPaths(): malloc failed\n");
1676 exit (1);
1678 sprintf (pcblibpath, ".%s%s", PCB_PATH_DELIMETER, pcblibdir);
1680 /* and the newlib search path */
1681 l = strlen (pcblibdir) + 1 + strlen (pcbtreedir)
1682 + strlen ("pcblib-newlib") + 2;
1683 if ( (pcbtreepath = (char *) malloc (l * sizeof (char) )) == NULL )
1685 fprintf (stderr, "InitPaths(): malloc failed\n");
1686 exit (1);
1688 sprintf (pcbtreepath, "%s%s%s%spcblib-newlib", pcbtreedir,
1689 PCB_PATH_DELIMETER, pcblibdir,
1690 PCB_DIR_SEPARATOR_S);
1692 #ifdef DEBUG
1693 printf ("bindir = %s\n", bindir);
1694 printf ("pcblibdir = %s\n", pcblibdir);
1695 printf ("pcblibpath = %s\n", pcblibpath);
1696 printf ("pcbtreedir = %s\n", pcbtreedir);
1697 printf ("pcbtreepath = %s\n", pcbtreepath);
1698 #endif
1700 l = sizeof (main_attribute_list) / sizeof (main_attribute_list[0]);
1701 for (i = 0; i < l ; i++)
1703 if (NSTRCMP (main_attribute_list[i].name, "lib-command-dir") == 0)
1705 main_attribute_list[i].default_val.str_value = pcblibdir;
1708 if ( (NSTRCMP (main_attribute_list[i].name, "font-path") == 0)
1709 || (NSTRCMP (main_attribute_list[i].name, "element-path") == 0)
1710 || (NSTRCMP (main_attribute_list[i].name, "lib-path") == 0) )
1712 main_attribute_list[i].default_val.str_value = pcblibpath;
1715 if (NSTRCMP (main_attribute_list[i].name, "lib-newlib") == 0)
1717 main_attribute_list[i].default_val.str_value = pcbtreepath;
1723 char *tmps;
1725 tmps = getenv ("HOME");
1727 if (tmps == NULL) {
1728 tmps = getenv ("USERPROFILE");
1731 if (tmps != NULL) {
1732 homedir = strdup (tmps);
1733 } else {
1734 homedir = NULL;
1740 /* ----------------------------------------------------------------------
1741 * main program
1744 char *program_name = 0;
1745 char *program_basename = 0;
1746 char *program_directory = 0;
1748 #include "dolists.h"
1751 main (int argc, char *argv[])
1753 int i;
1755 /* init application:
1756 * - make program name available for error handlers
1757 * - evaluate special options
1758 * - initialize toplevel shell and resources
1759 * - create an empty PCB with default symbols
1760 * - initialize all other widgets
1761 * - update screen and get size of drawing area
1762 * - evaluate command-line arguments
1763 * - register 'call on exit()' function
1766 #include "core_lists.h"
1767 setbuf (stdout, 0);
1768 InitPaths (argv[0]);
1770 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1771 textdomain(GETTEXT_PACKAGE);
1772 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
1773 setlocale(LC_ALL,"");
1775 srand ( time(NULL) ); /* Set seed for rand() */
1777 initialize_units();
1778 polygon_init ();
1779 hid_init ();
1781 hid_load_settings ();
1783 program_name = argv[0];
1784 program_basename = strrchr (program_name, PCB_DIR_SEPARATOR_C);
1785 if (program_basename)
1787 program_directory = strdup (program_name);
1788 *strrchr (program_directory, PCB_DIR_SEPARATOR_C) = 0;
1789 program_basename++;
1791 else
1793 program_directory = ".";
1794 program_basename = program_name;
1796 Progname = program_basename;
1798 /* Print usage or version if requested. Then exit. */
1799 if (argc > 1 &&
1800 (strcmp (argv[1], "-h") == 0 ||
1801 strcmp (argv[1], "-?") == 0 ||
1802 strcmp (argv[1], "--help") == 0))
1803 usage ();
1804 if (argc > 1 && strcmp (argv[1], "-V") == 0)
1805 print_version ();
1806 /* Export pcb from command line if requested. */
1807 if (argc > 1 && strcmp (argv[1], "-p") == 0)
1809 exporter = gui = hid_find_printer ();
1810 argc--;
1811 argv++;
1813 else if (argc > 2 && strcmp (argv[1], "-x") == 0)
1815 exporter = gui = hid_find_exporter (argv[2]);
1816 argc -= 2;
1817 argv += 2;
1819 /* Otherwise start GUI. */
1820 else
1821 gui = hid_find_gui ();
1823 /* Exit with error if GUI failed to start. */
1824 if (!gui)
1825 exit (1);
1827 /* Set up layers. */
1828 for (i = 0; i < MAX_LAYER; i++)
1830 char buf[20];
1831 sprintf (buf, "signal%d", i + 1);
1832 Settings.DefaultLayerName[i] = strdup (buf);
1833 Settings.LayerColor[i] = "#c49350";
1834 Settings.LayerSelectedColor[i] = "#00ffff";
1837 gui->parse_arguments (&argc, &argv);
1839 if (show_help || (argc > 1 && argv[1][0] == '-'))
1840 usage ();
1841 if (show_version)
1842 print_version ();
1843 if (show_defaults)
1844 print_defaults ();
1845 if (show_copyright)
1846 copyright ();
1848 settings_post_process ();
1851 if (show_actions)
1853 print_actions ();
1854 exit (0);
1857 if (do_dump_actions)
1859 extern void dump_actions (void);
1860 dump_actions ();
1861 exit (0);
1864 /* Create a new PCB object in memory */
1865 PCB = CreateNewPCB (true);
1866 PCB->Data->LayerN = DEF_LAYER;
1867 ParseGroupString (Settings.Groups, &PCB->LayerGroups, DEF_LAYER);
1868 /* Add silk layers to newly created PCB */
1869 CreateNewPCBPost (PCB, 1);
1870 if (argc > 1)
1871 command_line_pcb = argv[1];
1873 ResetStackAndVisibility ();
1875 if (gui->gui)
1876 InitCrosshair ();
1877 InitHandler ();
1878 InitBuffers ();
1879 SetMode (ARROW_MODE);
1881 if (command_line_pcb)
1883 /* keep filename even if initial load command failed;
1884 * file might not exist
1886 if (LoadPCB (command_line_pcb))
1887 PCB->Filename = strdup (command_line_pcb);
1890 if (Settings.InitialLayerStack
1891 && Settings.InitialLayerStack[0])
1893 LayerStringToLayerStack (Settings.InitialLayerStack);
1896 /* This must be called before any other atexit functions
1897 * are registered, as it configures an atexit function to
1898 * clean up and free various items of allocated memory,
1899 * and must be the last last atexit function to run.
1901 leaky_init ();
1903 /* Register a function to be called when the program terminates.
1904 * This makes sure that data is saved even if LEX/YACC routines
1905 * abort the program.
1906 * If the OS doesn't have at least one of them,
1907 * the critical sections will be handled by parse_l.l
1909 atexit (EmergencySave);
1911 /* read the library file and display it if it's not empty
1913 if (!ReadLibraryContents () && Library.MenuN)
1914 hid_action ("LibraryChanged");
1916 #ifdef HAVE_LIBSTROKE
1917 stroke_init ();
1918 #endif
1920 if (Settings.ScriptFilename)
1922 Message (_("Executing startup script file %s\n"),
1923 Settings.ScriptFilename);
1924 hid_actionl ("ExecuteFile", Settings.ScriptFilename, NULL);
1926 if (Settings.ActionString)
1928 Message (_("Executing startup action %s\n"), Settings.ActionString);
1929 hid_parse_actions (Settings.ActionString);
1932 if (gui->printer || gui->exporter)
1934 // Workaround to fix batch output for non-C locales
1935 setlocale(LC_NUMERIC,"C");
1936 gui->do_export (0);
1937 exit (0);
1940 #if HAVE_DBUS
1941 pcb_dbus_setup();
1942 #endif
1944 EnableAutosave ();
1946 #ifdef DEBUG
1947 printf ("Settings.LibraryCommandDir = \"%s\"\n",
1948 Settings.LibraryCommandDir);
1949 printf ("Settings.FontPath = \"%s\"\n",
1950 Settings.FontPath);
1951 printf ("Settings.ElementPath = \"%s\"\n",
1952 Settings.ElementPath);
1953 printf ("Settings.LibraryPath = \"%s\"\n",
1954 Settings.LibraryPath);
1955 printf ("Settings.LibraryTree = \"%s\"\n",
1956 Settings.LibraryTree);
1957 printf ("Settings.MakeProgram = \"%s\"\n",
1958 UNKNOWN (Settings.MakeProgram));
1959 printf ("Settings.GnetlistProgram = \"%s\"\n",
1960 UNKNOWN (Settings.GnetlistProgram));
1961 #endif
1963 gui->do_export (0);
1964 #if HAVE_DBUS
1965 pcb_dbus_finish();
1966 #endif
1968 return (0);