--- ./du2ps.1.org	2005-02-19 17:30:33.000000000 +0900
+++ ./du2ps.1	2009-05-29 16:55:00.000000000 +0900
@@ -2,7 +2,7 @@
 .\" Copyleft 1994-2005 nagae@media.t-kougei.ac.jp and mac@line.to
 .\" du2ps.man
 .\""
-.TH du2ps 1 "Feb 19, 2005"
+.TH du2ps 1 "Feb 13, 2009"
 .SH NAME
 du2ps \- filter for converting output of du to PostScript file
 .SH SYNOPSIS
@@ -81,6 +81,21 @@
 and
 .I height
 are the width and height of a BoundingBox.
+.TP
+.BI \-B " size"
+Specify the size of block unit for input. Default 512 byte.
+.TP
+.BI \-K
+Assume 1024-byte of block unit for input.
+.TP
+.BI \-k
+Specify 1K-byte unit for output. Default depend on input.
+.TP
+.BI \-m
+Specify 1M-byte unit for output.
+.TP
+.BI \-h
+Specify Human-readable output.
 .SH EXAMPLES
 .B " du | du2ps | lpr
 .IP
@@ -115,12 +130,20 @@
 The most left directory name becomes ``..'', and print
 ``The number of disk blocks used at''
 in the upper left corner.
+.PP
+.B " du -k ~ | du2ps -K -h | ps2pdf -sPAPERSIZE=a4 - /tmp/du2.pdf"
+.IP
+The most left directory name becomes your own home, and print
+``The number of disk blocks used at $HOME'' in the upper left corner.
+The generated ``/tmp/du2.pdf'' will be ``Human-readable'' format with
+``-k'' option of ``du'', ``-K'' and ``-h'' options of ``du2ps''.
 .SH SEE ALSO
 .BR du (1),
 .BR xdu (1)
 .SH AUTHORS
-Takanori Nagae <nagae@media.t-kougei.ac.jp> and
-Shigeru Makino <mac@line.to>
+Takanori Nagae <nagae@media.t-kougei.ac.jp>,
+Shigeru Makino <mac@line.to> and
+Taiji Yamada <taiji@aihara.co.jp>
 .PP
 The du2ps is based on xdu.
 The author of xdu is Phillip C. Dykstra <phil@BRL.MIL>.
--- ./du2ps.1j.org	2005-02-19 17:30:33.000000000 +0900
+++ ./du2ps.1j	2009-05-29 16:55:00.000000000 +0900
@@ -82,6 +82,21 @@
 ‚Æ
 .I height
 ‚ÍBoundingBox‚Ì•�‚Æ�‚‚³‚Å‚·�D
+.TP
+.BI \-B " size"
+“ü—Í‚Ìƒuƒ�ƒbƒNƒTƒCƒY’PˆÊ‚ÌƒTƒCƒY‚ðŽw’è‚µ‚Ü‚·�DƒfƒtƒHƒ‹ƒg‚Í 512 byte ‚Å‚·�D
+.TP
+.BI \-K
+“ü—Í‚Ìƒuƒ�ƒbƒNƒTƒCƒY’PˆÊ‚ÌƒTƒCƒY‚ð 1024 byte ‚Æ‚µ‚Ü‚·�D
+.TP
+.BI \-k
+�o—Í‚ÌƒTƒCƒY’PˆÊ‚ð 1K byte ‚Æ‚µ‚Ü‚·�DƒfƒtƒHƒ‹ƒg‚Í“ü—Í‚ÉˆË‘¶‚µ‚Ü‚·�D
+.TP
+.BI \-m
+�o—Í‚ÌƒTƒCƒY’PˆÊ‚ð 1M byte ‚Æ‚µ‚Ü‚·�D
+.TP
+.BI \-h
+�o—Í‚ÌƒTƒCƒY’PˆÊ‚ð�lŠÔ‚É“Ç‚Ý‚â‚·‚­Œˆ‚ß‚Ü‚·�D
 .SH EXAMPLES
 .B " du | du2ps | lpr
 .IP
@@ -115,6 +130,14 @@
 ˆê”Ô�¶‚ÌƒfƒBƒŒƒNƒgƒŠ–¼‚ª``..''‚É‚È‚è�C�¶Œ¨‚É
 ``The number of disk blocks used at''
 ‚Æ•\Ž¦‚³‚ê‚Ü‚·�D
+.PP
+.B " du -k ~ | du2ps -K -h | ps2pdf -sPAPERSIZE=a4 - /tmp/du2.pdf"
+.IP
+ˆê”Ô�¶‚ÌƒfƒBƒŒƒNƒgƒŠ‚ª–¼‚ª‚ ‚È‚½‚Ìƒz�[ƒ€‚É‚È‚è�C�¶Œ¨‚É
+``The number of disk blocks used at $HOME'' ‚Æ•\Ž¦‚³‚ê‚Ü‚·�D
+�¶�¬‚³‚ê‚½ ``/tmp/du2.pdf'' ‚Í ``du'' ƒRƒ}ƒ“ƒh‚Ì ``-k'' ƒIƒvƒVƒ‡ƒ“‹y‚Ñ
+``du2ps'' ƒRƒ}ƒ“ƒh‚Ì ``-K'', ``-h'' ƒIƒvƒVƒ‡ƒ“‚É‚æ‚Á‚Ä�C
+�lŠÔ‚É“Ç‚Ý‚â‚·‚¢Œ`Ž®‚Æ‚È‚è‚Ü‚·�D
 .SH SEE ALSO
 .BR du (1),
 .BR xdu (1)
--- ./du2ps.h.org	2005-02-19 17:30:33.000000000 +0900
+++ ./du2ps.h	2009-05-29 16:55:00.000000000 +0900
@@ -1,9 +1,10 @@
 /* $Id: du2ps.h,v 3.1 2005/02/19 08:29:53 mac Exp $
  *
  * du2ps is a modification of xdu
- * 1992 1994 2005
+ * 1992 1994 2005 2009
  * 	Takanori Nagae <nagae@media.t-kougei.ac.jp>
  *      Shigeru Makino <mac@line.to>
+ *      Taiji Yamada <taiji@aihara.co.jp>
  */
 /*
  * The following is the copyright & permission notices of xdu
@@ -40,6 +41,7 @@
 
 
 #define strdup(_s_) strcpy(malloc(strlen(_s_)+ 1),_s_)
+#define getopt scanopt
 
 #define MAXDEPTH  80    /* max elements in a path */
 
@@ -47,14 +49,28 @@
 #	define MAXPATH   4096  /* max total pathname length */
 #endif
 
+#ifndef NCOLS_PORTRAIT
 #define NCOLS_PORTRAIT 7
+#endif
+#ifndef NCOLS_LANDSCAPE
 #define NCOLS_LANDSCAPE 10 
+#endif
 #define MIN_DEPTH 0
+#ifndef MARGIN
 #define MARGIN 50
+#endif
+#ifndef FONT_SIZE
 #define FONT_SIZE 8
+#endif
+#ifndef FONT_FAMILY
 #define FONT_FAMILY "Times-Roman"
+#endif
+#ifndef LINE_WIDTH
 #define LINE_WIDTH 0.5
+#endif
+#ifndef HEAD_SEP
 #define HEAD_SEP 5.0
+#endif
 #define A3_WIDTH 841.889764
 #define A3_HEIGHT 1190.55118
 #define A4_WIDTH 595.275591
@@ -76,7 +92,7 @@
     struct _node_ *peer;  /* siblings */
     struct _node_ *child; /* list of children if !NULL */
     int nchild;		  /* number of children */
-    int size;             /* from here down */
+    unsigned long long size; /* from here down */
     char *name;
 } Node;
 
--- ./getopt.c.org	2005-02-19 17:30:33.000000000 +0900
+++ ./getopt.c	2009-05-29 16:55:00.000000000 +0900
@@ -18,6 +18,9 @@
 double paper_width, paper_height, margin, font_size, linewidth;
 char *font_family;
 int ps_type;
+unsigned long long in_unit = 512;
+int unit_type = 0; /* -1: Human-readable, 0: depend on input, 1: Kilobyte, 2:Megabyte,
+	3:Gigabyte, 4:Terabyte and 5:Petabyte, ... for output */
 
 static char *usage[] ={
 	"",
@@ -48,6 +51,11 @@
 	"  -lw size    ... line width",
 	"  -ncols num  ... number of columns",
 	"  -eps w h    ... output an epsfile contained in BoundingBox:0 0 w h",
+	"  -B size     ... specified-size byte unit input",
+	"  -K          ... 1024-byte (1K-byte) unit input",
+	"  -k          ... 1K-byte unit output",
+	"  -m          ... 1M-byte unit output",
+	"  -h          ... Human-readable output",
 	NULL,
 };
 
@@ -144,6 +152,21 @@
 			paper_height = atof(argv[i + 2]);
 			ps_type = EPS;
 			i += 3;
+		} else if(!strcmp("-B", argv[i])){
+			in_unit = strtoull(argv[i + 1], (char **)NULL, 10);
+			i += 2;
+		} else if(!strcmp("-K", argv[i])){
+			in_unit = 1024;
+			i++;
+		} else if(!strcmp("-k", argv[i])){
+			unit_type = 1;
+			i++;
+		} else if(!strcmp("-m", argv[i])){
+			unit_type = 2;
+			i++;
+		} else if(!strcmp("-h", argv[i])){
+			unit_type = -1;
+			i++;
 		} else {
 			fprintf(stderr, "unknown option %s\n", argv[i]);
 			print_message(usage);
--- ./Makefile.org	2005-02-19 17:30:33.000000000 +0900
+++ ./Makefile	2009-05-29 16:55:00.000000000 +0900
@@ -1,9 +1,11 @@
 # du2ps makefile
 
+prefix=/opt/local
 LIB = -lm
 NAME = du2ps
 #CC = gcc
-CFLAGS= -Wall -pedantic
+CPPFLAGS=-DNCOLS_PORTRAIT=8 -DNCOLS_LANDSCAPE=12 -DMARGIN=40 -DFONT_SIZE=6 -DFONT_FAMILY=\"Times-Roman\" -DLINE_WIDTH=.25
+CFLAGS= -Wall -pedantic -std=gnu99
 
 OBJ = $(NAME).o nodeop.o getopt.o
 BINDIR = .
@@ -15,3 +17,10 @@
 	rm -f $(BINDIR)/$(NAME) *.o *~ tmp
 
 $(OBJ): du2ps.h
+
+install:
+	cp du2ps $(prefix)/bin
+
+install.man:
+	chmod -x du2ps.1
+	cp du2ps.1 $(prefix)/man/man1
--- ./nodeop.c.org	2005-02-19 17:30:33.000000000 +0900
+++ ./nodeop.c	2009-05-29 16:55:00.000000000 +0900
@@ -14,6 +14,8 @@
  */
 #include "du2ps.h"
 unsigned dhue;
+extern unsigned long long in_unit;
+extern int unit_type;
 
 Node *top;
 int (*cmp)();
@@ -22,9 +24,40 @@
 drawrect(Node *nodep, double y, double height, int depth,
 		unsigned h, unsigned s, unsigned b)
 {
-	printf("%d (%s \\(%d\\)) %.2f %.2f %f %f %f\n",
-        depth, nodep->name, nodep->size, height, y,
-	(double) h / 0x8000 , (double) s, (double) b);
+	unsigned long long u = 1;
+	int i = 0, pi = 0;
+	char *p[] = {
+	  "B",
+	  "K",
+	  "M",
+	  "G",
+	  "T",
+	  "P",
+	};
+
+	switch (unit_type) {
+	case 0:
+		printf("%d (%s \\(%llu\\)) %.2f %.2f %f %f %f\n",
+			depth, nodep->name, nodep->size, height, y,
+			(double) h / 0x8000 , (double) s, (double) b);
+		break;
+	default:
+		if(unit_type > 0){
+			pi = unit_type;
+			while(i++ < pi)
+				u *= 1024;
+		}
+		else {
+			while(pi+1 < sizeof(p)/sizeof(p[0]) && nodep->size*(in_unit?in_unit:1)/(u*1024) > 0){
+				u *= 1024;
+				pi++;
+			}
+		}
+		printf("%d (%s \\(%g%s\\)) %.2f %.2f %f %f %f\n",
+			depth, nodep->name, (float)nodep->size*(in_unit?in_unit:1)/u, (unit_type > 0)?"":p[pi], height, y,
+			(double) h / 0x8000 , (double) s, (double) b);
+		break;
+	}
 }
 
 /*
@@ -49,7 +82,7 @@
 
 
 static void
-addtree(Node *nodep, char **path, int size)
+addtree(Node *nodep, char **path, unsigned long long size)
 {
 	Node *child;
 
@@ -84,7 +117,7 @@
 int
 cmp_size(Node **p, Node **q)
 {
-	return ((*q)->size - (*p)->size);
+	return ((*q)->size > (*p)->size) ? 1 : ((*q)->size < (*p)->size) ? -1 : 0;
 }
 
 static void
@@ -168,14 +201,27 @@
 char *
 parse(void)
 {
-	char buf[MAXLL], name[MAXPATH+2], *n;
+	char fmt[1024], buf[MAXLL], name[MAXPATH+2], *n;
 	char *path[MAXDEPTH]; /* break up path into this list */
-	int depth, size;
+	int depth;
+	unsigned long long size;
 	int i;
+	float z;
+	char u;
 
+	snprintf(fmt, sizeof(fmt), "%%f%%c %%%lu[^\n]\n", (unsigned long)sizeof(name)-1);
 	top = makenode("..");
 	while(fgets(buf, MAXLL, stdin)  != 0){
-		sscanf(buf, "%d %s\n", &size, n = name);
+		sscanf(buf, fmt, &z, &u, n = name);
+		switch (u) {
+		case 'P': z *= 1024;
+		case 'T': z *= 1024;
+		case 'G': z *= 1024;
+		case 'M': z *= 1024;
+		case 'K': z *= 1024;
+		case 'B': in_unit = 0;
+		default: size = z; break;
+		}
 		if('/' == *n) {
 			if ( strlen(name) > MAXPATH ) {
 				fprintf(stderr, "too long path\n");
