// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:00:57
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/utils/ActionParser

package com.macromedia.generator.utils;

import com.macromedia.generator.api.Action;
import com.macromedia.generator.api.GeneratorApiException;
import com.macromedia.generator.app.FlashEnvironment;
import java.io.*;
import java.util.*;

public class ActionParser
{

    public ActionParser(FlashEnvironment flashenvironment, boolean flag)
    {
        _fld0270 = null;
        _fld0271 = null;
        _fld0272 = null;
        _fld0273 = null;
        _fld0274 = true;
        _fld0275 = 0;
        _fld0272 = new Vector(5, 5);
        _fld0273 = flashenvironment;
        _fld0274 = flag;
    }

    private int _mth0270(String s)
    {
        char c = '\004';
        if(s.equalsIgnoreCase("Enter"))
            c = '\001';
        else
        if(s.equalsIgnoreCase("Down"))
            c = '\004';
        else
        if(s.equalsIgnoreCase("Up"))
            c = '@';
        else
        if(s.equalsIgnoreCase("Exit"))
            c = '\u0110';
        else
            _mth0274("InvalidTransition: " + s);
        return c;
    }

    private String _mth0271()
    {
        String s = null;
        if(_fld0270 != null)
            try
            {
                _fld0270.nextToken();
                _fld0275 = _fld0270.ttype;
                if(_fld0270.ttype == -3)
                    s = _fld0270.sval;
                else
                if(_fld0270.ttype == 34 || _fld0270.ttype == 39)
                    s = _fld0270.sval;
                else
                if(_fld0270.ttype == -2)
                {
                    int i = (int)_fld0270.nval;
                    double d = i;
                    if(d == _fld0270.nval)
                        s = Integer.toString((int)_fld0270.nval);
                    else
                        s = Double.toString(_fld0270.nval);
                } else
                if(_fld0270.ttype == -1)
                    _mth0274("EOF");
                else
                    _mth0274("Unknown tokenizer type: " + _fld0270.ttype);
            }
            catch(IOException ioexception)
            {
                _mth0274("error getting token: " + ioexception);
            }
        else
        if(_fld0271 != null)
            try
            {
                s = _fld0271.nextToken();
                _fld0275 = -3;
                if(s != null)
                {
                    if(s.startsWith("\""))
                        s = s.substring(1);
                    if(s.endsWith("\""))
                        s = s.substring(0, s.length() - 1);
                }
            }
            catch(NoSuchElementException _ex)
            {
                _fld0275 = -1;
                _mth0274("EOF");
            }
        return s;
    }

    private int _mth0272(String s)
    {
        byte byte0 = 1;
        if(s.equalsIgnoreCase("xpos") || s.equalsIgnoreCase("xposition"))
            byte0 = 1;
        else
        if(s.equalsIgnoreCase("ypos") || s.equalsIgnoreCase("yposition"))
            byte0 = 2;
        else
        if(s.equalsIgnoreCase("xscale"))
            byte0 = 3;
        else
        if(s.equalsIgnoreCase("yscale"))
            byte0 = 4;
        else
        if(s.equalsIgnoreCase("alpha"))
            byte0 = 5;
        else
        if(s.equalsIgnoreCase("vis") || s.equalsIgnoreCase("visibility"))
            byte0 = 6;
        else
        if(s.equalsIgnoreCase("rot") || s.equalsIgnoreCase("rotation"))
            byte0 = 7;
        else
        if(s.equalsIgnoreCase("name"))
            byte0 = 8;
        else
            _mth0274("Invalid property: " + s);
        return byte0;
    }

    private int _mth0273()
    {
        return _fld0275;
    }

    private void _mth0274(String s)
    {
        if(_fld0274)
            if(_fld0273 != null)
                _fld0273.logMessage(s);
            else
                System.out.println("ActionParser Error: " + s);
    }

    private void _mth0275()
    {
        Object obj = null;
        try
        {
            Action action = new Action();
            _fld0272.addElement(action);
            action.setTransitionState(4);
            for(String s = _mth0271(); _mth0273() != -1; s = _mth0271())
                if(s.equalsIgnoreCase("newAction"))
                {
                    action = new Action();
                    _fld0272.addElement(action);
                    action.setTransitionState(4);
                    _mth0274("New Action");
                } else
                if(s.equalsIgnoreCase("transition"))
                {
                    String s1 = _mth0271();
                    _mth0274("Transition: " + s1);
                    int i = _mth0270(s1);
                    action.setTransitionState(i);
                } else
                if(s.equalsIgnoreCase("push"))
                {
                    String s2 = _mth0271();
                    if(s2 != null)
                    {
                        _mth0274("Push: " + s2);
                        action.addPush(s2);
                    } else
                    {
                        _mth0274("Push argument error");
                    }
                } else
                if(s.equalsIgnoreCase("GotoFrame"))
                {
                    String s3 = _mth0271();
                    _mth0274("GotoFrame " + s3);
                    action.addGotoFrame(Integer.parseInt(s3));
                } else
                if(s.equalsIgnoreCase("GetURL"))
                {
                    String s4 = _mth0271();
                    String s11 = _mth0271();
                    _mth0274("GetURL: " + s4 + ", " + s11);
                    action.addGetURL(s4, s11);
                } else
                if(s.equalsIgnoreCase("NextFrame"))
                {
                    _mth0274("NextFrame");
                    action.addNextFrame();
                } else
                if(s.equalsIgnoreCase("PrevFrame"))
                {
                    _mth0274("PrevFrame");
                    action.addPrevFrame();
                } else
                if(s.equalsIgnoreCase("Play"))
                {
                    _mth0274("Play");
                    action.addPlay();
                } else
                if(s.equalsIgnoreCase("Stop"))
                {
                    _mth0274("Stop");
                    action.addStop();
                } else
                if(s.equalsIgnoreCase("ToggleQuality"))
                {
                    _mth0274("ToggleQuality");
                    action.addToggleQuality();
                } else
                if(s.equalsIgnoreCase("StopSounds"))
                {
                    _mth0274("StopSounds");
                    action.addStopSounds();
                } else
                if(s.equalsIgnoreCase("WaitForFrame"))
                {
                    String s5 = _mth0271();
                    _mth0274("WaitForFrame " + s5);
                    action.addWaitForFrame(Integer.parseInt(s5));
                } else
                if(s.equalsIgnoreCase("TellTarget"))
                {
                    String s6 = _mth0271();
                    _mth0274("TellTarget " + s6);
                    action.addTellTarget(s6);
                } else
                if(s.equalsIgnoreCase("GotoLabel"))
                {
                    String s7 = _mth0271();
                    _mth0274("GotoLabel " + s7);
                    action.addGotoLabel(s7);
                } else
                if(s.equalsIgnoreCase("Add"))
                {
                    _mth0274("Add");
                    action.addAdd();
                } else
                if(s.equalsIgnoreCase("Subtract"))
                {
                    _mth0274("Subtract");
                    action.addSubtract();
                } else
                if(s.equalsIgnoreCase("Multiply"))
                {
                    _mth0274("Multiply");
                    action.addMultiply();
                } else
                if(s.equalsIgnoreCase("Divide"))
                {
                    _mth0274("Divide");
                    action.addDivide();
                } else
                if(s.equalsIgnoreCase("Eq") || s.equalsIgnoreCase("Equals"))
                {
                    _mth0274("Eq");
                    action.addEq();
                } else
                if(s.equalsIgnoreCase("Less"))
                {
                    _mth0274("Less");
                    action.addLess();
                } else
                if(s.equalsIgnoreCase("And"))
                {
                    _mth0274("And");
                    action.addAnd();
                } else
                if(s.equalsIgnoreCase("Or"))
                {
                    _mth0274("Or");
                    action.addOr();
                } else
                if(s.equalsIgnoreCase("Not"))
                {
                    _mth0274("Not");
                    action.addNot();
                } else
                if(s.equalsIgnoreCase("StringEq") || s.equalsIgnoreCase("StringEquals") || s.equalsIgnoreCase("StrEq") || s.equalsIgnoreCase("StrEquals"))
                {
                    _mth0274("StringEq");
                    action.addStringEq();
                } else
                if(s.equalsIgnoreCase("StringLen") || s.equalsIgnoreCase("StringLength") || s.equalsIgnoreCase("StrLen") || s.equalsIgnoreCase("StrLength"))
                {
                    _mth0274("StringLength");
                    action.addStringLength();
                } else
                if(s.equalsIgnoreCase("StringAdd") || s.equalsIgnoreCase("StrAdd"))
                {
                    _mth0274("StringAdd");
                    action.addStringAdd();
                } else
                if(s.equalsIgnoreCase("StringExtract") || s.equalsIgnoreCase("StrExtract"))
                {
                    _mth0274("StringExtract");
                    action.addStringExtract();
                } else
                if(s.equalsIgnoreCase("Push"))
                {
                    String s8 = _mth0271();
                    _mth0274("Push " + s8);
                    action.addPush(s8);
                } else
                if(s.equalsIgnoreCase("Pop"))
                {
                    _mth0274("Pop");
                    action.addPop();
                } else
                if(s.equalsIgnoreCase("ToInteger"))
                {
                    _mth0274("ToInteger");
                    action.addToInteger();
                } else
                if(s.equalsIgnoreCase("Jump"))
                {
                    _mth0274("Jump");
                    action.addJump();
                } else
                if(s.equalsIgnoreCase("EndJump"))
                {
                    _mth0274("EndJump");
                    action.addEndJump();
                } else
                if(s.equalsIgnoreCase("If"))
                {
                    _mth0274("If");
                    action.addIf();
                } else
                if(s.equalsIgnoreCase("EndIf"))
                {
                    _mth0274("EndIf");
                    action.addEndIf();
                } else
                if(s.equalsIgnoreCase("Call"))
                {
                    _mth0274("Call");
                    action.addCall();
                } else
                if(s.equalsIgnoreCase("GetVariable"))
                {
                    _mth0274("GetVariable");
                    action.addGetVariable();
                } else
                if(s.equalsIgnoreCase("SetVariable"))
                {
                    _mth0274("SetVariable");
                    action.addSetVariable();
                } else
                if(s.equalsIgnoreCase("GetURL2"))
                {
                    String s9 = _mth0271();
                    _mth0274("GetURL2: " + s9);
                    char c = '\0';
                    if(s9.equalsIgnoreCase("GET"))
                        c = '\201';
                    else
                    if(s9.equalsIgnoreCase("POST"))
                        c = '\202';
                    else
                    if(s9.equalsIgnoreCase("MOVIE") || s9.equalsIgnoreCase("LOADMOVIE"))
                    {
                        c = '\0';
                    } else
                    {
                        if(!s9.equalsIgnoreCase("NOSEND"))
                            _mth0274("Unrecognized send type.  Using NOSEND");
                        c = '\200';
                    }
                    action.addGetURL2(c);
                } else
                if(s.equalsIgnoreCase("GotoFrame2"))
                {
                    _mth0274("GotoFrame2");
                    action.addGotoFrame2();
                } else
                if(s.equalsIgnoreCase("PushProperty") || s.equalsIgnoreCase("PushProp"))
                {
                    String s10 = _mth0271();
                    int j = _mth0272(s10);
                    action.addPushProperty(j);
                } else
                if(s.equalsIgnoreCase("SetTarget2"))
                {
                    _mth0274("SetTarget2");
                    action.addSetTarget2();
                } else
                if(s.equalsIgnoreCase("GetProperty"))
                {
                    _mth0274("GetProperty");
                    action.addGetProperty();
                } else
                if(s.equalsIgnoreCase("SetProperty"))
                {
                    _mth0274("SetProperty");
                    action.addSetProperty();
                } else
                if(s.equalsIgnoreCase("CloneSprite"))
                {
                    _mth0274("CloneSprite");
                    action.addCloneSprite();
                } else
                if(s.equalsIgnoreCase("RemoveSprite"))
                {
                    _mth0274("RemoveSprite");
                    action.addRemoveSprite();
                } else
                if(s.equalsIgnoreCase("Trace"))
                {
                    _mth0274("Trace");
                    action.addTrace();
                } else
                if(s.equalsIgnoreCase("StartDrag"))
                {
                    _mth0274("StartDrag");
                    action.addStartDrag();
                } else
                if(s.equalsIgnoreCase("EndDrag"))
                {
                    _mth0274("EndDrag");
                    action.addEndDrag();
                } else
                if(s.equalsIgnoreCase("StringLess"))
                {
                    _mth0274("StringLess");
                    action.addStringLess();
                } else
                if(s.equalsIgnoreCase("WaitForFrame2"))
                {
                    _mth0274("WaitForFrame2");
                    action.addWaitForFrame2();
                } else
                if(s.equalsIgnoreCase("RandomNumber"))
                {
                    _mth0274("RandomNumber");
                    action.addRandomNumber();
                } else
                if(s.equalsIgnoreCase("MBStringLength"))
                {
                    _mth0274("MBStringLength");
                    action.addMBStringLength();
                } else
                if(s.equalsIgnoreCase("CharToAscii"))
                {
                    _mth0274("CharToAscii");
                    action.addCharToAscii();
                } else
                if(s.equalsIgnoreCase("AsciiToChar"))
                {
                    _mth0274("AsciiToChar");
                    action.addAsciiToChar();
                } else
                if(s.equalsIgnoreCase("GetTime"))
                {
                    _mth0274("GetTime ");
                    action.addGetTime();
                } else
                if(s.equalsIgnoreCase("MBStringExtract"))
                {
                    _mth0274("MBStringExtract");
                    action.addMBStringExtract();
                } else
                if(s.equalsIgnoreCase("MBCharToAscii"))
                {
                    _mth0274("MBCharToAscii");
                    action.addMBCharToAscii();
                } else
                if(s.equalsIgnoreCase("MBAsciiToChar"))
                {
                    _mth0274("MBAsciiToChar");
                    action.addMBAsciiToChar();
                } else
                {
                    _mth0274("Unknown command: " + s);
                    return;
                }

        }
        catch(GeneratorApiException generatorapiexception)
        {
            _mth0274("api exception: " + generatorapiexception);
        }
        catch(NumberFormatException numberformatexception)
        {
            _mth0274("Number format exception: " + numberformatexception);
        }
    }

    public Action[] ParseActionsFromFile(String s)
    {
        if(_fld0272 == null)
            _fld0272 = new Vector(5, 5);
        try
        {
            FileInputStream fileinputstream = new FileInputStream(s);
            BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(fileinputstream));
            _fld0270 = new StreamTokenizer(bufferedreader);
            _fld0270.ordinaryChar(46);
            _fld0270.ordinaryChar(47);
            _fld0270.ordinaryChar(58);
            _fld0270.parseNumbers();
            _mth0275();
        }
        catch(FileNotFoundException filenotfoundexception)
        {
            _mth0274("Failed to open data source: " + filenotfoundexception);
            return null;
        }
        catch(IOException ioexception)
        {
            _mth0274("Error getting token: " + ioexception);
            return null;
        }
        _fld0270 = null;
        int i = _fld0272.size();
        Action aaction[] = null;
        if(i > 0)
        {
            aaction = new Action[i];
            Enumeration enumeration = _fld0272.elements();
            int j = 0;
            while(enumeration.hasMoreElements()) 
                aaction[j++] = (Action)enumeration.nextElement();
        }
        _fld0272 = null;
        return aaction;
    }

    public Action[] ParseActionsFromString(String s)
    {
        if(_fld0272 == null)
            _fld0272 = new Vector(5, 5);
        _fld0271 = new StringTokenizer(s);
        _mth0275();
        int i = _fld0272.size();
        Action aaction[] = null;
        if(i > 0)
        {
            aaction = new Action[i];
            Enumeration enumeration = _fld0272.elements();
            int j = 0;
            while(enumeration.hasMoreElements()) 
                aaction[j++] = (Action)enumeration.nextElement();
        }
        _fld0272 = null;
        _fld0271 = null;
        return aaction;
    }

    StreamTokenizer _fld0270;
    StringTokenizer _fld0271;
    Vector _fld0272;
    FlashEnvironment _fld0273;
    boolean _fld0274;
    int _fld0275;
}