Frink 2.0 The latest version of Frink is always available by ftp from catless.ncl.ac.uk in the /pub directory: ftp://catless.ncl.ac.uk/pub/frink.tar.gz Frink is a tcl formatting and static check program. It can prettify your program, minimise, obfuscate or just sanity check it. It can also do some rewriting. You pass it filenames (or the stdin) and the output is generated to stdout. There are a variety of options you can pass in : -a : add spaces after {} and "" when processing -command. (default = OFF) -A : turn OFF special processing of expr commands. -b : add braces (see manual page for details) (default = OFF) -B : turn OFF processing code passed to the bind command. -c : set further indent for continuations to n. default = 2 -C : turn OFF processing code passed to the catch command. -d : remove braces in certain (safe) circumstances (default = OFF) -e : produce "else". default = OFF -E : extract constant strings. The parameter is the locale for which the strings are currently written. If the -f flag is also used then only the constant strings that are rewritten will be output. Output goes to a file called ".msg". -f : rewrite some strings to use msgcat. (currently -text and -label options) -F

: selectively control which heuristics are used. Currently the parameter is a single hex coded number with each bit representing a test. The values you need to know are: 00001 : append parameter testing 00002 : lappend parameter testing 00004 : set parameter testing 00008 : incr parameter testing 00010 : return checks 00020 : check for : or ::: in names 00040 : expr checks 00080 : foreach var checking. -g : indent switch cases. default = OFF -h : print information about options. -H : turn on heuristic tests and warnings. (default = OFF) -i : set indent for each level to n. default = 4 -j : remove non-essential blank lines. (default = OFF) -J : Just do checks, no output. (default = OFF) -k : remove non-essential braces. (default = OFF) -K : specify file of extra code specs (see below for details). -l : try for one-liners -m : minimise the code by removing redundant spacing. default = OFF -n : do not generate tab characters. default = OFF -N : do not put a newline out before elseif. default = OFF -o : obfuscate : default = OFF -p : If v is a number produce that many blank lines after each proc definition, otherwise produce whatever format the code indicates. No codes are defined yet..... (default = do nothing) -r : remove comments. default = OFF -s : format according to style name "c". (no style names defined yet) -S : Stop preserving end of line comments. default = OFF -t : set tabs every n characters. -T : produce "then". default = OFF -u : Safe to remove brackets from round elseif conditions. default = OFF -v : put { } round variable names where appropriate. -w : set line length. default = 80 -W : halt on warning. -x : produce "xf style" continuations -X : recognise tclX features -y : Don't process -command (deafult = OFF) -z : do not put a single space before the \ character on continuations. Please try it and let me know how else you would like to be able to tailor the output. (And all the bugs you find as well) Currently it is geared very much towards the style of tcl programming that I use myself. Obfuscation is not particularly sophisticated yet. In particular it can be (in most cases) reversed by running the obfuscated program through frink again! Frink uses quite a few heuristics (i.e. a bunch of ad hoc hacks) to improve both formatting and minimisation. In some obscure cases these may burn you. Please let me know of any cases you find. Suggestions for new heuristics are always welcome. Currently frink supports straightforward tcl (it doesn't do case either), tclX and [incr tcl] 1.0. N.B. frink assumes that you are running it over a correct tcl program. If this is not the case then all bets are off! There are some constructions possible in tcl where it is impossible to determine the correct formatting except at runtime. If you use these, sorry, but frink can't help you. Comment handling is not brilliant - suggestions are welcome for how it could be improved..... Rewriting ========= Frink will try to detect the cases where you use the options -text or -label and can rewrite the string passed in to use the message catalogue. Thus label .foo -text "This is an example" would become label .foo -text [::msgcat::mc "This is an example"] If Frink detects the the string is already of the form [::msgcat::mc ......] then it does not rewrite. N.B. Frink does not generate the "package require msgcat" statement for you!!!! Heuristics ========== Frink applies a variety of heuristics to the tcl code to try to detect possible errors. Note that sometimes the things that it points out are not in fact incorrect. At the moment the checks it does are as follows: 1) detects if certain commands are used without parameters. 2) detects certain cases where too many or too few parameters are provided. 3) detects "< " at the end of a line (bad continuation usually). 4) detects missing }, ] and ". 5) detects when non-constant strings are passed as the first parameter to set, append and lappend. 6) detects variable names with single or more than two sequential colons in them. 7) detects exprs where the expression is not braced. 8) detects some missing ) cases. 9) detects where return is used inconsistently (i.e. sometimes you return a result, sometimes not). Picks up missing returns at end of procs that return results too. 10) checks nested foreach statements to see if variables get reused. I have other heuristic tests planned, and if you have any suggestions for tests i can implement please let me know. Extending the analysis ====================== The -K flag allows you to specify a file that describes new commands to Frink so that it can format/check them correctly. The syntax is very simple. 1) comment lines start with a # 2) blank lines are ignored 3) definition lines start with the name of the command and are followed by a specification of the parameters. These tell Frink what to expect in these positions and what formatting/checks it should therefore carry out. Here are some specs for commands that you already are familiar with: append {var any args} append's first parameter is a variable name the second can be anything and this can be followed by 0 or more parameters. proc {any any code} proc's first two parameters can be anything the third is code. Lindsay -- Lindsay.Marshall@newcastle.ac.uk