[Frugalware-darcs] pacman: pacman: use logarithm to count the number of needed space in cb_trans_progress()

VMiklos vmiklos at frugalware.org
Thu Mar 16 17:45:45 CET 2006


[pacman: use logarithm to count the number of needed space in cb_trans_progress()
VMiklos <vmiklos at frugalware.org>**20060129012715
 also a big cleanup of krix's shit ;)
 closes #298
] {
hunk ./configure.ac 193
+
+dnl Check for math
+AC_CHECK_LIB([m], [log10], [AC_CHECK_HEADER([math.h], [LIBM='-lm'])])
+if test -n "$LIBM"; then
+    LDFLAGS="$LDFLAGS $LIBM"
+else
+    AC_MSG_ERROR("math library not found!");
+fi
hunk ./src/pacman/trans.c 29
+#include <math.h>
hunk ./src/pacman/trans.c 146
-	int i, hash;
+	int i, hash, maxpkglen;
+	char addstr[] = "installing";
+	char upgstr[] = "upgrading";
+	char *ptr;
+
+	if (!pkgname)
+		return;
+	if (percent > 100)
+		return;
hunk ./src/pacman/trans.c 158
-		if (!pkgname)
-			break;
-		if (percent > 100)
-			break;
-		hash = percent/6.25;
-		if (howmany < 10) {
-			printf("(%d/%d) installing %s", remain, howmany, pkgname);
-		} else if ((howmany > 10) && (remain < 10)) {
-			printf("( %d/%d) installing %s", remain, howmany, pkgname);
-		} else if ((howmany > 10) && (remain > 10)) {
-			printf("(%d/%d) installing %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 10)) {
-			printf("(  %d/%d) installing %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 100)) {
-			printf("( %d/%d) installing %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 100)) {
-			printf("(%d/%d) installing %s", remain, howmany, pkgname);
-		} else {
-			printf("(%d/%d) installing %s", remain, howmany, pkgname);
-		}
-		if (strlen(pkgname)<35)
-			for (i=35-strlen(pkgname)-1; i>0; i--)
-				printf(" ");
-		printf("[");
-		for (i = 16; i > 0; i--) {
-			if (i >= 16 - hash)
-				printf("#");
-			else
-				printf("-");
-			}
-		MSG(CL, "] %3d%%\r", percent);
+			ptr = addstr;
hunk ./src/pacman/trans.c 162
-		if (!pkgname)
-			break;
-		if (percent > 100)
-			break;
-		hash = percent/6.25;
-		if (howmany < 10) {
-			printf("(%d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else if ((howmany > 10) && (remain < 10)) {
-			printf("( %d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else if ((howmany > 10) && (remain > 10)) {
-			printf("(%d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 10)) {
-			printf("(  %d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 100)) {
-			printf("( %d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else if ((howmany > 100) && (remain < 100)) {
-			printf("(%d/%d) upgrading  %s", remain, howmany, pkgname);
-		} else {
-			printf("(%d/%d) upgrading  %s", remain, howmany, pkgname);
-		}
-		if (strlen(pkgname)<35)
-			for (i=35-strlen(pkgname)-1; i>0; i--)
-				printf(" ");
-		printf("[");
-		for (i = 16; i > 0; i--) {
-			if (i >= 16 - hash)
-				printf("#");
-			else
-				printf("-");
-		}
-		MSG(CL, "] %3d%%\r", percent);
+			ptr = upgstr;
hunk ./src/pacman/trans.c 165
+	hash = percent/6.25;
+
+	// if the package name is too long, then slice the ending
+	maxpkglen=46-strlen(ptr)-(3+2*(int)log10(howmany));
+	if(strlen(pkgname)>maxpkglen)
+		pkgname[maxpkglen]='\0';
+
+	putchar('(');
+	for(i=0;i<(int)log10(howmany)-(int)log10(remain);i++)
+		putchar(' ');
+	printf("%d/%d) %s %s ", remain, howmany, ptr, pkgname);
+	if (strlen(pkgname)<maxpkglen)
+		for (i=maxpkglen-strlen(pkgname)-1; i>0; i--)
+			putchar(' ');
+	printf("[");
+	for (i = 16; i > 0; i--) {
+		if (i >= 16 - hash)
+			printf("#");
+		else
+			printf("-");
+	}
+	MSG(CL, "] %3d%%\r", percent);
}


More information about the Frugalware-darcs mailing list