Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2/.git;a=commitdiff;h=66292c5716a9d02037cf999e7fe79238793902a2

commit 66292c5716a9d02037cf999e7fe79238793902a2
Author: VMiklos <[EMAIL PROTECTED]>
Date:   Wed Jul 25 00:23:01 2007 +0200

libpacman: new PM_OPT_DLREMAIN and PM_OPT_DLHOWMANY options

diff --git a/lib/libpacman/handle.c b/lib/libpacman/handle.c
index a4ceac0..750e5a6 100644
--- a/lib/libpacman/handle.c
+++ b/lib/libpacman/handle.c
@@ -259,6 +259,12 @@ int _pacman_handle_set_option(pmhandle_t *handle, unsigned 
char val, unsigned lo
case PM_OPT_DLETA_S:
pm_dleta_s = (unsigned char *)data;
break;
+               case PM_OPT_DLREMAIN:
+                       handle->dlremain = (int *)data;
+               break;
+               case PM_OPT_DLHOWMANY:
+                       handle->dlhowmany = (int *)data;
+               break;
case PM_OPT_UPGRADEDELAY:
handle->upgradedelay = data;
break;
@@ -354,6 +360,8 @@ int _pacman_handle_get_option(pmhandle_t *handle, unsigned 
char val, long *data)
case PM_OPT_DLETA_H:   *data = (long)pm_dleta_h; break;
case PM_OPT_DLETA_M:   *data = (long)pm_dleta_m; break;
case PM_OPT_DLETA_S:   *data = (long)pm_dleta_s; break;
+               case PM_OPT_DLREMAIN:  *data = (long)handle->dlremain; break;
+               case PM_OPT_DLHOWMANY: *data = (long)handle->dlhowmany; break;
case PM_OPT_PROXYHOST: *data = (long)handle->proxyhost; break;
case PM_OPT_PROXYPORT: *data = handle->proxyport; break;
case PM_OPT_XFERCOMMAND: *data = (long)handle->xfercommand; break;
diff --git a/lib/libpacman/handle.h b/lib/libpacman/handle.h
index 1c5d162..19759e1 100644
--- a/lib/libpacman/handle.h
+++ b/lib/libpacman/handle.h
@@ -60,6 +60,8 @@ typedef struct __pmhandle_t {
unsigned short maxtries; /* for downloading */
pmlist_t *needles; /* for searching */
char *language;
+       int *dlremain;
+       int *dlhowmany;
} pmhandle_t;

extern pmhandle_t *handle;
diff --git a/lib/libpacman/pacman.h b/lib/libpacman/pacman.h
index 1d28668..2b7801c 100644
--- a/lib/libpacman/pacman.h
+++ b/lib/libpacman/pacman.h
@@ -117,7 +117,9 @@ enum {
PM_OPT_CHOMP,
PM_OPT_NEEDLES,
PM_OPT_MAXTRIES,
-       PM_OPT_OLDDELAY
+       PM_OPT_OLDDELAY,
+       PM_OPT_DLREMAIN,
+       PM_OPT_DLHOWMANY
};

int pacman_set_option(unsigned char parm, unsigned long data);
diff --git a/src/pacman-g2/download.c b/src/pacman-g2/download.c
index 4df1294..ea27df8 100644
--- a/src/pacman-g2/download.c
+++ b/src/pacman-g2/download.c
@@ -29,6 +29,7 @@
#include <time.h>
#include <sys/time.h>
#include <libintl.h>
+#include <math.h>

#include <pacman.h>
/* pacman-g2 */
@@ -44,7 +45,7 @@ int offset;
struct timeval t0, t;
float rate;
int xfered1;
-unsigned int eta_h, eta_m, eta_s;
+unsigned int eta_h, eta_m, eta_s, remain = 1, howmany = 10;

/* pacman options */
extern config_t *config;
@@ -65,6 +66,7 @@ int log_progress(PM_NETBUF *ctl, int xfered, void *arg)
int chomp;
static unsigned short mouth;
static unsigned int   lastcur = 0;
+       unsigned int maxpkglen;

/* we don't need that parameter */
ctl=NULL;
@@ -103,7 +105,18 @@ int log_progress(PM_NETBUF *ctl, int xfered, void *arg)
eta_s -= eta_m * 60;
}

-       printf(" %s [", sync_fnm);
+       // if the package name is too long, then slice the ending
+       maxpkglen=PM_DLFNM_LEN-(3+2*(int)log10(howmany));
+       if(strlen(sync_fnm)>maxpkglen)
+               sync_fnm[maxpkglen-1]='\0';
+
+       putchar('(');
+       for(i=0;i<(int)log10(howmany)-(int)log10(remain);i++)
+               putchar(' ');
+       printf("%d/%d) %s [", remain, howmany, sync_fnm);
+       if (strlen(sync_fnm)<maxpkglen)
+               for (i=maxpkglen-strlen(sync_fnm)-1; i>0; i--)
+                       putchar(' ');
cur = (int)((maxcols-64)*pct/100);
for(i = 0; i < maxcols-64; i++) {
if(chomp) {
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to