# Path: wrd/parser.py
# def parse_command(data):
#   
#   header = data.peek("uint:8")
#   
#   if not header == CMD_MARKER:
#     raise InvalidWrdHeader("Command 0x%02X does not begin with 0x%02X" % (header, CMD_MARKER))
#   
#   data.read("uint:8")
#   op = data.read("uint:8")
#   
#   params = OrderedDict()
#   
#   if op in OP_PARAMS:
#     param_info = OP_PARAMS[op]
#     
#     # If it's a custom function, use that.
#     if isinstance(param_info, basestring):
#       if param_info in globals():
#         params = globals()[param_info](data)
#       else:
#         raise Exception("Function %s not defined." % param_info)
#     
#     # Otherwise, just use the param list.
#     else:
#       param_names = [info[0] for info in param_info]
#       param_types = [info[1] for info in param_info]
#       
#       param_vals  = data.readlist(param_types)
#       
#       for name, val in zip(param_names, param_vals):
#         
#         if name == None:
#           try:
#             params[None].append(val)
#           except:
#             params[None] = [val]
#         else:
#           params[name] = val
#   
#   else:
#     print "Unknown opcode encountered: 0x%02X" % op
#     
#   return op, params
# 
# class InvalidWrdHeader(Exception):
#   pass


import bitstring
from bitstring import BitStream, ConstBitStream
from wrd.ops import *
from wrd.parser import parse_command, InvalidWrdHeader
### 
### The Super Duper Script Editor 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.
### 
### The Super Duper Script Editor 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 the Super Duper Script Editor.
### If not, see <http://www.gnu.org/licenses/>.
################################################################################



################################################################################
### Converts binary wrd data to a list of commands which can be used in all
### the other functions in this module.
################################################################################
def from_bin(data):

  # Eat the header.
  parse_command(data)
  
  commands = []
  while True:
    try:

# Path: wrd/parser.py
# def parse_command(data):
#   
#   header = data.peek("uint:8")
#   
#   if not header == CMD_MARKER:
#     raise InvalidWrdHeader("Command 0x%02X does not begin with 0x%02X" % (header, CMD_MARKER))
#   
#   data.read("uint:8")
#   op = data.read("uint:8")
#   
#   params = OrderedDict()
#   
#   if op in OP_PARAMS:
#     param_info = OP_PARAMS[op]
#     
#     # If it's a custom function, use that.
#     if isinstance(param_info, basestring):
#       if param_info in globals():
#         params = globals()[param_info](data)
#       else:
#         raise Exception("Function %s not defined." % param_info)
#     
#     # Otherwise, just use the param list.
#     else:
#       param_names = [info[0] for info in param_info]
#       param_types = [info[1] for info in param_info]
#       
#       param_vals  = data.readlist(param_types)
#       
#       for name, val in zip(param_names, param_vals):
#         
#         if name == None:
#           try:
#             params[None].append(val)
#           except:
#             params[None] = [val]
#         else:
#           params[name] = val
#   
#   else:
#     print "Unknown opcode encountered: 0x%02X" % op
#     
#   return op, params
# 
# class InvalidWrdHeader(Exception):
#   pass


# Path: wrd/bin.py
import bitstring
from bitstring import BitStream, ConstBitStream
from wrd.ops import *
from wrd.parser import parse_command, InvalidWrdHeader

### 
### The Super Duper Script Editor 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.
### 
### The Super Duper Script Editor 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 the Super Duper Script Editor.
### If not, see <http://www.gnu.org/licenses/>.
################################################################################



################################################################################
### Converts binary wrd data to a list of commands which can be used in all
### the other functions in this module.
################################################################################
def from_bin(data):

  # Eat the header.
  parse_command(data)
  
  commands = []
  while True:
    try:

      op, params = parse_command(data)