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
56 #ifdef HAVE_LIBDMALLOC
62 /* ---------------------------------------------------------------------- */
64 /* %start-doc actions 00macros
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.
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
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");
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
127 CommandLoadLayout (int argc
, char **argv
, int x
, int y
)
129 char *filename
, *name
= NULL
;
133 case 1: /* filename is passed in commandline */
138 Message ("Usage: l [name]\n loads layout data\n");
142 if (!PCB
->Changed
|| gui
->confirm_dialog ("OK to override layout data?", 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.
165 CommandLoadElementToBuffer (int argc
, char **argv
, int x
, int y
)
171 case 1: /* filename is passed in commandline */
173 if (filename
&& LoadElementToBuffer (PASTEBUFFER
, filename
, true))
174 SetMode (PASTEBUFFER_MODE
);
178 Message (false, "Usage: le [name]\n loads element data to buffer\n");
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.
201 CommandLoadLayoutToBuffer (int argc
, char **argv
, int x
, int y
)
207 case 1: /* filename is passed in commandline */
209 if (filename
&& LoadLayoutToBuffer (PASTEBUFFER
, filename
))
210 SetMode (PASTEBUFFER_MODE
);
214 Message ("Usage: m [name]\n loads layout data to buffer\n");
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.
236 CommandQuit (int argc
, char **argv
, int x
, int y
)
238 if (!PCB
->Changed
|| gui
->close_confirm_dialog () == HID_CLOSE_CONFIRM_OK
)
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
258 CommandReallyQuit (int argc
, char **argv
, int x
, int y
)
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).
285 CommandLoadNetlist (int argc
, char **argv
, int x
, int y
)
287 char *filename
, *name
= NULL
;
291 case 1: /* filename is passed in commandline */
296 Message ("Usage: rn [name]\n reads in a netlist file\n");
299 if (PCB
->Netlistname
)
300 free (PCB
->Netlistname
);
301 PCB
->Netlistname
= StripWhiteSpaceAndDup (filename
);
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.
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}.
337 CommandSaveLayout (int argc
, char **argv
, int x
, int y
)
343 SavePCB (PCB
->Filename
);
345 Message ("No filename to save to yet\n");
353 Message ("Usage: s [name] | w [name]\n saves layout data\n");
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}.
375 CommandSaveLayoutAndQuit (int argc
, char **argv
, int x
, int y
)
377 if (!CommandSaveLayout (argc
, argv
, x
, y
))
378 return CommandQuit (0, 0, 0, 0);
382 /* --------------------------------------------------------------------------- */
384 HID_Action command_action_list
[] = {
385 {"h", 0, CommandHelp
,
388 {"l", 0, CommandLoadLayout
,
391 {"le", 0, CommandLoadElementToBuffer
,
394 {"m", 0, CommandLoadLayoutToBuffer
,
397 {"q", 0, CommandQuit
,
400 {"q!", 0, CommandReallyQuit
,
401 qreally_help
, qreally_syntax
}
403 {"rn", 0, CommandLoadNetlist
,
406 {"s", 0, CommandSaveLayout
,
409 {"w", 0, CommandSaveLayout
,
412 {"wq", 0, CommandSaveLayoutAndQuit
,
417 REGISTER_ACTIONS (command_action_list
)