Example #1
0
url
operator | (url u1, url u2) {
  if (is_none (u1)) return u2;
  if (is_none (u2)) return u1;
  if (is_or (u1)) return u1[1] | (u1[2] | u2);
  if (u1 == u2) return u2;
  if (is_or (u2) && (u1 == u2[1])) return u2;
  return as_url (tuple ("or", u1->t, u2->t));
}
Example #2
0
url
glue (url u, string s) {
  if (is_atomic (u)) return as_url (tree (u->t->label * s));
  if (is_concat (u)) return u[1] * glue (u[2], s);
  if (is_or (u)) return glue (u[1], s) | glue (u[2], s);
  failed_error << "u= " << u << "\n";
  failed_error << "s= " << s << "\n";
  FAILED ("can't glue string to url");
  return u;
}
Example #3
0
url
unglue (url u, int nr) {
  if (is_atomic (u))
    return as_url (tree (u->t->label (0, max (N(u->t->label) - nr, 0))));
  if (is_concat (u)) return u[1] * unglue (u[2], nr);
  if (is_or (u)) return unglue (u[1], nr) | unglue (u[2], nr);
  failed_error << "u = " << u << "\n";
  failed_error << "nr= " << nr << "\n";
  FAILED ("can't unglue from url");
  return u;
}
Example #4
0
static url
url_get_atom (string s, int type) {
  if (type < URL_STANDARD) {
    if (s == "~") return url_system (get_env ("HOME"));
    if (starts (s, "$")) {
      string val= get_env (s (1, N(s)));
      if (val == "") return url_none ();
      return unblank (url_system (val));
    }
  }
  if (occurs ("*", s)) return url_wildcard (s);
#ifdef WINPATHS
  if(N(s)==2 && ends (s, ":")) s->resize(1);	// remove the ':' after unit letter
#endif
  return as_url (tree (s));
}
Example #5
0
static url
get_cache (url name) {
    if (web_cache_resolve->contains (name->t)) {
        int i, j;
        tree tmp= web_cache_resolve [name->t];
        for (i=0; i<MAX_CACHED; i++)
            if (web_cache[i] == name->t) {
                // cout << name << " in cache as " << tmp << " at " << i << "\n";
                for (j=i; ((j+1) % MAX_CACHED) != web_nr; j= (j+1) % MAX_CACHED)
                    web_cache[j]= web_cache[(j+1) % MAX_CACHED];
                web_cache[j]= name->t;
                break;
            }
        return as_url (tmp); // url_system (tmp);
    }
    return url_none ();
}
Example #6
0
url
operator * (url u1, url u2) {
  //cout << "concat " << u1->t << " * " << u2->t << "\n";
  if (is_root (u2) || (is_concat (u2) && is_root (u2[1]))) {
    if (is_concat (u1) && is_root_web (u1[1])) {
      if (is_root (u2, "default") ||
          (is_concat (u2) && is_root (u2[1], "default")))
        {
          url v= u1[2];
          while (is_concat (v)) v= v[1];
          if (is_root (u2)) return u1[1] * v;
          return u1[1] * v * u2[2];
        }
      if (is_root (u2, "blank") ||
          (is_concat (u2) && is_root (u2[1], "blank")))
        return reroot (u2, u1[1][1]->t->label);
    }
    return u2;
  }
  if (is_here (u1) || (u1->t == "")) return u2;
  if (is_here (u2)) return u1;
  if (is_none (u1)) return url_none ();
  if (is_none (u2)) return url_none ();
  if (u2 == url_parent ()) {
    if (is_root (u1)) return u1;
    if (is_pseudo_atomic (u1) && (!is_parent (u1))) return url_here ();
    if (is_semi_root (u1)) return u1;
  }
  if (is_concat (u2) && (u2[1] == url_parent ())) {
    if (is_root (u1)) return u1 * u2[2];
    if (is_pseudo_atomic (u1) && (!is_parent (u1))) return u2[2];
    if (is_semi_root (u1)) return u1 * u2[2];
  }
  if (is_concat (u1)) return u1[1] * (u1[2] * u2);
  return as_url (tuple ("concat", u1->t, u2->t));
}
Example #7
0
inline url url_ancestor () { return as_url (tree ("...")); }
Example #8
0
inline url url_parent () { return as_url (tree ("..")); }
Example #9
0
inline url url_here () { return as_url (tree (".")); }
Example #10
0
inline url url_none () { return as_url (tuple ("none")); }
Example #11
0
url
url_wildcard (string name) {
  return as_url (tuple ("wildcard", name));
}
Example #12
0
url
url_wildcard () {
  return as_url (tuple ("wildcard"));
}
Example #13
0
url
url_ramdisc (string contents) {
  return as_url (tuple ("root", "ramdisc", contents));
}
Example #14
0
url
url_root (string protocol) {
  return as_url (tuple ("root", protocol));
}