comparison src/variables.cc @ 5102:b04b30d30c66

[project @ 2004-12-28 01:59:05 by jwe]
author jwe
date Tue, 28 Dec 2004 01:59:05 +0000
parents 11bea7392e69
children 5fa9670b5956
comparison
equal deleted inserted replaced
5101:9b1af8135ecd 5102:b04b30d30c66
142 142
143 DEFCMD (mark_as_command, args, , 143 DEFCMD (mark_as_command, args, ,
144 "-*- texinfo -*-\n\ 144 "-*- texinfo -*-\n\
145 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ 145 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\
146 Enter @var{name} into the list of commands.\n\ 146 Enter @var{name} into the list of commands.\n\
147 @end deftypefn") 147 @end deftypefn\n\
148 @seealso{unmark_command, iscommand}")
148 { 149 {
149 octave_value_list retval; 150 octave_value_list retval;
150 151
151 if (at_top_level ()) 152 if (at_top_level ())
152 { 153 {
173 return retval; 174 return retval;
174 } 175 }
175 176
176 DEFCMD (unmark_command, args, , 177 DEFCMD (unmark_command, args, ,
177 "-*- texinfo -*-\n\ 178 "-*- texinfo -*-\n\
178 @deftypefn {Built-in Function} {} mark_as_command (@var{name})\n\ 179 @deftypefn {Built-in Function} {} unmark_command (@var{name})\n\
179 Remove @var{name} from the list of commands.\n\ 180 Remove @var{name} from the list of commands.\n\
180 @end deftypefn") 181 @end deftypefn\n\
182 @seealso{mark_as_command, iscommand}")
181 { 183 {
182 octave_value_list retval; 184 octave_value_list retval;
183 185
184 if (at_top_level ()) 186 if (at_top_level ())
185 { 187 {
223 retval = true; 225 retval = true;
224 } 226 }
225 } 227 }
226 else 228 else
227 retval = is_marked_as_command (s); 229 retval = is_marked_as_command (s);
230
231 return retval;
232 }
233
234 DEFCMD (iscommand, args, ,
235 "-*- texinfo -*-\n\
236 @deftypefn {Built-in Function} {} iscommand (@var{name})\n\
237 Return true if @var{name} is a command style function. If @var{name}\n\
238 is omitted, return a list of identifiers which are marked as commands with\n\
239 mark_as_command.\n\
240 @end deftypefn\n\
241 @seealso{mark_as_command, unmark_command}")
242 {
243 octave_value retval;
244
245 int nargin = args.length ();
246
247 if (nargin == 0)
248 {
249 string_vector lst (command_set.size ());
250
251 int i = 0;
252 for (std::set<std::string>::const_iterator p = command_set.begin ();
253 p != command_set.end (); p++)
254 lst[i++] = *p;
255
256 retval = Cell (lst.qsort ());
257 }
258 else if (nargin == 1)
259 {
260 string_vector argv = args.make_argv ("iscommand");
261
262 if (! error_state)
263 {
264 std::string s = argv[1];
265 retval = is_command_name(s);
266 }
267 }
268 else
269 print_usage ("iscommand");
270
271 return retval;
272 }
273
274 // Is this a raw input command?
275
276 static std::set <std::string> rawcommand_set;
277
278 static inline bool
279 is_marked_as_rawcommand (const std::string& s)
280 {
281 return rawcommand_set.find (s) != rawcommand_set.end ();
282 }
283
284 static inline void
285 mark_as_rawcommand (const std::string& s)
286 {
287 command_set.insert (s);
288 rawcommand_set.insert (s);
289 }
290
291 static inline void
292 unmark_rawcommand (const std::string& s)
293 {
294 rawcommand_set.erase (s);
295
296 symbol_record *sr = fbi_sym_tab->lookup (s);
297
298 if (sr)
299 sr->unmark_rawcommand ();
300 }
301
302 DEFCMD (mark_as_rawcommand, args, ,
303 "-*- texinfo -*-\n\
304 @deftypefn {Built-in Function} {} mark_as_rawcommand (@var{name})\n\
305 Enter @var{name} into the list of raw input commands and to the list of\n\
306 command style functions.\n\
307 Raw input commands are like normal command style functions, but they\n\
308 receive their input unprocessed (ie. strings still contain the quotes\n\
309 and escapes they had when input). However, comments and continuations\n\
310 are handled as usual, you cannot pass a token starting with a comment\n\
311 character ('#' or '%') to your function, and the last token cannot be\n\
312 a continuation token ('\\' or '...').\n\
313 @end deftypefn\n\
314 @seealso{unmark_rawcommand, israwcommand, iscommand, mark_as_command}")
315 {
316 octave_value_list retval;
317
318 if (at_top_level ())
319 {
320 int nargin = args.length ();
321
322 if (nargin > 0)
323 {
324 int argc = nargin + 1;
325
326 string_vector argv = args.make_argv ("mark_as_rawcommand");
327
328 if (! error_state)
329 {
330 for (int i = 1; i < argc; i++)
331 mark_as_rawcommand (argv[i]);
332 }
333 }
334 else
335 print_usage ("mark_as_rawcommand");
336 }
337 else
338 warning ("mark_as_rawcommand: invalid use inside function body");
339
340 return retval;
341 }
342
343 DEFCMD (unmark_rawcommand, args, ,
344 "-*- texinfo -*-\n\
345 @deftypefn {Built-in Function} {} unmark_rawcommand (@var{name})\n\
346 Remove @var{name} from the list of raw input commands.\n\
347 Note that this does not remove @var{name} from the list of command style\n\
348 functions.\n\
349 @end deftypefn\n\
350 @seealso{mark_as_rawcommand, israwcommand, iscommand, unmark_command}")
351 {
352 octave_value_list retval;
353
354 if (at_top_level ())
355 {
356 int nargin = args.length ();
357
358 if (nargin > 0)
359 {
360 int argc = nargin + 1;
361
362 string_vector argv = args.make_argv ("unmark_rawcommand");
363
364 if (! error_state)
365 {
366 for (int i = 1; i < argc; i++)
367 unmark_rawcommand (argv[i]);
368 }
369 }
370 else
371 print_usage ("unmark_rawcommand");
372 }
373 else
374 warning ("unmark_rawcommand: invalid use inside function body");
375
376 return retval;
377 }
378
379 bool
380 is_rawcommand_name (const std::string& s)
381 {
382 bool retval = false;
383
384 symbol_record *sr = fbi_sym_tab->lookup (s);
385
386 if (sr)
387 {
388 if (sr->is_rawcommand ())
389 retval = true;
390 else if (is_marked_as_rawcommand (s))
391 {
392 sr->mark_as_rawcommand ();
393 retval = true;
394 }
395 }
396 else
397 retval = is_marked_as_rawcommand (s);
398
399 return retval;
400 }
401
402 DEFCMD (israwcommand, args, ,
403 "-*- texinfo -*-\n\
404 @deftypefn {Built-in Function} {} israwcommand (@var{name})\n\
405 Return true if @var{name} is a raw input command function.\n\
406 If @var{name} is omitted, return a list of identifiers which are marked as\n\
407 raw input commands with mark_as_rawcommand.\n\
408 @end deftypefn\n\
409 @seealso{mark_as_rawcommand, unmark_rawcommand}")
410 {
411 octave_value retval;
412
413 int nargin = args.length ();
414
415 if (nargin == 0)
416 {
417 string_vector lst (rawcommand_set.size());
418
419 int i = 0;
420 for (std::set<std::string>::const_iterator p = rawcommand_set.begin ();
421 p != rawcommand_set.end ();
422 p++)
423 lst[i++] = *p;
424
425 retval = Cell (lst.qsort ());
426 }
427 else if (nargin == 1)
428 {
429 string_vector argv = args.make_argv ("israwcommand");
430
431 if (! error_state)
432 {
433 std::string s = argv[1];
434 retval = is_rawcommand_name(s);
435 }
436 }
437 else
438 print_usage ("israwcommand");
228 439
229 return retval; 440 return retval;
230 } 441 }
231 442
232 // Is this a built-in function? 443 // Is this a built-in function?