3050N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3050N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3050N/A * This code is free software; you can redistribute it and/or modify it 3050N/A * under the terms of the GNU General Public License version 2 only, as 3050N/A * published by the Free Software Foundation. 3050N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3050N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3050N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3050N/A * version 2 for more details (a copy is included in the LICENSE file that 3050N/A * You should have received a copy of the GNU General Public License version 3050N/A * 2 along with this work; if not, write to the Free Software Foundation, 3050N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3050N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3050N/A * or visit www.oracle.com if you need additional information or have any 3050N/A * java NewResourcesNames $( 3050N/A * egrep -q '(ResourcesMgr.getString|rb.getString)' $a && echo $a 3050N/A * Before running this tool, run the following two commands to make sure there 3050N/A * are only these 2 types of calls into the resources: 3050N/A * cat $a | perl -ne 'print if /\bResourcesMgr\b/'; done | 3050N/A * grep -v ResourcesMgr.getString 3050N/A * cat $a | perl -ne 'print if /\brb\b/'; done | 3050N/A // Max length of normalized names 3050N/A // Load all names inside resources files 3050N/A // Modify the callers. There are two patterns: 3050N/A // 1. ResourcesMgr.getString(" 3050N/A // Special case 1: KeyTool's enum definition of commands and options 3050N/A // Special case 2: PolicyFile called this 4 times 3050N/A "ResourcesMgr.getString(POLICY+\""));
3050N/A // During the calls above, you can read sth like: 3050N/A // This means a " exists right after getString(. Sometimes you see 3050N/A // BAD!! pmatch != match: 212 != 209 3050N/A // BAD!! pmatch != match: 14 != 10 3050N/A // which is mismatch. There are only two such special cases list above. 3050N/A // For KeyTool, there are 3 calls for showing help. For PolicyTool, 3 3050N/A // for name prefixed with POLICY. They are covered in the two special 3050N/A // Names used but not defined. This is mostly error, except for 3050N/A // special case 2 above. So it's OK to see 3 entries red here 3050N/A // Names defined but not used. Mostly this is old entries not removed. 3050N/A // When soemone remove a line of code, he dares not remove the entry 3050N/A // in case it's also used somewhere else. 3050N/A * Loads the three resources files. Saves names into a Map. 3050N/A // This is to check that word parsing is identical to Java thinks 3050N/A * Special case treat for enums description in KeyTool 3050N/A int stage =
0;
// 1. commands, 2. options, 3. finished 3050N/A * Loads a resources using JRE and returns the names 3050N/A // Check if normalize() creates dup entries. This is crucial. 3050N/A * Rewrites a file using a pattern. The name string should be right after 3050N/A * the pattern. Note: pattern ignores whitespaces. Returns names found. 3050N/A // The bare XXX.getString is also matched. Sometimes getString is 3050N/A // called but does not use literal strings. This is harder to solve. 3050N/A // The non-whitespace chars read since, used to check for pattern 3050N/A // Save things after the second ". Maybe it's an end, maybe 3050N/A // it's just literal string concatenation. 3050N/A boolean in =
true;
// inside name string 3050N/A "I don't know this escape: %s%c",
3050N/A // Maybe string concat? say bytes until clear 3050N/A if (n ==
'"') {
// string concat, in again 3050N/A }
else if (n ==
',' || n ==
')') {
// real end 3050N/A // Check pheadlen > 0. Don't want to mess with rewrite for resources 3050N/A * Normalize a string. Rules: 3050N/A * 1. If all spacebar return "nSPACE", n is count 3050N/A * 2. If consisting at least one alphanumeric: 3050N/A * a. All alphanumeric remain 3050N/A * b. All others in a row goes to a single ".", even if at head or tail 3050N/A * a. "****\n\n" to "STARNN", special case 3050N/A * b. the English name if first char in *,.\n():'" 3050N/A * Current observations show there's no dup, Hurray! Otherwise, add more 3050N/A if (n ==
1)
return "SPACE";
3050N/A else if (n >
1)
return "" + n +
"SPACE";
3050N/A // Rememeber the last dot, we want shorter form nice 3050N/A // "." only added when an alphanumeric is seen. This makes 3050N/A // sure sb is empty when there's no alphanumerics at all 3050N/A case '\n':
return "NEWLINE";
3050N/A case '\'':
case '"':
return "QUOTE";
3050N/A // tail "." only added when there are alphanumerics