"Fossies" - the Fresh Open Source Software Archive

Member "TeXmacs-2.1.2-src/src/System/Classes/url.hpp" (5 May 2022, 6986 Bytes) of package /linux/misc/TeXmacs-2.1.2-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "url.hpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.1.1_vs_2.1.2.

    1 
    2 /******************************************************************************
    3 * MODULE     : url.hpp
    4 * DESCRIPTION: unified resource location handling
    5 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
    6 *******************************************************************************
    7 * This software falls under the GNU general public license version 3 or later.
    8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
    9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
   10 ******************************************************************************/
   11 
   12 #ifndef URL_H
   13 #define URL_H
   14 #include "tree.hpp"
   15 
   16 #define URL_SYSTEM 0
   17 #define URL_UNIX 1
   18 #define URL_STANDARD 2
   19 #define URL_CLEAN_UNIX 3
   20 
   21 /******************************************************************************
   22 * The url data type
   23 ******************************************************************************/
   24 
   25 struct url_rep: concrete_struct {
   26   tree t;
   27   inline url_rep (tree t2): t (t2) {}
   28 };
   29 
   30 class url {
   31   CONCRETE(url);
   32 private:
   33   url (tree t): rep (tm_new<url_rep> (t)) {}
   34 public:
   35   url ();
   36   url (const char* name);
   37   url (string name);
   38   url (string dir, string name);
   39   inline bool operator == (url u) { return rep->t == u->t; }
   40   inline bool operator != (url u) { return rep->t != u->t; }
   41   inline url operator [] (int i) { return url (rep->t[i]); }
   42   friend url as_url (tree t);
   43 };
   44 CONCRETE_CODE(url);
   45 
   46 tm_ostream& operator << (tm_ostream& out, url u);
   47 inline url as_url (tree t) { return url(t); }
   48 string as_string (url u, int type= URL_SYSTEM);
   49 inline tree as_tree (url u) { return tree (u->t); }
   50 inline string as_system_string (url u) { return as_string (u, URL_SYSTEM); }
   51 inline string as_unix_string (url u) { return as_string (u, URL_UNIX); }
   52 inline string as_standard_string (url u) { return as_string (u,URL_STANDARD); }
   53 
   54 /******************************************************************************
   55 * url constructors
   56 ******************************************************************************/
   57 
   58 url url_general (string name, int type);
   59 url url_unix (string name);
   60 url url_unix (string dir, string name);
   61 url url_system (string name);
   62 url url_system (string dir, string name);
   63 url url_standard (string name);
   64 url url_standard (string dir, string name);
   65 
   66 inline url url_none () { return as_url (tuple ("none")); }
   67 inline url url_here () { return as_url (tree (".")); }
   68 inline url url_parent () { return as_url (tree ("..")); }
   69 inline url url_ancestor () { return as_url (tree ("...")); }
   70 inline url url_pwd () { return url_system ("$PWD"); }
   71 
   72 url url_root (string protocol);       // root url
   73 url url_ramdisc (string contents);    // ramdisc with contents contents
   74 url url_wildcard ();                  // any url
   75 url url_wildcard (string name);       // string with * wildcards
   76 
   77 url operator * (url u1, url u2);      // concatenation of url with rootless url
   78 url operator * (url u1, const char* name);
   79 url operator * (url u1, string name);
   80 url operator | (url u1, url u2);      // disjunction of urls like in file paths
   81 
   82 inline url url_parent (url u) { return u * url_parent (); }
   83 
   84 /******************************************************************************
   85 * predicates
   86 ******************************************************************************/
   87 
   88 inline bool is_none (url u) { return is_tuple (u->t, "none", 0); }
   89 inline bool is_here (url u) { return u->t == "."; }
   90 inline bool is_parent (url u) { return u->t == ".."; }
   91 inline bool is_ancestor (url u) { return u->t == "..."; }
   92 inline bool is_atomic (url u) { return is_atomic (u->t); }
   93 inline bool is_concat (url u) { return is_tuple (u->t, "concat", 2); }
   94 inline bool is_or (url u) { return is_tuple (u->t, "or", 2); }
   95 inline bool is_root (url u) {
   96   return is_tuple (u->t, "root") && (N(u->t) >= 2); }
   97 inline bool is_root (url u, string s) {
   98   return is_root (u) && (u[1]->t->label == s); }
   99 inline bool is_root_web (url u) {
  100   return is_root (u, "http") || is_root (u, "https") || is_root (u, "ftp") ||
  101          is_root (u, "blank"); }
  102 inline bool is_root_tmfs (url u) { return is_root (u, "tmfs"); }
  103 inline bool is_root_blank (url u) { return is_root (u, "blank"); }
  104 inline bool is_wildcard (url u) { return is_tuple (u->t, "wildcard"); }
  105 inline bool is_wildcard (url u, int n) {
  106   return is_tuple (u->t, "wildcard", n); }
  107 inline bool is_pseudo_atomic (url u) {
  108   return is_atomic (u->t) || is_tuple (u->t, "wildcard", 1); }
  109 
  110 bool is_rooted (url u);
  111 bool is_rooted (url u, string protocol);
  112 bool is_rooted_web (url u);
  113 bool is_rooted_tmfs (url u);
  114 bool is_rooted_tmfs (url u, string sub_protocol);
  115 bool is_rooted_blank (url u);
  116 bool is_name (url u);
  117 bool is_rooted_name (url u);
  118 bool is_ramdisc (url u);
  119 
  120 /******************************************************************************
  121 * operations on urls
  122 ******************************************************************************/
  123 
  124 url    head (url u);                 // keep only the directory of the file
  125 url    tail (url u);                 // keep only the file name without path
  126 string suffix (url u);               // get suffix of file
  127 string basename (url u, string suf); // get basename of file with given suffix
  128 string basename (url u);             // get basename of file
  129 url    glue (url u, string s);       // glue suffix to url tail
  130 url    unglue (url u, int nr);       // remove nr chars from suffix
  131 url    unblank (url u);              // a/b/ -> a/b
  132 url    relative (url base, url u);   // a/b, c -> a/c
  133 url    delta (url base, url u);      // relative (a, delta (a, b)) == b
  134 string get_root (url u);             // get root
  135 url    unroot (url u);               // remove root
  136 url    reroot (url u, string s);     // reroot using new protocol
  137 url    expand (url u);               // rewrite a/{b:c} -> a/b:a/c
  138 url    sort (url u);                 // order items in ors
  139 url    factor (url u);               // inverse of expand; also sorts
  140 bool   descends (url u, url base);   // does u descend from base?
  141 bool   is_secure (url u);            // is u secure?
  142 
  143 /******************************************************************************
  144 * url resolution
  145 ******************************************************************************/
  146 
  147 url  complete (url u, string filter= "fr"); // wildcard completion
  148 url  resolve (url u, string filter= "fr");  // find first match only
  149 url  resolve_in_path (url u);               // find file in path
  150 bool exists (url u);                        // file exists
  151 bool exists_in_path (url u);                // file exists in path
  152 bool has_permission (url u, string filter); // check file permissions
  153 url  descendance (url u);                   // utility for style&package menus
  154 url  subdirectories (url u);                // similarly for patters
  155 url  concretize_url (url u);                // variant of concretize below
  156 string concretize (url u);                  // system name for resolved url
  157 string materialize (url u, string f= "fr"); // resolve + concretize
  158 
  159 #endif // defined URL_H