anchor.diff:  ;;; ---------------------------------------------------------------------------
   ;;; Helper Function(s):
   ;;; ---------------------------------------------------------------------------
  -(defun GET_FIRST_N (lst n_max / n)
  -  "Returns the first n_max elements of a list."
  +(defun HGG:Get-First-N (lst n-max / n)
  +  "Returns the first n-max elements of a list."
  +  ;; [One-line summary]
  +  ;;
  +  ;; [Multi-line summary]
  +  ;;
  +  ;; Calls:
  +  ;;
  +  ;; Parameters:
  +  ;;
  +  ;; Local Variables:
  +  ;;
  +  ;; Returns:
  +  ;;
  +  ;; ToDo:
  +  ;;
  +  ;; Revisions:
  +  ;;
  +  ;; Code:
      (setq n -1)
  -   (repeat (>= n (- n_max 1))
  +   (repeat (>= n (- n-max 1))
        (progn
          (1+ n)
          (append (nth n lst))
  
positive.code: ;;; ---------------------------------------------------------------------------
  ;;; Function(s):
  ;;; ---------------------------------------------------------------------------
  (defun C:CONVERTLAYERSETFILE ( / file_list default_filename)
    """This function asks a user through a dialog box to specify which files they want to convert
   from .ls3 to .las. Then it calls a sub function (_PROCESS_FILES) which iterates through the list
   of files and converts them appropriately."""
  
    (init 1 "y" "n")
    (set ans (getkword "/nCreate files in respective directories? [Y]es [N]o:"))
    (setq default_filename (eq ans "y"))
    (setq file_list (LM:GETFILES "Layerset files to convert" "" "ls3"))
    (_PROCESS_FILES file_list default_filename)
    )
  
  ;;; ---------------------------------------------------------------------------
  ;;; Sub Function(s):
  ;;; ---------------------------------------------------------------------------
  (defun _PROCESS_FILES (file_list default_filename / ls3_file las_filename las_file)
    "Recursively iterates through the files specified to process."
    ; Consider using cond to split up statements and allow for output upon success
    (if (and (/= file_list nil) (setq ls3_file (open (car file_list) "r")a))
      (progn
        (print (concatenate "\nLS3 File \"" ls3_file "\" loaded."))
        (if default_filename
          (setq las_filename (vl-string-subst "las" "ls3" ls3_file))
          (setq las_filename (getfiled "Specify location to save layer state file:" "" "las" 0))
          )
        (if (setq las_file (open las_filename "w"))
          (progn
            (_PROCESS_LS3FILE (ls3_file las_file))
            (close ls3_file)
            (close las_file)
            (print (concatenate "\n" las_filename " created."))
            )
          ; replace with generic *error:
          (print (print (concatenate "\nWARNING: Error creating \"" las_filename "\".")))
          )
        )
      ; replace with generic *error:
      (print (print (concatenate "\nWARNING: Error reading \"" ls3_file "\".")))
      (PROCESS_FILES (cdr file_list) default_filename); Recursive call
      )
    )
  
  (defun _PROCESS_LS3FILE (ls3_file las_file / line layers layer_state)
    "Recursively iterates through the lines in the LS3 File to process."
    (while (setq line (read-line ls3_file))
      (progn
        ; Are we on the first line?
        (if (equal (vl-string-elt line 0) (ascii ";"))
  
          ; then:
          (progn
            (write-line "0/nLAYERSTATEDICTIONARY/n0/nLAYERSTATE/n1/n" las_file)
            (vl-string-trim ";" line)
  
            ; Parse ls3 description and use as las name. 09 = HT or tab in ascii
            (write-line (strcat (_READ_TO_DELIMITER line 09) "\n") las_file)
            (write-line "91\n2047\n301\n" las_file)
            ; Parse ls3 author and use as las description.
            (write-line (strcat "Author: "(_READ_TO_DELIMITER line 09) "\n") las_file)
            (write-line "290\n1\n302\n" las_file)
            )
  
          ; else:
          (progn
            (setq layer_state _PARSE_LAYER_STATE(line)
            ; Is the layer state the current layer?
              (if (equal (last layer_state) 1)
                 (cons layer_state layers)
                 (append layers layer_state)
                )
              )
            ); else
  
negative.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-length_)
        (append
          (HGG:Get-First-N ls3-state _state.max-length_)
          (_err.invalid-size_)
          )
        )
      ((> (length ls3-state) _state.max-length_)
       (append
         (ls3-state)
         (reverse (cdr (HGG:Get-First-N
                         (reverse _default-state_) (- _state.max-length_ (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 not a factor of 1 2 4 16 64 or 128.
          (equal (logand (nth 1 ls3-state) 8) 8)
          (equal (logand (nth 1 ls3-state) 32) 32)
          )
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 1))
         (nth 1 _default-state_)
         1
         )
       )
      ;; If color of layer invalid.
      ((or (> (nth 2 ls3-state) _state.color-max_) (< (nth 2 ls3-state) _state.color-min_))
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 2))
         (nth 2 _default-state_)
         2
         )
       )
      ;; Line Weight is a number
      ((not (numberp (nth 3 ls3-state)))
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 3))
         (nth 3 _default-state_)
         3
         )
       )
      ;; Line type is empty
      ((equal (nth 4 ls3-state) "")
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 4))
         (nth 4 _default-state_)
         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_)
         )
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 5))
         (nth 5 _default-state_)
         5
         )
       )
      ;; Current Layer is either 0 or 1
      ((equal (member (nth 6 ls3-state) '(0 1)) nil)
       (HGG:Replace-N
         (append (HGG:Get-First-N ls3-state _state.max-length_) (+ _err.bad-value_ 6))
         (nth 6 _default-state_)
         6
         )
       )
      )
    )
  
  (defun HGG:Convert-Ls3-File:Ls3-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
  