Subversion Repositories Electronics.Rangefider

Rev

Rev 10 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 florent_ba 1
$failed = @()
2
$treated = @()
3
$schematicbased = @()
4
$thispath = pwd
5
 
6
$asylist = Get-ChildItem . -Recurse -Include *.asy
7
 
8
$encodings = @("UTF8", "UNICODE", "ASCII")
9
$encode_mode = 0
10
 
11
 
12
 
13
foreach($asy in $asylist)
14
{
15
    $asyname = Split-Path $asy -Leaf
16
    $all_encodes_done = 0
17
    $encode_mode = 0
18
    $successmatch = 0
19
    $modelfile = ""
20
 
21
 
22
    while(1)
23
    {
24
        if($args[0] -eq "-v"){
25
        Write-Host "Trying encoding <" $encodings[$encode_mode] "> on " $asyname " : " -nonewline
26
        pause
27
        }
28
 
29
        $content = Get-Content $asy -Encoding $encodings[$encode_mode]
30
 
31
 
32
        # extracting model file in case it does not match the .asy name
33
        foreach ($line in $content)
34
        {
35
           if($line -match "\b[^\\\s]+\.(lib|mdl|mod)\b")
36
           {
37
             $modelfile = $matches[0]
38
             $successmatch = 1
39
 
40
 
41
             if($args[0] -eq "-v"){
42
             Write-Host "Success, found " $matches[0]
43
             }
44
 
45
             break #break from the foreach
46
           }
47
        }
48
 
49
        #if regex succeeded, break from the encoding reader loop
50
        if($successmatch){
51
            break
52
        }
53
        #else, try to change the encoder or if no encoder remaining, set as failed
54
        else
55
        {
56
            if($args[0] -eq "-v"){
57
            Write-Host "Failed, selecting another encoder..."}
58
 
59
            $encode_mode = $encode_mode + 1
60
 
61
            if($encode_mode -ge $encodings.Count)
62
            {
63
                break
64
            }
65
        }
66
    }
67
 
68
 
69
    #if the model file is not found, previous steps failed.
70
    if($modelfile -eq "")
71
    {
72
 
73
        if($args[0] -eq "-v"){
74
        echo "model file is empty"}
75
 
76
        $ascpath = $asyname.Split('.')[0] + ".asc"
77
 
78
        if(Test-Path -Path $ascpath)
79
        {
80
 
81
            if($args[0] -eq "-v"){
82
            echo "$asyname has a corresponsing .asc : $ascpath"
83
            echo "-----------------------------------"
84
            echo "Processing .asy : $asyname" 
85
            echo "Schematic file  : $ascpath" 
86
            echo "-----------------------------------"}
87
 
88
            $schematicbased += $asyname
89
        }
90
        else
91
        {
92
 
93
            if($args[0] -eq "-v"){
94
            echo "no link to model file for $asyname, extracted : $modelfile."}
95
 
96
            $failed += $asyname
97
        }
98
 
99
    }
100
    else
101
    {
102
 
103
 
104
        if($args[0] -eq "-v"){
105
        echo "-----------------------------------"
106
        echo "Processing .asy : $asyname" 
107
        echo "Model file      : $modelfile" 
108
        echo "-----------------------------------"}
109
 
110
 
111
        $symattr = 'SYMATTR ModelFile ' + $modelfile
112
        $edited = $content -replace ( 'SYMATTR ModelFile (.+)', $symattr)
113
        $edited | Set-Content $asy
114
        $treated += $asyname
115
    }
116
 
117
}
118
 
119
$okcount = $treated.Count
120
$nokcount = $failed.Count
121
$schematiccount = $schematicbased.Count
122
 
123
echo "Files using a referenced .lib, .mdl, .mod:"
124
echo "-----------------------------------"
125
foreach($ffile in $treated)
126
{
127
    echo $ffile
128
}
129
echo "-----------------------------------"
130
echo ""
131
 
132
echo "Files using a matched-name .asc :"
133
echo "-----------------------------------"
134
foreach($ffile in $schematicbased)
135
{
136
    echo $ffile
137
}
138
echo "-----------------------------------"
139
echo ""
140
 
141
echo "Failed files, no .lib reference or no matched .asc :"
142
echo "-----------------------------------"
143
foreach($ffile in $failed)
144
{
145
    echo $ffile
146
}
147
echo "-----------------------------------"
148
 
149
echo ""
150
echo "Edited $okcount files, $schematiccount based on a matched LTspice schematic, $nokcount failed."
151
echo ""
152
 
153