Remove unused functions {LO,PV}TouchesLine() and their callbacks
[geda-pcb/pcjc2.git] / src / command.c
blob8055ec80aaa9d84d41736caa0b592925ac3e86b5
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996, 2005 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
27 /* executes commands from user
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include <stdlib.h>
35 #ifdef HAVE_STRING_H
36 #include <string.h>
37 #endif
38 #include <ctype.h>
40 #include "global.h"
41 #include "action.h"
42 #include "buffer.h"
43 #include "command.h"
44 #include "data.h"
45 #include "djopt.h"
46 #include "error.h"
47 #include "file.h"
48 #include "mymem.h"
49 #include "misc.h"
50 #include "rats.h"
51 #include "set.h"
52 #include "vendor.h"
54 #ifdef HAVE_LIBDMALLOC
55 #include <dmalloc.h>
56 #endif
58 /* ---------------------------------------------------------------------- */
60 /* %start-doc actions 00macros
62 @macro colonaction
64 This is one of the command box helper actions. While it is a regular
65 action and can be used like any other action, its name and syntax are
66 optimized for use with the command box (@code{:}) and thus the syntax
67 is documented for that purpose.
69 @end macro
71 %end-doc */
73 /* ---------------------------------------------------------------------- */
75 static const char h_syntax[] = "h";
77 static const char h_help[] = "Print a help message for commands.";
79 /* %start-doc actions h
81 @colonaction
83 %end-doc */
85 static int
86 CommandHelp (int argc, char **argv, Coord x, Coord y)
88 Message ("following commands are supported:\n"
89 " Command() execute an action command (too numerous to list)\n"
90 " see the manual for the list of action commands\n"
91 " h display this help message\n"
92 " l [file] load layout\n"
93 " le [file] load element to buffer\n"
94 " m [file] load layout to buffer (merge)\n"
95 " q quits the application\n"
96 " q! quits without save warning\n"
97 " rn [file] read in a net-list file\n"
98 " s [file] save layout\n"
99 " w [file] save layout\n"
100 " wq [file] save layout and quit\n");
101 return (0);
104 /* ---------------------------------------------------------------------- */
106 static const char l_syntax[] = "l [name]";
108 static const char l_help[] = "Loads layout data.";
110 /* %start-doc actions l
112 Loads a new datafile (layout) and, if confirmed, overwrites any
113 existing unsaved data. The filename and the searchpath
114 (@emph{filePath}) are passed to the command defined by
115 @emph{fileCommand}. If no filename is specified a file select box
116 will popup.
118 @colonaction
120 %end-doc */
122 static int
123 CommandLoadLayout (int argc, char **argv, Coord x, Coord y)
125 char *filename, *name = NULL;
127 switch (argc)
129 case 1: /* filename is passed in commandline */
130 filename = argv[0];
131 break;
133 default: /* usage */
134 Message ("Usage: l [name]\n loads layout data\n");
135 return (1);
138 if (!PCB->Changed || gui->confirm_dialog ("OK to override layout data?", 0))
139 LoadPCB (filename);
140 free (name);
141 return (0);
144 /* --------------------------------------------------------------------------- */
146 static const char le_syntax[] = "le [name]";
148 static const char le_help[] = "Loads an element into the current buffer.";
150 /* %start-doc actions le
152 The filename and the searchpath (@emph{elementPath}) are passed to the
153 command defined by @emph{elementCommand}. If no filename is specified
154 a file select box will popup.
156 @colonaction
158 %end-doc */
160 static int
161 CommandLoadElementToBuffer (int argc, char **argv, Coord x, Coord y)
163 char *filename;
165 switch (argc)
167 case 1: /* filename is passed in commandline */
168 filename = argv[0];
169 if (filename && LoadElementToBuffer (PASTEBUFFER, filename, true))
170 SetMode (PASTEBUFFER_MODE);
171 break;
173 default: /* usage */
174 Message (false, "Usage: le [name]\n loads element data to buffer\n");
175 return (1);
177 return (0);
180 /* --------------------------------------------------------------------------- */
182 static const char m_syntax[] = "m [name]";
184 static const char m_help[] = "Loads a layout into the current buffer.";
186 /* %start-doc actions m
188 The filename and the searchpath (@emph{filePath}) are passed to the
189 command defined by @emph{fileCommand}.
190 If no filename is specified a file select box will popup.
192 @colonaction
194 %end-doc */
196 static int
197 CommandLoadLayoutToBuffer (int argc, char **argv, Coord x, Coord y)
199 char *filename;
201 switch (argc)
203 case 1: /* filename is passed in commandline */
204 filename = argv[0];
205 if (filename && LoadLayoutToBuffer (PASTEBUFFER, filename))
206 SetMode (PASTEBUFFER_MODE);
207 break;
209 default: /* usage */
210 Message ("Usage: m [name]\n loads layout data to buffer\n");
211 return (1);
213 return (0);
216 /* --------------------------------------------------------------------------- */
218 static const char q_syntax[] = "q";
220 static const char q_help[] = "Quits the application after confirming.";
222 /* %start-doc actions q
224 If you have unsaved changes, you will be prompted to confirm (or
225 save) before quitting.
227 @colonaction
229 %end-doc */
231 static int
232 CommandQuit (int argc, char **argv, Coord x, Coord y)
234 if (!PCB->Changed || gui->close_confirm_dialog () == HID_CLOSE_CONFIRM_OK)
235 QuitApplication ();
236 return 0;
239 static const char qreally_syntax[] = "q!";
241 static const char qreally_help[] =
242 "Quits the application without confirming.";
244 /* %start-doc actions q!
246 Note that this command neither saves your data nor prompts for
247 confirmation.
249 @colonaction
251 %end-doc */
253 static int
254 CommandReallyQuit (int argc, char **argv, Coord x, Coord y)
256 QuitApplication ();
257 return 0;
260 /* ---------------------------------------------------------------------- */
262 static const char rn_syntax[] = "rn [name]";
264 static const char rn_help[] = "Reads netlist.";
266 /* %start-doc actions rn
268 If no filename is given a file select box will pop up. The file is
269 read via the command defined by the @emph{RatCommand} resource. The
270 command must send its output to @emph{stdout}.
272 Netlists are used for generating rat's nests (see @ref{Rats Nest}) and
273 for verifying the board layout (which is also accomplished by the
274 @emph{Ratsnest} command).
276 @colonaction
278 %end-doc */
280 static int
281 CommandLoadNetlist (int argc, char **argv, Coord x, Coord y)
283 char *filename, *name = NULL;
285 switch (argc)
287 case 1: /* filename is passed in commandline */
288 filename = argv[0];
289 break;
291 default: /* usage */
292 Message ("Usage: rn [name]\n reads in a netlist file\n");
293 return (1);
295 if (PCB->Netlistname)
296 free (PCB->Netlistname);
297 PCB->Netlistname = StripWhiteSpaceAndDup (filename);
298 free (name);
299 return (0);
302 /* ---------------------------------------------------------------------- */
304 static const char s_syntax[] = "s [name]";
306 static const char s_help[] = "Saves layout data.";
308 /* %start-doc actions s
310 Data and the filename are passed to the command defined by the
311 resource @emph{saveCommand}. It must read the layout data from
312 @emph{stdin}. If no filename is entered, either the last one is used
313 again or, if it is not available, a file select box will pop up.
315 @colonaction
317 %end-doc */
319 static const char w_syntax[] = "w [name]";
321 static const char w_help[] = "Saves layout data.";
323 /* %start-doc actions w
325 This commands has been added for the convenience of @code{vi} users
326 and has the same functionality as @code{s}.
328 @colonaction
330 %end-doc */
332 static int
333 CommandSaveLayout (int argc, char **argv, Coord x, Coord y)
335 switch (argc)
337 case 0:
338 if (PCB->Filename)
340 if (SavePCB (PCB->Filename) == 0)
341 SetChangedFlag (false);
343 else
344 Message ("No filename to save to yet\n");
345 break;
347 case 1:
348 if (SavePCB (argv[0]) == 0)
350 SetChangedFlag (false);
351 free (PCB->Filename);
352 PCB->Filename = strdup (argv[0]);
353 if (gui->notify_filename_changed != NULL)
354 gui->notify_filename_changed ();
356 break;
358 default:
359 Message ("Usage: s [name] | w [name]\n saves layout data\n");
360 return (1);
362 return (0);
365 /* --------------------------------------------------------------------------- */
367 static const char wq_syntax[] = "wq";
369 static const char wq_help[] = "Saves the layout data and quits.";
371 /* %start-doc actions wq
373 This command has been added for the convenience of @code{vi} users and
374 has the same functionality as @code{s} combined with @code{q}.
376 @colonaction
378 %end-doc */
380 static int
381 CommandSaveLayoutAndQuit (int argc, char **argv, Coord x, Coord y)
383 if (!CommandSaveLayout (argc, argv, x, y))
384 return CommandQuit (0, 0, 0, 0);
385 return (1);
388 /* --------------------------------------------------------------------------- */
390 HID_Action command_action_list[] = {
391 {"h", 0, CommandHelp,
392 h_help, h_syntax}
394 {"l", 0, CommandLoadLayout,
395 l_help, l_syntax}
397 {"le", 0, CommandLoadElementToBuffer,
398 le_help, le_syntax}
400 {"m", 0, CommandLoadLayoutToBuffer,
401 m_help, m_syntax}
403 {"q", 0, CommandQuit,
404 q_help, q_syntax}
406 {"q!", 0, CommandReallyQuit,
407 qreally_help, qreally_syntax}
409 {"rn", 0, CommandLoadNetlist,
410 rn_help, rn_syntax}
412 {"s", 0, CommandSaveLayout,
413 s_help, s_syntax}
415 {"w", 0, CommandSaveLayout,
416 w_help, w_syntax}
418 {"wq", 0, CommandSaveLayoutAndQuit,
419 wq_help, wq_syntax}
423 REGISTER_ACTIONS (command_action_list)