diff scripts/pkg/pkg.m @ 5947:009fa69b6182

[project @ 2006-08-21 16:15:20 by jwe]
author jwe
date Mon, 21 Aug 2006 16:15:20 +0000
parents e86311bdecc9
children fc46f9c99028
line wrap: on
line diff
--- a/scripts/pkg/pkg.m	Mon Aug 21 15:57:09 2006 +0000
+++ b/scripts/pkg/pkg.m	Mon Aug 21 16:15:20 2006 +0000
@@ -27,6 +27,9 @@
 ## @deftypefnx{Command} pkg load -nodeps @var{pkg-name} ...
 ## XXX: Where's the docs?
 ## @end deftypefn
+
+## PKG_ADD: mark_as_command pkg
+
 function [local_packages, global_packages] = pkg(varargin)
     ## Handle input
     if (length(varargin) == 0 || !iscellstr(varargin))
@@ -89,7 +92,11 @@
     if (issuperuser())
         global_install = true;
         if (!prefix_exist)
-            OCTAVE_PACKAGE_PREFIX = [OCTAVE_HOME "share/octave/packages/"];
+	    if (strcmp(OCTAVE_HOME()(end),"/"))
+                OCTAVE_PACKAGE_PREFIX = [OCTAVE_HOME "share/octave/packages/"];
+	    else
+		OCTAVE_PACKAGE_PREFIX = [OCTAVE_HOME "/share/octave/packages/"];
+           endif
         endif
     else
         global_install = false;
@@ -123,9 +130,7 @@
     endif
    
     ## Uncompress the packages and read the DESCRIPTION files
-    tmpdirs = cell(1, length(files));
-    packdirs = cell(1, length(files));
-    descriptions = cell(1, length(files));
+    tmpdirs = packdirs = descriptions = {};
     try
         ## Unpack the package files and read the DESCRIPTION files
         packages_to_uninstall = [];
@@ -134,7 +139,7 @@
             
             ## Create a temporary directory 
             tmpdir = tmpnam();
-            tmpdirs{i} = tmpdir;
+            tmpdirs{end+1} = tmpdir;
             [status, msg] = mkdir(tmpdir);
             if (status != 1)
                 error("Couldn't create temporary directory: %s\n", msg);
@@ -143,35 +148,37 @@
             ## Uncompress the package
             untar(tgz, tmpdir);
 
-            ## Get the name of the directory produced by tar
+            ## Get the name of the directories produced by tar
             [dirlist, err, msg] = readdir(tmpdir);
             if (err)
                 error("Couldn't read directory produced by tar: %s\n", msg);
             endif
-            packdir = [tmpdir "/" dirlist{end} "/"];
-            packdirs{i} = packdir;
+            
+            for k = 3:length(dirlist) # the two first entries of dirlist are "." and ".."
+                packdir = [tmpdir "/" dirlist{k} "/"];
+                packdirs{end+1} = packdir;
 
-            ## Make sure the package contains necessary files
-            verify_directory(packdir);
+                ## Make sure the package contains necessary files
+                verify_directory(packdir);
 
-            ## Read the DESCRIPTION file
-            filename = [packdir "DESCRIPTION"];
-            desc = get_description(filename);
+                ## Read the DESCRIPTION file
+                filename = [packdir "DESCRIPTION"];
+                desc = get_description(filename);
 
-            ## Set default installation directory
-            desc.dir = [prefix "/" desc.name "-" desc.version];
+                ## Set default installation directory
+                desc.dir = [prefix "/" desc.name "-" desc.version];
             
-            ## Save desc
-            descriptions{i} = desc;
+                ## Save desc
+                descriptions{end+1} = desc;
 
-            ## Are any of the new packages already installed?
-            ## If so we'll remove the old version.
-            for j = 1:length(packages)
-                if (strcmp(packages{j}.name, desc.name))
-                    packages_to_uninstall(end+1) = j;
-                endif
-            endfor
-            
+                ## Are any of the new packages already installed?
+                ## If so we'll remove the old version.
+                for j = 1:length(packages)
+                    if (strcmp(packages{j}.name, desc.name))
+                        packages_to_uninstall(end+1) = j;
+                    endif
+                endfor
+            endfor        
         endfor
     catch
         ## Something went wrong, delete tmpdirs