Created
June 10, 2016 12:36
-
-
Save blippy/1acf257d09cd4a8ac2ec48ba882f4027 to your computer and use it in GitHub Desktop.
Split a line as if it were a command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env tclsh | |
| # http://wiki.tcl.tk/21701 | |
| proc cmdSplit command { | |
| if {![info complete $command]} {error "non complete command"} | |
| set res ""; # the list of words | |
| set chunk "" | |
| foreach word [split $command " \t"] { | |
| # testing each word until the word being tested makes the | |
| # command up to it complete | |
| # example: | |
| # set "a b" | |
| # set -> complete, 1 word | |
| # set "a -> not complete | |
| # set "a b" -> complete, 2 words | |
| append chunk $word | |
| if {[info complete "$res $chunk\n"]} { | |
| lappend res $chunk | |
| set chunk "" | |
| } else { | |
| append chunk " " | |
| } | |
| } | |
| lsearch -inline -all -not $res {} ;# empty words denote consecutive whitespace | |
| } | |
| proc proc_cmds { cmd } { | |
| set chan [open "old/${cmd}s-0.txt" r+] | |
| set cout [open "${cmd}s-1.txt" w] | |
| while { [gets $chan line] >= 0 } { | |
| set fields [cmdSplit $line] | |
| if { [lindex $fields 0] == $cmd } { | |
| set txt ["proc_$cmd" $fields] | |
| puts $cout $txt | |
| } | |
| } | |
| close $chan | |
| close $cout | |
| } | |
| proc proc_comm { fields } { | |
| # TODO destructing bind in gist | |
| lassign $fields cmd sym dn typ curr ticker desc | |
| return "comm\t$ticker\t$dn\t$typ\t$curr\t$desc" | |
| } | |
| proc proc_etran { fields } { | |
| lassign $fields cmd tax ds way acc sym qty amt | |
| set sym1 "$sym.L" | |
| set special [list AFUSO AUG AUS CRC CSAL FGF FGSS FSS HYH KEYS SHOS] | |
| if { [lsearch $special $sym] != -1 } { set sym1 $sym } | |
| set idxs [list FTAS] | |
| if { [lsearch idxs $sym] != -1 } { set sym1 "^$sym" } | |
| set sym2 $sym1 | |
| return "etran $tax $ds $way $acc $sym2 $qty $amt" | |
| } | |
| proc proc_nacc { fields } { | |
| lassign $fields cmd dr cr typ m desc | |
| set dr1 [string map {"/" "_"} $dr] | |
| set cr1 [string map {"/" "_"} $cr] | |
| return "nacc $dr1\t$cr1\t$typ $m\t$desc" | |
| } | |
| proc proc_ntran { fields } { | |
| lassign $fields cmd ds dr cr amt cl desc | |
| return "ntran $ds $dr $cr\t$amt\t$desc" | |
| } | |
| proc_cmds comm | |
| proc_cmds etran | |
| proc_cmds nacc | |
| proc_cmds ntran | |
| #proc_comms |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from my file
/mnt/vivo/home/mcarter/repos/redact/docs/accts2015/data/upgrade-1.tcl