home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- #include "sys.h"
- #include "smg.h"
- #include "trc_dir.h"
- #include "dir_err.h"
- #include "dir_sos.h"
-
- // *************************************************************************
- void sos_Object_Directory::local_initialize(sos_Object_Directory dir)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::local_initialize");
- TT (dir_H, T_ENTER);
-
- dir.set_name (sos_String::copy (dir.get_name(), dir.container()));
-
- TT (dir_H, T_LEAVE);
- }
-
- // *************************************************************************
- void sos_Object_Directory::local_finalize(sos_Object_Directory dir)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::local_finalize");
- TT (dir_H, T_ENTER);
-
- dir.get_name().destroy();
- agg_iterate_association (dir, sos_String name, sos_Object elem)
- name.destroy();
- agg_iterate_association_end (dir, name, elem);
-
- TT (dir_H, T_LEAVE);
- }
-
-
- // *************************************************************************
- sos_Object_Directory sos_Object_Directory::root()
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::root");
- TT (dir_H, T_ENTER);
-
- sos_Bool open = (sos_Bool) ((ROOT_CONTAINER.status() == READABLE) OR
- (ROOT_CONTAINER.status() == WRITEABLE));
-
- if (NOT open) ROOT_CONTAINER.open (READING, WAITING);
-
- sos_Object_Directory d =
- sos_Object_Directory::make (ROOT_CONTAINER.root_object());
-
- if (NOT open) ROOT_CONTAINER.close ();
-
- TT (dir_H, T_LEAVE);
-
- return d;
- }
-
- // *************************************************************************
- sos_Object sos_Object_Directory::lookup(sos_String path)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::lookup");
- TT (dir_H, T_ENTER);
-
- sos_Object result = sos_Object_Directory::root();
- sos_Object_Directory dir;
- smg_String s0 = path;
- sos_Cstring s = s0.make_Cstring (SMG_BORROW);
- sos_Cstring name = new char[strlen(s)];
-
- for (;;)
- { if (s[0] == '/' AND result.isa (sos_Object_Directory_type))
- dir = sos_Object_Directory::make (result);
- else
- { result = sos_Object_Directory::make (NO_OBJECT);
- break;
- }
- if (*++s == EOS)
- break;
- sscanf (s, "%[^/]", name);
- if (name[0] != EOS)
- { sos_String str = smg_String (name).make_String (TEMP_CONTAINER);
- result = dir [str];
- str.destroy();
- s += strlen (name);
- if (result == NO_OBJECT OR s[0] == EOS)
- break;
- }
- }
- delete name;
-
- TT (dir_H, T_LEAVE);
-
- return result;
- }
-
- // *************************************************************************
- void sos_Object_Directory::insert(sos_Object so, sos_Object o)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::insert");
- TT (dir_H, T_ENTER);
-
- sos_String s = sos_String::make (so);
- sos_String name;
- if (self.is_key (s))
- name = s;
- else
- name = sos_String::copy (s, self.container());
- sos_Object_sos_Object_Mapping::insert (name, o);
- TT (dir_H, T_LEAVE);
- }
-
-
- // *************************************************************************
- void sos_Object_Directory::remove(sos_Object so)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::remove");
- TT (dir_H, T_ENTER);
-
- sos_String s = sos_String::make (so);
- sos_Cursor c = self.open_cursor ();
- self.move_cursor (c, s);
- sos_Object name = self.get_key (c);
- sos_Object_sos_Object_Mapping::remove (s);
- name.destroy();
- self.close_cursor (c);
-
- TT (dir_H, T_LEAVE);
- }
-
- static sos_Object_Directory *wd;
-
- // *************************************************************************
- void sos_Object_Directory::set_wd (sos_String path)
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::set_wd");
- TT (dir_H, T_ENTER);
-
- sos_Object d = sos_Object_Directory::lookup (path);
-
- if (d == NO_OBJECT OR NOT d.isa (sos_Object_Directory_type))
- { sos_Cstring pname = path.make_Cstring();
- err_raise (err_SYS, err_DIR_NO_DIR, pname);
- delete pname;
- }
- else
- { wd = new sos_Object_Directory;
- *wd = sos_Object_Directory::make (d);
- }
-
- TT (dir_H, T_LEAVE);
- }
-
- // *************************************************************************
- void sos_Object_Directory::set_wd_from_env ()
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::set_wd_from_env");
- TT (dir_H, T_ENTER);
-
- sos_Cstring e=getenv("SOSDIR");
- if (e==0)
- err_raise (err_SYS, err_DIR_NO_DIR, NULL, FALSE);
- else
- {
- sos_String s = smg_String (e).make_String (TEMP_CONTAINER);
- sos_Object_Directory::set_wd(s);
- s.destroy();
- }
-
- TT (dir_H, T_LEAVE);
- }
-
- // *************************************************************************
- sos_Object_Directory sos_Object_Directory::get_wd ()
- // *************************************************************************
- {
- T_PROC ("sos_Object_Directory::get_wd");
- TT (dir_H, T_ENTER);
-
- sos_Object_Directory result;
-
- if (wd)
- result = *wd;
- else
- { err_raise (err_SYS, err_DIR_NO_WD, NULL, FALSE);;
- result = sos_Object_Directory::make (NO_OBJECT);
- }
-
- TT (dir_H, T_LEAVE);
- return result;
- }
-