Author Topic: Converting LIST to STR and backwards?  (Read 2015 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 627
Converting LIST to STR and backwards?
« on: October 25, 2013, 09:50:20 AM »
I use some LISTs which I have to save into a text-file (INI), and when I read them from INI and want to use them as LISTs..

Any ideas? Standard commands which I missed? Special routines here or in DosLIB?

Thanks and regards
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V21

Lee Mac

  • Seagull
  • Posts: 12726
  • London, England
Re: Converting LIST to STR and backwards?
« Reply #1 on: October 25, 2013, 10:01:45 AM »
Maybe this thread will help?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1343
  • Marco
Re: Converting LIST to STR and backwards?
« Reply #2 on: October 27, 2013, 02:32:55 PM »
Why not write directly in Lisp lists?
See attached.

Code: [Select]
; Function: ALE_UtlCfg_WriteData
;
; Version 1.00 - 21/06/2006
;
; Example: (ALE_UtlCfg_WriteData '#CfgData #CfgFile)
;
(defun ALE_UtlCfg_WriteData (DatNam LspOut / FilPnt TmpVal SysTim)
  (if #CfgFlag
    (progn
      (vl-file-delete (strcat LspOut ".bak"))
      (cond
        ( (vl-file-rename LspOut (strcat LspOut ".bak")) )
        ( T
          (alert
            (strcat
;|e|;         "Impossible to rename CfgData.lsp!\n\n"
;|e|;         "This is normal for first installation.\n"
            )
          )
          (vl-file-rename LspOut (strcat LspOut ".bak"))
        )
      )
      (setq FilPnt (open LspOut "w") #CfgFlag nil)
      (write-line (strcat "(setq " (vl-symbol-name DatNam) " '(") FilPnt)
      (foreach ForElm (vl-symbol-value DatNam)
        (princ "(" FilPnt) (prin1 (car ForElm) FilPnt) (princ "\n" FilPnt)
        (foreach ForEl2 (cdr ForElm)
          (if (= 'REAL (type (setq TmpVal (cdr ForEl2))))
           (progn
             (princ "  (" FilPnt) (prin1 (car ForEl2) FilPnt) (princ " . " FilPnt)
             (princ (rtos (cdr ForEl2) 2) FilPnt) (princ ")\n" FilPnt)
           )
           (progn (princ "  " FilPnt) (prin1 ForEl2 FilPnt) (princ "\n" FilPnt))
          )
        )
        (write-line ")" FilPnt)
      )
      (write-line "))" FilPnt)
      (close FilPnt)
      (while (not (setq SysTim (vl-file-systime LspOut))) (ale_fuzzy 10))
      SysTim
    )
  )
)

Peter2

  • Swamp Rat
  • Posts: 627
Re: Converting LIST to STR and backwards?
« Reply #3 on: October 27, 2013, 03:27:21 PM »
Hi Lee, hi Marc'Antonio

thanks for your codes. Both are very powerful ideas which I will save for (maybe) later use.

But it seems that my question was not precise enough; the basic consideration was:

a) I have a text-based information which is connected with a "value"
b) The first part has a defined length, the second part can be concatenated with different parts and have a different length
c) This info has to be stored in a text-file
d) After reading from the text file the info has to be parsed again (in its different parts)

Because all info is text it could be a problem to define the "delimiter" between the "parts" - , : - _ / ; are not allowed as delimiter.
So the best thing would be to save it in a list: no problems with length, no problems with delimiters, ..

pseudo-Example of the INI-file:

Code: [Select]
[Definitions]
drilling=((modus . select) (Content ("this is an [important] text") ([LOGINNAME]) ("nice weather today, really {hot}") ({attdef.blockname}))

You see, the "Content" has a user-defined, free combination of standard text and different "dynamic values" which must be managed by the software ...
But the problem is: How to store this stuff in a text file and read it as list?

In the meantime I modified my code and try with delimiters

Code: [Select]
[Drilling]
modus=select
value= {SPEISUNG.RCS_OUTPUT_v01} {MELDUNG_NR..RCS_OUTPUT_v01}

The idea is that delimiter " " (Alt+0160) and "" (Alt+0182) are strange enough that nobody would use them in a text.

But my code is not proved and not done now - if someone has a better idea than my delimiters or a solution for my list I would be happy to see it
« Last Edit: October 27, 2013, 03:33:00 PM by Peter2 »
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V21

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Converting LIST to STR and backwards?
« Reply #4 on: October 27, 2013, 04:55:07 PM »
Peter,

Could you possibly save the list in a CSV file.  Its not per say a text file, but can be viewed with notepad, excel, or any other text viewer.

That way you can separate your values with commas.....

Bruce

Peter2

  • Swamp Rat
  • Posts: 627
Re: Converting LIST to STR and backwards?
« Reply #5 on: October 27, 2013, 05:24:48 PM »
Hi Bruce

beside the "logical" disadvantages of CSV related to INI there would be a problem to save "hello, my name is John" ..
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V21

Lee Mac

  • Seagull
  • Posts: 12726
  • London, England
Re: Converting LIST to STR and backwards?
« Reply #6 on: October 27, 2013, 06:03:17 PM »
How about using an arbitrary delimiter character (such as '=') in your INI file and mark any occurrences of the delimiter character within the actual data as literals using a backslash prefix that your parsing function could then test for.

This is how a CSV file differentiates cell delimiter characters (commas / semi-colons) from such characters found within the cell content, only using quotation marks as literal indicators.

Peter2

  • Swamp Rat
  • Posts: 627
Re: Converting LIST to STR and backwards?
« Reply #7 on: October 27, 2013, 06:14:42 PM »
How about using an arbitrary delimiter character (such as '=') in your INI file and mark any occurrences of the delimiter character within the actual data as literals using a backslash prefix that your parsing function could then test for....
Hi Lee
if I understand you correctly this is similar to my delimiters mentioned above?
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V21

Lee Mac

  • Seagull
  • Posts: 12726
  • London, England
Re: Converting LIST to STR and backwards?
« Reply #8 on: October 27, 2013, 06:34:42 PM »
if I understand you correctly this is similar to my delimiters mentioned above?

As I understand it, you are suggesting the use of obscure delimiter characters, with the assumption that such characters will not appear in the content; I am suggesting using any delimiter character and marking those which appear within the content as literals.

For example, if '=' is the delimiter:
Code: [Select]
key=some\=textWould be read as:
Code: [Select]
(key . "some=text")
Then, for literal backslashes:
Code: [Select]
key=some\\textWould be read as:
Code: [Select]
(key . "some\text")(of course, this would appear as "some\\text", since the backslash is also an escape character in AutoLISP).