mIRC Home    About    Download    Register    News    Help

Print Thread
#185863 15/09/07 11:24 AM
Joined: Jun 2007
Posts: 156
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jun 2007
Posts: 156
i have this script that shows sections of ini's

Code:
alias inisec {
  ; Syntax: /inisec inifile
  if (!$isfile($1-)) .echo -a File doesn't exist. $+($chr(40),$1-,$chr(41))
  var %i = 1
  while ($ini($1-,%i) != $null) {
    .echo -a $v1
    inc %i
  }
}

;//echo -a $ini(FILE.ini,1)


so it lists

[sect1]
[sect2]
...
...

my question, what should i do so it lists them
but like this: [sect1],[sect2],[sect3]

?

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Code:
alias inisec {
  if !$isfile($$1-) .echo -a File doesn't exist. $+($chr(40),$1-,$chr(41))
  var %i = 1
  while %i <= $ini($1-,0) {
    set %ini_sec $addtok(%ini_sec,$ini($1-,%i),44)
    inc %i
  }
  echo -a %ini_sec
]

NOTE: If you have an INI file with lots of sections, and/or sections with very long names, then this code might return a Variable Too Long error.

RusselB #185870 15/09/07 01:11 PM
Joined: Jun 2007
Posts: 156
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jun 2007
Posts: 156
Originally Posted By: RusselB

NOTE: If you have an INI file with lots of sections, and/or sections with very long names, then this code might return a Variable Too Long error.


any chance to bypass that ?
coz i realy have many many sections in INI

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Well, you could use binary variables. However, you are still limited to a maximum number of characters per line that you echo.

So just stick them on multiple lines whenever you get too many...
Code:
alias inisec {
  if (!$isfile($$1-)) { .echo -a File doesn't exist. $+($chr(40),$1-,$chr(41)) }
  var %i = 1, %total = $ini($1-,0)
  while (%i <= %total) {
    var %ini_sec = $addtok(%ini_sec,$ini($1-,%i),44)
    if ($len(%ini_sec) > 900) { echo -a %ini_sec | unset %ini_sec }
    inc %i
  }
  if (%ini_sec) { echo -a %ini_sec }
}


This will display and unset the variable anytime the length of the variable goes past 900 characters. Unless you have *really* long section names, this should work fine. You can, of course, change the 900 up or down to suit your needs.

*Note: This does not show just the first 900 characters. It shows the variable once you are *past* 900 characters.

Btw, when looping, avoid putting an identifier in the while line. You'll be evaluating it every single loop and that will slow the script considerably. Especially if you're reading from a file. Instead, put the value into a variable as shown.

Last edited by Riamus2; 15/09/07 04:51 PM.
Riamus2 #185887 15/09/07 04:42 PM
Joined: Jun 2007
Posts: 156
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jun 2007
Posts: 156
i get this:

Invalid format: $addtok

for line:
var %ini_sec $addtok(%ini_sec,$ini($1-,%i),44)

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
I edited it. Try now.

Riamus2 #185892 15/09/07 05:01 PM
Joined: Jun 2007
Posts: 156
W
Vogon poet
OP Offline
Vogon poet
W
Joined: Jun 2007
Posts: 156
ah
this works so great laugh

thank you smile


Link Copied to Clipboard