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
54 #ifdef HAVE_LIBDMALLOC
58 /* ---------------------------------------------------------------------- */
60 /* %start-doc actions 00macros
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.
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
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");
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
123 CommandLoadLayout (int argc
, char **argv
, Coord x
, Coord y
)
125 char *filename
, *name
= NULL
;
129 case 1: /* filename is passed in commandline */
134 Message ("Usage: l [name]\n loads layout data\n");
138 if (!PCB
->Changed
|| gui
->confirm_dialog ("OK to override layout data?", 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.
161 CommandLoadElementToBuffer (int argc
, char **argv
, Coord x
, Coord y
)
167 case 1: /* filename is passed in commandline */
169 if (filename
&& LoadElementToBuffer (PASTEBUFFER
, filename
, true))
170 SetMode (PASTEBUFFER_MODE
);
174 Message (false, "Usage: le [name]\n loads element data to buffer\n");
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.
197 CommandLoadLayoutToBuffer (int argc
, char **argv
, Coord x
, Coord y
)
203 case 1: /* filename is passed in commandline */
205 if (filename
&& LoadLayoutToBuffer (PASTEBUFFER
, filename
))
206 SetMode (PASTEBUFFER_MODE
);
210 Message ("Usage: m [name]\n loads layout data to buffer\n");
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.
232 CommandQuit (int argc
, char **argv
, Coord x
, Coord y
)
234 if (!PCB
->Changed
|| gui
->close_confirm_dialog () == HID_CLOSE_CONFIRM_OK
)
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
254 CommandReallyQuit (int argc
, char **argv
, Coord x
, Coord y
)
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).
281 CommandLoadNetlist (int argc
, char **argv
, Coord x
, Coord y
)
283 char *filename
, *name
= NULL
;
287 case 1: /* filename is passed in commandline */
292 Message ("Usage: rn [name]\n reads in a netlist file\n");
295 if (PCB
->Netlistname
)
296 free (PCB
->Netlistname
);
297 PCB
->Netlistname
= StripWhiteSpaceAndDup (filename
);
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.
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}.
333 CommandSaveLayout (int argc
, char **argv
, Coord x
, Coord y
)
340 if (SavePCB (PCB
->Filename
) == 0)
341 SetChangedFlag (false);
344 Message ("No filename to save to yet\n");
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 ();
359 Message ("Usage: s [name] | w [name]\n saves layout data\n");
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}.
381 CommandSaveLayoutAndQuit (int argc
, char **argv
, Coord x
, Coord y
)
383 if (!CommandSaveLayout (argc
, argv
, x
, y
))
384 return CommandQuit (0, 0, 0, 0);
388 /* --------------------------------------------------------------------------- */
390 HID_Action command_action_list
[] = {
391 {"h", 0, CommandHelp
,
394 {"l", 0, CommandLoadLayout
,
397 {"le", 0, CommandLoadElementToBuffer
,
400 {"m", 0, CommandLoadLayoutToBuffer
,
403 {"q", 0, CommandQuit
,
406 {"q!", 0, CommandReallyQuit
,
407 qreally_help
, qreally_syntax
}
409 {"rn", 0, CommandLoadNetlist
,
412 {"s", 0, CommandSaveLayout
,
415 {"w", 0, CommandSaveLayout
,
418 {"wq", 0, CommandSaveLayoutAndQuit
,
423 REGISTER_ACTIONS (command_action_list
)