Example #1
0
memorizer
memorize_finalize () {
  cout << UNINDENT << "Memorize finalize" << LF;
  memorizer mem= mem_stack[0];
  tm_delete_array (mem_pos);
  tm_delete_array (mem_stack);
  mem_max_pos  = 0;
  mem_pos      = NULL;
  mem_max_stack= 0;
  mem_stack    = NULL;
  return mem;
}
Example #2
0
tex_font_metric_rep::~tex_font_metric_rep () {
  if (header != NULL) tm_delete_array (header);
  if (char_info != NULL) tm_delete_array (char_info);
  if (width != NULL) tm_delete_array (width);
  if (height != NULL) tm_delete_array (height);
  if (depth != NULL) tm_delete_array (depth);
  if (italic != NULL) tm_delete_array (italic);
  if (lig_kern != NULL) tm_delete_array (lig_kern);
  if (kern != NULL) tm_delete_array (kern);
  if (exten != NULL) tm_delete_array (exten);
  if (param != NULL) tm_delete_array (param);
}
Example #3
0
int
unix_system (string s) {
  char* _s = as_charp (s * " > /dev/null 2>&1");
  int ret = system (_s);
  tm_delete_array (_s);  
  return ret;
}
Example #4
0
template<typename T> void
double_size (T*& in, int& size) {
  T* out= tm_new_array<T> (2*size);
  for (int i=0; i<size; i++)
    out[i]= in[i];
  tm_delete_array (in);
  in= out;
  size *= 2;
}
Example #5
0
int
unix_system (string cmd, string& result) {
  url temp= url_temp ();
  string temp_s= escape_sh (concretize (temp));
  char* _cmd = as_charp (cmd * " > " * temp_s * " 2>&1");
  int ret = system (_cmd);
  tm_delete_array (_cmd);
  bool flag= load_string (temp, result, false);
  remove (temp);
  if (flag) result= "";
  return ret;
}
Example #6
0
void
compound_memorizer_rep::set_children (memorizer* a2, int n2) {
  if (n != 0) {
    n= 0;
    tm_delete_array (a);
  }
  if (n2 != 0) {
    n= n2;
    a= tm_new_array<memorizer> (n);
    for (int i=0; i<n; i++)
      a[i]= a2[i];
  }
}
Example #7
0
 inline ~hashmap_rep<T,U> () { tm_delete_array (a); }
Example #8
0
tree
bibtex_run (string bib, string style, url bib_file, tree bib_t) {
  int i;
  string bib_s= "\\bibstyle{" * style * "}\n";
  for (i=0; i<arity(bib_t); i++)
    bib_s << "\\citation{" << as_string (bib_t[i]) << "}\n";

  string dir= concretize (head (bib_file));
  string bib_name= as_string (tail (bib_file));
  if ((N(bib_name) >= 4) && (bib_name (N(bib_name)-4, N(bib_name)) == ".bib"))
    bib_name= bib_name (0, N(bib_name)- 4);
  bib_s << "\\bibdata{" << bib_name << "}\n";
  save_string ("$TEXMACS_HOME_PATH/system/bib/temp.aux", bib_s);

#ifdef OS_WIN32
  char *directory = as_charp (dir);
  RunBibtex(directory, "$TEXMACS_HOME_PATH/system/bib", "temp");
  tm_delete_array (directory);
#else
  string cmdln= "cd $TEXMACS_HOME_PATH/system/bib; ";
  cmdln << "BIBINPUTS=" << dir << ":$BIBINPUTS "
	<< "BSTINPUTS=" << dir << ":$BSTINPUTS "
	<< bibtex_command << " temp";
  if (DEBUG_AUTO) cout << "TeXmacs] BibTeX command: " << cmdln << "\n";
  system (cmdln);
#endif

  return bibtex_load_bbl (bib, "$TEXMACS_HOME_PATH/system/bib/temp.bbl");
  /*
  string result;
  if (load_string ("$TEXMACS_HOME_PATH/system/bib/temp.bbl", result, false))
    return "Error: bibtex failed to create bibliography";

  int count=1;
  tree t= generic_to_tree (result, "latex-snippet");
  t= search_bib (t);
  if (t == "") return "";
  tree largest= t[0];
  t= t[1];
  tree u (DOCUMENT);
  for (i=0; i<arity(t); i++) {
    if (is_concat (t[i]) &&
	(is_compound (t[i][0], "bibitem") ||
	 is_compound (t[i][0], "bibitem*")))
      {
	tree item= t[i][0];
	if (is_compound (item, "bibitem"))
	  item= compound ("bibitem*", as_string (count++), item[0]);
	t[i][0]= item;
	tree v (CONCAT, compound ("bibitem*", item[0]));
	if (is_atomic (item[1]))
	  v << tree (LABEL, bib * "-" * item[1]->label);
	if (N(t[i])>1) {
	  v << remove_start_space (t[i][1]);
	  v << A (t[i] (2, N(t[i])));
	}
	u << v;
      }
  }
  if (N(u) == 0) u= tree (DOCUMENT, "");
  return compound ("bib-list", largest, u);
  */
}
Example #9
0
x_picture_rep::~x_picture_rep () {
  XFreePixmap (the_gui->dpy, pm);
  if (im != NULL) XDestroyImage (im);
  if (bm != 0) XFreePixmap (the_gui->dpy, bm);
  if (data != NULL) tm_delete_array (data); }
Example #10
0
static memorizer_ptr
bigmem_insert (memorizer_ptr ptr) {
  if (bigmem_size >= bigmem_bags) {
    if (bigmem_bags == 0) {
      bigmem_bags= 2;
      //bigmem_bags= 1<<24;
      //cout << "Construct bigmem " << bigmem_bags << LF;
      bigmem_mem = tm_new_array<memorizer_ptrs> (bigmem_bags);
      bigmem_len = tm_new_array<int> (bigmem_bags);
      bigmem_cap = tm_new_array<int> (bigmem_bags);
      for (int i=0; i<bigmem_bags; i++) {
	bigmem_mem[i]= NULL;
	bigmem_len[i]= 0;
	bigmem_cap[i]= 0;
      }
    }
    else {
      int new_bags= bigmem_bags << 1;
      //cout << "Larger bigmem " << new_bags << LF;
      int new_bags_mask= new_bags-1;
      memorizer_ptrs* new_mem= tm_new_array<memorizer_ptrs> (new_bags);
      int* new_len= tm_new_array<int> (new_bags);
      int* new_cap= tm_new_array<int> (new_bags);
      for (int i=0; i<bigmem_bags; i++) {
	int j= i+ bigmem_bags;
	int len= bigmem_len[i];
	int cap= bigmem_cap[i];
	//cout << "bag " << i << ": " << len << ", " << cap << LF;
	if (len == 0) cap= 0;
	else while ((len<<1) <= cap && cap >= 4) cap= cap>>1;
	new_len[i]= 0;
	new_len[j]= 0;
	new_cap[i]= cap;
	new_cap[j]= cap;
	if (cap == 0) {
	  new_mem[i]= NULL;
	  new_mem[j]= NULL;
	}
	else {
	  new_mem[i]= tm_new_array<memorizer_ptr> (cap);
	  new_mem[j]= tm_new_array<memorizer_ptr> (cap);
	  for (int k=0; k<len; k++) {
	    memorizer_ptr mem_ptr= bigmem_mem[i][k];
	    int h= mem_ptr->hash () & new_bags_mask;
	    //cout << "  insert " << h << LF;
	    ASSERT (h == i || h == j, "failed assertion");
	    new_mem[h][new_len[h]++]= mem_ptr;
	  }
	}
	if (cap != 0) tm_delete_array (bigmem_mem[i]);
      }
      tm_delete_array (bigmem_mem);
      tm_delete_array (bigmem_len);
      tm_delete_array (bigmem_cap);
      bigmem_bags= new_bags;
      bigmem_mem = new_mem;
      bigmem_len = new_len;
      bigmem_cap = new_cap;
    }
    bigmem_bags_mask= bigmem_bags-1;
  }

  int h= ptr->hash () & bigmem_bags_mask;
  memorizer_ptrs a= bigmem_mem[h];
  int i, len= bigmem_len[h];
  for (i=0; i<len; i++)
    if (a[i]->type () == ptr->type () && a[i]->equal (ptr))
      return a[i];
  int cap= bigmem_cap[h];
  if (len >= cap) {
    if (cap == 0) {
      a  = tm_new_array<memorizer_ptr> (2);
      cap= 2;
    }
    else {
      int new_cap= cap<<1;
      memorizer_ptrs b= tm_new_array<memorizer_ptr> (new_cap);
      for (i=0; i<len; i++) b[i]= a[i];
      tm_delete_array (a);
      a  = b;
      cap= new_cap;
    }
    bigmem_mem[h]= a;
    bigmem_cap[h]= cap;
  }
  a[bigmem_len[h]++]= ptr;
  bigmem_size++;
  //cout << "Added [" << bigmem_size << ", " << ptr << "] ";
  //ptr->print (cout);
  //cout << LF;
  return ptr;
}
Example #11
0
int
unix_system (array<string> arg,
	     array<int> fd_in, array<string> str_in,
	     array<int> fd_out, array<string*> str_out) {
  // Run command arg[0] with arguments arg[i], i >= 1.
  // str_in[i] is sent to the file descriptor fd_in[i].
  // str_out[i] is filled from the file descriptor fd_out[i].
  // If str_in[i] is -1 then $$i automatically replaced by a valid
  // file descriptor in arg.
  if (N(arg) == 0) return 0;
  string which= recompose (arg, " ");
  int n_in= N(fd_in), n_out= N(fd_out);
  ASSERT(N(str_in)  == n_in, "size mismatch");
  ASSERT(N(str_out) == n_out, "size mismatch");
  array<_pipe_t> pp_in (n_in), pp_out (n_out);
  _file_actions_t file_actions;
  for (int i= 0; i < n_in; i++) {
    if (posix_spawn_file_actions_addclose
	(&file_actions.rep, pp_in[i].out ()) != 0) return -1;
    if (fd_in[i] >= 0) {
      if (posix_spawn_file_actions_adddup2
	  (&file_actions.rep, pp_in[i].in (), fd_in[i]) != 0) return -1;
      if (posix_spawn_file_actions_addclose
	  (&file_actions.rep, pp_in[i].in ()) != 0) return -1; } }
  for (int i= 0; i < n_out; i++) {
    if (posix_spawn_file_actions_addclose
	(&file_actions.rep, pp_out[i].in ()) != 0) return -1;
    if (posix_spawn_file_actions_adddup2
	(&file_actions.rep, pp_out[i].out (), fd_out[i]) != 0) return -1;
    if (posix_spawn_file_actions_addclose
	(&file_actions.rep, pp_out[i].out ()) != 0) return -1; }
  array<string> arg_= arg;
  for (int j= 0; j < N(arg); j++)
    for (int i= 0; i < n_in; i++)
      if (fd_in[i] < 0)
        arg_[j]= replace (arg_[j], "$$" * as_string (i),
	  	          as_string (pp_in[i].in ()));
  if (DEBUG_IO)
    debug_io << "unix_system, launching: " << arg_ << "\n"; 
  array<char*> _arg;
  for (int j= 0; j < N(arg_); j++)
    _arg << as_charp (arg_[j]);
  _arg << (char*) NULL;
  pid_t pid;
  int status= posix_spawnp (&pid, _arg[0], &file_actions.rep, NULL,
			    A(_arg), environ);
  for (int j= 0; j < N(arg_); j++)
    tm_delete_array (_arg[j]);
  if (status != 0) {
    if (DEBUG_IO) debug_io << "unix_system, failed" << "\n";
    return -1;
  }
  if (DEBUG_IO)
    debug_io << "unix_system, succeeded to create pid "
	     << pid << "\n";

  // close useless ports
  for (int i= 0; i < n_in ; i++) close (pp_in[i].in ());
  for (int i= 0; i < n_out; i++) close (pp_out[i].out ());

  // write to spawn process
  array<_channel> channels_in (n_in);
  array<pthread_t> threads_write (n_in);
  for (int i= 0; i < n_in; i++) {
    channels_in[i]._init_in (pp_in[i].out (), str_in[i], 1 << 12);
    if (pthread_create (&threads_write[i], NULL /* &attr */,
			_background_write_task,
			(void *) &(channels_in[i])))
      return -1;
  }

  // read from spawn process
  array<_channel> channels_out (n_out);
  array<pthread_t> threads_read (n_out);
  for (int i= 0; i < n_out; i++) {
    channels_out[i]._init_out (pp_out[i].in (), 1 << 12); 
    if (pthread_create (&threads_read[i], NULL /* &attr */,
			_background_read_task,
			(void *) &(channels_out[i])))
      return -1;
  }

  int wret;
  time_t last_wait_time= texmacs_time ();
  while ((wret= waitpid (pid, &status, WNOHANG)) == 0) {
    usleep (100);
    if (texmacs_time () - last_wait_time > 5000) {
      last_wait_time= texmacs_time ();
      _unix_system_warn (pid, which, "waiting spawn process");
    }
  }
  if (DEBUG_IO)
    debug_io << "unix_system, pid " << pid << " terminated" << "\n"; 

  // wait for terminating threads
  void* exit_status;
  int thread_status= 0;
  for (int i= 0; i < n_in; i++) {
    pthread_join (threads_write[i], &exit_status);
    if (channels_in[i].status < 0) thread_status= -1;
  }
  for (int i= 0; i < n_out; i++) {
    pthread_join (threads_read[i], &exit_status);
    *(str_out[i])= string (channels_out[i].data.data (),
                           channels_out[i].data.length ());
    if (channels_out[i].status < 0) thread_status= -1;
  }

  if (thread_status < 0) return thread_status;
  if (wret < 0 || WIFEXITED(status) == 0) return -1;
  return WEXITSTATUS(status);
}
Example #12
0
glyph_rep::~glyph_rep () {
  tm_delete_array (raster);
}
Example #13
0
 inline ~polynomial_rep () { if (a != NULL) tm_delete_array (a); }
Example #14
0
 inline ~hashset_rep () { tm_delete_array (a); }
Example #15
0
 inline ~array_rep () { if (n!=0) tm_delete_array (a); }