Debian Codegraph @

w4/commandmenu.c

raw
1 /* File: commandmenu.c
2 * Author: Ed Griffiths ([email protected])
3 * Copyright (c) J Thierry-Mieg and R Durbin, 2000
4 *-------------------------------------------------------------------
5 * Acedb is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
19 *-------------------------------------------------------------------
20 * This file is part of the ACEDB genome database package, written by
21 * Richard Durbin (Sanger Centre, UK) [email protected], and
22 * Jean Thierry-Mieg (CRBM du CNRS, France) [email protected]
23 *
24 * Description: Handles the array of commands that can be interpreted
25 * by acedb.
26 * Contains the array describing the command.
27 * Returns an array of allowed commands for a given
28 * command/permissions set.
29 *
30 * Exported functions: See command_.h
31 * HISTORY:
32 * Last edited: May 24 12:02 2007 (edgrif)
33 * Created: Wed May 17 10:05:43 2000 (edgrif)
34 * CVS info: $Id: commandmenu.c,v 1.26 2007/06/06 10:34:22 edgrif Exp $
35 *-------------------------------------------------------------------
36 */
37
38 #include <wh/regular.h>
39 #include <wh/aceio.h>
40 #include <wh/status.h> /* For cmd line opts. */
41 #include <w4/command_.h>
42
43 /************************************************************/
44
45 static CmdFilespecArg getFlagFile(char **file_name, char *flag, char *curr_word,
46 ACEIN curr_string) ;
47 static CmdFilespecArg getNoFlagFile(char **file_name, char *curr_word,
48 CmdFilespecType filespec) ;
49
50
51 /************************************************************/
52
53
54 /* Some commands have unix/windows specific instructions to user etc... */
55 /* */
56 /* This is for the Parse cmd. */
57 #if defined(WIN32)
58 #define UNIX_OR_WINDOWS_INPUTFILES "parses pkzip (.zip) compressed or native ace files or stdin, until EOF"
59 #else
60 #define UNIX_OR_WINDOWS_INPUTFILES "parse an ace or ace.Z or ace.gz file or stdin, until ctrl-D or EOF"
61 #endif
62
63
64 /* This table defines the commands that can be executed against an acedb
65 * database.
66 * To add a new command you need to add an entry to this table checking
67 * _carefully_ that it does not clash with any entries here. You then need
68 * to add a new 'case' statement to handle the command in the big 'switch'
69 * statement in the aceCommandExecute routine in command.c, or add your own
70 * code to follow a call to aceCommandExecute to deal with the command (see
71 * aceserver.c or serverace.c for examples).
72 *
73 * There are permission levels and command types, each command should have
74 * just one of each set, e.g. READ and UNIVERSAL for command "find"
75 *
76 * All commands should be one of READ | WRITE | ADMIN
77 *
78 * All commands should be one of UNIVERSAL | NONSERVER | SERVER | GIF | RPC
79 * (note that RPC will be merged into SERVER once we stop supporting the
80 * rpc server)
81 *
82 * All commands should also specify their in/out file usage via
83 * */
84 static CHOIX choixMenu [] =
85 {
86 /* General commands. */
87 {CHOIX_UNIVERSAL, PERM_READ, -1,
88 "Quit : Exits the program. Any command abbreviates, $starts a subshell, until empty line",
89 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
90 {CHOIX_UNIVERSAL, PERM_READ, 402,
91 "system_list : issue the binary AceC system list dump",
92 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
93 {CHOIX_UNIVERSAL, PERM_READ, '?',
94 "? : List of commands",
95 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
96 {CHOIX_UNIVERSAL, PERM_READ,
97 'h', "Help : for further help",
98 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
99 {CHOIX_UNIVERSAL, PERM_WRITE, 'S',
100 "Save [-drop | -regain] :\n"
101 "\tSave current state otherwise the system saves every 600 seconds\n"
102 "\t-drop (default) drop write access after saving\n"
103 "\t-regain regain write access after saving\n",
104 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
105 {CHOIX_UNIVERSAL, PERM_WRITE, CMD_NOSAVE,
106 "NoSave [-stop | -start] :\n"
107 "\tStop or start all database saving, the -stop option prevents any saving by any command,\n"
108 "\tyou must use the -start option to turn saving on again.\n"
109 "\tThis is particularly useful if you want to test scripts that use tace for large\n"
110 "\tscale database updates without altering the database.\n"
111 "\t-stop (default) turn saving off\n"
112 "\t-start turn saving on.\n",
113 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
114 {CHOIX_UNIVERSAL, PERM_WRITE, CMD_WRITEACCESS,
115 "Writeaccess [-gain | -drop [save | nosave]] :\n"
116 "\tSet write access status\n"
117 "\t-gain (default) get write access\n"
118 "\t-drop lose write access, with or without saving.\n",
119 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
120 {CHOIX_NONSERVER, PERM_WRITE, '<',
121 "Read-only : Definitively drop present and future write access",
122 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
123 {CHOIX_UNIVERSAL, PERM_READ, '/',
124 "// : comment, do nothing",
125 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
126 {CHOIX_UNIVERSAL, PERM_READ, CMD_LASTMODIFIED,
127 "lastmodified : Returns time database was last modified as a string in acedb time format.",
128 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
129 {CHOIX_UNIVERSAL, PERM_READ, CMD_IDSUBMENU,
130 "ID <command> : id interface - type ID ? for commands",
131 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
132 {CHOIX_UNIVERSAL, PERM_READ, CMD_QUIET,
133 "quiet -on | -off :\n"
134 "\tTurn quiet mode on or off, when \"on\" commands produce only their output without any extra comments.\n"
135 "\t(Note the usual \"NNN Active Objects\" is no longer displayed, use the Count command.)\n"
136 "\tQuiet mode makes parsing command output easier because either the first line\n"
137 "\tis an acedb comment because the command failed or there are no acedb comments in the output.\n"
138 "\t-off (default) verbose output\n"
139 "\t-on no comments unless there is an error.\n",
140 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
141
142 {CHOIX_UNIVERSAL, PERM_READ,
143 'c', "Classes : Give a list of all the visible class names and how many objects they contain.",
144 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
145 {CHOIX_UNIVERSAL, PERM_READ,
146 'z', "Model [-jaq] model : Shows the model of a class or subtype, useful before Follow or Query commands",
147 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
148 {CHOIX_UNIVERSAL, PERM_READ,
149 'n', "Find class [name] : Creates a new list with all objects from class, optionally matching name",
150 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
151 {CHOIX_UNIVERSAL, PERM_READ,
152 't', "Follow Tag : i.e. Tag Author gives the authors of the papers of the current list",
153 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
154 {CHOIX_UNIVERSAL, PERM_READ, 'g', "Grep [-active] template : searches for *template* everywhere in the database except LongTexts",
155 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
156 {CHOIX_UNIVERSAL, PERM_READ, 'G', "LongGrep template : searches for *template* also in LongTexts",
157 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
158 {CHOIX_UNIVERSAL, PERM_READ, 'l',
159 "List [-h | -a | -p | -j | -x etc.] [-c max] [-f out_filename] [[-t] template]\n"
160 "\tlists names [matching template] of objects in active list in [human | ace | perl | java | xml] style\n"
161 "\tother styles: -J -k -K -xclass -xall -xnocontent",
162 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-f"}},
163 {CHOIX_UNIVERSAL, PERM_READ, 's',
164 "Show [-h | -a | -p | -j | -x etc.] [-T] [-b begin] [-c max] [-f out_filename] [-C] [[-t] tag]\n"
165 "\toutputs full object data for active list in [human | ace | perl | java] style\n"
166 "\t-T show time stamps, -b begin at object b, -c show max obj, -C ignore comments\n"
167 "\tthe last parameter restricts to the [tag]-branch\n"
168 "\tother styles: -P -J -k -K -xclass -xall -xnocontent",
169 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-f"}},
170 {CHOIX_UNIVERSAL, PERM_READ, 'i', "Is template : keeps in list only those objects whose name match the template",
171 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
172 {CHOIX_UNIVERSAL, PERM_READ, 'r', "Remove template : removes from list those objects whose name match the template",
173 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
174 {CHOIX_UNIVERSAL, PERM_READ, 'x', "Query query_string : performs a complex query - 'help query_syntax' for further info",
175 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
176 {CHOIX_UNIVERSAL, PERM_READ, 'x', "Where query_string : same as Query, kept for backwards compatibility, do NOT use",
177 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
178 {CHOIX_UNIVERSAL, PERM_READ, 'T', "Table-Maker [-active] [ -h | -a | -p | -j | -x etc.] [-b start] [-c max] [-title]\n"
179 "\t\t[-o out_filename] [-s obj_name] {command_infile | -n name | =} [params]\n"
180 "\tcommands come from file, named Table class object in database (-n option), or command line (= option)\n"
181 "\t-active searches active list, -s stores in database in Table class\n"
182 "\toutput styles are as in List, Show (see them for additional style options)",
183 {TRUE, CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-f", CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-o"}},
184 {CHOIX_UNIVERSAL, PERM_READ, 'b', "Biblio [-abstracts] : shows the associated bibliography [including the abstracts]",
185 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
186 {CHOIX_UNIVERSAL, PERM_READ, 'd',
187 "Dna [-mismatch] [-unspliced | -spliced | -cds] [-C | -p | -U] [-x1 begin] [-x2 end] [[-f] out_filename] :\n"
188 "\tFasta dump of related dna sequences\n"
189 "\t-C dump in \"C\" style struct\n"
190 "\t-p dump in perl style array\n"
191 "\t-u dump unformatted: just the dna as a single string.\n"
192 "\t-mismatch allow mismatches in construction of dna\n"
193 "\t-unspliced | -spliced | -cds for intron/exon objects, dna can be dumped for exons + introns,\n"
194 "\t\tthe spliced exons or just the CDS within the spliced exons.\n"
195 "\t x1 and x2 may be absent OR \"begin\" OR \"end\" OR a positive number,\n"
196 "\t[-f] out_filename output file for dna.\n",
197 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_OPTIONAL, NULL}},
198 {CHOIX_UNIVERSAL, PERM_READ, 'v', "Peptide [out_filename] : Fasta dump of related peptide sequences",
199 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_OPTIONAL, NULL}},
200 /* Why are these '0' ?? check back in the old code... */
201 /* 'a' contains no executed code, I just don't know about 'L'.... */
202 { 0, 0, 'L', "Alignment [out_filename] : Fasta dump of related sequences",
203 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_OPTIONAL, NULL}},
204 { 0, 0, 'a', "Array class :name format : formatted acedump of A class object",
205 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
206
207 {CHOIX_UNIVERSAL, PERM_READ, 'K', "KeySet-Read [in_filename | = Locus a;b;Sequence c] : \n\tread keyset from file filename or from stdin or from command line",
208 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
209
210 {CHOIX_UNIVERSAL, PERM_READ, '1', "spush : push active keyset onto stack",
211 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
212 {CHOIX_UNIVERSAL, PERM_READ, '2', "spop : remove top keyset from stack and make it the active keyset",
213 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
214 {CHOIX_UNIVERSAL, PERM_READ, '3', "swap : swap keyset on top of stack and active keyset",
215 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
216 {CHOIX_UNIVERSAL, PERM_READ, '4', "sand : replace top of stack by intersection of top of stack and active keyset",
217 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
218 {CHOIX_UNIVERSAL, PERM_READ, '5', "sor : replace top of stack by union of top of stack and active keyset",
219 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
220 {CHOIX_UNIVERSAL, PERM_READ, '6', "sxor : replace top of stack by exclusive or of top of stack and active keyset",
221 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
222 {CHOIX_UNIVERSAL, PERM_READ, '7', "sminus : removes members of the active keyset from the top of the stack ",
223 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
224 {CHOIX_UNIVERSAL, PERM_READ, '8', "spick nn : pick keyset nn>=0 from stack and make it the active keyset",
225 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
226 {CHOIX_UNIVERSAL, PERM_READ, '9', "subset : returns the subset of the alphabetic active keyset from x0>=1 of length nx ",
227 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
228
229 {CHOIX_UNIVERSAL, PERM_READ, 701, "kstore name : store active keyset in internal tmp space as name",
230 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
231 {CHOIX_UNIVERSAL, PERM_READ, 702, "kget name : copy named set as active keyset ",
232 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
233 {CHOIX_UNIVERSAL, PERM_READ, 703, "kclear name : clear named set ",
234 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
235
236
237 /* parsing in server/client is done via -ace_in command */
238 {CHOIX_NONSERVER, PERM_WRITE, 'p', "Parse [-NOXREF] [-v] [in_filename] : " UNIX_OR_WINDOWS_INPUTFILES "\n"
239 "\t[-v] print detailed statistics about parsing",
240 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
241 {CHOIX_NONSERVER, PERM_WRITE, 'P', "PParse [-NOXREF] [-v] [in_filename] : as above, but don't stop on first error",
242 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
243 /* EVENTUALLY WHEN CLIENT SIDE FILE READING/WRITING IS IMPLEMENTED, THIS */
244 /* WILL GO AWAY BECAUSE PARSE WILL BE THE SAME FOR SERVER/NONSERVER. */
245 {CHOIX_RPC, PERM_WRITE, 'p', "Parse [-NOXREF] [-v] [in_filename] : parse a file defined on the server, \n\trun aceclient -ace_in to parse a file or stdin defined on the client side",
246 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
247 {CHOIX_RPC, PERM_WRITE, 'P', "PParse [-NOXREF] [-v] [in_filename] : as above, but don't stop on first error",
248 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
249 {CHOIX_SERVER, PERM_WRITE, '_', "serverparse : parse files in server mode",
250 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
251
252 {CHOIX_UNIVERSAL, PERM_READ, 'w', "Write out_filename : acedump current list to file",
253 {TRUE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_COMPULSORY, NULL}},
254 {CHOIX_UNIVERSAL, PERM_WRITE, 'e', "Edit ace_file_command : Apply the command to every member of the activelist",
255 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
256 {CHOIX_UNIVERSAL, PERM_WRITE, 'E', "EEdit ace_file_command : Apply the command to every member of the activelist, "
257 "but unlike \"Edit\", conintue processing objects even if there is an error.",
258 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
259 {CHOIX_UNIVERSAL, PERM_WRITE, 'k',
260 "Kill : Kill and remove from acedb all objects in the current list",
261 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
262
263 /* encore stuff...these should not be included in the normal command sets/ */
264 /* perms because they are used internally by the code and are not for the */
265 /* user. */
266 {CHOIX_UNDEFINED, PERM_UNDEFINED, 'm', "More : If there are more objects to list",
267 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
268 {CHOIX_UNDEFINED, PERM_UNDEFINED, 'M', "More : If there are more objects to show",
269 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
270 {CHOIX_UNDEFINED, PERM_UNDEFINED, 'B', "More : If there are more lines in the table",
271 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
272 {CHOIX_UNDEFINED, PERM_UNDEFINED, 'D', "More : If there are more dna or peptide to dump",
273 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
274
275 {CHOIX_UNIVERSAL, PERM_ADMIN, 'R',
276 "Read-models [-index]: reads models, [reindex whole database] you must own the database to do this",
277 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
278
279 {CHOIX_NONSERVER, PERM_WRITE, 'Y', "tace [-f in_filename] [parameters] : Execute a file of acedb commands",
280 {FALSE, CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-f", CMD_FILESPEC_NONE, NULL}},
281
282 #ifdef ACEMBLY
283 {CHOIX_UNIVERSAL, PERM_WRITE, 'A', "Acembly [-f in_command_file] [parameters] : Sequence assembly and automatic edition",
284 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
285 #endif /* ACEMBLY */
286
287 {CHOIX_UNIVERSAL, PERM_READ, 'Z', "Status {on | off} : Show current stats or toggle statistics display\n"
288 "\t{" STATUS_OPTIONS_STRING "} : select stats to print\n",
289 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
290 {CHOIX_UNIVERSAL, PERM_READ, 'J',
291 "Date : prints the date and time",
292 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
293 {CHOIX_UNIVERSAL, PERM_READ, 'I', "Time_Stamps {on | off} : Show current setting or toggle time stamps creation",
294 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
295
296 {CHOIX_UNIVERSAL, PERM_WRITE, 'H', "Chrono {start | stop | show} built in profiler of chrono aware routines",
297 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
298
299 {CHOIX_UNIVERSAL, PERM_ADMIN, 'V', "Test : test subroutine, may vary",
300 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
301
302 {CHOIX_UNIVERSAL, PERM_READ, 450,
303 "AQL [-h | -a | -p | -j | -x etc.] [-s] [ -f in_query_file] [-o out_results_file] <aql query>\n"
304 "\tnew ace query language, -s for silent\n"
305 "\toutput styles are as in List, Show (see them for additional style options) plus -A",
306 {TRUE, CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-f", CMD_FILESPEC_OPTIONAL | CMD_FILESPEC_FLAG, "-o"}},
307 {CHOIX_UNIVERSAL, PERM_READ, 451, "Select ... <aql query> : new ace query language, use AQL to get options",
308 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
309
310 {CHOIX_UNIVERSAL, PERM_WRITE, 'F', "New Class Format : i.e New Plate ya\\%dx.y creates ya8x.y if ya7x.y exists",
311 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
312 {CHOIX_UNIVERSAL, PERM_READ, 'N', "Count : number of objects in active keyset",
313 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
314 {CHOIX_UNIVERSAL, PERM_READ, 'C', "Clear : Clear current keyset",
315 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
316 {CHOIX_UNIVERSAL, PERM_READ, 'u', "Undo : returns the current list to its previous state",
317 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
318
319 /* where do these fit in, looks like more specials...are these for assembly*/
320 /* somewhere ?? I don't know if these are used anywhere, can't see how */
321 /* they get called... */
322 { 0, 0, '-', "Depad [seqname] : depads an assembly, or currently padded assembly",
323 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
324 { 0, 0, '*', "Pad seqname : pads an assembly",
325 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
326
327 {CHOIX_GIF, PERM_READ, '#', "GIF : access to gif drawing submenu",
328 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
329 {CHOIX_UNIVERSAL, PERM_READ, 401, "layout : export the layout file",
330 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
331
332 {CHOIX_NONSERVER, PERM_ADMIN, 'j', "Dump [-s] [-T] [-C] [directory]: dump database, -s splits by class, -T gives timestamps, -C ignore comments",
333 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
334 {CHOIX_NONSERVER, PERM_ADMIN, 'Q', "dumpread filename : read in a dump, filename must be first dumpfile of a set of dump files.",
335 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
336
337
338 /* New, admin commands. */
339 {CHOIX_NONSERVER, PERM_ADMIN, CMD_NEWLOG, "newlog [-f old_log_name | -reopen] :\n"
340 "Starts a new log file renaming the old log as \"log.<ace-time>.wrm\"\n"
341 "\t-f allows you to specify a name for the old log file.\n"
342 "\t-reopen simply closes the log and then reopens it, this is useful with system rotatelogs script\n"
343 "\t supplied with some unix systems that can be used to control general log files",
344 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
345
346
347 /* Smap commands... */
348 {CHOIX_UNIVERSAL, PERM_READ, CMD_SMAP,
349 "smap [-coords x1 x2] -from class:object [-to class:object] : "
350 "maps cordinates between sequences that have a child -> parent relationship expressed in "
351 "SMap tags (or the now deprecated Source/Subsequence tags). Note that objects must be "
352 "specified in \"class:object\" as smap can map any class that contains SMap tags.\n"
353 "\t-coords x1 x2 coords to be mapped in the -from object, defaults to whole of -from object.\n"
354 "\t-from class:object object to be mapped into one of its parent.\n"
355 "\t-to class:object object to be mapped to, must be a parent of the -from object, defaults to "
356 "top parent in the smap tree above -from object.",
357 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
358 {CHOIX_UNIVERSAL, PERM_READ, CMD_SMAPDUMP, "smapdump [-f filename] class:object : "
359 "dumps to stdout (or optionally a file) the smap for the object.",
360 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
361 {CHOIX_UNIVERSAL, PERM_READ, CMD_SMAPLENGTH, "smaplength class:object : "
362 "gives the length of the object.",
363 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
364
365
366 /* server only commands. */
367 {CHOIX_RPC, PERM_ADMIN, CMD_SHUTDOWN, "shutdown [now] [norestart] : Closes the server (you need special privilege)",
368 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
369 {CHOIX_RPC, PERM_ADMIN, CMD_WHO, "who : who is connected now (you need special privilege)",
370 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
371 {CHOIX_RPC, PERM_ADMIN, CMD_VERSION, "data_version : data served now, as stated in wspec/server.wrm",
372 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
373 {CHOIX_RPC, PERM_ADMIN, CMD_WSPEC, "wspec : export wspec directory as a tar file",
374 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
375
376 /* admin only commands (socket server only). */
377 {CHOIX_SERVER, PERM_ADMIN, CMD_PASSWD, "passwd : change your password.",
378 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
379 {CHOIX_SERVER, PERM_ADMIN, CMD_USER, "user passwd|group|new|delete userid [password group] : Create/update/delete userids (you need special privilege).",
380 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
381 {CHOIX_SERVER, PERM_ADMIN, CMD_GLOBAL, "global read|write none|passwd|world : Change global read/write permissions for database (you need special privilege).",
382 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
383 {CHOIX_SERVER, PERM_ADMIN, CMD_DOMAIN, "domain group|new|delete domain-name [group] : Create/update/delete domain names (you need special privilege).",
384 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
385 {CHOIX_SERVER, PERM_ADMIN, CMD_REMOTEPARSE, "Parseremote [-NOXREF] [-v] in_filename : parse a file defined on the servers filesystem.",
386 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
387 {CHOIX_SERVER, PERM_ADMIN, CMD_REMOTEPPARSE, "PParseremote [-NOXREF] [-v] in_filename : as above, but don't stop on first error",
388 {TRUE, CMD_FILESPEC_OPTIONAL, NULL, CMD_FILESPEC_NONE, NULL}},
389 {CHOIX_SERVER, PERM_ADMIN, CMD_REMOTEDUMP, "Dumpremote [-s] [-T] [-C] directory : dump database to a file defined on the servers filesystem,\n\t -s splits by class, -T gives timestamps, -C ignore comments",
390 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
391 {CHOIX_SERVER, PERM_ADMIN, CMD_REMOTEDUMPREAD, "dumpreadremote filename : read in a dump held on the servers filesystem, filename must be first dumpfile of a set of dump files.",
392 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
393 {CHOIX_SERVER, PERM_ADMIN, CMD_SERVERLOG, "Serverlog [-f old_log_name | -reopen] : "
394 "Starts new log and serverlog files renaming the old logs as \"(server)log.<ace-time>.wrm\"\n"
395 "\t-f allows you to specify a name for the old log file."
396 "\t-reopen simply closes the log and then reopens it, this is useful with system rotatelogs script\n"
397 "\t supplied with some unix systems that can be used to control general log files",
398 {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}},
399
400 /* Special end of table entry. */
401 {CHOIX_UNDEFINED, PERM_UNDEFINED, 0, NULL, {FALSE, CMD_FILESPEC_NONE, NULL, CMD_FILESPEC_NONE, NULL}}
402 } ;
403
404
405
406 /************************************************************/
407 /* Given the integer representing a command, returns what group that command */
408 /* belongs to, e.g. CHOIX_SERVER. */
409 /* If the command is not known, returns CHOIX_UNDEFINED */
410
411 #ifdef ED_G_NEVER_INCLUDE_THIS_CODE
412 /* THIS IS NOT NEEDED AT THE MOMENT, I HAVE DONE WHAT I NEED TO BY USING */
413 /* THE choix MECHANISM. */
414
415 CmdChoix aceCommandGetChoixGroup(KEY key)
416 {
417 CmdChoix group = CHOIX_UNDEFINED ;
418 CHOIX *fc ;
419
420 fc = uAceCommandGetChoixMenu() ;
421
422 while (fc->key && group == CHOIX_UNDEFINED) /* watch for the loop termination... */
423 {
424 if (fc->key == key)
425 group = fc->choix ;
426
427 fc++ ;
428 }
429
430 return group ;
431 }
432 #endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
433
434
435 /************************************************************/
436
437 /* THIS IS NOT FINISHED... */
438 /* N.B. we just return CMD_FILE_ERR whether the command itself was in error, */
439 /* or whether the way the file was specified was the error. */
440 /* */
441 CmdFilespecArg aceCommandCheckForFiles(char *cmd_string, char **newcmd_string,
442 char **input_file, char **output_file)
443 {
444 CmdFilespecArg result ;
445 Array cmd_menu ;
446 unsigned int cmd_set, perm_set ;
447 BOOL answer ;
448 ACEIN command_in ;
449 FREEOPT *qmenu ;
450 KEY option ;
451 char *dummy ;
452
453
454 /* Default result. */
455 result = CMD_FILE_NONE ;
456 *input_file = *output_file = *newcmd_string = NULL ;
457
458 /* Is the command one of the recognised ones ? Note we have to do some */
459 /* contortions here to enable us to use existing code in acein to check */
460 /* for an option. We choose all possible commands and get returned a menu */
461 /* which we can then feed into aceInKey...phew... */
462 cmd_set = CHOIX_UNIVERSAL | CHOIX_NONSERVER | CHOIX_SERVER | CHOIX_GIF ;
463 perm_set = PERM_READ | PERM_WRITE | PERM_ADMIN ;
464 cmd_menu = uAceCommandChoisirMenu(cmd_set, perm_set) ;
465 qmenu = arrp (cmd_menu, 0, FREEOPT) ;
466 command_in = aceInCreateFromText(cmd_string, NULL, 0) ;
467 dummy = aceInCard(command_in) ;
468 answer = aceInKey(command_in, &option, qmenu) ;
469
470
471 /* Ok, now check for an input or output file for the command. */
472 if (!answer)
473 result = CMD_FILE_ERR ; /* unknown cmd. */
474 else
475 {
476 BOOL found ;
477 CHOIX *cmd_description ;
478
479 /* Find the command description in the command.c array of commands, */
480 /* the description tells how to process possible file arguments. */
481 found = FALSE ;
482 cmd_description = uAceCommandGetChoixMenu() ;
483 while (cmd_description->key && found == FALSE)
484 {
485 if (cmd_description->key == option)
486 found = TRUE ;
487 else
488 cmd_description++ ;
489 }
490 if (found == FALSE)
491 messcrash("Could not find \"%s\" in the command.c array of commands.", cmd_string) ;
492
493
494 /* Does the command use any files ? If yes, then check them out. */
495 if (!(cmd_description->filespec.any_files))
496 result = CMD_FILE_NONE ; /* This cmd does not use files. */
497 else
498 {
499 BOOL more_words ;
500 CmdFilespecArg status ;
501 char *word, prev_word[1000] ;
502 char *infile, *outfile ;
503 Stack cmd_out ;
504
505 /* aceInKey (above) does an aceInWord, so we need to go back and */
506 /* get the first word again, clumsy really, could do with an */
507 /* aceInWordBack. */
508 aceInCardBack(command_in) ;
509 dummy = aceInCard(command_in) ;
510 word = aceInWord(command_in) ;
511
512 /* Use a stack to build the command minus the file args. */
513 cmd_out = stackCreate(1000) ;
514 pushText(cmd_out, word) ;
515
516 /* Parse out the file args (if any). */
517 more_words = TRUE ;
518 word = infile = outfile = NULL ;
519 prev_word[0] = '\0' ;
520 while (more_words)
521 {
522 status = CMD_FILE_NONE ;
523 word = aceInWord(command_in) ;
524 if (word == NULL)
525 more_words = FALSE ;
526 else
527 strcpy(&(prev_word[0]), word) ;
528
529 if (word)
530 {
531 /* Still chonking through text, looking for flags... */
532 if ((cmd_description->filespec.infile & CMD_FILESPEC_FLAG)
533 && infile == NULL
534 && status == CMD_FILE_NONE)
535 status = getFlagFile(&infile, cmd_description->filespec.infile_flag,
536 word, command_in) ;
537
538 if ((cmd_description->filespec.outfile & CMD_FILESPEC_FLAG)
539 && outfile == NULL
540 && status == CMD_FILE_NONE)
541 status = getFlagFile(&outfile, cmd_description->filespec.outfile_flag,
542 word, command_in) ;
543
544 }
545 else
546 {
547 /* Got to the end of text, check for final file name. */
548 /* N.B. can only be one of an input OR an output file. */
549 if ((cmd_description->filespec.infile != CMD_FILESPEC_NONE)
550 && !(cmd_description->filespec.infile & CMD_FILESPEC_FLAG)
551 && status == CMD_FILE_NONE)
552 status = getNoFlagFile(&infile, &(prev_word[0]),
553 cmd_description->filespec.infile) ;
554 else if ((cmd_description->filespec.outfile != CMD_FILESPEC_NONE)
555 && !(cmd_description->filespec.outfile & CMD_FILESPEC_FLAG)
556 && status == CMD_FILE_NONE)
557 status = getNoFlagFile(&outfile, &(prev_word[0]),
558 cmd_description->filespec.outfile) ;
559 }
560
561 if (status == CMD_FILE_ERR)
562 {
563 result = status ;
564 break ;
565 }
566 else if (status == CMD_FILE_FOUND)
567 {
568 result = status ;
569 prev_word[0] = '\0' ;
570 }
571
572 if (prev_word[0] != '\0')
573 {
574 catText(cmd_out, " ") ;
575 catText(cmd_out, &(prev_word[0])) ;
576 }
577
578 } /* while */
579
580
581 /* Set up return values. */
582 if (result == CMD_FILE_FOUND)
583 {
584 if (infile)
585 *input_file = infile ;
586 if (outfile)
587 *output_file = outfile ;
588
589 *newcmd_string = strnew(popText(cmd_out), 0) ;
590 }
591
592 stackDestroy(cmd_out) ;
593
594 } /* cmd uses files */
595
596 } /* command is recognised */
597
598 aceInDestroy(command_in) ;
599
600 return result ;
601 }
602
603
604 /******************************************************************
605 ************************ private functions ***********************
606 ******************************************************************/
607
608
609 /* Access function to the main command array. */
610 /* */
611 CHOIX *uAceCommandGetChoixMenu(void)
612 {
613 return &(choixMenu[0]) ;
614 }
615
616
617 /****************************************************************/
618
619 /* Return an array of the allowed commands for the given choix and */
620 /* permissions sets (e.g. choix might be universal commands and permission */
621 /* might be read-only). */
622 /* */
623 /* Note we do NO checking of arguments here because this is a private */
624 /* function to the command package so the code just should be correct. */
625 /* */
626 Array uAceCommandChoisirMenu(unsigned int choix, unsigned int perms)
627 {
628 Array aMenu = arrayCreate (50, FREEOPT) ;
629 int i ;
630 CHOIX *fc = uAceCommandGetChoixMenu() ;
631 FREEOPT *ff ;
632
633 i = 1 ;
634 while (fc->key)
635 {
636 if ((fc->choix & choix) && (fc->perm & perms))
637 {
638 ff = arrayp (aMenu, i++, FREEOPT) ;
639 ff->key = fc->key ;
640 ff->text = fc->text ;
641 }
642 fc++ ;
643 }
644
645 ff = arrayp (aMenu, 0, FREEOPT) ;
646 ff->key = i - 1 ;
647 ff->text = "acedb" ;
648
649 return aMenu ;
650 } /* choisirMenu */
651
652
653 /****************************************************************/
654
655 static CmdFilespecArg getFlagFile(char **file_name, char *flag, char *curr_word, ACEIN curr_string)
656 {
657 CmdFilespecArg file_found = CMD_FILE_NONE ;
658
659 if (strcmp(curr_word, flag) == 0)
660 {
661 char *infile ;
662
663 infile = aceInWord(curr_string) ;
664
665 if (infile && *infile != '-')
666 {
667 *file_name = strnew(infile, 0) ;
668 file_found = CMD_FILE_FOUND ;
669 }
670 else
671 file_found = CMD_FILE_ERR ;
672 }
673
674 return file_found ;
675 }
676
677 /****************************************************************/
678
679 static CmdFilespecArg getNoFlagFile(char **file_name, char *curr_word, CmdFilespecType filespec)
680 {
681 CmdFilespecArg file_found = CMD_FILE_NONE ;
682
683 if (curr_word == NULL)
684 {
685 if ((filespec & CMD_FILESPEC_COMPULSORY))
686 file_found = CMD_FILE_ERR ;
687 else
688 file_found = CMD_FILE_NONE ;
689 }
690 else if (*curr_word == '-')
691 file_found = CMD_FILE_ERR ;
692 else
693 {
694 *file_name = strnew(curr_word, 0) ;
695 file_found = CMD_FILE_FOUND ;
696 }
697
698 return file_found ;
699 }
700
701
702