Back to index

texmacs  1.0.7.15
Defines | Functions
url.cpp File Reference
#include "boot.hpp"
#include "url.hpp"
#include "sys_utils.hpp"
#include "web_files.hpp"
#include "file.hpp"
#include "analyze.hpp"
#include <ctype.h>

Go to the source code of this file.

Defines

#define URL_CONCATER   '/'
#define URL_SEPARATOR   ':'

Functions

static url url_get_atom (string s, int type)
static url url_get_name (string s, int type=URL_STANDARD, int i=0)
static url url_get_path (string s, int type=URL_STANDARD, int i=0)
url url_root (string protocol)
url url_ramdisc (string contents)
static url url_default (string name, int type=URL_SYSTEM)
static url url_path (string s, int type=URL_SYSTEM)
static url url_local (string name)
static url url_file (string name)
static url url_http (string name)
static url url_ftp (string name)
static url url_tmfs (string name)
static url url_blank (string name)
static bool heuristic_is_path (string name, int type)
static bool heuristic_is_default (string name, int type)
static bool heuristic_is_http (string name)
static bool heuristic_is_ftp (string name)
url url_general (string name, int type=URL_SYSTEM)
url url_unix (string name)
url url_unix (string dir, string name)
url url_system (string name)
url url_system (string dir, string name)
url url_standard (string name)
url url_standard (string dir, string name)
static bool is_semi_root (url u)
url operator* (url u1, url u2)
url operator* (url u1, const char *name)
url operator* (url u1, string name)
url operator| (url u1, url u2)
url url_wildcard ()
url url_wildcard (string name)
bool is_rooted (url u)
bool is_rooted (url u, string protocol)
bool is_rooted_web (url u)
bool is_rooted_tmfs (url u)
bool is_rooted_blank (url u)
bool is_name (url u)
bool is_rooted_name (url u)
bool is_name_in_path (url u)
bool is_path (url u)
bool is_rooted_path (url u)
bool is_ramdisc (url u)
string as_string (url u, int type)
tm_ostreamoperator<< (tm_ostream &out, url u)
url head (url u)
url tail (url u)
string suffix (url u)
url glue (url u, string s)
url unglue (url u, int nr)
url unblank (url u)
url relative (url base, url u)
url delta_sub (url base, url u)
url delta (url base, url u)
static url expand (url u1, url u2)
url expand (url u)
bool descends (url u, url base)
bool is_secure (url u)
static bool operator<= (url u1, url u2)
static url sort_sub (url add, url to)
url sort (url u)
static url factor_sorted (url u)
static url factor_sub (url u)
url factor (url u)
url complete (url base, url u, string filter, bool flag)
url reroot (url u, string protocol)
static url complete (url base, url sub, url u, string filter, bool flag)
url complete (url u, string filter, bool flag)
url complete (url u, string filter)
url resolve (url u, string filter)
url resolve_in_path (url u)
bool exists (url u)
bool exists_in_path (url u)
bool has_permission (url u, string filter)
static url descendance_sub (url u)
url descendance (url u)
string concretize (url u)
string materialize (url u, string filter)

Define Documentation

#define URL_CONCATER   '/'

Definition at line 78 of file url.cpp.

#define URL_SEPARATOR   ':'

Definition at line 79 of file url.cpp.


Function Documentation

string as_string ( url  u,
int  type 
)

Definition at line 448 of file url.cpp.

                            {
  // This routine pritty prints an url as a string.
  // FIXME: the current algorithm is quadratic in time.
  if (is_none (u)) return "{}";
  if (is_atomic (u)) return u->t->label;
  if (is_concat (u)) {
    int stype= type;
    if (is_root (u[1]) && (!is_root (u[1], "default"))) stype= URL_STANDARD;
    string sep= (stype==URL_SYSTEM? string (URL_CONCATER): string ("/"));
    string s1 = as_string (u[1], type);
    string s2 = as_string (u[2], stype);
    if (is_root (u[1], "default")) s1= "";
    if ((!is_name (u[1])) && (!is_root (u[1]))) s1= "{" * s1 * "}";
    if ((!is_concat (u[2])) && (!is_atomic (u[2])) && (!is_wildcard (u[2], 1)))
      s2= "{" * s2 * "}";
#ifdef WINPATHS
    if (is_semi_root (u)) {
      if (ends (s2, ":")) return s2 * "\\";
      else return s2;
    }
    if (is_root (u[1]) && stype == URL_SYSTEM) return s2;
#endif
    return s1 * sep * s2;
  }
  if (is_or (u)) {
    string s1= as_string (u[1], type);
    string s2= as_string (u[2], type);
    if (!is_name_in_path (u[1])) s1= "{" * s1 * "}";
    if ((!is_or (u[2])) && (!is_name_in_path (u[2]))) s2= "{" * s2 * "}";
#ifdef WINPATHS
    if (type == URL_STANDARD) return s1 * ":" * s2;
    else return s1 * string (URL_SEPARATOR) * s2;
#else
    return s1 * string (URL_SEPARATOR) * s2;
#endif
  }
#ifdef WINPATHS
  if (is_root (u, "default")) {
    int stype= type;
    if (is_root (u[1]) && (!is_root (u[1], "default"))) stype= URL_STANDARD;
       if (stype == URL_SYSTEM) return ""; else return "/";
  }
#else
  if (is_root (u, "default")) return "/";
#endif
  if (is_root (u, "blank")) return "/";
  if (is_root (u, "file")) return u[1]->t->label * "://";
  if (is_root (u)) return u[1]->t->label * ":/";
  if (is_wildcard (u, 0)) return "**";
  if (is_wildcard (u, 1)) return u->t[1]->label;
  FAILED ("bad url");
  return "";
}

Here is the call graph for this function:

url complete ( url  base,
url  u,
string  filter,
bool  flag 
)

Definition at line 729 of file url.cpp.

                                                     {
 // cout << "complete " << base << " |||| " << u << LF;
  if (is_none (base)) return base;
  if (is_none (u)) return u;
  if ((!is_root (base)) && (!is_rooted_name (base))) {
    cerr << "base= " << base << LF;
    FAILED ("invalid base url");
  }
  if (is_name (u) || (is_concat (u) && is_root (u[1]) && is_name (u[2]))) {
    url comp= base * u;
    if (is_rooted (comp, "default") || is_rooted (comp, "file")) {
      if (is_of_type (comp, filter)) return reroot (u, "default");
      return url_none ();
    }
    if (is_rooted_web (comp) || is_rooted_tmfs (comp) || is_ramdisc (comp)) {
      if (is_of_type (comp, filter)) return u;
      return url_none ();
    }
    cerr << LF << "base= " << base << LF;
    ASSERT (is_rooted (comp), "unrooted url");
    FAILED ("bad protocol in url");
  }
  if (is_root (u)) {
    // FIXME: test filter flags here
    return u;
  }
  if (is_concat (u)) {
    url sub= complete (base, u[1], "", false);
    // "" should often be faster than the more correct "d" here
    return complete (base, sub, u[2], filter, flag);
  }
  if (is_or (u)) {
    url res1= complete (base, u[1], filter, flag);
    if ((!is_none (res1)) && flag) return res1;
    return res1 | complete (base, u[2], filter, flag);
  }
  if (is_wildcard (u)) {
    // FIXME: ret= ret | ... is unefficient (quadratic) in main loop
    if (!(is_rooted (base, "default") || is_rooted (base, "file"))) {
      cerr << LF << "base= " << base << LF;
      FAILED ("wildcards only implemented for files");
    }
    url ret= url_none ();
    if (is_wildcard (u, 0) && is_of_type (base, filter)) ret= url_here ();
    bool error_flag;
    array<string> dir= read_directory (base, error_flag);
    int i, n= N(dir);
    for (i=0; i<n; i++) {
      if ((!is_none (ret)) && flag) return ret;
      if ((dir[i] == ".") || (dir[i] == "..")) continue;
      if (is_wildcard (u, 0))
       ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag));
      else if (match_wildcard (dir[i], u[1]->t->label))
       ret= ret | complete (base, dir[i], filter, flag);
    }
    return ret;
  }
  cout << LF << "url= " << u << LF;
  FAILED ("bad url");
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url complete ( url  base,
url  sub,
url  u,
string  filter,
bool  flag 
) [static]

Definition at line 715 of file url.cpp.

                                                              {
  if (is_or (sub)) {
    url res1= complete (base, sub[1], u, filter, flag);
    if ((!is_none (res1)) && flag) return res1;
    return res1 | complete (base, sub[2], u, filter, flag);
  }
  if (is_concat (sub) && is_rooted (sub[1])) {
    url res= complete (sub[1], sub[2], u, filter, flag);
    return sub[1] * res;
  }
  return sub * complete (base * sub, u, filter, flag);
}

Here is the call graph for this function:

url complete ( url  u,
string  filter,
bool  flag 
)

Definition at line 792 of file url.cpp.

                                           {
  url home= url_pwd ();
  return home * complete (home, u, filter, flag);
}

Here is the call graph for this function:

url complete ( url  u,
string  filter 
)

Definition at line 798 of file url.cpp.

                                {
  // This routine can be used in order to find all possible matches
  // for the wildcards in an url and replace the wildcards by these matches.
  // Moreover, matches are normalized (file root -> default root).
  return complete (u, filter, false);
}

Here is the call graph for this function:

Definition at line 871 of file url.cpp.

                   {
  // This routine transforms a resolved url into a system file name.
  // In the case of distant files from the web, a local copy is created.
#ifdef WINPATHS
  // FIXME: this fix seems strange;
  // to start with, the if condition is not respected
  string s = as_string (u);
  if (starts (s, "file:///")) s= s (8, N(s));
  if (heuristic_is_default (s, 0)) return s;
  if (is_rooted (u, "blank")) return as_string (reroot (u, "default"));
#else
  if (is_rooted (u, "default") ||
      is_rooted (u, "file") ||
      is_rooted (u, "blank"))
    return as_string (reroot (u, "default"));
#endif
  if (is_rooted_web (u)) return concretize (get_from_web (u));
  if (is_rooted_tmfs (u)) return concretize (get_from_server (u));
  if (is_ramdisc (u)) return concretize (get_from_ramdisc (u));
  if (is_here (u)) return as_string (url_pwd ());
  if (is_parent (u)) return as_string (url_pwd () * url_parent ());
  if (is_wildcard (u, 1)) return u->t[1]->label;
  cerr << "TeXmacs] couldn't concretize " << u->t << LF;
  // cerr << "\nu= " << u << LF;
  // FAILED ("url has no root");
  return "xxx";
}

Here is the call graph for this function:

Here is the caller graph for this function:

url delta ( url  base,
url  u 
)

Definition at line 596 of file url.cpp.

                        {
  if (is_or (u))
    return delta (base, u[1]) | delta (base, u[2]);
  url res= delta_sub (base, u);
  if (is_none (res)) return u;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url delta_sub ( url  base,
url  u 
)

Definition at line 580 of file url.cpp.

                            {
#ifdef WINPATHS
  if (is_atomic (base) || heuristic_is_default (as_string (base), URL_SYSTEM))
    return u;
#else
  if (is_atomic (base))
    return u;
#endif
  if (is_concat (base) && is_concat (u) && (base[1] == u[1]))
    return delta_sub (base[2], u[2]);
  if (is_concat (base))
    return url_parent () * delta_sub (head (base), u);
  return url_none ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 860 of file url.cpp.

                    {
  // Utility for style and package menus in tm_server.cpp
  // Compute and merge subdirectories of directories in path
  return factor (descendance_sub (u));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url descendance_sub ( url  u) [static]

Definition at line 853 of file url.cpp.

                        {
  if (is_or (u))
    return descendance_sub (u[1]) | descendance_sub (u[2]);
  return complete (u, url_wildcard (), "r", false);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool descends ( url  u,
url  base 
)

Definition at line 625 of file url.cpp.

                           {
  if (is_or (base)) return descends (u, base[1]) || descends (u, base[2]);
  if (is_concat (u) && is_atomic (base))
    return u[1] == base;
  if (is_concat (u) && is_concat (base))
    return u[1] == base[1] && descends (u[2], base[2]);
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool exists ( url  u)

Definition at line 834 of file url.cpp.

               {
  return !is_none (resolve (u, "r"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool exists_in_path ( url  u)

Definition at line 839 of file url.cpp.

                       {
#if defined (OS_WIN32) || defined (__MINGW__) || defined (__MINGW32__)
  return !is_none (resolve_in_path (url (as_string (u) * ".exe")));
#else
  return !is_none (resolve_in_path (u));
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url expand ( url  u1,
url  u2 
) [static]

Definition at line 605 of file url.cpp.

                        {
  if (is_or (u1)) return expand (u1[1], u2) | expand (u1[2], u2);
  if (is_or (u2)) return expand (u1, u2[1]) | expand (u1, u2[2]);
  if (is_ancestor (u2)) {
    if (is_concat (u1)) return u1 | expand (u1[1], u2);
    return u1 | u2;
  }
  if (is_concat (u2) && is_ancestor (u2[1]))
    return expand (expand (u1, u2[1]), u2[2]);
  return u1 * u2;
}

Here is the call graph for this function:

url expand ( url  u)

Definition at line 618 of file url.cpp.

               {
  if (is_or (u)) return expand (u[1]) | expand (u[2]);
  if (is_concat (u)) return expand (expand (u[1]), expand (u[2]));
  return u;
}

Here is the call graph for this function:

url factor ( url  u)

Definition at line 696 of file url.cpp.

               {
  return factor_sub (factor_sorted (sort (u)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url factor_sorted ( url  u) [static]

Definition at line 676 of file url.cpp.

                      {
  if (!is_or (u)) return u;
  url v= factor_sorted (u[2]);
  if (is_concat (u[1])) {
    if (is_concat (v) && (u[1][1] == v[1]))
      return u[1][1] * (u[1][2] | v[2]);
    if (is_or (v) && is_concat (v[1]) && (u[1][1] == v[1][1]))
      return (u[1][1] * (u[1][2] | v[1][2])) | v[2];
  }
  return u[1] | v;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url factor_sub ( url  u) [static]

Definition at line 689 of file url.cpp.

                   {
  if (is_concat (u)) return u[1] * factor (u[2]);
  if (is_or (u)) return factor_sub (u[1]) | factor_sub (u[2]);
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url glue ( url  u,
string  s 
)

Definition at line 544 of file url.cpp.

                       {
  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);
  cerr << "\nu= " << u << "\n";
  cerr << "s= " << s << "\n";
  FAILED ("can't glue string to url");
  return u;
}

Here is the call graph for this function:

bool has_permission ( url  u,
string  filter 
)

Definition at line 848 of file url.cpp.

                                      {
  return !is_none (resolve (u, filter));
}

Here is the call graph for this function:

Here is the caller graph for this function:

url head ( url  u)

Definition at line 512 of file url.cpp.

             {
  return u * url_parent ();
}

Here is the call graph for this function:

static bool heuristic_is_default ( string  name,
int  type 
) [static]

Definition at line 208 of file url.cpp.

                                             {
#ifdef WINPATHS
  // FIXME: we probably should take into account 'type' too
  if (N(name) < 2) return false;
  if ((name[0] == '\\') && (name[1] == '\\')) return true;
  return
    isalpha (name[0]) && (name[1] == ':') &&
    ((N(name)==2) || (name[2] == '\\') || (name[2] == '/'));
#else
  char sep= (type==0)? URL_CONCATER: '/';
  return (name != "") && (name[0] == sep);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool heuristic_is_ftp ( string  name) [static]

Definition at line 229 of file url.cpp.

                               {
  return starts (name, "ftp.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool heuristic_is_http ( string  name) [static]

Definition at line 223 of file url.cpp.

                                {
  return starts (name, "www.");
  // FIXME: we might want to recognize some other ones like google.com too
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool heuristic_is_path ( string  name,
int  type 
) [static]

Definition at line 198 of file url.cpp.

                                          {
  char sep= (type==0)? URL_SEPARATOR: ':';
  int i, n= N(name);
  for (i=0; i<n; i++)
    if (name[i] == sep)
      return true;
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_name ( url  u)

Definition at line 409 of file url.cpp.

                {
  if (is_atomic (u)) return true;
  if (!is_concat (u)) return false;
  return is_name (u[1]) && is_name (u[2]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_name_in_path ( url  u)

Definition at line 421 of file url.cpp.

                        {
  if (is_name (u)) return true;
  return is_concat (u) && is_root (u[1], "default") && is_name (u[2]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_path ( url  u)

Definition at line 427 of file url.cpp.

                {
  if (is_atomic (u)) return true;
  if ((!is_or (u)) && (!is_concat (u))) return false;
  return is_path (u[1]) && is_path (u[2]);
}

Here is the call graph for this function:

bool is_ramdisc ( url  u)

Definition at line 439 of file url.cpp.

                   {
  return is_concat (u) && is_root (u[1], "ramdisc");
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_rooted ( url  u)

Definition at line 369 of file url.cpp.

                  {
  return
    is_root (u) ||
    (is_concat (u) && is_rooted (u[1])) ||
    (is_or (u) && is_rooted (u[1]) && is_rooted (u[2]));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_rooted ( url  u,
string  protocol 
)

Definition at line 377 of file url.cpp.

                                   {
  return
    is_root (u, protocol) ||
    (is_concat (u) && is_rooted (u[1], protocol)) ||
    (is_or (u) && is_rooted (u[1], protocol) && is_rooted (u[2], protocol));
}

Here is the call graph for this function:

bool is_rooted_blank ( url  u)

Definition at line 401 of file url.cpp.

                        {
  return
    is_root_blank (u) ||
    (is_concat (u) && is_rooted_blank (u[1])) ||
    (is_or (u) && is_rooted_blank (u[1]) && is_rooted_blank (u[2]));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_rooted_name ( url  u)

Definition at line 416 of file url.cpp.

                       {
  return is_concat (u) && is_root (u[1]) && is_name (u[2]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_rooted_path ( url  u)

Definition at line 434 of file url.cpp.

                       {
  return is_rooted (u) && is_path (u);
}

Here is the call graph for this function:

bool is_rooted_tmfs ( url  u)

Definition at line 393 of file url.cpp.

                       {
  return
    is_root_tmfs (u) ||
    (is_concat (u) && is_rooted_tmfs (u[1])) ||
    (is_or (u) && is_rooted_tmfs (u[1]) && is_rooted_tmfs (u[2]));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_rooted_web ( url  u)

Definition at line 385 of file url.cpp.

                      {
  return
    is_root_web (u) ||
    (is_concat (u) && is_rooted_web (u[1])) ||
    (is_or (u) && is_rooted_web (u[1]) && is_rooted_web (u[2]));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_secure ( url  u)

Definition at line 635 of file url.cpp.

                  {
  return descends (u, expand (url_path ("$TEXMACS_SECURE_PATH")));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool is_semi_root ( url  u) [static]

Definition at line 288 of file url.cpp.

                     {
  // url u such that u/.. == u (website or windows drive name)
#ifdef WINPATHS
  return is_concat (u) && is_root (u[1]) && is_atomic (u[2]);
#else
  return is_concat (u) && is_root_web (u[1]) && is_atomic (u[2]);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

string materialize ( url  u,
string  filter 
)

Definition at line 900 of file url.cpp.

                                   {
  // Combines resolve and concretize
  url r= resolve (u, filter);
  if (!(is_rooted (r) || is_here (r) || is_parent (r))) {
    cerr << "\nu= " << u << LF;
    FAILED ("url could not be resolved");
  }
  return concretize (r);
}

Here is the call graph for this function:

Here is the caller graph for this function:

url operator* ( url  u1,
url  u2 
)

Definition at line 298 of file url.cpp.

                            {
  //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_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_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));
}

Here is the call graph for this function:

url operator* ( url  u1,
const char *  name 
)

Definition at line 335 of file url.cpp.

                                      {
  return u1 * url (name);
}
url operator* ( url  u1,
string  name 
)

Definition at line 340 of file url.cpp.

                                 {
  return u1 * url (name);
}
tm_ostream& operator<< ( tm_ostream out,
url  u 
)

Definition at line 503 of file url.cpp.

                                     {
  return out << as_string (u, URL_SYSTEM);
}

Here is the call graph for this function:

static bool operator<= ( url  u1,
url  u2 
) [static]

Definition at line 644 of file url.cpp.

                             {
  if (is_atomic (u1) && is_atomic (u2))
    return u1->t->label <= u2->t->label;
  if (is_atomic (u1)) return true;
  if (is_atomic (u2)) return false;
  if (is_concat (u1) && is_concat (u2)) {
    if (u1[1] == u2[1]) return u1[2] <= u2[2];
    else return u1[1] <= u2[1];
  }
  if (is_concat (u1)) return true;
  if (is_concat (u2)) return false;
  return true; // does not matter for sorting
}

Here is the call graph for this function:

url operator| ( url  u1,
url  u2 
)

Definition at line 345 of file url.cpp.

                            {
  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));
}

Here is the call graph for this function:

url relative ( url  base,
url  u 
)

Definition at line 575 of file url.cpp.

                           {
  return head (base) * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url reroot ( url  u,
string  protocol 
)

Definition at line 707 of file url.cpp.

                                {
  if (is_concat (u)) return reroot (u[1], protocol) * u[2];
  if (is_or (u)) return reroot (u[1], protocol) | reroot (u[2], protocol);
  if (is_root (u)) return url_root (protocol);
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url resolve ( url  u,
string  filter 
)

Definition at line 806 of file url.cpp.

                               {
  // This routine does the same thing as complete, but it stops at
  // the first match. It is particularly useful for finding files in paths.
  return complete (u, filter, true);
  /*
  url res= complete (u, filter, true);
  if (is_none (res))
    cout << "Failed resolution of " << u << ", " << filter << LF;
  return res;
  */
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 819 of file url.cpp.

                        {
  if (use_which) {
    string name = escape_sh (as_string (u));
    string which= var_eval_system ("which " * name * " 2> /dev/null");
    if (ends (which, name))
      return which;
    else if ((which != "") &&
            (!starts (which, "which: ")) &&
            (!starts (which, "no ")))
      cout << "TeXmacs] " << which << "\n";
  }
  return resolve (url_path ("$PATH") * u, "x");
}

Here is the call graph for this function:

Here is the caller graph for this function:

url sort ( url  u)

Definition at line 669 of file url.cpp.

             {
  if (is_or (u))
    return sort_sub (u[1], sort (u[2]));
  else return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url sort_sub ( url  add,
url  to 
) [static]

Definition at line 659 of file url.cpp.

                           {
  if (is_or (to)) {
    if (add <= to[1]) return add | to;
    return to[1] | sort_sub (add, to[2]);
  }
  if (add <= to) return add | to;
  else return to | add;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string suffix ( url  u)

Definition at line 528 of file url.cpp.

               {
  u= tail (u);
  if (!is_atomic (u)) return "";
  string s= as_string (u);
  int i, n= N(s);
  for (i=n-1; i>=0; i--)
    if (s[i]=='.') break;
  if ((i>0) && (i<n-1)) {
    string r= s (i+1, n);
    while ((N(r)>0) && (r[N(r)-1]=='~' || r[N(r)-1]=='#')) r= r(0, N(r)-1);
    return r;
  }
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

url tail ( url  u)

Definition at line 517 of file url.cpp.

             {
  if (is_concat (u)) {
    if (is_root_web (u[1]) && is_atomic (u[2])) return url_here ();
    return tail (u[2]);
  }
  if (is_or (u)) return tail (u[1]) | tail (u[2]);
  if (is_root (u)) return url_here ();
  return u;
}

Here is the call graph for this function:

url unblank ( url  u)

Definition at line 567 of file url.cpp.

                {
  if (is_concat (u) && (u[2]->t == "")) return u[1];
  if (is_concat (u)) return u[1] * unblank (u[2]);
  if (is_or (u)) return unblank (u[1]) | unblank (u[2]);
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url unglue ( url  u,
int  nr 
)

Definition at line 555 of file url.cpp.

                       {
  if (is_atomic (u))
    return as_url (tree (u->t->label (0, N(u->t->label) - nr)));
  if (is_concat (u)) return u[1] * unglue (u[2], nr);
  if (is_or (u)) return unglue (u[1], nr) | unglue (u[2], nr);
  cerr << "\nu= " << u << "\n";
  cerr << "nr= " << nr << "\n";
  FAILED ("can't unglue from url");
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_blank ( string  name) [static]

Definition at line 188 of file url.cpp.

                        {
  url u= url_get_name (name);
  return url_root ("blank") * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_default ( string  name,
int  type = URL_SYSTEM 
) [static]

Definition at line 138 of file url.cpp.

                                                {
  url u= url_get_name (name, type);
#ifdef WINPATHS
  // FIXME: this hack seems a bit too simple
  if (is_concat (u) && (u[2]->t == "")) u= u[1];
  // cout << name << " -> " << url_root ("default") * u << "\n";
  return url_root ("default") * u;
#else
  if (u->t == "") return url_root ("default");
  return url_root ("default") * u;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_file ( string  name) [static]

Definition at line 164 of file url.cpp.

                       {
  url u= url_get_name (name);
  return url_root ("file") * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_ftp ( string  name) [static]

Definition at line 176 of file url.cpp.

                      {
  url u= url_get_name (name);
  return url_root ("ftp") * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_general ( string  name,
int  type = URL_SYSTEM 
)

Definition at line 234 of file url.cpp.

                                                {
  if (starts (name, "local:")) return url_local (name (6, N (name)));
  if (starts (name, "file://")) return url_file (name (7, N (name)));
  if (starts (name, "http://")) return url_http (name (7, N (name)));
  if (starts (name, "ftp://")) return url_ftp (name (6, N (name)));
  if (starts (name, "tmfs://")) return url_tmfs (name (7, N (name)));
  if (starts (name, "//")) return url_blank (name (2, N (name)));
  if (heuristic_is_path (name, type)) return url_path (name, type);
  if (heuristic_is_default (name, type)) return url_default (name, type);
  if (heuristic_is_http (name)) return url_http (name);
  if (heuristic_is_ftp (name)) return url_ftp (name);
  return url_get_name (name, type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_get_atom ( string  s,
int  type 
) [static]

Definition at line 87 of file url.cpp.

                                  {
  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));
    }
  }
  return as_url (tree (s));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_get_name ( string  s,
int  type = URL_STANDARD,
int  i = 0 
) [static]

Definition at line 100 of file url.cpp.

                                                         {
  char sep= (type == URL_SYSTEM)? URL_CONCATER: '/';
  int start= i, n= N(s);
  while ((i<n) && (s[i] != sep) && (s[i] != '/')) i++;
  url u= url_get_atom (s (start, i), type);
  // url u= tree (s (start, i));
  if (i == n) return u;
  if (start == i) return url_get_name (s, type, i+1);
  return u * url_get_name (s, type, i+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_get_path ( string  s,
int  type = URL_STANDARD,
int  i = 0 
) [static]

Definition at line 112 of file url.cpp.

                                                         {
  char sep= (type == URL_SYSTEM)? URL_SEPARATOR: ':';
  int start= i, n= N(s);
  if (i == n) return url_none ();
  while ((i<n) && (s[i] != sep)) i++;
  url u= url_general (s (start, i), type);
  if (i == n) return u;
  if (start == i) return url_get_path (s, type, i+1);
  return u | url_get_path (s, type, i+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_http ( string  name) [static]

Definition at line 170 of file url.cpp.

                       {
  url u= url_get_name (name);
  return url_root ("http") * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_local ( string  name) [static]

Definition at line 158 of file url.cpp.

                        {
  url u= url_get_name (name, URL_SYSTEM);
  return reroot (u, "file");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url url_path ( string  s,
int  type = URL_SYSTEM 
) [static]

Definition at line 152 of file url.cpp.

                                          {
  url u= url_get_path (s, type);
  return u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_ramdisc ( string  contents)

Definition at line 133 of file url.cpp.

                              {
  return as_url (tuple ("root", "ramdisc", contents));
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_root ( string  protocol)

Definition at line 128 of file url.cpp.

                           {
  return as_url (tuple ("root", protocol));
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_standard ( string  name)

Definition at line 269 of file url.cpp.

                           {
  return url_general (name, URL_STANDARD);
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_standard ( string  dir,
string  name 
)

Definition at line 274 of file url.cpp.

                                       {
  return url_standard (dir) * url_standard (name);
}

Here is the call graph for this function:

url url_system ( string  name)

Definition at line 259 of file url.cpp.

                         {
  return url_general (name, URL_SYSTEM);
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_system ( string  dir,
string  name 
)

Definition at line 264 of file url.cpp.

                                     {
  return url_system (dir) * url_system (name);
}

Here is the call graph for this function:

static url url_tmfs ( string  name) [static]

Definition at line 182 of file url.cpp.

                       {
  url u= url_get_name (name);
  return url_root ("tmfs") * u;
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_unix ( string  name)

Definition at line 249 of file url.cpp.

                       {
  return url_general (name, URL_UNIX);
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_unix ( string  dir,
string  name 
)

Definition at line 254 of file url.cpp.

                                   {
  return url_unix (dir) * url_unix (name);
}

Here is the call graph for this function:

Definition at line 355 of file url.cpp.

                {
  return as_url (tuple ("wildcard"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

url url_wildcard ( string  name)

Definition at line 360 of file url.cpp.

                           {
  return as_url (tuple ("wildcard", name));
}

Here is the call graph for this function: