44
50
#include "fileselect.h"
57
#ifdef HAVE_LIBDMALLOC
61
RCSID("$Id: command.c,v 1.4 2004/08/30 02:52:04 danmc Exp $");
50
63
/* ---------------------------------------------------------------------------
53
typedef int (*FunctionTypePtr)(void);
66
typedef int (*FunctionTypePtr) (void);
57
char *Text; /* commandstring */
58
FunctionTypePtr Function; /* function pointer */
59
} CommandType, *CommandTypePtr;
70
char *Text; /* commandstring */
71
FunctionTypePtr Function; /* function pointer */
73
CommandType, *CommandTypePtr;
61
75
/* ---------------------------------------------------------------------------
64
static int CommandCallAction(void);
65
static int CommandLoadElementToBuffer(void);
66
static int CommandLoadLayoutToBuffer(void);
67
static int CommandLoadLayout(void);
68
static int CommandLoadNetlist(void);
69
static int CommandSaveLayout(void);
70
static int CommandSaveLayoutAndQuit(void);
71
static int CommandQuit(void);
72
static int CommandHelp(void);
73
static int SetArgcArgv(char *);
78
static int CommandCallAction (void);
79
static int CommandLoadElementToBuffer (void);
80
static int CommandLoadLayoutToBuffer (void);
81
static int CommandLoadLayout (void);
82
static int CommandLoadNetlist (void);
83
static int CommandSaveLayout (void);
84
static int CommandSaveLayoutAndQuit (void);
85
static int CommandQuit (void);
86
static int CommandHelp (void);
87
static int SetArgcArgv (char *);
75
89
/* ---------------------------------------------------------------------------
76
90
* some local identifiers
78
static CommandType Command[] = {
80
{ "le", CommandLoadElementToBuffer },
81
{ "m", CommandLoadLayoutToBuffer },
82
{ "rn", CommandLoadNetlist },
83
{ "s", CommandSaveLayout },
84
{ "w", CommandSaveLayout },
85
{ "wq", CommandSaveLayoutAndQuit },
87
{ "q!", CommandQuit },
88
{ "l", CommandLoadLayout }};
92
static CommandType Command[] = {
94
{"le", CommandLoadElementToBuffer},
95
{"m", CommandLoadLayoutToBuffer},
96
{"rn", CommandLoadNetlist},
97
{"s", CommandSaveLayout},
98
{"w", CommandSaveLayout},
99
{"wq", CommandSaveLayoutAndQuit},
102
{"l", CommandLoadLayout}
90
static char **argv; /* command-line of arguments */
105
static char **argv; /* command-line of arguments */
93
108
/* ---------------------------------------------------------------------------
94
109
* quits the application after confirming
97
static int CommandQuit(void)
101
Message("Usage: q\n quits the application\n"
103
"quits without saving or warning for its need\n");
106
if (strcmp(argv[0], "q!") == 0)
108
if (!PCB->Changed || ConfirmDialog("OK to lose data ?"))
117
Message ("Usage: q\n quits the application\n"
119
"quits without saving or warning for its need\n");
122
if (strcasecmp (argv[0], "q!") == 0)
124
if (!PCB->Changed || ConfirmDialog ("OK to lose data ?"))
114
130
/* ---------------------------------------------------------------------------
115
131
* loads an element into the current buffer
116
132
* syntax: le [name]
118
static int CommandLoadElementToBuffer(void)
135
CommandLoadElementToBuffer (void)
124
case 1: /* open fileselect box */
125
filename = FileSelectBox("load element to buffer:", NULL,
141
case 1: /* open fileselect box */
142
filename = FileSelectBox ("load element to buffer:", NULL,
126
143
Settings.ElementPath);
127
if (filename && LoadElementToBuffer(PASTEBUFFER, filename, True))
128
SetMode(PASTEBUFFER_MODE);
131
case 2: /* filename is passed in commandline */
133
if (filename && LoadElementToBuffer(PASTEBUFFER, filename, True))
134
SetMode(PASTEBUFFER_MODE);
138
Message(False,"Usage: le [name]\n loads element data to buffer\n");
144
if (filename && LoadElementToBuffer (PASTEBUFFER, filename, True))
145
SetMode (PASTEBUFFER_MODE);
148
case 2: /* filename is passed in commandline */
150
if (filename && LoadElementToBuffer (PASTEBUFFER, filename, True))
151
SetMode (PASTEBUFFER_MODE);
155
Message (False, "Usage: le [name]\n loads element data to buffer\n");
144
161
/* ---------------------------------------------------------------------------
145
162
* loads a layout into the current buffer
146
163
* syntax: m [name]
148
static int CommandLoadLayoutToBuffer(void)
166
CommandLoadLayoutToBuffer (void)
154
case 1: /* open fileselect box */
155
filename = FileSelectBox("load layout to buffer:", NULL,
172
case 1: /* open fileselect box */
173
filename = FileSelectBox ("load layout to buffer:", NULL,
156
174
Settings.FilePath);
157
if (filename && LoadLayoutToBuffer(PASTEBUFFER, filename))
158
SetMode(PASTEBUFFER_MODE);
161
case 2: /* filename is passed in commandline */
163
if (filename && LoadLayoutToBuffer(PASTEBUFFER, filename))
164
SetMode(PASTEBUFFER_MODE);
168
Message("Usage: m [name]\n loads layout data to buffer\n");
175
if (filename && LoadLayoutToBuffer (PASTEBUFFER, filename))
176
SetMode (PASTEBUFFER_MODE);
179
case 2: /* filename is passed in commandline */
181
if (filename && LoadLayoutToBuffer (PASTEBUFFER, filename))
182
SetMode (PASTEBUFFER_MODE);
186
Message ("Usage: m [name]\n loads layout data to buffer\n");
174
192
/* ---------------------------------------------------------------------------
175
193
* saves the layout data and quits
177
static int CommandSaveLayoutAndQuit(void)
196
CommandSaveLayoutAndQuit (void)
179
if (argc != 1 && argc != 2)
181
Message("Usage: wq [name]\n saves layout data and quits\n");
184
if (!CommandSaveLayout())
186
if (!PCB->Changed || ConfirmDialog("OK to lose data ?"))
198
if (argc != 1 && argc != 2)
200
Message ("Usage: wq [name]\n saves layout data and quits\n");
203
if (!CommandSaveLayout ())
205
if (!PCB->Changed || ConfirmDialog ("OK to lose data ?"))
193
212
/* ----------------------------------------------------------------------
194
213
* saves layout data
197
static int CommandSaveLayout(void)
217
CommandSaveLayout (void)
223
case 1: /* query name if necessary */
203
case 1: /* query name if necessary */
206
filename = FileSelectBox("save layout as:", NULL,
212
SavePCB(PCB->Filename);
220
Message("Usage: s [name] | w [name]\n saves layout data\n");
226
filename = FileSelectBox ("save layout as:", NULL,
232
SavePCB (PCB->Filename);
240
Message ("Usage: s [name] | w [name]\n saves layout data\n");
226
246
/* ----------------------------------------------------------------------
227
247
* loads layout data
228
248
* syntax: l [name]
230
static int CommandLoadLayout(void)
251
CommandLoadLayout (void)
236
case 1: /* open fileselect box */
237
filename = FileSelectBox("load file:", NULL, Settings.FilePath);
242
case 2: /* filename is passed in commandline */
247
Message("Usage: l [name]\n loads layout data\n");
251
if (!PCB->Changed || ConfirmDialog("OK to override layout data?"))
257
case 1: /* open fileselect box */
258
filename = FileSelectBox ("load file:", NULL, Settings.FilePath);
263
case 2: /* filename is passed in commandline */
268
Message ("Usage: l [name]\n loads layout data\n");
272
if (!PCB->Changed || ConfirmDialog ("OK to override layout data?"))
256
277
/* ----------------------------------------------------------------------
258
279
* syntax: rn [name]
260
static int CommandLoadNetlist(void)
282
CommandLoadNetlist (void)
266
case 1: /* open fileselect box */
267
filename = FileSelectBox("load file:", NULL, Settings.FilePath);
272
case 2: /* filename is passed in commandline */
277
Message("Usage: rn [name]\n reads in a netlist file\n");
280
if (PCB->Netlistname)
281
SaveFree(PCB->Netlistname);
282
PCB->Netlistname = StripWhiteSpaceAndDup(filename);
288
case 1: /* open fileselect box */
289
filename = FileSelectBox ("load file:", NULL, Settings.FilePath);
294
case 2: /* filename is passed in commandline */
299
Message ("Usage: rn [name]\n reads in a netlist file\n");
302
if (PCB->Netlistname)
303
SaveFree (PCB->Netlistname);
304
PCB->Netlistname = StripWhiteSpaceAndDup (filename);
286
308
/* ----------------------------------------------------------------------
287
309
* Send an action command
289
static int CommandCallAction(void)
312
CommandCallAction (void)
291
XtCallActionProc(Output.Porthole, argv[0], (XEvent *) NULL, &argv[1], argc - 1);
314
CallActionProc (Output.Output, argv[0], (XEvent *) NULL, &argv[1],
295
319
/* ----------------------------------------------------------------------
296
320
* print a help message for commands
298
static int CommandHelp()
300
Message("following commands are supported:\n"
301
" Command() execute an action command (too numerous to list)\n"
302
" see the manual for the list of action commands\n"
303
" h display this help message\n"
304
" l [file] load layout\n"
305
" le [file] load element to buffer\n"
306
" m [file] load layout to buffer (merge)\n"
307
" q quits the application\n"
308
" q! quits without save warning\n"
309
" rn [file] read in a net-list file\n"
310
" s [file] save layout\n"
311
" w [file] save layout\n"
312
" wq [file] save layout and quit\n");
325
Message ("following commands are supported:\n"
326
" Command() execute an action command (too numerous to list)\n"
327
" see the manual for the list of action commands\n"
328
" h display this help message\n"
329
" l [file] load layout\n"
330
" le [file] load element to buffer\n"
331
" m [file] load layout to buffer (merge)\n"
332
" q quits the application\n"
333
" q! quits without save warning\n"
334
" rn [file] read in a net-list file\n"
335
" s [file] save layout\n"
336
" w [file] save layout\n"
337
" wq [file] save layout and quit\n");
316
341
/* ----------------------------------------------------------------------
317
342
* split commandline and fill argv/argc
319
static int SetArgcArgv(char *Line)
345
SetArgcArgv (char *Line)
321
static int maxcount = 0;
347
static int maxcount = 0;
324
for(argc = 0, p = strtok(Line, " \t;,()"); p; p = strtok(NULL, " \t;,()"))
350
for (argc = 0, p = strtok (Line, " \t;,()"); p;
351
p = strtok (NULL, " \t;,()"))
353
/* allocate more memory */
354
if (argc >= maxcount)
326
/* allocate more memory */
327
if (argc >= maxcount)
330
argv = (char **) MyRealloc(argv, maxcount*sizeof(char *),
357
argv = (char **) MyRealloc (argv, maxcount * sizeof (char *),
338
365
/* ---------------------------------------------------------------------------
339
366
* command is passed in, memory is already allocated
341
void ExecuteUserCommand(char *CommandLine)
369
ExecuteUserCommand (char *CommandLine)
345
if (SetArgcArgv(CommandLine))
347
/* scan command list */
348
for (i = 0; i < ENTRIES(Command); i++)
349
if (!strcmp(Command[i].Text, argv[0]))
351
if (i == ENTRIES(Command))
352
/* it wasn't listed, it must have been an action command */
355
if (Command[i].Function())
356
XBell(Dpy, Settings.Volume);
359
XBell(Dpy, Settings.Volume);
373
if (SetArgcArgv (CommandLine))
375
/* scan command list */
376
for (i = 0; i < ENTRIES (Command); i++)
377
if (!strcasecmp (Command[i].Text, argv[0]))
379
if (i == ENTRIES (Command))
380
/* it wasn't listed, it must have been an action command */
381
CommandCallAction ();
382
else if (Command[i].Function ())
383
Beep (Settings.Volume);
386
Beep (Settings.Volume);