Author Topic: Maximum length of a line of code  (Read 3250 times)

0 Members and 1 Guest are viewing this topic.

ScottBolton

  • Guest
Maximum length of a line of code
« on: March 12, 2013, 04:28:12 AM »
Chaps,

Does anybody know the maximum number of characters in a line of a .lsp file?

S

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Maximum length of a line of code
« Reply #1 on: March 12, 2013, 06:32:36 AM »
There is no limit. Lisp ignores all new-line markers as if they are spaces. So effectively you could have your entire LSP file on one single line, no matter how much is in the LSP file. The only reason programmers tend to split the code into lines is to make it easier for themselves to read.

So then you come to a scenario where each programmer might split at a different position because that's how they understand the code in their mind.

In general however, most programmers would split a line if it gets too long to be printed as text onto a normal sheet of paper (Letter / A4). Usually around 80 characters - though that's from the old printers (e.g. Dot Matrix / Daisy Wheel).

Inside AutoCAD's VLIDE you can adjust the "average" line length from the default around 75 with 90 as maximum. I tend to allow mine to go a bit longer, but that's just me. Generally an auto-format of VLIDE will stop a line at certain specific codes (e.g. it splits an if statement into the test, then and else portions on separate lines) even if combining into one line would still be less than the maximum.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ScottBolton

  • Guest
Re: Maximum length of a line of code
« Reply #2 on: March 12, 2013, 06:42:12 AM »
Thanks, irneb.

The reason I ask is I want to convert my working lisps into delivered lisps by removing comments and the like, leaving just the code.

S

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Maximum length of a line of code
« Reply #3 on: March 12, 2013, 08:20:30 AM »
You may be interested in this OLD lisp.
Code: [Select]
;;;==================[ Strip_comments.lsp ]===========================
;;; Author: Copyright© 2006 Charles Alan Butler
;;; Version:  1.2 Oct. 20, 2006
;;; Purpose: To strip trailing comments from the end of lines
;;;          in a lisp file.
;;; Requirements: User makes file selection and input of comment
;;;               string starting characters
;;;               Enter H for help at the 'String to Remove' propmt
;;;               User has the option to remove empty lined created
;;;               when they are stripped
;;; Returns: nil
;;;==================================================================
(defun c:strip_comments (/           file2read   file2write  filename
                         filepath    filespec    honorblocks ignoreon
                         lncnt       outfile     pos         pos2
                         stcnt       str         strpat      strippat
                         DelLines    skip        stflag      strip_help
                         sphraser
                        )
  ;;
  ;;----------------------------
  ;;          H E L P           
  ;;----------------------------
  ;;
  (defun strip_help ()
    (alert
      (strcat
        "Strip_Comment.lsp   (c) 2006 Charles Alan Butler\n"
        "\nEntering ;_&;- will strip the following lines"
        "\n  (if var1 ;- test var1  \n" "  ) ;_ endif "
        "\nNote a special case where \"; \" is entered, but this \";; \" will be ignored."
        "\nThe user may enter multiple strings to strip at the same time by"
        "\nseparating them with '&'      Example: ;_&;-&; F"
        "\nAny characters starting with ';_' or ';-' or '; F' will be stripped."
        "\nA warning though, it does not skip over quoted text. "
        "\nSo this would be stripped  (setq str \"This is a test ;_\")"
        "\nto this (setq str \"This is a test "
        "\nTherefore use caution in choosing the match characters."
        "\nAnother prompt will allow for the removal of any line made empty when"
        "\nthe comment is strpped."
        "\n\nPlease report any problems you may have.")
    )
  )  ; end defun help

  ;;-------------------------
  ;;  string phraser by CAB 
  ;;-------------------------
  ;; return a list of strings split from str using delim
  (defun sphraser (str delim / ptr lst stp)
    (setq stp 1)
    (while (setq ptr (vl-string-search delim str (1- stp)))
      (setq lst (cons (substr str stp (- (1+ ptr) stp)) lst))
      (setq stp (+ ptr 2))
    )
    (reverse (cons (substr str stp) lst))
  )



  ;;
  ;; o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
  ;;        M A I N   R O U T I N E   S T A R T S   H E R E       
  ;; o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
  ;;

  (if
    (and
      (setq filespec (getfiled "Select a File in the Folder you want to use"
                               "" "lsp" 4))
      (setq filepath (strcat (vl-filename-directory filespec) "\\"))
      (setq filename (strcat (vl-filename-base filespec)
                             (vl-filename-extension filespec)))
    )
     (progn ; --------- Begin File Operations  -------------------
       (while
         (progn
           ;; get search string, allow mutiple strings
           (setq strpat
                  (getstring t
                    (strcat
                      "\nEnter string to remove, Seperate strings with &  "
                      "\nExample \";_&; \"  Enter H for help "
                      "\nEnter only for default <;_>  "))
           )
           (cond
             ((= (strcase strpat) "H")
              (strip_help)
              t
             )
             ((= (vl-string-trim " \t\n" strpat) "")
              (setq strippat '(";_")) ; default
              nil ; exit loop
             )
             ((and (setq strippat (vl-remove "" (sphraser strpat "&")))
                   (> (length strippat) 0) ; this is the only error check
              )
              nil ; exit loop
             )
           )
         )
       )


       ;;  Yes/No to ignore Block Comments
       (initget "Yes No") ; Yes = nil = skip over Block Comments
       (setq HonorBlocks (/= (getkword "\nSkip Block Comments [Yes/No] <Yes>: ") "No"))
       
       ;;  Yes/No to remove emptied lines
       (initget "Yes No") ; Yes = t = delete lines if empty after striping
       (setq DelLines (/= (getkword
                            "\nRemove lines that are made empty [Yes/No] <No>: ") "Yes"))

       ;;  Output File Name
       (setq outfile (strcat (vl-filename-base filespec) "-NEW"
                             (vl-filename-extension filespec))
       )
       (if ; Open both Read & Write files are open
         (cond
           ((not (setq file2read (open filespec "r")))
            (alert (strcat "Error - Can not open file - " filename))
           )
           ((not (setq file2write (open (strcat filepath outfile) "w")))
            (alert (strcat "Error - Can not open file - " outfile))
           )
           (t ; all is OK if you are here
           )
         )


          ;;
          ;;   Process the File
          ;;
          (progn
            (setq lncnt 0
                  stcnt 0
                  ignoreon nil ; deal with Block Comments
            )
            ;;  Block Comments - does not support more than one pair
            ;;  in a single line
           
            (while (setq str (read-line file2read))
              (setq lncnt (1+ lncnt))
              (cond
                ;;  Check for block comments first
                ((and honorblocks ignoreon (setq pos (vl-string-search "|;" str)))
                 (setq ignoreon nil)
                 (if (and (setq pos2 (vl-string-search ";|" str))
                          (> pos2 pos)
                     )
                   (setq ignoreon t)
                 )
                )
                ((and honorblocks (setq pos (vl-string-search ";|" str)))
                 (setq ignoreon t)
                 (if (and (setq pos2 (vl-string-search "|;" str))
                          (< pos2 pos)
                     )
                   (setq ignoreon nil)
                 )
                )
                (ignoreon ; t = skip comment block
                 )
                ;;  Check for target string
                ((vl-remove nil
                   (mapcar '(lambda (x) (vl-string-search x str)) strippat)
                 )

                 (setq stflag nil)
                 (foreach sp strippat
                   ;;  ignore special case where target is "; " & this is found ";; "
                   (if (and (setq pos (vl-string-search sp str))
                            (or (/= sp "; ")
                                (and (= sp "; ")
                                     (or (zerop pos)
                                         (/= (substr str pos 1) ";")))))

                     (progn
                      (if (and (setq pos (vl-string-search sp str 0))
                               (setq pos2 (vl-string-search "\"" str 0))
                          )
                         (setq pos (StrSearch sp str))
                      )

                      (if pos ; nil if ; is within a quote
                        (progn
                          (setq str   (substr str 1 pos)
                                stflag t
                          )
                          (if (and DelLine (= (vl-string-trim "" str) ""))
                            (setq skip t)
                          )
                        )
                      )
                     )
                   )
                 )
                 (if stflag (setq stcnt (1+ stcnt)))
                )
                ;;  fall through if nothing to change
              )
              (if skip
                (setq skip nil)
                (write-line str file2write)
              )
            )
            (close file2read)
            (if (close file2write)
              (prompt (strcat "\n***  Error creating file " outfile "  ***"))
              (progn
                (prompt (strcat "\n***  New created. " outfile "  ***"
                                "\nLines examined " (itoa lncnt)
                                ". Lines stripped " (itoa stcnt) "."))
                ;;  debug - view new file in NotePad
                ;;  remove the ;; in the next line to start NotePad
                (startapp "notepad.exe" (strcat filepath outfile))
              )
            )
            (setq file2read nil
                  file2write
                   nil
            )
          )
          ;;  Else close file if they were opened
          (progn
            (and file2read (close file2read))
            (and file2write (close file2write))
          )
       )

     ) ; progn ----------------------------------
  )

  (princ)
)

(prompt "\nStrip_Comments.lsp loaded, Enter strip_comments to run.")
(princ)
;; EOF


;;;=======================[ StrSearch.lsp ]=======================
;;; Author: Copyright© 2006 Charles Alan Butler
;;; Version:  1.0 Oct. 20, 2006
;;; Purpose:
;;; This is a vl-string-search that will ignore characters
;;; found within quoted text, i.e. search unquoted text only
;;; return the position (base 0) of the target string
;;;  within the search string, honor quoted text
;;; 
;;; Requirements: -tar = String to search for
;;;               -str = String to search in
;;; Returns: -the position number, base 0, or nil
;;;==============================================================
;;;
;;;  Example: (setq str "\"yy;_\" ;_ real comment"
;;;           (setq pos (chk ";_" str)) ; returns 7
;;;           (substr str (1+ pos)) ; returns ";_ real comment"
;;;
(defun StrSearch (tar str / tlen q1 q2 qx idx idx2 sc loop rtn)

  (setq tlen (strlen tar)
        idx 0
        idx2 0
  )
  ;; NOTE loop is a dummy var so the value is returned from the cond

  ;;******************************************
  ;;  no quotes found, this should not happen
  ;;  added here as a fail safe
  ;;******************************************
  (if (null (vl-string-search "\"" str 0))
    (setq rtn (vl-string-search tar str 0)) ; return the position if it exist
  (while
    (cond
      ;;======================================
      ;;  find the opening quote, ignore \\\"

      ((and (null q1) (setq q1 (vl-string-search "\"" str idx)))
       (if (and (setq qx (vl-string-search "\\\"" str idx))
                (= (1- q1) qx)
           )
         (setq idx (1+ q1)
               q1  nil
               qx  nil
         )
         (setq idx (1+ q1))
       )
       
       t
      )

      ;;======================================
      ;;  find the closing quote for the open
      ;;   quote we have, ignore \\\"         
      ((and q1 (null q2)(setq q2 (vl-string-search "\"" str idx)))
       (if (and (setq qx (vl-string-search "\\\"" str idx))
                (= (1- q2) qx)
           )
         (setq idx (1+ q2)
               q2  nil
         )
       )
       t
      )

      ;;=====================================
      ((setq sc (vl-string-search tar str idx2))
       (cond
         ;; simicolon is within quotes
         ((< q1 sc q2)
           (setq idx2 (+ sc tlen) ; ignore it
                 sc   nil
           )
           t ; stay in loop
         )
         ;;  quote is in a comment
         ((or (and (null q1) (null q2))
              (and (null q2) (< sc q1))
              )
           (setq rtn  sc)  ; value to return
            nil ; exit the loop
         )
         ;; simicolon is out side of this quote pair
         ((> sc q2)
          (if (> sc (vl-string-search "\"" str (1+ q2)))
            ;; set up to look for another quote
            (setq idx  (1+ q2)
                  q1   nil
                  q2   nil
                  loop t
            )
            (setq rtn  sc  ; value to return
                  loop nil ; exit the loop
            )
          )
         )
         ;; quote is in the comment
         ((< sc q1)
            (setq rtn  sc)  ; value to return
            nil             ; exit the loop
          )
         
       ) ; end cond stmt
      )
      ;;====================================
    ) ; end cond stmt
  )  ; end while
    )

  rtn
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ScottBolton

  • Guest
Re: Maximum length of a line of code
« Reply #4 on: March 12, 2013, 08:25:18 AM »
Thanks, CAB. Look good.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Maximum length of a line of code
« Reply #5 on: March 12, 2013, 08:35:04 AM »
Or search for something called Kelvinator. It removes most blank space, all comments and changes all symbol names (except standard ones) to some "garbled" name. I.e. it obfuscates your code to make it less readable. You might need to add standard defun / constant names to its DEF file so it doesn't obfuscate those too.

But that's not too difficult to circumvent: A simple re-format would undo most of the blank space / new-line removal. The name obfuscation is harder to compensate for though.

Then you might also try to use an old utility called Encrypt, though there was also a Decrypt available which made it rather useless.

Or if you "really" want to stop others from being able to read your code - then use VLisp's vl-compile function to change your LSP file(s) into FAS files(s). Or even compile to VLX files - allows you to add even other types of files into one (e.g. the DCL together with your LSP).

Or there's also some guy who made a AutoLisp-to-C++ converter so you could then compile your LSP into ARX files. But I think that might be overkill.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ScottBolton

  • Guest
Re: Maximum length of a line of code
« Reply #6 on: March 12, 2013, 09:12:29 AM »
I'd already planned changing variable names by reading what comes after the (defun / statement.

My non-work-written code is always compiled to FAS or VLX but I'd heard that there are decompilers even for these. Not knowing what the decompiled code looks like I'd wanted to chuck in the lack of comments and dodgy variable names to mess it up some.

Groetjes!

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Maximum length of a line of code
« Reply #7 on: March 12, 2013, 09:25:13 AM »
There are decompilers for FAS and VLX ... I have them and have had to use them to recover code. They aren't well developed and they leave quite a job for reconstructing the code, but there is enough to make it worthwhile to use. However, unless you have some super lisp program that is cutting edge, I don't think the average user is going to try and decompile it because most of the time, it is simply easier to rewrite the thing.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Maximum length of a line of code
« Reply #8 on: March 12, 2013, 10:06:17 AM »
I agree, the FAS/VLX decompilers won't give you too much of the original source code. I think (as I understand it) the FAS/VLX already has all comments removed and names changed to codes instead - so you won't get any extras by changing the names manually. Though in general, such a FAS/VLX is more difficult to decompile than a DotNet DLL is: http://through-the-interface.typepad.com/through_the_interface/2007/01/protecting_inte.html

As I've said, you might be able to convert the AutoLisp code into ObjctARX c++ code and then compile that into ARX files. But then you'll need to (at least) compile for each major release of ACad. And you'll require a non-free version of Visual Studio to do so.

Anyhow, even a C++ compiled binary file is not a fool proof way of stopping disassembly. I've seen those things on the web as well as password breakers for VBA DVB files.

I don't think you can stop everyone from cracking your code - you can only make it more difficult. And even if you make it the most difficult thing in the world, all that's needed is one single guy to finally break it - and I'll bet you he'll share the means and/or your code on the net  - which then means your code is not even slightly protected anymore. It's the exact same principle which makes DRM absolutely useless against any form of piracy, many huge companies have spent billions on making the absolute state-of-the-art DRM system only to find that within a day or two some cracker has broken it and shared the cracking code on the net for everyone to use.

So I don't think you've got the same time and or money to waste on trying to "protect" your code in a futile attempt to stop those crackers from breaking into it. I'd say, go with something which takes the least extra time / effort on your part. Personally I prefer FAS/VLX as it also makes your code run faster without giving any issues for legitimate customers. If they're going to break into it, they're going to do so anyway - even if you add some 512 bit encryption with a forced per user password for every single command they try to use. It will be impossible to stop, don't waste your time on it.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Maximum length of a line of code
« Reply #9 on: March 12, 2013, 10:10:15 AM »
^agreed!

VLX / FAS will stop the casual user, but not those determined to reverse engineer it.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie