Author Topic: code + data in one file ...possibilities...  (Read 2242 times)

0 Members and 1 Guest are viewing this topic.

SOFITO_SOFT

  • Guest
code + data in one file ...possibilities...
« on: June 16, 2011, 09:29:08 AM »
This is a program for storing code and data in one file and enable others programs to modify the data  ....

; >>>>>>>>>> helper program to read the main program, very useful during debugging >>>>>>
Code: [Select]
(defun c:ll (/)
  (vl-load-com)
  (setq acadDocument (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq mSpace (vla-get-ModelSpace acadDocument))
  (or doc
      (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq space mspace )
  (setvar "REMEMBERFOLDERS" 1)
  (setq arma_3d_path "h:\\AA_SOFITO\\")                         <<<<<< atention !!!!! 
  (load (strcat arma_3d_path "LEER-LSP.LSP"))     
  ( C:LEER-LSP ) 
)
; <<<<<<<<<<<< end of helper program to read the main program
; >>>>>>>>>> main program >>>>>>
Code: [Select]
( DEFUN C:LEER-LSP ( /   vari valor lec file lista-vari-valo arma_3d_path sent )
( setq arma_3d_path "h:\\AA_SOFITO\\")                                                ;  <<<<<< atention !!!!!
( setq lista-vari-valo '() )
( SETQ FILE ( OPEN (strcat arma_3d_path "LEER-LSP.LSP" ) "R" ) )
( WHILE ( SETQ LEC ( READ-LINE FILE ) ) 
  ( if ( = ( strcase lec ) "DATA" ) 
    ( progn
           ( SETQ LEC ( READ-LINE FILE ) )
           ( setq vari lec )   
           ( SETQ LEC ( READ-LINE FILE ) )
           ( setq valor lec ) 
           ( set ( read vari ) valor )                                                 ;<<<<< 1RT TRUCK !!!   
           ( prompt ( strcat "\nTHE VARIABLE \"" VARI "\" IS NOW \"" VALOR "\"  ." ) )
           ( getint "\nPulse para seguir..." )
           ( setq lista-vari-valo  ( cons ( cons vari ( eval ( read vari ) ) ) lista-vari-valo  ) )
    )
  )
 ( if ( = ( strcase lec ) "DATA-EVAL" ) 
    ( progn
           ( SETQ sent ( READ-LINE FILE ) )               
           ( EVAL ( read sent ) )                                                  ;<<<<<   2ND  TRUCK !!!   
           ( prompt ( strcat "\nSENTENCE ALSO HAS BEEN EVALUATED \"" SENT "\""  ) )
           ( getint "\nINTRO TO CONTINUE..." )           
    )
  )
)
( CLOSE FILE )
; Verificating
( prompt  "\nLIST VARIABLES AND VALUES IN LIST OF DOTED PAIR ..." )
( foreach n lista-vari-valo
  ( print n )
)
( princ )
)
;|   
data
Paco
Suarez
data-eval
( setq tolo ( / 1 pi ) )
data-eval
( setq pipo ( strcat "Manuel" " " "Santana" ) )
data-eval
( setq pipa ( rem 1.2345 0.54 ) )
data-eval
( setq pipa2 ( * pipa 1000. ) )
|;
; <<<< end main program + data

Verificating variables and values....

Command:
Command: !paco
"Suarez"
Command: !tolo
0.31831
Command: !pipa
0.1545
Command: !pipa2
154.5


Greetings from Madrid...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: code + data in one file ...possibilities...
« Reply #1 on: June 16, 2011, 09:48:00 AM »
I put ini type data in lisp files (book ended with ;| |;) then read it via doslib's dos_getini function (could roll my own but why bother when Dale has done such a good job); works very well for my needs.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SOFITO_SOFT

  • Guest
Re: code + data in one file ...possibilities...
« Reply #2 on: June 16, 2011, 11:53:40 AM »
Hello:
I also use "DOS_getini" using ".LSPs" as ". INIS" ... It was just someone who needed to put more data in LSP without complications ....
Congratulations to you brother Dale....  Magnificent library  DOSLib ... .
Regards

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: code + data in one file ...possibilities...
« Reply #3 on: June 16, 2011, 12:01:46 PM »
For those interested ... make sure you create a section that serves only to "cap" the last "real" section, lest last section searches produce bogus key/data pairs.

In this example the [end] section caps [section3]. Use of the word "end' is arbitrary to dos_getini, just what I use.

;|
[section1]
key1=value1
key2=value2
key3=value3

[section2]
key1=value1
key2=value2
key3=value3

[section3]
key1=value1
key2=value2
key3=value3

[end]
|;


Hope that makes sense to you.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: code + data in one file ...possibilities...
« Reply #4 on: June 16, 2011, 07:45:52 PM »
Warning; No where near on topic:
What a great idea. ...After a good hour of solid coding (std C++), ive got the first level of the above ini example parsed. Now i just need to figure out the sections and how they can fit in my model. humm...

BTW, thank you for the distraction; i needed it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: code + data in one file ...possibilities...
« Reply #5 on: June 17, 2011, 03:38:07 AM »
why not store data as a list and then just read it?
;|
'(data (section1 (key1 . value1) (key2 . value2) (key3 . value3)) (section2 (key1 . value1) (key2 . value2) (key3 . value3)))
|;

SOFITO_SOFT

  • Guest
Re: code + data in one file ...possibilities...
« Reply #6 on: June 17, 2011, 05:47:52 AM »
why not store data as a list and then just read it?
;|
'(data (section1 (key1 . value1) (key2 . value2) (key3 . value3)) (section2 (key1 . value1) (key2 . value2) (key3 . value3)))
|;

The idea is that an excel spreadsheet edit ( re-writre ) the LSP with news DATAS and variables / values.
The easiest method? . I do not know.
Greetings.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: code + data in one file ...possibilities...
« Reply #7 on: June 17, 2011, 08:12:23 AM »
why not store data as a list and then just read it?
;|
'(data (section1 (key1 . value1) (key2 . value2) (key3 . value3)) (section2 (key1 . value1) (key2 . value2) (key3 . value3)))
|;


Is there a limit to the length of a line in a text file? (Just trying to think of why your idea wouldn't be viable)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: code + data in one file ...possibilities...
« Reply #8 on: June 17, 2011, 09:11:53 AM »
Can't speak for others in the thread but I needed to embed meta data into lisp files tobe read by other lisp files, that is this.lsp would be read by that.lsp. The ini method was a no brainer and easy to implement. There are numerous ways it could be emulated, including vanilla lisp solutions, but I opted for the afore mentioned technique because of its simplicity, the "readability" of the data, and a format easy for others to understand and use, i.e. others add the meta data to the lisp files. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst