-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepsel.mel
41 lines (40 loc) · 1.12 KB
/
repsel.mel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
global proc string[] repsel(string $fnd, string $rep){
string $lssl[] = `ls -sl`;
string $items[];
int $i;
for ($sel in $lssl){
$res = `substitute $fnd $sel $rep`;
$items[$i++] = $res;
}
select $items;
return $items;
}
global proc string[] doRepSel(
string $lssl[], string $fnd, string $rep, int $listmod){
// args:
// - listmod - if -1 reverse pairs: b(found), a(initial), ...
// 0 returns only found results
// 1 returns pairs: a(init), b(found)
// returns pairs of found items(a:initial, b:found) a, b, a, b, etc
string $res;
string $pairs[];
string $NEG = -1;
int $p;
for ($sel in $lssl){
$res = `substitute $fnd $sel $rep`;
if (`objExists $res`){
$a = $p++;
if ($listmod){
$pairs[$a] = $sel;
$pairs[$p++] = $res;
}
else{
if ($listmod < 0)
$pairs[$p++] = $sel;
if ($listmod <= 0)
$pairs[$a] = $res;
}
}
}
return $pairs;
}