TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 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
-
Maybe this thread (http://bit.ly/1aJyxF5) will help?
-
Why not write directly in Lisp lists?
See attached.
; 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
)
)
)
-
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:
[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
[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
-
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
-
Hi Bruce
beside the "logical" disadvantages of CSV related to INI there would be a problem to save "hello, my name is John" ..
-
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.
-
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?
-
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:
key=some\=text
Would be read as:
(key . "some=text")
Then, for literal backslashes:
key=some\\text
Would be read as:
(key . "some\text")
(of course, this would appear as "some\\text", since the backslash is also an escape character in AutoLISP).