/selectcase statement

By zonirc on Nov 09, 2008

This alias have been make due to the lack of select case statement in mIRC(actually theres another way to accomplish it). However it still not perfect, so if you guys had found any bugs/error please inform me so that I can update it and in sametime I can learn more :)

Installing

Copy the code and paste it into your remote section of mIRC editor.

Ok guys, hope youre enjoy use this thing.

;###SNIPPET INFORMATION###
; Name: /selectcase
; Author: zonIRC
; Version: 2
; mIRC Version: 6.35
; Contact: zonirc@email.com
;          #klkite (network: undernet)
;          zonirc (yahoo messenger)
; Tested: mIRC 6.35+Windows XP Home
;
;
; Description:
; A select case statement to use in mIRC.
;
; Syntax:
; /selectcase "case" Linenum File
; case "caseExpression"
; command
; case ""
; command
; /selectcase end
;
; "case" : the caseExpression that gonna be trigger. It must be quote
; Linenum : the line number of the header('/selectcase ...')
; File : the filename(and it doesnt need to be load)
; command : any valid mIRC command
; the caseExpression can be more than one
; the case ""(also can be called as 'case else') is optional just like if-then-else statement
; /selectcase end : the footer which is a mandatory and must be at the last line of the statement
;
;Example:
;ON *:START:{
;  selectcase $qt($version) $scriptline $script
;  /*
;  case "6.35"
;  echo -a Great $me $+ , you have a newer version
;  case "6.34"
;  echo -a This version is ok for me
;  case ""
;  echo -a Please upgrade $me
;  selectcase end
;  */
;}
; The above example would echoing a different message according to yours mIRC version.
; You can see that the line after the header have been put inside a comment to prevent mIRC from evaluate it.
; By use it like this, the code can be put inside a loaded script.
; The older comment line(e.g: ';') have been supported which means script would recognized it as a comment line.
;
;ON *:CONNECT:{
;  selectcase $qt($network) $scriptline $script
;  /*
;  case "undernet"
;  msg x@channels.undernet.org login yourUsername yourPassword
;  join #undernetChan
;  case "kampungchat"
;  msg nickserv identify yourPassword
;  join #kampungchatChan
;  case ""
;  join #beginner
;  selectcase end
;  */
;}
;The above example would identify and join a channel based on a network that you are connected.
;
;The Limitation:
; Unfortunately, the other statement such as if-then-else, while loops and etc. are not supported
;
; Distribution:
; You are allowed to re-distribute it into any form(such as website, magazine, etc) that you wish.
; Please leave the snippet information section as it is.
; You are allowed to edit the code but need to inform the user about that.
; 
; Version:
; First version
;----------------
; Have been submit at mirc.net(but still in virus queue)
; Unfortunately I had not make any copy of that file so this is a complete rewrite(based on my memory :P)
;###END OF INFORMATION###

alias selectcase {
  ;/selectcase "case" Linenum File
  var %echo echo -ftsc info * /selectcase:, %fn sc $+ $ticks, %case $1
  if (!$isfile($3-)) %echo $iif($3,no such file,insufficient parameter)
  else {
    ;open the file for reading
    .fopen %fn $qt($3-)
    ;start read from the specified line
    .fseek -l %fn $2
    var %read $fread(%fn), %fz $file($3-).size, %fp $fopen(%fn).pos, %iscase 0
    ;binary read from current position to the end of file
    ;this is needed to check the footer are specified
    bread $qt($3-) %fp $calc(%fz - %fp) &read
    if (!$regex(%read,/^\s*selectcase\s/i)) %echo invalid header( $+ %read $+ )
    elseif (!$bfind(&read, 1, selectcase end)) %echo no such footer
    else {
      ;started a loop to read each line
      while (!$feof) {
        var %read $fread(%fn)
        if (!$regex(%read,/^\s*;/)) {
          if (!%iscase) && ($regex(%read,/^\s*case $iif(%case,$v1,"") $+ \s*$/i)) var %iscase 1
          elseif (%iscase) {
            if ($regex(%read,/^\s*(selectcase end|case)(\s*.*)$/i)) break
            else $(%read,2)
          }
        }
      }
    }

  }
  ;this is to make sure the file being closed
  :error {
    if ($fopen(%fn)) .fclose %fn
  }
}

Comments

Sign in to comment.
zonirc   -  Nov 09, 2008

thanx Thelmrac, hopes it would be useful to others. Im have updated the documentation and added another example to show the idea for using it.

 Respond  
TheImrac   -  Nov 09, 2008

Interesting concept, looks pretty cool, I'll have to test it later.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.