--- ./du2ps.1.org 2005-02-19 17:30:33.000000000 +0900 +++ ./du2ps.1 2009-02-13 18:02:52.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 and -Shigeru Makino +Takanori Nagae , +Shigeru Makino and +Taiji Yamada .PP The du2ps is based on xdu. The author of xdu is Phillip C. Dykstra . --- ./du2ps.1j.org 2005-02-19 17:30:33.000000000 +0900 +++ ./du2ps.1j 2009-02-13 18:13:11.000000000 +0900 @@ -82,6 +82,21 @@ と .I height はBoundingBoxの幅と高さです. +.TP +.BI \-B " size" +入力のブロックサイズ単位のサイズを指定します.デフォルトは 512 byte です. +.TP +.BI \-K +入力のブロックサイズ単位のサイズを 1024 byte とします. +.TP +.BI \-k +出力のサイズ単位を 1K byte とします.デフォルトは入力に依存します. +.TP +.BI \-m +出力のサイズ単位を 1M byte とします. +.TP +.BI \-h +出力のサイズ単位を人間に読みやすく決めます. .SH EXAMPLES .B " du | du2ps | lpr .IP @@ -115,6 +130,14 @@ 一番左のディレクトリ名が``..''になり,左肩に ``The number of disk blocks used at'' と表示されます. +.PP +.B " du -k ~ | du2ps -K -h | ps2pdf -sPAPERSIZE=a4 - /tmp/du2.pdf" +.IP +一番左のディレクトリが名があなたのホームになり,左肩に +``The number of disk blocks used at $HOME'' と表示されます. +生成された ``/tmp/du2.pdf'' は ``du'' コマンドの ``-k'' オプション及び +``du2ps'' コマンドの ``-K'', ``-h'' オプションによって, +人間に読みやすい形式となります. .SH SEE ALSO .BR du (1), .BR xdu (1) --- ./du2ps.h.org 2005-02-19 17:30:33.000000000 +0900 +++ ./du2ps.h 2009-02-13 17:10:06.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 * Shigeru Makino + * Taiji Yamada */ /* * The following is the copyright & permission notices of xdu @@ -47,14 +48,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 +91,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-02-13 17:10:24.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-02-16 19:36:01.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=c99 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-02-13 17:11:05.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", 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");