@@ -61,10 +61,10 @@ static public KeywordMap getKeywords() {
61
61
try {
62
62
keywordColoring = new KeywordMap (false );
63
63
keywordToReference = new Hashtable ();
64
- getKeywords (Base . getLibStream ( "keywords.txt" ));
64
+ getKeywords (new File ( BaseNoGui . getContentFile ( "lib" ), "keywords.txt" ));
65
65
for (ContributedLibrary lib : Base .getLibraries ()) {
66
66
File keywords = new File (lib .getInstalledFolder (), "keywords.txt" );
67
- if (keywords .exists ()) getKeywords (new FileInputStream ( keywords ) );
67
+ if (keywords .exists ()) getKeywords (keywords );
68
68
}
69
69
} catch (Exception e ) {
70
70
Base .showError ("Problem loading keywords" ,
@@ -76,51 +76,56 @@ static public KeywordMap getKeywords() {
76
76
return keywordColoring ;
77
77
}
78
78
79
- static private void getKeywords (InputStream input ) throws Exception {
80
- InputStreamReader isr = new InputStreamReader (input );
81
- BufferedReader reader = new BufferedReader (isr );
82
-
83
- String line = null ;
84
- while ((line = reader .readLine ()) != null ) {
85
- //System.out.println("line is " + line);
86
- // in case there's any garbage on the line
87
- //if (line.trim().length() == 0) continue;
88
-
89
- String pieces [] = PApplet .split (line , '\t' );
90
- if (pieces .length >= 2 ) {
91
- //int tab = line.indexOf('\t');
92
- // any line with no tab is ignored
93
- // meaning that a comment is any line without a tab
94
- //if (tab == -1) continue;
95
-
96
- String keyword = pieces [0 ].trim ();
97
- //String keyword = line.substring(0, tab).trim();
98
- //String second = line.substring(tab + 1);
99
- //tab = second.indexOf('\t');
100
- //String coloring = second.substring(0, tab).trim();
101
- //String htmlFilename = second.substring(tab + 1).trim();
102
- String coloring = pieces [1 ].trim ();
103
-
104
- if (coloring .length () > 0 && Character .isDigit (coloring .charAt (coloring .length () - 1 ))) {
105
- // text will be KEYWORD or LITERAL
106
- boolean isKey = (coloring .charAt (0 ) == 'K' );
107
- // KEYWORD1 -> 0, KEYWORD2 -> 1, etc
108
- int num = coloring .charAt (coloring .length () - 1 ) - '1' ;
109
- byte id = (byte )
110
- ((isKey ? Token .KEYWORD1 : Token .LITERAL1 ) + num );
111
- //System.out.println("got " + (isKey ? "keyword" : "literal") +
112
- // (num+1) + " for " + keyword);
113
- keywordColoring .add (keyword , id );
114
- }
115
- if (pieces .length >= 3 ) {
116
- String htmlFilename = pieces [2 ].trim ();
117
- if (htmlFilename .length () > 0 ) {
118
- keywordToReference .put (keyword , htmlFilename );
79
+ static private void getKeywords (File input ) throws IOException {
80
+ BufferedReader reader = null ;
81
+ try {
82
+ reader = new BufferedReader (new InputStreamReader (new FileInputStream (input )));
83
+
84
+ String line = null ;
85
+ while ((line = reader .readLine ()) != null ) {
86
+ //System.out.println("line is " + line);
87
+ // in case there's any garbage on the line
88
+ //if (line.trim().length() == 0) continue;
89
+
90
+ String pieces [] = PApplet .split (line , '\t' );
91
+ if (pieces .length >= 2 ) {
92
+ //int tab = line.indexOf('\t');
93
+ // any line with no tab is ignored
94
+ // meaning that a comment is any line without a tab
95
+ //if (tab == -1) continue;
96
+
97
+ String keyword = pieces [0 ].trim ();
98
+ //String keyword = line.substring(0, tab).trim();
99
+ //String second = line.substring(tab + 1);
100
+ //tab = second.indexOf('\t');
101
+ //String coloring = second.substring(0, tab).trim();
102
+ //String htmlFilename = second.substring(tab + 1).trim();
103
+ String coloring = pieces [1 ].trim ();
104
+
105
+ if (coloring .length () > 0 && Character .isDigit (coloring .charAt (coloring .length () - 1 ))) {
106
+ // text will be KEYWORD or LITERAL
107
+ boolean isKey = (coloring .charAt (0 ) == 'K' );
108
+ // KEYWORD1 -> 0, KEYWORD2 -> 1, etc
109
+ int num = coloring .charAt (coloring .length () - 1 ) - '1' ;
110
+ byte id = (byte )
111
+ ((isKey ? Token .KEYWORD1 : Token .LITERAL1 ) + num );
112
+ //System.out.println("got " + (isKey ? "keyword" : "literal") +
113
+ // (num+1) + " for " + keyword);
114
+ keywordColoring .add (keyword , id );
115
+ }
116
+ if (pieces .length >= 3 ) {
117
+ String htmlFilename = pieces [2 ].trim ();
118
+ if (htmlFilename .length () > 0 ) {
119
+ keywordToReference .put (keyword , htmlFilename );
120
+ }
119
121
}
120
122
}
121
123
}
124
+ } finally {
125
+ if (reader != null ) {
126
+ reader .close ();
127
+ }
122
128
}
123
- reader .close ();
124
129
}
125
130
126
131
0 commit comments