#!../bin/seerc -r
/*
       -= SEER - C-Scripting engine v 0.94a =-
State      : under implementation
Author     : Przemyslaw Podsiadly
             email: ppodsiad@elka.pw.edu.pl
             WWW:   http://home.elka.pw.edu.pl/~ppodsiad/seer
File:exstdlib.sc
Desc:example of stdlib header: classes string
     this file we can also run with seerc :
          seerc -r exstdlib.sc Either play2me or 4me4everbe4me
     or in UNIX you can call it as a script:
          chmod +x exstdlib.sc
          ./exstdlib.sc
*/

#title "ExStdlib"
#author "Przemyslaw Podsiadly 1999"

//here is the header we want
#include stdlib

//here we tell, the master program can call function main
export main;

//here we tell, that we use external function printf...
import int printf(char *,...);

//main function (declared same as normal one)
int main(int argc,char **argv)
{
 int i=0;
//******************** the class string ***************************
 for (i=0;i<argc;i++)
 {
  string o=argv[i];
  //now we can change string o without changing argv[i] !
  //o contains copy of argv[i];

  //we can normally add strings
  //and pass them to functions as char* (without a cast)
  printf("%s\n",o+" is the argument "+string(i));

  //we can normally compare them
  if (o=="Enjoy!!!")
  {
    printf("----=====Enjoy SeeR v.%4.2f !=====------\n",SeeR/100.0);
    return 0;
  }

  //we can search in them
  //find returns the index of found substring, or -1 if not found
  if (o.find(string(i))!=-1)
  {
    printf("+ contains its number\n");

  //we can replace some parts of them
  //replace only the first occurance
    o.replace(string(i),string("<the number>"));
    printf("+ replace 1st with <the number> = %s\n",o);
  //replace all occurances (3rd parameter is true)
    o.replace(string(i),string("<again>"),true);
    printf("+ replace remaining with <again> = %s\n",o);
  }

  //we can get its length:
  if (o.length()>3)
  {

  //we can get the substring
    printf("+ substring(start=1, length=3) = %s\n",o(1,3));//equal:o.sub(1,3)

  //we can delete the substring (same as above)
    o.del(1,3);
    printf("+ delete(start=1, length=3) = %s\n",o);

  //we can insert string - starting at 1
    o.insert(1,string("???"));
    printf("+ insert(start=1, '???') = %s\n",o);
  }

  //we can also append strings to it
  o+=" (!)";
  printf("+ append(' (!)') = %s\n",o);

 }
// printf("Try also argument :\n Either play2me or 4me4everbe4me\n");
 return 0;
}

