OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tix/] [tools/] [tclc_s.tcl] - Blame information for rev 1782

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# tclc.tcl --
2
#
3
#       This Tcl script translates Tcl commands to one C string.
4
#
5
# Usage:
6
#       [tclsh] tclc.tcl file1.tcl [file2.tcl ...]
7
#
8
#       The output is printed in the standard output.
9
 
10
# ParseFile --
11
#
12
#       Read in a file and insert line number information into the code.
13
#
14
proc ParseFile {fileName n} {
15
    set fd [open $fileName {RDONLY}]
16
    set lineNum 1
17
 
18
    puts "static char script_$n\[\] = \{"
19
 
20
    set N [format \n]
21
    set T [format \t]
22
    set NTS [format "\n\t\ "]
23
    set sep ""
24
    while {![eof $fd]} {
25
        set line [gets $fd]
26
 
27
        # Check whether this line is backslash-ended. If so, merge this line
28
        # with the next one
29
        #
30
        regsub -all $N $line " " foo
31
        append foo \na
32
        set foo [subst -nocommands -novariables $foo]
33
        if [regexp $N $foo] {
34
            set cmd "$line\n"
35
        } else {
36
            regsub -all \\\\\[$NTS\]*$ $line " " line
37
            set cmd "$line"
38
        }
39
        set cmd '[join [split $cmd ""] ',']'
40
        regsub -all \\\\ $cmd \\\\\\\\ cmd
41
        regsub -all $N $cmd \\n cmd
42
        regsub -all $T $cmd \\t cmd
43
        regsub -all ''' $cmd '\\'' cmd
44
        regsub -all '\"' $cmd '\\\"' cmd
45
 
46
        puts -nonewline $sep$cmd
47
        set sep ,\n
48
    }
49
    puts "$sep'\\0'\};"
50
    close $fd
51
}
52
 
53
proc tclc_Main {} {
54
    global argv argv0
55
 
56
    set files [lrange $argv 0 end]
57
 
58
    set n 0
59
    foreach fileName $argv {
60
        ParseFile $fileName $n
61
        incr n
62
    }
63
 
64
    puts "static int LoadScripts(interp)"
65
    puts "    Tcl_Interp * interp;"
66
    puts "\{"
67
 
68
    if {$n > 0} {
69
        puts "    char *scripts\[$n\];"
70
        puts "    int i;"
71
 
72
        for {set k 0} {$k < $n} {incr k} {
73
            puts "    scripts\[$k\] = script_$k;"
74
        }
75
 
76
        puts "    for (i=0; i<$n; i++) \{"
77
        puts "        if (Tcl_Eval(interp, scripts\[i\]) != TCL_OK) \{"
78
        puts "            return TCL_ERROR;"
79
        puts "        \}"
80
        puts "    \}"
81
    }
82
 
83
    puts "    return TCL_OK;"
84
    puts "\}"
85
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.