[BACK]Return to misc.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-contrib / packages / src

File: [local] / OpenXM / src / asir-contrib / packages / src / Attic / misc.rr (download)

Revision 1.1, Wed Aug 22 01:52:44 2001 UTC (22 years, 10 months ago) by takayama
Branch: MAIN
CVS Tags: RELEASE_1_2_1

ox_work_dir() returns the working directory for OpenXM communication.
ox_new_file_name() returns a unique file name.

/* $OpenXM: OpenXM/src/asir-contrib/packages/src/misc.rr,v 1.1 2001/08/22 01:52:44 takayama Exp $ */

Misc_ox_work_dir_created = 0$
Misc_ox_file_name = 0$
def get_pid() {
  /* It should return the process id.
     This is a dummy function.  */
  return 1;
}
/* ox_work_dir() returns
   ~/OpenXM_tmp/pid
   If this direcotry does not exists, it creates the directory.
   If the environmental variable OpenXM_tmp is set, the value
   will be used.
*/
def ox_work_dir() {
  extern Misc_ox_work_dir_created;
  if (getenv("OpenXM_tmp") == 0) {
     Work_home = getenv("HOME")+"/OpenXM_tmp";
  }else{
     Work_home = getenv("OpenXM_tmp");
  }
  Work = Work_home+"/"+rtostr(get_pid());

  if (!Misc_ox_work_dir_created) {
    /* Unix dependent code to create a directory. */
    if (shell("test -d "+Work_home) != 0) {
      print("Working direcotry "+Work_home+" will be created.");
      if (shell("mkdir "+Work_home) != 0) {
         error("Could not create the directory "+Work_home);
      }
    }
    if (shell("test -d "+Work) != 0) {
      print("Working direcotry "+Work+" will be created.");
      if (shell("mkdir "+Work) != 0) {
         error("Could not create the directory "+Work);
      }
    }
    Misc_ox_work_dir_created = 1;
  }
  return Work;
}

def ox_remove_work_dir() {
  if (getenv("OpenXM_tmp") == 0) {
     Work_home = getenv("HOME")+"/OpenXM_tmp";
  }else{
     Work_home = getenv("OpenXM_tmp");
     /* Safety precaution. */
     if (Work_home == getenv("HOME") ||
         Work_home == "/" ||
         Work_home == "" ||
         Work_home == "." ||
         Work_home == ".." ) {
         error("ox_remove_work_dir():  Work_home seems to be wrong.");
     }
  }
  if (shell("test -d "+Work_home) == 0) {
     shell("rm -rf "+Work_home+" [0-9]*");
  }
  return Work_home;
}

def ox_new_file_name() {
  extern Misc_ox_file_name;
  Name = "work"+rtostr(Misc_ox_file_name);
  Misc_ox_file_name++;
  return Name;
}
end$