mIRC Home    About    Download    Register    News    Help

Print Thread
#185863 15/09/07 11:24 AM
W
WideOpenSpace
WideOpenSpace
W
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]

?

#185866 15/09/07 12:09 PM
R
RusselB
RusselB
R
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.

#185870 15/09/07 01:11 PM
W
WideOpenSpace
WideOpenSpace
W
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

#185875 15/09/07 02:15 PM
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
W
WideOpenSpace
WideOpenSpace
W
i get this:

Invalid format: $addtok

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

#185890 15/09/07 04:52 PM
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
W
WideOpenSpace
WideOpenSpace
W
ah
this works so great laugh

thank you smile


Link Copied to Clipboard