anchor.diff:       )
     )
   
  -(defun REPLACE_N (lst new_value nth_element )
  -  "Returns a list with the n'th_element replaced with new_value"
  +(defun HGG:Replace-N (lst new-value nth-element )
  +  "Returns a list with the n'th_element replaced with new-value"
  +  ;; [One-line summary]
  +  ;;
  +  ;; [Multi-line summary]
  +  ;;
  +  ;; Calls:
  +  ;;
  +  ;; Parameters:
  +  ;;
  +  ;; Local Variables:
  +  ;;
  +  ;; Returns:
  +  ;;
  +  ;; ToDo:
  +  ;;
  +  ;; Revisions:
  +  ;;
  +  ;; Code:
     (append
  -    (GET_FIRST_N lst (- nth_element 1))
  -    new_value
  -    (GET_FIRST_N (reverse lst) (- (length lst) nth_element))
  -    )
  -  )
  -
  -(defun _READ_TO_DELIMITER (raw_string delimiter_character_code / parsed_string delimiter_position)
  -  "Returns the string up to delimiter_code and removes it from raw_string."
  -  (setq delimiter_position (vl-string-position delimiter_character_code raw_string))
  -  (setq parsed_string (substr raw_string 1 delimiter_position))
  -  (setq raw_string (substr raw_string (+ 2 delimiter_position) (strlen raw_string)))
  -  (parsed_string)
  -  )
  +    (HGG:Get-First-N lst (- nth-element 1))
  +    new-value
  +    (HGG:Get-First-N (reverse lst) (- (length lst) nth-element))
  +    )
  +  )
  +
  +(defun HGG:Read-To-Delimiter (string delimiter-character-code / parsed-string delimiter-position)
  +  "Returns the string up to delimiter_code and removes it from string."
  +  ;; [One-line summary]
  +  ;;
  +  ;; [Multi-line summary]
  +  ;;
  +  ;; Calls:
  +  ;;
  +  ;; Parameters:
  +  ;;
  +  ;; Local Variables:
  +  ;;
  +  ;; Returns:
  +  ;;
  +  ;; ToDo:
  +  ;;
  +  ;; Revisions:
  +  ;;
  +  ;; Code:
  +  (setq delimiter-position (vl-string-position delimiter-character-code string))
  +  (setq parsed-string (substr string 1 delimiter-position))
  +  (setq string (substr string (+ 2 delimiter-position) (strlen string)))
  +  parsed-string
  +  )
  +
  +;; Program continuation:
  +(vl-load-com)
  +(princ)
  +;;; ConvertLayerSetFile.LSP
  
positive.code:       0
        )
      )
    (setq _ERR_NO_ERROR 0)
    (setq _ERR_INVALID_SIZE 1)
    (setq _ERR_BAD_VALUE 20)
    (setq _STATE_MAX_LENGTH 8)
    (if (= is_new_state 1) (1- _STATE_MAX_LENGTH))
    (setq _STATE_BIT_FACTORS (1 2 4 16 64 128))
    (setq _STATE_BIT_MAX (+ _STATE_BIT_FACTORS))
    (setq _STATE_BIT_MIN 0)
    (setq _STATE_COLOR_MAX 255)
    (setq _STATE_COLOR_MIN 0)
  
    (cond
      ; If ls3_state length is wrong.
      ((> (length ls3_state) _STATE_MAX_SIZE)
        (append
          (GET_FIRST_N ls3_state _STATE_MAX_SIZE)
          (_ERR_INVALID_SIZE)
          )
        )
      ((> (length ls3_state) _STATE_MAX_SIZE)
       (append
         (ls3_state)
         (reverse (cdr (GET_FIRST_N
                         (reverse _LS3_STATE_DEFAULT) (- _STATE_MAX_SIZE (length ls3_state))
                         )))
         (_ERR_INVALID_SIZE)
         )
       )
      ; If the state is an invalid state.
      ((or
          ; State is a number
          (numberp (nth 1 ls3_state))
          ; State is greater than max bit value or less than min bit value
          (< (nth 1 ls3_state) _STATE_BIT_MIN)
          (> (nth 1 ls3_state) _STATE_BIT_MAX)
          ; State is a factor of 1 2 4 16 64 or 128.
          )
       (REPLACE_N
         (append (GET_FIRST_N ls3_state _STATE_MAX_SIZE) (+ _ERR_BAD_VALUE 1))
         (nth 1 _LS3_STATE_DEFAULT)
         1
         )
       )
      ; If color of layer invalid.
      ((or (> (nth 2 ls3_state) _STATE_COLOR_MAX) (< (nth 2 ls3_state) _STATE_COLOR_MIN))
       (REPLACE_N
         (append (GET_FIRST_N ls3_state _STATE_MAX_SIZE) (+ _ERR_BAD_VALUE 2))
         (nth 2 _LS3_STATE_DEFAULT)
         2
         )
       )
      ; Line Weight is a number
      ; Line type is empty
      ((equal (nth 4 ls3_state) "")
       (REPLACE_N
         (append (GET_FIRST_N ls3_state _STATE_MAX_SIZE) (+ _ERR_BAD_VALUE 4))
         (nth 4 _LS3_STATE_DEFAULT)
         4
         )
       )
      ; Plot style string is in format of Color_###
      (
       (or
         (not (wcmatch (nth 5 ls3_state) "Color_*"))
         (atoi (vl-string-left-trim "Color_" (nth 5 ls3_state)))
         (> (atoi (vl-string-left-trim "Color_" (nth 5 ls3_state))) _STATE_COLOR_MAX)
         (< (atoi (vl-string-left-trim "Color_" (nth 5 ls3_state))) _STATE_COLOR_MIN)
         )
       (REPLACE_N
         (append (GET_FIRST_N ls3_state _STATE_MAX_SIZE) (+ _ERR_BAD_VALUE 5))
         (nth 5 _LS3_STATE_DEFAULT)
         5
         )
       )
      ; Current Layer is either 0 or 1
      ((equal (member (nth 6 ls3_state) '(0 1)) nil)
       (REPLACE_N
         (append (GET_FIRST_N ls3_state _STATE_MAX_SIZE) (+ _ERR_BAD_VALUE 6))
         (nth 6 _LS3_STATE_DEFAULT)
         6
         )
       )
      )
    )
  
  (defun _LAS_STATE_FROM_LS3 (ls3_state)
    """
    Converts a ls3 type layer state to a LAS type layer state.
  
    The LAS type layer state has the following structure:
      ls3_state[0] = Layer Name as a string.
      ls3_state[1] = Layer state as bits where bits are as follows:
                      1 = Is Off
                      2 = Is Frozen
                      4 = Is Locked
  
negative.code:     )
    (write-line (strcat (car (car layers)) "\n")); write current layer.
    (foreach layer layers
      ;; Create a list of layer-state's with #1 being the current layer.
      (if(HGG:Convert-Ls3-File:Ls3-State:State-Print layer); if success.
          (HGG:Convert-Ls3-File:Ls3-State:State-Print layer); then
          (print (strcat "Error in processing layer: " (car layer)))
        )
      )
    )
  
  (defun HGG:Convert-Ls3-File:Ls3-State:Parse-string (string / ls3-state)
    ;; Creates a layer state in LS3 format from a parsed strin and returns that layer state.
    ;;
    ;; The LS3 format is based upon the format of a layer state in the *.ls3 file. Reverse
    ;; engineering the format and putting it into a list format yields the below form of a list.
    ;; Because AutoLISP is a shitty language, the list is being used much like a struct with the
    ;; location of each member having a very important identiy.
    ;;
    ;; The typical structure of string found in a *.ls3 file:
    ;;
    ;;
    ;; The Structure of an ls3-state (see +default-ls3-state+ for default values):
    ;; (nth 0 ls3-state) :> "Layer name"
    ;; (nth 1 ls3-state) :> Integer being used for bit representation of states.
    ;;                      The bits are as follows:
    ;;                        1 = Is Frozen
    ;;                        2 = Is New VP Frozen
    ;;                        4 = Is Locked
    ;;                        8 = N/A
    ;;                        16 = Is Xref Dependent
    ;;                        32 = N/A
    ;;                        64 = Is Plottable
    ;;                        128 = Is VP Frozen
    ;; (nth 2 ls3-state) :> Integer representing color of layer from 1 - 255 and * -1 if the layer
    ;;                      is off.
    ;; (nth 3 ls3-state) :> Linetype
    ;; (nth 4 ls3-state) :> Line Weight
    ;; (nth 5 ls3-state) :> Plot Style
    ;; (nth 6 ls3-state) :> Is Current Layer (1 if it is, 0 if not)
    ;; (nth 7 ls3-state) :> Error Code as follows:
    ;;                        0 = No Error
    ;;                        1 = Invalid amount size (# of states) for Layer State
    ;;                        2 = Bad value for a state (i.e. color > 255) with # being a state
    ;;                            numbered 0 - 6.
    ;;                        3 = Multiple states were found to be invalid.
    ;;                        4 = Unknown error
    ;;
    ;; Calls:
    ;;    (HGG:Convert-Ls3-File:Ls3-State:Check-For-Errors)
    ;;    (HGG:Read-To-Delimiter)
    ;;
    ;; Parameters:
    ;;    (string) - The string to be parsed representing the layer state.
    ;;
    ;; Local Variables:
    ;;    (ls3-state) - An LS3 type state.
    ;;
    ;; Returns:
    ;;    The layer state in a LAS type format. See HGG:Convert-Ls3-File:Ls3-State:From-Ls3 for more
    ;;    info.
    ;;
    ;; ToDo:
    ;;
    ;; Revisions:
    ;;    (S.P.) @(01-05-16) - For reducing complexity, have this function return the layer state
    ;;                         in a LS3 type format. Makes it more testable as well.
    ;;
    ;; Code:
    (while (not (equal string "\n"))
      (setq ls3-state (append ls3-state (HGG:Read-To-Delimiter string 09)))
      )
    (HGG:Convert-Ls3-File:Ls3-State:Check-For-Errors ls3-state)
    )
  
  (defun HGG:Convert-Ls3-File:Ls3-State:Check-For-Errors (ls3-state is_new_state
                                     / _default-state_ _err.no-error_ _err.invalid-size_
                                     _err.bad-value_ _state.max-length_ _state.bit-factors_
                                     _state.bit-max_ _state.bit-min_ _state.color-max_ _state.color-min_)
    """
    Checks to see if the layer-state is valid then respectively sets the error code.
  
    The error codes are as follows:
                         0  = No Error.
                         1  = Invalid amount size (# of states) for Layer State.
  