2

I'm trying to start a program (vcom) from a TCL script with extra options:

set compilationArgs "-quiet -93"
vcom $compilationArgs -work work polar2rect/sc_corproc.vhd

But when I run this, I get following error message:

# Model Technology ModelSim ALTERA vcom 6.5e Compiler 2010.02 Feb 27 2010
# ** Error: (vcom-1902) Option "-quiet -93" is either unknown, requires an argument, or was given with a bad argument.
# Use the -help option for complete vcom usage.
# /opt/altera/10.0/modelsim_ase/linuxaloem/vcom failed.

TCL seems to pass the two extra options (-quiet) and (-93) as one option to vcom. If I use only one of these two options it works. And if I run (vcom -93 -quiet -work work polar2rect/sc_corproc.vhd) it also works.

How can I fix this?

Thanks, Hendrik.

Hendrik
  • 1,247
  • 7
  • 14

1 Answers1

5

The “problem” is that Tcl's being careful about managing spaces. This is very useful if you've got arguments with spaces in (such as many full filenames on Windows machines) but can sometimes be frustrating if you wanted the list to be broken up automatically. The fix is to indicate to Tcl that this is something that you want split into multiple words.

The best answer requires at least Tcl 8.5 (find out what version you've got with info tclversion, info patchlevel, or package require Tcl).

vcom {*}$compilationArgs -work work polar2rect/sc_corproc.vhd

If you're built against an older version of Tcl, you'll need this instead:

eval vcom $compilationArgs -work work polar2rect/sc_corproc.vhd

(Or this, to be officiously correct, but hardly anyone bothers for obvious reasons)

eval [list vcom] $compilationArgs [list -work work polar2rect/sc_corproc.vhd]

The version at the top with the expansion syntax ({*}) is best if supported. You can determine if it is easily enough; if it isn't, it's a syntax error.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • But if you're on an old version of Tcl and have filenames with spaces in (boo! hiss!) then you'll need the version with the `list` stuff. Expansion syntax was added because we realized that it was *that* hard to remember to get the syntax right, and as a result, `eval` is hardly ever used in Tcl these days. – Donal Fellows Dec 21 '10 at 09:13
  • Not to mention that eval opens you up to code injection attacks. – slebetman Dec 21 '10 at 12:19
  • @slebetman: not if you're the one composing the code to be eval'd and it doesn't include any user-generated data (which seems to be the case here...). Still, it's good to always be wary of such things when using eval. – Bryan Oakley Dec 22 '10 at 21:32
  • @slebetman: The `list` command (and anything that produces a proper list through “proper” mechanisms) generates data that is `eval`-safe. However, the cautious will use a safe interpreter too, so that anything that does “escape” can't do lasting damage. – Donal Fellows Dec 22 '10 at 22:10
  • @Donal: Yeah but $compilationArgs isn't listified here. If I recall, the best *old* way of doing it is using linsert and eval. – slebetman Dec 22 '10 at 23:58
  • @Bryan: That's always true for all injection attacks in all languages. It still doesn't make it any less of a problem mainly because people tend to be creatures of habit and tend to code the same way in both safe and unsafe environments. Besides, one always thinks that ones code is safe until it's too late ;-) – slebetman Dec 23 '10 at 00:03
  • @slebetman: In this case it doesn't matter; the string is a correct list and the performance difference is minimal by comparison with running an external program. And anyway, they should use `{*}`. – Donal Fellows Dec 23 '10 at 07:58