[OpenVMS, Java] VMS C RTL decc$translate_name translated to pure Java

PRODUCT: J2SE(TM) Development Kit (JDK) 6.0-1
OP/SYS: OpenVMS IA64 V8.3-1H1 and above
COMPONENT: OpenVMS file specification to Unix file specification.
SOURCE: Philippe Vouters Fontainebleau/France
HIGH QUALITY MOBILES+TABLETS: http://android-land.fr
OVERVIEW: The code in the PROGRAM section handles ODS-2 and ODS-5 VMS style file formats and turn them to Unix style file formats. ODS-5 escape sequences handling is based upon the statements at : http://h71000.www7.hp.com/doc/73final/6536/6536pro_002.html#ods5names_hd In fact this algorythm may be used in any compiled or interpreted code which enables access to a Regular Expressions library and needing to convert a VMS style file syntax into a Unix style file syntax. One such type of Opensource code performing a VMS to Unix filename translation is FileZilla. FileZilla is written in C++ and uses like this Java code an object oriented approach. For such an Opensource application, the Perl's Compatible Regular Expressions (PCRE) library may be used on both Windows and Linux. For more information about PCRE, refer to the PCRE home page at http://www.pcre.org/. For C and C++ PCRE usage code samples, refer to the document in this knowledge database at: ../tima/Linux-Tcl-PHP-Perl-Python-Ruby-Java-C-C++-PCRE-Turning_Cobol_DECforms_C_VMS_Listings_to_source.html
*** CAUTION *** This sample program has been tested using J2SE V6.0 on OpenVMS IA64 V8.3-1H1. However, we cannot guarantee its effectiveness because of the possibility of error in transmitting or implementing it. It is meant to be used as a template for writing your own program, and may require modification for use on your system.
PROGRAM NOTES: This code is primarily intended to people offering Java based languages such as JRyby and Jython, respectively implementing Java based Ruby and Python languages. This code is to aid porting such codes onto OpenVMS so that an OpenVMS file syntax is correclty handled by the Java based language.
PROGRAM OUTPUT: $! $! Testing normal ODS-2 file specifications. $! $ java "DeccTranslateName" foo.java; VMS style : foo.java;; Unix style : /PHV/PHV/foo.java $ java "DeccTranslateName" [directory.subdirectory]foo.java; VMS style : [directory.subdirectory]foo.java;; Unix style : /PHV/directory/subdirectory/foo.java $ java "DeccTranslateName" [.subdirectory]foo.java; VMS style : [.subdirectory]foo.java;; Unix style : /PHV/PHV/subdirectory/foo.java $ java "DeccTranslateName" <.subdirectory>foo.java; VMS style : <.subdirectory>foo.java;; Unix style : /PHV/PHV/subdirectory/foo.java $! $! Testing escaped dots. $! $ java "DeccTranslateName" $disk$1:[.proxy-2^.5^.4]proxy^.2^.5^.c.save VMS style : $disk$1:[.proxy-2^.5^.4]proxy^.2^.5^.c.save; Unix style : /$disk$1/PHV/proxy-2.5.4/proxy.2.5.c.save $ java "DeccTranslateName" $disk$1:[]proxy^.2^.5^.c.save VMS style : $disk$1:[]proxy^.2^.5^.c.save; Unix style : /$disk$1/PHV/proxy.2.5.c.save $ java "DeccTranslateName" proxy^.2^.5^.c.save VMS style : proxy^.2^.5^.c.save; Unix style : /PHV/PHV/proxy.2.5.c.save $! $! Testing '-' in directory paths. $! $ java "DeccTranslateName" [-.-]DECC_test.rb VMS style : [-.-]decc_test.rb; Unix style : /PHV/PHV/../../decc_test.rb $ java "DeccTranslateName" [-]DECC_test.rb VMS style : [-]decc_test.rb; Unix style : /PHV/PHV/../decc_test.rb $ java "DeccTranslateName" [.jruby_vms.-]DECC_test.rb; You entered an invalid Unix or VMS style filespec ./jruby_vms/../DECC_test.rb; $ java "DeccTranslateName" [.jruby_vms.-]DECC_test.rb;3 You entered an invalid Unix or VMS style filespec ./jruby_vms/../DECC_test.rb;3 $ define JAVA$FILENAME_CONTROLS 0 $ java "DeccTranslateName" [.jruby_vms.-]DECC_test.rb;3 VMS style : [.jruby_vms.-]DECC_test.rb;3; Unix style : /PHV/PHV/jruby_vms/../DECC_test.rb $! $! Testing "<>" in directory paths. $! $ dir DECC_test.rb Directory PHV:[PHV] DECC_test.rb;3 Total of 1 file. $ define JAVA$FILENAME_CONTROLS -1 $ java "DeccTranslateName" <>DECC_test.rb You entered a valid Unix style filespec :./decc_test.rb $ java "DeccTranslateName" <>DECC_test.rb; You entered an invalid Unix or VMS style filespec ./decc_test.rb; $ define JAVA$FILENAME_CONTROLS 0 $ java "DeccTranslateName" <>DECC_test.rb; VMS style : <>decc_test.rb;; Unix style : /PHV/PHV/decc_test.rb $ deassign JAVA$FILENAME_CONTROLS $! $! Testing non dot escaped characters. $! $ java "DeccTranslateName" g^+^+ VMS style : g^+^+; Unix style : /PHV/PHV/g++ $ java "DeccTranslateName" ...save; VMS style : ...save;; Unix style : /PHV/PHV/...save $ java "DeccTranslateName" "^ .save" VMS style : ^ .save; Unix style : /PHV/PHV/ .save $ java "DeccTranslateName" "^_.save" VMS style : ^_.save; Unix style : /PHV/PHV/ .save $ java "DeccTranslateName" ^&save.;32 VMS style : ^&save.;32; Unix style : /PHV/PHV/&save $ java "DeccTranslateName" <>foo.1.2.foo^;32 VMS style : <>foo.1.2.foo^;32; Unix style : /PHV/PHV/foo.1.2.foo;32 $ java "DeccTranslateName" [.file^:.foo]bar.txt VMS style : [.file^:.foo]bar.txt; Unix style : /PHV/PHV/file:/foo/bar.txt $! $! Testing dot escaped or non escaped filenames $! $ dire ...save Directory PHV:[PHV] ^.^..save;1 Total of 1 file. $ java "DeccTranslateName" ...save; VMS style : ...save;; Unix style : /PHV/PHV/...save $ java "DeccTranslateName" proxy^.2^.5.c.save VMS style : proxy^.2^.5.c.save; Unix style : /PHV/PHV/proxy.2.5.c.save $ java "DeccTranslateName" g...; VMS style : g...;; Unix style : /PHV/PHV/g.. $ java "DeccTranslateName" g^.^. VMS style : g^.^.; Unix style : /PHV/PHV/g.. $ java "DeccTranslateName" g^.^.. VMS style : g^.^..; Unix style : /PHV/PHV/g.. $ java "DeccTranslateName" g^.^..; VMS style : g^.^..;; Unix style : /PHV/PHV/g.. $ java "DeccTranslateName" []g... VMS style : []g...; Unix style : /PHV/PHV/g.. $! $! Testing file extensions without filename. $! The first one corresponds to ODS-2 or ODS-5 $disk$1:[].bash_history; $! The second one corresponds to ODS-2 or ODS-5 [].; $! The third one corresponds to ODS-2 or ODS-5 [].102; $! The fourth and fifth one corresponds to ODS-5 [].102;1 $! $ java "DeccTranslateName" $disk$1:[].bash_history VMS style : $disk$1:[].bash_history; Unix style : /$disk$1/PHV/.bash_history $ java "DeccTranslateName" .; VMS style : .;; Unix style : /PHV/PHV/ $ java "DeccTranslateName" [].102 VMS style : [].102; Unix style : /PHV/PHV/.102 $ java "DeccTranslateName" [].102.1 VMS style : [].102.1; Unix style : /PHV/PHV/.102 $ java "DeccTranslateName" [].102;1 VMS style : [].102;1; Unix style : /PHV/PHV/.102 $! $! With JAVA$FILENAME_CONTROLS set to "-1" $! $ java "DeccTranslateName" []. You entered a valid Unix style filespec :./. $! $! This one corresponds to ODS-5 g^.^..1; $! $ java "DeccTranslateName" []g^.^..1 VMS style : []g^.^..1; Unix style : /PHV/PHV/g...1 $! $! These two correspond to ODS-5 g^.^..;1 $! $ java "DeccTranslateName" []g^.^..;1 VMS style : []g^.^..;1; Unix style : /PHV/PHV/g.. $ java "DeccTranslateName" []g^.^...1 VMS style : []g^.^...1; Unix style : /PHV/PHV/g.. $! $! Testing escaped hexadecimal bytes and Unicode characters. $! Refer to http://www.utf8-chartable.de/unicode-utf8-table.pl $! for valid unicode bytes sequences. Here we test with C2A3 $! hexadecimal unicode value which corresponds to the pound sign $! and with C2BC hexadecimal unicode value which corresponds to $! the vulgar fraction one quarter. These two hexadecimal unicode $! values are taken from this table. We also test escaped $! hexadecimal byte 20 which corresponds to a space. $! $ define LANG "UTF8-20" $ java "DeccTranslateName" "^UC2A3^.foo.save" VMS style : ^UC2A3^.foo.save; Unix style : /PHV/PHV/£.foo.save $ java "DeccTranslateName" "^Uc2bc^.foo.save" VMS style : ^Uc2bc^.foo.save; Unix style : /PHV/PHV/¼.foo.save $ java "DeccTranslateName" "^20.save" VMS style : ^20.save; Unix style : /PHV/PHV/ .save $! $! Testing escaped sequences without the escape character. $! In fact, accepted sequences start with a character $! appearing after and including '0' in validEscapedCharacters $! variable. $! $ java "DeccTranslateName" foo_j.java; VMS style : foo_j.java;; Unix style : /PHV/PHV/foo_j.java $ java "DeccTranslateName" 20.save; VMS style : 20.save;; Unix style : /PHV/PHV/20.save $ java "DeccTranslateName" "U017E.save;" VMS style : U017E.save;; Unix style : /PHV/PHV/U017E.save $ java "DeccTranslateName" &foo_j.java; You entered an invalid Unix or VMS style filespec &foo_j.java; $! $! Below $disk$1 is neither a valid volume nor an existing $! logical on this OpenVMS computer. $! $ java "DeccTranslateName" $disk$1:login.com VMS style : $disk$1:login.com; Unix style : /$disk$1/PHV/login.com $! $! You will note that, with these two syntaxes, $! containing existing disk volumes or logicals, $! the input argument is turned by the Java runtime $! into a valid Unix style filespec !!! In fact, this $! is because JAVA$FILENAME_CONTROLS is set to -1 and $! each argument passed to Java is RMS searched for. $! $ java "DeccTranslateName" tcpip$library:tcpip$lib.olb You entered a valid Unix style filespec :/tcpip$library/tcpip$lib.olb $ java "DeccTranslateName" "PHV:login.com" You entered a valid Unix style filespec :/PHV/PHV/login.com $! $! More explanations about JAVA$FILENAME_CONTROLS logical and $! RMS searching for input arguments. $! $ define JAVA$FILENAME_CONTROLS 0 $ java "DeccTranslateName" "PHV:login.com" VMS style : PHV:login.com; Unix style : /PHV/PHV/login.com $ define JAVA$FILENAME_CONTROLS -1 %DCL-I-SUPERSEDE, previous value of JAVA$FILENAME_CONTROLS has been superseded $ java "DeccTranslateName" "PHV:login.com" You entered a valid Unix style filespec :/PHV/PHV/login.com $ set default [-] $ java -cp PHV/ "DeccTranslateName" "PHV:login.com" VMS style : PHV:login.com; Unix style : /PHV/000000/login.com $ set default [PHV] $! $! Invalid syntaxes. $! The first one is because ++ are not escaped. $! The second one is because $ is not a valid escape $! character. The third one is because ':' in $! "disk^+1^:" is not a valid ODS-5 character. $! The fourth one is because foo is not valid as a $! version number. The fifth and sixth syntax are $! rejected because the version number is greater $! than 32767. The seventh one is because the escape $! character '^' ends the file name. $! $ java "DeccTranslateName" <>g++.;32 You entered an invalid Unix or VMS style filespec <>g++.;32 $ java "DeccTranslateName" "disk$^$1:foo.save" You entered an invalid Unix or VMS style filespec disk$^$1:foo.save $ java "DeccTranslateName" disk^+1^::foo^.s^;ve.c; You entered an invalid Unix or VMS style filespec disk^+1^::foo^.s^;ve.c; $ java "DeccTranslateName" proxy^.2^.5.c.save;foo You entered an invalid Unix or VMS style filespec proxy^.2^.5.c.save;foo $ java "DeccTranslateName" proxy^.2^.5.c.save.32768 You entered an invalid Unix or VMS style filespec proxy^.2^.5.c.save.32768 $ java "DeccTranslateName" proxy^.2^.5.c.save;32768 You entered an invalid Unix or VMS style filespec proxy^.2^.5.c.save;32768 $ java "DeccTranslateName" g^.^ You entered an invalid Unix or VMS style filespec g^.^ $! $! Testing file versions $! $ java "DeccTranslateName" foo.1.2;32 VMS style : foo.1.2;32; Unix style : /PHV/PHV/foo.1.2 $ java "DeccTranslateName" <>foo.1.2.32 VMS style : <>foo.1.2.32; Unix style : /PHV/PHV/foo.1.2 $ java "DeccTranslateName" foo.1.2.32 You entered a valid Unix style filespec :foo.1.2.32 $! $! Valid Unix style filespec syntaxes $! $ java "DeccTranslateName" g++ You entered a valid Unix style filespec :g++ $ java "DeccTranslateName" g++.c You entered a valid Unix style filespec :g++.c $ java "DeccTranslateName" login.com You entered a valid Unix style filespec :login.com
SOURCE CODE DOWNLOAD: Instead of performing a cut'n paste of the program in the PROGRAM section, you can download it in zipped format from ../zip/DeccTranslateName.java.zip
PROGRAM: // // File : DeccTranslateName.java // // Copyright (C) 2011 by Philippe.Vouters@laposte.net // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>;. // import java.util.regex.Pattern; import java.util.regex.Matcher; import java.io.IOException; public class DeccTranslateName { // // For ODS-5 special characters and valid character set, refer to : // http://h71000.www7.hp.com/doc/73final/6536/6536pro_002.html#ods5names_hd // public static String validEscapedCharacters = "+,;\\[\\]%\\^\\:& "+ "012345789ABCDEFU._"; public static String invalidOds5Characters = "\"\\*\\\\<>/\\?\\|"; private static class StringAndIntRecord{ private String vmstoUnixFilespec; private String vmsFilespec; private int startStringIndex; private static final char[] kDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private int CheckValidEscapedCharacter(){ // // Parse the input string to check whether all circumflex characters // are immediately followed by a valid escaped character. // Except the dot, check whether an escaped character is not found // without a preceeding circumflex character. // for (int i = startStringIndex; i < vmsFilespec.length(); i++){ if (vmsFilespec.charAt(i) == '^' && i < vmsFilespec.length()-1){ int escapeCharIndex = validEscapedCharacters.indexOf(vmsFilespec.charAt(i+1)); if (escapeCharIndex == -1) return -1; if (escapeCharIndex < validEscapedCharacters.indexOf('0') || escapeCharIndex > validEscapedCharacters.indexOf('U')){ i++; continue; } else if (escapeCharIndex >= validEscapedCharacters.indexOf('0') && escapeCharIndex < validEscapedCharacters.indexOf('U') && i < vmsFilespec.length() - 2){ for (int j= 0; j < 2; j++){ if (vmsFilespec.charAt(i+1+j) >= 'a' && vmsFilespec.charAt(i+1+j) <= 'f') vmsFilespec = vmsFilespec.substring(0,i+1+j) + Character.toUpperCase( vmsFilespec.charAt(i+1+j)) + vmsFilespec.substring(i+2+j, vmsFilespec.length()); } for (int j= 0; j < 2; j++){ if (!Character.isDigit(vmsFilespec.charAt(i+1+j))&& (vmsFilespec.charAt(i+1+j) < 'A' || vmsFilespec.charAt(i+1+j) > 'F')) return -1; } i += 2; continue; } else if (escapeCharIndex == validEscapedCharacters.indexOf('U') && i < vmsFilespec.length() - 5) { for (int j = 0; j < 4 ; j++){ if (vmsFilespec.charAt(i+2+j) >= 'a' && vmsFilespec.charAt(i+2+j) <= 'f') vmsFilespec = vmsFilespec.substring(0,i+2+j) + Character.toUpperCase( vmsFilespec.charAt(i+2+j)) + vmsFilespec.substring(i+3+j, vmsFilespec.length()); } for (int j= 0; j < 4; j++){ if (!Character.isDigit(vmsFilespec.charAt(i+2+j))&& (vmsFilespec.charAt(i+2+j) < 'A' || vmsFilespec.charAt(i+2+j) > 'F')) return -1; } i += 5; continue; } else return -1; } int escapeCharIndex = validEscapedCharacters.indexOf(vmsFilespec.charAt(i)); if (escapeCharIndex != -1 && escapeCharIndex < validEscapedCharacters.indexOf('0')) return -1; } return 0; } // // the two hexToBytes methods are copied from: // http://www.java2s.com/Code/Java/Development-Class/ConverthexToBytes.htm // public static byte[] hexToBytes(char[] hex) { int length = hex.length / 2; byte[] raw = new byte[length]; for (int i = 0; i < length; i++) { int high = Character.digit(hex[i * 2], 16); int low = Character.digit(hex[i * 2 + 1], 16); int value = (high << 4) | low; if (value > 127) value -= 256; raw[i] = (byte) value; } return raw; } public static byte[] hexToBytes(String hex) { return hexToBytes(hex.toCharArray()); } public String getVmstoUnixFilespec(){ return vmstoUnixFilespec; } public StringAndIntRecord(String vmsFilespec, int startStringIndex){ this.startStringIndex = startStringIndex; this.vmsFilespec = vmsFilespec; } public void turnAllCircumflex(boolean addSlash){ int posDot; vmstoUnixFilespec = ""; if (vmsFilespec.length() == 0) return; if (CheckValidEscapedCharacter() == -1){ vmstoUnixFilespec = null; return; } // // Process all dots except if it starts the string and if not // preceeded by a cicumflex character for a directory operation // (addSlash == true). For a file operation (addSlash == false), // treat the dot as valid if not preceeded by a circumflex. // If preceeded by a circumflex, this is processed later in this // routine in the final while loop. // while ((posDot = vmsFilespec.indexOf('.',startStringIndex)) != -1){ if (startStringIndex < posDot && vmsFilespec.charAt(posDot-1) != '^'){ vmstoUnixFilespec += vmsFilespec.substring(startStringIndex, posDot); if (addSlash) vmstoUnixFilespec += "/"; else vmstoUnixFilespec += "."; } else if (posDot != startStringIndex && vmsFilespec.charAt(posDot-1) == '^') vmstoUnixFilespec += vmsFilespec.substring(startStringIndex, posDot+1); else if (posDot == startStringIndex && !addSlash){ vmstoUnixFilespec += "."; } startStringIndex = posDot+1; } // // No more dots to process, add in the remaining of the input string // if (startStringIndex < vmsFilespec.length()) vmstoUnixFilespec += vmsFilespec.substring(startStringIndex, vmsFilespec.length()); // // Add in final slash if requested. // if (addSlash && vmstoUnixFilespec.length() != 0) vmstoUnixFilespec += "/"; // // Process VMS file specification escape characters. // posDot = 0; while ((posDot = vmstoUnixFilespec.indexOf('^',posDot)) != -1){ if (validEscapedCharacters.indexOf( vmstoUnixFilespec.charAt(posDot+1)) != -1){ int escapeCharIndex = validEscapedCharacters.indexOf(vmstoUnixFilespec.charAt(posDot+1)); if (escapeCharIndex < validEscapedCharacters.indexOf('0') || escapeCharIndex > validEscapedCharacters.indexOf('U')){ if (validEscapedCharacters.charAt(escapeCharIndex) == '_') { vmstoUnixFilespec = vmstoUnixFilespec.substring(0,posDot) + " " + vmstoUnixFilespec.substring(posDot+2, vmstoUnixFilespec.length()); } else { vmstoUnixFilespec = vmstoUnixFilespec.substring(0,posDot) + vmstoUnixFilespec.charAt(posDot+1) + vmstoUnixFilespec.substring(posDot+2, vmstoUnixFilespec.length()); } } else if (escapeCharIndex >= validEscapedCharacters.indexOf('0') && escapeCharIndex < validEscapedCharacters.indexOf('U')){ byte[] hexChar = hexToBytes( vmstoUnixFilespec.substring(posDot+1, posDot+3)); // Do not accept control characters in the // range 0x00 to 0x1F if (hexChar[0] < 32 ){ vmstoUnixFilespec = null; return; } vmstoUnixFilespec = vmstoUnixFilespec.substring(0,posDot) + (char)hexChar[0] + vmstoUnixFilespec.substring(posDot+3, vmstoUnixFilespec.length()); } else if (escapeCharIndex == validEscapedCharacters.indexOf('U')){ byte [] hexTwoBytes = hexToBytes( vmstoUnixFilespec.substring(posDot+2, posDot+6)); // Do not accept control characters in the // range 0x00 to 0x1F if (hexTwoBytes[0] == 0 && hexTwoBytes[1] < 32 ){ vmstoUnixFilespec = null; return; } String UnicodeChar = new String(hexTwoBytes); vmstoUnixFilespec = vmstoUnixFilespec.substring(0,posDot) + UnicodeChar + vmstoUnixFilespec.substring(posDot+6, vmstoUnixFilespec.length()); } } posDot++; } // // process "-/" in directory paths. // if (addSlash){ posDot = 0; while ((posDot = vmstoUnixFilespec.indexOf("-/",posDot)) != -1){ vmstoUnixFilespec = vmstoUnixFilespec.substring(0,posDot) + "../" + vmstoUnixFilespec.substring(posDot+2, vmstoUnixFilespec.length()); posDot += 3; } } } } private static boolean checkVersionNumber(String version){ int versionNumber = Integer.parseInt(version); if (versionNumber > 32767) return false; return true; } public static String deccTranslate_name (String vmsFilespec) { String diskname = "^([^"\\[+invalidOds5Characters+"\\]]+:)?"; String directory = "((\\[|<)" + "([^"+invalidOds5Characters+"]){0,}"+ "(\\]|>))?"; String filename = "([^"+invalidOds5Characters+"]+)"; String extension = "(\\.([^"+invalidOds5Characters+"]+)?)"; String version = "(;(\\d+)?)?"; Pattern regex = Pattern.compile(diskname + directory + filename + "{0,1}" + extension + version); int MAX_MATCH = 10; Matcher fit=regex.matcher(vmsFilespec); if (!fit.matches()){ regex = Pattern.compile(diskname + directory + filename); fit=regex.matcher(vmsFilespec); if (!fit.matches()) return null; else MAX_MATCH = 7; } boolean debug = Boolean.valueOf(System.getProperty("debug","false")); if (debug) { for (int i=0; i<MAX_MATCH;i++) System.out.println("fit.group("+i+") = "+fit.group(i)); } char closingDir = 0; if (fit.group(1) != null && fit.group(2) == null) closingDir = ':'; if ((fit.group(3) != null && fit.group(5) == null) || (fit.group(3) == null && fit.group(5) != null)) return null; if (fit.group(3) != null && fit.group(5) != null){ if (fit.group(3).compareTo("[") == 0 && fit.group(5).compareTo("]") != 0) return null; if (fit.group(3).compareTo("<") == 0 && fit.group(5).compareTo(">") != 0) return null; closingDir = fit.group(5).charAt(0); } String currentDir; try { currentDir = new java.io.File( "." ).getCanonicalPath(); } catch (IOException e) { return null; } int posDot; int startStringIndex = 1; boolean processMatch2 = true; String vmstoUnixFilespec = new String(currentDir); int lastIndexOfCurrentDir = vmstoUnixFilespec.lastIndexOf('/'); for (int i = 1; i < MAX_MATCH; i++){ switch (i) { case 1: if (fit.group(1) != null){ int posSlash = vmstoUnixFilespec.indexOf('/',1); if (posSlash == -1) posSlash = vmstoUnixFilespec.length(); else posSlash++; StringAndIntRecord record = new StringAndIntRecord( fit.group(1).substring( 0, fit.group(1).indexOf(':')), 0); record.turnAllCircumflex(true); String returnedString = record.getVmstoUnixFilespec(); if (returnedString == null) return null; vmstoUnixFilespec = "/"+ returnedString + vmstoUnixFilespec.substring( posSlash, vmstoUnixFilespec.length()); } if (vmstoUnixFilespec.charAt( vmstoUnixFilespec.length()- 1) != '/') vmstoUnixFilespec += "/"; break; case 2: if (fit.group(2) != null && processMatch2 && startStringIndex < fit.group(2).length()){ StringAndIntRecord record = new StringAndIntRecord( fit.group(2).substring( startStringIndex, fit.group(2).indexOf(closingDir)), 0); record.turnAllCircumflex(true); String returnedString = record.getVmstoUnixFilespec(); if (returnedString == null) return null; vmstoUnixFilespec += returnedString; } break; case 6: if (fit.group(6) != null){ StringAndIntRecord record = new StringAndIntRecord( fit.group(6), 0); record.turnAllCircumflex(false); String returnedString = record.getVmstoUnixFilespec(); if (MAX_MATCH == 10 && returnedString == null && fit.group(6).charAt(fit.group(6).length()-1) == '^' && fit.group(7).compareTo(".") == 0){ String correctedString = fit.group(6) + fit.group(7); record = new StringAndIntRecord( correctedString, 0); record.turnAllCircumflex(false); returnedString = record.getVmstoUnixFilespec(); } if (returnedString == null) return null; vmstoUnixFilespec += returnedString; } break; case 8: if (fit.group(8) != null) { // // Valid if filename is foo.1.2.3 in which // case .3 is taken as a version number. In this // case, fit.group(8) is "3" and fit.group(6) equals // "foo.1.2" which leads to ODS-5 filename foo.1.2;3. // Do not take into if filename foo.1 in which // case fit.group(6) is equal to "foo" and this // fit.group(8) is "1", the ODS-5 filename is // foo.1;. For []foo...1, the ODS-5 filename is // foo^..;1 so the version must taken into account. // For []foo..102, the ODS-5 filename is foo^..102; // so add in 102 as the file extension. // int lastIndexDot = vmstoUnixFilespec.lastIndexOf('.'); String numeric = new String("\\d+"); Pattern numericRegex = Pattern.compile(numeric); Matcher matcher = numericRegex.matcher(fit.group(8)); if (matcher.matches()){ matcher = numericRegex.matcher( vmstoUnixFilespec.substring( lastIndexDot +1, vmstoUnixFilespec.length())); if (matcher.matches()){ if (!checkVersionNumber(fit.group(8))) return null; break; } else if (lastIndexDot != -1 && lastIndexDot != vmstoUnixFilespec.length() - 1){ if (!checkVersionNumber(fit.group(8))) return null; break; } else if (lastIndexDot != -1 && lastIndexDot == vmstoUnixFilespec.length() - 1 && fit.group(6).charAt( fit.group(6).length() -2) != '^'){ if (!checkVersionNumber(fit.group(8))) return null; vmstoUnixFilespec = vmstoUnixFilespec.substring( 0, vmstoUnixFilespec.length() - 1); break; } } int lastSemiColon = fit.group(8).lastIndexOf(';'); if (lastSemiColon == - 1 || (lastSemiColon > 0 && fit.group(8).charAt(lastSemiColon - 1) == '^')) lastSemiColon = fit.group(8).length(); else if (lastSemiColon != fit.group(8).length() - 1){ matcher = numericRegex.matcher( fit.group(8).substring( lastSemiColon +1, fit.group(8).length())); if (!matcher.matches()) return null; if (!checkVersionNumber( fit.group(8).substring( lastSemiColon +1, fit.group(8).length()))) return null; } StringAndIntRecord record = new StringAndIntRecord( fit.group(8).substring( 0,lastSemiColon), 0); record.turnAllCircumflex(false); String returnedString = record.getVmstoUnixFilespec(); if (returnedString == null) return null; if (lastSemiColon > 0) vmstoUnixFilespec += "." + returnedString; } break; } // end switch } return vmstoUnixFilespec; } public static void main (String[] args) throws java.io.IOException { if (args.length != 1){ System.out.println ("Usage: java \"DeccTranslateName\" filespec"); System.exit(1); } Pattern regex = Pattern.compile("^((/)?([\\w\\-\\$\\.\\+ ])){1,}"); Matcher fit=regex.matcher(args[0]); if (fit.matches()){ System.out.println ("You entered a valid Unix style filespec :" + args[0]); } else { String vmsToUnixString = deccTranslate_name(args[0]);; if (vmsToUnixString == null) System.out.println ("You entered an invalid Unix or VMS "+ "style filespec\n" + args[0]); else System.out.println ("VMS style : "+args[0]+"; Unix style : "+ vmsToUnixString); } } }
REFERENCE(S): Google searches for Java code samples.