Back to index

texmacs  1.0.7.15
sys_utils.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : sys_utils.cpp
00004 * DESCRIPTION: file handling
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "sys_utils.hpp"
00013 #include "file.hpp"
00014 #include "tree.hpp"
00015 #ifdef OS_WIN32
00016 #  include <sys/misc.h>
00017 #endif
00018 
00019 #if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__))
00020 #  include "Qt/qt_sys_utils.hpp"
00021 #else
00022 #  include "Unix/unix_sys_utils.hpp"
00023 #endif
00024 
00025 int script_status = 1;
00026 
00027 /******************************************************************************
00028 * System functions
00029 ******************************************************************************/
00030 
00031 static int
00032 system (string s, string& result) {
00033 #if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__))
00034   int r= qt_system (s, result);
00035 #else
00036   int r= unix_system (s, result);
00037 #endif  
00038   return r;
00039 }
00040 
00041 int
00042 system (string s) {
00043   if (DEBUG_STD) cerr << "TeXmacs] System: " << s << "\n";
00044   if (DEBUG_VERBOSE) {
00045     string result;
00046     int r= system (s, result);
00047     cerr << result;
00048     return r;
00049   }
00050   else {
00051 #if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__))
00052     // if (starts (s, "convert ")) return 1;
00053     return qt_system (s);
00054 #else
00055     return unix_system (s);
00056 #endif
00057   }
00058 }
00059 
00060 string
00061 eval_system (string s) {
00062   string result;
00063   (void) system (s, result);
00064   return result;
00065 }
00066 
00067 string
00068 var_eval_system (string s) {
00069   string r= eval_system (s);
00070   while ((N(r)>0) && (r[N(r)-1]=='\n')) r= r (0,N(r)-1);
00071   return r;
00072 }
00073 
00074 string
00075 get_env (string var) {
00076   char* _var= as_charp (var);
00077   char* _ret= getenv (_var);
00078   tm_delete_array (_var);
00079   if (_ret==NULL) {
00080     if (var == "PWD") return get_env ("HOME");
00081     return "";
00082   }
00083   string ret (_ret);
00084   return ret;
00085   // do not delete _ret !
00086 }
00087 
00088 void
00089 set_env (string var, string with) {
00090 #if defined(STD_SETENV) && !defined(__MINGW32__)
00091   char* _var = as_charp (var);
00092   char* _with= as_charp (with);
00093   setenv (_var, _with, 1);
00094   tm_delete_array(_var);
00095   tm_delete_array(_with);
00096 #else
00097   char* _varw= as_charp (var * "=" * with);
00098   (void) putenv (_varw);
00099   // do not delete _varw !!!
00100   // -> known memory leak, but solution more complex than it is worth
00101 #endif
00102 }