Introduce POLYGONHOLE_MODE for creating holes in polygons
[geda-pcb/gde.git] / src / command.c
blobb41263beb6800e1d7138bd086fbadd711cf537b9
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Contact addresses for paper mail and Email:
24 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
25 * Thomas.Nau@rz.uni-ulm.de
29 /* executes commands from user
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
36 #include <stdlib.h>
37 #ifdef HAVE_STRING_H
38 #include <string.h>
39 #endif
40 #include <ctype.h>
42 #include "global.h"
43 #include "action.h"
44 #include "buffer.h"
45 #include "command.h"
46 #include "data.h"
47 #include "djopt.h"
48 #include "error.h"
49 #include "file.h"
50 #include "mymem.h"
51 #include "misc.h"
52 #include "rats.h"
53 #include "set.h"
54 #include "vendor.h"
56 #ifdef HAVE_LIBDMALLOC
57 #include <dmalloc.h>
58 #endif
60 RCSID ("$Id$");
62 /* ---------------------------------------------------------------------- */
64 /* %start-doc actions 00macros
66 @macro colonaction
68 This is one of the command box helper actions. While it is a regular
69 action and can be used like any other action, its name and syntax are
70 optimized for use with the command box (@code{:}) and thus the syntax
71 is documented for that purpose.
73 @end macro
75 %end-doc */
77 /* ---------------------------------------------------------------------- */
79 static const char h_syntax[] = "h";
81 static const char h_help[] = "Print a help message for commands.";
83 /* %start-doc actions h
85 @colonaction
87 %end-doc */
89 static int
90 CommandHelp (int argc, char **argv, int x, int y)
92 Message ("following commands are supported:\n"
93 " Command() execute an action command (too numerous to list)\n"
94 " see the manual for the list of action commands\n"
95 " h display this help message\n"
96 " l [file] load layout\n"
97 " le [file] load element to buffer\n"
98 " m [file] load layout to buffer (merge)\n"
99 " q quits the application\n"
100 " q! quits without save warning\n"
101 " rn [file] read in a net-list file\n"
102 " s [file] save layout\n"
103 " w [file] save layout\n"
104 " wq [file] save layout and quit\n");
105 return (0);
108 /* ---------------------------------------------------------------------- */
110 static const char l_syntax[] = "l [name]";
112 static const char l_help[] = "Loads layout data.";
114 /* %start-doc actions l
116 Loads a new datafile (layout) and, if confirmed, overwrites any
117 existing unsaved data. The filename and the searchpath
118 (@emph{filePath}) are passed to the command defined by
119 @emph{fileCommand}. If no filename is specified a file select box
120 will popup.
122 @colonaction
124 %end-doc */
126 static int
127 CommandLoadLayout (int argc, char **argv, int x, int y)
129 char *filename, *name = NULL;
131 switch (argc)
133 case 1: /* filename is passed in commandline */
134 filename = argv[0];
135 break;
137 default: /* usage */
138 Message ("Usage: l [name]\n loads layout data\n");
139 return (1);
142 if (!PCB->Changed || gui->confirm_dialog ("OK to override layout data?", 0))
143 LoadPCB (filename);
144 free (name);
145 return (0);
148 /* --------------------------------------------------------------------------- */
150 static const char le_syntax[] = "le [name]";
152 static const char le_help[] = "Loads an element into the current buffer.";
154 /* %start-doc actions le
156 The filename and the searchpath (@emph{elementPath}) are passed to the
157 command defined by @emph{elementCommand}. If no filename is specified
158 a file select box will popup.
160 @colonaction
162 %end-doc */
164 static int
165 CommandLoadElementToBuffer (int argc, char **argv, int x, int y)
167 char *filename;
169 switch (argc)
171 case 1: /* filename is passed in commandline */
172 filename = argv[0];
173 if (filename && LoadElementToBuffer (PASTEBUFFER, filename, true))
174 SetMode (PASTEBUFFER_MODE);
175 break;
177 default: /* usage */
178 Message (false, "Usage: le [name]\n loads element data to buffer\n");
179 return (1);
181 return (0);
184 /* --------------------------------------------------------------------------- */
186 static const char m_syntax[] = "m [name]";
188 static const char m_help[] = "Loads a layout into the current buffer.";
190 /* %start-doc actions m
192 The filename and the searchpath (@emph{filePath}) are passed to the
193 command defined by @emph{fileCommand}.
194 If no filename is specified a file select box will popup.
196 @colonaction
198 %end-doc */
200 static int
201 CommandLoadLayoutToBuffer (int argc, char **argv, int x, int y)
203 char *filename;
205 switch (argc)
207 case 1: /* filename is passed in commandline */
208 filename = argv[0];
209 if (filename && LoadLayoutToBuffer (PASTEBUFFER, filename))
210 SetMode (PASTEBUFFER_MODE);
211 break;
213 default: /* usage */
214 Message ("Usage: m [name]\n loads layout data to buffer\n");
215 return (1);
217 return (0);
220 /* --------------------------------------------------------------------------- */
222 static const char q_syntax[] = "q";
224 static const char q_help[] = "Quits the application after confirming.";
226 /* %start-doc actions q
228 If you have unsaved changes, you will be prompted to confirm (or
229 save) before quitting.
231 @colonaction
233 %end-doc */
235 static int
236 CommandQuit (int argc, char **argv, int x, int y)
238 if (!PCB->Changed || gui->close_confirm_dialog () == HID_CLOSE_CONFIRM_OK)
239 QuitApplication ();
240 return 0;
243 static const char qreally_syntax[] = "q!";
245 static const char qreally_help[] =
246 "Quits the application without confirming.";
248 /* %start-doc actions q!
250 Note that this command neither saves your data nor prompts for
251 confirmation.
253 @colonaction
255 %end-doc */
257 static int
258 CommandReallyQuit (int argc, char **argv, int x, int y)
260 QuitApplication ();
261 return 0;
264 /* ---------------------------------------------------------------------- */
266 static const char rn_syntax[] = "rn [name]";
268 static const char rn_help[] = "Reads netlist.";
270 /* %start-doc actions rn
272 If no filename is given a file select box will pop up. The file is
273 read via the command defined by the @emph{RatCommand} resource. The
274 command must send its output to @emph{stdout}.
276 Netlists are used for generating rat's nests (see @ref{Rats Nest}) and
277 for verifying the board layout (which is also accomplished by the
278 @emph{Ratsnest} command).
280 @colonaction
282 %end-doc */
284 static int
285 CommandLoadNetlist (int argc, char **argv, int x, int y)
287 char *filename, *name = NULL;
289 switch (argc)
291 case 1: /* filename is passed in commandline */
292 filename = argv[0];
293 break;
295 default: /* usage */
296 Message ("Usage: rn [name]\n reads in a netlist file\n");
297 return (1);
299 if (PCB->Netlistname)
300 SaveFree (PCB->Netlistname);
301 PCB->Netlistname = StripWhiteSpaceAndDup (filename);
302 free (name);
303 return (0);
306 /* ---------------------------------------------------------------------- */
308 static const char s_syntax[] = "s [name]";
310 static const char s_help[] = "Saves layout data.";
312 /* %start-doc actions s
314 Data and the filename are passed to the command defined by the
315 resource @emph{saveCommand}. It must read the layout data from
316 @emph{stdin}. If no filename is entered, either the last one is used
317 again or, if it is not available, a file select box will pop up.
319 @colonaction
321 %end-doc */
323 static const char w_syntax[] = "w [name]";
325 static const char w_help[] = "Saves layout data.";
327 /* %start-doc actions w
329 This commands has been added for the convenience of @code{vi} users
330 and has the same functionality as @code{s}.
332 @colonaction
334 %end-doc */
336 static int
337 CommandSaveLayout (int argc, char **argv, int x, int y)
339 switch (argc)
341 case 0:
342 if (PCB->Filename)
343 SavePCB (PCB->Filename);
344 else
345 Message ("No filename to save to yet\n");
346 break;
348 case 1:
349 SavePCB (argv[0]);
350 break;
352 default:
353 Message ("Usage: s [name] | w [name]\n saves layout data\n");
354 return (1);
356 return (0);
359 /* --------------------------------------------------------------------------- */
361 static const char wq_syntax[] = "wq";
363 static const char wq_help[] = "Saves the layout data and quits.";
365 /* %start-doc actions wq
367 This command has been added for the convenience of @code{vi} users and
368 has the same functionality as @code{s} combined with @code{q}.
370 @colonaction
372 %end-doc */
374 static int
375 CommandSaveLayoutAndQuit (int argc, char **argv, int x, int y)
377 if (!CommandSaveLayout (argc, argv, x, y))
378 return CommandQuit (0, 0, 0, 0);
379 return (1);
382 /* --------------------------------------------------------------------------- */
384 HID_Action command_action_list[] = {
385 {"h", 0, CommandHelp,
386 h_help, h_syntax}
388 {"l", 0, CommandLoadLayout,
389 l_help, l_syntax}
391 {"le", 0, CommandLoadElementToBuffer,
392 le_help, le_syntax}
394 {"m", 0, CommandLoadLayoutToBuffer,
395 m_help, m_syntax}
397 {"q", 0, CommandQuit,
398 q_help, q_syntax}
400 {"q!", 0, CommandReallyQuit,
401 qreally_help, qreally_syntax}
403 {"rn", 0, CommandLoadNetlist,
404 rn_help, rn_syntax}
406 {"s", 0, CommandSaveLayout,
407 s_help, s_syntax}
409 {"w", 0, CommandSaveLayout,
410 w_help, w_syntax}
412 {"wq", 0, CommandSaveLayoutAndQuit,
413 wq_help, wq_syntax}
417 REGISTER_ACTIONS (command_action_list)