strflags should free buf() at the end.
[geda-pcb/pcjc2.git] / src / main.c
blob9c558a660b42046bd770092fbe650f987bc3deea
1 /*!
2 * \file src/main.c
4 * \brief Main program, initializes some stuff and handles user input.
6 * <hr>
8 * <h1><b>Copyright.</b></h1>\n
10 * PCB, interactive printed circuit board design
12 * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Contact addresses for paper mail and Email:
29 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
30 * Thomas.Nau@rz.uni-ulm.de
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <stdlib.h>
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #endif
42 #include <signal.h>
43 #include <unistd.h>
44 #include <sys/stat.h>
45 #include <time.h> /* Seed for srand() */
47 #include "global.h"
48 #include "data.h"
49 #include "buffer.h"
50 #include "create.h"
51 #include "crosshair.h"
52 #include "draw.h"
53 #include "error.h"
54 #include "file.h"
55 #include "set.h"
56 #include "action.h"
57 #include "misc.h"
58 #include "lrealpath.h"
59 #include "free_atexit.h"
60 #include "polygon.h"
61 #include "gettext.h"
62 #include "pcb-printf.h"
63 #include "strflags.h"
65 #include "hid/common/actions.h"
67 /* This next one is so we can print the help messages. */
68 #include "hid/hidint.h"
70 #ifdef HAVE_DBUS
71 #include "dbus.h"
72 #endif
74 #ifdef HAVE_LIBDMALLOC
75 #include <dmalloc.h>
76 #endif
78 #define PCBLIBPATH ".:" PCBLIBDIR
81 #ifdef HAVE_LIBSTROKE
82 extern void stroke_init (void);
83 #endif
86 /*!
87 * \brief Initialize signal and error handlers.
89 static void
90 InitHandler (void)
93 signal(SIGHUP, CatchSignal);
94 signal(SIGQUIT, CatchSignal);
95 signal(SIGABRT, CatchSignal);
96 signal(SIGSEGV, CatchSignal);
97 signal(SIGTERM, CatchSignal);
98 signal(SIGINT, CatchSignal);
101 /* calling external program by popen() may cause a PIPE signal,
102 * so we ignore it
104 #ifdef SIGPIPE
105 signal (SIGPIPE, SIG_IGN);
106 #endif
110 /* ----------------------------------------------------------------------
111 | command line and rc file processing.
113 static char *command_line_pcb;
116 * \brief Print the copyright notice.
118 void
119 copyright (void)
121 printf ("\n"
122 " COPYRIGHT for %s version %s\n\n"
123 " PCB, interactive printed circuit board design\n"
124 " Copyright (C) 1994,1995,1996,1997 Thomas Nau\n"
125 " Copyright (C) 1998, 1999, 2000 Harry Eaton\n\n"
126 " This program is free software; you can redistribute it and/or modify\n"
127 " it under the terms of the GNU General Public License as published by\n"
128 " the Free Software Foundation; either version 2 of the License, or\n"
129 " (at your option) any later version.\n\n"
130 " This program is distributed in the hope that it will be useful,\n"
131 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
132 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
133 " GNU General Public License for more details.\n\n"
134 " You should have received a copy of the GNU General Public License\n"
135 " along with this program; if not, write to the Free Software\n"
136 " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
137 Progname, VERSION);
138 exit (0);
141 static inline void
142 u (const char *fmt, ...)
144 va_list ap;
145 va_start (ap, fmt);
146 vfprintf (stderr, fmt, ap);
147 fputc ('\n', stderr);
148 va_end (ap);
151 typedef struct UsageNotes {
152 struct UsageNotes *next;
153 HID_Attribute *seen;
154 } UsageNotes;
156 static UsageNotes *usage_notes = NULL;
158 static void
159 usage_attr (HID_Attribute * a)
161 int i, n;
162 const Unit *unit_list;
163 static char buf[200];
165 if (a->help_text == ATTR_UNDOCUMENTED)
166 return;
168 switch (a->type)
170 case HID_Label:
171 return;
172 case HID_Integer:
173 case HID_Real:
174 sprintf (buf, "--%s <num>", a->name);
175 break;
176 case HID_Coord:
177 sprintf (buf, "--%s <measure>", a->name);
178 break;
179 case HID_String:
180 sprintf (buf, "--%s <string>", a->name);
181 break;
182 case HID_Boolean:
183 sprintf (buf, "--%s", a->name);
184 break;
185 case HID_Mixed:
186 case HID_Enum:
187 sprintf (buf, "--%s ", a->name);
188 if (a->type == HID_Mixed)
189 strcat (buf, " <val>");
190 for (i = 0; a->enumerations[i]; i++)
192 strcat (buf, i ? "|" : "<");
193 strcat (buf, a->enumerations[i]);
195 strcat (buf, ">");
196 break;
197 case HID_Path:
198 sprintf (buf, "--%s <path>", a->name);
199 break;
200 case HID_Unit:
201 unit_list = get_unit_list ();
202 n = get_n_units ();
203 sprintf (buf, "--%s ", a->name);
204 for (i = 0; i < n; i++)
206 strcat (buf, i ? "|" : "<");
207 strcat (buf, unit_list[i].suffix);
209 strcat (buf, ">");
210 break;
213 if (strlen (buf) <= 30)
215 if (a->help_text)
216 fprintf (stderr, " %-30s\t%s\n", buf, a->help_text);
217 else
218 fprintf (stderr, " %-30s\n", buf);
220 else if (a->help_text && strlen (a->help_text) + strlen (buf) < 72)
221 fprintf (stderr, " %s\t%s\n", buf, a->help_text);
222 else if (a->help_text)
223 fprintf (stderr, " %s\n\t\t\t%s\n", buf, a->help_text);
224 else
225 fprintf (stderr, " %s\n", buf);
228 static void
229 usage_hid (HID * h)
231 HID_Attribute *attributes;
232 int i, n_attributes = 0;
233 UsageNotes *note;
235 if (h->gui)
237 fprintf (stderr, "\n%s gui options:\n", h->name);
238 attributes = h->get_export_options (&n_attributes);
240 else
242 fprintf (stderr, "\n%s options:\n", h->name);
243 exporter = h;
244 attributes = exporter->get_export_options (&n_attributes);
245 exporter = NULL;
248 note = (UsageNotes *)malloc (sizeof (UsageNotes));
249 note->next = usage_notes;
250 note->seen = attributes;
251 usage_notes = note;
253 for (i = 0; i < n_attributes; i++)
254 usage_attr (attributes + i);
257 static void
258 usage (void)
260 HID **hl = hid_enumerate ();
261 HID_AttrNode *ha;
262 UsageNotes *note;
263 int i;
264 int n_printer = 0, n_gui = 0, n_exporter = 0;
266 for (i = 0; hl[i]; i++)
268 if (hl[i]->gui)
269 n_gui++;
270 if (hl[i]->printer)
271 n_printer++;
272 if (hl[i]->exporter)
273 n_exporter++;
276 u ("PCB Printed Circuit Board editing program, http://pcb.geda-project.org");
277 u ("%s [-h|-V|--copyright]\t\t\tHelp, version, copyright", Progname);
278 u ("%s [gui options] <pcb file>\t\tto edit", Progname);
279 u ("Available GUI hid%s:", n_gui == 1 ? "" : "s");
280 for (i = 0; hl[i]; i++)
281 if (hl[i]->gui)
282 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
283 u ("%s -p [printing options] <pcb file>\tto print", Progname);
284 u ("Available printing hid%s:", n_printer == 1 ? "" : "s");
285 for (i = 0; hl[i]; i++)
286 if (hl[i]->printer)
287 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
288 u ("%s -x hid [export options] <pcb file>\tto export", Progname);
289 u ("Available export hid%s:", n_exporter == 1 ? "" : "s");
290 for (i = 0; hl[i]; i++)
291 if (hl[i]->exporter)
292 fprintf (stderr, "\t%-8s %s\n", hl[i]->name, hl[i]->description);
294 for (i = 0; hl[i]; i++)
295 if (hl[i]->gui)
296 usage_hid (hl[i]);
297 for (i = 0; hl[i]; i++)
298 if (hl[i]->printer)
299 usage_hid (hl[i]);
300 for (i = 0; hl[i]; i++)
301 if (hl[i]->exporter)
302 usage_hid (hl[i]);
304 u ("\nCommon options:");
305 for (ha = hid_attr_nodes; ha; ha = ha->next)
307 for (note = usage_notes; note && note->seen != ha->attributes; note = note->next)
309 if (note)
310 continue;
311 for (i = 0; i < ha->n; i++)
313 usage_attr (ha->attributes + i);
317 exit (1);
320 static void
321 print_defaults_1 (HID_Attribute * a, void *value)
323 int i;
324 Coord c;
325 double d;
326 const char *s;
328 /* Remember, at this point we've parsed the command line, so they
329 may be in the global variable instead of the default_val. */
330 switch (a->type)
332 case HID_Integer:
333 i = value ? *(int *) value : a->default_val.int_value;
334 fprintf (stderr, "%s %d\n", a->name, i);
335 break;
336 case HID_Boolean:
337 i = value ? *(char *) value : a->default_val.int_value;
338 fprintf (stderr, "%s %s\n", a->name, i ? "yes" : "no");
339 break;
340 case HID_Real:
341 d = value ? *(double *) value : a->default_val.real_value;
342 fprintf (stderr, "%s %g\n", a->name, d);
343 break;
344 case HID_Coord:
345 c = value ? *(Coord *) value : a->default_val.coord_value;
346 pcb_fprintf (stderr, "%s %$mS\n", a->name, c);
347 break;
348 case HID_String:
349 case HID_Path:
350 s = value ? *(char **) value : a->default_val.str_value;
351 fprintf (stderr, "%s \"%s\"\n", a->name, s);
352 break;
353 case HID_Enum:
354 i = value ? *(int *) value : a->default_val.int_value;
355 fprintf (stderr, "%s %s\n", a->name, a->enumerations[i]);
356 break;
357 case HID_Mixed:
358 i = value ?
359 ((HID_Attr_Val*)value)->int_value : a->default_val.int_value;
360 d = value ?
361 ((HID_Attr_Val*)value)->real_value : a->default_val.real_value;
362 fprintf (stderr, "%s %g%s\n", a->name, d, a->enumerations[i]);
363 break;
364 case HID_Label:
365 break;
366 case HID_Unit:
367 i = value ? *(int *) value : a->default_val.int_value;
368 fprintf (stderr, "%s %s\n", a->name, get_unit_list()[i].suffix);
372 static void
373 print_defaults ()
375 HID **hl = hid_enumerate ();
376 HID_Attribute *e;
377 int i, n, hi;
379 for (hi = 0; hl[hi]; hi++)
381 HID *h = hl[hi];
382 if (h->gui)
384 HID_AttrNode *ha;
385 fprintf (stderr, "\ngui defaults:\n");
386 for (ha = hid_attr_nodes; ha; ha = ha->next)
387 for (i = 0; i < ha->n; i++)
388 print_defaults_1 (ha->attributes + i, ha->attributes[i].value);
390 else
392 fprintf (stderr, "\n%s defaults:\n", h->name);
393 exporter = h;
394 e = exporter->get_export_options (&n);
395 exporter = NULL;
396 if (e)
397 for (i = 0; i < n; i++)
398 print_defaults_1 (e + i, 0);
401 exit (1);
404 #define SSET(F,D,N,H) { N, H, \
405 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
406 #define ISET(F,D,N,H) { N, H, \
407 HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }
408 #define BSET(F,D,N,H) { N, H, \
409 HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }
410 #define RSET(F,D,N,H) { N, H, \
411 HID_Real, 0, 0, { 0, 0, D }, 0, &Settings.F }
412 #define CSET(F,D,N,H) { N, H, \
413 HID_Coord, 0, 0, { 0, 0, 0, D }, 0, &Settings.F }
415 #define COLOR(F,D,N,H) { N, H, \
416 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }
417 #define LAYERCOLOR(N,D) { "layer-color-" #N, "Color for layer " #N, \
418 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }
419 #define LAYERNAME(N,D) { "layer-name-" #N, "Name for layer " #N, \
420 HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }
421 #define LAYERSELCOLOR(N) { "layer-selected-color-" #N, "Color for layer " #N " when selected", \
422 HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }
424 static int show_help = 0;
425 static int show_version = 0;
426 static int show_copyright = 0;
427 static int show_defaults = 0;
428 static int show_actions = 0;
429 static int do_dump_actions = 0;
430 static char *grid_units;
431 static Increments increment_mm = { 0 };
432 static Increments increment_mil = { 0 };
434 void save_increments (const Increments *mm, const Increments *mil)
436 memcpy (&increment_mm, mm, sizeof (*mm));
437 memcpy (&increment_mil, mil, sizeof (*mil));
440 HID_Attribute main_attribute_list[] = {
442 /* %start-doc options "1 General Options"
443 @ftable @code
444 @item --help
445 Show help on command line options.
446 @end ftable
447 %end-doc
449 {"help", "Show help on command line options", HID_Boolean, 0, 0, {0, 0, 0}, 0,
450 &show_help},
452 /* %start-doc options "1 General Options"
453 @ftable @code
454 @item --version
455 Show version.
456 @end ftable
457 %end-doc
459 {"version", "Show version", HID_Boolean, 0, 0, {0, 0, 0}, 0, &show_version},
461 /* %start-doc options "1 General Options"
462 @ftable @code
463 @item --verbose
464 Be verbose on stdout.
465 @end ftable
466 %end-doc
468 {"verbose", "Be verbose on stdout", HID_Boolean, 0, 0, {0, 0, 0}, 0,
469 &Settings.verbose},
471 /* %start-doc options "1 General Options"
472 @ftable @code
473 @item --copyright
474 Show copyright.
475 @end ftable
476 %end-doc
478 {"copyright", "Show Copyright", HID_Boolean, 0, 0, {0, 0, 0}, 0,
479 &show_copyright},
481 /* %start-doc options "1 General Options"
482 @ftable @code
483 @item --show-defaults
484 Show option defaults.
485 @end ftable
486 %end-doc
488 {"show-defaults", "Show option defaults", HID_Boolean, 0, 0, {0, 0, 0}, 0,
489 &show_defaults},
491 /* %start-doc options "1 General Options"
492 @ftable @code
493 @item --show-actions
494 Show available actions and exit.
495 @end ftable
496 %end-doc
498 {"show-actions", "Show available actions", HID_Boolean, 0, 0, {0, 0, 0}, 0,
499 &show_actions},
501 /* %start-doc options "1 General Options"
502 @ftable @code
503 @item --dump-actions
504 Dump actions (for documentation).
505 @end ftable
506 %end-doc
508 {"dump-actions", "Dump actions (for documentation)", HID_Boolean, 0, 0,
509 {0, 0, 0}, 0, &do_dump_actions},
511 /* %start-doc options "1 General Options"
512 @ftable @code
513 @item --grid-units-mm <string>
514 Set default grid units. Can be mm or mil. Defaults to mil.
515 @end ftable
516 %end-doc
518 {"grid-units", "Default grid units (mm|mil)", HID_String, 0, 0, {0, "mil", 0},
519 0, &grid_units},
521 /* %start-doc options "1 General Options"
522 @ftable @code
523 @item --clear-increment-mm <string>
524 Set default clear increment (amount to change when user presses k or K)
525 when user is using a metric grid unit.
526 @end ftable
527 %end-doc
529 {"clear-increment-mm", "Default clear increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
530 0, &increment_mm.clear},
532 /* %start-doc options "1 General Options"
533 @ftable @code
534 @item --grid-increment-mm <string>
535 Set default grid increment (amount to change when user presses g or G)
536 when user is using a metric grid unit.
537 @end ftable
538 %end-doc
540 {"grid-increment-mm", "Default grid increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
541 0, &increment_mm.grid},
543 /* %start-doc options "1 General Options"
544 @ftable @code
545 @item --line-increment-mm <string>
546 Set default line increment (amount to change when user presses l or L)
547 when user is using a metric grid unit.
548 @end ftable
549 %end-doc
551 {"line-increment-mm", "Default line increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
552 0, &increment_mm.line},
554 /* %start-doc options "1 General Options"
555 @ftable @code
556 @item --size-increment-mm <string>
557 Set default size increment (amount to change when user presses s or S)
558 when user is using a metric grid unit.
559 @end ftable
560 %end-doc
562 {"size-increment-mm", "Default size increment amount (metric)", HID_Coord, 0, 0, {0, 0, 0},
563 0, &increment_mm.size},
565 /* %start-doc options "1 General Options"
566 @ftable @code
567 @item --clear-increment-mil <string>
568 Set default clear increment (amount to change when user presses k or K)
569 when user is using an imperial grid unit.
570 @end ftable
571 %end-doc
573 {"clear-increment-mil", "Default clear increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
574 0, &increment_mil.clear},
576 /* %start-doc options "1 General Options"
577 @ftable @code
578 @item --grid-increment-mil <string>
579 Set default grid increment (amount to change when user presses g or G)
580 when user is using a imperial grid unit.
581 @end ftable
582 %end-doc
584 {"grid-increment-mil", "Default grid increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
585 0, &increment_mil.grid},
587 /* %start-doc options "1 General Options"
588 @ftable @code
589 @item --line-increment-mil <string>
590 Set default line increment (amount to change when user presses l or L)
591 when user is using a imperial grid unit.
592 @end ftable
593 %end-doc
595 {"line-increment-mil", "Default line increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
596 0, &increment_mil.line},
598 /* %start-doc options "1 General Options"
599 @ftable @code
600 @item --size-increment-mil <string>
601 Set default size increment (amount to change when user presses s or S)
602 when user is using a imperial grid unit.
603 @end ftable
604 %end-doc
606 {"size-increment-mil", "Default size increment amount (imperial)", HID_Coord, 0, 0, {0, 0, 0},
607 0, &increment_mil.size},
609 /* %start-doc options "3 Colors"
610 @ftable @code
611 @item --black-color <string>
612 Color value for black. Default: @samp{#000000}
613 @end ftable
614 %end-doc
616 COLOR (BlackColor, "#000000", "black-color", "color value of 'black'"),
618 /* %start-doc options "3 Colors"
619 @ftable @code
620 @item --black-color <string>
621 Color value for white. Default: @samp{#ffffff}
622 @end ftable
623 %end-doc
625 COLOR (WhiteColor, "#ffffff", "white-color", "color value of 'white'"),
627 /* %start-doc options "3 Colors"
628 @ftable @code
629 @item --background-color <string>
630 Background color of the canvas. Default: @samp{#e5e5e5}
631 @end ftable
632 %end-doc
634 COLOR (BackgroundColor, "#e5e5e5", "background-color",
635 "color for background"),
637 /* %start-doc options "3 Colors"
638 @ftable @code
639 @item --crosshair-color <string>
640 Color of the crosshair. Default: @samp{#ff0000}
641 @end ftable
642 %end-doc
644 COLOR (CrosshairColor, "#ff0000", "crosshair-color",
645 "color for the crosshair"),
647 /* %start-doc options "3 Colors"
648 @ftable @code
649 @item --cross-color <string>
650 Color of the cross. Default: @samp{#cdcd00}
651 @end ftable
652 %end-doc
654 COLOR (CrossColor, "#cdcd00", "cross-color", "color of the cross"),
656 /* %start-doc options "3 Colors"
657 @ftable @code
658 @item --via-color <string>
659 Color of vias. Default: @samp{#7f7f7f}
660 @end ftable
661 %end-doc
663 COLOR (ViaColor, "#7f7f7f", "via-color", "color of vias"),
665 /* %start-doc options "3 Colors"
666 @ftable @code
667 @item --via-selected-color <string>
668 Color of selected vias. Default: @samp{#00ffff}
669 @end ftable
670 %end-doc
672 COLOR (ViaSelectedColor, "#00ffff", "via-selected-color",
673 "color for selected vias"),
675 /* %start-doc options "3 Colors"
676 @ftable @code
677 @item --pin-color <string>
678 Color of pins. Default: @samp{#4d4d4d}
679 @end ftable
680 %end-doc
682 COLOR (PinColor, "#4d4d4d", "pin-color", "color of pins"),
684 /* %start-doc options "3 Colors"
685 @ftable @code
686 @item --pin-selected-color <string>
687 Color of selected pins. Default: @samp{#00ffff}
688 @end ftable
689 %end-doc
691 COLOR (PinSelectedColor, "#00ffff", "pin-selected-color",
692 "color of selected pins"),
694 /* %start-doc options "3 Colors"
695 @ftable @code
696 @item --pin-name-color <string>
697 Color of pin names and pin numbers. Default: @samp{#ff0000}
698 @end ftable
699 %end-doc
701 COLOR (PinNameColor, "#ff0000", "pin-name-color",
702 "color for pin names and pin numbers"),
704 /* %start-doc options "3 Colors"
705 @ftable @code
706 @item --element-color <string>
707 Color of components. Default: @samp{#000000}
708 @end ftable
709 %end-doc
711 COLOR (ElementColor, "#000000", "element-color", "color of components"),
713 /* %start-doc options "3 Colors"
714 @ftable @code
715 @item --rat-color <string>
716 Color of ratlines. Default: @samp{#b8860b}
717 @end ftable
718 %end-doc
720 COLOR (RatColor, "#b8860b", "rat-color", "color of ratlines"),
722 /* %start-doc options "3 Colors"
723 @ftable @code
724 @item --invisible-objects-color <string>
725 Color of invisible objects. Default: @samp{#cccccc}
726 @end ftable
727 %end-doc
729 COLOR (InvisibleObjectsColor, "#cccccc", "invisible-objects-color",
730 "color of invisible objects"),
732 /* %start-doc options "3 Colors"
733 @ftable @code
734 @item --invisible-mark-color <string>
735 Color of invisible marks. Default: @samp{#cccccc}
736 @end ftable
737 %end-doc
739 COLOR (InvisibleMarkColor, "#cccccc", "invisible-mark-color",
740 "color of invisible marks"),
742 /* %start-doc options "3 Colors"
743 @ftable @code
744 @item --element-selected-color <string>
745 Color of selected components. Default: @samp{#00ffff}
746 @end ftable
747 %end-doc
749 COLOR (ElementSelectedColor, "#00ffff", "element-selected-color",
750 "color of selected components"),
752 /* %start-doc options "3 Colors"
753 @ftable @code
754 @item --rat-selected-color <string>
755 Color of selected rats. Default: @samp{#00ffff}
756 @end ftable
757 %end-doc
759 COLOR (RatSelectedColor, "#00ffff", "rat-selected-color",
760 "color of selected rats"),
762 /* %start-doc options "3 Colors"
763 @ftable @code
764 @item --connected-color <string>
765 Color to indicate physical connections. Default: @samp{#00ff00}
766 @end ftable
767 %end-doc
769 COLOR (ConnectedColor, "#00ff00", "connected-color",
770 "color to indicate physically connected objects"),
772 /* %start-doc options "3 Colors"
773 @ftable @code
774 @item --found-color <string>
775 Color to indicate logical connections. Default: @samp{#ff00ff}
776 @end ftable
777 %end-doc
779 COLOR (FoundColor, "#ff00ff", "found-color",
780 "color to indicate logically connected objects"),
782 /* %start-doc options "3 Colors"
783 @ftable @code
784 @item --off-limit-color <string>
785 Color of off-canvas area. Default: @samp{#cccccc}
786 @end ftable
787 %end-doc
789 COLOR (OffLimitColor, "#cccccc", "off-limit-color",
790 "color of off-canvas area"),
792 /* %start-doc options "3 Colors"
793 @ftable @code
794 @item --grid-color <string>
795 Color of the grid. Default: @samp{#ff0000}
796 @end ftable
797 %end-doc
799 COLOR (GridColor, "#ff0000", "grid-color", "color of the grid"),
801 /* %start-doc options "3 Colors"
802 @ftable @code
803 @item --layer-color-<n> <string>
804 Color of layer @code{<n>}, where @code{<n>} is an integer from 1 to 16.
805 @end ftable
806 %end-doc
808 LAYERCOLOR (1, "#8b2323"),
809 LAYERCOLOR (2, "#3a5fcd"),
810 LAYERCOLOR (3, "#104e8b"),
811 LAYERCOLOR (4, "#cd3700"),
812 LAYERCOLOR (5, "#548b54"),
813 LAYERCOLOR (6, "#8b7355"),
814 LAYERCOLOR (7, "#00868b"),
815 LAYERCOLOR (8, "#228b22"),
816 LAYERCOLOR (9, "#8b2323"),
817 LAYERCOLOR (10, "#3a5fcd"),
818 LAYERCOLOR (11, "#104e8b"),
819 LAYERCOLOR (12, "#cd3700"),
820 LAYERCOLOR (13, "#548b54"),
821 LAYERCOLOR (14, "#8b7355"),
822 LAYERCOLOR (15, "#00868b"),
823 LAYERCOLOR (16, "#228b22"),
824 /* %start-doc options "3 Colors"
825 @ftable @code
826 @item --layer-selected-color-<n> <string>
827 Color of layer @code{<n>}, when selected. @code{<n>} is an integer from 1 to 16.
828 @end ftable
829 %end-doc
831 LAYERSELCOLOR (1),
832 LAYERSELCOLOR (2),
833 LAYERSELCOLOR (3),
834 LAYERSELCOLOR (4),
835 LAYERSELCOLOR (5),
836 LAYERSELCOLOR (6),
837 LAYERSELCOLOR (7),
838 LAYERSELCOLOR (8),
839 LAYERSELCOLOR (9),
840 LAYERSELCOLOR (10),
841 LAYERSELCOLOR (11),
842 LAYERSELCOLOR (12),
843 LAYERSELCOLOR (13),
844 LAYERSELCOLOR (14),
845 LAYERSELCOLOR (15),
846 LAYERSELCOLOR (16),
848 /* %start-doc options "3 Colors"
849 @ftable @code
850 @item --warn-color <string>
851 Color of offending objects during DRC. Default value is @code{"#ff8000"}
852 @end ftable
853 %end-doc
855 COLOR (WarnColor, "#ff8000", "warn-color", "color of offending objects during DRC"),
857 /* %start-doc options "3 Colors"
858 @ftable @code
859 @item --mask-color <string>
860 Color of the mask layer. Default value is @code{"#ff0000"}
861 @end ftable
862 %end-doc
864 COLOR (MaskColor, "#ff0000", "mask-color", "color for solder mask"),
867 /* %start-doc options "5 Sizes"
868 All parameters should be given with an unit. If no unit is given, 1/100 mil
869 (cmil) will be used. Write units without space to the
870 number like @code{3mm}, not @code{3 mm}.
871 Valid Units are:
872 @table @samp
873 @item km
874 Kilometer
875 @item m
876 Meter
877 @item cm
878 Centimeter
879 @item mm
880 Millimeter
881 @item um
882 Micrometer
883 @item nm
884 Nanometer
885 @item in
886 Inch (1in = 0.0254m)
887 @item mil
888 Mil (1000mil = 1in)
889 @item cmil
890 Centimil (1/100 mil)
891 @end table
893 @ftable @code
894 @item --via-thickness <num>
895 Default diameter of vias. Default value is @code{60mil}.
896 @end ftable
897 %end-doc
899 CSET (ViaThickness, MIL_TO_COORD(60), "via-thickness",
900 "default diameter of vias in 1/100 mil"),
902 /* %start-doc options "5 Sizes"
903 @ftable @code
904 @item --via-drilling-hole <num>
905 Default diameter of holes. Default value is @code{28mil}.
906 @end ftable
907 %end-doc
909 CSET (ViaDrillingHole, MIL_TO_COORD(28), "via-drilling-hole",
910 "default diameter of holes"),
912 /* %start-doc options "5 Sizes"
913 @ftable @code
914 @item --line-thickness <num>
915 Default thickness of new lines. Default value is @code{10mil}.
916 @end ftable
917 %end-doc
919 CSET (LineThickness, MIL_TO_COORD(10), "line-thickness",
920 "initial thickness of new lines"),
922 /* %start-doc options "5 Sizes"
923 @ftable @code
924 @item --rat-thickness <num><unit>
925 Thickness of rats. If no unit is given, PCB units are assumed (i.e. 100
926 means "1 nm"). This option allows for a special unit @code{px} which
927 sets the rat thickness to a fixed value in terms of screen pixels.
928 Maximum fixed thickness is 100px. Minimum saling rat thickness is 101nm.
929 Default value is @code{10mil}.
930 @end ftable
931 %end-doc
933 CSET (RatThickness, MIL_TO_COORD(10), "rat-thickness", "thickness of rat lines"),
935 /* %start-doc options "5 Sizes"
936 @ftable @code
937 @item --keepaway <num>
938 Default minimum distance between a track and adjacent copper.
939 Default value is @code{10mil}.
940 @end ftable
941 %end-doc
943 CSET (Keepaway, MIL_TO_COORD(10), "keepaway", "minimum distance between adjacent copper"),
945 /* %start-doc options "5 Sizes"
946 @ftable @code
947 @item --default-PCB-width <num>
948 Default width of the canvas. Default value is @code{6000mil}.
949 @end ftable
950 %end-doc
952 CSET (MaxWidth, MIL_TO_COORD(6000), "default-PCB-width",
953 "default width of the canvas"),
955 /* %start-doc options "5 Sizes"
956 @ftable @code
957 @item --default-PCB-height <num>
958 Default height of the canvas. Default value is @code{5000mil}.
959 @end ftable
960 %end-doc
962 CSET (MaxHeight, MIL_TO_COORD(5000), "default-PCB-height",
963 "default height of the canvas"),
965 /* %start-doc options "5 Sizes"
966 @ftable @code
967 @item --text-scale <num>
968 Default text scale. This value is in percent. Default value is @code{100}.
969 @end ftable
970 %end-doc
972 ISET (TextScale, 100, "text-scale", "default text scale in percent"),
974 /* %start-doc options "5 Sizes"
975 @ftable @code
976 @item --alignment-distance <num>
977 Specifies the distance between the board outline and alignment targets.
978 Default value is @code{2mil}.
979 @end ftable
980 %end-doc
982 CSET (AlignmentDistance, MIL_TO_COORD(2), "alignment-distance",
983 "distance between the boards outline and alignment targets"),
985 /* %start-doc options "7 DRC Options"
986 All parameters should be given with an unit. If no unit is given, 1/100 mil
987 (cmil) will be used for backward compability. Valid units are given in section
988 @ref{Sizes}.
989 %end-doc
993 /* %start-doc options "7 DRC Options"
994 @ftable @code
995 @item --bloat <num>
996 Minimum spacing. Default value is @code{10mil}.
997 @end ftable
998 %end-doc
1000 CSET (Bloat, MIL_TO_COORD(10), "bloat", "DRC minimum spacing in 1/100 mil"),
1002 /* %start-doc options "7 DRC Options"
1003 @ftable @code
1004 @item --shrink <num>
1005 Minimum touching overlap. Default value is @code{10mil}.
1006 @end ftable
1007 %end-doc
1009 CSET (Shrink, MIL_TO_COORD(10), "shrink", "DRC minimum overlap in 1/100 mils"),
1011 /* %start-doc options "7 DRC Options"
1012 @ftable @code
1013 @item --min-width <num>
1014 Minimum width of copper. Default value is @code{10mil}.
1015 @end ftable
1016 %end-doc
1018 CSET (minWid, MIL_TO_COORD(10), "min-width", "DRC minimum copper spacing"),
1020 /* %start-doc options "7 DRC Options"
1021 @ftable @code
1022 @item --min-silk <num>
1023 Minimum width of lines in silk. Default value is @code{10mil}.
1024 @end ftable
1025 %end-doc
1027 CSET (minSlk, MIL_TO_COORD(10), "min-silk", "DRC minimum silk width"),
1029 /* %start-doc options "7 DRC Options"
1030 @ftable @code
1031 @item --min-drill <num>
1032 Minimum diameter of holes. Default value is @code{15mil}.
1033 @end ftable
1034 %end-doc
1036 CSET (minDrill, MIL_TO_COORD(15), "min-drill", "DRC minimum drill diameter"),
1038 /* %start-doc options "7 DRC Options"
1039 @ftable @code
1040 @item --min-ring <num>
1041 Minimum width of annular ring. Default value is @code{10mil}.
1042 @end ftable
1043 %end-doc
1045 CSET (minRing, MIL_TO_COORD(10), "min-ring", "DRC minimum annular ring"),
1048 /* %start-doc options "5 Sizes"
1049 @ftable @code
1050 @item --grid <num>
1051 Initial grid size. Default value is @code{10mil}.
1052 @end ftable
1053 %end-doc
1055 CSET (Grid, MIL_TO_COORD(10), "grid", "Initial grid size in 1/100 mil"),
1057 /* %start-doc options "5 Sizes"
1058 @ftable @code
1059 @item --minimum polygon area <num>
1060 Minimum polygon area.
1061 @end ftable
1062 %end-doc
1064 RSET (IsleArea, MIL_TO_COORD(100) * MIL_TO_COORD(100), "minimum polygon area", 0),
1067 /* %start-doc options "1 General Options"
1068 @ftable @code
1069 @item --backup-interval
1070 Time between automatic backups in seconds. Set to @code{0} to disable.
1071 The default value is @code{60}.
1072 @end ftable
1073 %end-doc
1075 ISET (BackupInterval, 60, "backup-interval",
1076 "Time between automatic backups in seconds. Set to 0 to disable"),
1078 /* %start-doc options "4 Layer Names"
1079 @ftable @code
1080 @item --layer-name-1 <string>
1081 Name of the 1st Layer. Default is @code{"top"}.
1082 @end ftable
1083 %end-doc
1085 LAYERNAME (1, "top"),
1087 /* %start-doc options "4 Layer Names"
1088 @ftable @code
1089 @item --layer-name-2 <string>
1090 Name of the 2nd Layer. Default is @code{"ground"}.
1091 @end ftable
1092 %end-doc
1094 LAYERNAME (2, "ground"),
1096 /* %start-doc options "4 Layer Names"
1097 @ftable @code
1098 @item --layer-name-3 <string>
1099 Name of the 3nd Layer. Default is @code{"signal2"}.
1100 @end ftable
1101 %end-doc
1103 LAYERNAME (3, "signal2"),
1105 /* %start-doc options "4 Layer Names"
1106 @ftable @code
1107 @item --layer-name-4 <string>
1108 Name of the 4rd Layer. Default is @code{"signal3"}.
1109 @end ftable
1110 %end-doc
1112 LAYERNAME (4, "signal3"),
1114 /* %start-doc options "4 Layer Names"
1115 @ftable @code
1116 @item --layer-name-5 <string>
1117 Name of the 5rd Layer. Default is @code{"power"}.
1118 @end ftable
1119 %end-doc
1121 LAYERNAME (5, "power"),
1123 /* %start-doc options "4 Layer Names"
1124 @ftable @code
1125 @item --layer-name-6 <string>
1126 Name of the 6rd Layer. Default is @code{"bottom"}.
1127 @end ftable
1128 %end-doc
1130 LAYERNAME (6, "bottom"),
1132 /* %start-doc options "4 Layer Names"
1133 @ftable @code
1134 @item --layer-name-7 <string>
1135 Name of the 7rd Layer. Default is @code{"outline"}.
1136 @end ftable
1137 %end-doc
1139 LAYERNAME (7, "outline"),
1141 /* %start-doc options "4 Layer Names"
1142 @ftable @code
1143 @item --layer-name-8 <string>
1144 Name of the 8rd Layer. Default is @code{"spare"}.
1145 @end ftable
1146 %end-doc
1148 LAYERNAME (8, "spare"),
1150 /* %start-doc options "1 General Options"
1151 @ftable @code
1152 @item --groups <string>
1153 Layer group string. Defaults to @code{"1,c:2:3:4:5:6,s:7:8"}.
1154 @end ftable
1155 %end-doc
1157 SSET (Groups, "1,c:2:3:4:5:6,s:7:8", "groups", "Layer group string"),
1160 /* %start-doc options "6 Commands"
1161 pcb uses external commands for input output operations. These commands can be
1162 configured at start-up to meet local requirements. The command string may include
1163 special sequences @code{%f}, @code{%p} or @code{%a}. These are replaced when the
1164 command is called. The sequence @code{%f} is replaced by the file name,
1165 @code{%p} gets the path and @code{%a} indicates a package name.
1166 %end-doc
1169 /* %start-doc options "6 Commands"
1170 @ftable @code
1171 @item --font-command <string>
1172 Command to load a font.
1173 @end ftable
1174 %end-doc
1176 SSET (FontCommand, "", "font-command", "Command to load a font"),
1178 /* %start-doc options "6 Commands"
1179 @ftable @code
1180 @item --file-command <string>
1181 Command to read a file.
1182 @end ftable
1183 %end-doc
1185 SSET (FileCommand, "", "file-command", "Command to read a file"),
1187 /* %start-doc options "6 Commands"
1188 @ftable @code
1189 @item --element-command <string>
1190 Command to read a footprint. @*
1191 Defaults to @code{"M4PATH='%p';export M4PATH;echo 'include(%f)' | m4"}
1192 @end ftable
1193 %end-doc
1195 SSET (ElementCommand,
1196 "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4,
1197 "element-command", "Command to read a footprint"),
1199 /* %start-doc options "6 Commands"
1200 @ftable @code
1201 @item --print-file <string>
1202 Command to print to a file.
1203 @end ftable
1204 %end-doc
1206 SSET (PrintFile, "%f.output", "print-file", "Command to print to a file"),
1208 /* %start-doc options "6 Commands"
1209 @ftable @code
1210 @item --lib-command-dir <string>
1211 Path to the command that queries the library.
1212 @end ftable
1213 %end-doc
1215 SSET (LibraryCommandDir, PCBLIBDIR, "lib-command-dir",
1216 "Path to the command that queries the library"),
1218 /* %start-doc options "6 Commands"
1219 @ftable @code
1220 @item --lib-command <string>
1221 Command to query the library. @*
1222 Defaults to @code{"QueryLibrary.sh '%p' '%f' %a"}
1223 @end ftable
1224 %end-doc
1226 SSET (LibraryCommand, "QueryLibrary.sh '%p' '%f' %a",
1227 "lib-command", "Command to query the library"),
1229 /* %start-doc options "6 Commands"
1230 @ftable @code
1231 @item --lib-contents-command <string>
1232 Command to query the contents of the library. @*
1233 Defaults to @code{"ListLibraryContents.sh %p %f"} or,
1234 on Windows builds, an empty string (to disable this feature).
1235 @end ftable
1236 %end-doc
1238 SSET (LibraryContentsCommand,
1239 #ifdef __WIN32__
1241 #else
1242 "ListLibraryContents.sh '%p' '%f'",
1243 #endif
1244 "lib-contents-command", "Command to query the contents of the library"),
1246 /* %start-doc options "5 Paths"
1247 @ftable @code
1248 @item --lib-newlib <string>
1249 Top level directory for the newlib style library.
1250 @end ftable
1251 %end-doc
1253 SSET (LibraryTree, PCBTREEPATH, "lib-newlib",
1254 "Top level directory for the newlib style library"),
1256 /* %start-doc options "6 Commands"
1257 @ftable @code
1258 @item --save-command <string>
1259 Command to save to a file.
1260 @end ftable
1261 %end-doc
1263 SSET (SaveCommand, "", "save-command", "Command to save to a file"),
1265 /* %start-doc options "5 Paths"
1266 @ftable @code
1267 @item --lib-name <string>
1268 The default filename for the library.
1269 @end ftable
1270 %end-doc
1272 SSET (LibraryFilename, LIBRARYFILENAME, "lib-name",
1273 "The default filename for the library"),
1275 /* %start-doc options "5 Paths"
1276 @ftable @code
1277 @item --default-font <string>
1278 The name of the default font.
1279 @end ftable
1280 %end-doc
1282 SSET (FontFile, "default_font", "default-font",
1283 "File name of default font"),
1285 /* %start-doc options "1 General Options"
1286 @ftable @code
1287 @item --route-styles <string>
1288 A string that defines the route styles. Defaults to @*
1289 @code{"Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000
1290 :Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"}
1291 @end ftable
1292 %end-doc
1294 SSET (Routes, "Signal,1000,3600,2000,1000:Power,2500,6000,3500,1000"
1295 ":Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600", "route-styles",
1296 "A string that defines the route styles"),
1298 /* %start-doc options "5 Paths"
1299 @ftable @code
1300 @item --file-path <string>
1301 A colon separated list of directories or commands (starts with '|'). The path
1302 is passed to the program specified in @option{--file-command} together with the selected
1303 filename.
1304 @end ftable
1305 %end-doc
1307 SSET (FilePath, "", "file-path", 0),
1309 /* %start-doc options "6 Commands"
1310 @ftable @code
1311 @item --rat-command <string>
1312 Command for reading a netlist. Sequence @code{%f} is replaced by the netlist filename.
1313 @end ftable
1314 %end-doc
1316 SSET (RatCommand, "", "rat-command", "Command for reading a netlist"),
1318 /* %start-doc options "5 Paths"
1319 @ftable @code
1320 @item --font-path <string>
1321 A colon separated list of directories to search the default font. Defaults to
1322 the default library path.
1323 @end ftable
1324 %end-doc
1326 SSET (FontPath, PCBLIBPATH, "font-path",
1327 "Colon separated list of directories to search the default font"),
1329 /* %start-doc options "1 General Options"
1330 @ftable @code
1331 @item --element-path <string>
1332 A colon separated list of directories or commands (starts with '|').
1333 The path is passed to the program specified in @option{--element-command}.
1334 @end ftable
1335 %end-doc
1337 SSET(ElementPath, PCBLIBPATH, "element-path",
1338 "A colon separated list of directories or commands (starts with '|')"),
1340 /* %start-doc options "5 Paths"
1341 @ftable @code
1342 @item --lib-path <string>
1343 A colon separated list of directories that will be passed to the commands specified
1344 by @option{--element-command} and @option{--element-contents-command}.
1345 @end ftable
1346 %end-doc
1348 SSET (LibraryPath, PCBLIBPATH, "lib-path",
1349 "A colon separated list of directories"),
1351 /* %start-doc options "1 General Options"
1352 @ftable @code
1353 @item --action-script <string>
1354 If set, this file is executed at startup.
1355 @end ftable
1356 %end-doc
1358 SSET (ScriptFilename, 0, "action-script",
1359 "If set, this file is executed at startup"),
1361 /* %start-doc options "1 General Options"
1362 @ftable @code
1363 @item --action-string <string>
1364 If set, this string of actions is executed at startup.
1365 @end ftable
1366 %end-doc
1368 SSET (ActionString, 0, "action-string",
1369 "If set, this is executed at startup"),
1371 /* %start-doc options "1 General Options"
1372 @ftable @code
1373 @item --fab-author <string>
1374 Name of author to be put in the Gerber files.
1375 @end ftable
1376 %end-doc
1378 SSET (FabAuthor, "", "fab-author",
1379 "Name of author to be put in the Gerber files"),
1381 /* %start-doc options "1 General Options"
1382 @ftable @code
1383 @item --layer-stack <string>
1384 Initial layer stackup, for setting up an export. A comma separated list of layer
1385 names, layer numbers and layer groups.
1386 @end ftable
1387 %end-doc
1389 SSET (InitialLayerStack, "", "layer-stack",
1390 "Initial layer stackup, for setting up an export."),
1392 SSET (MakeProgram, NULL, "make-program",
1393 "Sets the name and optionally full path to a make(3) program"),
1394 SSET (GnetlistProgram, NULL, "gnetlist",
1395 "Sets the name and optionally full path to the gnetlist(3) program"),
1397 /* %start-doc options "2 General GUI Options"
1398 @ftable @code
1399 @item --pinout-offset-x <num>
1400 Horizontal offset of the pin number display. Defaults to @code{100mil}.
1401 @end ftable
1402 %end-doc
1404 CSET (PinoutOffsetX, MIL_TO_COORD(1), "pinout-offset-x",
1405 "Horizontal offset of the pin number display in mil"),
1407 /* %start-doc options "2 General GUI Options"
1408 @ftable @code
1409 @item --pinout-offset-y <num>
1410 Vertical offset of the pin number display. Defaults to @code{100mil}.
1411 @end ftable
1412 %end-doc
1414 CSET (PinoutOffsetY, MIL_TO_COORD(1), "pinout-offset-y",
1415 "Vertical offset of the pin number display in mil"),
1417 /* %start-doc options "2 General GUI Options"
1418 @ftable @code
1419 @item --pinout-text-offset-x <num>
1420 Horizontal offset of the pin name display. Defaults to @code{800mil}.
1421 @end ftable
1422 %end-doc
1424 CSET (PinoutTextOffsetX, MIL_TO_COORD(8), "pinout-text-offset-x",
1425 "Horizontal offset of the pin name display in mil"),
1427 /* %start-doc options "2 General GUI Options"
1428 @ftable @code
1429 @item --pinout-text-offset-y <num>
1430 Vertical offset of the pin name display. Defaults to @code{-100mil}.
1431 @end ftable
1432 %end-doc
1434 CSET (PinoutTextOffsetY, MIL_TO_COORD(-1), "pinout-text-offset-y",
1435 "Vertical offset of the pin name display in mil"),
1437 /* %start-doc options "2 General GUI Options"
1438 @ftable @code
1439 @item --draw-grid
1440 If set, draw the grid at start-up.
1441 @end ftable
1442 %end-doc
1444 BSET (DrawGrid, 0, "draw-grid", "If set, draw the grid at start-up"),
1446 /* %start-doc options "2 General GUI Options"
1447 @ftable @code
1448 @item --clear-line
1449 If set, new lines clear polygons.
1450 @end ftable
1451 %end-doc
1453 BSET (ClearLine, 1, "clear-line", "If set, new lines clear polygons"),
1455 /* %start-doc options "2 General GUI Options"
1456 @ftable @code
1457 @item --full-poly
1458 If set, new polygons are full ones.
1459 @end ftable
1460 %end-doc
1462 BSET (FullPoly, 0, "full-poly", 0),
1464 /* %start-doc options "2 General GUI Options"
1465 @ftable @code
1466 @item --unique-names
1467 If set, you will not be permitted to change the name of an component to match that
1468 of another component.
1469 @end ftable
1470 %end-doc
1472 BSET (UniqueNames, 1, "unique-names", "Prevents identical component names"),
1474 /* %start-doc options "2 General GUI Options"
1475 @ftable @code
1476 @item --snap-pin
1477 If set, pin centers and pad end points are treated as additional grid points
1478 that the cursor can snap to.
1479 @end ftable
1480 %end-doc
1482 BSET (SnapPin, 1, "snap-pin",
1483 "If set, the cursor snaps to pads and pin centers"),
1485 /* %start-doc options "1 General Options"
1486 @ftable @code
1487 @item --save-last-command
1488 If set, the last user command is saved.
1489 @end ftable
1490 %end-doc
1492 BSET (SaveLastCommand, 0, "save-last-command", 0),
1494 /* %start-doc options "1 General Options"
1495 @ftable @code
1496 @item --save-in-tmp
1497 If set, all data which would otherwise be lost are saved in a temporary file
1498 @file{/tmp/PCB.%i.save} . Sequence @samp{%i} is replaced by the process ID.
1499 @end ftable
1500 %end-doc
1502 BSET (SaveInTMP, 0, "save-in-tmp",
1503 "When set, all data which would otherwise be lost are saved in /tmp"),
1505 /* %start-doc options "1 General Options"
1506 @ftable @code
1507 @item --save-metric-only
1508 If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm.
1509 @end ftable
1510 %end-doc
1512 BSET (SaveMetricOnly, 0, "save-metric-only",
1513 "If set, save pcb files using only mm unit suffix rather than 'smart' mil/mm."),
1515 /* %start-doc options "2 General GUI Options"
1516 @ftable @code
1517 @item --all-direction-lines
1518 Allow all directions, when drawing new lines.
1519 @end ftable
1520 %end-doc
1522 BSET (AllDirectionLines, 0, "all-direction-lines",
1523 "Allow all directions, when drawing new lines"),
1525 /* %start-doc options "2 General GUI Options"
1526 @ftable @code
1527 @item --show-number
1528 Pinout shows number.
1529 @end ftable
1530 %end-doc
1532 BSET (ShowNumber, 0, "show-number", "Pinout shows number"),
1534 /* %start-doc options "1 General Options"
1535 @ftable @code
1536 @item --reset-after-element
1537 If set, all found connections are reset before a new component is scanned.
1538 @end ftable
1539 %end-doc
1541 BSET (ResetAfterElement, 1, "reset-after-element",
1542 "If set, all found connections are reset before a new component is scanned"),
1544 /* %start-doc options "1 General Options"
1545 @ftable @code
1546 @item --ring-bell-finished
1547 Execute the bell command when all rats are routed.
1548 @end ftable
1549 %end-doc
1551 BSET (RingBellWhenFinished, 0, "ring-bell-finished",
1552 "Execute the bell command when all rats are routed"),
1555 REGISTER_ATTRIBUTES (main_attribute_list)
1556 /* ----------------------------------------------------------------------
1557 * post-process settings.
1559 static void settings_post_process ()
1561 char *tmps;
1563 if (Settings.LibraryCommand != NULL &&
1564 Settings.LibraryCommand[0] != '\0' &&
1565 Settings.LibraryCommand[0] != PCB_DIR_SEPARATOR_C &&
1566 Settings.LibraryCommand[0] != '.')
1568 Settings.LibraryCommand
1570 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1571 Settings.LibraryCommand,
1572 NULL);
1574 if (Settings.LibraryContentsCommand != NULL &&
1575 Settings.LibraryContentsCommand[0] != '\0' &&
1576 Settings.LibraryContentsCommand[0] != PCB_DIR_SEPARATOR_C &&
1577 Settings.LibraryContentsCommand[0] != '.')
1579 Settings.LibraryContentsCommand
1581 Concat (Settings.LibraryCommandDir, PCB_DIR_SEPARATOR_S,
1582 Settings.LibraryContentsCommand, NULL);
1585 if (Settings.LineThickness > MAX_LINESIZE
1586 || Settings.LineThickness < MIN_LINESIZE)
1587 Settings.LineThickness = MIL_TO_COORD(10);
1589 if (Settings.ViaThickness > MAX_PINORVIASIZE
1590 || Settings.ViaThickness < MIN_PINORVIASIZE)
1591 Settings.ViaThickness = MIL_TO_COORD(40);
1593 if (Settings.ViaDrillingHole <= 0)
1594 Settings.ViaDrillingHole =
1595 DEFAULT_DRILLINGHOLE * Settings.ViaThickness / 100;
1597 Settings.MaxWidth = CLAMP (Settings.MaxWidth, MIN_SIZE, MAX_COORD);
1598 Settings.MaxHeight = CLAMP (Settings.MaxHeight, MIN_SIZE, MAX_COORD);
1600 ParseRouteString (Settings.Routes, &Settings.RouteStyle[0], "cmil");
1603 * Make sure we have settings for some various programs we may wish
1604 * to call
1606 if (Settings.MakeProgram == NULL) {
1607 tmps = getenv ("PCB_MAKE_PROGRAM");
1608 if (tmps != NULL)
1609 Settings.MakeProgram = strdup (tmps);
1611 if (Settings.MakeProgram == NULL) {
1612 Settings.MakeProgram = strdup ("make");
1615 if (Settings.GnetlistProgram == NULL) {
1616 tmps = getenv ("PCB_GNETLIST");
1617 if (tmps != NULL)
1618 Settings.GnetlistProgram = strdup (tmps);
1620 if (Settings.GnetlistProgram == NULL) {
1621 Settings.GnetlistProgram = strdup ("gnetlist");
1624 if (grid_units)
1625 Settings.grid_unit = get_unit_struct (grid_units);
1626 if (!grid_units || Settings.grid_unit == NULL)
1627 Settings.grid_unit = get_unit_struct ("mil");
1629 copy_nonzero_increments (get_increments_struct (METRIC), &increment_mm);
1630 copy_nonzero_increments (get_increments_struct (IMPERIAL), &increment_mil);
1632 Settings.increments = get_increments_struct (Settings.grid_unit->family);
1636 * \brief Print help or version messages.
1638 static void
1639 print_version ()
1641 printf ("PCB version %s\n", VERSION);
1642 exit (0);
1645 /* ----------------------------------------------------------------------
1646 * Figure out the canonical name of the executed program
1647 * and fix up the defaults for various paths
1649 char *bindir = NULL;
1650 char *exec_prefix = NULL;
1651 char *pcblibdir = NULL;
1652 char *pcblibpath = NULL;
1653 char *pcbtreedir = NULL;
1654 char *pcbtreepath = NULL;
1655 char *homedir = NULL;
1658 * \brief See if argv0 has enough of a path to let lrealpath give the
1659 * real path.
1661 * This should be the case if you invoke pcb with something like
1662 * /usr/local/bin/pcb or ./pcb or ./foo/pcb but if you just use pcb and
1663 * it exists in your path, you'll just get back pcb again.
1665 static void
1666 InitPaths (char *argv0)
1668 size_t l;
1669 int i;
1670 int haspath;
1671 char *t1, *t2;
1672 int found_bindir = 0;
1674 haspath = 0;
1675 for (i = 0; i < strlen (argv0) ; i++)
1677 if (argv0[i] == PCB_DIR_SEPARATOR_C)
1678 haspath = 1;
1681 #ifdef DEBUG
1682 printf ("InitPaths (%s): haspath = %d\n", argv0, haspath);
1683 #endif
1685 if (haspath)
1687 bindir = strdup (lrealpath (argv0));
1688 found_bindir = 1;
1690 else
1692 char *path, *p, *tmps;
1693 struct stat sb;
1694 int r;
1696 tmps = getenv ("PATH");
1698 if (tmps != NULL)
1700 path = strdup (tmps);
1702 /* search through the font path for a font file */
1703 for (p = strtok (path, PCB_PATH_DELIMETER); p && *p;
1704 p = strtok (NULL, PCB_PATH_DELIMETER))
1706 #ifdef DEBUG
1707 printf ("Looking for %s in %s\n", argv0, p);
1708 #endif
1709 if ( (tmps = (char *)malloc ( (strlen (argv0) + strlen (p) + 2) * sizeof (char))) == NULL )
1711 fprintf (stderr, "InitPaths(): malloc failed\n");
1712 exit (1);
1714 sprintf (tmps, "%s%s%s", p, PCB_DIR_SEPARATOR_S, argv0);
1715 r = stat (tmps, &sb);
1716 if (r == 0)
1718 #ifdef DEBUG
1719 printf ("Found it: \"%s\"\n", tmps);
1720 #endif
1721 bindir = lrealpath (tmps);
1722 found_bindir = 1;
1723 free (tmps);
1724 break;
1726 free (tmps);
1728 free (path);
1732 #ifdef DEBUG
1733 printf ("InitPaths(): bindir = \"%s\"\n", bindir);
1734 #endif
1736 if (found_bindir)
1738 /* strip off the executible name leaving only the path */
1739 t2 = NULL;
1740 t1 = strchr (bindir, PCB_DIR_SEPARATOR_C);
1741 while (t1 != NULL && *t1 != '\0')
1743 t2 = t1;
1744 t1 = strchr (t2 + 1, PCB_DIR_SEPARATOR_C);
1746 if (t2 != NULL)
1747 *t2 = '\0';
1749 #ifdef DEBUG
1750 printf ("After stripping off the executible name, we found\n");
1751 printf ("bindir = \"%s\"\n", bindir);
1752 #endif
1754 else
1756 /* we have failed to find out anything from argv[0] so fall back to the original
1757 * install prefix
1759 bindir = strdup (BINDIR);
1762 /* now find the path to exec_prefix */
1763 l = strlen (bindir) + 1 + strlen (BINDIR_TO_EXECPREFIX) + 1;
1764 if ( (exec_prefix = (char *) malloc (l * sizeof (char) )) == NULL )
1766 fprintf (stderr, "InitPaths(): malloc failed\n");
1767 exit (1);
1769 sprintf (exec_prefix, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1770 BINDIR_TO_EXECPREFIX);
1772 /* now find the path to PCBLIBDIR */
1773 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBLIBDIR) + 1;
1774 if ( (pcblibdir = (char *) malloc (l * sizeof (char) )) == NULL )
1776 fprintf (stderr, "InitPaths(): malloc failed\n");
1777 exit (1);
1779 sprintf (pcblibdir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1780 BINDIR_TO_PCBLIBDIR);
1782 /* and the path to PCBTREEDIR */
1783 l = strlen (bindir) + 1 + strlen (BINDIR_TO_PCBTREEDIR) + 1;
1784 if ( (pcbtreedir = (char *) malloc (l * sizeof (char) )) == NULL )
1786 fprintf (stderr, "InitPaths(): malloc failed\n");
1787 exit (1);
1789 sprintf (pcbtreedir, "%s%s%s", bindir, PCB_DIR_SEPARATOR_S,
1790 BINDIR_TO_PCBTREEDIR);
1792 /* and the search path including PCBLIBDIR */
1793 l = strlen (pcblibdir) + 3;
1794 if ( (pcblibpath = (char *) malloc (l * sizeof (char) )) == NULL )
1796 fprintf (stderr, "InitPaths(): malloc failed\n");
1797 exit (1);
1799 sprintf (pcblibpath, ".%s%s", PCB_PATH_DELIMETER, pcblibdir);
1801 /* and the newlib search path */
1802 l = strlen (pcblibdir) + 1 + strlen (pcbtreedir)
1803 + strlen ("pcblib-newlib") + 2;
1804 if ( (pcbtreepath = (char *) malloc (l * sizeof (char) )) == NULL )
1806 fprintf (stderr, "InitPaths(): malloc failed\n");
1807 exit (1);
1809 sprintf (pcbtreepath, "%s%s%s%spcblib-newlib", pcbtreedir,
1810 PCB_PATH_DELIMETER, pcblibdir,
1811 PCB_DIR_SEPARATOR_S);
1813 #ifdef DEBUG
1814 printf ("bindir = %s\n", bindir);
1815 printf ("pcblibdir = %s\n", pcblibdir);
1816 printf ("pcblibpath = %s\n", pcblibpath);
1817 printf ("pcbtreedir = %s\n", pcbtreedir);
1818 printf ("pcbtreepath = %s\n", pcbtreepath);
1819 #endif
1821 l = sizeof (main_attribute_list) / sizeof (main_attribute_list[0]);
1822 for (i = 0; i < l ; i++)
1824 if (NSTRCMP (main_attribute_list[i].name, "lib-command-dir") == 0)
1826 main_attribute_list[i].default_val.str_value = pcblibdir;
1829 if ( (NSTRCMP (main_attribute_list[i].name, "font-path") == 0)
1830 || (NSTRCMP (main_attribute_list[i].name, "element-path") == 0)
1831 || (NSTRCMP (main_attribute_list[i].name, "lib-path") == 0) )
1833 main_attribute_list[i].default_val.str_value = pcblibpath;
1836 if (NSTRCMP (main_attribute_list[i].name, "lib-newlib") == 0)
1838 main_attribute_list[i].default_val.str_value = pcbtreepath;
1844 char *tmps;
1846 tmps = getenv ("HOME");
1848 if (tmps == NULL) {
1849 tmps = getenv ("USERPROFILE");
1852 if (tmps != NULL) {
1853 homedir = strdup (tmps);
1854 } else {
1855 homedir = NULL;
1861 /* ----------------------------------------------------------------------
1862 * main program
1865 char *program_name = 0;
1866 char *program_basename = 0;
1867 char *program_directory = 0;
1869 #include "dolists.h"
1872 * \brief Free up memory allocated to the PCB.
1874 * Why bother when we're about to exit ?\n
1875 * Because it removes some false positives from heap bug detectors such
1876 * as lib dmalloc.
1878 void
1879 pcb_main_uninit (void)
1881 int i;
1883 if (gui->uninit != NULL)
1884 gui->uninit (gui);
1886 hid_uninit ();
1888 UninitBuffers ();
1890 FreePCBMemory (PCB);
1891 free (PCB);
1893 for (i = 0; i < MAX_LAYER; i++)
1894 free (Settings.DefaultLayerName[i]);
1896 if (Settings.FontFile != NULL)
1898 free (Settings.FontFile);
1899 Settings.FontFile = NULL;
1902 uninit_strflags_buf ();
1906 * \brief Main program.
1908 * Init application:
1910 * - make program name available for error handlers
1911 * - evaluate special options
1912 * - initialize toplevel shell and resources
1913 * - create an empty PCB with default symbols
1914 * - initialize all other widgets
1915 * - update screen and get size of drawing area
1916 * - evaluate command-line arguments
1917 * - register 'call on exit()' function
1920 main (int argc, char *argv[])
1922 int i;
1924 #include "core_lists.h"
1925 setbuf (stdout, 0);
1926 InitPaths (argv[0]);
1928 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1929 textdomain (GETTEXT_PACKAGE);
1930 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1932 #ifdef ENABLE_NLS
1933 setlocale (LC_ALL, "");
1934 setlocale (LC_NUMERIC, "C");
1935 #endif
1937 srand ( time(NULL) ); /* Set seed for rand() */
1939 initialize_units();
1940 polygon_init ();
1941 hid_init ();
1943 hid_load_settings ();
1945 program_name = argv[0];
1946 program_basename = strrchr (program_name, PCB_DIR_SEPARATOR_C);
1947 if (program_basename)
1949 program_directory = strdup (program_name);
1950 *strrchr (program_directory, PCB_DIR_SEPARATOR_C) = 0;
1951 program_basename++;
1953 else
1955 program_directory = ".";
1956 program_basename = program_name;
1958 Progname = program_basename;
1960 /* Print usage or version if requested. Then exit. */
1961 if (argc > 1 &&
1962 (strcmp (argv[1], "-h") == 0 ||
1963 strcmp (argv[1], "-?") == 0 ||
1964 strcmp (argv[1], "--help") == 0))
1965 usage ();
1966 if (argc > 1 && strcmp (argv[1], "-V") == 0)
1967 print_version ();
1968 /* Export pcb from command line if requested. */
1969 if (argc > 1 && strcmp (argv[1], "-p") == 0)
1971 exporter = gui = hid_find_printer ();
1972 argc--;
1973 argv++;
1975 else if (argc > 2 && strcmp (argv[1], "-x") == 0)
1977 exporter = gui = hid_find_exporter (argv[2]);
1978 argc -= 2;
1979 argv += 2;
1981 /* Otherwise start GUI. */
1982 else
1983 gui = hid_find_gui ();
1985 /* Exit with error if GUI failed to start. */
1986 if (!gui)
1987 exit (1);
1989 /* Set up layers. */
1990 for (i = 0; i < MAX_LAYER; i++)
1992 char buf[20];
1993 sprintf (buf, "signal%d", i + 1);
1994 Settings.DefaultLayerName[i] = strdup (buf);
1995 Settings.LayerColor[i] = "#c49350";
1996 Settings.LayerSelectedColor[i] = "#00ffff";
1999 gui->parse_arguments (&argc, &argv);
2001 if (show_help || (argc > 1 && argv[1][0] == '-'))
2002 usage ();
2003 if (show_version)
2004 print_version ();
2005 if (show_defaults)
2006 print_defaults ();
2007 if (show_copyright)
2008 copyright ();
2010 settings_post_process ();
2013 if (show_actions)
2015 print_actions ();
2016 exit (0);
2019 if (do_dump_actions)
2021 extern void dump_actions (void);
2022 dump_actions ();
2023 exit (0);
2026 /* Create a new PCB object in memory */
2027 PCB = CreateNewPCB ();
2028 ParseGroupString (Settings.Groups, &PCB->LayerGroups, &PCB->Data->LayerN);
2029 /* Add silk layers to newly created PCB */
2030 CreateNewPCBPost (PCB, 1);
2031 if (argc > 1)
2032 command_line_pcb = argv[1];
2034 ResetStackAndVisibility ();
2036 if (gui->gui)
2037 InitCrosshair ();
2038 InitHandler ();
2039 InitBuffers ();
2040 SetMode (ARROW_MODE);
2042 if (command_line_pcb)
2044 /* keep filename even if initial load command failed;
2045 * file might not exist
2047 if (LoadPCB (command_line_pcb))
2048 PCB->Filename = strdup (command_line_pcb);
2051 if (Settings.InitialLayerStack
2052 && Settings.InitialLayerStack[0])
2054 LayerStringToLayerStack (Settings.InitialLayerStack);
2057 /* This must be called before any other atexit functions
2058 * are registered, as it configures an atexit function to
2059 * clean up and free various items of allocated memory,
2060 * and must be the last last atexit function to run.
2062 leaky_init ();
2064 /* Register a function to be called when the program terminates.
2065 * This makes sure that data is saved even if LEX/YACC routines
2066 * abort the program.
2067 * If the OS doesn't have at least one of them,
2068 * the critical sections will be handled by parse_l.l
2070 atexit (EmergencySave);
2072 /* read the library file and display it if it's not empty
2074 if (!ReadLibraryContents () && Library.MenuN)
2075 hid_action ("LibraryChanged");
2077 #ifdef HAVE_LIBSTROKE
2078 stroke_init ();
2079 #endif
2081 if (Settings.ScriptFilename)
2083 Message (_("Executing startup script file %s\n"),
2084 Settings.ScriptFilename);
2085 hid_actionl ("ExecuteFile", Settings.ScriptFilename, NULL);
2087 if (Settings.ActionString)
2089 Message (_("Executing startup action %s\n"), Settings.ActionString);
2090 hid_parse_actions (Settings.ActionString);
2093 if (gui->printer || gui->exporter)
2095 gui->do_export (0);
2096 exit (0);
2099 #if HAVE_DBUS
2100 pcb_dbus_setup();
2101 #endif
2103 EnableAutosave ();
2105 #ifdef DEBUG
2106 printf ("Settings.LibraryCommandDir = \"%s\"\n",
2107 Settings.LibraryCommandDir);
2108 printf ("Settings.FontPath = \"%s\"\n",
2109 Settings.FontPath);
2110 printf ("Settings.ElementPath = \"%s\"\n",
2111 Settings.ElementPath);
2112 printf ("Settings.LibraryPath = \"%s\"\n",
2113 Settings.LibraryPath);
2114 printf ("Settings.LibraryTree = \"%s\"\n",
2115 Settings.LibraryTree);
2116 printf ("Settings.MakeProgram = \"%s\"\n",
2117 UNKNOWN (Settings.MakeProgram));
2118 printf ("Settings.GnetlistProgram = \"%s\"\n",
2119 UNKNOWN (Settings.GnetlistProgram));
2120 #endif
2122 gui->do_export (0);
2123 #if HAVE_DBUS
2124 pcb_dbus_finish();
2125 #endif
2127 pcb_main_uninit ();
2129 return (0);