From 602cea1bbeb1adae33b72c44bef46544dda1754e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Wed, 1 May 2013 15:01:05 +0200 Subject: [PATCH] replacing images --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 89 +- .../decompiler/flash/SWFInputStream.java | 14 + .../decompiler/flash/SWFOutputStream.java | 90 ++ .../jpexs/decompiler/flash/gui/MainFrame.java | 136 +- .../flash/tags/DefineBitsJPEG2Tag.java | 26 +- .../flash/tags/DefineBitsJPEG3Tag.java | 40 +- .../flash/tags/DefineBitsJPEG4Tag.java | 36 +- .../flash/tags/DefineBitsLossless2Tag.java | 59 +- .../flash/tags/DefineBitsLosslessTag.java | 47 +- .../decompiler/flash/tags/DefineBitsTag.java | 47 +- .../decompiler/flash/tags/base/ImageTag.java | 62 + .../decompiler/flash/tags/text/TextLexer.java | 1332 +++++++++-------- 12 files changed, 1184 insertions(+), 794 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 5c89bc1c7..a94e5622b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -52,12 +52,6 @@ import com.jpexs.decompiler.flash.gui.TagNode; import com.jpexs.decompiler.flash.helpers.Helper; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsLossless2Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag; -import com.jpexs.decompiler.flash.tags.DefineBitsTag; import com.jpexs.decompiler.flash.tags.DefineButton2Tag; import com.jpexs.decompiler.flash.tags.DefineButtonTag; import com.jpexs.decompiler.flash.tags.DefineSoundTag; @@ -75,6 +69,7 @@ import com.jpexs.decompiler.flash.tags.VideoFrameTag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.Container; +import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.types.RECT; @@ -560,24 +555,6 @@ public class SWF { } } - private static String getImageFormat(byte data[]) { - if (hasErrorHeader(data)) { - return "jpg"; - } - if (data.length > 2 && ((data[0] & 0xff) == 0xff) && ((data[1] & 0xff) == 0xd8)) { - return "jpg"; - } - if (data.length > 6 && ((data[0] & 0xff) == 0x47) && ((data[1] & 0xff) == 0x49) && ((data[2] & 0xff) == 0x46) && ((data[3] & 0xff) == 0x38) && ((data[4] & 0xff) == 0x39) && ((data[5] & 0xff) == 0x61)) { - return "gif"; - } - - if (data.length > 8 && ((data[0] & 0xff) == 0x89) && ((data[1] & 0xff) == 0x50) && ((data[2] & 0xff) == 0x4e) && ((data[3] & 0xff) == 0x47) && ((data[4] & 0xff) == 0x0d) && ((data[5] & 0xff) == 0x0a) && ((data[6] & 0xff) == 0x1a) && ((data[7] & 0xff) == 0x0a)) { - return "png"; - } - - return "unk"; - } - public static boolean hasErrorHeader(byte data[]) { if (data.length > 4) { if ((data[0] & 0xff) == 0xff) { @@ -864,7 +841,7 @@ public class SWF { } } - public static void exportImages(String outdir, List tags, JPEGTablesTag jtt) throws IOException { + public void exportImages(String outdir, List tags) throws IOException { if (tags.isEmpty()) { return; } @@ -872,64 +849,8 @@ public class SWF { (new File(outdir)).mkdirs(); } for (Tag t : tags) { - if ((t instanceof DefineBitsJPEG2Tag) || (t instanceof DefineBitsJPEG3Tag) || (t instanceof DefineBitsJPEG4Tag)) { - byte imageData[] = null; - int characterID = 0; - if (t instanceof DefineBitsJPEG2Tag) { - imageData = ((DefineBitsJPEG2Tag) t).imageData; - characterID = ((DefineBitsJPEG2Tag) t).characterID; - } - if (t instanceof DefineBitsJPEG3Tag) { - imageData = ((DefineBitsJPEG3Tag) t).imageData; - characterID = ((DefineBitsJPEG3Tag) t).characterID; - } - if (t instanceof DefineBitsJPEG4Tag) { - imageData = ((DefineBitsJPEG4Tag) t).imageData; - characterID = ((DefineBitsJPEG4Tag) t).characterID; - } - - FileOutputStream fos = null; - try { - fos = new FileOutputStream(outdir + File.separator + characterID + "." + getImageFormat(imageData)); - if (hasErrorHeader(imageData)) { - fos.write(imageData, 4, imageData.length - 4); - } else { - fos.write(imageData); - } - } finally { - if (fos != null) { - try { - fos.close(); - } catch (Exception ex) { - //ignore - } - } - } - } - if (t instanceof DefineBitsLosslessTag) { - DefineBitsLosslessTag dbl = (DefineBitsLosslessTag) t; - ImageIO.write(dbl.getImage(), "PNG", new File(outdir + File.separator + dbl.characterID + ".png")); - } - if (t instanceof DefineBitsLossless2Tag) { - DefineBitsLossless2Tag dbl = (DefineBitsLossless2Tag) t; - - ImageIO.write(dbl.getImage(), "PNG", new File(outdir + File.separator + dbl.characterID + ".png")); - } - if ((jtt != null) && (t instanceof DefineBitsTag)) { - DefineBitsTag dbt = (DefineBitsTag) t; - FileOutputStream fos = null; - try { - fos = new FileOutputStream(outdir + File.separator + dbt.characterID + ".jpg"); - fos.write(dbt.getFullImageData(jtt)); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (Exception ex) { - //ignore - } - } - } + if (t instanceof ImageTag) { + ImageIO.write(((ImageTag) t).getImage(this.tags), ((ImageTag) t).getImageFormat().toUpperCase(), new File(outdir + File.separator + ((ImageTag) t).getCharacterID() + "." + ((ImageTag) t).getImageFormat())); } } } @@ -941,7 +862,7 @@ public class SWF { jtt = (JPEGTablesTag) t; } } - exportImages(outdir, tags, jtt); + exportImages(outdir, tags); } public void exportShapes(String outdir) throws IOException { diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 88766cce5..5286bac64 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -50,6 +50,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -61,6 +62,7 @@ import java.util.Scanner; import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.zip.InflaterInputStream; /** * Class for reading data from SWF file @@ -394,6 +396,18 @@ public class SWFInputStream extends InputStream { return ret; } + public byte[] readBytesZlib(long count) throws IOException { + byte data[] = readBytes(count); + InflaterInputStream dis = new InflaterInputStream(new ByteArrayInputStream(data)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte buf[] = new byte[4096]; + int c = 0; + while ((c = dis.read(buf)) > 0) { + baos.write(buf, 0, c); + } + return baos.toByteArray(); + } + /** * Reads one EncodedU32 (Encoded unsigned 32bit value) value from the stream * diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java index a453fd2f7..13e391f8d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash; +import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.types.*; import com.jpexs.decompiler.flash.types.filters.BEVELFILTER; @@ -36,6 +37,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; +import java.util.zip.DeflaterOutputStream; /** * Class for writing data into SWF file @@ -718,6 +720,19 @@ public class SWFOutputStream extends OutputStream { writeUI8(value.alpha); } + /** + * Writes ARGB value to the stream + * + * @param value ARGB value + * @throws IOException + */ + public void writeARGB(ARGB value) throws IOException { + writeUI8(value.alpha); + writeUI8(value.red); + writeUI8(value.green); + writeUI8(value.blue); + } + /** * Writes RGB value to the stream * @@ -1585,4 +1600,79 @@ public class SWFOutputStream extends OutputStream { writeUI16(value.alignmentCoordinate); writeUI16(value.range); } + + public void writeBytesZlib(byte data[]) throws IOException { + DeflaterOutputStream deflater = new DeflaterOutputStream(this); + deflater.write(data); + deflater.flush(); + } + + /** + * Reads one BITMAPDATA value from the stream + * + * @throws IOException + */ + public void writeBITMAPDATA(BITMAPDATA value, int bitmapFormat, int bitmapWidth, int bitmapHeight) throws IOException { + int dataLen = 0; + int pos = 0; + for (int y = 0; y < bitmapHeight; y++) { + int x = 0; + for (; x < bitmapWidth; x++) { + if (bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) { + dataLen += 2; + writePIX15(value.bitmapPixelDataPix15[pos]); + } + if (bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB) { + dataLen += 4; + writePIX24(value.bitmapPixelDataPix24[pos]); + } + pos++; + } + while ((dataLen % 4) != 0) { + dataLen++; + writeUI8(0); + } + } + } + + /** + * Reads one ALPHABITMAPDATA value from the stream + * + * @throws IOException + */ + public void writeALPHABITMAPDATA(ALPHABITMAPDATA value, int bitmapFormat, int bitmapWidth, int bitmapHeight) throws IOException { + int pos = 0; + for (int y = 0; y < bitmapHeight; y++) { + for (int x = 0; x < bitmapWidth; x++) { + writeARGB(value.bitmapPixelData[pos]); + pos++; + } + } + } + + /** + * Writes PIX24 value to the stream + * + * @param value PIX24 value + * @throws IOException + */ + public void writePIX24(PIX24 value) throws IOException { + writeUI8(0); + writeUI8(value.red); + writeUI8(value.green); + writeUI8(value.blue); + } + + /** + * Writes PIX15 value to the stream + * + * @param value PIX15 value + * @throws IOException + */ + public void writePIX15(PIX15 value) throws IOException { + writeUB(1, 0); + writeUB(5, value.red); + writeUB(5, value.green); + writeUB(5, value.blue); + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 5c5e5450f..4b4ec80d4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -75,6 +75,7 @@ import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.Container; import com.jpexs.decompiler.flash.tags.base.FontTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.tags.text.ParseException; import com.jpexs.decompiler.flash.types.GLYPHENTRY; @@ -111,8 +112,6 @@ import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; @@ -126,18 +125,17 @@ import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; -import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; -import javax.swing.UIManager; import javax.swing.border.BevelBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; +import javax.swing.filechooser.FileFilter; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeModel; @@ -186,6 +184,8 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi private JButton textCancelButton; private JPanel parametersPanel; private JSplitPane previewSplitPane; + private JButton imageReplaceButton; + private JPanel imageButtonsPanel; public void setPercent(int percent) { progressBar.setValue(percent); @@ -500,7 +500,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi JPanel textTopPanel = new JPanel(new BorderLayout()); textValue = new LineMarkedEditorPane(); textTopPanel.add(new JScrollPane(textValue), BorderLayout.CENTER); - textValue.setEditable(false); + textValue.setEditable(false); //textValue.setFont(UIManager.getFont("TextField.font")); /*JPanel textBottomPanel = new JPanel(); @@ -554,10 +554,10 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi displayWithPreview.add(textPanel, CARDTEXTPANEL); //displayWithPreview.setVisible(false); - - - + + + Component leftComponent = null; try { @@ -565,40 +565,55 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } catch (FlashUnsupportedException fue) { } displayPanel = new JPanel(new CardLayout()); - + if (flashPanel != null) { - leftComponent=flashPanel; + leftComponent = flashPanel; } else { JPanel swtPanel = new JPanel(new BorderLayout()); swtPanel.add(new JLabel("
Preview of this object is not available on this platform. (Windows only)
", JLabel.CENTER), BorderLayout.CENTER); swtPanel.setBackground(Color.white); - leftComponent = swtPanel; + leftComponent = swtPanel; } - + textValue.setContentType("text/swf_text"); - - previewSplitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + + previewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); previewSplitPane.setDividerLocation(300); - JPanel pan=new JPanel(new BorderLayout()); - JLabel prevLabel=new JLabel("SWF preview"); + JPanel pan = new JPanel(new BorderLayout()); + JLabel prevLabel = new JLabel("SWF preview"); prevLabel.setHorizontalAlignment(SwingConstants.CENTER); prevLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - - JLabel paramsLabel=new JLabel("Parameters"); + + JLabel paramsLabel = new JLabel("Parameters"); paramsLabel.setHorizontalAlignment(SwingConstants.CENTER); paramsLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - pan.add(prevLabel,BorderLayout.NORTH); - pan.add(leftComponent,BorderLayout.CENTER); + pan.add(prevLabel, BorderLayout.NORTH); + pan.add(leftComponent, BorderLayout.CENTER); previewSplitPane.setLeftComponent(pan); - - parametersPanel=new JPanel(new BorderLayout()); - parametersPanel.add(paramsLabel,BorderLayout.NORTH); - parametersPanel.add(displayWithPreview,BorderLayout.CENTER); + + parametersPanel = new JPanel(new BorderLayout()); + parametersPanel.add(paramsLabel, BorderLayout.NORTH); + parametersPanel.add(displayWithPreview, BorderLayout.CENTER); previewSplitPane.setRightComponent(parametersPanel); parametersPanel.setVisible(false); displayPanel.add(previewSplitPane, CARDFLASHPANEL); imagePanel = new ImagePanel(); - displayPanel.add(imagePanel, CARDIMAGEPANEL); + JPanel imagesCard = new JPanel(new BorderLayout()); + imagesCard.add(imagePanel, BorderLayout.CENTER); + + + + + imageReplaceButton = new JButton("Replace...", View.getIcon("edit16")); + imageReplaceButton.setMargin(new Insets(3, 3, 3, 10)); + imageReplaceButton.setActionCommand("REPLACEIMAGE"); + imageReplaceButton.addActionListener(this); + imageButtonsPanel = new JPanel(new FlowLayout()); + imageButtonsPanel.add(imageReplaceButton); + + imagesCard.add(imageButtonsPanel, BorderLayout.SOUTH); + + displayPanel.add(imagesCard, CARDIMAGEPANEL); displayPanel.add(new JPanel(), CARDEMPTYPANEL); if (actionPanel != null) { displayPanel.add(actionPanel, CARDACTIONSCRIPTPANEL); @@ -1106,6 +1121,53 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi @Override public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("REPLACEIMAGE")) { + Object tagObj = tagTree.getLastSelectedPathComponent(); + if (tagObj == null) { + return; + } + + if (tagObj instanceof TagNode) { + tagObj = ((TagNode) tagObj).tag; + } + if (tagObj instanceof ImageTag) { + ImageTag it = (ImageTag) tagObj; + if (it.importSupported()) { + JFileChooser fc = new JFileChooser(); + fc.setCurrentDirectory(new File((String) Configuration.getConfig("lastOpenDir", "."))); + fc.setFileFilter(new FileFilter() { + @Override + public boolean accept(File f) { + return (f.getName().toLowerCase().endsWith(".jpg")) + || (f.getName().toLowerCase().endsWith(".jpeg")) + || (f.getName().toLowerCase().endsWith(".gif")) + || (f.getName().toLowerCase().endsWith(".png")) + || (f.isDirectory()); + } + + @Override + public String getDescription() { + return "Images (*.jpg,*.gif,*.png)"; + } + }); + JFrame f = new JFrame(); + View.setWindowIcon(f); + int returnVal = fc.showOpenDialog(f); + if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.setConfig("lastOpenDir", fc.getSelectedFile().getParentFile().getAbsolutePath()); + File selfile = fc.getSelectedFile(); + byte data[] = Helper.readFile(selfile.getAbsolutePath()); + try { + it.setImage(data); + } catch (IOException ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "message", ex); + JOptionPane.showMessageDialog(null, "Invalid image.","Error",JOptionPane.ERROR_MESSAGE); + } + reload(true); + } + } + } + } if (e.getActionCommand().equals("REMOVEITEM")) { Object tagObj = tagTree.getLastSelectedPathComponent(); if (tagObj == null) { @@ -1286,7 +1348,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } } } - SWF.exportImages(selFile + File.separator + "images", images, jtt); + swf.exportImages(selFile + File.separator + "images", images); SWF.exportShapes(selFile + File.separator + "shapes", shapes); swf.exportTexts(selFile + File.separator + "texts", texts, isFormatted); swf.exportMovies(selFile + File.separator + "movies", movies); @@ -1632,24 +1694,10 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } else if (tagObj instanceof ASMSource) { showCard(CARDACTIONSCRIPTPANEL); actionPanel.setSource((ASMSource) tagObj); - } else if (tagObj instanceof DefineBitsTag) { + } else if (tagObj instanceof ImageTag) { + imageButtonsPanel.setVisible(((ImageTag) tagObj).importSupported()); showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsTag) tagObj).getFullImageData(jtt)); - } else if (tagObj instanceof DefineBitsJPEG2Tag) { - showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsJPEG2Tag) tagObj).imageData); - } else if (tagObj instanceof DefineBitsJPEG3Tag) { - showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsJPEG3Tag) tagObj).imageData); - } else if (tagObj instanceof DefineBitsJPEG4Tag) { - showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsJPEG4Tag) tagObj).imageData); - } else if (tagObj instanceof DefineBitsLosslessTag) { - showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsLosslessTag) tagObj).getImage()); - } else if (tagObj instanceof DefineBitsLossless2Tag) { - showCard(CARDIMAGEPANEL); - imagePanel.setImage(((DefineBitsLossless2Tag) tagObj).getImage()); + imagePanel.setImage(((ImageTag) tagObj).getImage(swf.tags)); } else if ((tagObj instanceof FrameNode && ((FrameNode) tagObj).isDisplayed()) || (((tagObj instanceof CharacterTag) || (tagObj instanceof FontTag)) && (tagObj instanceof Tag))) { try { @@ -1834,7 +1882,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi if (tagObj instanceof TextTag) { parametersPanel.setVisible(true); - previewSplitPane.setDividerLocation(previewSplitPane.getWidth()/2); + previewSplitPane.setDividerLocation(previewSplitPane.getWidth() / 2); showDetailWithPreview(CARDTEXTPANEL); textValue.setText(((TextTag) tagObj).getFormattedText(swf.tags)); } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java index ccb9614de..17e5f8c25 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG2Tag.java @@ -18,11 +18,14 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.List; +import javax.imageio.ImageIO; -public class DefineBitsJPEG2Tag extends CharacterTag implements AloneTag { +public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag { public int characterID; public byte[] imageData; @@ -32,10 +35,29 @@ public class DefineBitsJPEG2Tag extends CharacterTag implements AloneTag { return characterID; } + @Override + public String getImageFormat() { + return ImageTag.getImageFormat(imageData); + } + + @Override + public BufferedImage getImage(List tags) { + try { + return ImageIO.read(new ByteArrayInputStream(imageData)); + } catch (IOException ex) { + } + return null; + } + public DefineBitsJPEG2Tag(byte[] data, int version, long pos) throws IOException { super(21, "DefineBitsJPEG2", data, pos); SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version); characterID = sis.readUI16(); imageData = sis.readBytes(sis.available()); } + + @Override + public void setImage(byte data[]) { + imageData = data; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java index 5821e6eea..d3f605c7e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java @@ -19,13 +19,17 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import javax.imageio.ImageIO; -public class DefineBitsJPEG3Tag extends CharacterTag implements AloneTag { +public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag { public int characterID; public byte imageData[]; @@ -36,13 +40,41 @@ public class DefineBitsJPEG3Tag extends CharacterTag implements AloneTag { return characterID; } + @Override + public void setImage(byte data[]) { + imageData = data; + if (ImageTag.getImageFormat(data).equals("jpg")) { + BufferedImage image = getImage(new ArrayList()); + bitmapAlphaData = new byte[image.getWidth() * image.getHeight()]; + for (int i = 0; i < bitmapAlphaData.length; i++) { + bitmapAlphaData[i] = (byte) 255; + } + } else { + bitmapAlphaData = new byte[0]; + } + } + + @Override + public String getImageFormat() { + return ImageTag.getImageFormat(imageData); + } + + @Override + public BufferedImage getImage(List tags) { + try { + return ImageIO.read(new ByteArrayInputStream(imageData)); + } catch (IOException ex) { + } + return null; + } + public DefineBitsJPEG3Tag(byte[] data, int version, long pos) throws IOException { super(35, "DefineBitsJPEG3", data, pos); SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version); characterID = sis.readUI16(); long alphaDataOffset = sis.readUI32(); imageData = sis.readBytes(alphaDataOffset); - bitmapAlphaData = sis.readBytes(sis.available()); + bitmapAlphaData = sis.readBytesZlib(sis.available()); } /** @@ -60,7 +92,7 @@ public class DefineBitsJPEG3Tag extends CharacterTag implements AloneTag { sos.writeUI16(characterID); sos.writeUI32(imageData.length); sos.write(imageData); - sos.write(bitmapAlphaData); + sos.writeBytesZlib(bitmapAlphaData); } catch (IOException e) { } return baos.toByteArray(); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java index fcb8e79e4..1da59d68c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java @@ -19,18 +19,22 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import javax.imageio.ImageIO; /** * * * @author JPEXS */ -public class DefineBitsJPEG4Tag extends CharacterTag implements AloneTag { +public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag { public int characterID; public int deblockParam; @@ -42,6 +46,34 @@ public class DefineBitsJPEG4Tag extends CharacterTag implements AloneTag { return characterID; } + @Override + public String getImageFormat() { + return ImageTag.getImageFormat(imageData); + } + + @Override + public void setImage(byte data[]) { + imageData = data; + if (ImageTag.getImageFormat(data).equals("jpg")) { + BufferedImage image = getImage(new ArrayList()); + bitmapAlphaData = new byte[image.getWidth() * image.getHeight()]; + for (int i = 0; i < bitmapAlphaData.length; i++) { + bitmapAlphaData[i] = (byte) 255; + } + } else { + bitmapAlphaData = new byte[0]; + } + } + + @Override + public BufferedImage getImage(List tags) { + try { + return ImageIO.read(new ByteArrayInputStream(imageData)); + } catch (IOException ex) { + } + return null; + } + /** * Gets data bytes * diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java index b81322977..58de530fb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLossless2Tag.java @@ -16,12 +16,15 @@ */ package com.jpexs.decompiler.flash.tags; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +import static com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag.FORMAT_24BIT_RGB; import com.jpexs.decompiler.flash.tags.base.AloneTag; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.types.ALPHABITMAPDATA; import com.jpexs.decompiler.flash.types.ALPHACOLORMAPDATA; +import com.jpexs.decompiler.flash.types.ARGB; import com.jpexs.decompiler.flash.types.RGBA; import java.awt.Color; import java.awt.Graphics; @@ -30,9 +33,11 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.List; import java.util.zip.InflaterInputStream; +import javax.imageio.ImageIO; -public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { +public class DefineBitsLossless2Tag extends ImageTag implements AloneTag { public int characterID; public int bitmapFormat; @@ -41,14 +46,46 @@ public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { public int bitmapColorTableSize; public byte zlibBitmapData[]; //TODO: Parse ALPHACOLORMAPDATA,ALPHABITMAPDATA public static final int FORMAT_8BIT_COLORMAPPED = 3; - public static final int FORMAT_15BIT_RGB = 4; - public static final int FORMAT_24BIT_RGB = 5; + public static final int FORMAT_32BIT_ARGB = 5; @Override public int getCharacterID() { return characterID; } + @Override + public void setImage(byte data[]) throws IOException { + BufferedImage image = ImageIO.read(new ByteArrayInputStream(data)); + ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA(); + bitmapFormat = FORMAT_24BIT_RGB; + bitmapWidth = image.getWidth(); + bitmapHeight = image.getHeight(); + bitmapData.bitmapPixelData = new ARGB[bitmapWidth * bitmapHeight]; + int pos = 0; + for (int y = 0; y < bitmapHeight; y++) { + for (int x = 0; x < bitmapWidth; x++) { + int argb = image.getRGB(x, y); + int a = (argb >> 24) & 0xff; + int r = (argb >> 16) & 0xff; + int g = (argb >> 8) & 0xff; + int b = (argb >> 0) & 0xff; + bitmapData.bitmapPixelData[pos] = new ARGB(); + bitmapData.bitmapPixelData[pos].alpha = a; + bitmapData.bitmapPixelData[pos].red = r; + bitmapData.bitmapPixelData[pos].green = g; + bitmapData.bitmapPixelData[pos].blue = b; + pos++; + } + } + ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream(); + SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, SWF.DEFAULT_VERSION); + sos.writeALPHABITMAPDATA(bitmapData, bitmapFormat, bitmapWidth, bitmapHeight); + ByteArrayOutputStream zlibOS = new ByteArrayOutputStream(); + SWFOutputStream sos2 = new SWFOutputStream(zlibOS, SWF.DEFAULT_VERSION); + sos2.writeBytesZlib(bitmapDataOS.toByteArray()); + zlibBitmapData = zlibOS.toByteArray(); + } + public DefineBitsLossless2Tag(byte[] data, int version, long pos) throws IOException { super(36, "DefineBitsLossless2", data, pos); SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version); @@ -85,7 +122,7 @@ public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { colorMapData = sis.readALPHACOLORMAPDATA(bitmapColorTableSize, bitmapWidth, bitmapHeight); } - if ((bitmapFormat == FORMAT_15BIT_RGB) || (bitmapFormat == FORMAT_24BIT_RGB)) { + if (bitmapFormat == FORMAT_32BIT_ARGB) { bitmapData = sis.readALPHABITMAPDATA(bitmapFormat, bitmapWidth, bitmapHeight); } } catch (IOException ex) { @@ -118,7 +155,13 @@ public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { return baos.toByteArray(); } - public BufferedImage getImage() { + @Override + public String getImageFormat() { + return "png"; + } + + @Override + public BufferedImage getImage(List tags) { BufferedImage bi = new BufferedImage(bitmapWidth, bitmapHeight, BufferedImage.TYPE_INT_ARGB); Graphics g = bi.getGraphics(); ALPHACOLORMAPDATA colorMapData = null; @@ -126,7 +169,7 @@ public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { if (bitmapFormat == DefineBitsLossless2Tag.FORMAT_8BIT_COLORMAPPED) { colorMapData = getColorMapData(); } - if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_15BIT_RGB) || (bitmapFormat == DefineBitsLossless2Tag.FORMAT_24BIT_RGB)) { + if (bitmapFormat == DefineBitsLossless2Tag.FORMAT_32BIT_ARGB) { bitmapData = getBitmapData(); } int pos32aligned = 0; @@ -137,7 +180,7 @@ public class DefineBitsLossless2Tag extends CharacterTag implements AloneTag { RGBA color = colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff]; g.setColor(new Color(color.red, color.green, color.blue, color.alpha)); } - if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_15BIT_RGB) || (bitmapFormat == DefineBitsLossless2Tag.FORMAT_24BIT_RGB)) { + if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_32BIT_ARGB)) { g.setColor(new Color(bitmapData.bitmapPixelData[pos].red, bitmapData.bitmapPixelData[pos].green, bitmapData.bitmapPixelData[pos].blue, bitmapData.bitmapPixelData[pos].alpha)); } g.fillRect(x, y, 1, 1); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java index 959a26529..bd8e9fd48 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsLosslessTag.java @@ -16,12 +16,14 @@ */ package com.jpexs.decompiler.flash.tags; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.types.BITMAPDATA; import com.jpexs.decompiler.flash.types.COLORMAPDATA; +import com.jpexs.decompiler.flash.types.PIX24; import com.jpexs.decompiler.flash.types.RGB; import java.awt.Color; import java.awt.Graphics; @@ -30,9 +32,11 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.List; import java.util.zip.InflaterInputStream; +import javax.imageio.ImageIO; -public class DefineBitsLosslessTag extends CharacterTag implements AloneTag { +public class DefineBitsLosslessTag extends ImageTag implements AloneTag { public int characterID; public int bitmapFormat; @@ -47,7 +51,39 @@ public class DefineBitsLosslessTag extends CharacterTag implements AloneTag { private BITMAPDATA bitmapData; private boolean decompressed = false; - public BufferedImage getImage() { + @Override + public void setImage(byte data[]) throws IOException { + BufferedImage image = ImageIO.read(new ByteArrayInputStream(data)); + bitmapFormat = FORMAT_24BIT_RGB; + bitmapWidth = image.getWidth(); + bitmapHeight = image.getHeight(); + bitmapData.bitmapPixelDataPix24 = new PIX24[bitmapWidth * bitmapHeight]; + int pos = 0; + for (int y = 0; y < bitmapHeight; y++) { + for (int x = 0; x < bitmapWidth; x++) { + int argb = image.getRGB(x, y); + //int a = (argb >> 24) & 0xff; + int r = (argb >> 16) & 0xff; + int g = (argb >> 8) & 0xff; + int b = (argb >> 0) & 0xff; + bitmapData.bitmapPixelDataPix24[pos] = new PIX24(); + bitmapData.bitmapPixelDataPix24[pos].red = r; + bitmapData.bitmapPixelDataPix24[pos].green = g; + bitmapData.bitmapPixelDataPix24[pos].blue = b; + pos++; + } + } + ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream(); + SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, SWF.DEFAULT_VERSION); + sos.writeBITMAPDATA(bitmapData, bitmapFormat, bitmapWidth, bitmapHeight); + ByteArrayOutputStream zlibOS = new ByteArrayOutputStream(); + SWFOutputStream sos2 = new SWFOutputStream(zlibOS, SWF.DEFAULT_VERSION); + sos2.writeBytesZlib(bitmapDataOS.toByteArray()); + zlibBitmapData = zlibOS.toByteArray(); + } + + @Override + public BufferedImage getImage(List tags) { BufferedImage bi = new BufferedImage(bitmapWidth, bitmapHeight, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); COLORMAPDATA colorMapData = null; @@ -153,4 +189,9 @@ public class DefineBitsLosslessTag extends CharacterTag implements AloneTag { } return baos.toByteArray(); } + + @Override + public String getImageFormat() { + return "png"; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java index dd3bfe495..d3cc50186 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsTag.java @@ -19,16 +19,30 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.tags.base.CharacterTag; +import com.jpexs.decompiler.flash.tags.base.ImageTag; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.List; +import javax.imageio.ImageIO; -public class DefineBitsTag extends CharacterTag { +public class DefineBitsTag extends ImageTag { public int characterID; public byte jpegData[]; + private JPEGTablesTag jtt = null; + + @Override + public void setImage(byte data[]) { + throw new UnsupportedOperationException("Set image is not supported for DefineBits"); + } + + @Override + public boolean importSupported() { + return false; + } public DefineBitsTag(byte[] data, int version, long pos) throws IOException { super(6, "DefineBits", data, pos); @@ -37,7 +51,20 @@ public class DefineBitsTag extends CharacterTag { jpegData = sis.readBytes(sis.available()); } - public byte[] getFullImageData(JPEGTablesTag jtt) { + private void getJPEGTables(List tags) { + if (jtt == null) { + for (Tag t : tags) { + if (t instanceof JPEGTablesTag) { + jtt = (JPEGTablesTag) t; + break; + } + } + } + } + + @Override + public BufferedImage getImage(List tags) { + getJPEGTables(tags); if ((jtt != null)) { ByteArrayOutputStream baos = null; @@ -60,7 +87,14 @@ public class DefineBitsTag extends CharacterTag { } } } - return baos.toByteArray(); + if (baos == null) { + return null; + } + try { + return ImageIO.read(new ByteArrayInputStream(baos.toByteArray())); + } catch (IOException ex) { + return null; + } } return null; } @@ -88,4 +122,9 @@ public class DefineBitsTag extends CharacterTag { public int getCharacterID() { return characterID; } + + @Override + public String getImageFormat() { + return "jpg"; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java new file mode 100644 index 000000000..a322df425 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2013 JPEXS + * + * 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, see . + */ +package com.jpexs.decompiler.flash.tags.base; + +import static com.jpexs.decompiler.flash.SWF.hasErrorHeader; +import com.jpexs.decompiler.flash.tags.Tag; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class ImageTag extends CharacterTag { + + public ImageTag(int id, String name, byte[] data, long pos) { + super(id, name, data, pos); + } + + public abstract BufferedImage getImage(List tags); + + public abstract void setImage(byte data[]) throws IOException; + + public abstract String getImageFormat(); + + public boolean importSupported() { + return true; + } + + public static String getImageFormat(byte data[]) { + if (hasErrorHeader(data)) { + return "jpg"; + } + if (data.length > 2 && ((data[0] & 0xff) == 0xff) && ((data[1] & 0xff) == 0xd8)) { + return "jpg"; + } + if (data.length > 6 && ((data[0] & 0xff) == 0x47) && ((data[1] & 0xff) == 0x49) && ((data[2] & 0xff) == 0x46) && ((data[3] & 0xff) == 0x38) && ((data[4] & 0xff) == 0x39) && ((data[5] & 0xff) == 0x61)) { + return "gif"; + } + + if (data.length > 8 && ((data[0] & 0xff) == 0x89) && ((data[1] & 0xff) == 0x50) && ((data[2] & 0xff) == 0x4e) && ((data[3] & 0xff) == 0x47) && ((data[4] & 0xff) == 0x0d) && ((data[5] & 0xff) == 0x0a) && ((data[6] & 0xff) == 0x1a) && ((data[7] & 0xff) == 0x0a)) { + return "png"; + } + + return "unk"; + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java b/trunk/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java index fe1b3158e..6827a7051 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java @@ -18,244 +18,245 @@ */ package com.jpexs.decompiler.flash.tags.text; - - /** - * This class is a scanner generated by - * JFlex 1.4.3 - * on 30.4.13 19:25 from the specification file + * This class is a scanner generated by + * JFlex 1.4.3 on 30.4.13 19:25 from the + * specification file * D:/Dokumenty/Programovani/JavaSE/FFDec/trunk/src/com/jpexs/decompiler/flash/tags/text/text.flex */ public final class TextLexer { - /** This character denotes the end of file */ - public static final int YYEOF = -1; + /** + * This character denotes the end of file + */ + public static final int YYEOF = -1; + /** + * initial size of the lookahead buffer + */ + private static final int ZZ_BUFFERSIZE = 16384; + /** + * lexical states + */ + public static final int YYINITIAL = 0; + public static final int VALUE = 4; + public static final int PARAMETER = 2; + /** + * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l + * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l at the + * beginning of a line l is of the form l = 2*k, k a non negative integer + */ + private static final int ZZ_LEXSTATE[] = { + 0, 0, 1, 1, 2, 2 + }; + /** + * Translates characters to character classes + */ + private static final String ZZ_CMAP_PACKED = + "\12\0\1\15\2\0\1\3\22\0\1\3\1\0\1\13\4\0\1\14" + + "\10\0\12\1\41\0\1\4\1\5\1\2\1\0\1\1\1\0\1\1" + + "\1\6\3\1\1\11\7\1\1\10\3\1\1\12\1\1\1\7\6\1" + + "\uff85\0"; + /** + * Translates characters to character classes + */ + private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); + /** + * Translates DFA states to action switch labels. + */ + private static final int[] ZZ_ACTION = zzUnpackAction(); + private static final String ZZ_ACTION_PACKED_0 = + "\3\0\1\1\1\2\1\1\1\3\1\4\1\5\1\3" + + "\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15" + + "\1\16\1\17\1\20\1\21"; - /** initial size of the lookahead buffer */ - private static final int ZZ_BUFFERSIZE = 16384; - - /** lexical states */ - public static final int YYINITIAL = 0; - public static final int VALUE = 4; - public static final int PARAMETER = 2; - - /** - * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l - * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l - * at the beginning of a line - * l is of the form l = 2*k, k a non negative integer - */ - private static final int ZZ_LEXSTATE[] = { - 0, 0, 1, 1, 2, 2 - }; - - /** - * Translates characters to character classes - */ - private static final String ZZ_CMAP_PACKED = - "\12\0\1\15\2\0\1\3\22\0\1\3\1\0\1\13\4\0\1\14"+ - "\10\0\12\1\41\0\1\4\1\5\1\2\1\0\1\1\1\0\1\1"+ - "\1\6\3\1\1\11\7\1\1\10\3\1\1\12\1\1\1\7\6\1"+ - "\uff85\0"; - - /** - * Translates characters to character classes - */ - private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); - - /** - * Translates DFA states to action switch labels. - */ - private static final int [] ZZ_ACTION = zzUnpackAction(); - - private static final String ZZ_ACTION_PACKED_0 = - "\3\0\1\1\1\2\1\1\1\3\1\4\1\5\1\3"+ - "\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15"+ - "\1\16\1\17\1\20\1\21"; - - private static int [] zzUnpackAction() { - int [] result = new int[22]; - int offset = 0; - offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAction(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); + private static int[] zzUnpackAction() { + int[] result = new int[22]; + int offset = 0; + offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); + return result; } - return j; - } - - /** - * Translates a state to a row index in the transition table - */ - private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); - - private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\16\0\34\0\52\0\52\0\70\0\52\0\106"+ - "\0\52\0\124\0\142\0\52\0\52\0\52\0\52\0\52"+ - "\0\52\0\52\0\52\0\52\0\52\0\52"; - - private static int [] zzUnpackRowMap() { - int [] result = new int[22]; - int offset = 0; - offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackRowMap(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int high = packed.charAt(i++) << 16; - result[j++] = high | packed.charAt(i++); + private static int zzUnpackAction(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do { + result[j++] = value; + } while (--count > 0); + } + return j; } - return j; - } + /** + * Translates a state to a row index in the transition table + */ + private static final int[] ZZ_ROWMAP = zzUnpackRowMap(); + private static final String ZZ_ROWMAP_PACKED_0 = + "\0\0\0\16\0\34\0\52\0\52\0\70\0\52\0\106" + + "\0\52\0\124\0\142\0\52\0\52\0\52\0\52\0\52" + + "\0\52\0\52\0\52\0\52\0\52\0\52"; - /** - * The transition table of the DFA - */ - private static final int [] ZZ_TRANS = zzUnpackTrans(); - - private static final String ZZ_TRANS_PACKED_0 = - "\4\4\1\5\1\6\7\4\2\7\1\10\1\11\1\12"+ - "\2\7\5\10\2\7\1\12\2\13\1\11\1\12\11\13"+ - "\1\12\16\0\2\14\1\15\1\14\1\16\1\17\1\20"+ - "\1\21\1\22\1\23\1\24\1\25\1\26\2\0\1\10"+ - "\4\0\5\10\6\0\1\12\11\0\1\12\2\13\2\0"+ - "\11\13\1\0"; - - private static int [] zzUnpackTrans() { - int [] result = new int[112]; - int offset = 0; - offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackTrans(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - value--; - do result[j++] = value; while (--count > 0); + private static int[] zzUnpackRowMap() { + int[] result = new int[22]; + int offset = 0; + offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); + return result; } - return j; - } - - /* error codes */ - private static final int ZZ_UNKNOWN_ERROR = 0; - private static final int ZZ_NO_MATCH = 1; - private static final int ZZ_PUSHBACK_2BIG = 2; - - /* error messages for the codes above */ - private static final String ZZ_ERROR_MSG[] = { - "Unkown internal scanner error", - "Error: could not match input", - "Error: pushback value was too large" - }; - - /** - * ZZ_ATTRIBUTE[aState] contains the attributes of state aState - */ - private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); - - private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\3\0\2\11\1\1\1\11\1\1\1\11\2\1\13\11"; - - private static int [] zzUnpackAttribute() { - int [] result = new int[22]; - int offset = 0; - offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); - return result; - } - - private static int zzUnpackAttribute(String packed, int offset, int [] result) { - int i = 0; /* index in packed string */ - int j = offset; /* index in unpacked array */ - int l = packed.length(); - while (i < l) { - int count = packed.charAt(i++); - int value = packed.charAt(i++); - do result[j++] = value; while (--count > 0); + private static int zzUnpackRowMap(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int high = packed.charAt(i++) << 16; + result[j++] = high | packed.charAt(i++); + } + return j; } - return j; - } + /** + * The transition table of the DFA + */ + private static final int[] ZZ_TRANS = zzUnpackTrans(); + private static final String ZZ_TRANS_PACKED_0 = + "\4\4\1\5\1\6\7\4\2\7\1\10\1\11\1\12" + + "\2\7\5\10\2\7\1\12\2\13\1\11\1\12\11\13" + + "\1\12\16\0\2\14\1\15\1\14\1\16\1\17\1\20" + + "\1\21\1\22\1\23\1\24\1\25\1\26\2\0\1\10" + + "\4\0\5\10\6\0\1\12\11\0\1\12\2\13\2\0" + + "\11\13\1\0"; - /** the input device */ - private java.io.Reader zzReader; + private static int[] zzUnpackTrans() { + int[] result = new int[112]; + int offset = 0; + offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); + return result; + } - /** the current state of the DFA */ - private int zzState; + private static int zzUnpackTrans(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + value--; + do { + result[j++] = value; + } while (--count > 0); + } + return j; + } + /* error codes */ + private static final int ZZ_UNKNOWN_ERROR = 0; + private static final int ZZ_NO_MATCH = 1; + private static final int ZZ_PUSHBACK_2BIG = 2; - /** the current lexical state */ - private int zzLexicalState = YYINITIAL; + /* error messages for the codes above */ + private static final String ZZ_ERROR_MSG[] = { + "Unkown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" + }; + /** + * ZZ_ATTRIBUTE[aState] contains the attributes of state + * aState + */ + private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); + private static final String ZZ_ATTRIBUTE_PACKED_0 = + "\3\0\2\11\1\1\1\11\1\1\1\11\2\1\13\11"; - /** this buffer contains the current text to be matched and is - the source of the yytext() string */ - private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; + private static int[] zzUnpackAttribute() { + int[] result = new int[22]; + int offset = 0; + offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); + return result; + } - /** the textposition at the last accepting state */ - private int zzMarkedPos; - - /** the current text position in the buffer */ - private int zzCurrentPos; - - /** startRead marks the beginning of the yytext() string in the buffer */ - private int zzStartRead; - - /** endRead marks the last character in the buffer, that has been read - from input */ - private int zzEndRead; - - /** number of newlines encountered up to the start of the matched text */ - private int yyline; - - /** the number of characters up to the start of the matched text */ - private int yychar; - - /** - * the number of characters from the last newline up to the start of the - * matched text - */ - private int yycolumn; - - /** - * zzAtBOL == true <=> the scanner is currently at the beginning of a line - */ - private boolean zzAtBOL = true; - - /** zzAtEOF == true <=> the scanner is at the EOF */ - private boolean zzAtEOF; - - /** denotes if the user-EOF-code has already been executed */ - private boolean zzEOFDone; - - /* user code: */ - - StringBuffer string = null; - boolean finish=false; - String parameterName=null; + private static int zzUnpackAttribute(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do { + result[j++] = value; + } while (--count > 0); + } + return j; + } + /** + * the input device + */ + private java.io.Reader zzReader; + /** + * the current state of the DFA + */ + private int zzState; + /** + * the current lexical state + */ + private int zzLexicalState = YYINITIAL; + /** + * this buffer contains the current text to be matched and is the source of + * the yytext() string + */ + private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; + /** + * the textposition at the last accepting state + */ + private int zzMarkedPos; + /** + * the current text position in the buffer + */ + private int zzCurrentPos; + /** + * startRead marks the beginning of the yytext() string in the buffer + */ + private int zzStartRead; + /** + * endRead marks the last character in the buffer, that has been read from + * input + */ + private int zzEndRead; + /** + * number of newlines encountered up to the start of the matched text + */ + private int yyline; + /** + * the number of characters up to the start of the matched text + */ + private int yychar; + /** + * the number of characters from the last newline up to the start of the + * matched text + */ + private int yycolumn; + /** + * zzAtBOL == true <=> the scanner is currently at the beginning of a line + */ + private boolean zzAtBOL = true; + /** + * zzAtEOF == true <=> the scanner is at the EOF + */ + private boolean zzAtEOF; + /** + * denotes if the user-EOF-code has already been executed + */ + private boolean zzEOFDone; + /* user code: */ + StringBuffer string = null; + boolean finish = false; + String parameterName = null; /** * Create an empty lexer, yyrset will be called later to reset and assign * the reader */ public TextLexer() { - } public int yychar() { @@ -263,456 +264,501 @@ public final class TextLexer { } public int yyline() { - return yyline+1; + return yyline + 1; } - - - /** - * Creates a new scanner - * There is also a java.io.InputStream version of this constructor. - * - * @param in the java.io.Reader to read input from. - */ - public TextLexer(java.io.Reader in) { - this.zzReader = in; - } - - /** - * Creates a new scanner. - * There is also java.io.Reader version of this constructor. - * - * @param in the java.io.Inputstream to read input from. - */ - public TextLexer(java.io.InputStream in) { - this(new java.io.InputStreamReader(in)); - } - - /** - * Unpacks the compressed character translation table. - * - * @param packed the packed character translation table - * @return the unpacked character translation table - */ - private static char [] zzUnpackCMap(String packed) { - char [] map = new char[0x10000]; - int i = 0; /* index in packed string */ - int j = 0; /* index in unpacked array */ - while (i < 62) { - int count = packed.charAt(i++); - char value = packed.charAt(i++); - do map[j++] = value; while (--count > 0); - } - return map; - } - - - /** - * Refills the input buffer. - * - * @return false, iff there was new input. - * - * @exception java.io.IOException if any I/O-Error occurs - */ - private boolean zzRefill() throws java.io.IOException { - - /* first: make room (if you can) */ - if (zzStartRead > 0) { - System.arraycopy(zzBuffer, zzStartRead, - zzBuffer, 0, - zzEndRead-zzStartRead); - - /* translate stored positions */ - zzEndRead-= zzStartRead; - zzCurrentPos-= zzStartRead; - zzMarkedPos-= zzStartRead; - zzStartRead = 0; + /** + * Creates a new scanner There is also a java.io.InputStream version of this + * constructor. + * + * @param in the java.io.Reader to read input from. + */ + public TextLexer(java.io.Reader in) { + this.zzReader = in; } - /* is the buffer big enough? */ - if (zzCurrentPos >= zzBuffer.length) { - /* if not: blow it up */ - char newBuffer[] = new char[zzCurrentPos*2]; - System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); - zzBuffer = newBuffer; + /** + * Creates a new scanner. There is also java.io.Reader version of this + * constructor. + * + * @param in the java.io.Inputstream to read input from. + */ + public TextLexer(java.io.InputStream in) { + this(new java.io.InputStreamReader(in)); } - /* finally: fill the buffer with new input */ - int numRead = zzReader.read(zzBuffer, zzEndRead, - zzBuffer.length-zzEndRead); - - if (numRead > 0) { - zzEndRead+= numRead; - return false; + /** + * Unpacks the compressed character translation table. + * + * @param packed the packed character translation table + * @return the unpacked character translation table + */ + private static char[] zzUnpackCMap(String packed) { + char[] map = new char[0x10000]; + int i = 0; /* index in packed string */ + int j = 0; /* index in unpacked array */ + while (i < 62) { + int count = packed.charAt(i++); + char value = packed.charAt(i++); + do { + map[j++] = value; + } while (--count > 0); + } + return map; } - // unlikely but not impossible: read 0 characters, but not at end of stream - if (numRead == 0) { - int c = zzReader.read(); - if (c == -1) { + + /** + * Refills the input buffer. + * + * @return false, iff there was new input. + * + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + + /* first: make room (if you can) */ + if (zzStartRead > 0) { + System.arraycopy(zzBuffer, zzStartRead, + zzBuffer, 0, + zzEndRead - zzStartRead); + + /* translate stored positions */ + zzEndRead -= zzStartRead; + zzCurrentPos -= zzStartRead; + zzMarkedPos -= zzStartRead; + zzStartRead = 0; + } + + /* is the buffer big enough? */ + if (zzCurrentPos >= zzBuffer.length) { + /* if not: blow it up */ + char newBuffer[] = new char[zzCurrentPos * 2]; + System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); + zzBuffer = newBuffer; + } + + /* finally: fill the buffer with new input */ + int numRead = zzReader.read(zzBuffer, zzEndRead, + zzBuffer.length - zzEndRead); + + if (numRead > 0) { + zzEndRead += numRead; + return false; + } + // unlikely but not impossible: read 0 characters, but not at end of stream + if (numRead == 0) { + int c = zzReader.read(); + if (c == -1) { + return true; + } else { + zzBuffer[zzEndRead++] = (char) c; + return false; + } + } + + // numRead < 0 return true; - } else { - zzBuffer[zzEndRead++] = (char) c; - return false; - } } - // numRead < 0 - return true; - } + /** + * Closes the input stream. + */ + public final void yyclose() throws java.io.IOException { + zzAtEOF = true; /* indicate end of file */ + zzEndRead = zzStartRead; /* invalidate buffer */ - - /** - * Closes the input stream. - */ - public final void yyclose() throws java.io.IOException { - zzAtEOF = true; /* indicate end of file */ - zzEndRead = zzStartRead; /* invalidate buffer */ - - if (zzReader != null) - zzReader.close(); - } - - - /** - * Resets the scanner to read from a new input stream. - * Does not close the old reader. - * - * All internal variables are reset, the old input stream - * cannot be reused (internal buffer is discarded and lost). - * Lexical state is set to ZZ_INITIAL. - * - * @param reader the new input stream - */ - public final void yyreset(java.io.Reader reader) { - zzReader = reader; - zzAtBOL = true; - zzAtEOF = false; - zzEOFDone = false; - zzEndRead = zzStartRead = 0; - zzCurrentPos = zzMarkedPos = 0; - yyline = yychar = yycolumn = 0; - zzLexicalState = YYINITIAL; - } - - - /** - * Returns the current lexical state. - */ - public final int yystate() { - return zzLexicalState; - } - - - /** - * Enters a new lexical state - * - * @param newState the new lexical state - */ - public final void yybegin(int newState) { - zzLexicalState = newState; - } - - - /** - * Returns the text matched by the current regular expression. - */ - public final String yytext() { - return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); - } - - - /** - * Returns the character at position pos from the - * matched text. - * - * It is equivalent to yytext().charAt(pos), but faster - * - * @param pos the position of the character to fetch. - * A value from 0 to yylength()-1. - * - * @return the character at position pos - */ - public final char yycharat(int pos) { - return zzBuffer[zzStartRead+pos]; - } - - - /** - * Returns the length of the matched text region. - */ - public final int yylength() { - return zzMarkedPos-zzStartRead; - } - - - /** - * Reports an error that occured while scanning. - * - * In a wellformed scanner (no or only correct usage of - * yypushback(int) and a match-all fallback rule) this method - * will only be called with things that "Can't Possibly Happen". - * If this method is called, something is seriously wrong - * (e.g. a JFlex bug producing a faulty scanner etc.). - * - * Usual syntax/scanner level error handling should be done - * in error fallback rules. - * - * @param errorCode the code of the errormessage to display - */ - private void zzScanError(int errorCode) { - String message; - try { - message = ZZ_ERROR_MSG[errorCode]; - } - catch (ArrayIndexOutOfBoundsException e) { - message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; - } - - throw new Error(message); - } - - - /** - * Pushes the specified amount of characters back into the input stream. - * - * They will be read again by then next call of the scanning method - * - * @param number the number of characters to be read again. - * This number must not be greater than yylength()! - */ - public void yypushback(int number) { - if ( number > yylength() ) - zzScanError(ZZ_PUSHBACK_2BIG); - - zzMarkedPos -= number; - } - - - /** - * Resumes scanning until the next regular expression is matched, - * the end of input is encountered or an I/O-Error occurs. - * - * @return the next token - * @exception java.io.IOException if any I/O-Error occurs - */ - public ParsedSymbol yylex() throws java.io.IOException, ParseException { - int zzInput; - int zzAction; - - // cached fields: - int zzCurrentPosL; - int zzMarkedPosL; - int zzEndReadL = zzEndRead; - char [] zzBufferL = zzBuffer; - char [] zzCMapL = ZZ_CMAP; - - int [] zzTransL = ZZ_TRANS; - int [] zzRowMapL = ZZ_ROWMAP; - int [] zzAttrL = ZZ_ATTRIBUTE; - - while (true) { - zzMarkedPosL = zzMarkedPos; - - yychar+= zzMarkedPosL-zzStartRead; - - boolean zzR = false; - for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; - zzCurrentPosL++) { - switch (zzBufferL[zzCurrentPosL]) { - case '\u000B': - case '\u000C': - case '\u0085': - case '\u2028': - case '\u2029': - yyline++; - yycolumn = 0; - zzR = false; - break; - case '\r': - yyline++; - yycolumn = 0; - zzR = true; - break; - case '\n': - if (zzR) - zzR = false; - else { - yyline++; - yycolumn = 0; - } - break; - default: - zzR = false; - yycolumn++; + if (zzReader != null) { + zzReader.close(); } - } + } - if (zzR) { - // peek one character ahead if it is \n (if we have counted one line too much) - boolean zzPeek; - if (zzMarkedPosL < zzEndReadL) - zzPeek = zzBufferL[zzMarkedPosL] == '\n'; - else if (zzAtEOF) - zzPeek = false; - else { - boolean eof = zzRefill(); - zzEndReadL = zzEndRead; - zzMarkedPosL = zzMarkedPos; - zzBufferL = zzBuffer; - if (eof) - zzPeek = false; - else - zzPeek = zzBufferL[zzMarkedPosL] == '\n'; + /** + * Resets the scanner to read from a new input stream. Does not close the + * old reader. + * + * All internal variables are reset, the old input stream + * cannot be reused (internal buffer is discarded and lost). Lexical + * state is set to ZZ_INITIAL. + * + * @param reader the new input stream + */ + public final void yyreset(java.io.Reader reader) { + zzReader = reader; + zzAtBOL = true; + zzAtEOF = false; + zzEOFDone = false; + zzEndRead = zzStartRead = 0; + zzCurrentPos = zzMarkedPos = 0; + yyline = yychar = yycolumn = 0; + zzLexicalState = YYINITIAL; + } + + /** + * Returns the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + /** + * Enters a new lexical state + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + /** + * Returns the text matched by the current regular expression. + */ + public final String yytext() { + return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead); + } + + /** + * Returns the character at position pos from the matched text. + * + * It is equivalent to yytext().charAt(pos), but faster + * + * @param pos the position of the character to fetch. A value from 0 to + * yylength()-1. + * + * @return the character at position pos + */ + public final char yycharat(int pos) { + return zzBuffer[zzStartRead + pos]; + } + + /** + * Returns the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos - zzStartRead; + } + + /** + * Reports an error that occured while scanning. + * + * In a wellformed scanner (no or only correct usage of yypushback(int) and + * a match-all fallback rule) this method will only be called with things + * that "Can't Possibly Happen". If this method is called, something is + * seriously wrong (e.g. a JFlex bug producing a faulty scanner etc.). + * + * Usual syntax/scanner level error handling should be done in error + * fallback rules. + * + * @param errorCode the code of the errormessage to display + */ + private void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } - if (zzPeek) yyline--; - } - zzAction = -1; - zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; - - zzState = ZZ_LEXSTATE[zzLexicalState]; + throw new Error(message); + } + /** + * Pushes the specified amount of characters back into the input stream. + * + * They will be read again by then next call of the scanning method + * + * @param number the number of characters to be read again. This number must + * not be greater than yylength()! + */ + public void yypushback(int number) { + if (number > yylength()) { + zzScanError(ZZ_PUSHBACK_2BIG); + } + + zzMarkedPos -= number; + } + + /** + * Resumes scanning until the next regular expression is matched, the end of + * input is encountered or an I/O-Error occurs. + * + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs + */ + public ParsedSymbol yylex() throws java.io.IOException, ParseException { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + char[] zzBufferL = zzBuffer; + char[] zzCMapL = ZZ_CMAP; + + int[] zzTransL = ZZ_TRANS; + int[] zzRowMapL = ZZ_ROWMAP; + int[] zzAttrL = ZZ_ATTRIBUTE; - zzForAction: { while (true) { - - if (zzCurrentPosL < zzEndReadL) - zzInput = zzBufferL[zzCurrentPosL++]; - else if (zzAtEOF) { - zzInput = YYEOF; - break zzForAction; - } - else { - // store back cached positions - zzCurrentPos = zzCurrentPosL; - zzMarkedPos = zzMarkedPosL; - boolean eof = zzRefill(); - // get translated positions and possibly new buffer - zzCurrentPosL = zzCurrentPos; - zzMarkedPosL = zzMarkedPos; - zzBufferL = zzBuffer; - zzEndReadL = zzEndRead; - if (eof) { - zzInput = YYEOF; - break zzForAction; - } - else { - zzInput = zzBufferL[zzCurrentPosL++]; - } - } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; - if (zzNext == -1) break zzForAction; - zzState = zzNext; + zzMarkedPosL = zzMarkedPos; - int zzAttributes = zzAttrL[zzState]; - if ( (zzAttributes & 1) == 1 ) { - zzAction = zzState; - zzMarkedPosL = zzCurrentPosL; - if ( (zzAttributes & 8) == 8 ) break zzForAction; - } + yychar += zzMarkedPosL - zzStartRead; + boolean zzR = false; + for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; + zzCurrentPosL++) { + switch (zzBufferL[zzCurrentPosL]) { + case '\u000B': + case '\u000C': + case '\u0085': + case '\u2028': + case '\u2029': + yyline++; + yycolumn = 0; + zzR = false; + break; + case '\r': + yyline++; + yycolumn = 0; + zzR = true; + break; + case '\n': + if (zzR) { + zzR = false; + } else { + yyline++; + yycolumn = 0; + } + break; + default: + zzR = false; + yycolumn++; + } + } + + if (zzR) { + // peek one character ahead if it is \n (if we have counted one line too much) + boolean zzPeek; + if (zzMarkedPosL < zzEndReadL) { + zzPeek = zzBufferL[zzMarkedPosL] == '\n'; + } else if (zzAtEOF) { + zzPeek = false; + } else { + boolean eof = zzRefill(); + zzEndReadL = zzEndRead; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + if (eof) { + zzPeek = false; + } else { + zzPeek = zzBufferL[zzMarkedPosL] == '\n'; + } + } + if (zzPeek) { + yyline--; + } + } + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + + zzForAction: + { + while (true) { + + if (zzCurrentPosL < zzEndReadL) { + zzInput = zzBufferL[zzCurrentPosL++]; + } else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } else { + zzInput = zzBufferL[zzCurrentPosL++]; + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + if (zzNext == -1) { + break zzForAction; + } + zzState = zzNext; + + int zzAttributes = zzAttrL[zzState]; + if ((zzAttributes & 1) == 1) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ((zzAttributes & 8) == 8) { + break zzForAction; + } + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 1: { + if (string == null) { + string = new StringBuffer(); + } + string.append(yytext()); + } + case 18: + break; + case 7: { + throw new ParseException("Illegal escape sequence \"" + yytext() + "\"", yyline + 1); + } + case 19: + break; + case 13: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\n'); + } + case 20: + break; + case 2: { + yybegin(PARAMETER); + if (string != null) { + String ret = string.toString(); + string = null; + return new ParsedSymbol(SymbolType.TEXT, ret.toString()); + } + } + case 21: + break; + case 11: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\b'); + } + case 22: + break; + case 17: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\''); + } + case 23: + break; + case 4: { + parameterName = yytext(); + yybegin(VALUE); + } + case 24: + break; + case 6: { + yybegin(PARAMETER); + return new ParsedSymbol(SymbolType.PARAMETER, new Object[]{parameterName, yytext()}); + } + case 25: + break; + case 8: { + if (string == null) { + string = new StringBuffer(); + } + string.append(']'); + } + case 26: + break; + case 12: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\t'); + } + case 27: + break; + case 9: { + if (string == null) { + string = new StringBuffer(); + } + string.append('['); + } + case 28: + break; + case 10: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\\'); + } + case 29: + break; + case 16: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\"'); + } + case 30: + break; + case 15: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\r'); + } + case 31: + break; + case 14: { + if (string == null) { + string = new StringBuffer(); + } + string.append('\f'); + } + case 32: + break; + case 5: { + yybegin(YYINITIAL); + } + case 33: + break; + case 3: { + } + case 34: + break; + default: + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + switch (zzLexicalState) { + case YYINITIAL: { + if (finish) { + return null; + } else { + finish = true; + return new ParsedSymbol(SymbolType.TEXT, string.toString()); + } + } + case 23: + break; + default: { + return null; + } + } + } else { + zzScanError(ZZ_NO_MATCH); + } + } } - } - - // store back cached position - zzMarkedPos = zzMarkedPosL; - - switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { - case 1: - { if(string==null) string=new StringBuffer(); string.append( yytext() ); - } - case 18: break; - case 7: - { throw new ParseException("Illegal escape sequence \""+yytext()+"\"",yyline+1); - } - case 19: break; - case 13: - { if(string==null) string=new StringBuffer(); string.append( '\n' ); - } - case 20: break; - case 2: - { yybegin(PARAMETER); - if(string!=null){ - String ret=string.toString(); - string = null; - return new ParsedSymbol(SymbolType.TEXT,ret.toString()); - } - } - case 21: break; - case 11: - { if(string==null) string=new StringBuffer(); string.append( '\b' ); - } - case 22: break; - case 17: - { if(string==null) string=new StringBuffer(); string.append( '\'' ); - } - case 23: break; - case 4: - { parameterName = yytext(); - yybegin(VALUE); - } - case 24: break; - case 6: - { yybegin(PARAMETER); - return new ParsedSymbol(SymbolType.PARAMETER,new Object[]{parameterName,yytext()}); - } - case 25: break; - case 8: - { if(string==null) string=new StringBuffer(); string.append( ']' ); - } - case 26: break; - case 12: - { if(string==null) string=new StringBuffer(); string.append( '\t' ); - } - case 27: break; - case 9: - { if(string==null) string=new StringBuffer(); string.append( '[' ); - } - case 28: break; - case 10: - { if(string==null) string=new StringBuffer(); string.append( '\\' ); - } - case 29: break; - case 16: - { if(string==null) string=new StringBuffer(); string.append( '\"' ); - } - case 30: break; - case 15: - { if(string==null) string=new StringBuffer(); string.append( '\r' ); - } - case 31: break; - case 14: - { if(string==null) string=new StringBuffer(); string.append( '\f' ); - } - case 32: break; - case 5: - { yybegin(YYINITIAL); - } - case 33: break; - case 3: - { - } - case 34: break; - default: - if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { - zzAtEOF = true; - switch (zzLexicalState) { - case YYINITIAL: { - if(finish){return null;}else{finish=true; return new ParsedSymbol(SymbolType.TEXT,string.toString());} - } - case 23: break; - default: - { - return null; - } - } - } - else { - zzScanError(ZZ_NO_MATCH); - } - } } - } - - }