ICI: A C-look alike script language with OO features

[top]

  1. Object oriented script language but looks like C.
  2. Example: Cross referencer

    #!/usr/local/bin/ici
    # tiny cross referencer written in ICI
    
    static xref = [struct];
    static linno = 0;
    
    static strupper(s)
    {
      auto i;
      s = explode(s);
      for (i = nels(s) - 1; i >= 0; --i) {
        auto c;
        c = s[i];
        if ($toint("a") <= c && c <= $toint("z"))
          s[i] = c + $toint("A") - $toint("a");
      }
      s = implode(s);
      return s;
    }
    
    static cmp(a, b)
    {
      if (a == b)
        return 0;
      if (a < b)
        return -1;
      return 1;
    }
    
    # pass 1
    static doscan(fp)
    {
      auto lin;
      auto ids;
      auto pat = regexp("([A-Za-z_][A-Za-z_0-9]*)(.*)$");
      while (lin = getline(fp)) {
        ++linno;
        while (ids = (lin ~~~ pat)) {
          auto id;
          id = ids[0];
          if (!fetch(xref, id))
    	xref[id] = array(linno);
          else {
    	if (xref[id][nels(xref[id]) - 1] != linno)
    	  push(xref[id], linno);
          }
          lin = ids[1];
        }
      }
    }
    
    if (argc == 1)
      doscan(stdin);
    else {
      auto fn;
      forall (fn in interval(argv, 1)) {
        auto fp;
        try
          fp = fopen(fn);
        onerror {
          fprintf(stderr, "can't open %s\n", fn);
          continue;
        }
        doscan(fp);
        close(fp);
      }
    }
    static w, ks, lno;
    ks = keys(xref);
    sort(ks, [func (a, b) {
    	    auto la;
    	    auto lb;
    	    auto r;
    	    la = strupper(a);
    	    lb = strupper(b);
    	    r = cmp(la, lb);
    	    return r == 0 ? cmp(a, b) : r;
    	  }]);
    forall(w in ks) {
      printf("%9s:", w);
      forall(lno in xref[w]) {
        printf("%3d", lno);
      }
      printf("\n");
    }
    

[top]