forked from moehman/PoolEditSrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.5. Added C header file support to the Import function.
- changed SingleDOM.java to call FileTools.getNewFileChooser() - changed getImageFile() in Tools.java to call FileTools.joinPaths() - changed PoolImportDialog to show header files (.h) - added processHeaderFile() to PoolImporter.java - added new CArrayReader class NOTES: - importing h files is useful in testing as it allows importing object pools that have been exported and then parsed into h files - currently the system almost works but there is a slight problem with the various character encodings in the parser which is likely related to this (from the Expat XML parser homepage): "... although Expat may accept input in various encodings, the strings that it passes to the handlers are always encoded in UTF-8 or UTF-16 (depending on how Expat was compiled). Your application is responsible for any translation of these strings into other encodings."
- Loading branch information
moehman
committed
Nov 11, 2019
1 parent
70668d5
commit c9724f2
Showing
5 changed files
with
249 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright (C) 2019 Automation technology laboratory, | ||
* Helsinki University of Technology | ||
* | ||
* Visit automation.tkk.fi for information about the automation | ||
* technology laboratory. | ||
* | ||
* 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 (at your option) 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, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
* MA 02111-1307, USA. | ||
*/ | ||
package poolimporter; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
/** | ||
* | ||
* @author moehman | ||
*/ | ||
class CArrayReader implements ByteReader { | ||
private final Scanner sc; | ||
public CArrayReader(Scanner sc) { | ||
this.sc = sc; | ||
} | ||
@Override | ||
public int readId() { | ||
return readWord(); | ||
} | ||
|
||
@Override | ||
public int readWord() { | ||
return | ||
(readByte()) | | ||
(readByte() << 8); | ||
} | ||
|
||
@Override | ||
public int readDWord() { | ||
return | ||
(readByte()) | | ||
(readByte() << 8) | | ||
(readByte() << 16) | | ||
(readByte() << 24); | ||
} | ||
|
||
@Override | ||
public float readFloat() { | ||
return Float.intBitsToFloat(readDWord()); | ||
} | ||
|
||
@Override | ||
public int readColor() { | ||
return readByte(); | ||
} | ||
|
||
@Override | ||
public int readType() { | ||
return readByte(); | ||
} | ||
|
||
@Override | ||
public int readByte() { | ||
final int val = Integer.parseInt(sc.next()); | ||
if (val > 0xFF) | ||
throw new RuntimeException("byte too large: " + val); | ||
|
||
return val; | ||
} | ||
|
||
@Override | ||
public byte[] readByteArray(int len) { | ||
byte[] b = new byte[len]; | ||
for (int i = 0; i < len; i++) { | ||
b[i] = (byte) readByte(); | ||
} | ||
return b; | ||
} | ||
|
||
@Override | ||
public int readKeyCode() { | ||
return readByte(); | ||
} | ||
|
||
@Override | ||
public List<Integer> readBytes(int nro) { | ||
List<Integer> list = new ArrayList<>(); | ||
for (int i = 0; i < nro; i++) { | ||
list.add(readByte()); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public int readRef() { | ||
return readWord(); | ||
} | ||
|
||
@Override | ||
public List<Integer> readRefs(int nro) { | ||
List<Integer> list = new ArrayList<>(); | ||
for (int i = 0; i < nro; i++) { | ||
list.add(readRef()); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public List<RefXY> readRefXYs(int nro) { | ||
List<RefXY> list = new ArrayList<>(); | ||
for (int i = 0; i < nro; i++) { | ||
list.add(new RefXY(readRef(), | ||
readWord(), | ||
readWord())); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public List<PointXY> readPoints(int nro) { | ||
List<PointXY> list = new ArrayList<>(); | ||
for (int i = 0; i < nro; i++) { | ||
list.add(new PointXY(readWord(), readWord())); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public List<String> readLanguages(int nro) { | ||
List<String> list = new ArrayList<>(); | ||
for (int i = 0; i < nro; i++) { | ||
String val = readString(2); | ||
list.add(val); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public String readString(int len) { | ||
byte[] b = readByteArray(len); | ||
return new String(b, Charset.forName("ISO-8859-1")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters