-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlias.java
More file actions
83 lines (72 loc) · 1.71 KB
/
Alias.java
File metadata and controls
83 lines (72 loc) · 1.71 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.util.StringTokenizer;
public class Alias{
private int args;
private String[] coms;
private int[] argpos;
//public static final String SPLITSYMBOL = "\\";
public Alias(String combo){
this.args = 0;
this.coms = new String[1];
this.coms[0] = combo;
this.argpos = new int[0];
}
public Alias(String[] combo, int[] pos){
this.args = combo.length-1;
this.coms = combo;
this.argpos = pos;
}
public Alias(String name, String definer)
throws Exception{
/*
StringTokenizer semicolons = new StringTokenizer(definer,SPLITSYMBOL);
String combo = "";
while(semicolons.hasMoreTokens()){
combo += semicolons.nextToken();
if(semicolons.hasMoreTokens()){
combo += ";";
}
}
*/
StringTokenizer arguments = new StringTokenizer(definer,"#");
coms = new String[arguments.countTokens()];
argpos = new int[coms.length-1];
args = 0;
for(int i=0; i<coms.length; i++){
String bit = arguments.nextToken();
if(i == 0){
coms[i] = bit;
} else {
coms[i] = bit.substring(1,bit.length());
argpos[i-1] = Integer.parseInt(bit.substring(0,1))-1;
if(argpos[i-1] < 0){
throw new Exception();
}
if(argpos[i-1]+1 > args){
args = argpos[i-1]+1;
}
}
}
}
public int getArgumentCount(){
return args;
}
public int[] getArgumentPositions(){
return argpos;
}
public String getCommand(String[] arguments){
String alias = "";
for(int i=0; i<this.coms.length-1; i++){
alias += this.coms[i];
if(arguments.length > argpos[i]){
alias += arguments[argpos[i]];
}
}
alias += this.coms[this.coms.length-1];
int i=args;
while(arguments.length > i){
alias += arguments[i]+" ";
i++;
}
return alias;
}
}