Thank you Devon, it's quite useful as a start. I'll modify it a bit and
write the WriteIniString.
Gerald
On 4/8/06, Devon McCormick <[EMAIL PROTECTED]> wrote:
>
> I don't have exactly what you're looking for but this could be a start:
>
> NB.* parseIniFile: return 2-column mat (0: section name; 1: name/value
> pairs)
> NB. given INI file name.
> parseIniFile=: 3 : 0
> inifl=. f2v y.
> whbrkt=. -._1 e.&>,&.>(<'^\[.*\]') rxmatch&.>dlb&.>inifl
> nvp=. elimEmptyRows&.>nvPair&>&.>whbrkt<;._1 inifl
> ((}.@:}:@:dlb@:dtb)&.>whbrkt#inifl),.nvp
> NB.EG inifl=. f2v WINDIR,'cdPlayer.ini'
> )
>
> NB.* nvPair: Name=Value pair from string of form 'Name=Value'.
> nvPair=: 13 : '0 1}.&.>(y.i.''='')({.;}.)y.'
>
> NB.* elimEmptyRows: eliminate rows of boxed mat if all items empty.
> elimEmptyRows=: 13 : 'y.#~0+./ . ~:|:#&>y.'
>
> This requires 'regex' and the standard deblanking utilities "dlb" and
> "dtb",
> as
> well as these 2 utilities (which I think have standard J-equivalents but I
> haven't
> looked them up):
> f2v=: 3 : 0
> NB.* f2v: File to Vector: read file -> vector of lines.
> vec=. l2v 1!:1 <y.
> )
>
> l2v=: 3 : 0
> NB.* l2v: Lines to Vec: convert lines terminated by LF to vector elements.
> vec=. y.
> if. 0~:#y. do.
> vec=. vec-.CR NB. Use only single-char for line
> delimiter
> vec=. vec,(LF~:{:vec)#LF NB. Ensure terminal line delimiter
> whq=. ~:/\'"'=vec NB. Mask interiors of quoted strings
> ptn=. LF=vec NB. Partition lines but
> ptn=. ptn*.-.whq*.ptn NB. exclude quoted end-of-lines
> vec=. ptn <;._2 vec NB. Make into vector of lines
> end.
> vec
> )
>
> So, for example:
>
> $ii=. parseIniFile WINDIR,'cdPlayer.ini'
> 42 2
> 2{.ii
> +--------------+--------------------+
> |OptionSettings|+-------+-----+ |
> | ||Animate|False| |
> | |+-------+-----+ |
> | ||OnTop |False| |
> | |+-------+-----+ |
> | ||Float |False| |
> | |+-------+-----+ |
> | ||Repeat |False| |
> | |+-------+-----+ |
> +--------------+--------------------+
> |742fba5c |+---------+--------+|
> | ||EntryType|1 ||
> | |+---------+--------+|
> | ||artist |Artist ||
> | |+---------+--------+|
> | ||title |Album ||
> | |+---------+--------+|
> | ||genre | ||
> | |+---------+--------+|
> | ||numtracks|2 ||
> | |+---------+--------+|
> | ||0 |Track 01||
> | |+---------+--------+|
> | ||1 |Track 02||
> | |+---------+--------+|
> +--------------+--------------------+
>
> On 4/8/06, Gerald Mylog <[EMAIL PROTECTED]> wrote:
> >
> > Is there somewhere in the "J code corpus" utilities for reading and
> > writing
> > INI-files that either comply with the "classical" text file format or
> with
> > the nowadays recommended XML-format?
> >
> > It's not really important how data is stored as long as it's portable
> (not
> > using the WIN API, the WIN registry or any database)
> >
> > Simulation from a J session:
> >
> ...
> --
> Devon McCormick
> ^me^ at acm.
> org is my
> preferred e-mail
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm