added --percent, --hash
authorroot <devnull@localhost>
Mon, 22 Jan 1996 21:12:55 +0000 (21:12 +0000)
committerroot <devnull@localhost>
Mon, 22 Jan 1996 21:12:55 +0000 (21:12 +0000)
CVS patchset: 218
CVS date: 1996/01/22 21:12:55

install.c
install.h

index 76e6a9b..48be717 100644 (file)
--- a/install.c
+++ b/install.c
@@ -1,19 +1,59 @@
 #include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "install.h"
 #include "lib/rpmlib.h"
 #include "messages.h"
 
-void doInstall(char * prefix, char * arg, int test, int installFlags) {
+static int hashesPrinted = 0;
+
+static void printHash(const unsigned long amount, const unsigned long total);
+static void printPercent(const unsigned long amount, const unsigned long total);
+
+static void printHash(const unsigned long amount, const unsigned long total) {
+    int hashesNeeded;
+
+    if (hashesPrinted != 50) {
+       hashesNeeded = 50 * (((float) amount) / total);
+       while (hashesNeeded > hashesPrinted) {
+           printf("#");
+           hashesPrinted++;
+       }
+       fflush(stdout);
+       hashesPrinted = hashesNeeded;
+
+       if (hashesPrinted == 50)
+           printf("\n");
+    }
+}
+
+static void printPercent(const unsigned long amount, const unsigned long total) 
+{
+    printf("%%%% %f\n", (float) (((float) amount) / total) * 100);
+}
+
+void doInstall(char * prefix, char * arg, int installFlags, int interfaceFlags) {
     rpmdb db;
     int fd;
     int mode, rc;
+    char * chptr;
+    notifyFunction fn;
 
-    if (test) 
+    hashesPrinted = 0;
+
+    if (installFlags & INSTALL_TEST) 
        mode = O_RDONLY;
     else
        mode = O_RDWR | O_EXCL;
+
+    if (interfaceFlags & RPMINSTALL_PERCENT)
+       fn = printPercent;
+    else if (interfaceFlags & RPMINSTALL_HASH)
+       fn = printHash;
+    else
+       fn = NULL;
        
     if (!rpmdbOpen(prefix, &db, mode, 0644)) {
        /* try opening it O_CREAT */
@@ -33,7 +73,20 @@ void doInstall(char * prefix, char * arg, int test, int installFlags) {
        return;
     }
 
-    rc = rpmInstallPackage(prefix, db, fd, installFlags, test);
+    if (interfaceFlags & RPMINSTALL_PERCENT) 
+       printf("%%f %s\n", arg);
+    else if (isVerbose() && (interfaceFlags & RPMINSTALL_HASH)) {
+       chptr = strrchr(arg, '/');
+       if (!chptr)
+           chptr = arg;
+       else
+           chptr++;
+
+       printf("%-28s", chptr);
+    } else if (isVerbose())
+       printf("Installing %s\n", arg);
+
+    rc = rpmInstallPackage(prefix, db, fd, installFlags, fn);
     if (rc == 1) {
        fprintf(stderr, "error: %s cannot be installed\n", arg);
     }
index ebd3f92..34b3fa0 100644 (file)
--- a/install.h
+++ b/install.h
@@ -1,7 +1,11 @@
 #ifndef _H_INSTALL
 #define _H_INSTALL
 
-void doInstall(char * prefix, char * arg, int test, int installFlags);
+#define RPMINSTALL_PERCENT 1
+#define RPMINSTALL_HASH           2
+
+void doInstall(char * prefix, char * arg, int installFlags,
+              int interfaceFlags);
 void doUninstall(char * prefix, char * arg, int test, int uninstallFlags);
 
 #endif