Branch: Tag:

2003-05-31

2003-05-31 12:47:29 by Martin Stjernholm <mast@lysator.liu.se>

Cleaned up get_clean_program_path for external use. It's now called
program_path_to_name.

Rev: lib/master.pike.in:1.285

6:   // Pike is distributed under GPL, LGPL and MPL. See the file COPYING   // for more information.   // - // $Id: master.pike.in,v 1.284 2003/05/31 11:05:35 mast Exp $ + // $Id: master.pike.in,v 1.285 2003/05/31 12:47:29 mast Exp $      #pike __REAL_VERSION__   
2294:    if (sizeof(cwd) && (cwd[-1] != '/')) {    cwd += "/";    } -  if(s[..sizeof(cwd)-1]==cwd) return s[sizeof(cwd)..]; +  if(has_prefix (s, cwd)) return s[sizeof(cwd)..];    };    return s;   }
2648:   }       - static string get_clean_program_path ( program p, string pref1, -  string suff1, string suff2 ) + string program_path_to_name ( string path, +  void|string module_prefix, void|string module_suffix, +  void|string object_suffix ) + //! Converts a module path on the form @expr{"Foo.pmod/Bar.pmod"@} or + //! @expr{"/path/to/pike/lib/modules/Foo.pmod/Bar.pmod"@} to a module + //! identifier on the form @expr{"Foo.Bar"@}. + //! + //! If @[module_prefix] or @[module_suffix] are given, they are + //! prepended and appended, respectively, to the returned string if + //! it's a module file (i.e. ends with @expr{".pmod"@} or + //! @expr{".so"@}). If @[object_suffix] is given, it's appended to the + //! returned string if it's an object file (i.e. ends with + //! @expr{".pike"@}).   {    array(string) sort_paths_by_length(array(string) paths)    {    sort(map(paths, sizeof), paths);    return reverse(paths);    }; -  string path = programs_reverse_lookup (p); -  if (path) { -  if (path == "/master") return "master"+suff2; +  +  if (path == "/master") return "master" + (object_suffix || ""); +     foreach(sort_paths_by_length(map(pike_module_path - ({""}),    lambda(string s) {    if (s[-1] == '/') return s;
2670:    break;    }    } +  + #if 0 +  // This seems broken. Why should the current directory or the +  // setting of SHORT_PIKE_ERRORS etc affect the module identifiers? +  // /mast    path = trim_file_name(path); -  + #endif +     string modname = replace(path, ".pmod/", ".");    if(search(modname, "/")<0) path=modname; -  +     if (has_suffix(path, ".module.pmod")) { -  return pref1+path[..sizeof(path)-13]+suff1; +  return (module_prefix || "") + path[..sizeof(path)-13] + (module_suffix || "");    }    if (has_suffix(path, ".pmod")) { -  return pref1+path[..sizeof(path)-6]+suff1; +  return (module_prefix || "") + path[..sizeof(path)-6] + (module_suffix || "");    }    if (has_suffix(path, ".so")) { -  return pref1+path[..sizeof(path)-4]+suff1; +  return (module_prefix || "") + path[..sizeof(path)-4] + (module_suffix || "");    }    if (has_suffix(path, ".pike")) { -  return path[..sizeof(path)-6]+suff2; +  return path[..sizeof(path)-6] + (object_suffix || "");    } -  return path + suff2; +  return path + (object_suffix || "");   } -  return 0; - } +          //! Describe the path to the module @[mod].
2733:    }    if (!object_program(parent_fun)) {    // We might be a top-level entity. -  string path = get_clean_program_path(parent_fun, "", ".", "()->"); -  if(path) return path; +  if (string path = programs_reverse_lookup (parent_fun)) +  return program_path_to_name(path, "", ".", "()->");    }    // Begin by describing our parent.    array(object) parent_obj = ({ 0 });
2819:    }    };    if(objectp (objects[parent_fun])) -  if(s=get_clean_program_path(parent_fun, "", "", "()")) +  if ((s = programs_reverse_lookup (parent_fun)) && +  (s=program_path_to_name(s, "", "", "()")))    return s;    /* Try identifying the program. */    if(( s=describe_program(parent_fun) ))
2838:    return "object_program(_static_modules)";       if(programp(p) && -  (s=get_clean_program_path([program]p, "object_program(", ")", ""))) +  (s = programs_reverse_lookup ([program] p)) && +  (s=program_path_to_name(s, "object_program(", ")", "")))    return s;       if(object|program tmp=(function_object(p) || function_program(p))) {