#75987 - 2003-07-18 07:25 PM
ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Trying to get this to work.. Any comments, ideas, etc. are welcome.
It works, but does not "return" anything in it's current state:
code:
CLS BREAK ON ;ENUMINI $fl=@scriptdir+'\test.ini' $rc=ENUMINI($fl) $rc sleep 2 FUNCTION ENUMINI($fl) DIM $fl,$line,$section,$key,$r IF EXIST($fl) $rc=Open(1,$fl) $line=ReadLine(1) WHILE @error=0 IF LEFT($line,1)=';' ;IGNORE COMMENTS ENDIF IF LEFT($line,1)='[' $section=substr($line,2,len($line)-2) ENDIF IF NOT INSTR($line,'[') $key=SPLIT($line,'=')[0] ENDIF IF $section<>'' AND $key<>'' ;Be sure both of these are populated ;sections and keys are done, let's do the READPROFILESTRING $r=READPROFILESTRING($fl,$section,$key) ENDIF $line=ReadLine(1) LOOP close(1) ENDIF ENDFUNCTION
TEST.INI is - code:
[DOMAIN1\PDX] ;H='\\SERVER7\'+@userid+'$$' R=\\SERVER5\APPS S=\\SERVER6\SHARED
[DOMAIN2\PDX] H='\\SERVER7\'+@userid+'$$' R=\\SERVER5\APPS S=\\SERVER6\SHARED
[DOMAIN1\Info_Technology] G=\\SERVER7\IS
Thanks,
Kent
|
|
Top
|
|
|
|
#75989 - 2003-07-18 07:40 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
The purpose being is to generate the $section and $key by reading through the INI file without knowing these values. In other words, "automating" this process.
So...
What the intent was to -
- Read the lines..
- Determine if it is commented, header, key, etc.
- Once all parameters are found for READPROFILESTRING, it would do just that.
If there is a better way to do this, I am open to suggestions. Thanks, Kent [ 18. July 2003, 19:41: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#75991 - 2003-07-18 07:51 PM
Re: ENUMINI() - Trying to create a new UDF
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
You mean this:code:
$sections=split(readprofilestring($fl,'',''),chr(10) for each $sectionentry in $sections ? 'Section = '+$sectionentry $keys=split(readprofilestring($fl,$sectionentry,''),chr(10) for each $sectionkey in $keys ? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"' next next
See the KiXtart Manual, too.
And throw in an EXECUTE statement to convert the macros. [ 18. July 2003, 19:55: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#75993 - 2003-07-18 08:26 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jens,
Works great with a couple of mods.
code:
$sections=split(readprofilestring($fl,'',''),chr(10)) FOR EACH $sectionentry IN $sections IF $sectionentry <>'' ?'Section '+$sectionentry $keys=split(readprofilestring($fl,$sectionentry,''),chr(10)) FOR EACH $sectionkey IN $keys IF $sectionkey <>'' ? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"' ENDIF NEXT ENDIF NEXT
Thanks,
Kent
|
|
Top
|
|
|
|
#75994 - 2003-07-18 08:57 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok..
Seems to work ok, but...
Here is the changed code -
code:
CLS BREAK ON ;ENUMINI $fl=@scriptdir+'\test.ini' ENUMINI($fl) FUNCTION ENUMINI($fl) $sections=split(readprofilestring($fl,'',''),chr(10)) FOR EACH $sectionentry IN $sections IF $sectionentry <>'' ?'Section '+$sectionentry $keys=split(readprofilestring($fl,$sectionentry,''),chr(10)) FOR EACH $sectionkey IN $keys IF $sectionkey <>'' ? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"' $resource=readprofilestring($fl,$sectionentry,$sectionkey) IF INGROUP($sectionentry) USE $sectionkey+':' $resource ENDIF ENDIF NEXT ENDIF NEXT ENDFUNCTION
The problem is that if I want to map the drive using a $ share (personal drive), it is not picked up. I have used single $, double $$, and chr(36) and these do not work..
Here is the modified INI file -
code:
[DOMAIN1\PDX] H=\\SERVER7\@userid+'$$' R=\\SERVER5\APPS S=\\SERVER6\SHARED [DOMAIN2\PDX] H=\\SERVER7\@userid+'$$' R=\\SERVER5\APPS S=\\SERVER6\SHARED [DOMAIN1\Info_Technology] G=\\SERVER7\IS
Thanks,
Kent
|
|
Top
|
|
|
|
#75996 - 2003-07-18 09:00 PM
Re: ENUMINI() - Trying to create a new UDF
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You need to "execute" the string to get the "$" appended.
|
|
Top
|
|
|
|
#75997 - 2003-07-18 10:02 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
OK.. I am feeling a little slow as I have not used the EXECUTE() before.
Here is the code at this point -
code:
CLS BREAK ON $fl=@scriptdir+'\test.ini' ENUMINI($fl) FUNCTION ENUMINI($fl) $sections=split(readprofilestring($fl,'',''),chr(10)) FOR EACH $sectionentry IN $sections IF $sectionentry <>'' ?'Section '+$sectionentry $keys=split(readprofilestring($fl,$sectionentry,''),chr(10)) FOR EACH $sectionkey IN $keys IF $sectionkey <>'' ? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"' $resource=readprofilestring($fl,$sectionentry,$sectionkey) IF INSTR($resource,'$') $server=SPLIT($resource,'\')[2] $nul=Execute('$$resource = '+@userid+'$$') ;$nul=Execute('$$resource = '+@USERID+'$$') ;?$$resource IF INGROUP($sectionentry) ;USE $sectionkey+':' '\\'+$server+'\'+$$resource+'$$' USE $sectionkey+':' '\\'+$server+'\'+@userid+'$$' ENDIF ELSE IF INGROUP($sectionentry) USE $sectionkey+':' $resource ENDIF ENDIF ENDIF NEXT ENDIF NEXT ENDFUNCTION
I am sure that this can be improved upon.
Thanks,
Kent
|
|
Top
|
|
|
|
#75999 - 2003-07-18 10:12 PM
Re: ENUMINI() - Trying to create a new UDF
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
What does this give you:
code:
CLS BREAK ON $fl=@scriptdir+'\test.ini' ENUMINI($fl) FUNCTION ENUMINI($fl) $sections=split(readprofilestring($fl,'',''),chr(10)) FOR EACH $sectionentry IN $sections IF $sectionentry <>'' ?'Section '+$sectionentry $keys=split(readprofilestring($fl,$sectionentry,''),chr(10)) FOR EACH $sectionkey IN $keys IF $sectionkey <>'' ? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"' $resource=readprofilestring($fl,$sectionentry,$sectionkey) $rc=execute("$$resource="+$resource) IF INGROUP($sectionentry) USE $sectionkey+':' $resource ENDIF ELSE IF INGROUP($sectionentry) USE $sectionkey+':' $resource ENDIF ENDIF ENDIF NEXT ENDIF NEXT ENDFUNCTION
|
|
Top
|
|
|
|
#76003 - 2003-07-18 11:15 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Howard,
Here are the results - quote:
Key "H" = "\\SERVER7\@userid+'$$'"KDyer$
Jens -
code:
H="'\\SERVER7\'+@userid+'$'"
Works fine with NoVarsInStrings.
Thanks,
Kent
|
|
Top
|
|
|
|
#76004 - 2003-07-18 11:28 PM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jens,
This appears to work too -
With NoVarsInStrings:
code:
H=\\SERVER7\+@userid+'$'
Without NoVarsInStrings:
code:
H=\\SERVER7\+@userid+'$$'
Thanks,
Kent
|
|
Top
|
|
|
|
#76005 - 2003-07-19 08:46 AM
Re: ENUMINI() - Trying to create a new UDF
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Two other variations - DELPROFILESTRING.. I think there is a version of this using WRITEPROFILESTRING in PostPrep.
Kent
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 895 anonymous users online.
|
|
|