1% -*- slang -*- 2 3% This file gets loaded whenever slsh runs. Its primary purpose is to define 4% some functions that are useful in scripts, and to set up some local paths 5 6private define dir_exists (dir) 7{ 8 if (dir == NULL) return 0; 9 variable s = stat_file (dir); 10 if (s == NULL) return 0; 11 return stat_is ("dir", s.st_mode); 12} 13 14private define check_dirs (dirs) 15{ 16 if (dirs == NULL) 17 return NULL; 18 19 variable new_dirs = String_Type[0]; 20 foreach (strchop (dirs, path_get_delimiter(), 0)) 21 { 22 variable dir = (); 23 if (dir_exists (dir)) 24 new_dirs = [new_dirs, dir]; 25 } 26 if (length (new_dirs) == 0) 27 return NULL; 28 return strjoin (new_dirs, char (path_get_delimiter())); 29} 30 31%!%+ 32%\function{prepend_to_slang_load_path} 33%\synopsis{Prepend a directory to the load-path} 34%\usage{prepend_to_slang_load_path (String_Type dir)} 35%\description 36% This function adds a directory to the beginning of the interpreter's 37% load-path. 38%\seealso{append_to_slang_load_path, set_slang_load_path} 39%!%- 40public define prepend_to_slang_load_path (p) 41{ 42 p = check_dirs (p); 43 if (p != NULL) 44 set_slang_load_path (sprintf ("%s%c%s", p, path_get_delimiter (), get_slang_load_path ())); 45} 46 47%!%+ 48%\function{append_to_slang_load_path} 49%\synopsis{Append a directory to the load-path} 50%\usage{append_to_slang_load_path (String_Type dir)} 51%\description 52% This function adds a directory to the end of the interpreter's 53% load-path. 54%\seealso{prepend_to_slang_load_path, set_slang_load_path} 55%!%- 56public define append_to_slang_load_path (p) 57{ 58 p = check_dirs (p); 59 if (p != NULL) 60 set_slang_load_path (sprintf ("%s%c%s", get_slang_load_path (), path_get_delimiter (), p)); 61} 62 63% This function gets called from slsh after loading this file 64public define __slsh_startup_hook () 65{ 66 () = evalfile ("autoload.sl"); 67#ifdef __INTERACTIVE__ 68 () = evalfile ("slshrl.sl"); 69#endif 70} 71prepend_to_slang_load_path (getenv (SLSH_PATH_ENV)); 72 73% Add local additions here 74 75