Back to index

texmacs  1.0.7.15
Defines | Functions | Variables
web_files.cpp File Reference
#include "file.hpp"
#include "web_files.hpp"
#include "sys_utils.hpp"
#include "analyze.hpp"
#include "hashmap.hpp"
#include "scheme.hpp"

Go to the source code of this file.

Defines

#define MAX_CACHED   25

Functions

static url get_cache (url name)
static url set_cache (url name, url tmp)
void web_cache_invalidate (url name)
static string web_encode (string s)
url get_from_web (url name)
url get_from_server (url u)
bool save_to_server (url u, string s)
url get_from_ramdisc (url u)

Variables

static int web_nr = 0
static array< treeweb_cache (MAX_CACHED)
static hashmap< tree, treeweb_cache_resolve ("")

Define Documentation

#define MAX_CACHED   25

Definition at line 23 of file web_files.cpp.


Function Documentation

static url get_cache ( url  name) [static]

Definition at line 33 of file web_files.cpp.

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 163 of file web_files.cpp.

                         {
  if (!is_ramdisc (u)) return url_none ();
  url res= get_cache (u);
  if (!is_none (res)) return (res);
  url tmp= url_temp (string (".") * suffix (u));
  save_string (tmp, u[1][2]->t->label);
  return set_cache (u, tmp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file web_files.cpp.

                        {
  if (!is_rooted_tmfs (u)) return url_none ();
  url res= get_cache (u);
  if (!is_none (res)) return res;

  string name= as_string (u);
  if (ends (name, "~") || ends (name, "#")) return url_none ();
  string r= as_string (call ("tmfs-load", object (name)));
  if (r == "") return url_none ();
  url tmp= url_temp ();
  (void) save_string (tmp, r, true);

  return set_cache (u, tmp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

url get_from_web ( url  name)

Definition at line 78 of file web_files.cpp.

                        {
  if (!is_rooted_web (name)) return url_none ();
  url res= get_cache (name);
  if (!is_none (res)) return res;

#ifdef OS_WIN32
  char *urlPath;
  char *tempFilePath;
  string urlString = as_string (name);
  url tmp = url_temp();
       
  if (starts (urlString, "www."))
    urlString = "http://" * urlString;
  else if (starts (urlString, "ftp."))
    urlString = "ftp://" * urlString;
  else if (starts (urlString, "ftp://"))
    urlPath = NULL;
  else if (starts (urlString, "http://"))
    urlPath = NULL;
  else
    urlString = "http://" * urlString;
  urlString= web_encode (urlString);

  urlPath = as_charp(urlString);
  tempFilePath = as_charp(as_string(tmp));

  if(!URL_Get(urlPath, tempFilePath)){
    tm_delete_array (urlPath);
    tm_delete_array (tempFilePath);
    return url_none();
  }

  else return set_cache (name, tmp);
#else
  string test= var_eval_system ("which wget");
  if (!ends (test, "wget")) return url_none ();
  url tmp= url_temp ();
  string tmp_s= escape_sh (concretize (tmp));
  string cmd= "wget --header='User-Agent: TeXmacs-" TEXMACS_VERSION "' -q";
  cmd << " -O " << tmp_s << " " << escape_sh (web_encode (as_string (name)));
  // cout << cmd << "\n";
  system (cmd);
  // cout << "got " << name << " as " << tmp << "\n";

  if (var_eval_system ("cat " * tmp_s * " 2> /dev/null") == "") {
    remove (tmp);
    return url_none ();
  }
  else return set_cache (name, tmp);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool save_to_server ( url  u,
string  s 
)

Definition at line 151 of file web_files.cpp.

                                 {
  if (!is_rooted_tmfs (u)) return true;
  string name= as_string (u);
  (void) call ("tmfs-save", object (name), object (s));
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static url set_cache ( url  name,
url  tmp 
) [static]

Definition at line 51 of file web_files.cpp.

                              {
  web_cache_resolve->reset (web_cache [web_nr]);
  web_cache [web_nr]= name->t;
  web_cache_resolve (name->t)= tmp->t;
  web_nr= (web_nr+1) % MAX_CACHED;
  return tmp;
}

Here is the caller graph for this function:

void web_cache_invalidate ( url  name)

Definition at line 60 of file web_files.cpp.

                                {
  for (int i=0; i<MAX_CACHED; i++)
    if (web_cache[i] == name->t) {
      web_cache[i]= tree ("");
      web_cache_resolve->reset (name->t);
    }
}

Here is the caller graph for this function:

static string web_encode ( string  s) [static]

Definition at line 73 of file web_files.cpp.

                      {
  return tm_decode (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int web_nr = 0 [static]

Definition at line 24 of file web_files.cpp.