-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCallpointSubroutines.java
144 lines (114 loc) · 4.81 KB
/
CustomCallpointSubroutines.java
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* Copyright Basis International, Ltd.
* User: shaney
* Date: 5/2/12
* Time: 5:52 PM
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class CustomCallpointSubroutines extends HashMap<String,String>{
public ArrayList<String> subroutineList =new ArrayList<String>();
String fileName;
boolean changed=false;
enum State{SEEKING,NAMING,GATHERING}
protected String customCallpointHeader="";
private static final Pattern subroutineNamePattern = Pattern.compile("[a-zA-Z0-9_]+:");
private static final Pattern includePattern = Pattern.compile("^[ \t]*\\#include .*");
private static final Pattern lineBeginsWithREMPattern = Pattern.compile("[ \t]*[Rr][Ee][Mm]");
private CustomCallpointSubroutines(){}
public CustomCallpointSubroutines(String customCallpointSegment) {
String lines[]=customCallpointSegment.split("\n");
String subroutineName ="";
String subroutine="";
State state=State.SEEKING;
Matcher subroutineNameMatcher;
Matcher includeMatcher;
for (String currentLine:lines ){
if (currentLine.startsWith("rem =====")) {
if (state==State.GATHERING) {
subroutineList.add(subroutineName);
put(subroutineName, subroutine);
subroutine="";
subroutineName ="";
}
if (state==State.SEEKING || state==State.GATHERING) {
state=State.NAMING;
subroutine=subroutine.concat(currentLine+"\n");
continue;
}
if (state==State.NAMING) {
state=State.GATHERING;
subroutine=subroutine.concat(currentLine+"\n");
continue;
}
}
if (state==State.NAMING) {
subroutine=subroutine.concat(currentLine+"\n");
if (lineBeginsWithREMPattern.matcher(currentLine).lookingAt()){
continue;
}
subroutineNameMatcher=subroutineNamePattern.matcher(currentLine);
if (subroutineNameMatcher.find()){
subroutineName=currentLine.substring(subroutineNameMatcher.start(),subroutineNameMatcher.end()-1);
System.out.println("subroutine: "+subroutineName);
continue;
}
includeMatcher=includePattern.matcher(currentLine);
if (includeMatcher.lookingAt()){
if (subroutineName=="") {
subroutineName=currentLine.substring(includeMatcher.start(),includeMatcher.end());
System.out.println("subroutine: "+subroutineName);
}
continue;
}
}
if (state==State.GATHERING) {
subroutine=subroutine.concat(currentLine+"\n");
}
if (state==State.SEEKING) {
customCallpointHeader=customCallpointHeader.concat(currentLine+"\n");
}
}
if (state==State.GATHERING) {
subroutineList.add(subroutineName);
put(subroutineName, subroutine);
}
}
public void insert(String subroutineName, String subroutine){
if (subroutineName==null || subroutineName.equals("") || subroutineName.equals(" ")){
return;
}
String correspondingSubroutineName="";
// Look for a corresponding subroutine name
if (containsKey(subroutineName)) {
correspondingSubroutineName=subroutineName;
}
else {
// Find the corresponding subroutine name if the subroutine ends in a suffix
String suffixes[]={"_after", "_before", "_me"};
for (String suffix:suffixes){
if (subroutineName.endsWith(suffix)){
correspondingSubroutineName=subroutineName.substring(0,subroutineName.length()-suffix.length());
break;
}
}
}
// Handle before callpoints containing a skip and custom callpoints
if (correspondingSubroutineName.length()>0) {
if (remove(correspondingSubroutineName)==null) {
System.out.println("\t"+subroutineName+": not found");
return;
}
changed=true;
put(subroutineName, subroutine);
subroutineList.set(subroutineList.indexOf(correspondingSubroutineName),subroutineName);
System.out.println("\t"+subroutineName+": processed");
return;
}
}
public boolean getChanged(){
return changed;
}
}